home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / tmp4 / ckuus4.c < prev    next >
C/C++ Source or Header  |  2009-11-27  |  505KB  |  14,830 lines

  1. #include "ckcsym.h"
  2.  
  3. /*  C K U U S 4 --  "User Interface" for C-Kermit, part 4  */
  4.  
  5. /*
  6.   Authors:
  7.     Frank da Cruz <fdc@columbia.edu>,
  8.       The Kermit Project, Columbia University, New York City
  9.     Jeffrey E Altman <jaltman@secure-endpoints.com>
  10.       Secure Endpoints Inc., New York City
  11.  
  12.   Copyright (C) 1985, 2009,
  13.     Trustees of Columbia University in the City of New York.
  14.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  15.     copyright text in the ckcmai.c module for disclaimer and permissions.
  16. */
  17.  
  18. /*
  19.   File ckuus4.c -- Functions moved from other ckuus*.c modules to even
  20.   out their sizes.
  21. */
  22. #include "ckcdeb.h"
  23. #include "ckcasc.h"
  24. #include "ckcker.h"
  25. #include "ckcnet.h"                     /* Network symbols */
  26. #include "ckuusr.h"
  27. #include "ckuver.h"
  28. #include "ckcxla.h"                     /* Character sets */
  29.  
  30. #ifdef CK_AUTHENTICATION
  31. #include "ckuath.h"
  32. #endif /* CK_AUTHENTICATION */
  33. #ifdef CK_SSL
  34. #include "ck_ssl.h"
  35. #endif /* CK_SSL */
  36.  
  37. #ifdef VMS
  38. #include <errno.h>                      /* For \v(errno) */
  39. extern char * ckvmserrstr(unsigned long);
  40. #ifndef OLD_VMS
  41. #include <lib$routines.h>               /* Not for VAX C 2.4 */
  42. #else
  43. #include <libdef.h>
  44. #endif /* OLD_VMS */
  45. _PROTOTYP(int vmsttyfd, (void) );
  46. #endif /* VMS */
  47.  
  48. #ifdef OS2
  49. #ifndef NT
  50. #define INCL_NOPM
  51. #define INCL_VIO                        /* Needed for ckocon.h */
  52. #include <os2.h>
  53. #undef COMMENT
  54. #else
  55. #include <windows.h>
  56. #include <tapi.h>
  57. #include "ckntap.h"
  58. #define APIRET ULONG
  59. #endif /* NT */
  60. #include "ckocon.h"
  61. #include "ckoetc.h"
  62. int StartedFromDialer = 0;
  63. HWND hwndDialer = 0;
  64. LONG KermitDialerID = 0;
  65. #ifdef putchar
  66. #undef putchar
  67. #endif /* putchar */
  68. #define putchar(x) conoc(x)
  69. #ifdef CK_PID
  70. #include <process.h>
  71. #endif /* CK_PID */
  72. #endif /* OS2 */
  73.  
  74. #ifdef KUI
  75. extern struct keytab * term_font;
  76. extern int ntermfont, tt_font, tt_font_size;
  77. #endif /* KUI */
  78.  
  79. extern xx_strp xxstring;
  80.  
  81. #ifdef DEC_TCPIP
  82. #include <descrip>
  83. #include <dvidef>
  84. #include <dcdef>
  85. #endif /* DEC_TCPIP */
  86.  
  87. #ifdef FNFLOAT
  88. #include <math.h>                       /* Floating-point functions */
  89. #endif /* FNFLOAT */
  90.  
  91. extern int quiet, network, xitsta, escape, nopush, xferstat,
  92.   exitonclose, tn_exit, ttnproto, autodl, flow, byteorder, what, lastxfer;
  93.  
  94. extern int filepeek, nscanfile, makestrlen;
  95. extern char * k_info_dir;
  96.  
  97. #ifndef MAC
  98. #ifndef AMIGA
  99. extern int ttyfd;
  100. #endif /* MAC */
  101. #endif /* AMIGA */
  102.  
  103. #ifdef TNCODE
  104. extern int tn_nlm, tn_b_nlm, tn_b_xfer, tn_sb_bug;
  105. extern int tn_rem_echo;
  106. extern int tn_b_meu, tn_b_ume, tn_auth_krb5_des_bug;
  107. #endif /* TNCODE */
  108.  
  109. static char * lastkwval = NULL;
  110.  
  111. char * xferfile = NULL;
  112. int xferlog = 0;
  113.  
  114. extern int local, xargc, stayflg, rcflag, bgset, backgrd, cfilef,
  115.   inserver, srvcdmsg, success;
  116.  
  117. #ifdef VMS
  118. extern int batch;
  119. #endif /* VMS */
  120.  
  121. extern char cmdfil[], *versio, *ckxsys, **xargv;
  122. #ifdef DEBUG
  123. extern char debfil[];                   /* Debug log file name */
  124. extern int debtim;
  125. #endif /* DEBUG */
  126.  
  127. extern int noinit;
  128.  
  129. static char ndatbuf[10];
  130.  
  131. char *months[] = {
  132.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  133.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  134. };
  135.  
  136. char *
  137. zzndate() {                             /* Returns today's date as yyyymmdd */
  138.     char * p = NULL;
  139.     int x;
  140.  
  141. /* WARNING - This will fail if asctime() returns non-English month names */
  142.  
  143.     ztime(&p);                          /* Get "asctime" string */
  144.     if (p == NULL || *p == NUL) return("");
  145.     for (x = 20; x < 24; x++)           /* yyyy */
  146.       ndatbuf[x - 20] = p[x];
  147.     ndatbuf[6] = (char) ((p[8] == ' ') ? '0' : p[8]);
  148.     ndatbuf[7] = p[9];                  /* dd */
  149.     for (x = 0; x < 12; x++)            /* mm */
  150.       if (!strncmp(p+4,months[x],3)) break;
  151.     if (x == 12) {
  152.         ndatbuf[4] = ndatbuf[5] = '?';
  153.     } else {
  154.         x++;
  155.         ndatbuf[4] = (char) ((x < 10) ? '0' : '1');
  156.         ndatbuf[5] = (char) ((x % 10) + 48);
  157.     }
  158.     ndatbuf[8] = NUL;
  159.     debug(F110,"zzndate return",ndatbuf,0);
  160.     return((char *)ndatbuf);
  161. }
  162.  
  163. #ifdef DCMDBUF
  164. extern struct cmdptr *cmdstk;
  165. extern char *line, *tmpbuf;
  166. #else
  167. extern struct cmdptr cmdstk[];
  168. extern char line[], tmpbuf[];
  169. #endif /* DCMDBUF */
  170.  
  171. #ifdef OS2
  172. extern char exedir[];
  173. #else
  174. extern char * exedir;
  175. #endif /* OS2 */
  176.  
  177. extern int nettype;
  178.  
  179. #ifndef NOICP                           /* Most of this file... */
  180. #ifdef CKLOGDIAL
  181. extern char diafil[];
  182. #endif /* CKLOGDIAL */
  183.  
  184. #ifndef AMIGA
  185. #ifndef MAC
  186. #include <signal.h>
  187. #endif /* MAC */
  188. #endif /* AMIGA */
  189.  
  190. #ifdef SV68                /* July 2006 believe it or not */
  191. #ifndef SEEK_CUR
  192. #include <unistd.h>
  193. #endif    /* SEEK_CUR */
  194. #endif    /* SV68 */
  195.  
  196. #ifdef STRATUS                          /* Stratus Computer, Inc.  VOS */
  197. #ifdef putchar
  198. #undef putchar
  199. #endif /* putchar */
  200. #define putchar(x) conoc(x)
  201. #ifdef getchar
  202. #undef getchar
  203. #endif /* getchar */
  204. #define getchar(x) coninc(0)
  205. #endif /* STRATUS */
  206.  
  207.  
  208. #ifdef ANYX25
  209. extern int revcall, closgr, cudata;
  210. int x25ver;
  211. extern char udata[];
  212. #ifndef IBMX25
  213. extern int npadx3;
  214. extern CHAR padparms[];
  215. extern struct keytab padx3tab[];
  216. #endif /* !IBMX25 */
  217. #ifdef IBMX25
  218. /* global variables only available for IBM X.25 - possibly interesting for
  219.  * other implementations
  220.  */
  221. extern x25addr_t local_nua;
  222. extern x25addr_t remote_nua;
  223. #endif /* IBMX25 */
  224. #endif /* ANYX25 */
  225.  
  226. #ifdef NETCONN
  227. #ifndef NODIAL
  228. extern int nnetdir;
  229. extern char *netdir[];
  230. #endif /* NODIAL */
  231. extern char ipaddr[];
  232.  
  233. #ifdef CK_NETBIOS
  234. extern unsigned short netbiosAvail;
  235. extern unsigned long NetbeuiAPI;
  236. extern unsigned char NetBiosName[];
  237. extern unsigned char NetBiosAdapter;
  238. extern unsigned char NetBiosLSN;
  239. #endif /* CK_NETBIOS */
  240.  
  241. #ifdef TCPSOCKET
  242. extern char myipaddr[];
  243. extern int tcp_rdns;
  244. #ifdef CK_DNS_SRV
  245. extern int tcp_dns_srv;
  246. #endif /* CK_DNS_SRV */
  247. extern char * tcp_address;
  248. #ifndef NOHTTP
  249. extern char * tcp_http_proxy;
  250. #endif /* NOHTTP */
  251. #ifdef NT
  252. #ifdef CK_SOCKS
  253. extern char * tcp_socks_svr;
  254. #ifdef CK_SOCKS_NS
  255. extern char * tcp_socks_ns;
  256. #endif /* CK_SOCKS_NS */
  257. #endif /* CK_SOCKS */
  258. #endif /* NT */
  259.  
  260. #ifndef NOTCPOPTS
  261. #ifdef SOL_SOCKET
  262. #ifdef SO_LINGER
  263. extern int tcp_linger;
  264. extern int tcp_linger_tmo;
  265. #endif /* SO_LINGER */
  266. #ifdef SO_DONTROUTE
  267. extern int tcp_dontroute;
  268. #endif /* SO_DONTROUTE */
  269. #ifdef TCP_NODELAY
  270. extern int tcp_nodelay;
  271. #endif /* TCP_NODELAY */
  272. #ifdef SO_SNDBUF
  273. extern int tcp_sendbuf;
  274. #endif /* SO_SNDBUF */
  275. #ifdef SO_RCVBUF
  276. extern int tcp_recvbuf;
  277. #endif /* SO_RCVBUF */
  278. #ifdef SO_KEEPALIVE
  279. extern int tcp_keepalive;
  280. #endif /* SO_KEEPALIVE */
  281. #endif /* SOL_SOCKET */
  282. #endif /* NOTCPOPTS */
  283. #endif /* TCPSOCKET */
  284. #endif /* NETCONN */
  285.  
  286. extern char * floname[];
  287.  
  288. #ifndef NOSPL
  289. extern int vareval;            /* Variable evaluation method */
  290. extern int fndiags;                     /* Function diagnostics on/off */
  291. extern int divbyzero;
  292. int itsapattern = 0;
  293. int isinbuflen = 0;
  294. int isjoin = 0;
  295. #ifdef CK_APC
  296. extern int apcactive;                   /* Nonzero = APC command was rec'd */
  297. extern int apcstatus;                   /* Are APC commands being processed? */
  298. #ifdef DCMDBUF
  299. extern char *apcbuf;                    /* APC command buffer */
  300. #else
  301. extern char apcbuf[];
  302. #endif /* DCMDBUF */
  303. #endif /* CK_APC */
  304.  
  305. extern char evalbuf[];                  /* EVALUATE result */
  306. extern char uidbuf[], pwbuf[], prmbuf[];
  307. _PROTOTYP( static char * fneval, (char *, char * [], int, char * ) );
  308. _PROTOTYP( static VOID myflsh, (void) );
  309. _PROTOTYP( static char * getip, (char *) );
  310. _PROTOTYP( int delta2sec, (char *, long *) );
  311.  
  312. #ifdef NEWFTP
  313. _PROTOTYP( char * ftp_cpl_mode, (void) );
  314. _PROTOTYP( char * ftp_dpl_mode, (void) );
  315. _PROTOTYP( char * ftp_authtype, (void) );
  316. #endif /* NEWFTP */
  317.  
  318. #ifndef NOHTTP
  319. _PROTOTYP( char * http_host, (void) );
  320. _PROTOTYP( int http_isconnected, (void) );
  321. _PROTOTYP( char * http_security, (void) );
  322. #endif /* NOHTTP */
  323.  
  324. #ifndef NOSEXP
  325. _PROTOTYP( char * dosexp, (char *) );
  326. int fsexpflag = 0;
  327. #endif /* NOSEXP */
  328.  
  329. static char hexdigits[16] = {
  330.     '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  331. };
  332. extern char * tempdir;
  333.  
  334. #ifdef CK_REXX
  335. extern char rexxbuf[];
  336. #endif /* CK_REXX */
  337.  
  338. extern int tfline[];
  339.  
  340. char *wkdays[] = {
  341.     "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  342. };
  343. #endif /* NOSPL */
  344.  
  345. #ifdef OS2
  346. extern char startupdir[], inidir[];
  347. #else
  348. #ifdef VMSORUNIX
  349. extern char startupdir[];
  350. #endif /* VMSORUNIX */
  351. #endif /* OS2 */
  352.  
  353. #ifdef OS2
  354. _PROTOTYP (int os2getcp, (void) );
  355. #ifdef TCPSOCKET
  356. extern char tcpname[];
  357. #endif /* TCPSOCKET */
  358. extern int tcp_avail;
  359. #ifdef DECNET
  360. extern int dnet_avail;
  361. #endif /* DECNET */
  362. #ifdef SUPERLAT
  363. extern int slat_avail;
  364. #endif /* SUPERLAT */
  365.  
  366. #ifndef NOTERM
  367. extern int tt_type, max_tt;
  368. extern struct tt_info_rec tt_info[];
  369. #endif /* NOTERM */
  370. extern int tt_rows[], tt_cols[];
  371. #else /* OS2 */
  372. extern int tt_rows, tt_cols;
  373. #endif /* OS2 */
  374.  
  375. #ifdef CK_TAPI
  376. extern int tttapi;
  377. extern int tapipass;
  378. extern struct keytab * tapilinetab;
  379. extern struct keytab * _tapilinetab;
  380. extern int ntapiline;
  381. #endif /* CK_TAPI */
  382.  
  383. extern struct keytab colxtab[];
  384. extern int ncolx;
  385.  
  386. extern char ttname[], *zinptr, *kermrc;
  387. extern char inidir[];
  388.  
  389. extern int activecmd, remonly, cmd_rows, cmd_cols, parity, seslog,
  390.   sessft, sosi, hwparity, tsecs, xargs, zincnt, tlevel, insilence, cmdmsk,
  391.   timint, timef, inbufsize, dialog, binary, carrier, cdtimo, cmask, duplex,
  392.   fmask, inecho, nmac, turnch, turn, kbchar;
  393.  
  394. #ifndef NOXFER
  395. extern CHAR eol,  mypadc, mystch, padch, seol, stchr, * epktmsg, feol;
  396. extern char *cksysid;
  397. extern struct ck_p ptab[];
  398. extern int
  399.   protocol, prefixing, xfrbel, xfrcan, xfrint, xfrchr, xfrnum, pktpaus,
  400.   lscapr, lscapu, xfermode, dest, slostart, maxrps, maxsps, maxtry, mypadn,
  401.   npad, pkttim, bigrbsiz, bigsbsiz, keep, atcapr, autopar, bctr, bctu,
  402.   crunched, ckdelay, ebq, ebqflg, pktlog, retrans, rpackets, rptflg, rptq,
  403.   rtimo, spackets, spsiz, spsizf, spsizr, timeouts, fncact, fncnv, urpsiz,
  404.   wmax, wslotn, wslotr, fdispla, spmax, fnrpath, fnspath, crc16;
  405. #endif /* NOXFER */
  406.  
  407. #ifdef OS2
  408. extern int zxpn;
  409. extern int viewonly;
  410. #endif /* OS2 */
  411.  
  412. #ifndef NOXFER
  413. #ifdef GFTIMER
  414. extern CKFLOAT fptsecs, fpxfsecs;
  415. #endif /* GFTIMER */
  416. extern long xfsecs, tfcps;
  417.  
  418. #ifdef CK_TMPDIR
  419. extern char *dldir;
  420. #endif /* CK_TMPDIR */
  421. #endif /* NOXFER */
  422.  
  423. #ifdef RECURSIVE
  424. extern int recursive;
  425. #endif /* RECURSIVE */
  426.  
  427. #ifdef VMS
  428. extern int frecl;
  429. #endif /* VMS */
  430.  
  431. extern CK_OFF_T ffc, tfc, tlci, tlco;
  432. extern long filcnt, rptn, speed,  ccu, ccp, vernum, xvernum;
  433.  
  434. #ifndef NOSPL
  435. extern char fspec[], myhost[];
  436. #endif /* NOSPL */
  437.  
  438. extern char *tfnam[];                   /* Command file names */
  439.  
  440. extern char pktfil[],                   /* Packet log file name */
  441. #ifdef TLOG
  442.   trafil[],                             /* Transaction log file name */
  443. #endif /* TLOG */
  444.   sesfil[];                             /* Session log file name */
  445.  
  446. #ifndef NOXMIT                          /* TRANSMIT command variables */
  447. extern char xmitbuf[];
  448. extern int xmitf, xmitl, xmitx, xmits, xmitw, xmitt;
  449. #endif /* NOXMIT */
  450.  
  451. extern int cmdlvl;
  452.  
  453. #ifndef NOSPL
  454. /* Script programming language items */
  455. extern char **a_ptr[];                  /* Arrays */
  456. extern int a_dim[];
  457. static char * inpmatch = NULL;
  458. #ifdef CKFLOAT
  459. char * inpscale = NULL;
  460. #endif    /* CKFLOAT */
  461. extern char * inpbuf, inchar[];         /* Buffers for INPUT and REINPUT */
  462. extern char *inpbp;                     /* And pointer to same */
  463. static char *r3 = (char *)0;
  464. extern int incount;                     /* INPUT character count */
  465. extern int m_found;                     /* MINPUT result */
  466. extern int maclvl;                      /* Macro invocation level */
  467. extern struct mtab *mactab;             /* Macro table */
  468. extern char *mrval[];
  469. extern int macargc[], topargc;
  470.  
  471. #ifdef COMMENT
  472. extern char *m_line[];
  473. extern char *topline;
  474. #endif /* COMMENT */
  475.  
  476. extern char *m_arg[MACLEVEL][10]; /* You have to put in the dimensions */
  477. extern char *g_var[GVARS];        /* for external 2-dimensional arrays. */
  478. #ifdef DCMDBUF
  479. extern int *count, *inpcas;
  480. #else
  481. extern int count[], inpcas[];
  482. #endif /* DCMDBUF */
  483. #endif /* NOSPL */
  484.  
  485. #ifdef UNIX
  486. extern int haslock;                     /* For UUCP locks */
  487. extern char flfnam[];
  488. #ifndef USETTYLOCK
  489. extern char lock2[];
  490. #endif /* USETTYLOCK */
  491. #endif /* UNIX */
  492.  
  493. #ifdef OS2ORUNIX
  494. extern int maxnam, maxpath;             /* Longest name, path length */
  495. #endif /* OS2ORUNIX */
  496.  
  497. extern int mdmtyp, mdmsav;
  498.  
  499. #ifndef NODIAL
  500. /* DIAL-related variables */
  501. extern char modemmsg[];
  502. extern MDMINF *modemp[];                /* Pointers to modem info structs */
  503. extern int nmdm, dialhng, dialtmo, dialksp, dialdpy, dialsrt, dialsta;
  504. extern int dialrtr, dialint, dialrstr, dialcon, dialcq, dialfld;
  505. extern int mdmspd, dialec, dialdc, dialmth, dialmauto, dialesc;
  506. extern char *dialnum,   *dialini,  *dialdir[], *dialcmd,  *dialnpr,
  507.  *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd, *diallac,
  508.  *dialhwfc, *dialswfc,  *dialnofc, *dialpulse, *dialtone, *dialname,
  509.  *dialaaon, *dialaaoff, *dialmac;
  510. extern char *diallcc,   *dialixp,  *dialixs,   *dialldp,  *diallds,
  511.  *dialpxi,  *dialpxo,   *dialsfx,  *dialtfp;
  512. extern char *diallcp,   *diallcs;
  513. extern int ntollfree, ndialpxx, nlocalac;
  514. extern char *dialtfc[], *diallcac[], *dialpxx[], *matchpxx;
  515. extern int ndialpucc, ndialtocc;
  516. extern char *dialtocc[], *dialpucc[];
  517. extern int ndialdir, dialcnf, dialcvt, dialidt, dialpace;
  518. extern long dialmax, dialcapas;
  519.  
  520. extern struct keytab mdmtab[];
  521.  
  522. #ifdef BIGBUFOK
  523. #define ARGBUFSIZ 8191
  524. #else
  525. #define ARGBUFSIZ 1023
  526. #endif /* BIGBUFOK */
  527.  
  528. #ifdef BIGBUFOK
  529. extern char * dialmsg[];
  530. #endif /* BIGBUFOK */
  531.  
  532. #endif /* NODIAL */
  533.  
  534. #ifndef NOCSETS
  535. /* Translation stuff */
  536. extern int fcharset, tcharset, tslevel, language, nlng, tcsr, tcsl;
  537. extern int dcset7, dcset8;
  538. extern struct keytab lngtab[];
  539. extern struct csinfo fcsinfo[], tcsinfo[];
  540. extern struct langinfo langs[];
  541. #ifdef CK_ANSIC
  542. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  543. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  544. #else
  545. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(); /* Character set */
  546. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(); /* translation functions. */
  547. #endif /* CK_ANSIC */
  548. #ifdef UNICODE
  549.     extern int ucsbom, ucsorder;
  550. #endif /* UNICODE */
  551. #endif /* NOCSETS */
  552.  
  553. #ifndef NOSPL
  554. /* Built-in variable names, maximum length VNAML (20 characters) */
  555.  
  556. struct keytab vartab[] = {
  557.     { "_line",     VN_TFLN,  CM_INV},   /* 192 */
  558. #ifdef OS2
  559.     { "_regname",  VN_REGN,  CM_INV},   /* 1.1.12 */
  560.     { "_regorg",   VN_REGO,  CM_INV},   /* 1.1.12 */
  561.     { "_regnum",   VN_REGS,  CM_INV},   /* 1.1.12 */
  562. #endif /* OS2 */
  563.     { "apcactive", VN_APC,   CM_INV},   /* 192 */
  564. #ifdef NT
  565.     { "appdata",   VN_APPDATA, 0},      /* 201 */
  566. #endif /* NT */
  567.     { "argc",      VN_ARGC,  0},
  568.     { "args",      VN_ARGS,  0},
  569.     { "authname",  VN_AUTHN, 0},        /* 196 */
  570.     { "authstate", VN_AUTHS, 0},        /* 195 */
  571.     { "authtype",  VN_AUTHT, 0},        /* 195 */
  572.     { "bits",      VN_BITS,  0},        /* 212 */
  573.     { "blockcheck",VN_BLK,   0},        /* 195 */
  574. #ifdef BROWSER
  575.     { "browser",   VN_BROWSR,0},        /* 193 */
  576.     { "browsopts", VN_BROPT, 0},        /* 193 */
  577.     { "browsurl",  VN_URL,   0},        /* 193 */
  578.     { "buildid",   VN_BUILD, 0},        /* 199 */
  579. #endif /* BROWSER */
  580.     { "byteorder", VN_BYTE,  0},        /* 195 */
  581. #ifndef NOCSETS
  582.     { "charset",   VN_CSET,  0},        /* 192 */
  583. #endif /* NOCSETS */
  584.     { "cmdbufsize",VN_CMDBL, 0},        /* 195 */
  585.     { "cmdfile",   VN_CMDF,  0},
  586.     { "cmdlevel",  VN_CMDL,  0},
  587.     { "cmdsource", VN_CMDS,  0},
  588.     { "cols",      VN_COLS,  0},        /* 190 */
  589. #ifdef NT
  590.     { "common",    VN_COMMON, 0},       /* 201 */
  591. #endif /* NT */
  592.     { "connection",VN_CONN,  0},        /* 190 */
  593.     { "count",     VN_COUN,  0},
  594. #ifndef NOXFER
  595.     { "cps",       VN_CPS,   0},        /* 190 */
  596. #endif /* NOXFER */
  597.     { "cpu",       VN_CPU,   0},
  598. #ifndef NOXFER
  599.     { "crc16",     VN_CRC16, 0},        /* 192 */
  600.     { "ctty",      VN_TTYNAM,0},        /* 196 */
  601. #endif /* NOXFER */
  602. #ifndef NOLOGDIAL
  603. #ifndef NOLOCAL
  604.     { "cx_time",   VN_CXTIME,0},        /* 195 */
  605.     { "cx_status", VN_CX_STA,0},        /* 199 */
  606. #endif /* NOLOCAL */
  607. #endif /* NOLOGDIAL */
  608. #ifndef NODIAL
  609.     { "d$ac",      VN_D_AC,  0},        /* 192 */
  610.     { "d$cc",      VN_D_CC,  0},        /* 192 */
  611.     { "d$ip",      VN_D_IP,  0},        /* 192 */
  612.     { "d$lc",      VN_D_LCP, 0},        /* 193 */
  613.     { "d$lcp",     VN_D_LCP, CM_INV},   /* 193 */
  614.     { "d$lp",      VN_D_LP,  0},        /* 192 */
  615.     { "d$px",      VN_D_PXX, 0},        /* 195 */
  616.     { "d$pxx",     VN_D_PXX, CM_INV},   /* 195 */
  617. #endif /* NODIAL */
  618.     { "date",      VN_DATE,  0},
  619.     { "day",       VN_DAY,   0},
  620. #ifdef NT
  621.     { "desktop",   VN_DESKTOP, 0},     /* 201 */
  622. #endif /* NT */
  623. #ifndef NODIAL
  624.     { "dialcount", VN_DRTR,  0},        /* 195 */
  625.     { "dialmessage",VN_DMSG, 0},    /* 212 */
  626.     { "dialnumber",VN_DNUM,  0},        /* 192 */
  627.     { "dialresult",VN_MDMSG, 0},        /* 192 */
  628.     { "dialstatus",VN_DIAL,  0},        /* 190 */
  629.     { "dialsuffix",VN_PDSFX, 0},        /* 193 */
  630.     { "dialtype",  VN_DTYPE, 0},        /* 193 */
  631. #endif /* NODIAL */
  632.     { "directory", VN_DIRE,  0},
  633. #ifndef NODIAL
  634.     { "dm_hf",     VN_DM_HF, 0},        /* 199 */
  635.     { "dm_lp",     VN_DM_LP, 0},        /* 195 */
  636.     { "dm_sp",     VN_DM_SP, 0},        /* 195 */
  637.     { "dm_pd",     VN_DM_PD, 0},        /* 195 */
  638.     { "dm_td",     VN_DM_TD, 0},        /* 195 */
  639.     { "dm_wa",     VN_DM_WA, 0},        /* 195 */
  640.     { "dm_wb",     VN_DM_WB, 0},        /* 199 */
  641.     { "dm_wd",     VN_DM_WD, 0},        /* 195 */
  642.     { "dm_rc",     VN_DM_RC, 0},        /* 195 */
  643. #endif /* NODIAL */
  644. #ifndef NOXFER
  645.     { "download",  VN_DLDIR, 0},        /* 192 */
  646. #endif /* NOXFER */
  647.     { "editor",    VN_EDITOR,0},
  648.     { "editfile",  VN_EDFILE,0},
  649.     { "editopts",  VN_EDOPT, 0},
  650.     { "errno",     VN_ERRNO, 0},        /* 192 */
  651.     { "errstring", VN_ERSTR, 0},        /* 192 */
  652.     { "escape",    VN_ESC,   0},        /* 193 */
  653.     { "evaluate",  VN_EVAL,  0},        /* 190 */
  654. #ifdef OS2ORUNIX
  655.     { "exedir",    VN_EXEDIR,0},        /* 192 */
  656. #endif /* OS2ORUNIX */
  657.     { "exitstatus",VN_EXIT,  0},
  658. #ifdef CKCHANNELIO
  659.     { "f_count",   VN_FCOU,  0},        /* 195 */
  660.     { "f_error",   VN_FERR,  0},        /* 195 */
  661.     { "f_max",     VN_FMAX,  0},        /* 195 */
  662.     { "fileerror", VN_FERR,  CM_INV},   /* 195 */
  663.     { "filemax",   VN_FERR,  CM_INV},   /* 195 */
  664. #endif /* CKCHANNELIO */
  665.     { "filename",  VN_FNAM,  0},        /* 193 */
  666.     { "filenumber",VN_FNUM,  0},        /* 193 */
  667.     { "filespec",  VN_FILE,  0},
  668.     { "fsize",     VN_FFC,   0},        /* 190 */
  669. #ifdef GFTIMER
  670.     { "ftime",     VN_FTIME, 0},        /* 199 */
  671. #else
  672.     { "ftime",     VN_NTIM,  CM_INV},
  673. #endif /* GFTIMER */
  674. #ifndef NOFTP
  675. #ifndef SYSFTP
  676.     { "ftp_code",         VN_FTP_C, 0}, /* 199 */
  677.     { "ftp_cpl",          VN_FTP_B, 0}, /* 199 */
  678.     { "ftp_connected",    VN_FTP_X, 0}, /* 199 */
  679.     { "ftp_dpl",          VN_FTP_D, 0}, /* 199 */
  680.     { "ftp_getputremote", VN_FTP_G, 0}, /* 199 */
  681.     { "ftp_host",         VN_FTP_H, 0}, /* 199 */
  682.     { "ftp_loggedin",     VN_FTP_L, 0}, /* 199 */
  683.     { "ftp_message",      VN_FTP_M, 0}, /* 199 */
  684.     { "ftp_msg",          VN_FTP_M, CM_INV}, /* 199 */
  685.     { "ftp_security",     VN_FTP_Z, 0}, /* 199 */
  686.     { "ftp_server",       VN_FTP_S, 0}, /* 199 */
  687. #endif /* SYSFTP */
  688. #endif /* NOFTP */
  689.     { "ftype",     VN_MODE,  0},        /* 190 */
  690. #ifdef KUI
  691.     { "gui_fontname", VN_GUI_FNM, 0},    /* 205 */
  692.     { "gui_fontsize", VN_GUI_FSZ, 0},    /* 205 */
  693.     { "gui_runmode", VN_GUI_RUN, 0},    /* 205 */
  694.     { "gui_xpos",    VN_GUI_XP,  0},    /* 205 */
  695.     { "gui_xres",    VN_GUI_XR,  0},    /* 205 */
  696.     { "gui_ypos",    VN_GUI_YP,  0},    /* 205 */
  697.     { "gui_yres",    VN_GUI_YR,  0},    /* 205 */
  698. #endif /* KUI */
  699.     { "herald",    VN_HERALD, 0},
  700.     { "home",      VN_HOME,   0},
  701.     { "host",      VN_HOST,   0},
  702.     { "hour",      VN_HOUR,   0},       /* 200 */
  703. #ifndef NOHTTP
  704.     { "http_code",      VN_HTTP_C, 0},  /* 199 */
  705.     { "http_connected", VN_HTTP_N, 0},  /* 199 */
  706.     { "http_host",      VN_HTTP_H, 0},  /* 199 */
  707.     { "http_message",   VN_HTTP_M, 0},  /* 199 */
  708.     { "http_security",  VN_HTTP_S, 0},  /* 199 */
  709. #endif /* NOHTTP */
  710.     { "hwparity",  VN_HWPAR, 0},        /* 195 */
  711.     { "input",     VN_IBUF,  0},
  712.     { "inchar",    VN_ICHR,  0},
  713.     { "incount",   VN_ICNT,  0},
  714.     { "inidir",    VN_INI,   0},        /* 192 */
  715.     { "inmatch",   VN_MATCH, 0},        /* 196 */
  716.     { "inmessage", VN_INPMSG,0},        /* 212 */
  717.     { "inscale",   VN_ISCALE,0},        /* 210 */
  718.     { "instatus",  VN_ISTAT, 0},        /* 192 */
  719.     { "intime",    VN_INTIME,0},        /* 193 */
  720.     { "inwait",    VN_INTMO, 0},        /* 195 */
  721.     { "ip",        VN_IPADDR, CM_ABR|CM_INV},
  722.     { "ipaddress", VN_IPADDR,0},        /* 192 */
  723.     { "iprompt",   VN_PROMPT,0},        /* 199 */
  724.     { "kbchar",    VN_KBCHAR,0},        /* 196 */
  725. #ifndef NOLOCAL
  726. #ifdef OS2
  727.     { "keyboard",  VN_KEYB,  0},
  728. #endif /* OS2 */
  729. #endif /* NOLOCAL */
  730. #ifdef CK_KERBEROS
  731.     { "krb4errmsg",    VN_K4EMSG,0},
  732.     { "krb4errno",     VN_K4ENO, 0},
  733.     { "krb4principal", VN_K4PRN, 0},
  734.     { "krb4realm",     VN_K4RLM, 0},
  735.     { "krb4service",   VN_K4SRV, 0},
  736.     { "krb5cc",        VN_K5CC,  0},
  737.     { "krb5errmsg",    VN_K5EMSG,0},
  738.     { "krb5errno",     VN_K5ENO, 0},
  739.     { "krb5principal", VN_K5PRN, 0},
  740.     { "krb5realm",     VN_K5RLM, 0},
  741.     { "krb5service",   VN_K5SRV, 0},
  742. #endif /* CK_KERBEROS */
  743. #ifndef NOLASTFILE
  744.     { "lastfilespec",  VN_LASTFIL, 0},    /* 212 */
  745. #endif    /* NOLASTFILE */
  746.     { "lastkeywordvalue",  VN_LASTKWV, 0}, /* 212 */
  747.     { "lastkwvalue",   VN_LASTKWV, CM_ABR|CM_INV}, /* 212 */
  748.     { "line",          VN_LINE,  0},
  749.     { "local",         VN_LCL,   0},
  750. #ifdef UNIX
  751.     { "lockdir",       VN_LCKDIR,0},    /* 195 */
  752.     { "lockpid",       VN_LCKPID,0},    /* 195 */
  753. #endif /* UNIX */
  754.     { "log_connection", VN_LOG_CON, 0}, /* 206 */
  755.     { "log_debug", VN_LOG_DEB, 0},      /* 206 */
  756.     { "log_packet", VN_LOG_PKT, 0},     /* 206 */
  757.     { "log_session", VN_LOG_SES, 0},    /* 206 */
  758.     { "log_transaction", VN_LOG_TRA, 0},/* 206 */
  759.     { "maclevel",  VN_MACLVL,0},        /* 195 */
  760.     { "macro",     VN_MAC,   0},
  761. #ifdef FNFLOAT
  762.     { "math_e",    VN_MA_E,  0},        /* 195 */
  763.     { "math_pi",   VN_MA_PI, 0},        /* 195 */
  764.     { "math_precision", VN_MA_PR, 0},   /* 195 */
  765. #endif /* FNFLOAT */
  766.     { "minput",    VN_MINP,  0},        /* 192 */
  767.     { "model",     VN_MODL,  0},        /* 193 */
  768.     { "modem",     VN_MDM,   0},
  769. #ifndef NOLOCAL
  770. #ifdef OS2
  771.     { "mousecurx", VN_MOU_X, 0},        /* K95 1.1.14 */
  772.     { "mousecury", VN_MOU_Y, 0},        /* K95 1.1.14 */
  773. #endif /* OS2 */
  774. #endif /* NOLOCAL */
  775. #ifndef NODIAL
  776.     { "m_aa_off",  VN_M_AAX, 0},        /* all 192... */
  777.     { "m_aa_on",   VN_M_AAO, 0},
  778.     { "m_dc_off",  VN_M_DCX, 0},
  779.     { "m_dc_on",   VN_M_DCO, 0},
  780.     { "m_dial",    VN_M_DCM, 0},
  781.     { "m_ec_off",  VN_M_ECX, 0},
  782.     { "m_ec_on",   VN_M_ECO, 0},
  783.     { "m_fc_hw",   VN_M_HWF, 0},
  784.     { "m_fc_no",   VN_M_NFC, 0},
  785.     { "m_fc_sw",   VN_M_SWF, 0},
  786.     { "m_hup",     VN_M_HUP, 0},
  787.     { "m_init",    VN_M_INI, 0},
  788.     { "m_name",    VN_M_NAM, 0},        /* 195 */
  789.     { "m_pulse",   VN_M_PDM, 0},
  790.     { "m_sig_cd",  VN_MS_CD, 0},        /* 195 */
  791.     { "m_sig_cts", VN_MS_CTS,0},        /* 195 */
  792.     { "m_sig_dsr", VN_MS_DSR,0},        /* 195 */
  793.     { "m_sig_dtr", VN_MS_DTR,0},        /* 195 */
  794.     { "m_sig_ri",  VN_MS_RI, 0},        /* 195 */
  795.     { "m_sig_rts", VN_MS_RTS,0},        /* 195 */
  796.     { "m_tone",    VN_M_TDM, 0},
  797. #endif /* NODIAL */
  798.     { "name",      VN_NAME,  0},
  799.     { "ndate",     VN_NDAT,  0},
  800.     { "nday",      VN_NDAY,  0},
  801.     { "newline",   VN_NEWL,  0},
  802.     { "ntime",     VN_NTIM,  0},
  803.     { "osname",    VN_OSNAM, 0},        /* 193 */
  804.     { "osrelease", VN_OSREL, 0},        /* 193 */
  805.     { "osversion", VN_OSVER, 0},        /* 193 */
  806. #ifndef NOXFER
  807.     { "packetlen", VN_RPSIZ, 0},        /* 192 */
  808. #endif /* NOXFER */
  809.     { "parity",    VN_PRTY,  0},        /* 190 */
  810.     { "password",  VN_PWD,   CM_INV},   /* 192 */
  811. #ifdef NT
  812.     { "personal",  VN_PERSONAL, 0},     /* 201 */
  813. #endif /* NT */
  814. #ifdef PEXITSTAT
  815.     { "pexitstat", VN_PEXIT, 0},        /* 193 */
  816. #endif /* PEXITSTAT */
  817. #ifdef CK_PID
  818.     { "pid",       VN_PID,   0},        /* 193 */
  819. #endif /* CK_PID */
  820.     { "platform",  VN_SYSV,  0},
  821.     { "printer",   VN_PRINT, 0},        /* 193 */
  822.     { "program",   VN_PROG,  0},
  823.     { "prompt",    VN_PRM,   CM_INV},   /* 192 */
  824. #ifndef NOXFER
  825.     { "protocol",  VN_PROTO, 0},        /* 192 */
  826.     { "p_8bit",    VN_P_8BIT,0},        /* 193 */
  827.     { "p_ctl",     VN_P_CTL, 0},        /* 193 */
  828.     { "p_rpt",     VN_P_RPT, 0},        /* 193 */
  829.     { "query",     VN_QUE,   0},        /* 190 */
  830. #endif /* NOXFER */
  831.     { "remoteip",  VN_HOSTIP,0},    /* 212 */
  832.     { "return",    VN_RET,   0},
  833. #ifdef CK_REXX
  834.     { "rexx",      VN_REXX,  0},        /* 190 */
  835. #endif /* CK_REXX */
  836. #ifdef TN_COMPORT
  837.     { "rfc2217_signature", VN_TNC_SIG, 0}, /* 201 */
  838.     { "rfc2717_signature", VN_TNC_SIG, CM_INV}, /* 202 */
  839. #endif /* TN_COMPORT */
  840.     { "rows",      VN_ROWS,  0},        /* 190 */
  841. #ifndef NOSEXP
  842.     { "sdepth",    VN_LSEXP,0},         /* 199 */
  843. #endif /* NOSEXP */
  844.     { "secure",    VN_SECURE, 0},       /* 199 */
  845. #ifndef NOLOCAL
  846. #ifdef OS2
  847.     { "select",    VN_SELCT, 0},        /* 192 */
  848. #endif /* OS2 */
  849. #endif /* NOLOCAL */
  850.     { "sendlist",  VN_SNDL,  0},
  851.     { "serial",    VN_SERIAL,0},        /* 195 */
  852.     { "setlinemsg",VN_SLMSG, 0},        /* 195 */
  853. #ifndef NOSEXP
  854.     { "sexpression",VN_SEXP, 0},        /* 199 */
  855. #endif /* NOSEXP */
  856.     { "speed",     VN_SPEE,  0},
  857. #ifdef OS2
  858.     { "space",     VN_SPA,   0},
  859.     { "startup",   VN_STAR,  0},        /* 190 */
  860. #else
  861. #ifdef UNIX
  862.     { "startup",   VN_STAR,  0},        /* 193 */
  863. #else
  864. #ifdef VMS
  865.     { "startup",   VN_STAR,  0},        /* 193 */
  866. #endif /* VMS */
  867. #endif /* UNIX */
  868. #endif /* OS2 */
  869.     { "status",    VN_SUCC,  0},
  870. #ifndef NOSEXP
  871.     { "svalue",    VN_VSEXP, 0},        /* 199 */
  872. #endif /* NOSEXP */
  873. #ifndef NOXFER
  874.     { "sysid",     VN_SYSI,  0},
  875. #endif /* NOXFER */
  876.     { "system",    VN_SYST,  0},
  877.     { "terminal",  VN_TTYP,  0},
  878. #ifdef OS2
  879. #ifndef NOKVERBS
  880.     { "termkey",   VN_TRMK,  CM_INV},   /* 192 */
  881. #endif /* NOKVERBS */
  882. #endif /* OS2 */
  883.     { "test",      VN_TEST,  0},        /* 193 */
  884.     { "textdir",   VN_TXTDIR,0},        /* 195 */
  885. #ifndef NOXFER
  886.     { "tfsize",    VN_TFC,   0},
  887.     { "tftime",    VN_TFTIM, 0},        /* 195 */
  888. #endif /* NOXFER */
  889.     { "time",      VN_TIME,  0},
  890.     { "timestamp", VN_NOW,   0},        /* 200 */
  891.     { "tmpdir",    VN_TEMP,  0},        /* 192 */
  892. #ifdef CK_TRIGGER
  893.     { "trigger",   VN_TRIG,  0},        /* 193 */
  894. #endif /* CK_TRIGGER */
  895. #ifdef CK_TTYFD
  896.     { "ttyfd",     VN_TTYF,  0},
  897. #endif /* CK_TTYFD */
  898.     { "ty_ln",     VN_TY_LN, 0},        /* 195 */
  899.     { "ty_lc",     VN_TY_LC, 0},        /* 195 */
  900.     { "ty_lm",     VN_TY_LM, 0},        /* 195 */
  901. #ifdef BROWSER
  902.     { "url",       VN_URL,   CM_INV},   /* 193 */
  903. #endif /* BROWSER */
  904.     { "userid",    VN_UID,   0},        /* 192 */
  905.     { "vareval",   VN_VAREVAL, 0},    /* 212 */
  906.     { "version",   VN_VERS,  0},
  907. #ifndef NOXFER
  908.     { "window",    VN_WINDO, 0},        /* 192 */
  909. #endif /* NOXFER */
  910. #ifdef IBMX25
  911.     { "x25local_nua", VN_X25LA, 0},     /* 193 */
  912.     { "x25remote_nua", VN_X25RA, 0},    /* 193 */
  913. #endif /* IBMX25 */
  914. #ifdef CK_SSL
  915.     { "x509_issuer",  VN_X509_I, 0},
  916.     { "x509_subject", VN_X509_S, 0},
  917. #endif /* CK_SSL */
  918. #ifndef NOXFER
  919.     { "xferstatus",VN_XFSTAT,0},        /* 193 */
  920.     { "xfermsg",   VN_XFMSG, 0},        /* 193 */
  921.     { "xfer_badpackets", VN_XF_BC, 0},  /* 195 */
  922.     { "xfer_timeouts",   VN_XF_TM, 0},  /* 195 */
  923.     { "xfer_retransmits",VN_XF_RX, 0},  /* 195 */
  924. #endif /* NOXFER */
  925.     { "xprogram",  VN_XPROG, 0},        /* 193 */
  926.     { "xversion",  VN_XVNUM, 0}         /* 192 */
  927. };
  928. int nvars = (sizeof(vartab) / sizeof(struct keytab));
  929. #endif /* NOSPL */
  930.  
  931. #ifndef NOSPL
  932. struct keytab fnctab[] = {              /* Function names */
  933. #ifdef OS2
  934.     { ".oox",       FN_OOX, CM_INV},    /* ... */
  935. #endif /* OS2 */
  936.  
  937. #ifdef CKCHANNELIO
  938.     { "_eof",       FN_FEOF,   0},
  939.     { "_errmsg",    FN_FERMSG, 0},
  940.     { "_getblock",  FN_FGBLK,  0},
  941.     { "_getchar",   FN_FGCHAR, 0},
  942.     { "_getline",   FN_FGLINE, 0},
  943.     { "_handle",    FN_FILNO,  0},
  944.     { "_line",      FN_NLINE,  0},
  945.     { "_pos",       FN_FPOS,   0},
  946.     { "_putblock",  FN_FPBLK,  0},
  947.     { "_putchar",   FN_FPCHAR, 0},
  948.     { "_putline",   FN_FPLINE, 0},
  949.     { "_status",    FN_FSTAT,  0},
  950. #endif /* CKCHANNELIO */
  951.  
  952.     { "aaconvert",  FN_AADUMP, 0},      /* Associative Array conversion */
  953.     { "absolute",   FN_ABS,  0},        /* Absolute value */
  954. #ifdef TCPSOCKET
  955.     { "addr2name",  FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  956.     { "addrtoname", FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  957. #endif /* TCPSOCKET */
  958.     { "arraylook",  FN_ALOOK,0},        /* Array lookup */
  959.     { "b64decode",  FN_FMB64,0},        /* Base-64 conversion */
  960.     { "b64encode",  FN_TOB64,0},        /* ... */
  961.     { "basename",   FN_BSN,  0},        /* Basename */
  962.     { "break",      FN_BRK,  0},        /* Break (as in Snobol) */
  963.     { "ca",         FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  964.     { "cap",        FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  965.     { "capitalize", FN_CAP,  0},        /* First Letter -> uppercase */
  966.     { "caps",       FN_CAP,  CM_INV},   /* ditto */
  967.     { "character",  FN_CHR,  0},        /* Character from code */
  968.     { "checksum",   FN_CHK,  0},        /* Checksum */
  969.     { "cmdstack",   FN_CMDSTK,0},       /* Command stack */
  970.     { "cmpdates",   FN_CMPDATE,0},      /* Compare dates */
  971.     { "code",       FN_COD,  0},        /* Code from character */
  972. #ifndef NOPUSH
  973.     { "command",    FN_CMD,  0},        /* Output from a command */
  974. #endif /* NOPUSH */
  975.     { "contents",   FN_CON,  0},        /* Definition (contents) of variable */
  976.     { "count",      FN_COUNT, 0},       /* Occurrences of string in string */
  977.     { "crc16",      FN_CRC,  0},        /* CRC-16 */
  978. #ifdef OS2
  979.     { "crypt",      FN_CRY, CM_INV},
  980. #endif /* OS2 */
  981.     { "cvtdate",    FN_DTIM, 0},        /* Convert free date/time to std */
  982. #ifdef ZFCDAT
  983.     { "date",       FN_FD,   0},        /* File modification/creation date */
  984. #endif /* ZFCDAT */
  985.     { "day",        FN_DAY,  0},        /* Day of week */
  986.     { "dayofyear",  FN_JDATE,0},        /* Date to Day of Year */
  987.     { "definition", FN_DEF,  0},        /* Return definition of given macro */
  988.     { "delta2secs", FN_DELSEC, 0},      /* Delta time to seconds */
  989.     { "deltatosecs", FN_DELSEC, CM_INV}, /* Delta time to seconds */
  990. #ifndef NODIAL
  991.     { "dialconvert",FN_PNCVT,0},        /* Convert portable phone number */
  992. #endif /* NODIAL */
  993.     { "diffdates",  FN_DIFDATE,0},      /* Difference of two date-times */
  994.     { "dimension",  FN_DIM,  0},        /* Dimension of array */
  995.     { "dir",        FN_DIR,  CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  996.     { "dire",       FN_DIR,  CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  997.     { "direc",      FN_DIR,  CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  998.     { "direct",     FN_DIR,  CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  999.     { "directo",    FN_DIR,  CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  1000.     { "director",   FN_DIR,  CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  1001.     { "directories",FN_DIR,  0},        /* List of directories */
  1002.     { "directory",  FN_DIR,  CM_INV},        /* List of directories */
  1003.     { "dirname",    FN_DNAM, 0},        /* Directory part of filename */
  1004.     { "dos2unixpath",FN_PC_DU, },       /* DOS to UNIX path */
  1005.     { "dostounixpath",FN_PC_DU, CM_INV}, /* DOS to UNIX path */
  1006.     { "doy",        FN_JDATE,CM_INV},   /* Date to Day of Year */
  1007.     { "doy2date",   FN_DATEJ,0},        /* Day of Year to date */
  1008.     { "doytodate",  FN_DATEJ,CM_INV},   /* Day of Year to date */
  1009.     { "emailaddress",FN_EMAIL, 0},    /* Email address */
  1010. #ifdef FN_ERRMSG
  1011.     { "errstring",  FN_ERRMSG,0},       /* Error code to message */
  1012. #endif /* FN_ERRMSG */
  1013.     { "evaluate",   FN_EVA,  0},        /* Evaluate given arith expression */
  1014.     { "execute",    FN_EXE,  0},        /* Execute given macro */
  1015.     { "files",      FN_FC,   0},        /* File count */
  1016. #ifdef FNFLOAT
  1017.     { "fpabsolute", FN_FPABS, 0},       /* Floating-point absolute value */
  1018.     { "fpadd",      FN_FPADD, 0},       /* FP add */
  1019.     { "fpcosine",   FN_FPCOS, 0},       /* FP cosine */
  1020.     { "fpdivide",   FN_FPDIV, 0},       /* FP divide */
  1021.     { "fpexp",      FN_FPEXP, 0},       /* FP e to the x */
  1022.     { "fpint",      FN_FPINT, 0},       /* FP to integer */
  1023.     { "fplog10",    FN_FPLOG, 0},       /* FP base-10 logarithm */
  1024.     { "fplogn",     FN_FPLN,  0},       /* FP natural logarithm */
  1025.     { "fpmaximum",  FN_FPMAX, 0},       /* FP maxinum */
  1026.     { "fpminimum",  FN_FPMIN, 0},       /* FP mininum */
  1027.     { "fpmodulus",  FN_FPMOD, 0},       /* FP modulus */
  1028.     { "fpmultiply", FN_FPMUL, 0},       /* FP multiply */
  1029.     { "fpraise",    FN_FPPOW, 0},       /* FP raise to a power */
  1030.     { "fpround",    FN_FPROU, 0},       /* FP round */
  1031.     { "fpsine",     FN_FPSIN, 0},       /* FP sine */
  1032.     { "fpsqrt",     FN_FPSQR, 0},       /* FP square root */
  1033.     { "fpsubtract", FN_FPSUB, 0},       /* FP subtract */
  1034.     { "fptangent",  FN_FPTAN, 0},       /* FP tangent */
  1035. #endif /* FNFLOAT */
  1036.     { "function",   FN_FUNC, 0 },       /* Test for existence of a function */
  1037.     { "getpidinfo", FN_PID, 0  },       /* Get PID info */
  1038.     { "hex2ip",     FN_HEX2IP,0},       /* Hex to IP address */
  1039.     { "hextoip",    FN_HEX2IP,CM_INV},  /* Hex to IP address */
  1040.     { "hex2n",      FN_HEX2N, CM_INV},  /* Hex to decimal number */
  1041.     { "hexify",     FN_HEX,   0},       /* Hexify (string) */
  1042.     { "index",      FN_IND,   0},       /* Index (string search) */
  1043.     { "ip2hex",     FN_IP2HEX,0},       /* IP address to hex */
  1044.     { "iptohex",    FN_IP2HEX,CM_INV},  /* IP address to hex */
  1045.     { "ipaddress",  FN_IPA,   0},       /* Find and return IP address */
  1046.     { "jdate",      FN_JDATE, CM_INV},  /* Date to Day of Year */
  1047.     { "join",       FN_JOIN,  0},       /* Join array elements */
  1048.     { "keywordvalue",  FN_KWVAL, 0},    /* Keyword=Value */
  1049. #ifdef CK_KERBEROS
  1050.     { "krbflags",      FN_KRB_FG, 0},   /* Kerberos functions */
  1051.     { "krbisvalid",    FN_KRB_IV, 0},
  1052.     { "krbnextticket", FN_KRB_NX, 0},
  1053.     { "krbtickets",    FN_KRB_TK, 0},
  1054.     { "krbtimeleft",   FN_KRB_TT, 0},
  1055. #endif /* CK_KERBEROS */
  1056.     { "kwvalue",    FN_KWVAL, CM_INV},    /* Keyword=Value */
  1057.     { "left",       FN_LEF,  0},        /* Leftmost n characters of string */
  1058.     { "length",     FN_LEN,  0},        /* Return length of argument */
  1059.     { "literal",    FN_LIT,  0},        /* Return argument literally */
  1060. #ifdef NT
  1061.     { "longpathname",FN_LNAME,0},    /* GetLongPathName() */
  1062. #else
  1063.     { "longpathname",FN_FFN,CM_INV},
  1064. #endif /* NT */
  1065.     { "lop",        FN_STL,  0},        /* Lop */
  1066.     { "lopx",       FN_LOPX, 0},        /* Lopx */
  1067.     { "lower",      FN_LOW,  0},        /* Return lowercased argument */
  1068.     { "lpad",       FN_LPA,  0},        /* Return left-padded argument */
  1069.     { "ltrim",      FN_LTR,  0},        /* Left-Trim */
  1070.     { "maximum",    FN_MAX,  0},        /* Return maximum of two arguments */
  1071.     { "minimum",    FN_MIN,  0},        /* Return minimum of two arguments */
  1072.     { "mjd",        FN_MJD,  0},        /* Date to Modified Julian Date */
  1073.     { "mjd2date",   FN_MJD2, 0},        /* MJD to Date */
  1074.     { "mjdtodate",  FN_MJD2, CM_INV},   /* MJD to Date */
  1075.     { "modulus",    FN_MOD,  0},        /* Return modulus of two arguments */
  1076. #ifdef COMMENT
  1077.     { "msleep",     FN_MSLEEP,0},       /* Sleep for n milliseconds */
  1078. #endif /* COMMENT */
  1079.     { "n2hex",      FN_2HEX, CM_INV},   /* Number to hex */
  1080.     { "n2octal",    FN_2OCT, CM_INV},   /* Number to octal */
  1081.     { "n2time",     FN_N2TIM,0},        /* Number to hh:mm:ss */
  1082. #ifdef TCPSOCKET
  1083.     { "name2addr",  FN_HSTNAM,CM_INV},  /* Hostname to IP Address */
  1084. #endif /* TCPSOCKET */
  1085.     { "nday",       FN_NDAY, 0},        /* Numeric day of week */
  1086.     { "nextfile",   FN_FIL,  0},        /* Next file in list */
  1087.     { "ntime",      FN_NTIM, 0},        /* Time to seconds since midnight */
  1088.     { "ntohex",     FN_2HEX, CM_INV},   /* Number to hex */
  1089.     { "ntooctal",   FN_2OCT, CM_INV},   /* Number to octal */
  1090.     { "ntotime",    FN_N2TIM,CM_INV},   /* Number to hh:mm:ss */
  1091.     { "oct2n",      FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1092.     { "octton",     FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1093.     { "pathname",   FN_FFN,  0},        /* Full file name */
  1094.     { "pattern",    FN_PATTERN, 0},     /* Pattern (for INPUT) */
  1095. #ifdef CK_PERMS
  1096.     { "permissions",FN_PERM, 0},        /* Permissions of file */
  1097. #else
  1098.     { "permissions",FN_PERM, CM_INV},   /* Permissions of file */
  1099. #endif /* CK_PERMS */
  1100.     { "pictureinfo",FN_PICTURE, 0 },    /* Picture orientation/dimensions */
  1101.     { "radix",      FN_RADIX, 0 },    /* Radix conversion */
  1102. #ifndef NORANDOM
  1103.     { "random",     FN_RAND, 0},        /* Random number */
  1104. #endif /* NORANDOM */
  1105. #ifndef NOPUSH
  1106.     { "rawcommand", FN_RAW,  0},        /* Output from a command (raw) */
  1107. #endif /* NOPUSH */
  1108. #ifdef RECURSIVE
  1109.     { "rdirectories", FN_RDIR, 0},      /* Recursive directory list */
  1110. #endif /* RECURSIVE */
  1111.     { "recurse",    FN_RECURSE, 0},    /* Recursive variable evaluation */
  1112. #ifdef RECURSIVE
  1113.     { "rfiles",       FN_RFIL, 0},      /* Recursive file list */
  1114. #endif /* RECURSIVE */
  1115.     { "rep",        FN_REP, CM_INV|CM_ABR},
  1116.     { "repeat",     FN_REP,  0},        /* Repeat argument given # of times */
  1117.     { "replace",    FN_RPL,  0},        /* Replace characters in string */
  1118.     { "reverse",    FN_REV,  0},        /* Reverse the argument string */
  1119.     { "right",      FN_RIG,  0},        /* Rightmost n characters of string */
  1120.     { "rindex",     FN_RIX,  0},        /* Right index */
  1121.     { "rpad",       FN_RPA,  0},        /* Right-pad the argument */
  1122.     { "rsearch",    FN_RSEARCH, 0},     /* R-L Search for pattern in string */
  1123. #ifdef OS2
  1124.     { "scrncurx",   FN_SCRN_CX,  0},    /* Screen Cursor X Pos */
  1125.     { "scrncury",   FN_SCRN_CY,  0},    /* Screen Cursor Y Pos */
  1126.     { "scrnstr",    FN_SCRN_STR, 0},    /* Screen String */
  1127. #endif /* OS2 */
  1128.     { "search",     FN_SEARCH, 0},      /* L-R Search for pattern in string */
  1129. #ifndef NOSEXP
  1130.     { "sexpression",FN_SEXP, 0},        /* S-Expression */
  1131. #endif /* NOSEXP */
  1132. #ifdef NT
  1133.     { "shortpathname",FN_SNAME,0},    /* GetShortPathName() */
  1134. #else
  1135.     { "shortpathname",FN_FFN,CM_INV},
  1136. #endif /* NT */
  1137.     { "size",       FN_FS,   0},        /* File size */
  1138. #ifdef COMMENT
  1139.     { "sleep",      FN_SLEEP,0},        /* Sleep for n seconds */
  1140. #endif /* COMMENT */
  1141.     { "span",       FN_SPN,  0},        /* Span - like Snobol */
  1142.     { "split",      FN_SPLIT,0},        /* Split string into words */
  1143.     { "squeeze",    FN_SQUEEZE,0},        /* Squeeze whitespace in string */
  1144.     { "stripb",     FN_STB,  0},        /* Strip enclosing braces/brackets */
  1145.     { "stripn",     FN_STN,  0},        /* Strip n chars */
  1146.     { "stripx",     FN_STX,  0},        /* Strip suffix */
  1147.     { "su",         FN_SUB,  CM_INV|CM_ABR},
  1148.     { "sub",        FN_SUB,  CM_INV|CM_ABR},
  1149.     { "subs",       FN_SUB,  CM_INV|CM_ABR},
  1150.     { "subst",      FN_SUB,  CM_INV|CM_ABR},
  1151.     { "substitute", FN_SUBST,0},        /* Substitute chars */
  1152.     { "substring",  FN_SUB,  0},        /* Extract substring from argument */
  1153.     { "tablelook",  FN_TLOOK,0},        /* Table lookup */
  1154.     { "time",       FN_TIME, 0},        /* Free-format time to hh:mm:ss */
  1155.     { "tod2secs",   FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1156.     { "todtosecs",  FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1157.     { "trim",       FN_TRM,  0},        /* Trim */
  1158.     { "unhexify",   FN_UNH,  0},        /* Unhexify */
  1159.     { "unix2dospath",FN_PC_UD, 0},      /* UNIX to DOS path */
  1160.     { "unixtodospath",FN_PC_UD, CM_INV}, /* UNIX to DOS path */
  1161.     { "untabify",   FN_UNTAB,0},        /* Untabify */
  1162.     { "upper",      FN_UPP,  0},        /* Return uppercased argument */
  1163.     { "utcdate",    FN_TOGMT,0},        /* Date-time to UTC (GMT) */
  1164.     { "verify",     FN_VER,  0},        /* Verify */
  1165.     { "word",       FN_WORD, 0},        /* Extract a word */
  1166.     { "", 0, 0}
  1167. };
  1168. int nfuncs = (sizeof(fnctab) / sizeof(struct keytab)) - 1;
  1169. #endif /* NOSPL */
  1170.  
  1171. #ifndef NOSPL                           /* Buffer for expansion of */
  1172. #ifdef BIGBUFOK                         /* built-in variables. */
  1173. #define VVBUFL 1024
  1174. #else
  1175. #define VVBUFL 256
  1176. #endif /* BIGBUFOK */
  1177. char vvbuf[VVBUFL+1];
  1178. #endif /* NOSPL */
  1179.  
  1180. struct keytab disptb[] = {              /* Log file disposition */
  1181.     { "append",    1,  0},
  1182.     { "new",       0,  0}
  1183. };
  1184.  
  1185. #ifdef CKFLOAT
  1186.  
  1187. /* I N I T F L O A T  --  Deduce floating-point precision by inspection */
  1188.  
  1189. int fp_rounding = 0;                /* Nonzero if printf("%f") rounds */
  1190. int fp_digits = 0;                  /* Digits of floating point precision */
  1191.  
  1192. #ifdef COMMENT
  1193. /* For looking at internal floating-point representations */
  1194. static char fp_xbuf[128];
  1195. static char *
  1196. tohex(s, n) CHAR * s; int n; {
  1197.     int x;
  1198.     char * p = fp_xbuf;
  1199.     while (n-- > 0) {
  1200.         x = (*s >> 4) & 0x0f;
  1201.         *p++ = hexdigits[x];
  1202.         x = *s++ & 0x0f;
  1203.         *p++ = hexdigits[x];
  1204.     }
  1205.     *p = NUL;
  1206.     return((char *)fp_xbuf);
  1207. }
  1208. #endif /* COMMENT */
  1209.  
  1210. char math_pi[] = "3.1415926535897932384626433832795";
  1211. char math_e[] =  "2.7182818284590452353602874713527";
  1212.  
  1213. VOID
  1214. initfloat() {
  1215.     char * buf = NULL;
  1216.     int i, x, y;
  1217. /*
  1218.   We malloc a big temporary buffer for sprintf() to minimize likelihood of
  1219.   (and damage from) sprintf buffer overflows.  In any case, the only way this
  1220.   could happen would be if sprintf() itself had bugs, since the format
  1221.   descriptor says to cut it off at 250 decimal places.
  1222. */
  1223.     if ((buf = (char *)malloc(4096))) {
  1224.         sprintf(buf,"%0.250f",(10.0 / 3.0));
  1225.         for (i = 2; i < 250 && buf[i] == '3'; i++) ;
  1226.         x = i - 1;
  1227.         debug(F111,"initfloat 10.0/3.0",buf,x);
  1228.         sprintf(buf,"%0.250f",(4.0 / 9.0));
  1229.         for (i = 2; i < 250 && buf[i] == '4'; i++) ;
  1230.         y = i - 1;
  1231.         debug(F111,"initfloat 4.0/9.0",buf,y);
  1232.         fp_digits = (x < y) ? x : y;
  1233.         if (fp_digits < sizeof(math_pi) - 1) {
  1234.             math_pi[fp_digits+1] = NUL;
  1235.             math_e[fp_digits+1] = NUL;
  1236.         }
  1237.         sprintf(buf,"%0.6f",(7.0 / 9.0));
  1238.         if (buf[7] == '8') fp_rounding = 1;
  1239.         debug(F111,"initfloat 7.0/9.0",buf,fp_rounding);
  1240.         debug(F101,"initfloat precision","",fp_digits);
  1241.         free(buf);
  1242.     }
  1243. }
  1244. #endif /* CKFLOAT */
  1245.  
  1246. /*
  1247.   P R E S C A N -- A quick look through the command-line options for
  1248.   items that must be handled before the initialization file is executed.
  1249. */
  1250. #ifdef NT
  1251. extern int StartedFromDialer;
  1252. #endif /* NT */
  1253. #ifdef OS2
  1254. extern int k95stdio;
  1255. unsigned long startflags = 0L;
  1256. #endif /* OS2 */
  1257.  
  1258. static char *
  1259. findinpath(arg) char * arg; {
  1260. #ifdef OS2
  1261.     char * scriptenv, * keymapenv;
  1262.     int len;
  1263. #endif /* OS2 */
  1264. #ifdef DCMDBUF
  1265.     extern char * cmdbuf;
  1266. #else
  1267.     extern char cmdbuf[];
  1268. #endif /* DCMDBUF */
  1269.     char takepath[4096];
  1270.     char * s;
  1271.     int x, z;
  1272.  
  1273.     /* Set up search path... */
  1274. #ifdef OS2
  1275.     char * appdata0 = NULL, *appdata1 = NULL;
  1276. #ifdef NT
  1277.     scriptenv = getenv("K95SCRIPTS");
  1278.     keymapenv = getenv("K95KEYMAPS");
  1279.     makestr(&appdata0,(char *)GetAppData(0));
  1280.     makestr(&appdata1,(char *)GetAppData(1));
  1281. #else /* NT */
  1282.     scriptenv = getenv("K2SCRIPTS");
  1283.     keymapenv = getenv("K2KEYMAPS");
  1284. #endif /* NT */
  1285.     if (!scriptenv)
  1286.       scriptenv = getenv("CK_SCRIPTS");
  1287.     if (!scriptenv)
  1288.       scriptenv = "";
  1289.     if (!keymapenv)
  1290.       keymapenv = getenv("CK_KEYMAPS");
  1291.     if (!keymapenv)
  1292.       keymapenv = "";
  1293.  
  1294.     debug(F110,"startupdir",startupdir,0);
  1295.     debug(F110,"common appdata directory",appdata1,0);
  1296.     debug(F110,"appdata directory",appdata0,0);
  1297.     debug(F110,"inidir",inidir,0);
  1298.     debug(F110,"home",zhome(),0);
  1299.     debug(F110,"exedir",exedir,0);
  1300.  
  1301.     len = strlen(scriptenv) + strlen(keymapenv) + 3*strlen(startupdir)
  1302.         + 3*strlen(inidir) + 3*strlen(zhome()) + 3*strlen(exedir)
  1303.         + (appdata0 ? 3*strlen(appdata0) : 0) 
  1304.         + (appdata1 ? 3*strlen(appdata1) : 0)
  1305.         + 6*strlen("SCRIPTS/") + 6*strlen("KEYMAPS/") + 16;
  1306.  
  1307.     if (len >= 4096) {                  /* SAFE (length is checked) */
  1308.         takepath[0] = '\0';
  1309.         debug(F111,"findinpath error - path length too long","len",len);
  1310.     } else
  1311.       sprintf(takepath,
  1312.               /* semicolon-separated path list */
  1313.     "%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",
  1314.               scriptenv,
  1315.               (scriptenv[0] && scriptenv[strlen(scriptenv)-1]==';')?"":";",
  1316.               keymapenv,
  1317.               (keymapenv[0] && keymapenv[strlen(keymapenv)-1]==';')?"":";",
  1318.               startupdir,
  1319.               startupdir, "SCRIPTS/",
  1320.               startupdir, "KEYMAPS/",
  1321.               appdata1 ? appdata1 : "", 
  1322.               appdata1 ? "Kermit 95;" : "",
  1323.               appdata1 ? appdata1 : "",
  1324.               appdata1 ? "Kermit 95/SCRIPTS/;" : "",
  1325.               appdata1 ? appdata1 : "",
  1326.               appdata1 ? "Kermit 95/KEYMAPS/;" : "",
  1327.               appdata0 ? appdata0 : "",
  1328.               appdata0 ? "Kermit 95;" : "",
  1329.               appdata0 ? appdata0 : "",
  1330.               appdata0 ? "Kermit 95/SCRIPTS/;" : "",
  1331.               appdata0 ? appdata0 : "",
  1332.               appdata0 ? "Kermit 95/KEYMAPS/;" : "",
  1333.               inidir,
  1334.               inidir, "SCRIPTS/",
  1335.               inidir, "KEYMAPS/",
  1336.               zhome(),
  1337.               zhome(), "SCRIPTS/",
  1338.               zhome(), "KEYMAPS/",
  1339.               exedir,
  1340.               exedir, "SCRIPTS/",
  1341.               exedir, "KEYMAPS/"
  1342.               );
  1343.     debug(F110,"findinpath takepath",takepath,0);
  1344. #ifdef NT
  1345.     makestr(&appdata0,NULL);
  1346.     makestr(&appdata1,NULL);
  1347. #endif /* NT */
  1348. #else /* not OS2 */
  1349. #ifndef NOSPL
  1350.     z = 1024;                           /* Look in home directory */
  1351.     s = takepath;
  1352.     zzstring("\\v(home)",&s,&z);
  1353. #else
  1354.     takepath[0] = '\0';
  1355. #endif /* NOSPL */
  1356. #endif /* OS2 */
  1357. /*
  1358.   All the logic for searching the take path is in the command parser.
  1359.   So even though we aren't parsing commands, we initialize and call the
  1360.   parser from here, with the purported filename stuffed into the command
  1361.   buffer, followed by some carriage returns to make the parser return.
  1362.   If the file is not found, or otherwise not accessible, the parser prints
  1363.   an appropriate message, and then we just exit.
  1364. */
  1365.     cmdini();                           /* Allocate command buffers etc */
  1366.     cmini(0);                           /* Initialize them */
  1367.     /* Stuff filename into command buf with braces in case of spaces */
  1368.     ckmakmsg(cmdbuf,CMDBL,"{",arg,"}",NULL);
  1369.     debug(F110,"findinpath cmdbuf",cmdbuf,0);
  1370.     ckstrncat(cmdbuf,"\r\r",CMDBL);     /* And some carriage returns */
  1371.     if (cmifip("","",&s,&x,0,takepath,xxstring) < 0)
  1372.       return(NULL);
  1373.     cmres();
  1374.     return(s);
  1375. }
  1376.  
  1377. static int tr_int;                      /* Flag if TRANSMIT interrupted */
  1378.  
  1379. #ifndef MAC
  1380. SIGTYP
  1381. #ifdef CK_ANSIC
  1382. trtrap(int foo)                         /* TRANSMIT interrupt trap */
  1383. #else
  1384. trtrap(foo) int foo;                    /* TRANSMIT interrupt trap */
  1385. #endif /* CK_ANSIC */
  1386. /* trtrap */ {
  1387. #ifdef __EMX__
  1388.     signal(SIGINT, SIG_ACK);
  1389. #endif
  1390.     tr_int = 1;                         /* (Need arg for ANSI C) */
  1391.     SIGRETURN;
  1392. }
  1393. #endif /* MAC */
  1394. #endif /* NOICP */
  1395.  
  1396. #ifdef UNIX
  1397. VOID
  1398. getexedir() {
  1399.     extern char * xarg0;
  1400.     long xx;
  1401.   /*
  1402.     Unix provides no standard service for this.  We look in argv[0], and if
  1403.     we're lucky there's a full pathname.  If not we do a PATH search.
  1404.   */
  1405.     if (ckstrchr(xarg0,'/')) {          /* Global copy of argv[0] */
  1406.         int i, k;
  1407.         char * p = NULL;
  1408.         if ((k = ckstrncpy(tmpbuf,xarg0,TMPBUFSIZ-2)) > 0) {
  1409.             p = tmpbuf;
  1410.             /* Convert to fully qualified pathname */
  1411.             if (tmpbuf[0]) if (tmpbuf[0] != '/') {
  1412.                 line[0] = NUL;
  1413.                 zfnqfp(tmpbuf,LINBUFSIZ-2,(char *)line);
  1414.                 if (line[0])
  1415.                   p = line;
  1416.             }
  1417.             xx = zchki(p);
  1418.             if (xx > -1) {        /* Is the result an existing file? */
  1419.                 k = strlen(p);
  1420.                 for (i = k-1; i > 0; i--) { /* Yes, strip name part */
  1421.                     if (p[i] == '/') {
  1422.                         if (i < k-1)
  1423.                           p[i+1] = NUL;
  1424.                         break;
  1425.                     }
  1426.                 }
  1427.             }
  1428.         makestr(&exedir,p);        /* Save the result */
  1429.         }
  1430.     }
  1431.     if (!exedir && xarg0) {             /* Not found? */
  1432.         char * p;
  1433.         p = getenv("PATH");             /* Search the PATH */
  1434.         if (p) {                        /* If there is one... */
  1435.             char * q, * PATH = NULL;
  1436.             int k;
  1437.             makestr(&PATH,p);           /* Pokeable copy of PATH string */
  1438.             if (PATH) {                 /* If malloc succeeded... */
  1439.                 p = PATH;
  1440.                 while (p && *p) {        /* Loop through segments */
  1441.                     q = ckstrchr(p,':'); /* End of this segment */
  1442.                     if (q == p) {       /* Null PATH segment */
  1443.                         p++;            /* Skip over colon */
  1444.                         continue;
  1445.                     }
  1446.                     if (q)              /* If not at end of PATH string */
  1447.                       *q++ = NUL;       /* zero out the colon */
  1448.                     if ((k = ckstrncpy(tmpbuf,p,TMPBUFSIZ)) > 0) {
  1449.                         if (tmpbuf[k-1] != '/') { /* Copy this PATH segment */
  1450.                             tmpbuf[k++] = '/';    /* Append '/' if needed */
  1451.                             tmpbuf[k] = NUL;
  1452.                         }
  1453.                         /* Append the argv[0] value */
  1454.                         if (ckstrncpy(&tmpbuf[k],xarg0,TMPBUFSIZ) > 0) {
  1455.                             if (zchki(tmpbuf) > -1) { /* File exists? */
  1456.                                 tmpbuf[k] = NUL;      /* Yes, we're done */
  1457.                                 zfnqfp(tmpbuf,LINBUFSIZ,(char *)line);
  1458.                                 makestr(&exedir,line);
  1459.                                 break;
  1460.                             }
  1461.                         } else break;
  1462.                     } else break;
  1463.                     p = q;              /* Not found, go to next segment  */
  1464.                 } /* while */
  1465.                 free(PATH);             /* Free PATH copy */
  1466.             }
  1467.         }
  1468.         if (!exedir) {                  /* Still nothing? */
  1469.             if (zchki(xarg0) > -1) {    /* Maybe it's in the current dir */
  1470.                 zfnqfp(zgtdir(),LINBUFSIZ,(char *)line);
  1471.                 makestr(&exedir,line);
  1472.             }
  1473.         }
  1474.     }
  1475.     if (!exedir) {                      /* Still nothing? */
  1476.         makestr(&exedir,"/");           /* Fake it with with root. */
  1477.     }
  1478. }
  1479. #endif /* UNIX */
  1480.  
  1481. int arg_x = 0;
  1482. static int x_prescan = 0;
  1483.  
  1484. /*
  1485.   The argument y once meant something but I can't imagine what so now
  1486.   it's ignored.  (Prior to 22 Aug 98, prescan() was called twice by main(),
  1487.   and the arg differentiated the two calls.  But this caused all sorts of
  1488.   problems & confusion, so I commented out the second call.  This issue might
  1489.   need to be revisited.)
  1490. */
  1491. VOID
  1492. prescan(dummy) int dummy; {             /* Arg is ignored. */
  1493.     extern int howcalled;
  1494.     int yargc; char **yargv;
  1495.     char x;
  1496.     char *yp, *yy;
  1497. #ifdef DEBUG
  1498.     int debcount = 0;
  1499. #endif /* DEBUG */
  1500.     int z;
  1501.  
  1502.     if (x_prescan)                      /* Only run once */
  1503.       return;
  1504.     x_prescan = 1;
  1505.  
  1506.     yargc = xargc;                      /* Make copy of arg vector */
  1507.     yargv = xargv;
  1508.  
  1509. #ifndef NOICP
  1510. #ifdef DCMDBUF
  1511.     if (!kermrc)
  1512.       if (!(kermrc = (char *) malloc(KERMRCL+1)))
  1513.         fatal("prescan: no memory for kermrc");
  1514. #endif /* DCMDBUF */
  1515.     ckstrncpy(kermrc,KERMRC,KERMRCL);   /* Default init file name */
  1516. #endif /* NOICP */
  1517.  
  1518. #ifdef OS2
  1519.     yp = getenv("K95STARTFLAGS");
  1520.     if (yp) {
  1521.         startflags = atoi(yp);
  1522.     }
  1523. #endif /* OS2 */
  1524.  
  1525. #ifdef IKSD
  1526.     if (howcalled == I_AM_IKSD)         /* Internet Kermit Service daemon */
  1527.       inserver = 1;                     /* (See inserver section of ckcmai) */
  1528. #endif /* IKSD */
  1529.  
  1530. /* Command line options for Kermit */
  1531.  
  1532. #ifndef NOCMDL
  1533.     if (yargc > 1
  1534.         && *yargv[1] != '-'
  1535.         && (yargv[1][0] != '=')
  1536. #ifdef KERBANG
  1537.         && (yargv[1][0] != '+')
  1538. #endif /* KERBANG */
  1539. #ifdef IKSD
  1540.         && (howcalled != I_AM_IKSD)
  1541. #endif /* IKSD */
  1542.         ) {                             /* Filename as 1st argument */
  1543. #ifndef NOICP
  1544.         char *s;
  1545. #endif /* NOICP */
  1546. #ifndef NOURL
  1547.         extern int haveurl;
  1548.         extern struct urldata g_url;
  1549.         if (urlparse(yargv[1],&g_url)) {
  1550.             if (!ckstrcmp(g_url.svc,"ftp",-1,0) ||
  1551.                 !ckstrcmp(g_url.svc,"ftps",-1,0)) {
  1552.                 haveurl = 1;
  1553.                 howcalled = I_AM_FTP;
  1554.             } else if (!ckstrcmp(g_url.svc,"telnet",-1,0) ||
  1555.                        !ckstrcmp(g_url.svc,"telnets",-1,0)) {
  1556.                 haveurl = 1;
  1557.                 howcalled = I_AM_TELNET;
  1558.             } else if (!ckstrcmp(g_url.svc,"ssh",-1,0)) {
  1559.                 haveurl = 1;
  1560.                 howcalled = I_AM_SSH;
  1561.             } else if (!ckstrcmp(g_url.svc,"iksd",-1,0) ||
  1562.                        !ckstrcmp(g_url.svc,"kermit",-1,0)) {
  1563.                 haveurl = 1;
  1564.                 howcalled = I_AM_KERMIT;
  1565.             } else if (!ckstrcmp(g_url.svc,"http",-1,0) ||
  1566.                        !ckstrcmp(g_url.svc,"https",-1,0)) {
  1567.                 haveurl = 1;
  1568.                 howcalled = I_AM_HTTP;
  1569.             }
  1570.             if (haveurl) {
  1571.                 while (--yargc > 0) {   /* Go through command-line args */
  1572.                     yargv++;            /* looking for -Y and -d */
  1573.                     yp = *yargv+1;
  1574.                     if (**yargv == '-') {
  1575.                         x = *(*yargv+1);
  1576.                         while (x) {
  1577.                             switch (x) {
  1578. #ifndef NOICP
  1579.                   case '+':
  1580.                   case '-':
  1581.                                 if (doxarg(yargv,1) < 0) {
  1582.                                     fatal("Extended argument error");
  1583.                                 }
  1584.                                 yp = "";
  1585.                                 break;
  1586. #endif /* NOICP */
  1587.                               case 'Y':
  1588.                                 noinit++;
  1589.                                 break;
  1590.  
  1591.                               case 'q':
  1592.                                 quiet = 1;
  1593.                                 break;
  1594.  
  1595.                               case 'h':
  1596.                                   noinit = 1;
  1597. #ifdef OS2
  1598.                                   startflags |= 2;    /* No network DLLs */
  1599.                                   startflags |= 4;    /* No TAPI DLLs */
  1600.                                   startflags |= 8;    /* No Security DLLs */
  1601.                                   startflags |= 16;   /* No Zmodem DLLs */
  1602.                                   startflags |= 32;   /* Stdin */
  1603.                                   startflags |= 64;   /* Stdout */
  1604. #endif /* OS2 */
  1605.                                   break;
  1606.                               case 'd': /* = SET DEBUG ON */
  1607. #ifdef DEBUG
  1608.                                 if (debcount++ > 0)
  1609.                                   debtim = 1;
  1610.                                 if (!deblog)
  1611.                                   deblog = debopn("debug.log",0);
  1612. #endif /* DEBUG */
  1613.                                 break;
  1614. #ifdef OS2
  1615.                               case 'W':
  1616.                                 if (*(yp+1))
  1617.                                   fatal("invalid argument bundling after -W");
  1618.                                 yargv++, yargc--;
  1619.                                 if (yargc < 1)
  1620.                                   fatal("Window handle missing");
  1621.                                 hwndDialer = (HWND) atol(*yargv);
  1622.                                 StartedFromDialer = 1;
  1623.                                 yargv++, yargc--;
  1624.                                 KermitDialerID = atol(*yargv) ;
  1625.                                 break;
  1626.                               case '#': /* K95 initialization options */
  1627.                                 if (*(yp+1)) {
  1628.                                     fatal("invalid argument bundling");
  1629.                                 }
  1630.                                 yargv++, yargc--;
  1631.                                 if (yargc < 1)
  1632.                                   fatal("-# argument missing");
  1633.                                 startflags |= atol(*yargv);
  1634.                                 break;
  1635. #endif /* OS2 */
  1636.                             }
  1637.                             if (!yp)
  1638.                               break;
  1639.                             x = *++yp;
  1640.                         }
  1641.                     }
  1642.                 }
  1643.                 return;
  1644.             }
  1645.         }
  1646.         /* after this point non-Kermit personalities must return */
  1647.         switch (howcalled) {
  1648.       case I_AM_KERMIT:
  1649.       case I_AM_IKSD:
  1650.       case I_AM_SSHSUB:
  1651.             break;
  1652.       default:
  1653.             return;
  1654.         }
  1655. #endif /* NOURL */
  1656.  
  1657. #ifndef NOICP
  1658.         /* If it is not a URL that we recognize, try to treat it as a file */
  1659.  
  1660.         if (!isabsolute(yargv[1]))      /* If not absolute */
  1661.           s = findinpath(yargv[1]);     /* Look in PATH */
  1662.         else
  1663.           s = yargv[1];
  1664.         if (!s)
  1665.           doexit(BAD_EXIT,xitsta);
  1666.         zfnqfp(s,CKMAXPATH,cmdfil);     /* In case of CD in file */
  1667.         yargc -= 1;                     /* Skip past the filename */
  1668.         yargv += 1;                     /* Otherwise we'll get an error */
  1669. #endif /* NOICP */
  1670.     }
  1671.  
  1672. #ifndef NOCMDL
  1673. #ifdef NEWFTP
  1674.     if (howcalled == I_AM_FTP) {        /* Kermit's FTP client personality */
  1675.         while (--yargc > 0) {           /* Go through command-line args */
  1676.             yargv++;                    /* looking for -Y and -d */
  1677.             yp = *yargv+1;
  1678.             if (**yargv == '-') {
  1679.                 x = *(*yargv+1);
  1680.                 while (x) {
  1681.                     switch (x) {
  1682. #ifndef NOICP
  1683.               case '+':
  1684.               case '-':
  1685.                         if (doxarg(yargv,1) < 0) {
  1686.                             fatal("Extended argument error");
  1687.                         }
  1688.                         yp = "";
  1689.                         break;
  1690. #endif /* NOICP */
  1691.                       case 'Y':
  1692.                         noinit++;
  1693.                         break;
  1694.  
  1695.                       case 'q':
  1696.                           quiet = 1;
  1697.                           break;
  1698.  
  1699.                       case 'h':
  1700.                         noinit = 1;
  1701. #ifdef OS2
  1702.                         startflags |= 2;    /* No network DLLs */
  1703.                         startflags |= 4;    /* No TAPI DLLs */
  1704.                         startflags |= 8;    /* No Security DLLs */
  1705.                         startflags |= 16;   /* No Zmodem DLLs */
  1706.                         startflags |= 32;   /* Stdin */
  1707.                         startflags |= 64;   /* Stdout */
  1708. #endif /* OS2 */
  1709.                         break;
  1710.                       case 'd':             /* = SET DEBUG ON */
  1711. #ifdef DEBUG
  1712.                         if (debcount++ > 0)
  1713.                           debtim = 1;
  1714.                         if (!deblog)
  1715.                           deblog = debopn("debug.log",0);
  1716. #endif /* DEBUG */
  1717.                         break;
  1718. #ifdef OS2
  1719.                       case 'W':
  1720.                         if (*(yp+1))
  1721.                           fatal("invalid argument bundling after -W");
  1722.                         yargv++, yargc--;
  1723.                         if (yargc < 1)
  1724.                           fatal("Window handle missing");
  1725.                         hwndDialer = (HWND) atol(*yargv);
  1726.                         StartedFromDialer = 1;
  1727.                         yargv++, yargc--;
  1728.                         KermitDialerID = atol(*yargv) ;
  1729.                         break;
  1730.                       case '#':         /* K95 initialization options */
  1731.                         if (*(yp+1)) {
  1732.                             fatal("invalid argument bundling");
  1733.                         }
  1734.                         yargv++, yargc--;
  1735.                         if (yargc < 1)
  1736.                           fatal("-# argument missing");
  1737.                         startflags |= atol(*yargv);
  1738.                         break;
  1739. #endif /* OS2 */
  1740.                     }
  1741.                     if (!yp)
  1742.                       break;
  1743.                     x = *++yp;
  1744.                 }
  1745.             }
  1746.         }
  1747.         return;
  1748.     }
  1749. #endif /* NEWFTP */
  1750. #endif /* NOCMDL */
  1751.  
  1752.     while (--yargc > 0) {               /* Go through command-line args */
  1753.         yargv++;
  1754.         yp = *yargv+1;                  /* Pointer for bundled args */
  1755.         if (**yargv == '=')             /* Same rules as cmdlin()... */
  1756.           return;
  1757.         debug(F110,"prescan *yargv",*yargv,0);
  1758.  
  1759. #ifndef NOICP
  1760. #ifdef KERBANG
  1761.         yy = *yargv;
  1762.         if (!strcmp(yy,"+") || (*yy == '+' && *(yy+1) < (char)33)) {
  1763.             char * s;
  1764.             yargv++;
  1765.             noinit = 1;
  1766.             if (!*yargv)
  1767.               return;
  1768.             cfilef = 1;
  1769.             s = findinpath(*yargv);
  1770.             if (s) {
  1771.                 zfnqfp(s,CKMAXPATH,cmdfil);
  1772.                 return;
  1773.             } else
  1774.               doexit(BAD_EXIT,xitsta);
  1775.         }
  1776. #endif /* KERBANG */
  1777. #endif /* NOICP */
  1778.         if (!strcmp(*yargv,"--"))       /* getopt() conformance */
  1779.           return;
  1780. #ifdef VMS
  1781.         else if (**yargv == '/')
  1782.           continue;
  1783. #endif /* VMS */
  1784.         else if (**yargv == '-') {      /* Got an option (begins with dash) */
  1785.             x = *(*yargv+1);            /* Get option letter */
  1786.             while (x) {                 /* Allow for bundled options */
  1787.                 debug(F000,"prescan arg","",x);
  1788.                 switch (x) {
  1789. #ifndef NOICP
  1790.                   case '+':
  1791.                   case '-':
  1792.                     if (doxarg(yargv,1) < 0) {
  1793.                         fatal("Extended argument error");
  1794.                     }
  1795. #ifndef COMMENT                /* Jeff 28 Apr 2003 */
  1796.                     yp = NULL;        /* (not "") */
  1797. #else
  1798.                     yargv++, yargc--;
  1799.                     yp = *yargv;
  1800. #endif /* COMMENT */
  1801.                     break;
  1802. #endif /* NOICP */
  1803.  
  1804.                   case '7':             /* Undocumented... */
  1805.                     sstelnet = 1;       /* (because it doesn't work) */
  1806.                     break;
  1807. #ifdef IKSD
  1808.                   case 'A': {
  1809.                       char * p;
  1810.                       inserver = 1;     /* Flag that we are doing this */
  1811.                       srvcdmsg = 2;     /* Preset this */
  1812.                       /* See inserver section of ckcmai.c for more settings */
  1813. #ifdef OS2
  1814.                       if (*(yp+1)) {
  1815.                           fatal("invalid argument bundling after -A");
  1816.                       }
  1817. #ifdef NT
  1818.                       /* Support for Pragma Systems Telnet/Terminal Servers */
  1819.                       p = getenv("PRAGMASYS_INETD_SOCK");
  1820.                       if (p && atoi(p) != 0) {
  1821.                           ttname[0] = '$';
  1822.                           ckstrncpy(&ttname[1],p,TTNAMLEN-1);
  1823.                           break;
  1824.                       }
  1825. #endif /* NT */
  1826.                       yargv++, yargc--;
  1827.                       if (yargc < 1 || **yargv == '-') {
  1828.                           fatal("-A argument missing");
  1829.                       } else {
  1830.                           ttname[0] = '$';
  1831.                           ckstrncpy(&ttname[1],*yargv,TTNAMLEN-1);
  1832.                       }
  1833. #endif /* OS2 */
  1834.                       break;
  1835.                   }
  1836. #endif /* IKSD */
  1837.  
  1838. #ifdef OS2
  1839.                   case 'W':
  1840.                     if (*(yp+1))
  1841.                       fatal("invalid argument bundling after -W");
  1842.                     yargv++, yargc--;
  1843.                     if (yargc < 1)
  1844.                       fatal("Window handle missing");
  1845. #ifdef COMMENT
  1846.                     if (dummy) {
  1847.                         yargv++, yargc--;
  1848.                         break;
  1849.                     } else {
  1850. #endif /* COMMENT */
  1851.                         hwndDialer = (HWND) atol(*yargv);
  1852.                         StartedFromDialer = 1;
  1853.                         yargv++, yargc--;
  1854.                         KermitDialerID = atol(*yargv) ;
  1855. #ifdef COMMENT
  1856.                     }
  1857. #endif /* COMMENT */
  1858.                     break;
  1859.  
  1860.                   case '#':             /* K95 initialization options */
  1861.                     if (*(yp+1)) {
  1862.                         fatal("invalid argument bundling");
  1863.                     }
  1864.                     yargv++, yargc--;
  1865.                     if (yargc < 1)
  1866.                       fatal("-# argument missing");
  1867.                     startflags |= atol(*yargv);
  1868.                     break;
  1869. #endif /* OS2 */
  1870.  
  1871. #ifndef NOSPL
  1872.                   case 'M':                             /* My User Name */
  1873.                     if (*(yp+1)) {
  1874.                         fatal("invalid argument bundling");
  1875.                     }
  1876.                     yargv++, yargc--;
  1877.                     if ((yargc < 1) || (**yargv == '-')) {
  1878.                         fatal("missing username");
  1879.                     }
  1880.                     if ((int)strlen(*yargv) > UIDBUFLEN) {
  1881.                         fatal("username too long");
  1882.                     }
  1883. #ifdef COMMENT
  1884. /*
  1885.   This can't work.  uidbuf is overwritten in sysinit() which has yet to be
  1886.   called.  This cannot be set in prescan().
  1887. */
  1888. #ifdef IKSD
  1889.                     if (!inserver)
  1890. #endif /* IKSD */
  1891.                       ckstrncpy(uidbuf,*yargv,UIDBUFLEN);
  1892. #endif /* COMMENT */
  1893.                     break;
  1894. #endif /* NOSPL */
  1895.                   case 'R':             /* Remote-only advisory */
  1896. #ifdef CK_IFRO
  1897.                     remonly = 1;
  1898. #endif /* CK_IFRO */
  1899.                     break;
  1900.                   case 'S':             /* STAY */
  1901.                     stayflg = 1;
  1902.                     break;
  1903.                   case 'h':
  1904.                     noinit = 1;
  1905. #ifdef OS2
  1906.                     startflags |= 2;    /* No network DLLs */
  1907.                     startflags |= 4;    /* No TAPI DLLs */
  1908.                     startflags |= 8;    /* No Security DLLs */
  1909.                     startflags |= 16;   /* No Zmodem DLLs */
  1910.                     startflags |= 32;   /* Stdin */
  1911.                     startflags |= 64;   /* Stdout */
  1912. #endif /* OS2 */
  1913.                     break;
  1914. #ifndef NOICP
  1915.                   case 'Y':             /* No init file */
  1916.                     noinit = 1;
  1917.                     break;
  1918. #endif /* NOICP */
  1919.  
  1920.                   case 'q':
  1921.                       quiet = 1;
  1922.                       break;
  1923.  
  1924.                   case 'd':             /* = SET DEBUG ON */
  1925. #ifdef DEBUG
  1926.                     if (debcount++ > 0)
  1927.                       debtim = 1;
  1928.                     if (!deblog)
  1929.                       deblog = debopn("debug.log",0);
  1930. #endif /* DEBUG */
  1931.                     break;
  1932.  
  1933.                   case 'x':             /* Server */
  1934.                     arg_x = 1;          /* Note in advance */
  1935.                     break;
  1936. #ifndef NOICP
  1937.                   case 'y':             /* Alternative init file */
  1938.                     noinit = 0;
  1939.                     yargv++, yargc--;
  1940.                     if (yargc < 1) fatal("missing name in -y");
  1941.                     /* Replace init file name */
  1942.                     ckstrncpy(kermrc,*yargv,KERMRCL);
  1943.                     rcflag = 1;         /* Flag that this has been done */
  1944.                     debug(F111,"prescan kermrc",kermrc,rcflag);
  1945.                     break;
  1946. #endif /* NOICP */
  1947.                   case 'z':             /* = SET BACKGROUND OFF */
  1948.                     bgset = 0;
  1949.                     backgrd = 0;
  1950. #ifdef VMS
  1951.                     batch = 0;
  1952. #endif /* VMS */
  1953.                     break;
  1954.  
  1955.                   case 'B':             /* Force background (batch) */
  1956.                     bgset = 1;
  1957.                     backgrd = 1;
  1958. #ifdef VMS
  1959.                     batch = 1;
  1960. #endif /* VMS */
  1961.                     break;
  1962.  
  1963. #ifdef CK_NETBIOS
  1964.                   case 'N':
  1965.                     {
  1966.                         int n ;
  1967.                         yargv++, yargc--;
  1968. #ifdef COMMENT
  1969.                         if (y)
  1970.                           break;
  1971. #endif /* COMMENT */
  1972.                         if (strlen(*yargv) != 1 || (*yargv)[0] == 'X') {
  1973.                             NetBiosAdapter = -1;
  1974.                         } else {
  1975.                             n = atoi(*yargv);
  1976.                             if (n >= 0 && n <= 9)
  1977.                               NetBiosAdapter = n;
  1978.                             else
  1979.                               NetBiosAdapter = -1;
  1980.                         }
  1981.                     }
  1982.                     break;
  1983. #endif /* CK_NETBIOS */
  1984.                   default:
  1985.                     break;
  1986.                 }
  1987.                 if (!yp)
  1988.                   break;
  1989.                 x = *++yp;              /* See if options are bundled */
  1990.             }
  1991.         }
  1992.     }
  1993. #endif /* NOCMDL */
  1994. }
  1995.  
  1996. /*  G E T T C S  --  Get Transfer (Intermediate) Character Set  */
  1997.  
  1998. /*
  1999.   Given two file character sets, this routine picks out the appropriate
  2000.   "transfer" character set to use for translating between them.
  2001.   The transfer character set number is returned.
  2002.  
  2003.   Translation between two file character sets is done, for example,
  2004.   by the CONNECT, TRANSMIT, and TRANSLATE commands.
  2005.  
  2006.   Translation between Kanji character sets is not yet supported.
  2007. */
  2008. int
  2009. gettcs(cs1,cs2) int cs1, cs2; {
  2010. #ifdef NOCSETS                          /* No character-set support */
  2011.     return(0);                          /* so no translation */
  2012. #else
  2013.     int tcs = TC_TRANSP;
  2014. #ifdef KANJI
  2015. /* Kanji not supported yet */
  2016.     if (fcsinfo[cs1].alphabet == AL_JAPAN ||
  2017.         fcsinfo[cs2].alphabet == AL_JAPAN )
  2018.       tcs = TC_TRANSP;
  2019.     else
  2020. #endif /* KANJI */
  2021. #ifdef CYRILLIC
  2022. /*
  2023.   I can't remember why we don't test both sets here, but I think there
  2024.   must have been a reason...
  2025. */
  2026.       if (fcsinfo[cs2].alphabet == AL_CYRIL)
  2027.         tcs = TC_CYRILL;
  2028.       else
  2029. #endif /* CYRILLIC */
  2030. #ifdef HEBREW
  2031.           if (fcsinfo[cs1].alphabet == AL_HEBREW ||
  2032.               fcsinfo[cs2].alphabet == AL_HEBREW )
  2033.             tcs = TC_HEBREW;
  2034.           else
  2035. #endif /* HEBREW */
  2036. #ifdef GREEK
  2037.           if (fcsinfo[cs1].alphabet == AL_GREEK ||
  2038.               fcsinfo[cs2].alphabet == AL_GREEK )
  2039.             tcs = TC_GREEK;
  2040.           else
  2041. #endif /* GREEK */
  2042.  
  2043.             /* Roman sets ... */
  2044.  
  2045. #ifdef LATIN2                           /* East European */
  2046.         if (cs1 == FC_2LATIN  || cs2 == FC_2LATIN || /* Latin-2 */
  2047.             cs1 == FC_CP852   || cs2 == FC_CP852  || /* CP852 */
  2048.             cs1 == FC_CP1250  || cs2 == FC_CP1250 || /* Windows Latin-2 */
  2049.             cs1 == FC_MAZOVIA || cs2 == FC_MAZOVIA)  /* Polish Mazovia */
  2050.           tcs = TC_2LATIN;
  2051.         else
  2052. #endif /* LATIN2 */
  2053.                                         /* West European Euro-aware */
  2054.           if (cs1 == FC_CP858 || cs1 == FC_9LATIN ||
  2055.               cs2 == FC_CP858 || cs2 == FC_9LATIN)
  2056.             tcs = TC_9LATIN;
  2057.           else                          /* Traditional West European */
  2058.             tcs = TC_1LATIN;
  2059.     return(tcs);
  2060. #endif /* NOCSETS */
  2061. }
  2062.  
  2063. #ifndef NOLOCAL
  2064. /*  D O C O N E C T  --  Do the connect command  */
  2065. /*
  2066.   q = 0 means issue normal informational message about how to get back, etc.
  2067.   q != 0 means to skip the message.
  2068. */
  2069.  
  2070. int
  2071. doconect(q,async) int q, async; {
  2072.     int x;                              /* Return code */
  2073. #ifdef CK_AUTODL
  2074.     extern CHAR ksbuf[];
  2075. #endif /* CK_AUTODL */
  2076. #ifndef NOKVERBS                        /* Keyboard macro material */
  2077.     extern int keymac, keymacx;
  2078. #endif /* NOKVERBS */
  2079.     extern int justone, adl_err;
  2080.     int qsave;                          /* For remembering "quiet" value */
  2081. #ifdef OS2
  2082.     extern int term_io;
  2083.     extern int display_demo;
  2084.     int term_io_save;
  2085. #ifdef KUI
  2086.     extern int kui_async;
  2087. #endif /* KUI */
  2088. #endif /* OS2 */
  2089.     int is_tn = 0;
  2090.  
  2091. #ifdef IKSD
  2092.     if (inserver) {
  2093.         if (!quiet)
  2094.           printf("?Sorry, IKSD cannot CONNECT.\r\n");
  2095.         return(success = 0);
  2096.     }
  2097. #endif /* IKSD */
  2098.  
  2099.     is_tn =
  2100. #ifdef TNCODE
  2101.       (local && network && IS_TELNET()) || (!local && sstelnet)
  2102. #else
  2103.         0
  2104. #endif /* TNCODE */
  2105.           ;
  2106. /*
  2107.   Saving, changing, and restoring the global "quiet" variable around calls
  2108.   to conect() to control whether the verbose CONNECT message is printed is
  2109.   obviously less elegant than passing a parameter to conect(), but we do it
  2110.   this way to avoid the need to change all of the ck?con.c modules.  NOTE:
  2111.   it is important to restore the value immediately upon return in case there
  2112.   is an autodownload or APC.
  2113. */
  2114.     qsave = quiet;                      /* Save it */
  2115.     if (!quiet && q > -1)
  2116.       quiet = q;                        /* Use argument temporarily */
  2117.     conres();                           /* Put console back to normal */
  2118.     debug(F101,"doconect justone 1","",justone);
  2119. #ifdef CK_AUTODL
  2120.     ksbuf[0] = NUL;                     /* Autodownload packet buffer */
  2121. #endif /* CK_AUTODL */
  2122. #ifdef OS2
  2123.     display_demo = 1;                   /* Remember to display demo */
  2124. #endif /* OS2 */
  2125.  
  2126. #ifdef IKS_OPTION
  2127.     if (is_tn && TELOPT_U(TELOPT_KERMIT) && ttchk() >= 0
  2128. #ifdef OS2
  2129.        && !viewonly
  2130. #endif /* OS2 */
  2131.         ) {
  2132.         /* If the remote side is in a state of IKS START-SERVER    */
  2133.         /* we request that the state be changed.  We will detect   */
  2134.         /* a failure to adhere to the request when we call ttinc() */
  2135.         if (!iks_wait(KERMIT_REQ_STOP,0) && !tcp_incoming) {
  2136.             if (!quiet) {
  2137.                 printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2138.                 printf(
  2139. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2140.                 printf(" SEND and GET for file transfer.\r\n");
  2141.                 printf(" REMOTE commands for file management.\r\n");
  2142.                 printf(" FINISH to terminate Client/Server mode.\r\n");
  2143.                 printf(" BYE to terminate and close connection.\r\n");
  2144.                 printf(" REMOTE HELP for additional information.\r\n\r\n");
  2145.             }
  2146.             quiet = qsave;
  2147.             return(0);      /* Failure */
  2148.         }
  2149.     }
  2150.  
  2151.     /* Let our peer know our state. */
  2152. #ifdef CK_AUTODL
  2153.     if (is_tn && TELOPT_ME(TELOPT_KERMIT)
  2154. #ifdef OS2
  2155.         && !viewonly
  2156. #endif /* OS2 */
  2157.          ) {
  2158.         if (autodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2159.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  2160.         } else if (!autodl && TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2161.             tn_siks(KERMIT_STOP);
  2162.         }
  2163.     }
  2164. #else /* CK_AUTODL */
  2165.     if (is_tn && TELOPT_ME(TELOPT_KERMIT) &&
  2166.     TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  2167.         tn_siks(KERMIT_STOP);
  2168. #endif /* CK_AUTODL */
  2169. #endif /* IKS_OPTION */
  2170.  
  2171.     debug(F101,"doconect flow","",flow);
  2172. #ifdef OS2
  2173.     debug(F101,"doconect async","",async);
  2174. #ifdef KUI
  2175.     if (kui_async)
  2176.       async = 1;;
  2177. #endif /* KUI */
  2178.     x = conect(async);                  /* Connect the first time */
  2179. #else /* OS2 */
  2180.     x = conect();
  2181. #endif /* OS2 */
  2182.     debok = 1;
  2183.  
  2184. #ifdef IKS_OPTION
  2185.     if (TELOPT_U(TELOPT_KERMIT) &&
  2186.         TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  2187.         !tcp_incoming && !quiet && ttchk() >= 0
  2188.         ) {
  2189.         printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2190.         printf(
  2191. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2192.         printf(" SEND and GET for file transfer.\r\n");
  2193.         printf(" REMOTE commands for file management.\r\n");
  2194.         printf(" FINISH to terminate Client/Server mode.\r\n");
  2195.         printf(" BYE to terminate and close connection.\r\n");
  2196.         printf(" REMOTE HELP for additional information.\r\n\r\n");
  2197.     }
  2198. #endif /* IKS_OPTION */
  2199.  
  2200.     quiet = qsave;                      /* Restore "quiet" value */
  2201.     debug(F101,"doconect justone 2","",justone);
  2202.  
  2203. #ifdef NETCONN
  2204.     if (network && tn_exit && ttchk() < 0)
  2205.       doexit(GOOD_EXIT,xitsta);         /* Exit with good status */
  2206. #endif /* NETCONN */
  2207.  
  2208. #ifdef OS2ORUNIX
  2209.     /* Exit on disconnect if the port is not open or carrier detect */
  2210.     if (exitonclose && (ttchk() < 0))
  2211.       doexit(GOOD_EXIT,xitsta);
  2212. #endif /* OS2ORUNIX */
  2213.  
  2214. #ifdef CKCONINTB4CB
  2215.     /* The order makes a difference in HP-UX 8.00. */
  2216.     /* The other order makes it think it's in the background when it */
  2217.     /* returns from CONNECT (Apr 1999). */
  2218.     setint();
  2219.     concb((char)escape);                /* Restore console for commands */
  2220. #else
  2221.     /* This is how it has always been so better leave it */
  2222.     /* this way for all non-HP-UX-8.00 builds. */
  2223.     concb((char)escape);                /* Restore console for commands */
  2224.     setint();
  2225. #endif /* CKCONINTB4CB */
  2226.  
  2227. #ifdef OS2
  2228.     if (!async) {
  2229.         term_io_save = term_io;         /* Disable I/O by emulator */
  2230.         term_io = 0;
  2231. #endif /* OS2 */
  2232.  
  2233. #ifdef CK_APC
  2234. /*
  2235.   If an APC command was received during CONNECT mode, we define it now
  2236.   as a macro, execute the macro, and then return to CONNECT mode.
  2237.   We do this in a WHILE loop in case additional APCs come during subsequent
  2238.   CONNECT sessions.
  2239. */
  2240.         debug(F101,"doconect apcactive","",apcactive);
  2241.         debug(F101,"doconect success","",success);
  2242.  
  2243.         while (x > 0 && (apcactive == APC_LOCAL ||
  2244.                          (apcactive == APC_REMOTE && apcstatus != APC_OFF))) {
  2245.             debug(F101,"doconect justone 3","",justone);
  2246.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  2247.                 debug(F110,"doconect about to execute APC",apcbuf,0);
  2248.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  2249.                 delmac("_apc_commands",1);
  2250. #ifdef DEBUG
  2251.             } else {
  2252.                 debug(F100,"doconect APC in progress","",0);
  2253. #endif /* DEBUG */
  2254.             }
  2255.             debug(F101,"doconect apcactive after domac","",apcactive);
  2256.             if (!apcactive) {               /* In case CLEAR APC was in APC */
  2257.                 debug(F101,"doconect quit APC loop: apcactive","",apcactive);
  2258.                 break;
  2259.             }
  2260.             /* Also don't reconnect if autodownload failed - very confusing! */
  2261.             /* Let them view the local screen to see what happened. - fdc */
  2262.  
  2263.             /* This should be conditional.  If someone is relying on the */
  2264.             /* connect mode autodownload for the kermit server to use with */
  2265.             /* a remotely executed script we should be able to return to */
  2266.             /* connect mode on the failure.  What we really need to do is */
  2267.             /* report the status of the transfer and then return to CONNECT. */
  2268.             /* In unix this would simply be a printf(), but in K95 it could */
  2269.             /* use a popup dialog to report the status. - Jeff */
  2270.  
  2271. #ifndef NOXFER
  2272.             debug(F101,"doconect xferstat","",xferstat);
  2273.             if (apcactive == APC_LOCAL && !xferstat && adl_err != 0) {
  2274.                 debug(F101,"doconect quit APC loop: xferstat","",xferstat);
  2275.                 apcactive = APC_INACTIVE;
  2276.                 break;
  2277.             }
  2278. #endif /* NOXFER */
  2279. #ifdef OS2
  2280.             msleep(250);
  2281. #endif /* OS2 */
  2282.             debug(F101,"doconect justone 4","",justone);
  2283.             qsave = quiet;              /* Do this again... */
  2284.             if (!quiet && q > -1)
  2285.               quiet = q;
  2286. #ifdef CK_AUTODL
  2287.             ksbuf[0] = NUL;
  2288. #endif /* CK_AUTODL */
  2289. #ifdef IKS_OPTION
  2290. #ifdef CK_AUTODL
  2291.             if (is_tn &&
  2292.                 TELOPT_ME(TELOPT_KERMIT) &&
  2293.                 !TELOPT_SB(TELOPT_KERMIT).kermit.me_start &&
  2294.                 autodl
  2295. #ifdef CK_APC
  2296.                 && !apcactive
  2297. #endif /* CK_APC */
  2298. #ifdef OS2
  2299.                 && !viewonly
  2300. #endif /* OS2 */
  2301.                 ) {
  2302.                 tn_siks(KERMIT_START);  /* Send Kermit-Server Start */
  2303.             }
  2304. #endif /* CK_AUTODL */
  2305. #endif /* IKS_OPTION */
  2306. #ifndef OS2
  2307.             x = conect();               /* Re-CONNECT. */
  2308. #else /* OS2 */
  2309.             x = conect(0);
  2310.             term_io = term_io_save;
  2311. #endif /* OS2 */
  2312.             debok = 1;
  2313.             quiet = qsave;
  2314.             debug(F101,"doconect justone 5","",justone);
  2315. #ifdef NETCONN
  2316.             if (network && ttchk() < 0) {
  2317.                 if (tn_exit || exitonclose)
  2318.                   doexit(GOOD_EXIT,xitsta);
  2319.                 else
  2320.                   break;
  2321.             }
  2322. #endif /* NETCONN */
  2323.  
  2324. #ifdef OS2ORUNIX
  2325.             /* If connection dropped */
  2326.             if (ttchk() < 0) {
  2327.                 concb((char)escape);    /* Restore console. */
  2328.                 if (exitonclose)
  2329.                   doexit(GOOD_EXIT,xitsta);
  2330.                 else
  2331.                   break;
  2332.             }
  2333. #endif /* OS2ORUNIX */
  2334.         } /* Loop back for more. */
  2335. #endif /* CK_APC */
  2336.  
  2337. #ifndef NOKVERBS
  2338.         if ((keymac > 0) && (keymacx > -1)) { /* Executing a keyboard macro? */
  2339.             /* Set up the macro and return */
  2340.             /* Do not clear the keymac flag */
  2341. #ifdef OS2
  2342.         term_io = term_io_save;
  2343. #endif /* OS2 */
  2344.             return(dodo(keymacx,NULL,CF_KMAC|cmdstk[cmdlvl].ccflgs));
  2345.         }
  2346. #endif /* NOKVERBS */
  2347. #ifdef OS2
  2348.         term_io = term_io_save;
  2349.     } /* if (!async) */
  2350. #endif /* OS2 */
  2351.  
  2352. #ifdef CKCONINTB4CB
  2353.     /* The order makes a difference in HP-UX 8.00. */
  2354.     /* The other order makes it think it's in the background when it */
  2355.     /* returns from CONNECT (Apr 1999). */
  2356.     setint();
  2357.     concb((char)escape);                /* Restore console for commands */
  2358. #else
  2359.     /* This is how it has always been so better leave it */
  2360.     /* this way for all non-HP-UX-8.00 builds. */
  2361.     concb((char)escape);                /* Restore console for commands */
  2362.     setint();
  2363. #endif /* CKCONINTB4CB */
  2364. #ifdef OS2
  2365.     if (!async)
  2366. #endif /* OS2 */
  2367.       what = W_COMMAND;                 /* Back in command mode. */
  2368.     return(x);                          /* Done. */
  2369. }
  2370. #endif /* NOLOCAL */
  2371.  
  2372. #ifndef NOICP
  2373. #ifdef COMMENT
  2374. /*
  2375.   It seemed that this was needed for OS/2, in which \v(cmdfile) and other
  2376.   file-oriented variables or functions can return filenames containing
  2377.   backslashes, which are subsequently interpreted as quotes rather than
  2378.   directory separators (e.g. see commented section for VN_CMDF below).
  2379.   But the problem can't be cured at this level.  Example:
  2380.  
  2381.     type \v(cmdfile)
  2382.  
  2383.   Without doubling, the filename is parsed correctly, but then when passed
  2384.   to UNIX 'cat' through the shell, the backslash is removed, and then cat
  2385.   can't open the file.  With doubling, the filename is not parsed correctly
  2386.   and the TYPE command fails immediately with a "file not found" error.
  2387. */
  2388. /*
  2389.   Utility routine to double all backslashes in a string.
  2390.   s1 is pointer to source string, s2 is pointer to destination string,
  2391.   n is length of destination string, both NUL-terminated.
  2392.   Returns 0 if OK, -1 if not OK (destination string too short).
  2393. */
  2394. int
  2395. dblbs(s1,s2,n) char *s1, *s2; int n; {
  2396.     int i = 0;
  2397.     while (*s1) {
  2398.         if (*s1 == '\\') {
  2399.             if (++i > n) return(-1);
  2400.             *s2++ = '\\';
  2401.         }
  2402.         if (++i > n) return(-1);
  2403.         *s2++ = *s1++;
  2404.     }
  2405.     *s2 = NUL;
  2406.     return(0);
  2407. }
  2408. #endif /* COMMENT */
  2409.  
  2410. char *
  2411. gmdmtyp() {                             /* Get modem type */
  2412. #ifndef NODIAL
  2413.     int i, x;
  2414.  
  2415.     debug(F111,"gmdmtyp","mdmtyp",mdmtyp);
  2416.     debug(F111,"gmdmtyp","mdmsav",mdmsav);
  2417.  
  2418.     x = mdmtyp;
  2419.     if (x < 0)                          /* In case of network dialing */
  2420.       x = mdmsav;
  2421.     if (x < 1)
  2422.       return("none");
  2423.     else
  2424.       for (i = 0; i < nmdm; i++)
  2425.         if ((mdmtab[i].kwval == x) && (mdmtab[i].flgs == 0))
  2426.           return(mdmtab[i].kwd);
  2427. #endif /* NODIAL */
  2428.     return("none");
  2429. }
  2430.  
  2431. #ifndef NOXMIT
  2432. #ifndef NOLOCAL
  2433. /*  T R A N S M I T  --  Raw upload  */
  2434.  
  2435. /*  Obey current line, duplex, parity, flow, text/binary settings. */
  2436. /*  Returns 0 upon apparent success, 1 on obvious failure.  */
  2437.  
  2438. /***
  2439.  Things to add:
  2440.  . Make both text and binary mode obey set file bytesize.
  2441.  . Maybe allow user to specify terminators other than CR?
  2442.  . Maybe allow user to specify prompts other than single characters?
  2443.  . Make STATISTICS also work for TRANSMIT.
  2444.  . If TRANSMIT is done without echo, make some kind of (optional) display.
  2445.  . Make the same optimization for binary-mode transmit that was done for
  2446.    text-mode (in the no-echo / no-prompt / no-pause case).
  2447. ***/
  2448.  
  2449. /*  T R A N S M I T  --  Raw upload  */
  2450.  
  2451. /*  s is the filename, t is the turnaround (prompt) character  */
  2452.  
  2453. /*
  2454.   Maximum number of characters to buffer.
  2455.   Must be less than LINBUFSIZ
  2456. */
  2457. #ifdef OS2
  2458. #define XMBUFS 4096                     /* For compatibility with XYZmodem */
  2459. #else /* OS2 */
  2460. #define XMBUFS 1024
  2461. #endif /* OS2 */
  2462.  
  2463. #ifdef TNCODE
  2464. #ifndef IAC
  2465. #define IAC 255
  2466. #endif /* IAC */
  2467. #endif /* TNCODE */
  2468.  
  2469. #define OUTXBUFSIZ 15
  2470. static CHAR inxbuf[OUTXBUFSIZ+1];       /* Host-to-screen expansion buffer */
  2471. static int inxcount = 0;                /* and count */
  2472. static CHAR outxbuf[OUTXBUFSIZ+1];      /* Keyboard-to-host expansion buf */
  2473. static int outxcount = 0;               /* and count */
  2474.  
  2475. /*  T R A N S M I T  --  Unguarded non-protocol file transmission  */
  2476. /*
  2477.   Call with:
  2478.     char * s:   Name of file to transmit.
  2479.     char t:     Turnaround char for text-mode transmission (normally LF).
  2480.     int xlate:  nonzero = charset translation for text-mode xfer, 0 = skip.
  2481.     int binary: nonzero = transmit in binary mode, 0 = in text mode.
  2482. */
  2483. #define XBBUFSIZ 508            /* For binary blasting */
  2484. static CHAR xbbuf[XBBUFSIZ+4];
  2485.  
  2486. int
  2487. #ifdef CK_ANSIC
  2488. transmit(char * s, char t, int xlate, int binary, int xxecho)
  2489. #else
  2490. transmit(s,t,xlate,binary,xxecho) char *s; char t; int xlate, binary, xxecho;
  2491. #endif /* CK_ANSIC */
  2492. /* transmit */ {
  2493. #ifdef MAC
  2494.     extern char sstate;
  2495.     int count = 100;
  2496. #else
  2497.     int count = 0;
  2498. #ifdef OS2
  2499. #ifdef NT
  2500.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  2501. #else /* NT */
  2502.     SIGTYP (* volatile oldsig)(int);
  2503. #endif /* NT */
  2504.  
  2505. #else /* OS2 */
  2506.     SIGTYP (* oldsig)();
  2507. #endif /* OS2 */
  2508. #endif /* MAC */
  2509.     int eof = 0;                        /* End of File flag */
  2510.     int eol = 0;                        /* End of Line flag */
  2511.     int rc = 1;                         /* Return code. 0=fail, 1=succeed. */
  2512.     int myflow;                         /* Local copy of global flow... */
  2513.     int is_tn = 0;                      /* Do Telnet negotiations */
  2514.     int xbufsiz = XMBUFS;               /* Size of TRANSMIT buffer */
  2515.     int x, y, c, i;                     /* Int workers... */
  2516.     int control = 0;                    /* Echo loop control */
  2517.     long nbytes = 0;                    /* File byte count */
  2518.     long zz;                            /* Long worker */
  2519.     char *p;                            /* Char * worker */
  2520.  
  2521. #ifdef PIPESEND
  2522.     extern int pipesend;
  2523. #endif /* PIPESEND */
  2524.  
  2525. #ifndef NOCSETS
  2526.     int tcs = TC_TRANSP;                /* Intermediate (xfer) char set */
  2527.     int langsv = L_USASCII;             /* Save current language */
  2528.     int unicode = 0;
  2529.     int tcssize = 0;
  2530.  
  2531. #ifdef CK_ANSIC /* ANSI C prototypes... */
  2532.     CHAR (*sxo)(CHAR);
  2533.     CHAR (*rxo)(CHAR);
  2534.     CHAR (*sxi)(CHAR);
  2535.     CHAR (*rxi)(CHAR);
  2536. #else /* Not ANSI C... */
  2537.     CHAR (*sxo)();
  2538.     CHAR (*rxo)();
  2539.     CHAR (*sxi)();
  2540.     CHAR (*rxi)();
  2541. #endif /* CK_ANSIC */
  2542. #ifdef UNICODE
  2543.     union ck_short uc;
  2544.     int bomorder = 0;
  2545. #ifdef CK_ANSIC
  2546.     extern int (*xl_ufc[MAXFCSETS+1])(USHORT);  /* Unicode to FCS */
  2547.     extern USHORT (*xl_fcu[MAXFCSETS+1])(CHAR); /* FCS to Unicode */
  2548.     extern int (*xuf)(USHORT);
  2549.     extern USHORT (*xfu)(CHAR);
  2550. #else
  2551.     extern int (*xl_ufc[MAXFCSETS+1])();
  2552.     extern USHORT (*xl_fcu[MAXFCSETS+1])();
  2553.     extern int (*xuf)();
  2554.     extern USHORT (*xfu)();
  2555. #endif /* CK_ANSIC */
  2556. #endif /* UNICODE */
  2557. #endif /* NOCSETS */
  2558.  
  2559.     debug(F101,"xmit t","",t);
  2560.     debug(F101,"xmit xlate","",xlate);
  2561.     debug(F101,"xmit binary","",binary);
  2562.  
  2563. #ifdef PIPESEND
  2564.     if (pipesend) {
  2565.         if (nopush) return(-2);
  2566.         if (zxcmd(ZIFILE,s) < 1) {
  2567.             printf("?Can't start command: %s\n",s);
  2568.             return(0);
  2569.         }
  2570.     } else
  2571. #endif /* PIPESEND */
  2572.     if (zopeni(ZIFILE,s) == 0) {        /* Open the file to be transmitted */
  2573.         printf("?Can't open file %s\n",s);
  2574.         return(0);
  2575.     }
  2576.     x = -1;                             /* Open the communication channel */
  2577.     if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) {  /* (no harm if already open) */
  2578.         printf("Can't open device %s\n",ttname);
  2579.         return(0);
  2580.     }
  2581.     zz = x ? speed : -1L;
  2582.     if (binary) {                       /* Binary file transmission */
  2583.         myflow = (flow == FLO_XONX) ? FLO_NONE : flow;
  2584.  
  2585.         if (ttvt(zz,myflow) < 0) {      /* So no Xon/Xoff! */
  2586.             printf("Can't condition line\n");
  2587.             return(0);
  2588.         }
  2589.     } else {
  2590.         if (ttpkt(zz,flow,parity) < 0) { /* Put the line in "packet mode" */
  2591.             printf("Can't condition line\n"); /* so Xon/Xoff will work, etc. */
  2592.             return(0);
  2593.         }
  2594.     }
  2595.     is_tn =
  2596. #ifdef TNCODE
  2597.       (local && network && IS_TELNET()) || (!local && sstelnet)
  2598. #else
  2599.         0
  2600. #endif /* TNCODE */
  2601.           ;
  2602.  
  2603. #ifndef NOCSETS
  2604. /* Set up character set translations */
  2605.  
  2606.     tcs = 0;                            /* "Transfer" or "Other" charset */
  2607.     sxo = rxo = NULL;                   /* Initialize byte-to-byte functions */
  2608.     sxi = rxi = NULL;
  2609.     unicode = 0;                        /* Assume Unicode won't be involved */
  2610.     if (!binary && xlate) {             /* Set up charset translations */
  2611. /*
  2612.   In the SENDING direction, we are converting from the local file's
  2613.   character-set (fcharset) to the remote terminal charset (tcsr).  In the
  2614.   RECEIVING direction (echoing) we are converting from the remote end of the
  2615.   terminal charset (tcsr) to its local end (tcsl), which is not necessarily
  2616.   the same as the file character-set.  Especially when the file character
  2617.   set is UCS-2, which is not a valid terminal character set.  The various
  2618.   combinations are represented in this table:
  2619.  
  2620.   FCS = File Character Set
  2621.   RCS = Remote Terminal Character Set
  2622.   CCS = Console (Local Terminal) Character Set
  2623.  
  2624.    8   4   2   1
  2625.   FCS FCS RCS CCS
  2626.   UCS UTF UTF UTF
  2627.    0   0   0   0   =   0   =   No translation
  2628.    0   0   0   1   =   1   =   FCS -> RCS, Echo RCS -> UTF
  2629.    0   0   1   0   =   2   =   FCS -> UTF, Echo UTF -> CCS
  2630.    0   0   1   1   =   3   =   FCS -> UTF, Echo no translation
  2631.  
  2632.    0   1   0   0   =   4   =   UTF -> RCS, Echo RCS -> CCS
  2633.    0   1   0   1   =   5   =   UTF -> RCS, Echo RCS -> UTF
  2634.    0   1   1   0   =   6   =   UTF -> UTF, Echo UTF -> CCS
  2635.    0   1   1   1   =   7   =   No translation
  2636.  
  2637.    1   0   0   0   =   8   =   UCS -> RCS, Echo RCS -> CCS
  2638.    1   0   0   1   =   9   =   UCS -> RCS, Echo RCS -> UTF
  2639.    1   0   1   0   =  10   =   UCS -> UTF, Echo UTF -> CCS
  2640.    1   0   1   1   =  11   =   UCS -> UTF, Echo no translation
  2641. */
  2642. #ifdef UNICODE
  2643.         xfu = NULL;                     /* Unicode translation functions */
  2644.         xuf = NULL;
  2645.         bomorder = ucsorder;            /* UCS-2 byte order */
  2646.  
  2647.         if (fcharset == FC_UCS2)        /* File charset is UCS-2 */
  2648.           unicode |= 8;
  2649.         else if (fcharset == FC_UTF8)   /* File charset is UTF-8 */
  2650.           unicode |= 4;
  2651.         if (tcsr == FC_UTF8)            /* Remote term charset is UTF-8 */
  2652.           unicode |= 2;
  2653.         if (tcsl == FC_UTF8)            /* Local term charset is UTF-8 */
  2654.           unicode |= 1;
  2655. #endif /* UNICODE */
  2656. /*
  2657.   When Unicode not involved -- TCS is the intermediate (xfer) set, and:
  2658.   sxo = File-to-Intermediate charset function
  2659.   rxo = Intermediate-to-Remote-Terminal charset function
  2660.   sxi = Remote-Terminal-to-Intermediate
  2661.   rxi = Intermediate-to-Local-Terminal
  2662. */
  2663.         tcs = gettcs(tcsr,fcharset);    /* Get intermediate set. */
  2664.         sxo = xls[tcs][fcharset];       /* translation function */
  2665.         rxo = xlr[tcs][tcsr];           /* pointers for output functions */
  2666.         sxi = xls[tcs][tcsr];           /* and for input functions. */
  2667.         rxi = xlr[tcs][tcsl];
  2668. /*
  2669.   At this point we have unicode nonzero if Unicode is involved in the
  2670.   conversion, and to 0 if it is not.
  2671.   The following is to prevent use of zmstuff() and zdstuff() by translation
  2672.   functions (stuffing works with file i/o, not with communication i/o).
  2673. */
  2674.         langsv = language;              /* Save current SET LANGUAGE */
  2675.         language = L_USASCII;           /* No language-specific translations */
  2676.     }
  2677. #endif /* NOCSETS */
  2678.  
  2679.     i = 0;                              /* Beginning of buffer. */
  2680. #ifndef MAC
  2681. #ifndef AMIGA
  2682.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  2683. #endif /* AMIGA */
  2684. #endif /* MAC */
  2685.     tr_int = 0;                         /* Have not been interrupted (yet). */
  2686.     rc = 1;                             /* Return code presumed good. */
  2687. #ifdef VMS
  2688.     conres();
  2689. #endif /* VMS */
  2690.  
  2691. #ifndef NOCSETS
  2692.     debug(F101,"XMIT unicode","",unicode);
  2693. #ifdef UNICODE
  2694.     debug(F101,"XMIT bomorder","",bomorder);
  2695. #endif /* UNICODE */
  2696. #endif /* NOCSETS */
  2697.  
  2698.     c = 0;                              /* Initial condition */
  2699.     while (c > -1 && !eof) {            /* Loop for all characters in file */
  2700.         eol = 0;
  2701. #ifdef MAC
  2702.         /*
  2703.          * It is expensive to run the miniparser so don't do it for
  2704.          * every character.
  2705.          */
  2706.         if (--count < 0) {
  2707.             count = 100;
  2708.             miniparser(1);
  2709.             if (sstate == 'a') {
  2710.                 sstate = '\0';
  2711.                 goto xmitfail;
  2712.             }
  2713.         }
  2714. #else /* Not MAC */
  2715.         if (tr_int) {                   /* Interrupted? */
  2716.             printf("^C...\n");          /* Print message */
  2717.             goto xmitfail;
  2718.         }
  2719. #endif /* MAC */
  2720.         c = zminchar();                 /* Get a file character */
  2721. #ifdef COMMENT
  2722. /* too much */
  2723. #ifdef DEBUG
  2724.         if (deblog) {
  2725.             if (c < 0)
  2726.               debug(F101,"XMIT zminchar","",c);
  2727.             else
  2728.               debug(F000,"XMIT zminchar","",c);
  2729.         }
  2730. #endif /* DEBUG */
  2731. #endif /* COMMENT */
  2732.         if (c < -1) {                   /* Other error */
  2733.             printf("?TRANSMIT file read error: %s\n",ck_errstr());
  2734.             goto xmitfail;
  2735.         } else if (c > -1) {
  2736.             nbytes++;
  2737.             c &= fmask;                 /* Apply SET FILE BYTESIZE mask */
  2738.         } else if (c == -1) {
  2739.             eof = 1;
  2740.             debug(F101,"XMIT eof","",eof);
  2741.         }
  2742.         if (binary) {                   /* Binary... */
  2743.             if (c == -1) {              /* If EOF */
  2744.                 rc = 1;                 /* Success */
  2745.                 eof = 1;
  2746.                 goto xmitexit;          /* Done */
  2747.             }
  2748.             if (!xmitw && !xxecho) {    /* Special "blast" mode */
  2749.                 if (count == XBBUFSIZ) { /* File input buffer full... */
  2750.                     while (count > 0) {
  2751.                         errno = 0;
  2752.                         y = ttol(xbbuf,count);
  2753.                         if (y < 0) {    /* try to send it. */
  2754.                             printf("?TRANSMIT output error: %s\n",
  2755.                                    ck_errstr());
  2756.                             debug(F111,"XMIT binary ttol error",
  2757.                                   ck_errstr(),errno);
  2758.                             rc = 0;
  2759.                             break;
  2760.                         }
  2761.                         if (y < 0) break;
  2762.                         count -= y;
  2763.                     }
  2764.                     count = 0;
  2765.                 }
  2766.                 xbbuf[count++] = c;
  2767. #ifdef TNCODE
  2768.                 if (c == IAC && is_tn)  /* Telnet IAC */
  2769.                   xbbuf[count++] = IAC; /* must be doubled */
  2770. #endif /* TNCODE */
  2771.                 continue;
  2772.             }
  2773.             if (ttoc(dopar((char) c)) < 0) { /* else just send the char */
  2774.                 printf("?Can't transmit character\n");
  2775.                 goto xmitfail;
  2776.             }
  2777. #ifdef TNCODE
  2778.             if (c == IAC && is_tn)      /* Quote Telnet IAC */
  2779.               ttoc((char)IAC);
  2780. #endif /* TNCODE */
  2781.  
  2782.             if (xmitw)                  /* Pause if requested */
  2783.               msleep(xmitw);
  2784.  
  2785.             if (xxecho) {               /* SET TRANSMIT ECHO ON? */
  2786.                 if (duplex) {           /* Yes, for half duplex */
  2787. #ifndef NOLOCAL
  2788. #ifdef OS2
  2789.                     /* Echo to emulator */
  2790.                     scriptwrtbuf((USHORT)(c & cmdmsk));
  2791. #endif /* OS2 */
  2792. #endif /* NOLOCAL */
  2793.                     if (conoc((char)(c & cmdmsk)) < 0) /* echo locally. */
  2794.                       goto xmitfail;
  2795.                 } else {                /* For full duplex, */
  2796.                     int i, n;           /* display whatever is there. */
  2797.                     n = ttchk();        /* See how many chars are waiting */
  2798.                     if (n < 0) {        /* Connection dropped? */
  2799.                         printf("?Connection lost\n");
  2800.                         goto xmitfail;
  2801.                     }
  2802.                     for (i = 0; i < n; i++) { /* Read and echo that many. */
  2803.                         x = ttinc(xmitt); /* Timed read just in case. */
  2804.                         if (x > -1) {   /* If no timeout */
  2805.                             if (parity) x &= 0x7f; /* display the char, */
  2806. #ifndef NOLOCAL
  2807. #ifdef OS2
  2808.                             /* Echo to emulator */
  2809.                             scriptwrtbuf((USHORT)x);
  2810. #endif /* OS2 */
  2811. #endif /* NOLOCAL */
  2812.                             if (conoc((char)(x & cmdmsk)) < 0) {
  2813.                                 printf("?Output error\n");
  2814.                                 goto xmitfail;
  2815.                             }
  2816.                         } else if (x == -2) {
  2817.                             printf("Connection closed.\n");
  2818.                             ttclos(1);
  2819.                             goto xmitfail;
  2820.                         } else if (x == -3) {
  2821.                             printf(
  2822.                             "Session Limit exceeded - closing connection.\n"
  2823.                                    );
  2824.                             ttclos(1);
  2825.                             goto xmitfail;
  2826.                         } else {
  2827.                             printf("?Communications error\n");
  2828.                             goto xmitfail;
  2829.                         }
  2830.                     }
  2831.                 }
  2832.             } else ttflui();            /* Not echoing, just flush input. */
  2833.  
  2834.         } else {                        /* Text mode, line at a time. */
  2835. #ifdef UNICODE
  2836.             if (fcharset == FC_UCS2 && xlate) { /* Special for UCS-2 */
  2837.                 char xbuf[8];
  2838.                 x = 1 - (nbytes & 1);   /* Odd or even byte */
  2839.                 if (x == 0)             /* Note: 1 = the 1st, 0 = 2nd, etc */
  2840.                   uc.x_short = 0;
  2841.                 if (bomorder)           /* Little Endian */
  2842.                   x = 1 - x;            /* Save byte in appropriate half */
  2843.                 debug(F101,"XMIT UCS2 x","",x);
  2844.                 uc.x_char[x] = (CHAR) (c & 0xff);
  2845.                 if (nbytes & 1)         /* First byte, go back for next */
  2846.                   continue;
  2847.                 if (nbytes == 2) {      /* UCS-2 Byte Order Mark */
  2848.                     if (uc.x_short == (USHORT) 0xfeff) {
  2849.                         debug(F100,"XMIT UCS2 BOM FEFF","",bomorder);
  2850.                         continue;
  2851.                     } else if (uc.x_short == (USHORT) 0xfffe) {
  2852.                         bomorder = 1 - bomorder;
  2853.                         debug(F100,"XMIT UCS2 BOM FFFE (swap)","",bomorder);
  2854.                         continue;
  2855.                     }
  2856.                 }
  2857.                 sprintf(xbuf,"%04X",uc.x_short); /* SAFE */
  2858.                 debug(F111,"XMIT UCS2",xbuf,uc.x_short);
  2859.                 if (nbytes & 1)         /* Special eol test for UCS-2 */
  2860.                   if (uc.x_short == '\n')
  2861.                     eol = 1;
  2862. #ifdef COMMENT
  2863.                 if (uc.x_short == 0x2028 || uc.x_short == 0x2029)
  2864.                     eol = 1;
  2865. #endif /* COMMENT */
  2866.             } else
  2867. #endif /* UNICODE */
  2868.               if (c == '\n') {          /* Normal eol test otherwise */
  2869.                   eol = 1;
  2870.             }
  2871.             if (eol) {                  /* End of line? */
  2872.                 int stuff = -1;
  2873.                 debug(F101,"XMIT eol length","",i);
  2874.                 if (i == 0) {           /* Blank line? */
  2875.                     if (xmitf)          /* Yes, insert fill if asked. */
  2876.                       line[i++] = dopar((char) xmitf);
  2877.                 }
  2878.                 if (i == 0 || ((char) line[i-1]) != ((char) dopar(CR)))
  2879.                   line[i++] = dopar(CR); /* Terminate it with CR */
  2880.                 if (xmitl) {
  2881.                     stuff = LF;
  2882. #ifdef TNCODE
  2883.                 } else if (is_tn && (tn_nlm != TNL_CR)) {
  2884.                     /* TELNET NEWLINE ON/OFF/RAW */
  2885.                     stuff = (tn_nlm == TNL_CRLF) ? LF : NUL;
  2886. #endif /* TNCODE */
  2887.                 }
  2888.                 if (stuff > -1)
  2889.                   line[i++] = dopar((char)stuff);
  2890.                 line[i] = NUL;
  2891.                 debug(F111,"XMIT eol line",line,i);
  2892.  
  2893.             } else if (c != -1) {       /* Not a newline, regular character */
  2894.                 int k, x;
  2895.                 outxbuf[0] = c;         /* In case of no translation */
  2896.                 outxcount = 1;          /* Assume result is one byte */
  2897. #ifndef NOCSETS
  2898.                 switch (unicode) {
  2899.                   case 0:               /* No Unicode involved */
  2900.                   case 1:
  2901.                     if (xlate) {        /* If not /TRANSPARENT */
  2902.                         /* Local-to-intermediate */
  2903.                         if (sxo) c = (*sxo)((char)c);
  2904.                         /* Intermediate-to-remote */
  2905.                         if (rxo) c = (*rxo)((char)c);
  2906.                         outxbuf[0] = c;
  2907.                     }
  2908.                     break;
  2909. #ifdef UNICODE
  2910.                   case 2:               /* Local byte to UTF-8 */
  2911.                   case 3:
  2912.                     xfu = xl_fcu[fcharset];
  2913.                     tcssize = fcsinfo[fcharset].size;
  2914.                     outxcount =
  2915.                       b_to_u((CHAR)c,outxbuf,OUTXBUFSIZ,tcssize);
  2916.                     break;
  2917.                   case 4:               /* Local UTF-8 to remote byte */
  2918.                   case 5:
  2919.                     xuf = xl_ufc[tcsr];
  2920.                     x = u_to_b((CHAR)c); /* Convert to byte */
  2921.                     if (x == -1) {      /* If more input bytes needed */
  2922.                         continue;       /* go back and get them */
  2923.                     } else if (x == -2) { /* LS or PS (shouldn't happen) */
  2924.                         outxbuf[0] = CR;
  2925.                     } else if (x == -9) { /* UTF-8 error */
  2926.                         outxbuf[0] = '?'; /* Insert error char */
  2927.                         outxbuf[1] = u_to_b2(); /* Insert next char */
  2928.                         outxcount = 2;
  2929.                     } else {
  2930.                         outxbuf[0] =    /* Otherwise store result */
  2931.                           (unsigned)(x & 0xff);
  2932.                     }
  2933.                     break;
  2934.                   case 6:               /* UTF-8 to UTF-8 */
  2935.                   case 7:
  2936.                     break;
  2937.                   case 8:               /* UCS-2 to byte */
  2938.                   case 9:
  2939.                     xuf = xl_ufc[tcsr];
  2940.                     outxbuf[0] = (*xuf)(uc.x_short);
  2941.                     break;
  2942.                   case 10:
  2943.                   case 11: {            /* UCS-2 to UTF-8 */
  2944.                       int j;
  2945.                       CHAR * buf = NULL;
  2946.                       x = ucs2_to_utf8(uc.x_short,&buf);
  2947.                       if (x < 0) {
  2948.                           outxbuf[0] = 0xff; /* (= U+FFFD) */
  2949.                           outxbuf[1] = 0xbd;
  2950.                           x = 2;
  2951.                       }
  2952.                       for (j = 0; j < x; j++)
  2953.                         outxbuf[j] = buf[j];
  2954.                       outxcount = x;
  2955.                       break;
  2956.                   }
  2957. #endif /* UNICODE */
  2958.                 }
  2959. #endif /* NOCSETS */
  2960.                 outxbuf[outxcount] = NUL;
  2961.                 debug(F111,"XMIT outxbuf",outxbuf,outxcount);
  2962. /*
  2963.   Now the input character (1 or more bytes) is translated into the output
  2964.   expansion buffer (1 or more bytes); outxcount = number of bytes to add to
  2965.   the TRANSMIT line buffer, which we do here, taking care of parity, SI/SO
  2966.   processing, and quoting Telnet IACs.
  2967. */
  2968.                 for (k = 0; k < outxcount; k++) {
  2969.                     c = outxbuf[k];
  2970.                     if (xmits && parity && (c & 0200)) { /* If shifting */
  2971.                         line[i++] = dopar(SO); /* needs to be done, */
  2972.                         line[i++] = dopar((char)c); /* do it here, */
  2973.                         line[i++] = dopar(SI); /* crudely. */
  2974.                     } else {
  2975.                         line[i++] = dopar((char)c);
  2976. #ifdef TNCODE
  2977.                         if (c == (CHAR)IAC && is_tn)
  2978.                           line[i++] = (CHAR)IAC;
  2979. #endif /* TNCODE */
  2980.                     }
  2981.                 }
  2982.             }
  2983. /*
  2984.   Send characters if buffer full, or at end of line, or at end of file.
  2985.   (End of line only if echoing, waiting for a prompt, or pausing.)
  2986. */
  2987.             debug(F000,"XMIT c",ckitoa(i),c);
  2988.             if (i >= xbufsiz || eof || (eol && (xxecho || xmitw || t))) {
  2989.                 p = line;
  2990.                 line[i] = '\0';
  2991.                 debug(F111,"transmit buf",p,i);
  2992.                 if (ttol((CHAR *)p,i) < 0) { /* try to send it. */
  2993.                     printf("?TRANSMIT output error: %s\n",ck_errstr());
  2994.                     rc = 0;
  2995.                     break;
  2996.                 }
  2997.                 i = 0;                  /* Reset buffer pointer. */
  2998. /*
  2999.   Now we handle the echo.  If the user wants to see it, or if we have to
  3000.   wait for the turnaround character, t.  If the echo is being displayed,
  3001.   and terminal character-set translation is required, we do it here.
  3002. */
  3003.                 if (duplex && xxecho) {  /* If local echo, echo it */
  3004.                     if (parity || cmdmsk == 0x7f) { /* Strip hi bits */
  3005.                         char *ss = line;             /* if necessary */
  3006.                         while (*ss) {
  3007.                             *ss &= 0x7f;
  3008.                             ss++;
  3009.                         }
  3010.                     }
  3011. #ifndef NOLOCAL
  3012. #ifdef OS2
  3013.                     {                   /* Echo to emulator */
  3014.                         char *ss = p;
  3015.                         while (*ss) {
  3016.                             scriptwrtbuf((USHORT)*ss);
  3017.                             ss++;
  3018.                         }
  3019.                     }
  3020. #endif /* OS2 */
  3021. #endif /* NOLOCAL */
  3022.                     if (conoll(p) < 0)
  3023.                       goto xmitfail;
  3024.                 }
  3025.                 if (xmitw)              /* Sleep TRANSMIT PAUSE interval */
  3026.                   msleep(xmitw);
  3027.  
  3028.                 control = 0;            /* Readback loop control */
  3029.                 if (t != 0 && eol)      /* TRANSMIT PROMPT given and at EOL */
  3030.                   control |= 1;
  3031.                 if (xxecho && !duplex)   /* Echo desired and is remote */
  3032.                   control |= 2;
  3033.  
  3034.                 if (control) {          /* Do this if reading back the echo */
  3035.                     int n;
  3036.                     x = 0;
  3037.                     while (1) {
  3038.                         if (control & 1) { /* Termination criterion */
  3039.                             if (x == t)    /* for turnaround */
  3040.                               break;
  3041.                         } else if (control & 2) { /* And for echoing */
  3042.                             if ((n = ttchk()) < 1)
  3043.                               break;
  3044.                         }
  3045.                         if ((x = ttinc(xmitt)) < 0) { /* Read with timeout */
  3046.                             switch (x) {
  3047.                               case -2:
  3048.                                 printf("Connection closed.\n");
  3049.                                 ttclos(1);
  3050.                                 goto xmitfail;
  3051.                               case -3:
  3052.                                 printf(
  3053.                               "Session Limit exceeded - closing connection.\n"
  3054.                                        );
  3055.                                 ttclos(1); /* full thru... */
  3056.                                 goto xmitfail;
  3057.                               default:
  3058.                                 printf("?Timeout\n");
  3059.                                 goto xmitfail;
  3060.                             }
  3061.                         }
  3062.                         if (x > -1 && (control & 2)) { /* Echo any echoes */
  3063.                             if (parity)
  3064.                               x &= 0x7f;
  3065.                             c = x;
  3066. #ifndef NOLOCAL
  3067. #ifdef OS2
  3068.                             scriptwrtbuf((USHORT)x);
  3069. #endif /* OS2 */
  3070. #endif /* NOLOCAL */
  3071.                             inxbuf[0] = c;
  3072.                             inxcount = 1;
  3073. #ifndef NOCSETS
  3074.                             switch (unicode & 3) { /* Remote bits */
  3075.                               case 0:
  3076.                                 if (xlate) {
  3077.                                     if (sxi) c = (*sxi)((CHAR)c);
  3078.                                     if (rxi) c = (*rxi)((CHAR)c);
  3079.                                     inxbuf[0] = c;
  3080.                                 }
  3081.                                 break;
  3082. #ifdef UNICODE
  3083.                               case 1:   /* Remote Byte to local UTF-8 */
  3084.                                 xfu = xl_fcu[tcsr];
  3085.                                 tcssize = fcsinfo[tcsr].size;
  3086.                                 inxcount =
  3087.                                   b_to_u((CHAR)c,
  3088.                                          inxbuf,
  3089.                                          OUTXBUFSIZ,
  3090.                                          tcssize
  3091.                                          );
  3092.                                 break;
  3093.                               case 2:   /* Remote UTF-8 to local Byte */
  3094.                                 xuf = xl_ufc[tcsl];
  3095.                                 x = u_to_b((CHAR)c);
  3096.                                 if (x < 0)
  3097.                                   continue;
  3098.                                 inxbuf[0] = (unsigned)(x & 0xff);
  3099.                                 break;
  3100.                               case 3:   /* UTF-8 to UTF-8 */
  3101.                                 break;
  3102. #endif /* UNICODE */
  3103.                             }
  3104. #endif /* NOCSETS */
  3105.                             inxbuf[inxcount] = NUL;
  3106.                             if (conxo(inxcount,(char *)inxbuf) < 0)
  3107.                               goto xmitfail;
  3108.                         }
  3109.                     }
  3110.                 } else                  /* Not echoing */
  3111.                   ttflui();             /* Just flush input buffer */
  3112.             } /* End of buffer-dumping block */
  3113.         } /* End of text mode */
  3114.         if (eof) {
  3115.             rc = 1;
  3116.             goto xmitexit;
  3117.         }
  3118.     } /* End of character-reading loop */
  3119.  
  3120.   xmitfail:                             /* Failure exit point */
  3121.     rc = 0;
  3122.  
  3123.   xmitexit:                             /* General exit point */
  3124.     if (rc > 0) {
  3125.         if (binary && !xmitw && !xxecho) { /* "blasting"? */
  3126.             while (count > 0) {            /* Partial buffer still to go? */
  3127.                 errno = 0;
  3128.                 y = ttol(xbbuf,count);
  3129.                 if (y < 0) {
  3130.                     printf("?TRANSMIT output error: %s\n",
  3131.                            ck_errstr());
  3132.                     debug(F111,"XMIT binary eof ttol error",
  3133.                           ck_errstr(),errno);
  3134.                     rc = 0;
  3135.                     break;
  3136.                 }
  3137.                 count -= y;
  3138.             }
  3139.         } else if (!binary && *xmitbuf) { /* Anything to send at EOF? */
  3140.             p = xmitbuf;                /* Yes, point to string. */
  3141.             while (*p)                  /* Send it. */
  3142.               ttoc(dopar(*p++));        /* Don't worry about echo here. */
  3143.         }
  3144.     }
  3145.  
  3146. #ifndef AMIGA
  3147. #ifndef MAC
  3148.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3149. #endif /* MAC */
  3150. #endif /* AMIGA */
  3151. #ifdef VMS
  3152.     concb(escape);                      /* Put terminal back, */
  3153. #endif /* VMS */
  3154.     zclose(ZIFILE);                     /* Close file, */
  3155. #ifndef NOCSETS
  3156.     language = langsv;                  /* restore language, */
  3157. #endif /* NOCSETS */
  3158.     ttres();                            /* and terminal modes, */
  3159.     return(rc);                         /* and return successfully. */
  3160. }
  3161. #endif /* NOLOCAL */
  3162. #endif /* NOXMIT */
  3163.  
  3164. #ifndef NOCSETS
  3165.  
  3166. _PROTOTYP( CHAR (*sxx), (CHAR) );       /* Local translation function */
  3167. _PROTOTYP( CHAR (*rxx), (CHAR) );       /* Local translation function */
  3168. _PROTOTYP( CHAR zl1as, (CHAR) );        /* Latin-1 to ascii */
  3169. _PROTOTYP( CHAR xl1as, (CHAR) );        /* ditto */
  3170.  
  3171. /*  X L A T E  --  Translate a local file from one character set to another */
  3172.  
  3173. /*
  3174.   Translates input file (fin) from character set csin to character set csout
  3175.   and puts the result in the output file (fout).  The two character sets are
  3176.   file character sets from fcstab.
  3177. */
  3178.  
  3179. int
  3180. xlate(fin, fout, csin, csout) char *fin, *fout; int csin, csout; {
  3181.  
  3182. #ifndef MAC
  3183. #ifdef OS2
  3184.     extern int k95stdout;
  3185.     extern int wherex[], wherey[];
  3186.     extern unsigned char colorcmd;
  3187. #ifdef NT
  3188.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  3189. #else /* NT */
  3190.     SIGTYP (* volatile oldsig)(int);    /* For saving old interrupt trap. */
  3191. #endif /* NT */
  3192. #else /* OS2 */
  3193.     SIGTYP (* oldsig)();
  3194. #endif /* OS2 */
  3195. #endif /* MAC */
  3196. #ifdef CK_ANSIC
  3197.     int (*fn)(char);                    /* Output function pointer */
  3198. #else
  3199.     int (*fn)();
  3200. #endif /* CK_ANSIC */
  3201.     extern int xlatype;
  3202.     int filecode;                       /* Code for output file */
  3203.     int scrnflg = 0;
  3204.  
  3205.     int z = 1;                          /* Return code. */
  3206.     int x, c, c2;                       /* Workers */
  3207. #ifndef UNICODE
  3208.     int tcs;
  3209. #endif /* UNICODE */
  3210.  
  3211.     ffc = 0L;
  3212.  
  3213.     if (zopeni(ZIFILE,fin) == 0) {      /* Open the file to be translated */
  3214. #ifdef COMMENT
  3215.         /* An error message was already printed by zopeni() */
  3216.         printf("?Can't open input file %s\n",fin);
  3217. #endif /* COMMENT */
  3218.         return(0);
  3219.     }
  3220. #ifdef MAC
  3221. /*
  3222.   If user specified no output file, it goes to the screen.  For the Mac,
  3223.   this must be done a special way (result goes to a new window); the Mac
  3224.   doesn't have a "controlling terminal" device name.
  3225. */
  3226.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZOFILE;
  3227. #else
  3228. #ifdef VMS
  3229.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZMFILE;
  3230. #else
  3231. #ifdef OS2
  3232.     filecode = (!stricmp(fout,"con") || !stricmp(fout,"con:")) ?
  3233.         ZCTERM : ZMFILE;
  3234.     if ((filecode == ZCTERM) && !k95stdout && !inserver)
  3235.         csout = FC_UCS2;
  3236. #else /* OS2 */
  3237.     filecode = ZOFILE;
  3238. #endif /* OS2 */
  3239. #endif /* VMS */
  3240. #endif /* MAC */
  3241.     if (zopeno(filecode,fout,NULL,NULL) == 0) { /* And the output file */
  3242.         printf("?Can't open output file %s\n",fout);
  3243.         return(0);
  3244.     }
  3245. #ifndef AMIGA
  3246. #ifndef MAC
  3247.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  3248. #endif /* MAC */
  3249. #endif /* AMIGA */
  3250.  
  3251.     scrnflg = (filecode == ZCTERM);     /* Set output function */
  3252.     if (scrnflg)
  3253.       fn = NULL;
  3254.     else if (filecode == ZMFILE)
  3255.       fn = putmfil;
  3256.     else
  3257.       fn = putfil;
  3258.  
  3259.     tr_int = 0;                         /* Have not been interrupted (yet). */
  3260.     z = 1;                              /* Return code presumed good. */
  3261.  
  3262.     if (!scrnflg && !quiet)
  3263.       printf(" %s (%s) => %s (%s)\n",   /* Say what we're doing. */
  3264.              fin, fcsinfo[csin].keyword,
  3265.              fout,fcsinfo[csout].keyword
  3266.              );
  3267.  
  3268. #ifndef UNICODE
  3269. /*
  3270.   Non-Unicode picks the "most appropriate" transfer character set as the
  3271.   intermediate set, which results in loss of any characters that the source
  3272.   and target sets have in common, but are lacking from the intermediate set.
  3273. */
  3274. #ifdef KANJI
  3275.     /* Special handling for Japanese... */
  3276.  
  3277.     if (fcsinfo[csin].alphabet == AL_JAPAN ||
  3278.          fcsinfo[csout].alphabet == AL_JAPAN) {
  3279.         USHORT eu;
  3280.         int c, x, y;
  3281.  
  3282.         xpnbyte(-1,0,0,NULL);           /* Reset output machine */
  3283.         xlatype = XLA_JAPAN;
  3284.  
  3285.         while ((c = xgnbyte(FC_JEUC,csin,NULL)) > -1) { /* Get an EUC byte */
  3286.             if (tr_int) {               /* Interrupted? */
  3287.                 printf("^C...\n");      /* Print message */
  3288.                 z = 0;
  3289.                 break;
  3290.             }
  3291.             /* Send EUC byte to output machine */
  3292.             if ((x = xpnbyte(c,TC_JEUC,csout,fn)) < 0) {
  3293.                 z = -1;
  3294.                 break;
  3295.             }
  3296.         }
  3297.         goto xxlate;
  3298.     }
  3299. #endif /* KANJI */
  3300.  
  3301.     /* Regular bytewise conversion... */
  3302.  
  3303.     tcs = gettcs(csin,csout);           /* Get intermediate set. */
  3304.     if (csin == csout) {                /* Input and output sets the same? */
  3305.         sxx = rxx = NULL;               /* If so, no translation. */
  3306.     } else {                            /* Otherwise, set up */
  3307.         if (tcs < 0 || tcs > MAXTCSETS ||
  3308.             csin < 0 || csin > MAXFCSETS ||
  3309.             csout < 0 || csout > MAXFCSETS) {
  3310.             debug(F100,"XLATE csets out of range","",0);
  3311.             sxx = rxx = NULL;
  3312.         } else {
  3313.             sxx = xls[tcs][csin];       /* translation function */
  3314.             rxx = xlr[tcs][csout];      /* pointers. */
  3315.             if (rxx == zl1as) rxx = xl1as;
  3316.         }
  3317.     }
  3318.     while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3319.         if (tr_int) {                   /* Interrupted? */
  3320.             printf("^C...\n");          /* Print message */
  3321.             z = 0;
  3322.             break;
  3323.         }
  3324.         if (sxx) c = (*sxx)((CHAR)c);   /* From fcs1 to tcs */
  3325.         if (rxx) c = (*rxx)((CHAR)c);   /* from tcs to fcs2 */
  3326.         if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3327.             z = -1;
  3328.             break;
  3329.         }
  3330.     }
  3331.     goto xxlate;                        /* Done. */
  3332.  
  3333. #else  /* UNICODE */
  3334. /*
  3335.    Use Unicode as the intermediate character set.  It's simple and gives
  3336.    little or no loss, but the overhead is a bit higher.
  3337. */
  3338.     initxlate(csin,csout);              /* Set up translation functions */
  3339.  
  3340.     if (xlatype == XLA_NONE) {
  3341.         while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3342.             if (tr_int) {               /* Interrupted? */
  3343.                 printf("^C...\n");      /* Print message */
  3344.                 z = 0;
  3345.                 break;
  3346.             }
  3347.             if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3348.                 z = -1;
  3349.                 break;
  3350.             }
  3351.         }
  3352.         goto xxlate;                    /* Done. */
  3353.     }
  3354.  
  3355.  
  3356. #ifndef NOLOCAL
  3357. #ifdef OS2
  3358.     if (csout == FC_UCS2 &&             /* we're translating to UCS-2 */
  3359.         filecode == ZCTERM &&           /* for the real screen... */
  3360.         !k95stdout && !inserver
  3361.         ) {
  3362.         union {
  3363.             USHORT ucs2;
  3364.             UCHAR  bytes[2];
  3365.         } output;
  3366.  
  3367.         while (1) {                     /* In this case we go two-by-two. */
  3368.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3369.               break;
  3370.             output.bytes[0] = c;
  3371.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3372.               break;
  3373.             output.bytes[1] = c;
  3374.  
  3375.             if (tr_int) {               /* Interrupted? */
  3376.                 printf("^C...\n");      /* Print message */
  3377.                 z = 0;
  3378.                 break;
  3379.             }
  3380.  
  3381.             VscrnWrtUCS2StrAtt(VCMD,
  3382.                                &output.ucs2,
  3383.                                1,
  3384.                                wherey[VCMD],
  3385.                                wherex[VCMD],
  3386.                                &colorcmd
  3387.                                );
  3388.         }
  3389.     } else
  3390. #endif /* OS2 */
  3391. #endif /* NOLOCAL */
  3392.  
  3393.       /* General case: Get next byte translated from fcs to UCS-2 */
  3394.  
  3395. #ifdef COMMENT
  3396.       while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1 &&
  3397.               (c2 = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3398.           extern int fileorder;
  3399.  
  3400.           if (tr_int) {                 /* Interrupted? */
  3401.               printf("^C...\n");        /* Print message */
  3402.               z = 0;
  3403.               break;
  3404.           }
  3405.           debug(F001,"XLATE c","",c);
  3406.           debug(F001,"XLATE c2","",c2);
  3407.  
  3408.           /* And then send UCS-2 byte to translate-and-output machine */
  3409.  
  3410.           if ((x = xpnbyte(fileorder?c2:c,TC_UCS2,csout,fn)) < 0) {
  3411.               z = -1;
  3412.               break;
  3413.           }
  3414.           if ((x = xpnbyte(fileorder?c:c2,TC_UCS2,csout,fn)) < 0) {
  3415.               z = -1;
  3416.               break;
  3417.           }
  3418.       }
  3419. #else
  3420.     while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3421.           if (tr_int) {                 /* Interrupted? */
  3422.               printf("^C...\n");        /* Print message */
  3423.               z = 0;
  3424.               break;
  3425.           }
  3426.           if ((x = xpnbyte(c,TC_UCS2,csout,fn)) < 0) {
  3427.               z = -1;
  3428.               break;
  3429.           }
  3430.       }
  3431. #endif /* COMMENT */
  3432.  
  3433. #endif /* UNICODE */
  3434.  
  3435.   xxlate:                               /* Common exit point */
  3436.  
  3437. #ifndef AMIGA
  3438. #ifndef MAC
  3439.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3440. #endif /* MAC */
  3441. #endif /* AMIGA */
  3442.     tr_int = 0;
  3443.     if (z < 0) {
  3444.         if (z == -1)
  3445.           printf("?File output error: %s\n",ck_errstr());
  3446.         z = 0;
  3447.     }
  3448.     zclose(ZIFILE);                     /* Close files */
  3449.     zclose(filecode);                   /* ... */
  3450.     return(success = z);                /* and return status. */
  3451. }
  3452.  
  3453. int
  3454. doxlate() {
  3455. #ifdef OS2ONLY
  3456.     extern int tt_font;
  3457. #endif /* OS2ONLY */
  3458. #ifdef UNIX
  3459.     extern char ** mtchs;               /* zxpand() file list */
  3460. #endif /* UNIX */
  3461.     extern int nfilc;
  3462.     extern struct keytab fcstab[];
  3463.     int x, y, incs, outcs, multiple = 0, wild = 0, fc = 0, len = 0;
  3464.     int ofisdir = 0;
  3465.     char * s, * tocs = "";
  3466.  
  3467.     if ((x = cmifi("File(s) to translate","",&s,&wild,xxstring)) < 0) {
  3468.         if (x == -3) {
  3469.             printf("?Name of an existing file\n");
  3470.             return(-9);
  3471.         } else
  3472.           return(x);
  3473.     }
  3474.     ckstrncpy(line,s,LINBUFSIZ);        /* Save copy of string just parsed. */
  3475.  
  3476.     if ((incs = cmkey(fcstab,nfilc,"from character-set","",xxstring)) < 0)
  3477.       return(incs);
  3478.  
  3479. #ifdef OS2
  3480.     if (isunicode())
  3481.       tocs = "ucs2";
  3482.     else
  3483. #endif /* OS2 */
  3484.       tocs = getdcset();
  3485.  
  3486.     if ((outcs = cmkey(fcstab,nfilc,"to character-set",tocs,xxstring)) < 0)
  3487.       return(outcs);
  3488.     if ((x = cmofi("output file",CTTNAM,&s,xxstring)) < 0) return(x);
  3489.     if (x > 1)
  3490.       ofisdir = 1;
  3491.  
  3492.     len = ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  3493.     if ((y = cmcfm()) < 0) return(y);   /* Confirm the command */
  3494.  
  3495.     if (len < 1)
  3496.       return(-2);
  3497.  
  3498.     if (ofisdir)
  3499.       multiple = 2;
  3500.     else if (wild) {
  3501.         if (isdir(tmpbuf))
  3502.           multiple = 2;
  3503.         else if (!strcmp(tmpbuf,CTTNAM))
  3504.           multiple = 1;
  3505. #ifdef OS2
  3506.         else if (!stricmp(tmpbuf,"con") || !stricmp(tmpbuf,"con:"))
  3507.           multiple = 1;
  3508. #else
  3509. #ifdef UNIXOROSK
  3510.         else if (!strncmp(tmpbuf,"/dev/",4))
  3511.           multiple = 1;
  3512. #endif /* UNIXOROSK */
  3513. #endif /* OS2 */
  3514.         if (!multiple) {
  3515.             printf("?A single file please\n");
  3516.             return(-9);
  3517.         }
  3518.     }
  3519.     if (!multiple) {                    /* Just one file */
  3520.         return(success = xlate(line,tmpbuf,incs,outcs));
  3521.     } else {                            /* Translate multiple files */
  3522.         char dirbuf[CKMAXPATH+4];
  3523.         int k;
  3524. #ifndef ZXREWIND
  3525.         int flags = ZX_FILONLY;
  3526. #endif /* ZXREWIND */
  3527.  
  3528.         if (multiple == 2) {            /* Target is a directory */
  3529.             k = ckstrncpy(dirbuf,tmpbuf,CKMAXPATH+1) - 1;
  3530.             if (k < 0)
  3531.               return(-2);
  3532. #ifdef OS2ORUNIX
  3533.             if (dirbuf[k] != '/') {
  3534.                 dirbuf[k+1] = '/';
  3535.                 dirbuf[k+2] = NUL;
  3536.             }
  3537. #else
  3538. #ifdef OSK
  3539.             if (dirbuf[k] != '/') {
  3540.                 dirbuf[k+1] = '/';
  3541.                 dirbuf[k+2] = NUL;
  3542.             }
  3543. #else
  3544. #ifdef VMS
  3545.             if (ckmatch("*.DIR;1",s,0,0))
  3546.               k = cvtdir(tmpbuf,dirbuf,TMPBUFSIZ);
  3547.             if (dirbuf[k] != ']' &&
  3548.                 dirbuf[k] != '>' &&
  3549.                 dirbuf[k] != ':')
  3550.               return(-2);
  3551. #else
  3552. #ifdef datageneral
  3553.             if (dirbuf[k] != ':') {
  3554.                 dirbuf[k+1] = ':';
  3555.                 dirbuf[k+2] = NUL;
  3556.             }
  3557. #else
  3558. #ifdef STRATUS
  3559.             if (dirbuf[k] != '>') {
  3560.                 dirbuf[k+1] = '>';
  3561.                 dirbuf[k+2] = NUL;
  3562.             }
  3563. #endif /* STRATUS */
  3564. #endif /* datageneral */
  3565. #endif /* VMS */
  3566. #endif /* OSK */
  3567. #endif /* OS2ORUNIX */
  3568.         }
  3569.  
  3570. #ifdef ZXREWIND
  3571.         fc = zxrewind();                /* Rewind the file list */
  3572. #else
  3573.         if (matchdot)  flags |= ZX_MATCHDOT;
  3574.         fc = nzxpand(line,flags);
  3575. #endif /* ZXREWIND */
  3576.  
  3577.         if (fc < 1) {
  3578.             printf("?Wildcard expansion error\n");
  3579.             return(-9);
  3580.         }
  3581. #ifdef UNIX
  3582.         sh_sort(mtchs,NULL,fc,0,0,filecase); /* Sort the file list */
  3583. #endif /* UNIX */
  3584.  
  3585.         while (1) {                     /* Loop through the files */
  3586.             znext(line);
  3587.             if (!line[0])
  3588.               break;
  3589.             if (multiple == 2)
  3590.               ckmakmsg(tmpbuf,TMPBUFSIZ,dirbuf,line,NULL,NULL);
  3591.             if (xlate(line,tmpbuf,incs,outcs) < 1)
  3592.               return(success = 0);
  3593.         }
  3594.     }
  3595.     return(success = 1);
  3596. }
  3597. #endif /* NOCSETS */
  3598.  
  3599. static char hompthbuf[CKMAXPATH+1];
  3600.  
  3601. char *
  3602. homepath() {
  3603.     int x;
  3604.     extern char * myhome;
  3605.     char * h;
  3606.  
  3607.     h = myhome ? myhome : zhome();
  3608.     hompthbuf[0] = NUL;
  3609. #ifdef UNIXOROSK
  3610.     x = ckstrncpy(hompthbuf,h,CKMAXPATH+1);
  3611.     if (x <= 0) {
  3612.         hompthbuf[0] = '/';
  3613.         hompthbuf[1] = NUL;
  3614.     } else if (x < CKMAXPATH - 2 && hompthbuf[x-1] != '/') {
  3615.         hompthbuf[x] = '/';
  3616.         hompthbuf[x+1] = NUL;
  3617.     }
  3618.     return(hompthbuf);
  3619. #else
  3620. #ifdef STRATUS
  3621.     if (strlen(h) < CKMAXPATH)
  3622.       sprintf(hompthbuf,"%s>",h);    /* SAFE */
  3623.     return(hompthbuf);
  3624. #else
  3625.     return(h);
  3626. #endif /* STRATUS */
  3627. #endif /* UNIXOROSK */
  3628. }
  3629.  
  3630. /*  D O L O G  --  Do the log command  */
  3631.  
  3632. int
  3633. dolog(x) int x; {
  3634.     int y, disp; char *s = NULL, * p = NULL, * q = NULL;
  3635.     extern int isguest;
  3636. #ifdef ZFNQFP
  3637.     struct zfnfp * fnp;
  3638. #endif /* ZFNQFP */
  3639.  
  3640.     if (isguest) {
  3641.         printf("?Anonymous log creation not allowed\n");
  3642.         return(-9);
  3643.     }
  3644.     switch (x) {                        /* Which log... */
  3645.  
  3646. #ifdef DEBUG
  3647.       case LOGD:
  3648.         q = "debug.log";
  3649.         y = cmofi("Name of debugging log file",q,&s,xxstring);
  3650.         break;
  3651. #endif /* DEBUG */
  3652.  
  3653.       case LOGP:
  3654.         q = "packet.log";
  3655.         y = cmofi("Name of packet log file",q,&s,xxstring);
  3656.         break;
  3657.  
  3658. #ifndef NOLOCAL
  3659.       case LOGS:
  3660.         q = "session.log";
  3661.         y = cmofi("Name of session log file",q,&s,xxstring);
  3662.         break;
  3663. #endif /* NOLOCAL */
  3664.  
  3665. #ifdef TLOG
  3666.       case LOGT:
  3667.         q = "transact.log";
  3668.         y = cmofi("Name of transaction log file",q,&s,xxstring);
  3669.         break;
  3670. #endif /* TLOG */
  3671.  
  3672. #ifdef CKLOGDIAL
  3673.       case LOGM: {
  3674.           int m, n;
  3675.           char mypath[CKMAXPATH+1];
  3676.           q = CXLOGFILE;
  3677.           m = ckstrncpy(mypath,homepath(),CKMAXPATH);
  3678.           n = strlen(CXLOGFILE);
  3679.           if (m + n < CKMAXPATH)
  3680.             ckstrncat(mypath,CXLOGFILE,CKMAXPATH);
  3681.           else
  3682.             ckstrncpy(mypath,CXLOGFILE,CKMAXPATH);
  3683.           y = cmofi("Name of connection log file",mypath,&s,xxstring);
  3684.           break;
  3685.       }
  3686. #endif /* CKLOGDIAL */
  3687.  
  3688.       default:
  3689.         printf("\n?Unknown log designator - %d\n",x);
  3690.         return(-2);
  3691.     }
  3692.     if (y < 0) return(y);
  3693.     if (y == 2) {                       /* If they gave a directory name */
  3694.         int k;
  3695.         char * ds = "/";
  3696.         k = strlen(s);
  3697.         if (k > 0 && s[k-1] == '/') ds = "";
  3698.         ckmakmsg(tmpbuf,TMPBUFSIZ,s,ds,q,NULL);
  3699.         s = tmpbuf;
  3700.     }
  3701. #ifdef ZFNQFP
  3702. #ifdef OS2ORUNIX
  3703.     if (*s != '|')                      /* Allow for pipes */
  3704. #else
  3705. #ifdef OSK
  3706.     if (*s != '|')
  3707. #endif /* OSK */
  3708. #endif /* OS2ORUNIX */
  3709.       if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3710.           if (fnp->fpath)
  3711.             if ((int) strlen(fnp->fpath) > 0)
  3712.               s = fnp->fpath;
  3713.       } /* else if error keep original string */
  3714. #endif /* ZFNQFP */
  3715.  
  3716.     ckstrncpy(line,s,LINBUFSIZ);
  3717.     s = line;
  3718. #ifdef MAC
  3719.     y = 0;
  3720. #else
  3721.  
  3722.     p = "new";
  3723. #ifdef TLOG
  3724.     if ((x == LOGT && tlogfmt == 2) || x == LOGM)
  3725.       p = "append";
  3726. #endif /* TLOG */
  3727.  
  3728.     if ((y = cmkey(disptb,2,"Disposition",p,xxstring)) < 0)
  3729.       return(y);
  3730. #endif /* MAC */
  3731.     disp = y;
  3732.     if ((y = cmcfm()) < 0) return(y);
  3733.  
  3734.     switch (x) {
  3735.  
  3736. #ifdef DEBUG
  3737.       case LOGD:
  3738.         return(deblog = debopn(s,disp));
  3739. #endif /* DEBUG */
  3740.  
  3741. #ifndef NOXFER
  3742.       case LOGP:
  3743.         return(pktlog = pktopn(s,disp));
  3744. #endif /* NOXFER */
  3745.  
  3746. #ifndef NOLOCAL
  3747.       case LOGS:
  3748.         setseslog(sesopn(s,disp));
  3749.         return(seslog);
  3750. #endif /* NOLOCAL */
  3751.  
  3752. #ifdef TLOG
  3753.       case LOGT:
  3754.         return(tralog = traopn(s,disp));
  3755. #endif /* TLOG */
  3756.  
  3757. #ifdef CKLOGDIAL
  3758.       case LOGM:
  3759.         return(dialog = diaopn(s,disp,0));
  3760. #endif /* CKLOGDIAL */
  3761.  
  3762.       default:
  3763.         return(-2);
  3764.     }
  3765. }
  3766.  
  3767. #ifndef NOXFER
  3768. int
  3769. pktopn(s,disp) char *s; int disp; {
  3770.     static struct filinfo xx;
  3771.  
  3772.     if (!s)
  3773.       s = "";
  3774.     if (!*s)
  3775.       return(0);
  3776.  
  3777.     debug(F111,"pktopn",s,disp);
  3778.  
  3779.     zclose(ZPFILE);
  3780.  
  3781. #ifdef OS2ORUNIX
  3782.     if (s[0] == '|') {                  /* Pipe */
  3783.         char * p = s + 1;
  3784.         debug(F110,"pktopn p",p,0);
  3785.         while (*p) {
  3786.             if (*p != ' ')
  3787.               break;
  3788.             else
  3789.               p++;
  3790.         }
  3791.         debug(F110,"pktopn pipe",p,0);
  3792.         pktlog = zxcmd(ZPFILE,p);
  3793.         debug(F101,"pktopn seslog","",seslog);
  3794.     } else {                            /* File */
  3795. #endif /* OS2ORUNIX */
  3796.         if (disp) {
  3797.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3798.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3799.             xx.lblopts = 0;
  3800.             pktlog = zopeno(ZPFILE,s,NULL,&xx);
  3801.         } else pktlog = zopeno(ZPFILE,s,NULL,NULL);
  3802.         if (!pktlog && !quiet)
  3803.           printf("?%s - %s\n",s,ck_errstr());
  3804. #ifdef OS2ORUNIX
  3805.     }
  3806. #endif /* OS2ORUNIX */
  3807.     if (pktlog > 0)
  3808.       ckstrncpy(pktfil,s,CKMAXPATH+1);
  3809.     else
  3810.       *pktfil = '\0';
  3811.     return(pktlog);
  3812. }
  3813. #endif /* NOXFER */
  3814.  
  3815. int
  3816. traopn(s,disp) char *s; int disp; {
  3817. #ifdef TLOG
  3818.     static struct filinfo xx;
  3819.  
  3820.     if (!s)
  3821.       s = "";
  3822.     if (!*s)
  3823.       return(0);
  3824.  
  3825.     debug(F111,"traopn",s,disp);
  3826.     debug(F101,"traopn tlogfmt","",tlogfmt);
  3827.  
  3828.     zclose(ZTFILE);
  3829.  
  3830. #ifdef OS2ORUNIX
  3831.     if (tlogfmt == 2) {                 /* FTP format is special... */
  3832.         VOID doiklog();
  3833.         if (!disp)                      /* Append? */
  3834.           if (zchki(s) > -1)            /* No - does file exist? */
  3835.             (VOID) zdelet(s);           /* Yes - delete it. */
  3836.         xferlog = 1;
  3837.         ckstrncpy(trafil,s,CKMAXPATH);
  3838.         makestr(&xferfile,s);
  3839.         doiklog();
  3840.         return(1);
  3841.     }
  3842.     if (s[0] == '|') {                  /* Pipe */
  3843.         char * p = s + 1;
  3844.         debug(F110,"traopn p",p,0);
  3845.         while (*p) {
  3846.             if (*p != ' ')
  3847.               break;
  3848.             else
  3849.               p++;
  3850.         }
  3851.         debug(F110,"traopn pipe",p,0);
  3852.         tralog = zxcmd(ZTFILE,p);
  3853.         debug(F101,"traopn tralog","",tralog);
  3854.     }
  3855. #endif /* OS2ORUNIX */
  3856.  
  3857.     if (s[0] != '|') {                  /* File */
  3858.         if (disp) {
  3859.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3860.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3861.             xx.lblopts = 0;
  3862.             tralog = zopeno(ZTFILE,s,NULL,&xx);
  3863.         } else tralog = zopeno(ZTFILE,s,NULL,NULL);
  3864.     }
  3865.     if (!tralog && !quiet)
  3866.       printf("?%s - %s\n",s,ck_errstr());
  3867.     if (tralog > 0 && tlogfmt > 0) {
  3868.         ckstrncpy(trafil,s,CKMAXPATH);
  3869.         tlog(F110,"Transaction Log:",versio,0L);
  3870. #ifndef MAC
  3871.         tlog(F100,ckxsys,"",0L);
  3872. #endif /* MAC */
  3873.         ztime(&s);
  3874.         tlog(F100,s,"",0L);
  3875.     } else
  3876.       *trafil = '\0';
  3877.     return(tralog);
  3878. #else
  3879.     return(0);
  3880. #endif /* TLOG */
  3881. }
  3882.  
  3883. #ifndef NOLOCAL
  3884. int
  3885. sesopn(s,disp) char * s; int disp; {
  3886.     static struct filinfo xx;
  3887.     extern int tsstate;
  3888.  
  3889.     tsstate = 0;                        /* Session log timestamp state */
  3890.  
  3891.     if (!s)
  3892.       s = "";
  3893.     if (!*s)
  3894.       return(0);
  3895.  
  3896.     debug(F111,"sesopn",s,disp);
  3897.  
  3898.     zclose(ZSFILE);
  3899.  
  3900. #ifdef OS2ORUNIX
  3901.     if (s[0] == '|') {                  /* Pipe */
  3902.         char * p = s + 1;
  3903.         debug(F110,"sesopn p",p,0);
  3904.         while (*p) {
  3905.             if (*p != ' ')
  3906.               break;
  3907.             else
  3908.               p++;
  3909.         }
  3910.         debug(F110,"sesopn pipe",p,0);
  3911.         setseslog(zxcmd(ZSFILE,p));
  3912.         debug(F101,"sesopn seslog","",seslog);
  3913.     } else {                            /* File */
  3914. #endif /* OS2ORUNIX */
  3915.         if (disp) {
  3916.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3917.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3918.             xx.lblopts = 0;
  3919.             setseslog(zopeno(ZSFILE,s,NULL,&xx));
  3920.         } else
  3921.           setseslog(zopeno(ZSFILE,s,NULL,NULL));
  3922.         if (!seslog && !quiet)
  3923.           printf("?%s - %s\n",s,ck_errstr());
  3924. #ifdef OS2ORUNIX
  3925.     }
  3926. #endif /* OS2ORUNIX */
  3927.     if (seslog > 0)
  3928.       ckstrncpy(sesfil,s,CKMAXPATH+1);
  3929.     else
  3930.       *sesfil = '\0';
  3931.     return(seslog);
  3932. }
  3933. #endif /* NOLOCAL */
  3934. #endif /* NOICP */
  3935.  
  3936. int
  3937. debopn(s,disp) char *s; int disp; {
  3938. #ifdef DEBUG
  3939. #ifdef CK_UTSNAME
  3940.     extern char unm_mch[], unm_nam[], unm_rel[], unm_ver[], unm_mod[];
  3941. #endif /* CK_UTSNAME */
  3942. #ifdef OS2
  3943.     extern char ckxsystem[];
  3944. #endif /* OS2 */
  3945.     char *tp;
  3946.     static struct filinfo xx;
  3947.  
  3948.     if (!s)
  3949.       s = "";
  3950.     if (!*s)
  3951.       return(0);
  3952.  
  3953.     zclose(ZDFILE);
  3954.  
  3955. #ifdef OS2ORUNIX
  3956.     if (s[0] == '|') {                  /* Pipe */
  3957.         char * p = s + 1;
  3958.         debug(F110,"debopn p",p,0);
  3959.         while (*p) {
  3960.             if (*p != ' ')
  3961.               break;
  3962.             else
  3963.               p++;
  3964.         }
  3965.         debug(F110,"debopn pipe",p,0);
  3966.         deblog = zxcmd(ZDFILE,p);
  3967.         debug(F101,"debopn deblog","",deblog);
  3968.     } else {                            /* File */
  3969. #endif /* OS2ORUNIX */
  3970.         if (disp) {
  3971.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3972.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3973.             xx.lblopts = 0;
  3974.             deblog = zopeno(ZDFILE,s,NULL,&xx);
  3975.         } else
  3976.           deblog = zopeno(ZDFILE,s,NULL,NULL);
  3977.         if (!deblog && !quiet)
  3978.           printf("?%s - %s\n",s,ck_errstr());
  3979. #ifdef OS2ORUNIX
  3980.     }
  3981. #endif /* OS2ORUNIX */
  3982.     if (deblog > 0) {
  3983.         ckstrncpy(debfil,s,CKMAXPATH+1);
  3984.         debug(F110,"Debug Log ",versio,0);
  3985. #ifndef MAC
  3986. #ifdef OS2
  3987.         debug(F110,ckxsys,ckxsystem,0);
  3988. #else /* OS2 */
  3989.         debug(F100,ckxsys,"",0);
  3990. #endif /* OS2 */
  3991. #endif /* MAC */
  3992. #ifdef CK_UTSNAME
  3993.         if (unm_mch[0]) {
  3994.             debug(F110,"uname machine",unm_mch,0);
  3995.             if (unm_mod[0])
  3996.               debug(F110,"uname model  ",unm_mod,0);
  3997.             debug(F110,"uname sysname",unm_nam,0);
  3998.             debug(F110,"uname release",unm_rel,0);
  3999.             debug(F110,"uname version",unm_ver,0);
  4000.         }
  4001. #ifdef KTARGET
  4002.         {
  4003.             char * s;                   /* Makefile target */
  4004.             s = KTARGET;
  4005.             if (!s) s = "";
  4006.             if (!*s) s = "(unknown)";
  4007.             debug(F110,"build target",s,0);
  4008.         }
  4009. #endif /* KTARGET */
  4010.         deblog = 0;
  4011.         ztime(&tp);
  4012.         deblog = 1;
  4013.         debug(F100,tp,"",0);
  4014. #endif /* UTSNAME */
  4015.         debug(F101,"byteorder","",byteorder);
  4016. #ifndef NOICP
  4017. #ifndef NOLOCAL
  4018.         if (local) {
  4019.             debug(F110,"Active connection: ",ttname,0);
  4020.             if (!network) {
  4021.                 debug(F101,"Speed","",speed);
  4022.                 if (hwparity)
  4023.                   debug(F110,"Parity[hardware]",parnam((char)hwparity),0);
  4024.                 else
  4025.                   debug(F110,"Parity",parnam((char)parity),0);
  4026.                 deblog = 0;
  4027.                 debug(F110,"Modem",gmdmtyp(),0);
  4028.                 deblog = 1;
  4029.             }
  4030.         } else {
  4031.             debug(F110,"Active connection: ","none",0);
  4032.         }
  4033. #endif /* NOLOCAL */
  4034. #endif /* NOICP */
  4035.     } else *debfil = '\0';
  4036.     return(deblog);
  4037. #else
  4038.     return(0);
  4039. #endif /* MAC */
  4040. }
  4041.  
  4042.  
  4043. /*  C K D A T E  --  Returns current date/time in standard format  */
  4044.  
  4045. static char nowbuf[18];
  4046.  
  4047. char *
  4048. ckdate() {
  4049.     extern struct keytab cmonths[];
  4050.     int x;
  4051.     char * t;                   /* Substitute today's date */
  4052.     char dbuf[32];
  4053.     ztime(&t);
  4054.  
  4055. /*  012345678901234567890123 */
  4056. /*  Sat Jul  4 12:16:43 1998 */
  4057.  
  4058.     ckstrncpy(dbuf,t,32);
  4059.     t = dbuf;
  4060.     debug(F110,"ckdate dbuf",dbuf,0);
  4061.     nowbuf[0] = t[20];
  4062.     nowbuf[1] = t[21];
  4063.     nowbuf[2] = t[22];
  4064.     nowbuf[3] = t[23];
  4065.  
  4066.     nowbuf[4] = NUL;
  4067.     debug(F110,"ckdate nowbuf",nowbuf,0);
  4068.  
  4069.     t[7] = NUL;
  4070.     if ((x = lookup(cmonths,t+4,12,NULL)) < 0) {
  4071.         debug(F110,"ckdate bad month",t,0);
  4072.         return("<BAD_MONTH>");
  4073.     }
  4074.     sprintf(nowbuf+4,"%02d",x);         /* SAFE */
  4075.     nowbuf[6] = (t[8] == SP) ? '0' : t[8];
  4076.     nowbuf[7] = t[9];
  4077.     nowbuf[8] = ' ';
  4078.  
  4079.     nowbuf[9] = NUL;
  4080.     debug(F110,"ckdate nowbuf",nowbuf,0);
  4081.  
  4082.     for (x = 11; x < 19; x++) nowbuf[x-2] = t[x];
  4083.     nowbuf[17] = NUL;
  4084.     debug(F110,"ckdate nowbuf",nowbuf,0);
  4085.  
  4086.     return((char *)nowbuf);
  4087. }
  4088.  
  4089. #ifndef NOICP
  4090. #ifdef CKLOGDIAL
  4091.  
  4092. /*
  4093.   fc = 0 for initial open, meaning open, then close immediately.
  4094.   fc > 0 for subsequent opens, meaning open for use, leave open.
  4095. */
  4096. int
  4097. diaopn(s,disp,fc) char *s; int disp, fc; {
  4098.     static struct filinfo xx;
  4099.  
  4100.     if (!s)
  4101.       s = "";
  4102.     if (!*s)
  4103.       return(0);
  4104.  
  4105.     debug(F110,"diaopn log",s,0);
  4106.     debug(F101,"diaopn fc",s,fc);
  4107.     debug(F101,"diaopn disp 1",s,disp);
  4108.     if (fc) disp = 1;                   /* Force append if open for use */
  4109.     debug(F101,"diaopn disp 2",s,disp);
  4110.  
  4111.     zclose(ZDIFIL);                     /* In case a log was already open */
  4112.  
  4113. #ifdef OS2ORUNIX
  4114.     if (s[0] == '|') {                  /* Pipe */
  4115.         char * p = s + 1;
  4116.         debug(F110,"diaopn p",p,0);
  4117.         while (*p) {
  4118.             if (*p != ' ')
  4119.               break;
  4120.             else
  4121.               p++;
  4122.         }
  4123.         debug(F110,"diaopn pipe",p,0);
  4124.         dialog = zxcmd(ZDIFIL,p);
  4125.         debug(F101,"diaopn dialog","",dialog);
  4126.     } else {                            /* File */
  4127. #endif /* OS2ORUNIX */
  4128.         if (disp) {
  4129.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  4130.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  4131.             xx.lblopts = 0;
  4132.             dialog = zopeno(ZDIFIL,s,NULL,&xx);
  4133.         } else dialog = zopeno(ZDIFIL,s,NULL,NULL);
  4134.         if (!dialog)
  4135.           printf("?%s - %s\n",s,ck_errstr());
  4136. #ifdef OS2ORUNIX
  4137.     }
  4138. #endif /* OS2ORUNIX */
  4139.     if (dialog > 0)
  4140.       ckstrncpy(diafil,s,CKMAXPATH+1);
  4141.     else
  4142.       *diafil = '\0';
  4143.     if (fc == 0)                        /* Initial open */
  4144.       zclose(ZDIFIL);                   /* close it */
  4145.     return(dialog);
  4146. }
  4147. #endif /* CKLOGDIAL */
  4148.  
  4149. #ifndef NOSHOW
  4150.  
  4151. /*  SHOW command routines */
  4152.  
  4153. char *
  4154. shoxm() {
  4155.     char * s;
  4156.     switch (binary) {
  4157.       case XYFT_T: s = "text";         break;
  4158. #ifdef VMS
  4159.       case XYFT_B: s = "binary fixed"; break;
  4160.       case XYFT_I: s = "image";        break;
  4161.       case XYFT_L: s = "labeled";      break;
  4162.       case XYFT_U: s = "binary undef"; break;
  4163. #else
  4164. #ifdef MAC
  4165.       case XYFT_B: s = "binary";       break;
  4166.       case XYFT_M: s = "macbinary";    break;
  4167. #else
  4168.       case XYFT_B: s = "binary";       break;
  4169. #ifdef CK_LABELED
  4170.       case XYFT_L: s = "labeled";      break;
  4171. #endif /* CK_LABELED */
  4172. #endif /* MAC */
  4173. #endif /* VMS */
  4174.       default: s = "unknown"; break;
  4175.     }
  4176.     return(s);
  4177. }
  4178.  
  4179. #ifndef NOXFER
  4180. VOID                                    /* SHOW TRANSFER */
  4181. shoxfer() {
  4182.     extern int docrc, usepipes, xfrxla, whereflg;
  4183.     extern char * xfrmsg;
  4184.     printf("\n");
  4185.     printf(" Transfer Bell: %s\n",showoff(xfrbel));
  4186.     printf(" Transfer Interruption: %s\n",showoff(xfrint));
  4187.     printf(" Transfer Cancellation: %s\n",showoff(xfrcan));
  4188. #ifndef NOCSETS
  4189.     printf(" Transfer Translation:  %s\n",showoff(xfrxla));
  4190.     printf(" Transfer Character-set: ");
  4191.     if (tcharset == TC_TRANSP)
  4192.       printf("Transparent\n");
  4193.     else
  4194.       printf("%s\n",tcsinfo[tcharset].keyword);
  4195. #endif /* NOCSETS */
  4196.     printf(" Transfer CRC-calculation: %s\n",showoff(docrc));
  4197.     printf(" Transfer Display: ");
  4198.     switch (fdispla) {
  4199.       case XYFD_N: printf("%s\n","none"); break;
  4200.       case XYFD_R: printf("%s\n","serial"); break;
  4201.       case XYFD_C: printf("%s\n","fullscreen"); break;
  4202.       case XYFD_S: printf("%s\n","crt"); break;
  4203.       case XYFD_B: printf("%s\n","brief"); break;
  4204.       case XYFD_G: printf("%s\n","gui"); break;
  4205.     }
  4206.     printf(" Transfer Message: %s\n", xfrmsg ? xfrmsg : "(none)");
  4207.     printf(" Transfer Locking-shift: ");
  4208.     if (lscapu == 2) {
  4209.         printf("forced");
  4210.     } else {
  4211.         printf("%s", (lscapr ? "enabled" : "disabled"));
  4212.         if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  4213.     }
  4214.     printf("\n Transfer Mode: %s\n",
  4215.            xfermode == XMODE_A ?
  4216.            "automatic" :
  4217.            "manual"
  4218.            );
  4219.     printf(" Transfer Pipes: %s\n", showoff(usepipes));
  4220.     printf(" Transfer Protocol: %s\n",ptab[protocol].p_name);
  4221.     printf(" Transfer Report: %s\n",showoff(whereflg));
  4222.     printf(" Transfer Slow-start: %s\n",showoff(slostart));
  4223.     printf("\n");
  4224. }
  4225. #endif /* NOXFER */
  4226.  
  4227. VOID
  4228. shoflow() {
  4229.     int i, x;
  4230.     extern int cxflow[], cxtype, ncxname, nfloname, autoflow;
  4231.     extern char * cxname[];
  4232.     printf("\nConnection type:        %s\n",cxname[cxtype]);
  4233.     if (autoflow) {
  4234.         printf("Current flow-control:   %s\n", floname[cxflow[cxtype]]);
  4235.         printf("Switches automatically: yes\n");
  4236.     } else {
  4237.         printf("Current flow-control:   %s\n", floname[flow]);
  4238.         printf("Switches automatically: no\n");
  4239.     }
  4240.     printf("\nDefaults by connection type:\n");
  4241.     debug(F111,"shoflow cxtype",cxname[cxtype],cxtype);
  4242.     debug(F101,"shoflow flow","",flow);
  4243.     for (i = 0; i < ncxname; i++) {
  4244. #ifdef NOLOCAL
  4245.         if (i > 0) break;
  4246. #endif /* NOLOCAL */
  4247. #ifndef NETCONN
  4248.         if (i > 2) break;
  4249. #endif /* NETCONN */
  4250. #ifndef DECNET
  4251.         if (i == CXT_DECNET) continue;
  4252. #endif /* DECNET */
  4253. #ifndef DECNET
  4254. #ifndef SUPERLAT
  4255.         if (i == CXT_LAT) continue;
  4256. #endif /* SUPERLAT */
  4257. #endif /* DECNET */
  4258. #ifndef CK_NETBIOS
  4259.         if (i == CXT_NETBIOS) continue;
  4260. #endif /* CK_NETBIOS */
  4261. #ifndef NPIPE
  4262.         if (i == CXT_NPIPE) continue;
  4263. #endif /* NPIPE */
  4264. #ifndef NETCMD
  4265.         if (i == CXT_PIPE) continue;
  4266. #endif /* NETCMD */
  4267. #ifndef ANYX25
  4268.         if (i == CXT_X25) continue;
  4269. #endif /* ANYX25 */
  4270.         x = cxflow[i];
  4271.         debug(F101,"shoflow x","",x);
  4272.         if (x < nfloname)
  4273.           printf("  %-14s: %s\n",cxname[i],floname[x]);
  4274.         else
  4275.           printf("  %-14s: (%d)\n",cxname[i],x);
  4276.     }
  4277.     printf("\n");
  4278. }
  4279.  
  4280. #ifndef NOLOCAL
  4281. #ifdef ANYX25
  4282. int
  4283. shox25(n) int n; {
  4284.     if (nettype == NET_SX25) {
  4285.         printf("SunLink X.25 V%d.%d",x25ver / 10,x25ver % 10);
  4286.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4287.         printf("\n");
  4288.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4289.         printf(" Reverse charge call %s",
  4290.                revcall ? "selected" : "not selected");
  4291.         printf (", Closed user group ");
  4292.         if (closgr > -1)
  4293.           printf ("%d",closgr);
  4294.         else
  4295.           printf ("not selected");
  4296.         printf("\n");
  4297.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4298.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4299.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4300.     } else if (nettype == NET_VX25) {
  4301.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4302.         printf("\n");
  4303.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4304.         printf(" Reverse charge call %s",
  4305.                revcall ? "selected" : "not selected");
  4306.         printf (", Closed user group [unsupported]");
  4307.         if (closgr > -1)
  4308.           printf ("%d",closgr);
  4309.         else
  4310.           printf ("not selected");
  4311.         printf (",");
  4312.         printf("\n");
  4313.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4314.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4315.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4316.     } else if (nettype == NET_IX25) {
  4317.         printf("AIX NPI X.25\n");
  4318.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4319.         printf("\n Reverse charge call %s",
  4320.                revcall ? "selected" : "not selected");
  4321.         printf (", Closed user group [unsupported]");
  4322.         if (closgr > -1)
  4323.           printf ("%d",closgr);
  4324.         else
  4325.           printf ("not selected");
  4326.         printf (",");
  4327.         printf("\n Call user data %s.\n", cudata ? udata : "not selected");
  4328.     }
  4329.     return(n);
  4330. }
  4331.  
  4332. #ifndef IBMX25
  4333. int
  4334. shopad(n) int n; {
  4335.     int i;
  4336.     printf("\nX.3 PAD Parameters:\n");
  4337.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4338.     for (i = 0; i < npadx3; i++) {
  4339.         printf(" [%d] %s %d\n",padx3tab[i].kwval,padx3tab[i].kwd,
  4340.                padparms[padx3tab[i].kwval]);
  4341.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4342.     }
  4343.     return(n);
  4344. }
  4345. #endif /* IBMX25 */
  4346. #endif /* ANYX25 */
  4347.  
  4348. VOID
  4349. shoparc() {
  4350.     extern int reliable, stopbits, clsondisc;
  4351.     int i; char *s;
  4352.     long zz;
  4353.  
  4354. #ifdef NEWFTP
  4355.     if (ftpisconnected()) {
  4356.         shoftp(1);
  4357.         printf("\n");
  4358.     }
  4359. #endif /* NEWFTP */
  4360.  
  4361.     printf("Communications Parameters:\n");
  4362.  
  4363.     if (network
  4364. #ifdef IKSD
  4365.          || inserver
  4366. #endif /* IKSD */
  4367.          ) {
  4368.         printf(" Network Host: %s%s",ttname,
  4369.                (reliable == SET_ON || (reliable == SET_AUTO && !local)
  4370. #ifdef TN_COMPORT
  4371.                && !istncomport()
  4372. #endif /* TN_COMPORT */
  4373. #ifdef IKSD
  4374.                || inserver
  4375. #endif /* IKSD */
  4376.                ) ? " (reliable)" : "");
  4377. #ifdef TN_COMPORT
  4378.         if (istncomport()) {
  4379.             int modemstate;
  4380.             char * oflow, * iflow = "", * parity, * stopsize, * signature;
  4381.             int baud = tnc_get_baud();
  4382.  
  4383.             switch (tnc_get_oflow()) {
  4384.               case TNC_CTL_OFLOW_NONE:
  4385.                 oflow = "none";
  4386.                 break;
  4387.               case TNC_CTL_OFLOW_XON_XOFF:
  4388.                 oflow = "xon/xoff";
  4389.                 break;
  4390.               case TNC_CTL_OFLOW_RTS_CTS:
  4391.                 oflow = "rts/cts";
  4392.                 break;
  4393.               case TNC_CTL_OFLOW_DCD:
  4394.                 oflow = "dcd";
  4395.                 break;
  4396.               case TNC_CTL_OFLOW_DSR:
  4397.                 oflow = "dsr";
  4398.                 break;
  4399.               default:
  4400.                 oflow = "(unknown)";
  4401.             }
  4402.             switch (tnc_get_iflow()) {
  4403.               case TNC_CTL_IFLOW_NONE:
  4404.                 iflow = "none";
  4405.                 break;
  4406.               case TNC_CTL_IFLOW_XON_XOFF:
  4407.                 iflow = "xon/xoff";
  4408.                 break;
  4409.               case TNC_CTL_IFLOW_RTS_CTS:
  4410.                 iflow = "rts/cts";
  4411.                 break;
  4412.               case TNC_CTL_IFLOW_DTR:
  4413.                 break;
  4414.               default:
  4415.                 iflow = oflow;
  4416.             }
  4417.             switch (tnc_get_parity()) {
  4418.               case TNC_PAR_NONE:
  4419.                 parity = "none";
  4420.                 break;
  4421.               case TNC_PAR_ODD:
  4422.                 parity = "odd";
  4423.                 break;
  4424.               case TNC_PAR_EVEN:
  4425.                 parity = "even";
  4426.                 break;
  4427.               case TNC_PAR_MARK:
  4428.                 parity = "mark";
  4429.                 break;
  4430.               case TNC_PAR_SPACE:
  4431.                 parity = "space";
  4432.                 break;
  4433.               default:
  4434.                 parity = "(unknown)";
  4435.             }
  4436.             switch (tnc_get_stopsize()) {
  4437.               case TNC_SB_1:
  4438.                 stopsize = "1";
  4439.                 break;
  4440.               case TNC_SB_1_5:
  4441.                 stopsize = "1.5";
  4442.                 break;
  4443.               case TNC_SB_2:
  4444.                 stopsize = "2";
  4445.                 break;
  4446.               default:
  4447.                 stopsize = "(unknown)";
  4448.             }
  4449.         signature = (char *)tnc_get_signature();
  4450.             printf("\n  Signature            : %s\n",signature?signature:"");
  4451.             if (baud <= 0)
  4452.               printf("  Speed                : (unknown)\n");
  4453.             else
  4454.               printf("  Speed                : %d\n", baud);
  4455.             printf("  Outbound Flow Control: %s\n", oflow);
  4456.             printf("  Inbound Flow Control : %s\n", iflow);
  4457.             printf("  Parity               : %s\n", parity);
  4458.             printf("  Data Size            : %d\n", tnc_get_datasize());
  4459.             printf("  Stop Bits            : %s\n", stopsize);
  4460.             printf("  DTR Signal           : %d\n", tnc_get_dtr_state());
  4461.             printf("  RTS Signal           : %d\n", tnc_get_rts_state());
  4462.             printf("  Modem State:\n");
  4463.             modemstate = tnc_get_ms();
  4464.             if (modemstate & TNC_MS_EDGE_RING)
  4465.               printf("    Trailing Edge Ring Detector On\n");
  4466.             else
  4467.               printf("    Trailing Edge Ring Detector Off\n");
  4468.             if (modemstate & TNC_MS_CTS_SIG)
  4469.               printf("    CTS Signal On\n");
  4470.             else
  4471.               printf("    CTS Signal Off\n");
  4472.             if (modemstate & TNC_MS_DSR_SIG)
  4473.               printf("    DSR Signal On\n");
  4474.             else
  4475.               printf("    DSR Signal Off\n");
  4476.             if (modemstate & TNC_MS_RI_SIG)
  4477.               printf("    Ring Indicator On\n");
  4478.             else
  4479.               printf("    Ring Indicator Off\n");
  4480.             if (modemstate & TNC_MS_RLSD_SIG)
  4481.               printf("    RLSD (CD) Signal On\n");
  4482.             else
  4483.               printf("    RLSD (CD) Signal Off\n");
  4484.             printf("\n");
  4485.         }
  4486. #endif /* TN_COMPORT */
  4487.     } else {
  4488.  
  4489.         printf(" %s: %s%s, speed: ",
  4490. #ifdef OS2
  4491.                "Port",
  4492. #else
  4493.                "Line",
  4494. #endif /* OS2 */
  4495.                ttname,
  4496. #ifdef CK_TTYFD
  4497.                (local &&
  4498. #ifdef VMS
  4499.                 vmsttyfd() < 0
  4500. #else
  4501.                 ttyfd == -1
  4502. #endif /* VMS */
  4503.                 ) ?
  4504.                  " (closed)" :
  4505.                    (reliable == SET_ON ? " (reliable)" : "")
  4506. #else
  4507.                ""
  4508. #endif /* CK_TTYFD */
  4509.                );
  4510.         if (
  4511. #ifdef CK_TTYFD
  4512. #ifdef VMS
  4513.             vmsttyfd() < 0
  4514. #else
  4515.             ttyfd == -1
  4516. #endif /* VMS */
  4517.             ||
  4518. #endif /* CK_TTYFD */
  4519.             (zz = ttgspd()) < 0) {
  4520.             printf("unknown");
  4521.         } else {
  4522.             if (speed == 8880) printf("75/1200");
  4523.             else if (speed == 134) printf("134.5");
  4524.             else printf("%ld",zz);
  4525.         }
  4526.     }
  4527.     if (network
  4528. #ifdef IKSD
  4529.          || inserver
  4530. #endif /* IKSD */
  4531.          )
  4532.       printf("\n Mode: ");
  4533.     else
  4534.       printf(", mode: ");
  4535.     if (local) printf("local"); else printf("remote");
  4536.     if (network == 0
  4537. #ifdef IKSD
  4538.          && !inserver
  4539. #endif/* IKSD */
  4540.          ) {
  4541. #ifdef CK_TAPI
  4542.         if (tttapi && !tapipass )
  4543.           printf(", modem: %s","TAPI");
  4544.         else
  4545. #endif /* CK_TAPI */
  4546.         printf(", modem: %s",gmdmtyp());
  4547.     } else {
  4548. #ifdef NETCONN
  4549.        if (nettype == NET_TCPA) printf(", TCP/IP");
  4550.        if (nettype == NET_TCPB) printf(", TCP/IP");
  4551.        if (nettype == NET_DEC) {
  4552.            if (ttnproto == NP_LAT) printf(", DECnet LAT");
  4553.            else if ( ttnproto == NP_CTERM ) printf(", DECnet CTERM");
  4554.            else printf(", DECnet");
  4555.        }
  4556.        if (nettype == NET_SLAT) printf(", Meridian Technologies' SuperLAT");
  4557. #ifdef NETFILE
  4558.        if (nettype == NET_FILE) printf(", local file");
  4559. #endif /* NETFILE */
  4560. #ifdef NETCMD
  4561.        if (nettype == NET_CMD) printf(", pipe");
  4562. #endif /* NETCMD */
  4563. #ifdef NETPTY
  4564.        if (nettype == NET_PTY) printf(", pseudoterminal");
  4565. #endif /* NETPTY */
  4566. #ifdef NETDLL
  4567.        if (nettype == NET_DLL) printf(", dynamic load library");
  4568. #endif /* NETDLL */
  4569.        if (nettype == NET_PIPE) printf(", Named Pipes");
  4570. #ifdef SSHBUILTIN
  4571.        if (nettype == NET_SSH)
  4572.          printf(", Secure Shell protocol (SECURE)");
  4573. #endif /* SSHBUILTIN */
  4574. #ifdef ANYX25
  4575.        if (shox25(0) < 0) return;
  4576. #endif /* ANYX25 */
  4577.        if (IS_TELNET()) {
  4578.            printf(", telnet protocol");
  4579.            if (0
  4580. #ifdef CK_ENCRYPTION
  4581.                || ck_tn_encrypting() && ck_tn_decrypting()
  4582. #endif /* CK_ENCRYPTION */
  4583. #ifdef CK_SSL
  4584.                || tls_active_flag || ssl_active_flag
  4585. #endif /* CK_SSL */
  4586.                )
  4587.              printf(" (SECURE)");
  4588.        }
  4589. #ifdef RLOGCODE
  4590.        else if (ttnproto == NP_RLOGIN || ttnproto == NP_K4LOGIN ||
  4591.                 ttnproto == NP_K5LOGIN)
  4592.          printf(", rlogin protocol");
  4593.        else if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN)
  4594.          printf(", rlogin protocol (SECURE)");
  4595. #endif /* RLOGCODE */
  4596. #ifdef CK_KERBEROS
  4597. #ifdef KRB5
  4598.        else if (ttnproto == NP_K5U2U)
  4599.          printf(", Kerberos 5 User to User protocol (SECURE)");
  4600. #endif /* KRB5 */
  4601. #endif /* CK_KERBEROS */
  4602. #endif /* NETCONN */
  4603.     }
  4604.     printf("\n");
  4605.     if (hwparity && local && !network)
  4606.       s = parnam((char)hwparity);
  4607.     else
  4608.       s = parnam((char)parity);
  4609.     printf(" Parity: %s%s",hwparity ? "hardware " : "", s);
  4610. #ifndef NOLOCAL
  4611.     if (local && !network) {
  4612.         int sb;
  4613.         char c;
  4614.         c = s[0];
  4615.         if (islower(c)) c = toupper(c);
  4616.         sb = stopbits;
  4617.         if (sb < 1) {
  4618.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  4619.             printf(", stop-bits: (default)");
  4620.         } else {
  4621.             printf(", stop-bits: %d",sb);
  4622.         }
  4623.         if (hwparity)
  4624.           printf(" (8%c%d)",c,sb);
  4625.         else if (parity)
  4626.           printf(" (7%c%d)",c,sb);
  4627.         else
  4628.           printf(" (8N%d)",sb);
  4629.         printf("\n D");
  4630.     } else
  4631.       printf(", d");
  4632. #endif /* NOLOCAL */
  4633.  
  4634.     printf("uplex: %s, ", duplex ? "half" : "full");
  4635.     debug(F101,"shoparp flow","",flow);
  4636.     printf("flow: %s", floname[flow]);
  4637.     printf(", handshake: ");
  4638.     if (turn) printf("%d\n",turnch); else printf("none\n");
  4639. #ifdef COMMENT
  4640.     if (local && !network) {            /* SET CARRIER-WATCH */
  4641. #endif /* COMMENT */
  4642.         if (carrier == CAR_OFF) s = "off";
  4643.         else if (carrier == CAR_ON) s = "on";
  4644.         else if (carrier == CAR_AUT) s = "auto";
  4645.         else s = "unknown";
  4646.         printf(" Carrier-watch: %s", s);
  4647.         if (carrier == CAR_ON) {
  4648.             if (cdtimo) printf(", timeout: %d sec", cdtimo);
  4649.             else printf(", timeout: none");
  4650.         }
  4651. #ifdef COMMENT
  4652.     }
  4653. #endif /* COMMENT */
  4654.     printf(", close-on-disconnect: %s\n",showoff(clsondisc));
  4655.  
  4656. #ifdef UNIX                             /* UUCP lockfile, UNIX only */
  4657.     if (local) {
  4658. #ifndef NOUUCP
  4659.         if (!network && haslock && *flfnam)
  4660.           printf(" Lockfile: %s",flfnam);
  4661. #ifndef USETTYLOCK
  4662.         if (!network && haslock && lock2[0])
  4663.           printf("\n Secondary lockfile: %s",lock2);
  4664. #endif /* USETTYLOCK */
  4665. #else
  4666. #ifdef QNX
  4667.         {
  4668.             extern int qnxportlock, qnxopencount();
  4669.             if (local)
  4670.               printf(" Qnx-port-lock: %s, Open count: %d",
  4671.                      showoff(qnxportlock),
  4672.                      qnxopencount()
  4673.                      );
  4674.             else
  4675.               printf(" Qnx-port-lock: %s", showoff(qnxportlock));
  4676.         }
  4677. #endif /* QNX */
  4678. #endif /* NOUUCP */
  4679.         printf("\n");
  4680.     } else {
  4681.         char * s;
  4682.         s = ttglckdir();
  4683.         if (!s) s = "";
  4684.         printf(" Lockfile directory: %s\n", *s ? s : "(none)");
  4685.     }
  4686. #endif /* UNIX */
  4687. #ifndef MACOSX
  4688.     if (!local) {
  4689.         printf(" Typical port device name: %s\n",ttgtpn());
  4690.     }
  4691. #endif    /* MACOSX */
  4692.     if (local) {
  4693.         int i;
  4694.         i = parity ? 7 : 8;
  4695.         if (i == 8) i = (cmask == 0177) ? 7 : 8;
  4696.         printf(" Terminal bytesize: %d,",i);
  4697.         printf(" escape character: %d (^%c)\n",escape,ctl(escape));
  4698.     }
  4699. }
  4700.  
  4701. int
  4702. shotcp(n) int n; {
  4703. #ifdef TCPSOCKET
  4704.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  4705.         printf("SET TCP parameters:\n");
  4706.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4707.         printf(" Reverse DNS lookup: %s\n", showooa(tcp_rdns));
  4708.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4709.  
  4710. #ifdef CK_DNS_SRV
  4711.         printf(" DNS Service Records lookup: %s\n", showooa(tcp_dns_srv));
  4712.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4713. #endif /* CK_DNS_SRV */
  4714.  
  4715. #ifndef NOTCPOPTS
  4716. #ifdef SOL_SOCKET
  4717. #ifdef SO_KEEPALIVE
  4718.         printf(" Keepalive: %s\n", showoff(tcp_keepalive));
  4719.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4720. #endif /* SO_KEEPALIVE */
  4721.  
  4722. #ifdef SO_LINGER
  4723.         printf(" Linger: %s", tcp_linger ? "on, " : "off\n" );
  4724.         if (tcp_linger) {
  4725.             if (tcp_linger_tmo)
  4726.               printf("%d x 10 milliseconds\n",tcp_linger_tmo);
  4727.             else
  4728.               printf("no timeout\n");
  4729.         }
  4730.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4731. #endif /* SO_LINGER */
  4732.  
  4733. #ifdef SO_DONTROUTE
  4734.         printf(" DontRoute: %s\n", tcp_dontroute ? "on" : "off" );
  4735.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4736. #endif /* SO_DONTROUTE */
  4737.  
  4738. #ifdef TCP_NODELAY
  4739.         printf(" Nodelay: %s\n", showoff(tcp_nodelay));
  4740.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4741. #endif /* TCP_NODELAY */
  4742.  
  4743. #ifdef SO_SNDBUF
  4744.         if (tcp_sendbuf <= 0)
  4745.           printf(" Send buffer: (default size)\n");
  4746.         else
  4747.           printf(" Send buffer: %d bytes\n", tcp_sendbuf);
  4748.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4749. #endif /* SO_SNDBUF */
  4750. #ifdef SO_RCVBUF
  4751.         if (tcp_recvbuf <= 0)
  4752.           printf(" Receive buffer: (default size)\n");
  4753.         else
  4754.           printf(" Receive buffer: %d bytes\n", tcp_recvbuf);
  4755.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4756. #endif /* SO_RCVBUF */
  4757. #endif /* SOL_SOCKET */
  4758. #endif /* NOTCPOPTS */
  4759.         printf(" address: %s\n",tcp_address ? tcp_address : "(none)");
  4760.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4761. #ifndef NOHTTP
  4762.         printf(" http-proxy: %s\n",tcp_http_proxy ? tcp_http_proxy : "(none)");
  4763.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4764. #endif /* NOHTTP */
  4765. #ifdef NT
  4766. #ifdef CK_SOCKS
  4767.         printf(" socks-server: %s\n",tcp_socks_svr ? tcp_socks_svr : "(none)");
  4768.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4769. #ifdef CK_SOCKS_NS
  4770.         printf(" socks-name-server: %s\n",
  4771.                tcp_socks_ns ? tcp_socks_ns : "(none)");
  4772.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4773. #endif /* CK_SOCKS_NS */
  4774. #endif /* CK_SOCKS */
  4775. #endif /* NT */
  4776.     }
  4777. #endif /* TCPSOCKET */
  4778.     return(n);
  4779. }
  4780.  
  4781. #ifdef TNCODE
  4782. int
  4783. shotopt(n) int n; {
  4784.     int opt;
  4785.  
  4786.     printf("%-21s %12s %12s %12s %12s\n\n",
  4787.            "Telnet Option","Me (client)","U (client)",
  4788.            "Me (server)","U (server)");
  4789.     n += 2;
  4790.     if (n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4791.  
  4792.     for ( opt = TELOPT_FIRST; opt <= TELOPT_LAST; opt++) {
  4793.         switch (opt) {
  4794.           case TELOPT_AUTHENTICATION:
  4795.           case TELOPT_ENCRYPTION:
  4796.           case TELOPT_TTYPE:
  4797.           case TELOPT_NAWS:
  4798.           case TELOPT_BINARY:
  4799.           case TELOPT_NEWENVIRON:
  4800.           case TELOPT_SNDLOC:
  4801.           case TELOPT_XDISPLOC:
  4802.           case TELOPT_SGA:
  4803.           case TELOPT_ECHO:
  4804.           case TELOPT_KERMIT:
  4805.           case TELOPT_START_TLS:
  4806.           case TELOPT_FORWARD_X:
  4807.           case TELOPT_COMPORT:
  4808.             break;
  4809.           default:
  4810.             continue;
  4811.         }
  4812.         printf("%03d %-17s ",
  4813.                opt, TELOPT(opt)
  4814.                );
  4815.         printf("%12s %12s ",
  4816.                TELOPT_MODE(TELOPT_DEF_C_ME_MODE(opt)),
  4817.                TELOPT_MODE(TELOPT_DEF_C_U_MODE(opt))
  4818.                );
  4819.         printf("%12s %12s\n",
  4820.                TELOPT_MODE(TELOPT_DEF_S_ME_MODE(opt)),
  4821.                TELOPT_MODE(TELOPT_DEF_S_U_MODE(opt))
  4822.                );
  4823.  
  4824.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4825.         if (sstelnet)
  4826.           printf("%21s %12s %12s %12s %12s\n",
  4827.                  "",
  4828.                  "",
  4829.                  "",
  4830.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4831.                  (TELOPT_U(opt)?"DO":"DONT")
  4832.                  );
  4833.         else
  4834.           printf("%21s %12s %12s %12s %12s\n",
  4835.                  "",
  4836.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4837.                  (TELOPT_U(opt)?"DO":"DONT"),
  4838.                  "",
  4839.                  ""
  4840.                  );
  4841.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4842.     }
  4843.     return(n);
  4844. }
  4845.  
  4846. int
  4847. shotel(n) int n; {
  4848.     extern int tn_duplex;
  4849. #ifdef CK_ENVIRONMENT
  4850.     extern int tn_env_flg;
  4851.     extern char tn_env_acct[];
  4852.     extern char tn_env_job[];
  4853.     extern char tn_env_prnt[];
  4854.     extern char tn_env_sys[];
  4855.     extern char * tn_env_uservar[8][2];
  4856.     int x;
  4857. #endif /* CK_ENVIRONMENT */
  4858. #ifdef CK_SNDLOC
  4859.     extern char * tn_loc;
  4860. #endif /* CK_SNDLOC */
  4861.     printf("SET TELNET parameters:\n echo: %s\n NVT newline-mode: ",
  4862.            tn_duplex ? "local" : "remote");
  4863.     switch (tn_nlm) {
  4864.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4865.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4866.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4867.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4868.     }
  4869.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4870. #ifdef CK_AUTHENTICATION
  4871.     {
  4872.         int type = ck_tn_authenticated();
  4873.         printf(" authentication: ");
  4874.         switch (sstelnet ?
  4875.                 TELOPT_U_MODE(TELOPT_AUTHENTICATION) :
  4876.                  TELOPT_ME_MODE(TELOPT_AUTHENTICATION)
  4877.                 ) {
  4878.           case TN_NG_AC: printf( "accepted " ); break;
  4879.           case TN_NG_RF: printf( "refused  " ); break;
  4880.           case TN_NG_RQ: printf( "requested"); break;
  4881.           case TN_NG_MU: printf( "required "); break;
  4882.         }
  4883.  
  4884. #ifdef CK_SSL
  4885.         if ((ssl_active_flag || tls_active_flag) &&
  4886.              ck_tn_auth_valid() == AUTH_VALID &&
  4887.              (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  4888.                type == AUTHTYPE_NULL ||
  4889.                type == AUTHTYPE_AUTO))
  4890.             printf("   in use: X.509 certificate\n");
  4891.         else
  4892. #endif /* CK_SSL */
  4893.           printf("   in use: %s\n",AUTHTYPE_NAME(type));
  4894.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4895.         if (forward_flag)
  4896.           printf("  credentials forwarding requested %s\n",
  4897.                  forwarded_tickets ? "and completed" :
  4898.                  "but not completed");
  4899.         else
  4900.           printf("  credentials forwarding disabled\n");
  4901.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4902.     }
  4903. #endif /* CK_AUTHENTICATION */
  4904. #ifdef CK_ENCRYPTION
  4905.     {
  4906.         int i,x;
  4907.         int e_type = ck_tn_encrypting();
  4908.         int d_type = ck_tn_decrypting();
  4909.         char * e_str = NULL, * d_str = NULL;
  4910.         static struct keytab * tnetbl = NULL;
  4911.         static int ntnetbl = 0;
  4912.  
  4913.         x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  4914.  
  4915.         for (i = 0; i < ntnetbl; i++) {
  4916.             if (e_type == tnetbl[i].kwval)
  4917.               e_str = tnetbl[i].kwd;
  4918.             if (d_type == tnetbl[i].kwval)
  4919.               d_str = tnetbl[i].kwd;
  4920.         }
  4921.         printf(" encryption: ");
  4922.         switch (TELOPT_ME_MODE(TELOPT_ENCRYPTION)) {
  4923.           /* This should be changed to report both ME and U modes */
  4924.           case TN_NG_AC: printf( "accepted " ); break;
  4925.           case TN_NG_RF: printf( "refused  " ); break;
  4926.           case TN_NG_RQ: printf( "requested"); break;
  4927.           case TN_NG_MU: printf( "required "); break;
  4928.         }
  4929.         printf("       in use: ");
  4930.         switch ((e_type ? 1 : 0) | (d_type ? 2 : 0)) {
  4931.           case 0:
  4932.             printf("plain text in both directions");
  4933.             break;
  4934.           case 1:
  4935.             printf("%s output, plain text input",e_str);
  4936.             break;
  4937.           case 2:
  4938.             printf("plain text output, %s input",d_str);
  4939.             break;
  4940.           case 3:
  4941.             printf("%s output, %s input",e_str,d_str);
  4942.             break;
  4943.         }
  4944.         printf("\n");
  4945.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4946.     }
  4947. #endif /* CK_ENCRYPTION */
  4948. #ifdef IKS_OPTION
  4949.     printf(" kermit: ");
  4950.     switch (TELOPT_U_MODE(TELOPT_KERMIT)) {
  4951.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4952.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4953.       case TN_NG_RQ: printf( "u, requested; "); break;
  4954.       case TN_NG_MU: printf( "u, required;  "); break;
  4955.     }
  4956.     switch (TELOPT_ME_MODE(TELOPT_KERMIT)) {
  4957.       case TN_NG_AC: printf( "me, accepted;  " ); break;
  4958.       case TN_NG_RF: printf( "me, refused;   " ); break;
  4959.       case TN_NG_RQ: printf( "me, requested; "); break;
  4960.       case TN_NG_MU: printf( "me, required;  "); break;
  4961.     }
  4962.     if (TELOPT_U(TELOPT_KERMIT))
  4963.       printf(" u, %s",
  4964.              TELOPT_SB(TELOPT_KERMIT).kermit.u_start ?
  4965.              "started" :
  4966.              "stopped"
  4967.              );
  4968.     else
  4969.       printf(" u, n/a");
  4970.     if (TELOPT_ME(TELOPT_KERMIT))
  4971.       printf(" me, %s;",
  4972.              TELOPT_SB(TELOPT_KERMIT).kermit.me_start ?
  4973.              "started" :
  4974.              "stopped"
  4975.              );
  4976.     else
  4977.       printf(" me, n/a;");
  4978.     printf("\n");
  4979.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4980. #endif /* IKS_OPTION */
  4981.     printf(" BINARY newline-mode: ");
  4982.     switch (tn_b_nlm) {
  4983.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4984.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4985.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4986.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4987.     }
  4988.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4989.     printf(" binary-mode: ");
  4990.     switch (TELOPT_U_MODE(TELOPT_BINARY)) {
  4991.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4992.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4993.       case TN_NG_RQ: printf( "u, requested; "); break;
  4994.       case TN_NG_MU: printf( "u, required;  "); break;
  4995.     }
  4996.     switch (TELOPT_ME_MODE(TELOPT_BINARY)) {
  4997.       case TN_NG_AC: printf( "me, accepted; " ); break ;
  4998.       case TN_NG_RF: printf( "me, refused; " ); break;
  4999.       case TN_NG_RQ: printf( "me, requested; "); break;
  5000.       case TN_NG_MU: printf( "me, required;  "); break;
  5001.     }
  5002.     printf("u, %s; me, %s\n",
  5003.            TELOPT_U(TELOPT_BINARY) ? "BINARY" : "NVT",
  5004.            TELOPT_ME(TELOPT_BINARY) ? "BINARY" : "NVT"
  5005.            );
  5006.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5007.     printf(" binary-transfer-mode: %s\n",showoff(tn_b_xfer));
  5008.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5009.     printf(" bug binary-me-means-u-too: %s\n",showoff(tn_b_meu));
  5010.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5011.     printf(" bug binary-u-means-me-too: %s\n",showoff(tn_b_ume));
  5012.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5013.     printf(" bug sb-implies-will-do: %s\n",showoff(tn_sb_bug));
  5014.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5015.     printf(" bug auth-krb5-des: %s\n",showoff(tn_auth_krb5_des_bug));
  5016.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5017.     printf(" terminal-type: ");
  5018.     if (tn_term) {
  5019.         printf("%s\n",tn_term);
  5020.     } else {
  5021.         char *p;
  5022. #ifdef OS2
  5023.         p = (tt_type >= 0 && tt_type <= max_tt) ?
  5024.           tt_info[tt_type].x_name :
  5025.             "UNKNOWN";
  5026. #else
  5027.         p = getenv("TERM");
  5028. #endif /* OS2 */
  5029.         if (p)
  5030.           printf("none (%s will be used)\n",p);
  5031.         else printf("none\n");
  5032.     }
  5033.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5034. #ifdef CK_ENVIRONMENT
  5035.     printf(" environment: %s\n", showoff(tn_env_flg));
  5036.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5037.     printf("   ACCOUNT: %s\n",tn_env_acct);
  5038.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5039.     printf("   DISPLAY: %s\n",(char *)tn_get_display() ?
  5040.             (char *)tn_get_display() : "");
  5041.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5042.     printf("   JOB    : %s\n",tn_env_job);
  5043.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5044.     printf("   PRINTER: %s\n",tn_env_prnt);
  5045.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5046. #ifndef NOSPL
  5047.     printf("   USER   : %s\n",uidbuf);
  5048.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5049. #endif /* NOSPL */
  5050.     printf("   SYSTEM : %s\n",tn_env_sys);
  5051.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5052.     for (x = 0; x < 8; x++) {
  5053.         if (tn_env_uservar[x][0] && tn_env_uservar[x][1]) {
  5054.             printf("   %-7s: %s\n",tn_env_uservar[x][0],
  5055.                    tn_env_uservar[x][1]);
  5056.             if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5057.         }
  5058.     }
  5059. #endif /* CK_ENVIRONMENT */
  5060. #ifdef CK_SNDLOC
  5061.     printf("  LOCATION: %s\n", tn_loc ? tn_loc : "");
  5062.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5063. #endif /* CK_SNDLOC */
  5064. #ifdef CK_FORWARD_X
  5065.     printf(" .Xauthority-file: %s\n", (char *)XauFileName() ?
  5066.             (char *)XauFileName() : "(none)");
  5067.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5068. #endif /* CK_FORWARD_X */
  5069.     return(n);
  5070. }
  5071. #endif /* TNCODE */
  5072.  
  5073. #ifdef CK_NETBIOS
  5074. static int
  5075. shonb(n) int n; {
  5076.     printf("NETBIOS parameters:\n");
  5077.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5078.     printf(" API       : %s\n",
  5079.            NetbeuiAPI ?
  5080.            "NETAPI.DLL - IBM Extended Services or Novell Netware Requester"
  5081.            : "ACSNETB.DLL - IBM Network Transport Services/2" ) ;
  5082.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5083.     printf(" Local Name: [%s]\n", NetBiosName);
  5084.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5085.     printf(" Adapter   : %d\n", NetBiosAdapter);
  5086.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5087.     if (NetBiosLSN > 0xFF) {
  5088.         printf(" Session   : %d\n", NetBiosLSN);
  5089.     } else {
  5090.         printf(" Session   : none active\n");
  5091.     }
  5092.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5093.     return(n);
  5094. }
  5095. #endif /* CK_NETBIOS */
  5096.  
  5097. #ifndef NONET
  5098. int
  5099. shonet() {
  5100.  
  5101. #ifndef NETCONN
  5102.     printf("\nNo networks are supported in this version of C-Kermit\n");
  5103.  
  5104. #else
  5105. #ifdef NOLOCAL
  5106.     printf("\nNo networks are supported in this version of C-Kermit\n");
  5107.  
  5108. #else /* rest of this routine */
  5109.  
  5110.     int i, n = 4;
  5111.  
  5112. #ifndef NODIAL
  5113.     if (nnetdir <= 1) {
  5114.         printf("\nNetwork directory: %s\n",netdir[0] ? netdir[0] : "(none)");
  5115.         n++;
  5116.     } else {
  5117.         int i;
  5118.         printf("\nNetwork directories:\n");
  5119.         for (i = 0; i < nnetdir; i++) {
  5120.             printf("%2d. %s\n",i,netdir[i]);
  5121.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5122.         }
  5123.     }
  5124. #endif /* NODIAL */
  5125.  
  5126. #ifdef SSHCMD
  5127.     {
  5128.         extern char * sshcmd;
  5129.         printf("SSH COMMAND: %s\n",sshcmd ? sshcmd : "ssh -e none");
  5130.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5131.     }
  5132. #endif /* SSHCMD */
  5133.  
  5134. #ifdef OS2
  5135.     printf("\nNetwork availability:\n");
  5136. #else
  5137.     printf("\nSupported networks:\n");
  5138. #endif /* OS2 */
  5139.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5140.  
  5141. #ifdef VMS
  5142.  
  5143. #ifdef TCPWARE
  5144.     printf(" Process Software Corporation TCPware for OpenVMS");
  5145. #else
  5146. #ifdef MULTINET
  5147.     printf(" TGV MultiNet TCP/IP");
  5148. #else
  5149. #ifdef WINTCP
  5150.     printf(" WOLLONGONG WIN/TCP");
  5151. #else
  5152. #ifdef DEC_TCPIP
  5153.     {
  5154.         static $DESCRIPTOR(tcp_desc,"_TCP0:");
  5155.         int status;
  5156.         long devclass;
  5157.         static int itmcod = DVI$_DEVCLASS;
  5158.  
  5159. #ifdef COMMENT
  5160.         status = LIB$GETDVI(&itmcod, 0, &tcp_desc, &devclass);
  5161. #else
  5162.         /* Martin Zinser 9/96 */
  5163.         status = lib$getdvi(&itmcod, 0, &tcp_desc, &devclass);
  5164. #endif /* COMMENT */
  5165.         if ((status & 1) && (devclass == DC$_SCOM))
  5166.           printf(" Process Software Corporation TCPware for OpenVMS");
  5167.         else
  5168. #ifdef UCX50
  5169.           printf(" DEC TCP/IP Services for (Open)VMS 5.0");
  5170. #else
  5171.           printf(" DEC TCP/IP Services for (Open)VMS");
  5172. #endif /* UCX50 */
  5173.     }
  5174. #else
  5175. #ifdef CMU_TCPIP
  5176.     printf(" CMU-OpenVMS/IP");
  5177. #else
  5178.     printf(" None");
  5179. #endif /* CMU_TCPIP */
  5180. #endif /* DEC_TCPIP */
  5181. #endif /* WINTCP */
  5182. #endif /* MULTINET */
  5183. #endif /* TCPWARE */
  5184.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5185. #ifdef TNCODE
  5186.     printf(", TELNET protocol\n\n");
  5187.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5188.     n = shotel(n);
  5189.     if (n < 0) return(0);
  5190.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5191. #endif /* TNCODE */
  5192.     printf("\n");
  5193.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5194.     printf("\n");
  5195.     n = shotcp(++n);
  5196.     if (n < 0) return(0);
  5197. #else /* Not VMS */
  5198.  
  5199. #ifdef SUNX25
  5200.     printf(" SunLink X.25\n");
  5201.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5202. #endif /* SUNX25 */
  5203.  
  5204. #ifdef STRATUSX25
  5205.     printf(" Stratus VOS X.25\n");
  5206.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5207. #endif /* STRATUSX25 */
  5208.  
  5209. #ifdef IBMX25
  5210.     printf(" IBM AIX X.25\n");
  5211.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5212. #endif /* IBMX25 */
  5213.  
  5214. #ifdef HPX25
  5215.     printf(" HP-UX X.25\n");
  5216.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5217. #endif /* HPX25 */
  5218.  
  5219. #ifdef SSHBUILTIN
  5220.     if (ck_ssleay_is_installed())
  5221.         printf(" SSH V1 and V2 protocols\n");
  5222.     else
  5223.         printf(" SSH V1 and V2 protocols - not available\n");
  5224. #endif /* SSHBUILTIN */
  5225.  
  5226. #ifdef DECNET
  5227. #ifdef OS2
  5228. #ifdef NT
  5229.     if (dnet_avail)
  5230.       printf(" DECnet, LAT and CTERM protocols\n");
  5231.     else
  5232.       printf(" DECnet, LAT and CTERM protocols - not available\n");
  5233.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5234. #else /* NT */
  5235.     if (dnet_avail)
  5236.       printf(" DECnet, LAT protocol\n");
  5237.     else
  5238.       printf(" DECnet, LAT protocol - not available\n");
  5239.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5240. #endif /* NT */
  5241. #else
  5242.     printf(" DECnet\n");
  5243.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5244. #endif /* OS2 */
  5245. #endif /* DECNET */
  5246.  
  5247. #ifdef NPIPE
  5248.     printf(" Named Pipes\n");
  5249.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5250. #endif /* NPIPE */
  5251.  
  5252. #ifdef CK_NETBIOS
  5253.     if (netbiosAvail)
  5254.       printf(" NETBIOS\n");
  5255.     else
  5256.       printf(" NETBIOS - not available\n");
  5257.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5258. #endif /* CK_NETBIOS */
  5259.  
  5260. #ifdef SUPERLAT
  5261.     if (slat_avail)
  5262.       printf(" SuperLAT\n");
  5263.     else
  5264.       printf(" SuperLAT - not available\n") ;
  5265.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5266. #endif /* SUPERLAT */
  5267.  
  5268. #ifdef TCPSOCKET
  5269.     if (
  5270. #ifdef OS2
  5271.         tcp_avail
  5272. #else
  5273.         1
  5274. #endif /* OS2 */
  5275.         ) {
  5276.         char ipaddr[16];
  5277.  
  5278.         if (getlocalipaddrs(ipaddr,16,0) < 0) {
  5279. #ifdef OS2ONLY
  5280.             printf(" TCP/IP via %s\n", tcpname);
  5281. #else
  5282.             printf(" TCP/IP\n");
  5283. #endif /* OS2ONLY */
  5284.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5285.         } else {
  5286.             int i = 1;
  5287. #ifdef OS2ONLY
  5288.           printf(" TCP/IP [%16s] via %s\n", ipaddr, tcpname);
  5289. #else
  5290.           printf(" TCP/IP [%16s]\n",ipaddr);
  5291. #endif /* OS2ONLY */
  5292.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5293.  
  5294.             while (getlocalipaddrs(ipaddr,16,i++) >= 0) {
  5295.                 printf("        [%16s]\n",ipaddr);
  5296.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5297.             }
  5298.         }
  5299.         if (nettype == NET_TCPB) {
  5300.             printf("\n");
  5301.             n = shotcp(++n);
  5302.             if (n < 0) return(0);
  5303. #ifdef TNCODE
  5304.             printf("\n");
  5305.             n = shotel(++n);
  5306.             if (n < 0) return(0);
  5307. #endif /* TNCODE */
  5308.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5309.         }
  5310. #ifdef OS2
  5311.     } else {
  5312.         printf(" TCP/IP - not available%s\n",tcpname[0] ? tcpname : "" );
  5313.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5314. #endif /* OS2 */
  5315.     }
  5316. #endif /* TCPSOCKET */
  5317.  
  5318. #ifdef CK_NETBIOS
  5319.     if (netbiosAvail && nettype == NET_BIOS) {
  5320.        printf("\n") ;
  5321.        if ((n = shonb(++n)) < 0) return(0);
  5322.        if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5323.     }
  5324. #endif /* CK_NETBIOS */
  5325.  
  5326. #endif /* VMS */
  5327.  
  5328.     printf("\nActive network connection:\n");
  5329.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5330.  
  5331.     if (network) {
  5332.         printf(" Host: %s",ttname);
  5333.         if ((nettype == NET_TCPA || nettype == NET_TCPB) && *ipaddr)
  5334.           printf(" [%s]",ipaddr);
  5335.     } else
  5336.       printf(" Host: none");
  5337.     printf(", via: ");
  5338.     if (nettype == NET_TCPA || nettype == NET_TCPB)
  5339.       printf("tcp/ip\n");
  5340.     else if (nettype == NET_SX25)
  5341.       printf("SunLink X.25\n");
  5342.     else if (nettype == NET_VX25)
  5343.       printf("Stratus VOS X.25\n");
  5344.     else if (nettype == NET_IX25)
  5345.       printf("IBM AIX X.25\n");
  5346.     else if (nettype == NET_HX25)
  5347.       printf("HP-UX X.25\n");
  5348.     else if (nettype == NET_DEC) {
  5349.         if ( ttnproto == NP_LAT )
  5350.           printf("DECnet LAT\n");
  5351.         else if ( ttnproto == NP_CTERM )
  5352.           printf("DECnet CTERM\n");
  5353.         else
  5354.           printf("DECnet\n");
  5355.     } else if (nettype == NET_PIPE)
  5356.       printf("Named Pipes\n");
  5357.     else if (nettype == NET_BIOS)
  5358.       printf("NetBIOS\n");
  5359.     else if (nettype == NET_SLAT)
  5360.       printf("SuperLAT\n");
  5361.  
  5362. #ifdef NETFILE
  5363.     else if ( nettype == NET_FILE )
  5364.       printf("local file\n");
  5365. #endif /* NETFILE */
  5366. #ifdef NETCMD
  5367.     else if ( nettype == NET_CMD )
  5368.       printf("pipe\n");
  5369. #endif /* NETCMD */
  5370. #ifdef NETPTY
  5371.     else if ( nettype == NET_PTY )
  5372.         printf("pseudoterminal\n");
  5373. #endif /* NETPTY */
  5374. #ifdef NETDLL
  5375.     else if ( nettype == NET_DLL )
  5376.       printf("dynamic link library\n");
  5377. #endif /* NETDLL */
  5378.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5379.  
  5380. #ifdef ANYX25
  5381.     if ((nettype == NET_SX25) ||
  5382.         (nettype == NET_VX25) ||
  5383.         (nettype == NET_IX25))
  5384.       if ((n = shox25(n)) < 0) return(0);
  5385. #endif /* ANYX25 */
  5386.  
  5387. #ifdef SSHBUILTIN
  5388.     if (nettype == NET_SSH) {
  5389.         printf("Secure Shell protocol\n");
  5390.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5391.     }
  5392. #endif /* SSHBUILTIN */
  5393.  
  5394.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  5395. #ifdef RLOGCODE
  5396.         if (ttnproto == NP_RLOGIN) {
  5397.             printf(" LOGIN (rlogin) protocol\n");
  5398.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5399.         }
  5400. #ifdef CK_KERBEROS
  5401.         else if (ttnproto == NP_K4LOGIN) {
  5402.             printf(" Kerberos 4 LOGIN (klogin) protocol\n");
  5403.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5404.         }
  5405.         else if (ttnproto == NP_EK4LOGIN) {
  5406.             printf(" Encrypted Kerberos 4 LOGIN (eklogin) protocol\n");
  5407.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5408.         }
  5409.         else if (ttnproto == NP_K5LOGIN) {
  5410.             printf(" Kerberos 5 LOGIN (klogin) protocol\n");
  5411.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5412.         }
  5413.         else if (ttnproto == NP_EK5LOGIN) {
  5414.             printf(" Encrypted Kerberos 5 LOGIN (eklogin) protocol\n");
  5415.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5416.         }
  5417. #endif /* CK_KERBEROS */
  5418. #endif /* RLOGCODE */
  5419. #ifdef CK_KERBEROS
  5420.         if (ttnproto == NP_K5U2U) {
  5421.             printf(" Kerberos 5 User to User protocol\n");
  5422.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5423.         }
  5424. #endif /* CK_KERBEROS */
  5425.  
  5426. #ifdef TNCODE
  5427.         if (IS_TELNET()) {
  5428.             printf(" TELNET protocol\n");
  5429.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5430.             printf(" Echoing is currently %s\n",duplex ? "local" : "remote");
  5431.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5432.         }
  5433. #endif /* TNCODE */
  5434.         if (ttnproto == NP_TCPRAW) {
  5435.             printf(" Raw TCP socket\n");
  5436.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5437.         }
  5438.     }
  5439.     printf("\n");
  5440. #endif /* NOLOCAL */
  5441. #endif /* NETCONN */
  5442.     return(0);
  5443. }
  5444. #endif /* NONET */
  5445.  
  5446. #ifndef NODIAL
  5447. VOID
  5448. shodial() {
  5449.     if (mdmtyp >= 0 || local != 0) doshodial();
  5450. }
  5451.  
  5452. VOID
  5453. shods(s) char *s; {                     /* Show a dial-related string */
  5454.     char c;
  5455.     if (s == NULL || !(*s)) {           /* Empty? */
  5456.         printf("(none)\n");
  5457.     } else {                            /* Not empty. */
  5458.         while ((c = *s++))              /* Can contain controls */
  5459.           if (c == '\\')                /* a backslash */
  5460.             printf("\\\\");
  5461.           else if (c > 31 && c < 127) {
  5462.               putchar(c);
  5463.           } else
  5464.             printf("\\{%d}",c);
  5465.         printf("\n");
  5466.     }
  5467. }
  5468.  
  5469. int
  5470. doshodial() {
  5471.  
  5472.     int i, n = 2;
  5473.  
  5474.     printf(" Dial status:  %d", dialsta);
  5475.  
  5476. #ifdef BIGBUFOK
  5477.     if (dialsta > 90)
  5478.       printf(" = Unknown error");
  5479.     else if (dialsta < 0)
  5480.       printf(" = (none)");
  5481.     else if (dialsta < 35 && dialmsg[dialsta])
  5482.       printf(" = %s", dialmsg[dialsta]);
  5483. #endif /* BIGBUFOK */
  5484.     n++;
  5485.     if (ndialdir <= 1) {
  5486.         printf("\n Dial directory: %s\n",dialdir[0] ? dialdir[0] : "(none)");
  5487.     } else {
  5488.         int i;
  5489.         printf("\n Dial directories:\n");
  5490.         for (i = 0; i < ndialdir; i++)
  5491.           printf("%2d. %s\n",i+1,dialdir[i]);
  5492.         n += ndialdir;
  5493.     }
  5494.     printf(" Dial method:  ");
  5495.     if      (dialmauto)         printf("auto   ");
  5496.     else if (dialmth == XYDM_D) printf("default");
  5497.     else if (dialmth == XYDM_P) printf("pulse  ");
  5498.     else if (dialmth == XYDM_T) printf("tone   ");
  5499.     printf("         Dial sort: %s\n",dialsrt ? "on" : "off");
  5500.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5501.     printf(" Dial hangup:  %s             Dial display: %s\n",
  5502.            dialhng ? "on " : "off", dialdpy ? "on" : "off");
  5503.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5504.     if (dialrtr > 0) {
  5505.         printf(" Dial retries: %-12d    Dial interval: %d\n",
  5506.                dialrtr, dialint);
  5507.     } else {
  5508.         printf(" Dial retries: (auto)          Dial interval: %d\n", dialint);
  5509.     }
  5510.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5511.     printf(" Dial timeout: ");
  5512. #ifdef CK_TAPI
  5513.     if (tttapi && !tapipass)
  5514.         printf("(tapi)");
  5515.     else
  5516. #endif /* CK_TAPI */
  5517.     if (dialtmo > 0)
  5518.       printf("%4d sec", dialtmo);
  5519.     else
  5520.       printf("0 (auto)");
  5521.     printf("        Redial number: %s\n",dialnum ? dialnum : "(none)");
  5522.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5523.     printf(" Dial confirmation: %s        Dial convert-directory: %s\n",
  5524.            dialcnf ? "on " : "off",
  5525.            dialcvt ? ((dialcvt == 1) ? "on" : "ask") : "off");
  5526.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5527.     printf(" Dial ignore-dialtone: %s", dialidt ? "on " : "off");
  5528.     printf("     Dial pacing: %d\n",dialpace);
  5529.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5530.     printf(
  5531. " Dial prefix:                  %s\n", dialnpr ? dialnpr : "(none)");
  5532.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5533.     printf(
  5534. " Dial suffix:                  %s\n", dialsfx ? dialsfx : "(none)");
  5535.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5536.     printf(
  5537. " Dial country-code:            %-12s", diallcc ? diallcc : "(none)");
  5538.     printf("Dial connect:  %s", dialcon ? ((dialcon == 1) ? "on" : "auto")
  5539.            : "off");
  5540.     if (dialcon != CAR_OFF)
  5541.       printf(" %s", dialcq ? "quiet" : "verbose");
  5542.     printf(
  5543. "\n Dial area-code:               %-12s", diallac ? diallac : "(none)");
  5544.     n++;
  5545.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5546.     printf("Dial restrict: ");
  5547.     if (dialrstr == 5) printf("international\n");
  5548.     else if (dialrstr == 4) printf("long-distance\n");
  5549.     else if (dialrstr == 2) printf("local\n");
  5550.     else if (dialrstr == 6) printf("none\n");
  5551.     else printf("?\n");
  5552.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5553.     printf(" Dial lc-area-codes:           ");
  5554.     if (nlocalac == 0)
  5555.       printf("(none)");
  5556.     else
  5557.       for (i = 0; i < nlocalac; i++)
  5558.         printf("%s ", diallcac[i]);
  5559.     printf(
  5560. "\n Dial lc-prefix:               %s\n", diallcp ? diallcp : "(none)");
  5561.     n++;
  5562.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5563.     printf(
  5564. " Dial lc-suffix:               %s\n", diallcs ? diallcs : "(none)");
  5565.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5566.     printf(
  5567. " Dial ld-prefix:               %s\n", dialldp ? dialldp : "(none)");
  5568.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5569.     printf(
  5570. " Dial ld-suffix:               %s\n", diallds ? diallds : "(none)");
  5571.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5572.     printf(
  5573. " Dial force-long-distance      %s\n", showoff(dialfld));
  5574.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5575.     printf(
  5576. " Dial intl-prefix:             %s\n", dialixp ? dialixp : "(none)");
  5577.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5578.     printf(
  5579. " Dial intl-suffix:             %s\n", dialixs ? dialixs : "(none)");
  5580.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5581.     printf(
  5582. " Dial toll-free-area-code:     ");
  5583.     if (ntollfree == 0)
  5584.       printf("(none)");
  5585.     else
  5586.       for (i = 0; i < ntollfree; i++)
  5587.         printf("%s ", dialtfc[i]);
  5588.     printf("\n");
  5589.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5590.  
  5591.     printf(
  5592. " Dial pulse-countries:         ");
  5593.     if (ndialpucc == 0)
  5594.       printf("(none)");
  5595.     else
  5596.       for (i = 0; i < ndialpucc; i++)
  5597.         printf("%s ", dialpucc[i]);
  5598.     printf("\n");
  5599.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5600.  
  5601.     printf(
  5602. " Dial tone-countries:          ");
  5603.     if (ndialtocc == 0)
  5604.       printf("(none)");
  5605.     else
  5606.       for (i = 0; i < ndialtocc; i++)
  5607.         printf("%s ", dialtocc[i]);
  5608.     printf("\n");
  5609.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5610.  
  5611.     printf(
  5612.     " Dial toll-free-prefix:        %s\n",
  5613.     dialtfp ? dialtfp :
  5614.     (dialldp ? dialldp : "(none)")
  5615.     );
  5616.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5617.     printf(" Dial pbx-exchange:            ");
  5618.     if (ndialpxx == 0)
  5619.       printf("(none)");
  5620.     else
  5621.       for (i = 0; i < ndialpxx; i++)
  5622.         printf("%s ", dialpxx[i]);
  5623.     printf("\n");
  5624.  
  5625.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5626.     printf(
  5627. " Dial pbx-inside-prefix:       %s\n", dialpxi ? dialpxi : "(none)");
  5628.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5629.     printf(
  5630. " Dial pbx-outside-prefix:      %s\n", dialpxo ? dialpxo : "(none)");
  5631.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5632.     printf(
  5633. " Dial macro:                   %s\n", dialmac ? dialmac : "(none)");
  5634.     return(0);
  5635. }
  5636. #endif /* NODIAL */
  5637. #endif /* NOLOCAL */
  5638.  
  5639. /*  Show File Parameters */
  5640.  
  5641. static char *
  5642. pathval(x) int x; {
  5643.     switch (x) {
  5644.       case PATH_OFF:  return("off");
  5645.       case PATH_ABS:  return("absolute");
  5646.       case PATH_REL:  return("relative");
  5647.       case PATH_AUTO: return("auto");
  5648.       default: return("unknown");
  5649.     }
  5650. }
  5651.  
  5652. VOID
  5653. shofil() {
  5654.     char *s; int i = 0, n = 1;
  5655.     extern char * ifdnam[];
  5656.     extern int wildena;
  5657. #ifdef UNIX
  5658.     extern int wildxpand;
  5659. #endif /* UNIX */
  5660.     extern char * snd_move, * snd_rename, * rcv_move, * rcv_rename;
  5661. #ifdef PATTERNS
  5662.     extern int patterns;
  5663. #endif /* PATTERNS */
  5664.     extern char * rfspec, * sfspec;
  5665. #ifdef UNIX
  5666.     extern int zobufsize, zofbuffer, zofblock;
  5667. #endif /* UNIX */
  5668. #ifdef CK_CTRLZ
  5669.     extern int eofmethod;
  5670. #endif /* CK_CTRLZ */
  5671.  
  5672.     printf("\n");
  5673.  
  5674. #ifdef VMS
  5675.     printf(" File record-Length:      %5d\n",frecl);
  5676.     n++;
  5677. #endif /* VMS */
  5678.  
  5679. #ifndef NOXFER
  5680.     printf(" Transfer mode:           %s\n",
  5681.            xfermode == XMODE_A ?
  5682.            "automatic" :
  5683.            "manual"
  5684.            );
  5685.     n++;
  5686. #ifdef PATTERNS
  5687.     printf(" File patterns:           %s", showooa(patterns));
  5688.     if (xfermode == XMODE_M && patterns)
  5689.       printf(" (but disabled by TRANSFER-MODE MANUAL)");
  5690.     else if (patterns)
  5691.       printf(" (SHOW PATTERNS for list)");
  5692.     printf("\n");
  5693.     n++;
  5694. #endif /* PATTERNS */
  5695.     if (filepeek)
  5696.       printf(" File scan:               on %d\n", nscanfile);
  5697.     else
  5698.       printf(" File scan:               off\n");
  5699.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5700.     if (xfermode == XMODE_A)
  5701.       printf(" Default file type:       %s\n",shoxm());
  5702.     else
  5703.       printf(" File type:               %s\n",shoxm());
  5704.     n++;
  5705.     if (fncnv == XYFN_L)
  5706.       s = "literal";
  5707.     else if (fncnv == XYFN_C)
  5708.       s = "converted";
  5709.     else
  5710.       s = "(unknown)";
  5711.     printf(" File names:              %s\n",s);
  5712.     n++;
  5713.     printf(" Send pathnames:          %s\n", pathval(fnspath));
  5714.     n++;
  5715.     printf(" Receive pathnames:       %s\n", pathval(fnrpath));
  5716.     n++;
  5717. #ifdef UNIXOROSK
  5718.     printf(" Match dot files:         %s\n", matchdot ? "yes" : "no");
  5719.     n++;
  5720. #ifdef UNIX
  5721.     printf(" Wildcard-expansion:      %s (%s)\n", showoff(wildena),
  5722.        wildxpand ? "shell" : "kermit");
  5723.     n++;
  5724. #endif /* UNIX */
  5725. #endif /* UNIXOROSK */
  5726.     printf(" File collision:          ");
  5727.     for (i = 0; i < ncolx; i++)
  5728.       if (colxtab[i].kwval == fncact) break;
  5729.     printf("%s\n", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5730.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5731.     printf(" File destination:        %s\n",
  5732.            (dest == DEST_D) ? "disk" :
  5733.            ((dest == DEST_S) ? "screen" :
  5734.             ((dest == DEST_N) ? "nowhere" :
  5735.             "printer"))
  5736.            );
  5737.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5738.     s = (keep >= 0 && keep <= 2) ? ifdnam[keep] : "keep";
  5739.     printf(" File incomplete:         %s\n",s);
  5740.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5741.     printf(" File bytesize:           %d\n",(fmask == 0177) ? 7 : 8);
  5742.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5743. #ifndef NOCSETS
  5744.     printf(" File character-set:      %s\n",fcsinfo[fcharset].keyword);
  5745.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5746.     printf(" File default 7-bit:      %s\n",fcsinfo[dcset7].keyword);
  5747.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5748.     printf(" File default 8-bit:      %s\n",fcsinfo[dcset8].keyword);
  5749.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5750. #ifdef UNICODE
  5751.     printf(" File UCS bom:            %s\n",showoff(ucsbom));
  5752.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5753.     printf(" File UCS byte-order:     %s-endian\n",
  5754.            ucsorder ? "little" : "big");
  5755.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5756.     printf(" Computer byteorder:      %s-endian\n",
  5757.            byteorder ? "little" : "big");
  5758.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5759. #endif /* UNICODE */
  5760. #endif /* NOCSETS */
  5761.  
  5762.     printf(" File end-of-line:        ");
  5763.     i = feol;
  5764.     switch (feol) {
  5765.       case XYFA_C: printf("%s\n","cr"); break;
  5766.       case XYFA_L: printf("%s\n","lf"); break;
  5767.       case XYFA_2: printf("%s\n","crlf"); break;
  5768.       default: printf("%d\n",i);
  5769.     }
  5770.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5771. #endif /* NOXFER */
  5772.  
  5773. #ifdef CK_CTRLZ
  5774.     printf(" File eof:                %s\n", eofmethod ? "ctrl-z" : "length");
  5775.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5776. #endif /* CK_CTRLZ */
  5777. #ifndef NOXFER
  5778. #ifdef CK_TMPDIR
  5779.     printf(" File download-directory: %s\n", dldir ? dldir : "(none)");
  5780.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5781. #ifdef COMMENT
  5782.     i = 256;
  5783.     s = line;
  5784.     zzstring("\\v(tmpdir)",&s,&i);
  5785.     printf(" Temporary directory:     %s\n", line);
  5786.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5787. #endif /* COMMENT */
  5788. #endif /* CK_TMPDIR */
  5789. #ifdef VMS
  5790.     {
  5791.         extern int vmssversions, vmsrversions;
  5792.         printf(" Send version-numbers:    %s\n",showoff(vmssversions));
  5793.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5794.         printf(" Receive version-numbers: %s\n",showoff(vmsrversions));
  5795.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5796.     }
  5797. #endif /* VMS */
  5798.     printf(" Send move-to:            %s\n",
  5799.            snd_move ? snd_move : "(none)");
  5800.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5801.     printf(" Send rename-to:          %s\n",
  5802.            snd_rename ? snd_rename : "(none)");
  5803.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5804.     printf(" Receive move-to:         %s\n",
  5805.            rcv_move ? rcv_move : "(none)");
  5806.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5807.     printf(" Receive rename-to:       %s\n",
  5808.            rcv_rename ? rcv_rename : "(none)");
  5809.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5810. #endif /* NOXFER */
  5811. #ifdef KERMRC
  5812.     printf(" Initialization file:     %s\n", noinit ? "(none)" :
  5813. #ifdef CK_SYSINI
  5814.            CK_SYSINI
  5815. #else
  5816.            kermrc
  5817. #endif /* CK_SYSINI */
  5818.            );
  5819. #endif /* KERMRC */
  5820.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5821.  
  5822.     if (k_info_dir) {
  5823.         printf(" Kermit doc files:        %s\n", k_info_dir);
  5824.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5825.     }
  5826.  
  5827. #ifdef CKROOT
  5828.     s = zgetroot();
  5829.     printf(" Root set:                %s\n", s ? s : "(none)");
  5830. #endif /* CKROOT */
  5831.  
  5832. #ifdef UNIX
  5833.     printf(" Disk output buffer:      %d (writes are %s, %s)\n",
  5834.            zobufsize,
  5835.            zofbuffer ? "buffered" : "unbuffered",
  5836.            zofblock ? "blocking" : "nonblocking"
  5837.            );
  5838.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5839. #ifdef DYNAMIC
  5840.     printf(" Stringspace:             %d\n", zsetfil(0,2));
  5841.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5842.     printf(" Listsize:                %d\n", zsetfil(0,4));
  5843.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5844. #endif /* DYNAMIC */
  5845. #endif /* UNIX */
  5846. #ifdef OS2ORUNIX
  5847.     printf(" Longest filename:        %d\n", maxnam);
  5848.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5849.     printf(" Longest pathname:        %d\n", maxpath);
  5850.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5851. #endif /* OS2ORUNIX */
  5852.  
  5853.     printf(" Last file sent:          %s\n", sfspec ? sfspec : "(none)");
  5854.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5855.     printf(" Last file received:      %s\n", rfspec ? rfspec : "(none)");
  5856.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5857.     printf("\n Also see:\n");
  5858.     n++;
  5859.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5860.     printf(" SHOW PROTOCOL, SHOW XFER");
  5861. #ifdef CK_LABELED
  5862.     printf(", SHOW LABELED");
  5863. #endif /* CK_LABELED */
  5864. #ifdef PATTERNS
  5865.     printf(", SHOW PATTERNS");
  5866. #endif /* PATTERNS */
  5867. #ifdef STREAMING
  5868.     printf(", SHOW STREAMING");
  5869. #endif /* STREAMING */
  5870. #ifndef NOCSETS
  5871.     printf(", SHOW CHARACTER-SETS");
  5872. #endif /* NOCSETS */
  5873.     printf("\n\n");
  5874. }
  5875.  
  5876. #ifndef NOXFER
  5877. VOID
  5878. shoparp() {                             /* Protocol */
  5879.     extern int docrc, skipbup;
  5880.     char *s;
  5881.  
  5882. #ifdef CK_TIMERS
  5883.     extern int rttflg;
  5884. #endif /* CK_TIMERS */
  5885.  
  5886.     printf("Protocol: %s\n",ptab[protocol].p_name);
  5887.  
  5888.     if (protocol == PROTO_K) {
  5889.         printf("\nProtocol Parameters:   Send    Receive");
  5890.         if (timef)
  5891.           printf("\n Timeout (used=%2d):%7d*%8d ", timint, rtimo, pkttim);
  5892.         else
  5893.           printf("\n Timeout (used=%2d):%7d%9d ",  timint, rtimo, pkttim);
  5894. #ifdef XFRCAN
  5895.         printf("       Cancellation:    %s",showoff(xfrcan));
  5896.         if (xfrcan)
  5897.           printf(" %d %d", xfrchr, xfrnum);
  5898. #endif /* XFRCAN */
  5899.         printf("\n Padding:      %11d%9d", npad,   mypadn);
  5900.         if (bctr == 4)
  5901.           printf("        Block Check: blank-free-2\n");
  5902.         else
  5903.           printf("        Block Check: %6d\n",bctr);
  5904.         printf(  " Pad Character:%11d%9d", padch,  mypadc);
  5905.         printf("        Delay:       %6d\n",ckdelay);
  5906.         printf(  " Pause:        %11d%9d", pktpaus, pktpaus);
  5907.         printf("        Attributes:      %s\n",showoff(atcapr));
  5908.         printf(  " Packet Start: %11d%9d", mystch, stchr);
  5909.         printf("        Max Retries: %6d%s\n",
  5910.                maxtry,
  5911.                (maxtry == 0) ? " (unlimited)" : ""
  5912.                );
  5913.         printf(  " Packet End:   %11d%9d", seol,   eol);
  5914.         if (ebqflg)
  5915.           printf("        8th-Bit Prefix: '%c'",ebq);
  5916.         else
  5917.           printf("        8th-Bit Prefix: ('%c' but not used)",ebq);
  5918.         printf(  "\n Packet Length:%11d ", spmax);
  5919.         printf("%8d     ",  urpsiz);
  5920.         if (rptflg)
  5921.           printf("   Repeat Prefix:  '%c'",rptq);
  5922.         else
  5923.           printf("   Repeat Prefix:  ('%c' but not used)",rptq);
  5924.         printf(  "\n Maximum Length: %9d%9d", maxsps, maxrps);
  5925.         printf("        Window Size:%7d set, %d used\n",wslotr,wmax);
  5926.         printf(    " Buffer Size:  %11d%9d", bigsbsiz, bigrbsiz);
  5927.         printf("        Locking-Shift:    ");
  5928.         if (lscapu == 2) {
  5929.             printf("forced");
  5930.         } else {
  5931.             printf("%s", (lscapr ? "enabled" : "disabled"));
  5932.             if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  5933.         }
  5934.         printf("\n\n");
  5935.  
  5936.         if (!(s = ptab[protocol].h_b_init)) s = "";
  5937.         printf(" Auto-upload command (binary): ");
  5938.         if (*s) {
  5939.             shostrdef((CHAR *)s);
  5940.             printf("\n");
  5941.         } else {
  5942.             printf("(none)\n");
  5943.         }
  5944.         if (!(s = ptab[protocol].h_t_init)) s = "";
  5945.         printf(" Auto-upload command (text):   ");
  5946.         if (*s) {
  5947.             shostrdef((CHAR *)s);
  5948.             printf("\n");
  5949.         } else {
  5950.             printf("(none)\n");
  5951.         }
  5952.         if (!(s = ptab[protocol].h_x_init)) s = "";
  5953.         printf(" Auto-server command:          ");
  5954.         if (*s) {
  5955.             shostrdef((CHAR *)s);
  5956.             printf("\n");
  5957.         } else {
  5958.             printf("(none)\n");
  5959.         }
  5960.         tmpbuf[0] = NUL;
  5961. #ifdef CK_TIMERS
  5962.         if (rttflg) {
  5963.             extern int mintime, maxtime;
  5964.             sprintf(tmpbuf," Packet timeouts: dynamic %d:%d", /* SAFE */
  5965.                     mintime,
  5966.                     maxtime);
  5967.         } else {
  5968.             sprintf(tmpbuf," Packet timeouts: fixed"); /* SAFE */
  5969.         }
  5970. #endif /* CK_TIMERS */
  5971.         if (tmpbuf[0])
  5972.           printf("%-31s",tmpbuf);
  5973.         printf("Send backup: %s\n",showoff(!skipbup));
  5974.  
  5975.         printf(" Transfer mode:   %s", xfermode == XMODE_A ?
  5976.                "automatic   " :
  5977.                "manual      "
  5978.                );
  5979.         printf(" Transfer slow-start: %s, crc: %s\n",
  5980.                showoff(slostart),
  5981.                showoff(docrc)
  5982.                );
  5983. #ifdef PIPESEND
  5984.         {
  5985.             extern int usepipes;
  5986.             printf(" Transfer pipes:  %s         ",usepipes ? "on " : "off");
  5987.         }
  5988. #endif /* PIPESEND */
  5989. #ifndef NOCSETS
  5990.         printf(" Transfer character-set: ");
  5991.         if (tcharset == TC_TRANSP)
  5992.           printf("transparent\n");
  5993.         else
  5994.           printf("%s\n", tcsinfo[tcharset].keyword );
  5995. #endif /* NOCSETS */
  5996. #ifdef PIPESEND
  5997.         {
  5998.             extern char * sndfilter, * rcvfilter;
  5999.             printf(" Send filter:     %s\n", sndfilter ? sndfilter : "(none)");
  6000.             printf(" Receive filter:  %s\n", rcvfilter ? rcvfilter : "(none)");
  6001.         }
  6002. #endif /* PIPESEND */
  6003.         printf("\nAlso see:\n");
  6004.         printf(" SHOW FILE, SHOW XFER");
  6005.  
  6006. #ifdef CK_LABELED
  6007.         printf(", SHOW LABELED");
  6008. #endif /* CK_LABELED */
  6009. #ifdef PATTERNS
  6010.         printf(", SHOW PATTERNS");
  6011. #endif /* PATTERNS */
  6012. #ifdef STREAMING
  6013.         printf(", SHOW STREAMING");
  6014. #endif /* STREAMING */
  6015. #ifndef NOCSETS
  6016.         printf(", SHOW CHARACTER-SETS");
  6017. #endif /* NOCSETS */
  6018.     }
  6019.  
  6020. #ifdef CK_XYZ
  6021. #ifdef XYZ_INTERNAL
  6022.     if (protocol != PROTO_K) {
  6023.         int i;
  6024.         int x;
  6025.         printf(" File type: %s\n", binary ? "binary" : "text");
  6026.         if (protocol == PROTO_Z) {              /* Zmodem */
  6027.             printf(" Window size:   ");
  6028.             if (ptab[protocol].winsize < 1)
  6029.               printf("none\n");
  6030.             else
  6031.               printf("%d\n",wslotr);
  6032. #ifdef COMMENT
  6033.             printf(" Packet (frame) length: ");
  6034.             if (ptab[protocol].spktlen < 0)
  6035.               printf("none\n");
  6036.             else
  6037.               printf("%d\n",spmax);
  6038. #endif /* COMMENT */
  6039.         } else {
  6040.             if (ptab[protocol].spktlen >= 1000)
  6041.               printf(" 1K packets\n");
  6042.             else
  6043.               printf(" 128-byte packets\n");
  6044.         }
  6045.         printf(" Pathname stripping when sending:   %s\n",
  6046.                showoff(ptab[protocol].fnsp)
  6047.                );
  6048.         printf(" Pathname stripping when receiving: %s\n",
  6049.                showoff(ptab[protocol].fnrp)
  6050.                );
  6051.         printf(" Filename collision action:         ");
  6052.         for (i = 0; i < ncolx; i++)
  6053.           if (colxtab[i].kwval == fncact) break;
  6054.         printf("%-12s", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  6055.  
  6056.         printf("\n Escape control characters:          ");
  6057.         x = ptab[protocol].prefix;
  6058.         if (x == PX_ALL)
  6059.           printf("all\n");
  6060.         else if (x == PX_CAU || x==PX_WIL)
  6061.           printf("minimal\n");
  6062.         else
  6063.           printf("none\n");
  6064.         if (!(s = ptab[protocol].h_b_init))
  6065.           s = "";
  6066.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  6067.         if (!(s = ptab[protocol].h_t_init))
  6068.           s = "";
  6069.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  6070.     }
  6071. #else
  6072. #ifndef NOPUSH
  6073.     if (protocol != PROTO_K) {
  6074.     _PROTOTYP( VOID shoextern, (void) );
  6075.         printf("\nExecuted by external commands:\n\n");
  6076.         s = ptab[protocol].p_b_scmd;
  6077.         if (!s) s = "";
  6078.         printf(" SEND command (binary):        %s\n", *s ? s : "(none)");
  6079.         s = ptab[protocol].p_t_scmd;
  6080.         if (!s) s = "";
  6081.         printf(" SEND command (text):          %s\n", *s ? s : "(none)");
  6082.         s = ptab[protocol].p_b_rcmd;
  6083.         if (!s) s = "";
  6084.         printf(" RECEIVE command (binary):     %s\n", *s ? s : "(none)");
  6085.         s = ptab[protocol].p_t_rcmd;
  6086.         if (!s) s = "";
  6087.         printf(" RECEIVE command (text):       %s\n", *s ? s : "(none)");
  6088.         s = ptab[protocol].h_b_init;
  6089.         if (!s) s = "";
  6090.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  6091.         s = ptab[protocol].h_t_init;
  6092.         if (!s) s = "";
  6093.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  6094.     (VOID) shoextern();
  6095.     }
  6096. #endif /* NOPUSH */
  6097. #endif /* XYZ_INTERNAL */
  6098. #endif /* CK_XYZ */
  6099. }
  6100. #endif /* NOXFER */
  6101.  
  6102. #ifndef NOCSETS
  6103. /* Character-set items */
  6104.  
  6105. extern int s_cset, r_cset, axcset[], afcset[];
  6106. extern struct keytab xfrmtab[];
  6107.  
  6108. VOID
  6109. shoparl() {
  6110. #ifdef COMMENT
  6111.     int i;
  6112. /* Misleading... */
  6113.     printf("\nAvailable Languages:\n");
  6114.     for (i = 0; i < MAXLANG; i++) {
  6115.         printf(" %s\n",langs[i].description);
  6116.     }
  6117. #else
  6118.     printf("\nLanguage-specific translation rules: %s\n",
  6119.            language == L_USASCII ? "none" : langs[language].description);
  6120.     shocharset();
  6121.     printf("\n\n");
  6122. #endif /* COMMENT */
  6123. }
  6124.  
  6125. VOID
  6126. shocharset() {
  6127.     int x;
  6128. #ifdef COMMENT
  6129.     char * s = "Unknown";
  6130.     extern int xlatype;
  6131. #endif /* COMMENT */
  6132.  
  6133. #ifndef NOXFER
  6134.     extern int xfrxla;
  6135. #endif /* NOXFER */
  6136.  
  6137.     debug(F101,"SHOW FILE CHAR","",fcharset);
  6138.     printf("\n");
  6139. #ifndef NOXFER
  6140.     printf(" Transfer Translation: %s\n", showoff(xfrxla));
  6141.     if (!xfrxla) {
  6142.         printf(
  6143.       " Because transfer translation is off, the following are ignored:\n\n");
  6144.     }
  6145. #endif /* NOXFER */
  6146.     printf(" File Character-Set: %s (%s), ",
  6147.            fcsinfo[fcharset].keyword,
  6148.            fcsinfo[fcharset].name
  6149.            );
  6150.     if ((x = fcsinfo[fcharset].size) == 128)
  6151.       printf("7-bit");
  6152.     else if (x == 256)
  6153.       printf("8-bit");
  6154.     else
  6155.       printf("multibyte");
  6156.     printf("\n");
  6157.     printf(" File Scan: %s\n",showoff(filepeek));
  6158.     printf("   Default 7bit-Character-Set: %s\n",fcsinfo[dcset7].keyword);
  6159.     printf("   Default 8bit-Character-Set: %s\n",fcsinfo[dcset8].keyword);
  6160.     printf(" Transfer Character-Set");
  6161. #ifdef COMMENT
  6162.     if (tslevel == TS_L2)
  6163.       printf(": (international)");
  6164.     else
  6165. #endif /* COMMENT */
  6166.     if (tcharset == TC_TRANSP)
  6167.       printf(": Transparent");
  6168.     else
  6169.       printf(": %s (%s)",tcsinfo[tcharset].keyword, tcsinfo[tcharset].name);
  6170.     printf("\n");
  6171. #ifdef COMMENT
  6172.     switch (xlatype) {
  6173.       case XLA_NONE: s = "None"; break;
  6174.       case XLA_BYTE: s = "Byte"; break;
  6175.       case XLA_JAPAN: s = "Japanese"; break;
  6176.       case XLA_UNICODE: s = "Unicode"; break;
  6177.     }
  6178.     printf("\n Translation type: %s\n",s);
  6179. #endif /* COMMENT */
  6180.     printf(" SEND character-set-selection: %s\n",xfrmtab[s_cset].kwd);
  6181.     printf(" RECEIVE character-set-selection: %s\n",xfrmtab[r_cset].kwd);
  6182.     if (s_cset == XMODE_A || r_cset == XMODE_A)
  6183.       printf(
  6184.       " (Use SHOW ASSOCIATIONS to list automatic character-set selections.)\n"
  6185.              );
  6186. }
  6187.  
  6188. VOID
  6189. showassoc() {
  6190.     int i, k, n = 4;
  6191.     char * s;
  6192.     printf("\nFor incoming files:\n\n");
  6193.     printf("Transfer Character-Set   File Character-Set\n");
  6194.     for (i = 1; i <= MAXTCSETS; i++) {
  6195.         k = axcset[i];
  6196.         if (k < 0 || k > MAXFCSETS)
  6197.           s = "(none)";
  6198.         else
  6199.           s = fcsinfo[k].keyword;
  6200.         if (!s) s = "";
  6201.         if (!*s) s = "(none)";
  6202.         printf(" %-25s%s\n",tcsinfo[i].keyword,s);
  6203.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6204.     }
  6205.     printf("\nFor outbound files:\n\n");
  6206.     n += 2;
  6207.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6208.     printf("File Character-Set       Transfer Character-Set\n");
  6209.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6210.     for (i = 0; i <= MAXFCSETS; i++) {
  6211.         k = afcset[i];
  6212.         if (k < 0 || k > MAXTCSETS)
  6213.           s = "(none)";
  6214.         else
  6215.           s = tcsinfo[k].keyword;
  6216.         if (!s) s = "";
  6217.         if (!*s) s = "(none)";
  6218.         printf(" %-25s%s\n",fcsinfo[i].keyword,s);
  6219.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6220.     }
  6221. }
  6222. #endif /* NOCSETS */
  6223.  
  6224. VOID
  6225. shopar() {
  6226.     printf("Show what?  (Type \"show ?\" for a list of possibilities.)\n");
  6227. }
  6228. #endif /* NOSHOW */
  6229.  
  6230. #ifndef NOXFER
  6231. /*  D O S T A T  --  Display file transfer statistics.  */
  6232.  
  6233. int
  6234. dostat(brief) int brief; {
  6235.     extern long filrej, peakcps;
  6236.     extern int lastspmax, streamed, cleared, streamok;
  6237.     extern char whoareu[];
  6238.     int n = 0, ftp = 0;
  6239.     extern int docrc, interrupted, fatalio;
  6240.  
  6241.     ftp = lastxfer & W_FTP;
  6242.  
  6243. #ifdef CK_TTGWSIZ
  6244. #ifdef OS2
  6245.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  6246.       ttgwsiz();
  6247. #else /* OS2 */
  6248.     if (ttgwsiz() > 0) {
  6249.         if (tt_rows > 0 && tt_cols > 0) {
  6250.             cmd_rows = tt_rows;
  6251.             cmd_cols = tt_cols;
  6252.         }
  6253.     }
  6254. #endif /* OS2 */
  6255. #endif /* CK_TTGWSIZ */
  6256.  
  6257.     debug(F101,"dostat xferstat","",xferstat);
  6258.     if (xferstat < 0) {
  6259.         printf(" No file transfers yet.\n");
  6260.         return(1);
  6261.     }
  6262.     n = 0;
  6263.     if (brief) { printf("\n"); n++; };
  6264.     printf(" protocol               : %s\n",
  6265.            ftp ? "ftp" : ptab[protocol].p_name);
  6266.     n++;
  6267.     printf(" status                 : ");
  6268.     if (xferstat) printf("SUCCESS\n");
  6269.     else if (interrupted) printf("FAILURE (interrupted)\n");
  6270.     else if (fatalio) printf("FAILURE (i/o error)\n");
  6271.     else printf("FAILURE\n");
  6272. #ifndef XYZ_INTERNAL
  6273.     if (!ftp && protocol != PROTO_K) {
  6274.         printf("\n external protocol statistics not available\n");
  6275.         return(1);
  6276.     }
  6277. #endif /* XYZ_INTERNAL */
  6278.     n++;
  6279.     if (!ftp) {
  6280.         if (!xferstat > 0) {
  6281.             if (docrc)
  6282.               printf(" crc-16 of file(s)      : %ld\n", crc16);
  6283.             else
  6284.               printf(" crc-16 of file(s)      : (disabled)\n");
  6285.             n++;
  6286.         }
  6287.         if (!xferstat && *epktmsg) {
  6288.             printf(" reason                 : %s\n", epktmsg);
  6289.             n++;
  6290.         }
  6291.     }
  6292.     if (!brief) {
  6293. #ifdef NEWFTP
  6294.         if (ftp) {
  6295.             extern char ftp_srvtyp[];
  6296.             printf(" remote system type     : %s\n",ftp_srvtyp);
  6297.         } else
  6298. #endif /* NEWFTP */
  6299.           if (whoareu[0]) {
  6300.             printf(" remote system type     : %s\n",
  6301.                    getsysid((char *)whoareu));
  6302.             n++;
  6303.         }
  6304.         printf(" files transferred      : %ld\n",filcnt - filrej);
  6305.         if (!ftp)
  6306.           printf(" files not transferred  : %ld\n",filrej);
  6307.         printf(" characters last file   : %s\n",ckfstoa(ffc));
  6308.         printf(" total file characters  : %s\n",ckfstoa(tfc));
  6309.         n += ftp ? 3 : 4;
  6310.         if (!ftp) {
  6311.             printf(" communication line in  : %s\n",ckfstoa(tlci));
  6312.             printf(" communication line out : %s\n",ckfstoa(tlco));
  6313.             printf(" packets sent           : %d\n", spackets);
  6314.             printf(" packets received       : %d\n", rpackets);
  6315.             n += 4;
  6316.         }
  6317.     }
  6318.     if (ftp) goto dotimes;
  6319.  
  6320.     printf(" damaged packets rec'd  : %d\n", crunched);
  6321.     printf(" timeouts               : %d\n", timeouts);
  6322.     printf(" retransmissions        : %d\n", retrans);
  6323.     n += 3;
  6324.  
  6325.     if (!brief) {
  6326.         if (filcnt > 0) {
  6327.             printf(" parity                 : %s",parnam((char)parity));
  6328.             n++;
  6329.             if (autopar) { printf(" (detected automatically)"); n++; }
  6330.             printf(
  6331.                  "\n control characters     : %ld prefixed, %ld unprefixed\n",
  6332.                    ccp, ccu);
  6333.             n++;
  6334.             printf(" 8th bit prefixing      : ");
  6335.             n++;
  6336.             if (ebqflg) printf("yes [%c]\n",ebq); else printf("no\n");
  6337.             n++;
  6338.             printf(" locking shifts         : %s\n", lscapu ? "yes" : "no");
  6339.             n++;
  6340.         }
  6341.     }
  6342.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6343.     if (streamed > 0)
  6344.       printf(" window slots used      : (streaming)\n");
  6345.     else
  6346.       printf(" window slots used      : %d of %d\n", wmax, wslotr);
  6347.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6348.     printf(" reliable:              : %s%s\n",
  6349.            streamok ? "" : "not ", "negotiated");
  6350.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6351.     printf(" clearchannel:          : %s%s\n",
  6352.            cleared  ? "" : "not ", "negotiated");
  6353.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6354.  
  6355.     if (!brief) {
  6356.         printf(" packet length          : %d (send), %d (receive)\n",
  6357.                lastspmax, urpsiz);
  6358.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6359.         printf(" compression            : ");
  6360.         if (rptflg)
  6361.           printf("yes [%c] (%ld)\n",(char) rptq,rptn);
  6362.         else
  6363.           printf("no\n");
  6364.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6365.         if (bctu == 4)
  6366.           printf(" block check type used  : blank-free-2\n");
  6367.         else
  6368.           printf(" block check type used  : %d\n",bctu);
  6369.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6370.     }
  6371.  
  6372.   dotimes:
  6373.  
  6374. #ifdef GFTIMER
  6375. #ifdef COMMENT
  6376.     printf(" elapsed time           : %0.3f sec, %s\n", fptsecs,hhmmss(tsecs));
  6377. #endif /* COMMENT */
  6378.     printf(" elapsed time           : %s (%0.3f sec)\n",
  6379.            hhmmss((long)(fptsecs + 0.5)),fptsecs);
  6380. #else
  6381. #ifdef COMMENT
  6382.     printf(" elapsed time           : %s (%d sec)\n",hhmmss(tsecs),tsecs);
  6383. #endif /* COMMENT */
  6384.     printf(" elapsed time           : %d sec, %s\n",tsecs,hhmmss(tsecs));
  6385. #endif /* GFTIMER */
  6386.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6387.     if (!ftp && local && !network && !brief) {
  6388.         if (speed <= 0L) speed = ttgspd();
  6389.         if (speed > 0L) {
  6390.             if (speed == 8880)
  6391.               printf(" transmission rate      : 75/1200 bps\n");
  6392.             else
  6393.               printf(" transmission rate      : %ld bps\n",speed);
  6394.             if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6395.         }
  6396.     }
  6397.     if (!ftp && local && !network &&    /* Only makes sense for */
  6398.         mdmtyp == 0 &&                  /* direct serial connections */
  6399.         speed > 99L &&                  /* when we really know the speed */
  6400.         speed != 8880L
  6401.         ) {
  6402.         int eff;
  6403.         eff = (((tfcps * 100L) / (speed / 100L)) + 5L) / 10L;
  6404.         printf(" effective data rate    : %ld cps (%d%%)\n",tfcps,eff);
  6405.     } else
  6406.       printf(" effective data rate    : %ld cps\n", tfcps);
  6407.     if (!ftp && peakcps > 0L && peakcps > tfcps)
  6408.       printf(" peak data rate         : %ld cps\n", peakcps);
  6409.     if (brief)
  6410.       printf("\nUse STATISTICS /VERBOSE for greater detail.\n\n");
  6411.     return(1);
  6412. }
  6413. #endif /* NOXFER */
  6414.  
  6415. #ifndef NOSPL
  6416.  
  6417. /* The INPUT command */
  6418.  
  6419. /*
  6420.   NOTE: An INPUT timeout of 0 means to perform a nonblocking read of the
  6421.   material that has already arrived and is waiting to be read, and perform
  6422.   matches against it, without doing any further reads.  It should succeed
  6423.   or fail instantaneously.
  6424. */
  6425.  
  6426. /* Output buffering for "doinput" */
  6427.  
  6428. #ifdef pdp11
  6429. #define MAXBURST 16             /* Maximum size of input burst */
  6430. #else
  6431. #define MAXBURST 1024
  6432. #endif /* pdp11 */
  6433. #ifdef OSK
  6434. static CHAR *conbuf;            /* Buffer to hold output for console */
  6435. #else
  6436. static CHAR conbuf[MAXBURST];   /* Buffer to hold output for console */
  6437. #endif /* OSK */
  6438. static int concnt = 0;          /* Number of characters buffered */
  6439. #ifdef OSK
  6440. static CHAR *sesbuf;            /* Buffer to hold output for session log */
  6441. #else
  6442. static CHAR sesbuf[MAXBURST];   /* Buffer to hold output for session log */
  6443. #endif /* OSK */
  6444. static int sescnt = 0;          /* Number of characters buffered */
  6445.  
  6446. extern int debses;                      /* TERMINAL DEBUG ON/OFF */
  6447.  
  6448. static VOID                             /* Flush INPUT echoing */
  6449. myflsh() {                              /* and session log output. */
  6450.     if (concnt > 0) {
  6451.         if (debses) {                   /* Terminal debugging? */
  6452.             int i;
  6453.             for (i = 0; i < concnt; i++)
  6454.               conol(dbchr(conbuf[i]));
  6455.         } else
  6456.           conxo(concnt, (char *) conbuf);
  6457.         concnt = 0;
  6458.     }
  6459.     if (sescnt > 0) {
  6460.         logstr((char *) sesbuf, sescnt);
  6461.         sescnt = 0;
  6462.     }
  6463. }
  6464.  
  6465. /* Execute the INPUT and MINPUT commands */
  6466.  
  6467. int instatus = -1;
  6468. long inetime = -1L;
  6469. int inwait = 0;
  6470. int nowrap = 0;
  6471.  
  6472. /* For returning the input sequence that matched */
  6473.  
  6474. #ifdef BIGBUFOK
  6475. #define MATCHBUFSIZ 8191
  6476. #else
  6477. #define MATCHBUFSIZ 1023
  6478. #endif /* BIGBUFOK */
  6479. static char * matchbuf = NULL;
  6480. static int matchindex = 0;
  6481. static int burst = 0;                      /* Chars remaining in input burst */
  6482. /*
  6483.   timo = How long to wait:
  6484.          < 0 = Wait forever
  6485.            0 = Don't wait at all - material must already have arrived
  6486.          > 0 = Wait this many seconds
  6487.   ms   = Array of strings to wait for.
  6488.   mp   = Array of flags.
  6489.          If mp[i] == 0, ms[i] is literal, else it's a pattern.
  6490.   flags = bit mask
  6491.     INPSW_NOM = /NOMATCH = 1
  6492.     INPSW_CLR = /CLEAR   = 2
  6493.     INPSW_NOW = /NOWRAP  = 4
  6494.     INPSW_COU = /COUNT   = 8
  6495.   count = /COUNT: value if a /COUNT switch was given.
  6496.  
  6497.  Returns:
  6498.     0 on failure, 1 on success.
  6499. */
  6500. int
  6501.  
  6502. doinput(timo,ms,mp,flags,count)
  6503.     int timo; char *ms[]; int mp[]; int flags; int count; {
  6504.     extern int inintr;
  6505. #ifdef CK_AUTODL
  6506.     extern int inautodl;
  6507. #endif /* CK_AUTODL */
  6508.     int x, y, i, t, rt, icn, anychar = 0, mi[MINPMAX];
  6509. #ifdef GFTIMER
  6510.     CKFLOAT fpt = 0.0;
  6511. #endif /* GFTIMER */
  6512.     int savecount = 0;
  6513.     int nomatch = 0;
  6514.     int clearfirst = 0;
  6515.     int lastchar = 0;
  6516.     int waiting = 0;
  6517.     int imask = 0;
  6518.     char ch, *xp, *s;
  6519.     CHAR c;
  6520. #ifndef NOLOCAL
  6521. #ifdef OS2
  6522.     extern int term_io;
  6523.     int term_io_save;
  6524. #endif /* OS2 */
  6525. #endif /* NOLOCAL */
  6526. #ifdef TNCODE
  6527.     static int cr = 0;
  6528. #endif /* TNCODE */
  6529.     int is_tn = 0;
  6530. #ifdef SSHBUILTIN
  6531.     extern int ssh_cas;
  6532.     extern char * ssh_cmd;
  6533. #endif /* SSHBUILTIN */
  6534.  
  6535.     debug(F101,"input count","",count);
  6536.     debug(F101,"input flags","",flags);
  6537.  
  6538. /*
  6539.   CK_BURST enables the INPUT speedup code, which depends on ttchk() returning
  6540.   accurate information.  If INPUT fails with this code enabled, change the
  6541.   above "#define" to "#undef".
  6542. */
  6543. #define CK_BURST
  6544.  
  6545.     imask = cmask;
  6546.     if (parity) imask = 0x7f;
  6547.     inwait = timo;                      /* For \v(inwait) */
  6548.  
  6549.     /* Options from command switches */
  6550.  
  6551.     nowrap = flags & INPSW_NOW;        /* 4 = /NOWRAP */
  6552.     nomatch = flags & INPSW_NOM;    /* 1 = /NOMATCH */
  6553.     clearfirst = flags & INPSW_CLR;    /* 2 = /CLEAR */
  6554.     savecount = count;
  6555.  
  6556.     makestr(&inpmatch,NULL);
  6557.     if (!matchbuf) {
  6558.         matchbuf = malloc(MATCHBUFSIZ+1);
  6559.         matchbuf[0] = NUL;
  6560.     }
  6561.     matchindex = 0;
  6562.  
  6563.     /* If last time through we returned because of /NOWRAP and buffer full */
  6564.     /* now we have to clear the buffer to make room for another load. */
  6565.  
  6566.     if (nowrap && instatus == INP_BF)
  6567.       clearfirst = 1;
  6568.  
  6569.     if (clearfirst) {            /* INPUT /CLEAR */
  6570.     int i;
  6571.     myflsh();            /* Flush screen and log buffers */
  6572.     for (i = 0; i < inbufsize; i++)
  6573.       inpbuf[i] = NUL;
  6574.     inpbp = inpbuf;
  6575.     }
  6576.     is_tn =
  6577. #ifdef TNCODE
  6578.         (local && network && IS_TELNET()) || (!local && sstelnet)
  6579. #else
  6580.          0
  6581. #endif /* TNCODE */
  6582.           ;
  6583.  
  6584. #ifdef CK_SSL
  6585.     if (is_tn) if (ssl_raw_flag || tls_raw_flag) is_tn = 0;
  6586. #endif    /* CK_SSL */
  6587.  
  6588.     instatus = INP_IE;                  /* 3 = internal error */
  6589.     kbchar = 0;
  6590.  
  6591. #ifdef OSK
  6592.     if (conbuf == NULL) {
  6593.         if ((conbuf = (CHAR *)malloc(MAXBURST*2)) == NULL) {
  6594.             return(0);
  6595.         }
  6596.         sesbuf = conbuf + MAXBURST;
  6597.     }
  6598. #endif /* OSK */
  6599.  
  6600. #ifndef NOLOCAL
  6601.     if (local) {                        /* In local mode... */
  6602.         if ((waiting = ttchk()) < 0) {  /* check that connection is open */
  6603.         if (!quiet) {
  6604.         if ((!network 
  6605. #ifdef TN_COMPORT
  6606.               || istncomport()
  6607. #endif /* TN_COMPORT */
  6608.               ) && carrier != CAR_OFF)
  6609.             printf("?Carrier detect failure on %s.\n", ttname);
  6610.         else
  6611.             printf("?Connection %s %s is not open.\n",
  6612.                network ? "to" : "on",
  6613.                ttname
  6614.                );
  6615.         }
  6616.             instatus = INP_IO;
  6617.             return(0);
  6618.         }
  6619.         debug(F101,"doinput waiting","",waiting);
  6620.         y = ttvt(speed,flow);           /* Put line in "ttvt" mode */
  6621.         if (y < 0) {
  6622.             printf("?INPUT initialization error\n");
  6623.             instatus = INP_IO;
  6624.             return(0);                  /* Watch out for failure. */
  6625.         }
  6626.     }
  6627. #endif /* NOLOCAL */
  6628.  
  6629. #ifdef SSHBUILTIN
  6630.     if ( network && nettype == NET_SSH && ssh_cas && ssh_cmd && 
  6631.          !(strcmp(ssh_cmd,"kermit") && strcmp(ssh_cmd,"sftp"))) {
  6632.         if (!quiet)
  6633.       printf("?SSH Subsystem active: %s\n", ssh_cmd);
  6634.         instatus = INP_IKS;
  6635.         return(0);
  6636.     }
  6637. #endif /* SSHBUILTIN */
  6638.  
  6639.     debug(F111,"doinput ms[0]",ms[0],waiting);
  6640.  
  6641.     if (!ms[0] || isemptystring(ms[0])) { /* No search string was given nor */
  6642.     if (count < 2)              /* a /COUNT: switch so we just */
  6643.       anychar = 1;              /* wait for the first character */
  6644.     }
  6645.     if (nomatch) anychar = 0;        /* Don't match anything */
  6646.  
  6647.     if (!anychar && waiting == 0 && timo == 0)
  6648.       return(0);
  6649.  
  6650. #ifndef NODEBUG
  6651.     if (deblog) {
  6652.         char xbuf[24];
  6653.         debug(F101,"doinput anychar","",anychar);
  6654.         debug(F101,"doinput timo","",timo);
  6655.         debug(F101,"doinput echo","",inecho);
  6656. #ifdef CK_BURST
  6657.         debug(F101,"doinput burst","",burst);
  6658. #endif    /* CK_BURST */
  6659.         y = -1;
  6660.         while (ms[++y]) {
  6661.             sprintf(xbuf,"doinput string %2d",y); /* SAFE (24) */
  6662.             debug(F111,xbuf,ms[y],mp[y]);
  6663.         }
  6664.     }
  6665. #endif /* NODEBUG */
  6666.  
  6667. #ifdef IKS_OPTION
  6668.     if (is_tn) {
  6669.         /* If the remote side is in a state of IKS START-SERVER    */
  6670.         /* we request that the state be changed.  We will detect   */
  6671.         /* a failure to adhere to the request when we call ttinc() */
  6672.         if (TELOPT_U(TELOPT_KERMIT) &&
  6673.             TELOPT_SB(TELOPT_KERMIT).kermit.u_start)
  6674.           iks_wait(KERMIT_REQ_STOP,0);  /* Send Request-Stop */
  6675. #ifdef CK_AUTODL
  6676.         /* If we are processing packets during INPUT and we have not */
  6677.         /* sent a START message, do so now.                          */
  6678.         if (inautodl && TELOPT_ME(TELOPT_KERMIT) &&
  6679.             !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  6680.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  6681.         }
  6682. #endif /* CK_AUTODL */
  6683.     }
  6684. #endif /* IKS_OPTION */
  6685.     x = 0;                              /* Return code, assume failure */
  6686.     instatus = INP_TO;                  /* Status, assume timeout */
  6687.  
  6688.     for (y = 0; y < MINPMAX; y++)    /* Initialize... */
  6689.       mi[y] = 0;                        /*  ..string pattern match position */
  6690.  
  6691.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  6692.         y = -1;
  6693.         while ((xp = ms[++y])) {    /* Convert each target to lowercase */
  6694.             while (*xp) {
  6695.                 if (isupper(*xp)) *xp = (char) tolower(*xp);
  6696.                 xp++;
  6697.             }
  6698.         }
  6699.     }
  6700.     rtimer();                           /* Reset timer. */
  6701. #ifdef GFTIMER
  6702.     rftimer();                          /* Floating-point timer too. */
  6703. #endif /* GFTIMER */
  6704.     inetime = -1L;                      /* Initialize elapsed time. */
  6705.     t = 0;                              /* Time now is 0. */
  6706.     m_found = 0;                        /* Default to timed-out */
  6707.     incount = 0;                        /* Character counter */
  6708.     rt = (timo == 0) ? 0 : 1;           /* Character-read timeout interval */
  6709.  
  6710. #ifndef NOLOCAL
  6711. #ifdef OS2
  6712.     term_io_save = term_io;             /* Disable I/O by emulator */
  6713.     term_io = 0;
  6714. #endif /* OS2 */
  6715. #endif /* NOLOCAL */
  6716.  
  6717.     while (1) {                         /* Character-getting loop */
  6718. #ifdef CK_APC
  6719.         /* Check to see if there is an Autodown or other APC command */
  6720.         if (apcactive == APC_LOCAL ||
  6721.             (apcactive == APC_REMOTE && apcstatus != APC_OFF)) {
  6722.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  6723.                 debug(F110,"doinput about to execute APC",apcbuf,0);
  6724.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  6725.                 delmac("_apc_commands",1);
  6726.                 apcactive = APC_INACTIVE;
  6727. #ifdef DEBUG
  6728.             } else {
  6729.                 debug(F100,"doinput APC in progress","",0);
  6730. #endif /* DEBUG */
  6731.             }
  6732.         }
  6733. #endif /* CK_APC */
  6734.  
  6735.         if (timo == 0 && waiting < 1) { /* Special exit criterion */
  6736.             instatus = INP_TO;          /* for timeout == 0 */
  6737.             break;
  6738.         }
  6739.         if (local) {                    /* One case for local */
  6740.             y = ttinc(rt);              /* Get character from comm device */
  6741.             debug(F101,"doinput ttinc(rt) returns","",y);
  6742.             if (y < -1) {               /* Connection failed. */
  6743.                 instatus = INP_IO;      /* Status = i/o error */
  6744. #ifndef NOLOCAL
  6745. #ifdef OS2
  6746.                 term_io = term_io_save;
  6747. #endif /* OS2 */
  6748. #endif /* NOLOCAL */
  6749.                 switch (y) {
  6750.                   case -2:              /* Connection lost */
  6751.                     if (local && !network && carrier != CAR_OFF) {
  6752.                         dologend();
  6753.                         printf("Connection closed.\n");
  6754.                         ttclos(1);
  6755.                     }
  6756.                     break;
  6757.                   case -3:
  6758.                     dologend();
  6759.                     printf("Session Limit exceeded - closing connection.\n");
  6760.                     ttclos(1);
  6761.                   default:
  6762.                     break;
  6763.                 }
  6764.                 debug(F111,"doinput Connection failed","returning 0",y);
  6765.                 return(0);
  6766.             }
  6767.             if (inintr) {
  6768.                 debug(F111,"doinput","inintr",inintr);
  6769.                 if ((icn = conchk()) > 0) { /* Interrupted from keyboard? */
  6770.                     debug(F101,"input interrupted from keyboard","",icn);
  6771.                     kbchar = coninc(0);
  6772.                     if (kbchar >= 0) {
  6773.                         while (--icn > 0) {
  6774.                             debug(F110,"doinput","absorbing",0);
  6775.                             coninc(0);      /* Yes, absorb what was typed. */
  6776.                         }
  6777.                         instatus = INP_UI;  /* Fail and remember why. */
  6778.                         break;
  6779.                     }
  6780.                 }
  6781.             }
  6782.         } else {                        /* Another for remote */
  6783.             y = coninc(rt);
  6784.             debug(F101,"doinput coninc(rt) returns","",y);
  6785.         }
  6786.         if (y > -1) {                   /* A character arrived */
  6787.             debug(F111,"doinput","a character arrived",y);
  6788.             if (timo == 0)
  6789.               waiting--;
  6790. #ifndef OS2
  6791. #define TN_NOLO
  6792. #endif /* OS2 */
  6793. #ifdef NOLOCAL
  6794. #define TN_NOLO
  6795. #endif /* NOLOCAL */
  6796.  
  6797. #ifdef TN_NOLO
  6798.             debug(F100,"doinput TN_NOLO","",0);
  6799. #ifdef TNCODE
  6800.             /* Check for telnet protocol negotiation */
  6801.             if (is_tn) {
  6802.                 switch (y & 0xff) {
  6803.                   case IAC:
  6804.                     cr = 0;
  6805.                     myflsh();   /* Break from input burst for tn_doop() */
  6806. #ifdef CK_BURST
  6807.                     burst = 0;
  6808. #endif /* CK_BURST */
  6809.                     waiting -= 2;       /* (not necessarily...) */
  6810.                     switch (tn_doop((CHAR)(y & 0xff),duplex,ttinc)) {
  6811.                       case 2: duplex = 0; continue;
  6812.                       case 1: duplex = 1; continue;
  6813. #ifdef IKS_OPTION
  6814.                       case 4:
  6815.                         if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6816.                              !tcp_incoming) {
  6817.                             instatus = INP_IKS;
  6818.                             printf(
  6819.  " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6820.                                    );
  6821.                             break;
  6822.                         }
  6823.                         continue;
  6824. #endif /* IKS_OPTION */
  6825.                       case 6:           /* TELNET DO LOGOUT received */
  6826.             continue;
  6827.               case 7:
  6828.               case 3:        /* A quoted IAC */
  6829.             break;
  6830.                       default:
  6831.             continue;
  6832.                     }
  6833.                   case CR:
  6834.                     cr = 1;
  6835.                     break;
  6836.                   case NUL:
  6837.                     if (!TELOPT_U(TELOPT_BINARY) && cr) {
  6838.                         cr = 0;
  6839.                         continue;
  6840.                     }
  6841.                     cr = 0;
  6842.                     break;
  6843.                   default:
  6844.                     cr = 0;
  6845.                 }
  6846.                 /* I'm echoing remote chars */
  6847.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6848.                   ttoc((char)y);
  6849.             }
  6850. #endif /* TNCODE */
  6851. #ifdef CK_AUTODL
  6852.             /* Check for file transfer packets */
  6853.             if (inautodl) autodown(y);
  6854. #endif /* CK_AUTODL */
  6855. #else  /* TN_NOLO */
  6856.             debug(F100,"doinput !TN_NOLO","",0);
  6857. #ifdef TNCODE
  6858.             /* Check for telnet protocol negotiation */
  6859.             if (is_tn) {
  6860.                 int tx;
  6861.                 switch (y & 0xff) {
  6862.                   case IAC:
  6863.                     myflsh();   /* Break from input burst for tn_doop() */
  6864. #ifdef CK_BURST
  6865.                     burst = 0;
  6866. #endif /* CK_BURST */
  6867. #ifdef IKS_OPTION
  6868.                     tx = scriptwrtbuf((USHORT)y);
  6869.                     if (tx == 4) {
  6870.                         if (TELOPT_U(TELOPT_KERMIT) && 
  6871.                 TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6872.                             !tcp_incoming
  6873.                             ) {
  6874.                             instatus = INP_IKS;
  6875.                             printf(
  6876.   " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6877.                                    );
  6878.                             break;
  6879.                         }
  6880.                     } else if (tx == 6) {
  6881.                         /* TELNET DO LOGOUT received */
  6882.  
  6883.                     }
  6884. #else /* IKS_OPTION */
  6885.                     /* Handles Telnet negotiations */
  6886.                     tx = scriptwrtbuf((USHORT)y);
  6887.                     if (tx == 6) {
  6888.                         /* TELNET DO LOGOUT received */
  6889.                     }
  6890. #endif /* IKS_OPTION */
  6891.                     waiting -= 2;       /* (not necessarily...) */
  6892.                     cr = 0;
  6893.                     continue;           /* and autodownload check */
  6894.                   case CR:
  6895.                     cr = 1;
  6896.                     tx = scriptwrtbuf((USHORT)y);
  6897.                     if (tx == 6) {
  6898.                         /* TELNET DO LOGOUT received */
  6899.                     }
  6900.                     break;
  6901.                   case NUL:
  6902.                     cr = 0;
  6903.                     if (!TELOPT_U(TELOPT_BINARY) && cr)
  6904.                       continue;
  6905.                     tx = scriptwrtbuf((USHORT)y);
  6906.                     if (tx == 6) {
  6907.                         /* TELNET DO LOGOUT received */
  6908.                     }
  6909.                     break;
  6910.                   default:
  6911.                     cr = 0;
  6912.                     tx = scriptwrtbuf((USHORT)y);
  6913.                     if (tx == 6) {
  6914.                         /* TELNET DO LOGOUT received */
  6915.                     }
  6916.                 }
  6917.                 /* I'm echoing remote chars */
  6918.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6919.                   ttoc((CHAR)y);
  6920.             } else
  6921. #endif /* TNCODE */
  6922.               /* Handles terminal emulation responses */
  6923.               scriptwrtbuf((USHORT)y);
  6924. #endif /* TN_NOLO */
  6925.  
  6926.             /* Real input character to be checked */
  6927.  
  6928. #ifdef CK_BURST
  6929.             burst--;                    /* One less character waiting */
  6930.             debug(F101,"doinput burst","",burst);
  6931. #endif /* CK_BURST */
  6932.             c = (CHAR) (imask & (CHAR) y); /* Mask off any parity */
  6933.             inchar[0] = c;              /* Remember character for \v(inchar) */
  6934. #ifdef COMMENT
  6935. #ifdef CK_BURST
  6936.             /* Update "lastchar" time only once during input burst */
  6937.             if (burst <= 0)
  6938. #endif /* CK_BURST */
  6939. #endif /* COMMENT */
  6940.               lastchar = gtimer();      /* Remember when it came */
  6941.  
  6942.             if (c == '\0') {            /* NUL, we can't use it */
  6943.                 if (anychar) {          /* Except if any character will do? */
  6944.                     x = 1;              /* Yes, done. */
  6945.             instatus = INP_OK;
  6946.                     incount = 1;        /* This must be the first and only. */
  6947.                     break;
  6948.                 } else goto refill;    /* Otherwise continue INPUTting */
  6949.             }
  6950.             *inpbp++ = c;               /* Store char in circular buffer */
  6951.             incount++;                  /* Count it for \v(incount) */
  6952.  
  6953.         if (flags & INPSW_COU) {    /* INPUT /COUNT */
  6954.         if (--count < 1) {
  6955.             x = 1;
  6956.             instatus = INP_OK;
  6957.                     incount = savecount;
  6958.                     break;
  6959.         }
  6960.         }
  6961.             if (matchbuf) {
  6962.                 if (matchindex < MATCHBUFSIZ) {
  6963.                     matchbuf[matchindex++] = c;
  6964.                     matchbuf[matchindex] = NUL;
  6965.                 }
  6966.             }
  6967. #ifdef MAC
  6968.             {
  6969.                 extern char *ttermw;    /* fake pointer cast */
  6970.                 if (inecho) {
  6971.                     outchar(ttermw, c); /* echo to terminal window */
  6972.                     /* this might be too much overhead to do here ? */
  6973.                     updatecommand(ttermw);
  6974.                 }
  6975.             }
  6976. #else /* Not MAC */
  6977.             if (inecho) {               /* Buffer console output */
  6978.                 conbuf[concnt++] = c;
  6979.             }
  6980. #endif /* MAC */
  6981. #ifndef OS2
  6982.             if (seslog) {
  6983. #ifdef UNIX
  6984.                 if (sessft != 0 || c != '\r')
  6985. #else
  6986. #ifdef OSK
  6987.                 if (sessft != 0 || c != '\012')
  6988. #endif /* OSK */
  6989. #endif /* UNIX */
  6990.                   sesbuf[sescnt++] = c; /* Buffer session log output */
  6991.             }
  6992. #endif /* OS2 */
  6993.             if (anychar) {              /* Any character will do? */
  6994.                 x = 1;
  6995.         instatus = INP_OK;
  6996.                 break;
  6997.             }
  6998.             if (!inpcas[cmdlvl]) {      /* Ignore alphabetic case? */
  6999.                 if (isupper(c))         /* Yes, convert input char to lower */
  7000.                   c = (CHAR) tolower(c);
  7001.             }
  7002.             debug(F000,"doinput char","",c);
  7003.  
  7004.             /* Here is the matching section */
  7005.  
  7006.             y = -1;                     /* Loop thru search strings */
  7007.             while (!nomatch && (s = ms[++y])) {    /* ...as many as we have. */
  7008.                 if (mp[y]) {            /* Pattern match? */
  7009. #ifdef COMMENT
  7010.                     int j;
  7011.                     /* This is gross but it works... */
  7012.                     /* We could just as easily have prepended '*' to the  */
  7013.                     /* pattern and skipped the loop, except then we would */
  7014.                     /* not have any way to identify the matching string.  */
  7015.                     for (j = 0; j < matchindex; j++) {
  7016.                         if (ckmatch(s,&matchbuf[j],1,1)) {
  7017.                             matchindex = j;
  7018.                 instatus = INP_OK;
  7019.                             x = 1;
  7020.                             break;
  7021.                         }
  7022.                     }
  7023.                     if (x > 0)
  7024.                       break;
  7025. #else
  7026.                     /* July 2001 - ckmatch() returns match position. */
  7027.                     /* It works and it's not gross. */
  7028.             /* (4 = floating pattern) */
  7029.                     x = ckmatch(s,matchbuf,inpcas[cmdlvl],1+4);
  7030.                     if (x > 0) {
  7031.                         matchindex = x - 1;
  7032.             instatus = INP_OK;
  7033.                         x = 1;
  7034.                         break;
  7035.                     }
  7036. #endif /* COMMENT */
  7037.                     continue;
  7038.                 }                       /* Literal match. */
  7039.                 i = mi[y];              /* Match-position in search string. */
  7040.                 debug(F000,"compare char","",(CHAR)s[i]);
  7041.                 if (c == (CHAR) s[i]) { /* Check for match */
  7042.                     i++;                /* Got one, go to next character */
  7043.                 } else {                /* Don't have a match */
  7044.                     int j;
  7045.                     for (j = i; i > 0; ) { /* Back up in search string */
  7046.                         i--; /* (Do this here to prevent compiler foulup) */
  7047.                         /* j is the length of the substring that matched */
  7048.                         if (c == (CHAR) s[i]) {
  7049.                             if (!strncmp(s,&s[j-i],i)) {
  7050.                                 i++;          /* c actually matches -- cfk */
  7051.                                 break;
  7052.                             }
  7053.                         }
  7054.                     }
  7055.                 }
  7056.                 if ((CHAR) s[i] == (CHAR) '\0') { /* Matched to end? */
  7057.                     ckstrncpy(matchbuf,ms[y],MATCHBUFSIZ);
  7058.                     matchindex = 0;
  7059.             instatus = INP_OK;  /* Yes, */
  7060.                     x = 1;            
  7061.                     break;              /* done. */
  7062.                 }
  7063.                 mi[y] = i;              /* No, remember match-position */
  7064.             }
  7065.             if (x == 1) {               /* Set \v(minput) result */
  7066.         instatus = INP_OK;
  7067.                 m_found = y + 1;
  7068.                 break;
  7069.             }
  7070.             if (inpbp >= inpbuf + inbufsize) { /* Reached end of buffer? */
  7071.         if (nowrap) {        /* If /NOWRAP...*/
  7072.             instatus = INP_BF;    /* ...return indicating buffer full. */
  7073.             *inpbp = NUL;
  7074.             goto xinput;
  7075.         }
  7076.                 *inpbp = NUL;           /* Make it null-terminated */
  7077.                 inpbp = inpbuf;         /* Yes. */
  7078.             }
  7079.         }
  7080. #ifdef CK_BURST
  7081.         else if (y <= -1 && burst > 0) {
  7082.             debug(F111,"doinput (y<=-1&&burst>0)","burst",burst);
  7083.                                         /* A timeout occurred so there can't */
  7084.             burst = 0;                  /* be data waiting; must check timo */
  7085.         }
  7086.       refill:
  7087.         if (burst <= 0) {               /* No buffered chars remaining... */
  7088.             myflsh();                   /* Flush buffered output */
  7089.             if (local) {                /* Get size of next input burst */
  7090.                 burst = ttchk();
  7091.                 if (burst < 0) {        /* ttchk() says connection is closed */
  7092.                     instatus = INP_IO;  /* Status = i/o error */
  7093. #ifndef NOLOCAL
  7094. #ifdef OS2
  7095.                     term_io = term_io_save;
  7096. #endif /* OS2 */
  7097. #endif /* NOLOCAL */
  7098.  
  7099.             if ((!network 
  7100. #ifdef TN_COMPORT
  7101.                  || istncomport()
  7102. #endif /* TN_COMPORT */
  7103.              ) && carrier != CAR_OFF) {
  7104.     /* The test is written this way because the Microsoft compiler
  7105.      * is producing bad code if written:
  7106.      *
  7107.      *  if (network && (!istncomport() || carrier == CAR_OFF) )
  7108.      */
  7109.             break;
  7110.                      } else {
  7111.              printf("Fatal error - disconnected.\n");
  7112.              ttclos(1);
  7113.              break;
  7114.              }
  7115.                 }
  7116.                 if (inintr) {
  7117.                     if ((icn = conchk()) > 0) { /* Interrupt from keyboard? */
  7118.                         kbchar = coninc(0);
  7119.                         debug(F101,"input interrupted from keyboard","",icn);
  7120.                         while (--icn > 0) coninc(0); /* Yes, absorb chars. */
  7121.                         break;          /* And fail. */
  7122.                     }
  7123.                 }
  7124.             } else {
  7125.                 burst = conchk();
  7126.             }
  7127.             debug(F101,"doinput burst","",burst);
  7128.             /* Prevent overflow of "conbuf" and "sesbuf" */
  7129.             if (burst > MAXBURST)
  7130.               burst = MAXBURST;
  7131.  
  7132.             /* Did not match, timer exceeded? */
  7133.             t = gtimer();
  7134.             debug(F111,"doinput gtimer","burst",t);
  7135.             debug(F101,"doinput timo","",timo);
  7136.             if ((t >= timo) && (timo > 0))
  7137.               break;
  7138.             else if (insilence > 0 && (t - lastchar) > insilence)
  7139.               break;
  7140.         } else {
  7141.             debug(F111,"doinput (burst > 0)","burst",burst);
  7142.         }
  7143. #else  /* CK_BURST */
  7144.       refill:
  7145.         myflsh();                       /* Flush buffered output */
  7146.         /* Did not match, timer exceeded? */
  7147.         t = gtimer();
  7148.         debug(F111,"doinput gtimer","no burst",t);
  7149.         debug(F101,"doinput timo","",timo);
  7150.         if ((t >= timo) && (timo > -1))
  7151.           break;
  7152.         else if (insilence > 0 && (t - lastchar) > insilence)
  7153.           break;
  7154. #endif /* CK_BURST */
  7155.     }                                   /* Still have time left, continue. */
  7156.   xinput:
  7157.     myflsh();                           /* Flush buffered output */
  7158.     if (instatus == INP_BF) {        /* Buffer full and /NOWAIT */
  7159.     x = 0;                /* Must not succeed */
  7160.     } else {                /* Buffer full and /NOWAIT */
  7161.     if (nomatch) x = 1;        /* Succeed if nomatch and timed out */
  7162.     if (x > 0 && !nomatch)
  7163.       instatus = 0;
  7164.     }
  7165. #ifndef NOLOCAL
  7166. #ifdef OS2
  7167.     term_io = term_io_save;
  7168. #endif /* OS2 */
  7169. #endif /* NOLOCAL */
  7170. #ifdef COMMENT
  7171. #ifdef IKS_OPTION
  7172. #ifdef CK_AUTODL
  7173.     if (is_tn && TELOPT_ME(TELOPT_KERMIT) && inautodl) {
  7174.         tn_siks(KERMIT_STOP);           /* Send Kermit-Server Stop */
  7175.     }
  7176. #endif /* CK_AUTODL */
  7177. #endif /* IKS_OPTION */
  7178. #endif /* COMMENT */
  7179.  
  7180. #ifdef GFTIMER
  7181.     fpt = gftimer();                    /* Get elapsed time */
  7182.  
  7183. /* If a long is 32 bits, it would take about 50 days for this to overflow. */
  7184.  
  7185.     inetime = (int)(fpt * (CKFLOAT)1000.0);
  7186. #else
  7187.     inetime = (int)(gtimer() * 1000);
  7188. #endif /* GFTIMER */
  7189.  
  7190.     if (x > 0)
  7191.       makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  7192.     return(x);                          /* Return the return code. */
  7193. }
  7194. #endif /* NOSPL */
  7195.  
  7196. #ifndef NOSPL
  7197. /* REINPUT Command */
  7198.  
  7199. /*
  7200.   Note, the timeout parameter is required, but ignored.  Syntax is compatible
  7201.   with MS-DOS Kermit except timeout can't be omitted.  This function only
  7202.   looks at the characters already received and does not read any new
  7203.   characters from the connection.
  7204. */
  7205. int
  7206. doreinp(timo,s,pat) int timo; char *s; int pat; {
  7207.     int x, y, i;
  7208.     char *xx, *xp, *xq = (char *)0;
  7209.     CHAR c;
  7210.  
  7211.     if (!s) s = "";
  7212.     debug(F101,"doreinput pat","",pat);
  7213.  
  7214.     y = (int)strlen(s);
  7215.     debug(F111,"doreinput search",s,y);
  7216.  
  7217.     if (y > inbufsize) {                /* If search string longer than */
  7218.         debug(F101,"doreinput inbufsize","",inbufsize);
  7219.         return(0);                      /* input buffer, fail. */
  7220.     }
  7221.     makestr(&inpmatch,NULL);
  7222.     if (!matchbuf)
  7223.       matchbuf = malloc(MATCHBUFSIZ+1);
  7224.     matchindex = 0;
  7225.  
  7226.     x = 0;                              /* Return code, assume failure */
  7227.     i = 0;                              /* String pattern match position */
  7228.  
  7229.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  7230.         xp = malloc(y+2);               /* Make a separate copy of the */
  7231.         if (!xp) {                      /* search string. */
  7232.             printf("?malloc error 6\n");
  7233.             return(x);
  7234.         } else xq = xp;                 /* Keep pointer to beginning. */
  7235.         while (*s) {                    /* Yes, convert to lowercase */
  7236.             *xp = *s;
  7237.             if (isupper(*xp)) *xp = (char) tolower(*xp);
  7238.             xp++; s++;
  7239.         }
  7240.         *xp = NUL;                      /* Terminate it! */
  7241.         s = xq;                         /* Move search pointer to it. */
  7242.     }
  7243.     xx = *inpbp ? inpbp : inpbuf;       /* Current INPUT buffer pointer */
  7244.     do {
  7245.         c = *xx++;                      /* Get next character */
  7246.         if (!c) break;
  7247.         if (xx >= inpbuf + inbufsize)   /* Wrap around if necessary */
  7248.           xx = inpbuf;
  7249.         if (!inpcas[cmdlvl]) {          /* Ignore alphabetic case? */
  7250.             if (isupper(c)) c = (CHAR) tolower(c); /* Yes */
  7251.         }
  7252.         if (pat) {
  7253.             int j;
  7254.             if (matchbuf) {
  7255.                 if (matchindex < MATCHBUFSIZ) {
  7256.                     matchbuf[matchindex++] = c;
  7257.                     matchbuf[matchindex] = NUL;
  7258.                 }
  7259.                 for (j = 0; j < matchindex; j++) { /* Gross but effective */
  7260.                     if (ckmatch(s,&matchbuf[j],1,1)) {
  7261.                         debug(F101,"GOT IT","",j);
  7262.                         matchindex = j;
  7263.                         x = 1;
  7264.                         break;
  7265.                     }
  7266.                 }
  7267.             }
  7268.             if (x > 0)
  7269.               break;
  7270.             continue;
  7271.         }
  7272.         debug(F000,"doreinp char","",c);
  7273.         debug(F000,"compare char","",(CHAR) s[i]);
  7274.         if (((char) c) == ((char) s[i])) { /* Check for match */
  7275.             i++;                        /* Got one, go to next character */
  7276.         } else {                        /* Don't have a match */
  7277.             int j;
  7278.             for (j = i; i > 0; ) {      /* [jrs] search backwards for it  */
  7279.                 i--;
  7280.                 if (((char) c) == ((char) s[i])) {
  7281.                     if (!strncmp(s,&s[j-i],i)) {
  7282.                         i++;
  7283.                         break;
  7284.                     }
  7285.                 }
  7286.             }
  7287.         }                               /* [jrs] or return to zero from -1 */
  7288.         if (s[i] == '\0') {             /* Matched all the way to end? */
  7289.             ckstrncpy(matchbuf,s,MATCHBUFSIZ);
  7290.             matchindex = 0;
  7291.             x = 1;                      /* Yes, */
  7292.             break;                      /* done. */
  7293.         }
  7294.     } while (xx != inpbp && x < 1);     /* Until back where we started. */
  7295.  
  7296.     if (!inpcas[cmdlvl]) if (xq) free(xq); /* Free this if it was malloc'd. */
  7297.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  7298.     return(x);                          /* Return search result. */
  7299. }
  7300.  
  7301. /*  X X S T R I N G  --  Interpret strings containing backslash escapes  */
  7302. /*  Z Z S T R I N G  --  (new name...)  */
  7303. /*
  7304.  Copies result to new string.
  7305.   strips enclosing braces or doublequotes.
  7306.   interprets backslash escapes.
  7307.   returns 0 on success, nonzero on failure.
  7308.   tries to be compatible with MS-DOS Kermit.
  7309.  
  7310.  Syntax of input string:
  7311.   string = chars | "chars" | {chars}
  7312.   chars = (c*e*)*
  7313.   where c = any printable character, ascii 32-126
  7314.   and e = a backslash escape
  7315.   and * means 0 or more repetitions of preceding quantity
  7316.   backslash escape = \operand
  7317.   operand = {number} | number | fname(operand) | v(name) | $(name) | m(name)
  7318.   number = [r]n[n[n]]], i.e. an optional radix code followed by 1-3 digits
  7319.   radix code is oO (octal), xX (hex), dD or none (decimal) (see xxesc()).
  7320. */
  7321.  
  7322. #ifndef NOFRILLS
  7323. int
  7324. yystring(s,s2) char *s; char **s2; {    /* Reverse a string */
  7325.     int x;
  7326.     static char *new;
  7327.     new = *s2;
  7328.     if (!s || !new) return(-1);         /* Watch out for null pointers. */
  7329.     if ((x = (int)strlen(s)) == 0) {    /* Recursion done. */
  7330.         *new = '\0';
  7331.         return(0);
  7332.     }
  7333.     x--;                                /* Otherwise, call self */
  7334.     *new++ = s[x];                      /* to reverse rest of string. */
  7335.     s[x] = 0;
  7336.     return(yystring(s,&new));
  7337. }
  7338. #endif /* NOFRILLS */
  7339.  
  7340. static char ipabuf[16] = { NUL };       /* IP address buffer */
  7341.  
  7342. static char *
  7343. getip(s) char *s; {
  7344.     char c=NUL;                         /* Workers... */
  7345.     int i=0, p=0, d=0;
  7346.     int state = 0;                      /* State of 2-state FSA */
  7347.  
  7348.     while ((c = *s++)) {
  7349.         switch(state) {
  7350.           case 0:                       /* Find first digit */
  7351.             i = 0;                      /* Output buffer index */
  7352.             ipabuf[i] = NUL;            /* Initialize output buffer */
  7353.             p = 0;                      /* Period counter */
  7354.             d = 0;                      /* Digit counter */
  7355.             if (isdigit(c)) {           /* Have first digit */
  7356.                 d = 1;                  /* Count it */
  7357.                 ipabuf[i++] = c;        /* Copy it */
  7358.                 state = 1;              /* Change state */
  7359.             }
  7360.             break;
  7361.  
  7362.           case 1:                       /* In numeric field */
  7363.             if (isdigit(c)) {           /* Have digit */
  7364.                 if (++d > 3)            /* Too many */
  7365.                   state = 0;            /* Start over */
  7366.                 else                    /* Not too many */
  7367.                   ipabuf[i++] = c;      /* Keep it */
  7368.             } else if (c == '.' && p < 3) { /* Have a period */
  7369.                 p++;                    /* Count it */
  7370.                 if (d == 0)             /* Not preceded by a digit */
  7371.                   state = 0;            /* Start over */
  7372.                 else                    /* OK */
  7373.                   ipabuf[i++] = c;      /* Keep it */
  7374.                 d = 0;                  /* Reset digit counter */
  7375.             } else if (p == 3 && d > 0) { /* Not part of address */
  7376.                 ipabuf[i] = NUL;        /* If we have full IP address */
  7377.                 return((char *)ipabuf); /* Return it */
  7378.             } else {                    /* Otherwise */
  7379.                 state = 0;              /* Start over */
  7380.                 ipabuf[0] = NUL;        /* (in case no more chars left) */
  7381.             }
  7382.         }
  7383.     }                                   /* Fall thru at end of string */
  7384.     ipabuf[i] = NUL;                    /* Maybe we have one */
  7385.     return((p == 3 && d > 0) ? (char *)ipabuf : "");
  7386. }
  7387. #endif /* NOSPL */
  7388.  
  7389. /* Date Routines */
  7390.  
  7391. /* Z J D A T E  --  Convert yyyymmdd date to Day of Year */
  7392.  
  7393. static int jdays[12] = {  0,31,59,90,120,151,181,212,243,273,304,334 };
  7394. static int ldays[12] = {  0,31,60,91,121,152,182,213,244,274,305,335 };
  7395. static char zjdbuf[12] = { NUL, NUL };
  7396. /*
  7397.   Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat,
  7398.   statuimus bissextum quarto quoque anno (uti mos est) continuari debere,
  7399.   praeterquam in centesimis annis; qui, quamvis bissextiles antea semper
  7400.   fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps
  7401.   consequentur centesimi non omnes bissextiles sint, sed in quadringentis
  7402.   quibusque annis primi quique tres centesimi sine bissexto transigantur,
  7403.   quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC,
  7404.   MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus
  7405.   intercaletur, februario dies XXIX continente, idemque ordo intermittendi
  7406.   intercalandique bissextum diem in quadringentis quibusque annis perpetuo
  7407.   conservetur.  - Gregorius XIII, Anno Domini MDLXXXII.
  7408. */
  7409. char *
  7410. zjdate(date) char * date; {             /* date = yyyymmdd */
  7411.     char year[5];
  7412.     char month[3];
  7413.     char day[3];
  7414.     int d, m, x, y;
  7415.     int leapday, j;
  7416.     char * time = NULL;
  7417.  
  7418.     if (!date) date = "";               /* Validate arg */
  7419.     x = strlen(date);
  7420.     if (x < 1) return("0");
  7421.     if (x < 8) return("-1");
  7422.     for (x = 0; x < 8; x++)
  7423.       if (!isdigit(date[x]))
  7424.         return("-1");
  7425.  
  7426.     if (date[8]) if (date[9])
  7427.       time = date + 9;
  7428.  
  7429.     year[0] = date[0];                  /* Isolate year */
  7430.     year[1] = date[1];
  7431.     year[2] = date[2];
  7432.     year[3] = date[3];
  7433.     year[4] = '\0';
  7434.  
  7435.     month[0] = date[4];                 /* Month */
  7436.     month[1] = date[5];
  7437.     month[2] = '\0';;
  7438.  
  7439.     day[0] = date[6];                   /* And day */
  7440.     day[1] = date[7];
  7441.     day[2] = '\0';
  7442.  
  7443.     leapday = 0;                        /* Assume no leap day */
  7444.     y = atoi(year);
  7445.     m = atoi(month);
  7446.     d = atoi(day);
  7447.     if (m > 2) {                        /* No Leap day before March */
  7448.         if (y % 4 == 0) {               /* If year is divisible by 4 */
  7449.             leapday = 1;                /* It's a Leap year */
  7450.             if (y % 100 == 0) {         /* Except if divisible by 100 */
  7451.                 if (y % 400 != 0)       /* but not by 400 */
  7452.                   leapday = 0;
  7453.             }
  7454.         }
  7455.     }
  7456.     j = jdays[m - 1] + d + leapday;     /* Day of year */
  7457.     if (time)
  7458.       sprintf(zjdbuf,"%04d%03d %s",y,j,time); /* SAFE */
  7459.     else
  7460.       sprintf(zjdbuf,"%04d%03d",y,j);   /* SAFE */
  7461.     return((char *)zjdbuf);
  7462. }
  7463.  
  7464. static char jzdbuf[32];
  7465.  
  7466. /* J Z D A T E  --  Convert Day of Year to yyyyddmm date */
  7467.  
  7468. char *
  7469. jzdate(date) char * date; {             /* date = yyyyddd */
  7470.     char year[5];                       /* with optional time */
  7471.     char day[4];
  7472.     char * time = NULL, * p;
  7473.     int d, m, x, y;
  7474.     int leapday, j;
  7475.     int * zz;
  7476.  
  7477.     if (!date) date = "";               /* Validate arg */
  7478.     x = strlen(date);
  7479.  
  7480.     debug(F111,"jzdate len",date,x);
  7481.  
  7482.     if (x < 1) return("0");
  7483.     if (x < 7) return("-1");
  7484.     if (x > 8) time = date + 8;
  7485.  
  7486.     for (x = 0; x < 7; x++)
  7487.       if (!isdigit(date[x]))
  7488.         return("-1");
  7489.  
  7490.     year[0] = date[0];                  /* Isolate year */
  7491.     year[1] = date[1];
  7492.     year[2] = date[2];
  7493.     year[3] = date[3];
  7494.     year[4] = '\0';
  7495.  
  7496.     debug(F110,"jzdate year",year,0);
  7497.  
  7498.     day[0] = date[4];                   /* And day */
  7499.     day[1] = date[5];
  7500.     day[2] = date[6];
  7501.     day[3] = '\0';
  7502.  
  7503.     debug(F110,"jzdate day",day,0);
  7504.  
  7505.     j = atoi(day);
  7506.     if (j > 366)
  7507.       return("-1");
  7508.  
  7509.     leapday = 0;                        /* Assume no leap day */
  7510.     y = atoi(year);
  7511.     if (y % 4 == 0) {                   /* If year is divisible by 4 */
  7512.         leapday = 1;                    /* It's a Leap year */
  7513.         if (y % 100 == 0) {             /* Except if divisible by 100 */
  7514.             if (y % 400 != 0)           /* but not by 400 */
  7515.               leapday = 0;
  7516.         }
  7517.     }
  7518.     debug(F101,"jzdate leapday","",leapday);
  7519.     zz = leapday ? ldays : jdays;
  7520.  
  7521.     for (x = 0; x < 11; x++)
  7522.       if (j > zz[x] && j <= zz[x+1])
  7523.         break;
  7524.     m = x + 1;
  7525.  
  7526.     debug(F101,"jzdate m","",m);
  7527.  
  7528.     d = j - zz[x];
  7529.  
  7530.     debug(F101,"jzdate d","",d);
  7531.  
  7532.     if (time)
  7533.       sprintf(jzdbuf,"%04d%02d%02d %s",y,m,d,time); /* SAFE */
  7534.     else
  7535.       sprintf(jzdbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7536.  
  7537.     debug(F101,"jzdate jzdbuf",jzdbuf,0);
  7538.  
  7539.     p = ckcvtdate((char *)jzdbuf, 0);   /* Convert to standard form */
  7540.     ckstrncpy(jzdbuf,p,32);
  7541.     if (!time) jzdbuf[8] = NUL;         /* Remove time if not wanted */
  7542.     return((char *)jzdbuf);
  7543. }
  7544.  
  7545. /* M J D  --  Modified Julian Date */
  7546. /*
  7547.   Call with:
  7548.     Standard-format date-time string: yyyymmdd[ hh:mm:ss].
  7549.     The time, if any, is ignored.
  7550.  
  7551.   Returns:
  7552.     -1L on error, otherwise:
  7553.     The number of days since 17 Nov 1858 as a whole number:
  7554.     16 Nov 1858 = -1, 17 Nov 1858 = 0, 18 Nov 1858 = 1, 19 Nov 1858 = 2, ...
  7555.  
  7556.   The Modified Julian Date is defined by the International Astronomical
  7557.   Union as the true Julian date minus 2400000.5 days.  The true Julian
  7558.   date is the number days since since noon of 1 January 4713 BCE of the
  7559.   Julian proleptic calendar.  Conversions between calendar dates and
  7560.   Julian dates, however, assume Gregorian dating.
  7561. */
  7562. long
  7563. mjd(date) char * date; {
  7564.     char year[5];
  7565.     char month[3];
  7566.     char day[3];
  7567.     int x, a, d, m, y;
  7568.     long z;
  7569.  
  7570.     if (!date) date = "";               /* Validate arg */
  7571.     x = strlen(date);
  7572.     if (x < 1) return(0L);
  7573.     if (x < 8) return(-1L);
  7574.     for (x = 0; x < 8; x++)
  7575.       if (!isdigit(date[x]))
  7576.         return(-1L);
  7577.  
  7578.     year[0] = date[0];                  /* Isolate year */
  7579.     year[1] = date[1];
  7580.     year[2] = date[2];
  7581.     year[3] = date[3];
  7582.     year[4] = '\0';
  7583.  
  7584.     month[0] = date[4];                 /* Month */
  7585.     month[1] = date[5];
  7586.     month[2] = '\0';;
  7587.     m = atoi(month);
  7588.  
  7589.     day[0] = date[6];                   /* And day */
  7590.     day[1] = date[7];
  7591.     day[2] = '\0';
  7592.     d = atoi(day);
  7593.  
  7594.     a = (14-m)/12;                      /* Calculate true Julian date */
  7595.     y = atoi(year) + 4800 - a;
  7596.     m = m + 12 * a - 3;
  7597.     z = d + (long)(306*m+5)/10 + (long)(y*365) + y/4 - y/100 + y/400 - 32045L;
  7598.  
  7599.     z -= 2400001L;                      /* Convert JD to MJD */
  7600.  
  7601.     return(z);
  7602. }
  7603.  
  7604. static char mjd2dbuf[32];
  7605.  
  7606. /*  M J D 2 D A T E  --  Converts MJD to yyyymmdd  */
  7607.  
  7608. char *
  7609. #ifdef CK_ANSIC
  7610. mjd2date(long mjd)
  7611. #else
  7612. mjd2date(mjd) long mjd;
  7613. #endif /* CK_ANSIC */
  7614. /* mjd2date */ {
  7615.     long jd, l, n;
  7616.     int d, m, y;
  7617.     jd = (long)(mjd + 2400001L);
  7618.     l = jd + 68569;
  7619.     n = 4 * l / 146097L;
  7620.     l = l - (146097 * n + 3) / 4;
  7621.     y = 4000 * (l + 1) / 1461001L;
  7622.     l = l - 1461 * y / 4 + 31;
  7623.     m = 80 * l / 2447;
  7624.     d = l - 2447 * m / 80;
  7625.     l = m / 11;
  7626.     m = m + 2 - 12 * l;
  7627.     y = 100 * (n - 49) + y + l;
  7628.     sprintf(mjd2dbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7629.     return((char *)mjd2dbuf);
  7630. }
  7631.  
  7632. #ifndef NOSPL
  7633. static char ** flist = (char **) NULL;  /* File list for \fnextfile() */
  7634. static int flistn = 0;                  /* Number of items in file list */
  7635.  
  7636. /*
  7637.   The function return-value buffer must be global, since fneval() returns a
  7638.   pointer to it.  fneval() is called only by zzstring(), which always copies
  7639.   the result out of this buffer to somewhere else, so it's OK to have only
  7640.   one buffer for this in most cases.  However, since function calls can be
  7641.   nested -- e.g. functions whose arguments are functions, or recursive
  7642.   functions, at some point we should convert this to an array of buffers,
  7643.   indexed by function depth (which might or might not be the same as the
  7644.   "depth" variable).  Also, since function results are potentially quite big,
  7645.   we'd need to allocate and deallocate dynamically as we descend and ascend
  7646.   function depth.  Left for a future release...
  7647. */
  7648. char fnval[FNVALL+2];                   /* Function return value  */
  7649. static int fndepth = 0;                 /* (we don't actually use this yet) */
  7650. int fnsuccess = 1;
  7651. extern int fnerror;
  7652.  
  7653. /* f p f o r m a t  --  Floating-point number nicely formatted.  */
  7654. /*
  7655.    Returns results from a circular 1K buffer.
  7656.    Don't count on too many results remaining available at once; it could
  7657.    be anywhere from 5 to maybe 100, depending on the sizes of the results.
  7658. */
  7659. #ifdef CKFLOAT
  7660. #define FPFMTSIZ 1024
  7661. static char fpfmtbuf[FPFMTSIZ] = { NUL, NUL };
  7662. static int fpfbufpos = 0;               /* (why was this char before?) */
  7663.  
  7664. char *
  7665. fpformat(fpresult,places,round) CKFLOAT fpresult; int places, round; {
  7666.     char fbuf[16];                      /* For creating printf format */
  7667.     int nines = 0, sign = 0, x, y, i, j, size = 0;
  7668.     char * buf;
  7669.     CKFLOAT ftmp;
  7670.  
  7671.     x = places ? places : (fp_digits ? fp_digits : 6);
  7672.  
  7673.     debug(F101,"fpformat fpresult","",fpresult);
  7674.     debug(F101,"fpformat places","",places);
  7675.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7676.  
  7677.     ftmp = fpresult;
  7678.     if (ftmp < 0.0) ftmp = 0.0 - fpresult;
  7679.  
  7680. #ifdef FNFLOAT
  7681.     if (!fp_rounding &&                 /* If printf doesn't round, */
  7682.         (places > 0 ||                  /* round result to decimal places. */
  7683.          (places == 0 && round)))
  7684.       fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  7685.     y = (ftmp == 0.0) ? 1 : (int)log10(ftmp);
  7686.     size = y + x + 3;                   /* Estimated length of result */
  7687.     if (fpresult < 0.0) size++;
  7688. #else
  7689.     size = 200;                         /* No way to estimate, be generous */
  7690. #endif /* FNFLOAT */
  7691.  
  7692.     debug(F101,"fpformat size","",size);
  7693.  
  7694.     if (fpfbufpos > (FPFMTSIZ - size))  /* Wrap around if necessary */
  7695.       fpfbufpos = 0;
  7696.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7697.  
  7698.     buf = &fpfmtbuf[fpfbufpos];
  7699.  
  7700.     if (places > 0) {                   /* If places specified */
  7701.         /* use specified places to write given number of digits */
  7702.         sprintf(fbuf,"%%0.%df",places); /* SAFE */
  7703.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7704.     } else {                            /* Otherwise... */
  7705.         /* Go for max precision */
  7706.         sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  7707.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7708.     }
  7709.     if (buf[0] == '-') sign = 1;
  7710.     debug(F111,"fpresult 1 errno",buf,errno); /* Check for over/underflow */
  7711.     debug(F111,"fpresult 1 fpfbufpos",buf,fpfbufpos);
  7712.     /* Give requested decimal places */
  7713.     for (i = sign; i < FPFMTSIZ && buf[i]; i++) {
  7714.         if (buf[i] == '.')              /* First find the decimal point */
  7715.           break;
  7716.         else if (i > fp_digits + sign - 1) /* replacing garbage */
  7717.           buf[i] = '0';                 /* digits with 0... */
  7718.     }
  7719.     if (buf[i] == '.') {                /* Have decimal point */
  7720.         int gotend = 0;
  7721.         /* places < 0 so truncate fraction */
  7722.         if (places < 0 || (places == 0 && round)) {
  7723.             buf[i] = NUL;
  7724.         } else if (places > 0) {        /* d > 0 so this many decimal places */
  7725.             i++;                           /* First digit after decimal */
  7726.             for (j = 0; j < places; j++) { /* Truncate after d decimal */
  7727.                 if (!buf[j+i])        /* places or extend to d  */
  7728.                   gotend = 1;              /* decimal places. */
  7729.                 if (gotend || j+i+sign > fp_digits)
  7730.                   buf[j+i] = '0';
  7731.             }
  7732.             buf[j+i] = NUL;
  7733.         } else {                        /* places == 0 so Do The Right Thing */
  7734.             for (j = (int)strlen(buf) - 1; j > i+1; j--) {
  7735.                 if ((j - sign) > fp_digits)
  7736.                   buf[j] = '0';
  7737.                 if (buf[j] == '0')
  7738.                   buf[j] = NUL; /* Strip useless trailing 0's. */
  7739.                 else
  7740.                   break;
  7741.             }
  7742.         }
  7743.     }
  7744.     fpfmtbuf[FPFMTSIZ-1] = NUL;
  7745.     j = strlen(buf);
  7746.     sign = 0;
  7747.     for (i = j-1; i >= 0; i--) {
  7748.         if (buf[i] == '9')
  7749.           nines++;
  7750.         else
  7751.           break;
  7752.     }
  7753.     /* Do something about xx.xx99999999... */
  7754.     if (nines > 5) {
  7755.         if (isdigit(buf[i]) && i < FPFMTSIZ - 2) {
  7756.             buf[i] = buf[i] + 1;
  7757.             buf[i+1] = '0';
  7758.             buf[i+2] = '\0';
  7759.         }
  7760.     }
  7761.     if (!strncmp(buf,"-0.0",FPFMTSIZ))
  7762.       ckstrncpy(buf,"0.0",FPFMTSIZ);
  7763.     fpfbufpos += (int)strlen(buf) + 1;
  7764.     return((char *)buf);
  7765. }
  7766. #endif /* CKFLOAT */
  7767.  
  7768. static VOID
  7769. evalerr(fn) char * fn; {
  7770.     if (fndiags) {
  7771.         if (divbyzero)
  7772.           ckmakmsg(fnval,FNVALL,"<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  7773.         else
  7774.           ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  7775.     }
  7776. }
  7777.  
  7778.  
  7779. static int
  7780. ckcindex(c,s) char c, *s; {
  7781.     int rc;
  7782.     if (!c || !s) return(0);
  7783.     for (rc = 0; s[rc]; rc++) {
  7784.     if (c == s[rc]) return(rc+1);
  7785.     }
  7786.     return(0);
  7787. }
  7788.  
  7789. static char *
  7790. dokwval(s,sep) char * s, * sep; {
  7791.     char c = '\0', * p, * kw = NULL, * vp = NULL;
  7792.     char * rc = "0";            /* Return code */
  7793.     int x = 0;
  7794.     if (!s) return(rc);
  7795.     if (!*s) return(rc);
  7796.     debug(F110,"kwval arg",s,0);
  7797.     debug(F110,"kwval sep",sep,0);
  7798.     p = (char *)malloc((int)strlen(s)+1);
  7799.     if (!p) goto xdokwval;
  7800.     strcpy(p,s);                        /* SAFE */
  7801.     s = p;
  7802.     while (*s < '!' && *s > '\0')       /* Get first nonblank */
  7803.       s++;
  7804.     if (!*s) goto xdokwval;
  7805.     if (ckcindex(*s,sep))        /* Separator but no keyword */
  7806.       goto xdokwval;
  7807.     kw = s;                             /* Keyword */
  7808.     while (*s > ' ') {
  7809.     if (ckcindex(*s,sep)) {        /* keyword=... */
  7810.             c = *s;
  7811.             break;
  7812.         }
  7813.         s++;
  7814.     }
  7815.     if (*kw) rc = "1";            /* Have keyword, promote return code */
  7816.     *s++ = NUL;                         /* Terminate keyword */
  7817.     while (*s < '!' && *s > '\0')       /* Skip blanks */
  7818.       s++;
  7819.     if (!c && ckcindex(*s,sep)) {
  7820.         c = *s++;                       /* Have separator */
  7821.         while (*s < '!' && *s > '\0')   /* Skip blanks */
  7822.           s++;
  7823.     }
  7824.     if (c) {
  7825.         vp = s;
  7826.     if (*vp) rc = "2";        /* Have value, another promotion */
  7827. #ifdef COMMENT
  7828.         while (*s > ' ')                /* Skip to end */
  7829.           s++;
  7830.         *s = NUL;                       /* Terminate value */
  7831. #endif    /* COMMENT */
  7832.     }
  7833.     debug(F110,"kwval c",ckctoa(c),0);
  7834.     debug(F110,"kwval keyword",kw,0);
  7835.     debug(F110,"kwval value",vp,0);
  7836.     makestr(&lastkwval,kw);
  7837.     vp = brstrip(vp);
  7838.     debug(F110,"kwval value",vp,0);
  7839.     x = addmac(kw,vp);
  7840.     debug(F111,"kwval addmac",kw,x);
  7841.   xdokwval: 
  7842.     if (p) free(p);
  7843.     return((x < 0) ? "-1" : rc);
  7844. }
  7845.  
  7846. static int
  7847. isaarray(s) char * s; {            /* Is s an associative array element */
  7848.     int state = 0;
  7849.     CHAR c;
  7850.     if (!s) return(0);
  7851.     while ((c = *s++)) {
  7852.     if (!isprint(c)) {
  7853.         return(0);
  7854.     } else if (c == '<') {
  7855.         if (state != 0)
  7856.           return(0);
  7857.         state = 1;
  7858.     } else if (c == '>') {
  7859.         return((state != 1 || *s) ? 0 : 1);
  7860.     }
  7861.     }
  7862.     return(0);
  7863. }
  7864.  
  7865. static char *                           /* Evaluate builtin functions */
  7866. fneval(fn,argp,argn,xp) char *fn, *argp[]; int argn; char * xp; {
  7867.     int i=0, j=0, k=0, len1=0, len2=0, len3=0, n=0, t=0, x=0, y=0;
  7868.     int cx, failed = 0;                 /* Return code, 0 = ok */
  7869.     long z = 0L;
  7870.     char *bp[FNARGS + 1];               /* Pointers to malloc'd strings */
  7871.     char c = NUL;
  7872.     char *p = NULL, *s = NULL;
  7873.     char *val1 = NULL, *val2 = NULL;    /* Pointers to numeric string values */
  7874.  
  7875. #ifdef RECURSIVE
  7876.     int rsave = recursive;
  7877. #endif /* RECURSIVE */
  7878. #ifdef OS2
  7879.     int zsave = zxpn;
  7880. #endif /* OS2 */
  7881.  
  7882.     if (!fn) fn = "";                   /* Protect against null pointers */
  7883.     if (!*fn) return("");
  7884.  
  7885.     for (i = 0; i < FNARGS; i++)        /* Initialize argument pointers */
  7886.       bp[i] = NULL;
  7887. /*
  7888.   IMPORTANT: Note that argn is not an accurate count of the number of
  7889.   arguments.  We can't really tell if an argument is null until after we
  7890.   execute the code below.  So argn is really the maximum number of arguments
  7891.   we might have.  Argn should always be at least 1, even if the function is
  7892.   called with empty parentheses (but don't count on it).
  7893. */
  7894.     debug(F111,"fneval",fn,argn);
  7895.     debug(F110,"fneval",argp[0],0);
  7896.     if (argn > FNARGS)                  /* Discard excess arguments */
  7897.       argn = FNARGS;
  7898.  
  7899.     fndepth++;
  7900.     debug(F101,"fneval fndepth","",fndepth);
  7901.     p = fnval;
  7902.     fnval[0] = NUL;
  7903.     y = lookup(fnctab,fn,nfuncs,&x);    /* Look up the function name */
  7904.     cx = y;                             /* Because y is too generic... */
  7905.     if (cx < 0) {                        /* Not found */
  7906.         failed = 1;
  7907.         if (fndiags) {                  /* FUNCTION DIAGNOSTIC ON */
  7908.             int x;
  7909.             x = strlen(fn);
  7910.             /* The following sprintf's are safe */
  7911.             switch (cx) {
  7912.               case -1:
  7913.                 if (x + 32 < FNVALL)
  7914.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION:\\f%s()>",fn);
  7915.                 else
  7916.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION>");
  7917.                 break;
  7918.               case -2:
  7919.                 if (x + 26 < FNVALL)
  7920.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS:\\f%s()>",fn);
  7921.                 else
  7922.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS>");
  7923.                 break;
  7924.               case -3:
  7925.                 sprintf(fnval,"<ERROR:FUNCTION_NAME_MISSING:\\f()>");
  7926.                 break;
  7927.               default:
  7928.                 if (x + 26 < FNVALL)
  7929.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE:\\f%s()>",fn);
  7930.                 else
  7931.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE>");
  7932.                 break;
  7933.             }
  7934.         }
  7935.         goto fnend;                     /* Always leave via common exit */
  7936.     }
  7937.     fn = fnctab[x].kwd;                 /* Full name of function */
  7938.  
  7939.     if (argn < 0) {
  7940.         failed = 1;
  7941.         p = fnval;
  7942.         if (fndiags)
  7943.           sprintf(fnval,"<ERROR:MISSING_ARG:\\f%s()>",fn);
  7944.         goto fnend;
  7945.     }
  7946.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7947.         debug(F010,"flit",xp,0);
  7948.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7949.         goto fnend;
  7950.     }
  7951.  
  7952. #ifdef DEBUG
  7953.     if (deblog) {
  7954.         int j;
  7955.         for (j = 0; j < argn; j++)
  7956.       debug(F111,"fneval arg",argp[j],j);
  7957.     }
  7958. #endif /* DEBUG */
  7959.     for (j = argn-1; j >= 0; j--) {     /* Uncount empty trailing args */
  7960.         if (!argp[j])
  7961.           argn--;
  7962.         else if (!*(argp[j]))
  7963.           argn--;
  7964.         else break;
  7965.     }
  7966.     debug(F111,"fneval argn",fn,argn);
  7967. /*
  7968.   \fliteral() and \fcontents() are special functions that do not evaluate
  7969.   their arguments, and are treated specially here.  After these come the
  7970.   functions whose arguments are evaluated in the normal way.
  7971. */
  7972. #ifdef COMMENT
  7973.     /* (moved up) */
  7974.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7975.         debug(F110,"flit",xp,0);
  7976.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7977.         goto fnend;
  7978.     }
  7979. #endif /* COMMENT */
  7980.     if (cx == FN_CON) {                 /* Contents of variable, unexpanded. */
  7981.         char c;
  7982.         if (!(p = argp[0]) || !*p) {
  7983.             failed = 1;
  7984.             p = fnval;
  7985.             if (fndiags)
  7986.               sprintf(fnval,"<ERROR:MISSING_ARG:\\fcontents()>");
  7987.             goto fnend;
  7988.         }
  7989.         p = brstrip(p);
  7990.         if (*p == CMDQ) p++;
  7991.         if ((c = *p) == '%') {          /* Scalar variable. */
  7992.             c = *++p;                   /* Get ID character. */
  7993.             p = "";                     /* Assume definition is empty */
  7994.             if (!c) {                   /* Double paranoia */
  7995.                 failed = 1;
  7996.                 p = fnval;
  7997.                 if (fndiags)
  7998.                   sprintf(fnval,"<ERROR:ARG_BAD_VARIABLE:\\fcontents()>");
  7999.                 goto fnend;
  8000.             }
  8001.             if (c >= '0' && c <= '9') { /* Digit for macro arg */
  8002.                 if (maclvl < 0)         /* Digit variables are global */
  8003.                   p = g_var[c];         /* if no macro is active */
  8004.                 else                    /* otherwise */
  8005.                   p = m_arg[maclvl][c - '0']; /* they're on the stack */
  8006.             } else if (c == '*') {
  8007. #ifdef COMMENT
  8008.                 p = (maclvl > -1) ? m_line[maclvl] : topline;
  8009.                 if (!p) p = "";
  8010. #else
  8011.                 int nx = FNVALL;
  8012.                 char * sx = fnval;
  8013.                 p = fnval;
  8014. #ifdef COMMENT
  8015.                 if (cmdsrc() == 0 && topline)
  8016.                   p = topline;
  8017.                 else
  8018. #endif /* COMMENT */
  8019.                   if (zzstring("\\fjoin(&_[],{ },1)",&sx,&nx) < 0) {
  8020.                     failed = 1;
  8021.                     p = fnval;
  8022.                     if (fndiags)
  8023.                       sprintf(fnval,"<ERROR:OVERFLOW:\\fcontents()>");
  8024.             debug(F110,"zzstring fcontents(\\%*)",p,0);
  8025.                 }
  8026. #endif /* COMMENT */
  8027.             } else {
  8028.                 if (isupper(c)) c -= ('a'-'A');
  8029.                 p = g_var[c];           /* Letter for global variable */
  8030.             }
  8031.             if (!p) p = "";
  8032.             goto fnend;
  8033.         } else if (c == '&') {          /* Array reference. */
  8034.             int vbi, d;
  8035.             if (arraynam(p,&vbi,&d) < 0) { /* Get name and subscript */
  8036.                 failed = 1;
  8037.                 p = fnval;
  8038.                 if (fndiags)
  8039.                   sprintf(fnval,"<ERROR:ARG_BAD_ARRAY:\\fcontents()>");
  8040.                 goto fnend;
  8041.             }
  8042.             if (chkarray(vbi,d) >= 0) { /* Array is declared? */
  8043.                 vbi -= ARRAYBASE;       /* Convert name to index */
  8044.                 if (a_dim[vbi] >= d) {  /* If subscript in range */
  8045.                     char **ap;
  8046.                     ap = a_ptr[vbi];    /* get data pointer */
  8047.                     if (ap) {           /* and if there is one */
  8048.                         p = ap[d];
  8049.                         goto fnend;
  8050.                     }
  8051.                 }
  8052.             } else {
  8053.                 failed = 1;
  8054.                 p = fnval;
  8055.                 if (fndiags)
  8056.                   sprintf(fnval,"<ERROR:ARG_NOT_ARRAY:\\fcontents()>");
  8057.                 goto fnend;
  8058.             }
  8059.         } else {
  8060.             failed = 1;
  8061.             p = fnval;
  8062.             if (fndiags)
  8063.               sprintf(fnval,"<ERROR:ARG_NOT_VARIABLE:\\fcontents()>");
  8064.             goto fnend;
  8065.         }
  8066.     }
  8067.     p = fnval;                          /* Default result pointer */
  8068.     fnval[0] = NUL;                     /* Default result = empty string */
  8069.  
  8070.     for (i = 0; i < argn; i++) {        /* Loop to expand each argument */
  8071.         n = MAXARGLEN;                  /* Allow plenty of space */
  8072.         bp[i] = s = malloc(n+1);        /* Allocate space for this argument */
  8073.         if (bp[i] == NULL) {            /* Handle failure to get space */
  8074.             failed = 1;
  8075.             if (fndiags)
  8076.               ckmakmsg(fnval,FNVALL,"<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  8077.             goto fnend;
  8078.         }
  8079.         p = argp[i] ? argp[i] : "";     /* Point to this argument */
  8080.  
  8081. /*
  8082.   Trim leading and trailing spaces from the original argument, before
  8083.   evaluation.  This code new to edit 184.  Fixed in edit 199 to trim
  8084.   blanks BEFORE stripping braces.
  8085.  
  8086. */
  8087.         {
  8088.             int x, j;
  8089.             x = strlen(p);
  8090.             j = x - 1;                  /* Trim trailing whitespace */
  8091.             while (j > 0 && (*(p + j) == SP || *(p + j) == HT))
  8092.               *(p + j--) = NUL;
  8093.             while (*p == SP || *p == HT) /* Strip leading whitespace */
  8094.               p++;
  8095.             x = strlen(p);
  8096.             if (*p == '{' && *(p+x-1) == '}') { /* NOW strip braces */
  8097.                 p[x-1] = NUL;
  8098.                 p++;
  8099.                 x -= 2;
  8100.             }
  8101.         }
  8102.  
  8103. /* Now evaluate the argument */
  8104.  
  8105.         debug(F111,"fneval calling zzstring",p,n);
  8106.         t = zzstring(p,&s,&n);          /* Expand arg into new space */
  8107.         debug(F101,"fneval zzstring","",t);
  8108.         debug(F101,"fneval zzstring","",n);
  8109.         if (t < 0) {
  8110.             debug(F101,"fneval zzstring fails, arg","",i);
  8111.             failed = 1;
  8112.             if (fndiags) {
  8113.                 if (n == 0)
  8114.                   ckmakmsg(fnval,FNVALL,
  8115.                            "<ERROR:ARG_TOO_LONG:\\f",fn,"()>",NULL);
  8116.                 else
  8117.                   ckmakmsg(fnval,FNVALL,
  8118.                            "<ERROR:ARG_EVAL_FAILURE:\\f",fn,"()>",NULL);
  8119.             }
  8120.             goto fnend;
  8121.         }
  8122.         debug(F111,"fneval arg",bp[i],i);
  8123.     }
  8124.  
  8125. #ifdef DEBUG
  8126.     if (deblog) {
  8127.         int j;
  8128.         for (j = 0; j < argn; j++) {
  8129.             debug(F111,"fneval arg post eval",argp[j],j);
  8130.             debug(F111,"fneval evaluated arg",bp[j],j);
  8131.         }
  8132.     }
  8133. #endif /* DEBUG */
  8134.     {
  8135.     /* Adjust argn for empty trailing arguments. */
  8136.     /* For example when an arg is a variable name but the */
  8137.     /* variable has no value.   July 2006. */
  8138.     int j, old; char *p;
  8139.     old = argn;
  8140.     for (j = argn - 1; j >= 0; j--) {
  8141.         p = bp[j];
  8142.         if (!p)
  8143.           argn--;
  8144.         else if (!*p)
  8145.           argn--;
  8146.         else
  8147.           break;
  8148.     }
  8149. #ifdef DEBUG
  8150.     if (argn != old)
  8151.       debug(F101,"fneval adjusted argn","",argn);
  8152. #endif    /* DEBUG */
  8153.     }    
  8154.  
  8155. /*
  8156.   From this point on, bp[0..argn-1] are not NULL and all must be freed
  8157.   before returning.
  8158. */
  8159.     if (argn < 1) {                     /* Catch required args missing */
  8160.         switch (cx) {
  8161.           case FN_DEF:
  8162.           case FN_EVA:
  8163.           case FN_EXE:
  8164.           case FN_CHR:
  8165.           case FN_COD:
  8166.           case FN_MAX:
  8167.           case FN_MIN:
  8168.           case FN_MOD:
  8169.           case FN_FD:
  8170.           case FN_FS:
  8171.           case FN_TOD:
  8172.           case FN_FFN:
  8173.           case FN_BSN:
  8174.           case FN_RAW:
  8175.           case FN_CMD:
  8176.           case FN_2HEX:
  8177.           case FN_2OCT:
  8178.           case FN_DNAM:
  8179. #ifdef FN_ERRMSG
  8180.           case FN_ERRMSG:
  8181. #endif /* FN_ERRMSG */
  8182. #ifdef CK_KERBEROS
  8183.           case FN_KRB_TK:
  8184.           case FN_KRB_NX:
  8185.           case FN_KRB_IV:
  8186.           case FN_KRB_TT:
  8187.           case FN_KRB_FG:
  8188. #endif /* CK_KERBEROS */
  8189.           case FN_MJD2:
  8190.           case FN_N2TIM:
  8191.           case FN_DIM:
  8192.           case FN_DATEJ:
  8193.           case FN_PNCVT:
  8194.           case FN_PERM:
  8195.           case FN_ALOOK:
  8196.           case FN_TLOOK:
  8197.           case FN_ABS:
  8198.           case FN_AADUMP:
  8199.           case FN_JOIN:
  8200. #ifdef CKFLOAT
  8201.           case FN_FPABS:
  8202.           case FN_FPEXP:
  8203.           case FN_FPLOG:
  8204.           case FN_FPLN:
  8205.           case FN_FPMOD:
  8206.           case FN_FPSQR:
  8207.           case FN_FPADD:
  8208.           case FN_FPDIV:
  8209.           case FN_FPMUL:
  8210.           case FN_FPPOW:
  8211.           case FN_FPSUB:
  8212.           case FN_FPINT:
  8213.           case FN_FPROU:
  8214.           case FN_FPSIN:
  8215.           case FN_FPCOS:
  8216.           case FN_FPTAN:
  8217. #endif /* CKFLOAT */
  8218. #ifdef TCPSOCKET
  8219.           case FN_HSTADD:
  8220.           case FN_HSTNAM:
  8221. #endif /* TCPSOCKET */
  8222.           case FN_DELSEC:
  8223. #ifdef COMMENT
  8224.           case FN_KWVAL:
  8225.           case FN_SLEEP:
  8226.           case FN_MSLEEP:
  8227. #endif /* COMMENT */
  8228. #ifdef NT
  8229.           case FN_SNAME:
  8230.           case FN_LNAME:
  8231. #endif /* NT */
  8232.             failed = 1;
  8233.             p = fnval;
  8234.             if (fndiags)
  8235.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  8236.             goto fnend;
  8237.         }
  8238.     }
  8239.     p = fnval;                          /* Reset these again. */
  8240.     fnval[0] = NUL;
  8241.  
  8242.     switch (cx) {                       /* Do function on expanded args. */
  8243. #ifdef TCPSOCKET
  8244.       case FN_HSTADD:
  8245.         p = ckaddr2name(bp[0]);
  8246.         goto fnend;
  8247.       case FN_HSTNAM:
  8248.         p = ckname2addr(bp[0]);
  8249.         goto fnend;
  8250. #endif /* TCPSOCKET */
  8251.  
  8252.       case FN_DEF:                      /* \fdefinition(arg1) */
  8253.         k = isaarray(bp[0]) ?
  8254.         mxxlook(mactab,bp[0],nmac) :
  8255.         mxlook(mactab,bp[0],nmac);
  8256.         p = (k > -1) ? mactab[k].mval : "";
  8257.         goto fnend;
  8258.  
  8259.       case FN_EVA:                      /* \fevaluate(arg1) */
  8260.         p = *(bp[0]) ? evalx(bp[0]) : "";
  8261.         if (!*p && fndiags) {
  8262.             failed = 1;
  8263.             p = fnval;
  8264.             evalerr(fn);
  8265.         }
  8266.         goto fnend;
  8267.  
  8268.       case FN_EXE:                      /* \fexecute(arg1) */
  8269.         j = (int)strlen(s = bp[0]);     /* Length of macro invocation */
  8270.         p = "";                         /* Initialize return value to null */
  8271.         if (j) {                        /* If there is a macro to execute */
  8272.             while (*s == SP) s++,j--;   /* strip leading spaces */
  8273.             p = s;                      /* remember beginning of macro name */
  8274.             for (i = 0; i < j; i++) {   /* find end of macro name */
  8275.                 if (*s == SP)
  8276.                   break;
  8277.                 s++;
  8278.             }
  8279.             if (*s == SP)       {       /* if there was a space after */
  8280.                 *s++ = NUL;             /* terminate the macro name */
  8281.                 while (*s == SP) s++;   /* skip past any extra spaces */
  8282.             } else
  8283.               s = "";                   /* maybe there are no arguments */
  8284.             if (p && *p) {
  8285.                 k = mlook(mactab,p,nmac); /* Look up the macro name */
  8286.                 debug(F111,"fexec mlook",p,k);
  8287.             } else
  8288.               k = -1;
  8289.             if (k < 0) {
  8290.                 char * p2 = p;
  8291.                 failed = 1;
  8292.                 p = fnval;
  8293.                 if (fndiags)
  8294.                   ckmakxmsg(fnval,FNVALL,
  8295.                             "<ERROR:NO_SUCH_MACRO:\\f",fn,"(",p2,")>",
  8296.                             NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  8297.                 goto fnend;
  8298.             }
  8299. /*
  8300.   This is just a WEE bit dangerous because we are copying up to 9 arguments
  8301.   into the space reserved for one.  It won't overrun the buffer, but if there
  8302.   are lots of long arguments we might lose some.  The other problem is that if
  8303.   the macro has more than 3 arguments, the 4th through last are all
  8304.   concatenated onto the third.  (The workaround is to use spaces rather than
  8305.   commas to separate them.)  Leaving it like this to avoid having to allocate
  8306.   tons more buffers.
  8307. */
  8308.             if (argn > 1) {             /* Commas used instead of spaces */
  8309.                 int i;
  8310.                 char *p = bp[0];        /* Reuse this space */
  8311.                 *p = NUL;               /* Make into dodo() arg list */
  8312.                 for (i = 1; i < argn; i++) {
  8313.                     ckstrncat(p,bp[i],MAXARGLEN);
  8314.                     ckstrncat(p," ",MAXARGLEN);
  8315.                 }
  8316.                 s = bp[0];              /* Point to new list */
  8317.             }
  8318.             p = "";                     /* Initialize return value */
  8319.             if (k >= 0) {               /* If macro found in table */
  8320.                 /* Go set it up (like DO cmd) */
  8321.                 if ((j = dodo(k,s,cmdstk[cmdlvl].ccflgs)) > 0) {
  8322.                     if (cmpush() > -1) { /* Push command parser state */
  8323.                         extern int ifc;
  8324.                         int ifcsav = ifc; /* Push IF condition on stack */
  8325.                         k = parser(1);  /* Call parser to execute the macro */
  8326.                         cmpop();        /* Pop command parser */
  8327.                         ifc = ifcsav;   /* Restore IF condition */
  8328.                         if (k == 0) {   /* No errors, ignore action cmds. */
  8329.                             p = mrval[maclvl+1]; /* If OK, set return value. */
  8330.                             if (p == NULL) p = "";
  8331.                         }
  8332.                     } else {            /* Can't push any more */
  8333.                         debug(F100,"zzstring fneval fexec failure","",0);
  8334.                         printf("\n?\\fexec() too deeply nested\n");
  8335.                         while (cmpop() > -1) ;
  8336.                         p = "";
  8337.                     }
  8338.                 }
  8339.             }
  8340.         }
  8341.         debug(F110,"zzstring fneval fexecute final p",p,0);
  8342.         goto fnend;
  8343.  
  8344. #ifdef RECURSIVE
  8345.       case FN_RDIR:                     /* \frdir..() - Recursive dir count */
  8346.       case FN_RFIL:                     /* \frfiles() - Recursive file count */
  8347.         /* recursive = 2; */            /* fall thru... */
  8348. #endif /* RECURSIVE */
  8349.       case FN_FC:                       /* \ffiles() - File count. */
  8350.       case FN_DIR: {                    /* \ffdir.() - Directory count. */
  8351.           char abuf[16], *s;
  8352.           char ** ap = NULL;
  8353.           int x, xflags = 0;
  8354.           if (matchdot)
  8355.             xflags |= ZX_MATCHDOT;
  8356.           if (cx == FN_RDIR || cx == FN_RFIL) {
  8357.               xflags |= ZX_RECURSE;
  8358. #ifdef CKSYMLINK
  8359.               /* Recursive - don't follow symlinks */
  8360.               xflags |= ZX_NOLINKS;
  8361. #endif /* CKSYMLINK */
  8362.           }
  8363.           failed = 0;
  8364.           if (argn < 1) {
  8365.               p = "0";
  8366.               goto fnend;
  8367.           }
  8368.           if (cx == FN_DIR || cx == FN_RDIR) { /* Only list directories */
  8369.           debug(F100,"FN_DIR or FN_RDIR","",0);
  8370.               xflags |= ZX_DIRONLY;
  8371. #ifdef OS2
  8372.               zxpn = 1;                 /* Use the alternate list */
  8373. #endif /* OS2 */
  8374.           } else {                      /* List only files */
  8375.           debug(F100,"Not FN_DIR or FN_RDIR","",0);
  8376.               xflags |= ZX_FILONLY;
  8377. #ifdef OS2
  8378.               zxpn = 1;                 /* Use the alternate list */
  8379. #endif /* OS2 */
  8380.           }
  8381.           if (*(bp[0])) {
  8382.               k = nzxpand(bp[0],xflags);
  8383.               if (k < 0) k = 0;
  8384.               sprintf(fnval,"%d",k);    /* SAFE */
  8385.               p = fnval;
  8386.           } else
  8387.             p = "0";
  8388.  
  8389.           if (argn > 1) {               /* Assign list to array */
  8390.               fnval[0] = NUL;           /* Initial return value */
  8391.               ckstrncpy(abuf,bp[1],16); /* Get array reference */
  8392.               s = abuf;
  8393.               if (*s == CMDQ) s++;
  8394.               failed = 1;               /* Assume it's bad */
  8395.               p = fnval;                /* Point to result */
  8396.               if (fndiags)              /* Default is this error message */
  8397.                 ckmakmsg(fnval,FNVALL,
  8398.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  8399.               if (s[0] != '&')          /* "Address" of array */
  8400.                 goto fnend;
  8401.               if (s[2])
  8402.                 if (s[2] != '[' || s[3] != ']')
  8403.                   goto fnend;
  8404.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  8405.                 s[1] += 32;
  8406.               if ((x = dclarray(s[1],k)) < 0) /* File list plus count */
  8407.                 goto fnend;
  8408.               failed = 0;               /* Unset failure flag */
  8409.               ap = a_ptr[x];            /* Point to array we just declared */
  8410.               sprintf(fnval,"%d",k);    /* SAFE */
  8411.           }
  8412. #ifdef OS2
  8413.           if (ap) {                     /* We are making an array */
  8414.               int i;
  8415.               char tmp[16];
  8416.               ap[0] = NULL;             /* Containing number of files    */
  8417.               makestr(&(ap[0]),ckitoa(k));
  8418.  
  8419.               ckstrncpy(tmp,fnval,16);  /* Save return value */
  8420.  
  8421.               for (i = 1; i <= k; i++) { /* Fill it */
  8422.                   ap[i] = NULL;
  8423.                   znext(fnval);         /* Next filename */
  8424.                   if (!*fnval)          /* No more, done */
  8425.                     break;              /* In case a premature end */
  8426.                   makestr(&(ap[i]),fnval);
  8427.               }
  8428. #ifdef ZXREWIND
  8429.               k = zxrewind();           /* Reset the file expansion */
  8430. #else
  8431.               k = nzxpand(bp[0],xflags);
  8432. #endif /* ZXREWIND */
  8433.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8434.           }
  8435. #else /* OS2 */
  8436.           {                             /* Make copies of the list */
  8437.               int i; char tmp[16];
  8438.               if (flist) {              /* Free old file list, if any */
  8439.                   for (i = 0; flist[i]; i++) { /* and each string */
  8440.                       free(flist[i]);
  8441.                       flist[i] = NULL;
  8442.                   }
  8443.                   free((char *)flist);
  8444.               }
  8445.               ckstrncpy(tmp,fnval,16);  /* Save our return value */
  8446.               flist = (char **) malloc((k+1) * sizeof(char *)); /* New array */
  8447.               if (flist) {
  8448.                   for (i = 0; i <= k; i++) { /* Fill it */
  8449.                       flist[i] = NULL;
  8450.                       znext(fnval);     /* Next filename */
  8451.                       if (!*fnval)      /* No more, done */
  8452.                         break;
  8453.                       makestr(&(flist[i]),fnval);
  8454.                   }
  8455.                   if (ap) {             /* If array pointer given */
  8456.                       ap[0] = NULL;
  8457.                       makestr(&(ap[0]),ckitoa(k));
  8458.                       for (i = 0; i < k; i++) { /* Copy file list to array */
  8459.                           ap[i+1] = NULL;
  8460.                           makestr(&(ap[i+1]),flist[i]);
  8461.                       }
  8462.                   }
  8463.               }
  8464.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8465.               flistn = 0;               /* Reset global list pointer */
  8466.           }
  8467. #endif /* OS2 */
  8468. #ifdef RECURSIVE
  8469.           recursive = rsave;
  8470. #endif /* RECURSIVE */
  8471. #ifdef OS2
  8472.           zxpn = zsave;
  8473. #endif /* OS2 */
  8474.       }
  8475.       goto fnend;
  8476.  
  8477.       case FN_FIL:                      /* \fnextfile() - Next file in list. */
  8478.         p = fnval;                      /* (no args) */
  8479.         *p = NUL;
  8480. #ifdef OS2
  8481.         zxpn = 1;                       /* OS/2 - use the alternate list */
  8482.         znext(p);                       /* Call system-dependent function */
  8483.         zxpn = zsave;                   /* Restore original list */
  8484. #else
  8485.         if (flist)                      /* Others, use our own list. */
  8486.           if (flist[flistn])
  8487.         p = flist[flistn++];
  8488. #endif /* OS2 */
  8489.         goto fnend;
  8490.  
  8491.     } /* Break up big switch... */
  8492.  
  8493.     switch (cx) {
  8494.       case FN_IND:                      /* \findex(s1,s2,start,occurrence) */
  8495.       case FN_RIX:                      /* \frindex(s1,s2,start,occurrence) */
  8496.       case FN_SEARCH:                   /* \fsearch(pat,string,start,occ) */
  8497.       case FN_RSEARCH:            /* \frsearch(pat,string,start,occ) */
  8498.       case FN_COUNT: {            /* \fcount(s1,s2,start) */
  8499.     int i = 0, right = 0, search = 0, count = 0;
  8500.     int desired = 1;
  8501.         right = (cx == FN_RIX || cx == FN_RSEARCH);
  8502.         search = (cx == FN_SEARCH || cx == FN_RSEARCH);
  8503.     count = (cx == FN_COUNT);
  8504.         p = "0";
  8505.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8506.             int start = 0;
  8507.             char * pat = NULL;
  8508.             len1 = (int)strlen(pat = bp[0]); /* length of string to look for */
  8509.             len2 = (int)strlen(s = bp[1]); /* length of string to look in */
  8510.             if (len1 < 1 || len2 < 1)   /* Watch out for empty strings */
  8511.               goto fnend;
  8512.             start = right ? -1 : 0;     /* Default starting position */
  8513.             if (argn > 2) {
  8514.                 val1 = *(bp[2]) ? evalx(bp[2]) : "1";
  8515.         if (argn > 3) {
  8516.             val2 = *(bp[3]) ? evalx(bp[3]) : "1";
  8517.             if (chknum(val2)) desired = atoi(val2);
  8518.             if (desired * len1 > len2) goto fnend;
  8519.         }
  8520.                 if (chknum(val1)) {
  8521.                     int t;
  8522.                     t = atoi(val1);
  8523.                     if (!search) {      /* Index or Rindex */
  8524.                         j = len2 - len1; /* Length difference */
  8525.                         t--;             /* Convert position to 0-based */
  8526.                         if (t < 0) t = 0;
  8527.                         start = t;
  8528.                         if (!right && start < 0) start = 0;
  8529.                     } else {            /* Search or Rsearch */
  8530.                         int x;
  8531.                         if (t < 0) t = 0;
  8532.                         if (right) {    /* Right to left */
  8533.                             if (t > len2) t = len2;
  8534.                             start = len2 - t - 1;
  8535.                             if (start < 0)
  8536.                               goto fnend;
  8537.                             x = len2 - t;
  8538.                             s[x] = NUL;
  8539.                         } else {        /* Left to right */
  8540.                             start = t - 1;
  8541.                             if (start < 0) start = 0;
  8542.                             if (start >= len2)
  8543.                               goto fnend;
  8544.                         }
  8545.                     }
  8546.                 } else {
  8547.                     failed = 1;
  8548.                     evalerr(fn);
  8549.                     p = fnval;
  8550.                     goto fnend;
  8551.                 }
  8552.             }
  8553.         if (count) {        /* \fcount() */
  8554.         int j;
  8555.         for (i = 0; start < len2; i++) {
  8556.             j = ckindex(pat,bp[1],start,0,inpcas[cmdlvl]);
  8557.             if (j == 0) break;
  8558.             start = j;
  8559.         }
  8560.  
  8561.         } else if (search) {    /* \fsearch() or \frsearch() */
  8562.  
  8563.                 if (right && pat[0] == '^') {
  8564.                     right = 0;
  8565.                     start = 0;
  8566.                 }
  8567.                 if (right) {        /* From right */
  8568.             int k, j = 1;
  8569.                     if (start < 0)
  8570.               start = len2 - 1;
  8571.             i = 0;
  8572.             while (start >= 0 && j <= desired) {
  8573.             for (i = start;
  8574.                  (i >= 0) && 
  8575.                  !(k = ckmatch(pat,s+i,inpcas[cmdlvl],1+4));
  8576.                  i--) ;
  8577.             if (k < 1) {    /* No match */
  8578.                 i = 0;
  8579.                 break;
  8580.             }
  8581.             if (j == desired) { /* The match we want? */
  8582.                 i += k;    /* Yes, return string index */
  8583.                 break;
  8584.             }
  8585.             j++;        /* No, count this match */
  8586.             s[i] = NUL;    /* null it out */
  8587.             start = i-1;    /* move left and look again */
  8588.             }
  8589.  
  8590.                 } else {        /* From left */
  8591.             int j;
  8592.             i = 0;
  8593.             for (j = 1; j <= desired && start < len2; j++) {
  8594.             i = ckmatch(pat,&s[start],inpcas[cmdlvl],1+4);
  8595.             if (i == 0 || j == desired) break;
  8596.             start += i + 1;
  8597.             }            
  8598.             if (j == desired && i != 0)
  8599.               i += start;
  8600.             else
  8601.               i = 0;
  8602.                 }
  8603.             } else {            /* index or rindex */
  8604.         int j = 0;
  8605.         i = 0;
  8606.         for (j = 1; j <= desired && start < len2; j++) {
  8607.             i = ckindex(pat,bp[1],start,right,inpcas[cmdlvl]);
  8608.             if (i == 0 || j == desired) break;
  8609.             start = (right) ? len2 - i + 1 : i;
  8610.         }
  8611.         if (j != desired)
  8612.           i = 0;
  8613.             }
  8614.             sprintf(fnval,"%d",i);      /* SAFE */
  8615.             p = fnval;
  8616.         }
  8617.         goto fnend;
  8618.       }
  8619.  
  8620.       case FN_RPL:                      /* \freplace(s1,s2,s3) */
  8621.       /*
  8622.         s = bp[0] = source string
  8623.             bp[1] = match string
  8624.             bp[2] = replacement string
  8625.             bp[3] = which occurrence (default = all);
  8626.         p = fnval = destination (result) string
  8627.       */
  8628.         if (argn < 1)                   /* Nothing */
  8629.           goto fnend;
  8630.         if (argn < 2) {                 /* Only works if we have 2 or 3 args */
  8631.             ckstrncpy(p,bp[0],FNVALL);
  8632.         } else {
  8633.             int occur = 0, xx = 0, j2;
  8634.             len1 = (int)strlen(bp[0]);  /* length of string to look in */
  8635.             len2 = (int)strlen(bp[1]);  /* length of string to look for */
  8636.             len3 = (argn < 3) ? 0 : (int)strlen(bp[2]); /* Len of replacemnt */
  8637.             j = len1 - len2 + 1;
  8638.             j2 = j;
  8639.             if (argn > 3) {
  8640.                 if (chknum(bp[3])) {
  8641.                     occur = atoi(bp[3]);
  8642.                 } else {
  8643.                     failed = 1;
  8644.                     if (fndiags)
  8645.                       ckmakmsg(fnval,FNVALL,
  8646.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8647.                     goto fnend;
  8648.                 }
  8649.             }
  8650.             /* If args out of whack... */
  8651.             if (j < 1 || len1 == 0 || len2 == 0) {
  8652.                 ckstrncpy(p,bp[0],FNVALL); /* just return original string */
  8653.                 p[FNVALL] = NUL;
  8654.             } else {
  8655.               ragain:
  8656.                 s = bp[0];              /* Point to beginning of string */
  8657.                 while (j-- > 0) {       /* For each character */
  8658.                     if (!ckstrcmp(bp[1],s,len2,inpcas[cmdlvl]) &&
  8659.                         (occur == 0 || occur == ++xx)) {
  8660.                         if (len3) {
  8661.                             ckstrncpy(p,bp[2],FNVALL);
  8662.                             p += len3;
  8663.                         }
  8664.                         s += len2;      /* and skip past it. */
  8665.                     } else {            /* No, */
  8666.                         *p++ = *s++;    /* just copy this character */
  8667.                     }
  8668.                 }
  8669.                 *p = NUL;
  8670.                 while ((*p++ = *s++));
  8671.                 if (occur < 0) {        /* cheap... */
  8672.                     occur = xx + occur + 1;
  8673.                     xx = 0;
  8674.                     p = fnval;
  8675.                     j = j2;
  8676.                     if (occur > 0)
  8677.                       goto ragain;
  8678.                 }
  8679.             }
  8680.         }
  8681.         p = fnval;
  8682.         goto fnend;
  8683.  
  8684.       case FN_CHR:                      /* \fcharacter(arg1) */
  8685.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8686.         if (chknum(val1)) {             /* Must be numeric */
  8687.             i = atoi(val1);
  8688.             if (i >= 0 && i < 256) {    /* Must be an 8-bit value */
  8689.                 p = fnval;
  8690.                 *p++ = (char) i;
  8691.                 *p = NUL;
  8692.                 p = fnval;
  8693.             } else {
  8694.                 failed = 1;
  8695.                 if (fndiags)
  8696.                   ckmakmsg(fnval,FNVALL,
  8697.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  8698.             }
  8699.         } else {
  8700.             failed = 1;
  8701.             evalerr(fn);
  8702.         }
  8703.         goto fnend;
  8704.  
  8705.       case FN_COD:                      /* \fcode(char) */
  8706.         if ((int)strlen(bp[0]) > 0) {
  8707.             p = fnval;
  8708.             i = *bp[0];
  8709.             sprintf(p,"%d",(i & 0xff)); /* SAFE */
  8710.         } else p = "0";            /* Can't happen */
  8711.         goto fnend;
  8712.  
  8713.       case FN_LEN:                      /* \flength(arg1) */
  8714.         if (argn > 0) {
  8715.             p = fnval;
  8716.             sprintf(p,"%d",(int)strlen(bp[0])); /* SAFE */
  8717.         } else p = "0";
  8718.         goto fnend;
  8719.  
  8720.       case FN_LOW:                      /* \flower(arg1) */
  8721.         s = bp[0] ? bp[0] : "";
  8722.         p = fnval;
  8723.         while (*s) {
  8724.             if (isupper(*s))
  8725.               *p = (char) tolower(*s);
  8726.             else
  8727.               *p = *s;
  8728.             p++; s++;
  8729.         }
  8730.         *p = NUL;
  8731.         p = fnval;
  8732.         goto fnend;
  8733.  
  8734.       case FN_MAX:                      /* \fmax(arg1,arg2) */
  8735.       case FN_MIN:                      /* \fmin(arg1,arg2) */
  8736.       case FN_MOD:                      /* \fmod(arg1,arg2) */
  8737.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8738. #ifdef COMMENT
  8739.         /* No longer necessary because evalx() no longer overwrites its */
  8740.         /* result every time it's called (2000/09/23). */
  8741.         free(bp[0]);
  8742.         bp[0] = NULL;
  8743. #endif /* COMMENT */
  8744.         if (argn > 1) {
  8745. #ifdef COMMENT
  8746.             /* Ditto... */
  8747.             bp[0] = malloc((int)strlen(val1)+1);
  8748.             if (bp[0])
  8749.               strcpy(bp[0],val1);       /* safe */
  8750.             val1 = bp[0];
  8751. #endif /* COMMENT */
  8752.             val2 = *(bp[1]) ? evalx(bp[1]) : "";
  8753.             if (chknum(val1) && chknum(val2)) {
  8754.                 i = atoi(val1);
  8755.                 j = atoi(val2);
  8756.                 switch (y) {
  8757.                   case FN_MAX:
  8758.                     if (j < i) j = i;
  8759.                     break;
  8760.                   case FN_MIN:
  8761.                     if (j > i) j = i;
  8762.                     break;
  8763.                   case FN_MOD:
  8764.                     if (j == 0) {
  8765.                         failed = 1;
  8766.                         if (fndiags)
  8767.                           ckmakmsg(fnval,FNVALL,
  8768.                                    "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  8769.                         else
  8770.                           fnval[0] = NUL;
  8771.                         goto fnend;
  8772.                     } else
  8773.                       j = i % j;
  8774.                 }
  8775.                 p = fnval;
  8776.                 sprintf(p,"%d",j);      /* SAFE */
  8777.             } else {
  8778.                 failed = 1;
  8779.                 evalerr(fn);
  8780.             }
  8781.         } else p = val1;
  8782.         goto fnend;
  8783.     } /* Break up big switch... */
  8784.  
  8785.     switch (y) {
  8786.       case FN_SUB:                      /* \fsubstr(arg1,arg2,arg3) */
  8787.       case FN_RIG:                      /* \fright(arg1,arg2) */
  8788.       case FN_LEF:                      /* \fleft(arg1,arg2) */
  8789.         if (argn < 1)
  8790.           goto fnend;
  8791.         val1 = "";
  8792.         if (argn > 1)
  8793.           if (*(bp[1]))
  8794.             val1 =  evalx(bp[1]);
  8795. #ifdef COMMENT
  8796.         if (bp[1]) free(bp[1]);         /* Have to copy this */
  8797.         bp[1] = malloc((int)strlen(val1)+1);
  8798.         if (!bp[1]) {
  8799.             failed = 1;
  8800.             if (fndiags) {
  8801.                 p = fnval;
  8802.                 ckmakmsg(fnval,FNVALL,
  8803.                          "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  8804.             }
  8805.             goto fnend;
  8806.         }
  8807.         strcpy(bp[1],val1);             /* safe */
  8808.         val1 = bp[1];
  8809. #endif /* COMMENT */
  8810.         val2 = "";
  8811.         if (argn > 2)
  8812.           if (*(bp[2]))
  8813.             val2 = evalx(bp[2]);
  8814.         if (
  8815.             ((argn > 1) && (int)strlen(val1) && !rdigits(val1)) ||
  8816.             ((cx == FN_SUB) &&
  8817.               ((argn > 2) && (int)strlen(val2) && !rdigits(val2)))
  8818.             ) {
  8819.             failed = 1;
  8820.             evalerr(fn);
  8821.         } else {
  8822.             int lx;
  8823.             p = fnval;                  /* pointer to result */
  8824.             lx = strlen(bp[0]);         /* length of arg1 */
  8825.             if (cx == FN_SUB) {         /* substring */
  8826.                 k = (argn > 2) ? atoi(val2) : MAXARGLEN; /* length */
  8827.                 j = (argn > 1) ? atoi(val1) : 1; /* start pos for substr */
  8828.             } else if (cx == FN_LEF) {  /* left */
  8829.                 k = (argn > 1) ? atoi(val1) : lx;
  8830.                 j = 1;
  8831.             } else {                             /* right */
  8832.                 k = (argn > 1) ? atoi(val1) : lx; /* length */
  8833.                 j = lx - k + 1;                  /* start pos for right */
  8834.                 if (j < 1) j = 1;
  8835.             }
  8836.             if (k > 0 && j <= lx) {              /* if start pos in range */
  8837.                 s = bp[0]+j-1;                   /* point to source string */
  8838.                 for (i = 0; (i < k) && (*p++ = *s++); i++) ;  /* copy */
  8839.             }
  8840.             *p = NUL;                   /* terminate the result */
  8841.             p = fnval;                  /* and point to it. */
  8842.         }
  8843.         goto fnend;
  8844.  
  8845.       case FN_UPP:                      /* \fupper(arg1) */
  8846.         s = bp[0] ? bp[0] : "";
  8847.         p = fnval;
  8848.         while (*s) {
  8849.             if (islower(*s))
  8850.               *p = (char) toupper(*s);
  8851.             else
  8852.               *p = *s;
  8853.             p++; s++;
  8854.         }
  8855.         *p = NUL;
  8856.         p = fnval;
  8857.         goto fnend;
  8858.  
  8859.       case FN_REP:                      /* \frepeat(text,number) */
  8860.         if (argn < 1)
  8861.           goto fnend;
  8862.         val1 = "1";
  8863.         if (argn > 1)
  8864.           if (*(bp[1]))
  8865.             val1 = evalx(bp[1]);
  8866.         if (chknum(val1)) {             /* Repeat count */
  8867.             n = atoi(val1);
  8868.             debug(F111,"SUNDAY frepeat n",val1,n);
  8869.             if (n > 0) {                /* Make n copies */
  8870.                 p = fnval;
  8871.                 *p = '\0';
  8872.                 k = (int)strlen(bp[0]); /* Make sure string has some length */
  8873.                 debug(F111,"SUNDAY frepeat k","",k);
  8874.                 debug(F111,"SUNDAY frepeat FNVALL","",FNVALL);
  8875.                 if (k * n >= FNVALL) {  /* But not too much... */
  8876.                     failed = 1;
  8877.                     if (fndiags)
  8878.                       ckmakmsg(fnval,FNVALL,
  8879.                                "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  8880.                     else
  8881.                       fnval[0] = NUL;
  8882.                     p = fnval;
  8883.                     goto fnend;
  8884.                 }
  8885.                 if (k > 0) {            /* If there is something to copy */
  8886.                     for (i = 0; i < n; i++) { /* Copy loop */
  8887.                         s = bp[0];
  8888.                         for (j = 0; j < k; j++) {
  8889.                             if ((p - fnval) >= FNVALL)
  8890.                               break;    /* shouldn't happen... */
  8891.                             else
  8892.                               *p++ = *s++;
  8893.                         }
  8894.                     }
  8895.                     *p = NUL;
  8896.                 }
  8897.             }
  8898.         } else {
  8899.             failed = 1;
  8900.             evalerr(fn);
  8901.         }
  8902.         p = fnval;
  8903.         goto fnend;
  8904.  
  8905. #ifndef NOFRILLS
  8906.       case FN_REV:                      /* \freverse() */
  8907.         if (argn < 1)
  8908.           goto fnend;
  8909.         yystring(bp[0],&p);
  8910.         goto fnend;
  8911. #endif /* NOFRILLS */
  8912.  
  8913.       case FN_RPA:                      /* \frpad() and \flpad() */
  8914.       case FN_LPA:
  8915.         if (argn < 1)
  8916.           goto fnend;
  8917.         val1 = "";
  8918.         if (argn > 1)
  8919.           if (*(bp[1]))
  8920.             val1 = evalx(bp[1]);
  8921.         if (argn == 1) {                /* If a number wasn't given */
  8922.             p = fnval;                  /* just return the original string */
  8923.             ckstrncpy(p,bp[0],FNVALL);
  8924.         } else if (argn > 1 &&  !*val1) {
  8925.             failed = 1;
  8926.             evalerr(fn);
  8927.         } else /* if (chknum(val1)) */ { /* Repeat count */
  8928.             char pc;
  8929.             n = atoi(val1);
  8930.             if (n >= 0) {
  8931.                 p = fnval;
  8932.                 k = (int)strlen(bp[0]); /* Length of string to be padded */
  8933.                 if (k >= n) {           /* It's already long enough */
  8934.                     ckstrncpy(p,bp[0],FNVALL);
  8935.                 } else {
  8936.                     if (n + k <= FNVALL) {
  8937.                         pc = (char) ((argn < 3) ? SP : *bp[2]);
  8938.                         if (!pc) pc = SP;
  8939.                         if (cx == FN_RPA) { /* RPAD */
  8940.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8941.                             p[k] = NUL;
  8942.                             p += k;
  8943.                             for (i = k; i < n; i++)
  8944.                               *p++ = pc;
  8945.                         } else {        /* LPAD */
  8946.                             n -= k;
  8947.                             for (i = 0; i < n; i++)
  8948.                               *p++ = pc;
  8949.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8950.                             p[k] = NUL;
  8951.                             p += k;
  8952.                         }
  8953.                     }
  8954.                     *p = NUL;
  8955.                 }
  8956.             }
  8957.         }
  8958.         p = fnval;
  8959.         goto fnend;
  8960.  
  8961. #ifdef ZFCDAT
  8962.       case FN_FD:                       /* \fdate(filename) */
  8963.         p = fnval;
  8964.         s = zfcdat(bp[0]);
  8965.         if (!s) s = "";
  8966.         if (!*s) {
  8967.             failed = 1;
  8968.             if (fndiags)
  8969.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8970.             goto fnend;
  8971.         }
  8972.         ckstrncpy(fnval,s,FNVALL);
  8973. #endif /* ZFCDAT */
  8974.         goto fnend;
  8975.  
  8976.     } /* Break up big switch... */
  8977.  
  8978.     switch (y) {
  8979.       case FN_FS: {            /* \fsize(filename) */
  8980.       CK_OFF_T z;
  8981.       p = fnval;
  8982.       z = zchki(bp[0]);
  8983.       if (z < (CK_OFF_T)0) {
  8984.           failed = 1;
  8985.           if (fndiags) {
  8986.           if (z == (CK_OFF_T)-1)
  8987.             ckmakmsg(fnval,FNVALL,
  8988.                  "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8989.           else if (z == (CK_OFF_T)-2)
  8990.             ckmakmsg(fnval,FNVALL,
  8991.                  "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  8992.           else if (z == (CK_OFF_T)-3)
  8993.             ckmakmsg(fnval,FNVALL,
  8994.                  "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  8995.           else
  8996.             ckmakmsg(fnval,FNVALL,
  8997.                  "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  8998.           }
  8999.           goto fnend;
  9000.       }
  9001.       ckstrncpy(fnval,ckfstoa(z),FNVALL);
  9002.       goto fnend;
  9003.       }
  9004.       case FN_VER:                      /* \fverify() */
  9005.     p = "-1";
  9006.     if (argn == 1)            /* No second arg */
  9007.       goto fnend;
  9008.     else if (!bp[1])        /* Or second arg null */
  9009.       goto fnend;
  9010.     else if (!*(bp[1]))        /* or empty. */
  9011.       goto fnend;
  9012.         p = "0";
  9013.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  9014.             int start;
  9015.             char *s2, ch1, ch2;
  9016.             start = 0;
  9017.             if (argn > 2) {             /* Starting position specified */
  9018.                 val1 = *(bp[2]) ? evalx(bp[2]) : "0";
  9019.                 if (chknum(val1)) {
  9020.                     start = atoi(val1) /* - 1 */;
  9021.                     if (start < 0) start = 0;
  9022.                     if (start > (int)strlen(bp[1]))
  9023.                       goto verfin;
  9024.                 } else {
  9025.                     failed = 1;
  9026.                     evalerr(fn);
  9027.                     goto fnend;
  9028.                 }
  9029.             }
  9030.             i = start;
  9031.             p = "0";
  9032.             for (s = bp[1] + start; *s; s++,i++) {
  9033.                 ch1 = *s;
  9034.                 if (!inpcas[cmdlvl]) if (islower(ch1)) ch1 = toupper(ch1);
  9035.                 j = 0;
  9036.                 for (s2 = bp[0]; *s2; s2++) {
  9037.                     ch2 = *s2;
  9038.                     if (!inpcas[cmdlvl]) if (islower(ch2)) ch2 = toupper(ch2);
  9039.                     if (ch1 == ch2) {
  9040.                         j = 1;
  9041.                         break;
  9042.                     }
  9043.                 }
  9044.                 if (j == 0) {
  9045.                     sprintf(fnval,"%d",i+1); /* SAFE */
  9046.                     p = fnval;
  9047.                     break;
  9048.                 }
  9049.             }
  9050.         }
  9051.       verfin:
  9052.         goto fnend;
  9053.  
  9054.       case FN_IPA:                      /* Find and return IP address */
  9055.         if (argn > 0) {                 /* in argument string. */
  9056.             int start = 0;
  9057.             if (argn > 1) {             /* Starting position specified */
  9058.                 if (chknum(bp[1])) {
  9059.                     start = atoi(bp[1]) - 1;
  9060.                     if (start < 0) start = 0;
  9061.                 } else {
  9062.                     failed = 1;
  9063.                     if (fndiags)
  9064.                       ckmakmsg(fnval,FNVALL,
  9065.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9066.                     goto fnend;
  9067.                 }
  9068.             }
  9069.             p = getip(bp[0]+start);
  9070.         } else p = "";
  9071.         goto fnend;
  9072.  
  9073. #ifdef OS2
  9074.       case FN_CRY:
  9075.         p = "";
  9076.         if (argn > 0) {
  9077.             p = fnval;
  9078.             ckstrncpy(p,bp[0],FNVALL);
  9079.             ck_encrypt(p);
  9080.         }
  9081.         goto fnend;
  9082.  
  9083.       case FN_OOX:
  9084.         p = "";
  9085.         if (argn > 0)
  9086.           p = (char *) ck_oox(bp[0], (argn > 1) ? bp[1] : "");
  9087.         goto fnend;
  9088. #endif /* OS2 */
  9089.  
  9090.       case FN_HEX:                      /* \fhexify(arg1) */
  9091.         if (argn < 1)
  9092.           goto fnend;
  9093.         if ((int)strlen(bp[0]) < (FNVALL / 2)) {
  9094.             s = bp[0];
  9095.             p = fnval;
  9096.             while (*s) {
  9097.                 x = (*s >> 4) & 0x0f;
  9098.                 *p++ = hexdigits[x];
  9099.                 x = *s++ & 0x0f;
  9100.                 *p++ = hexdigits[x];
  9101.             }
  9102.             *p = NUL;
  9103.             p = fnval;
  9104.         }
  9105.         goto fnend;
  9106.  
  9107.       case FN_UNTAB:            /* \funtab(arg1) */
  9108.     if (argn < 1)
  9109.       goto fnend;
  9110.     if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  9111.         s = bp[0];
  9112.         p = fnval;
  9113.         if (untabify(bp[0],p,FNVALL) < 0) {
  9114.         failed = 1;
  9115.         if (fndiags)
  9116.           ckmakmsg(fnval,FNVALL,
  9117.                "<ERROR:OVERFLOW:\\f",fn,"()>",NULL);
  9118.         }
  9119.         goto fnend;
  9120.     }
  9121.  
  9122.       case FN_UNH: {                    /* \funhex(arg1) */
  9123.           int c[2], i;
  9124.           if (argn < 1)
  9125.             goto fnend;
  9126.           if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  9127.               s = bp[0];
  9128.               p = fnval;
  9129.               while (*s) {
  9130.                   for (i = 0; i < 2; i++) {
  9131.                       c[i] = *s++;
  9132.                       if (!c[i]) { p = ""; goto unhexfin; }
  9133.                       if (islower(c[i])) c[i] = toupper(c[i]);
  9134.                       if (c[i] >= '0' && c[i] <= '9') {
  9135.                           c[i] -= 0x30;
  9136.                       } else if (c[i] >= 'A' && c[i] <= 'F') {
  9137.                           c[i] -= 0x37;
  9138.                       } else {
  9139.                           failed = 1;
  9140.                           if (fndiags)
  9141.                             ckmakmsg(fnval,
  9142.                                      FNVALL,
  9143.                                      "<ERROR:ARG_OUT_OF_RANGE:\\f",
  9144.                                      fn,
  9145.                                      "()>",
  9146.                                      NULL
  9147.                                      );
  9148.                           goto fnend;
  9149.                       }
  9150.                   }
  9151.                   *p++ = ((c[0] << 4) & 0xf0) | (c[1] & 0x0f);
  9152.               }
  9153.               *p = NUL;
  9154.               p = fnval;
  9155.           }
  9156.         unhexfin:
  9157.           goto fnend;
  9158.       }
  9159.  
  9160.       case FN_BRK: {                    /* \fbreak() */
  9161.           char * c;                     /* Characters to break on */
  9162.           char c2, s2;
  9163.           int start = 0;
  9164.           int done = 0;
  9165.           if (argn < 1)
  9166.             goto fnend;
  9167.           if (argn > 2) {
  9168.               s = bp[2] ? bp[2] : "0";
  9169.               if (chknum(s)) {
  9170.                   start = atoi(s);
  9171.                   if (start < 0) start = 0;
  9172.                   if (start > (int)strlen(bp[0]))
  9173.                     goto brkfin;
  9174.               } else {
  9175.                   failed = 1;
  9176.                   if (fndiags)
  9177.                     ckmakmsg(fnval,FNVALL,
  9178.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9179.                   goto fnend;
  9180.               }
  9181.           }
  9182.           s = bp[0] + start;            /* Source pointer */
  9183.  
  9184.           while (*s && !done) {
  9185.               s2 = *s;
  9186.               if (!inpcas[cmdlvl] && islower(s2)) s2 = toupper(s2);
  9187.               c = bp[1] ? bp[1] : "";   /* Character to break on */
  9188.               while (*c) {
  9189.                   c2 = *c;
  9190.                   if (!inpcas[cmdlvl] && islower(c2)) c2 = toupper(c2);
  9191.                   if (c2 == s2) {
  9192.                       done = 1;
  9193.                       break;
  9194.                   }
  9195.                   c++;
  9196.               }
  9197.               if (done) break;
  9198.               *p++ = *s++;
  9199.           }
  9200.           *p = NUL;                     /* terminate the result */
  9201.           p = fnval;                    /* and point to it. */
  9202.         brkfin:
  9203.           goto fnend;
  9204.       }
  9205.  
  9206.       case FN_SPN: {                    /* \fspan() */
  9207.           char *q;
  9208.           char c1, c2;
  9209.           int start = 0;
  9210.           if (argn < 1)
  9211.             goto fnend;
  9212.           if (argn > 2) {               /* Starting position */
  9213.               s = bp[2] ? bp[2] : "0";
  9214.               if (chknum(s)) {
  9215.                   start = atoi(s);
  9216.                   if (start < 0) start = 0;
  9217.               } else {
  9218.                   failed = 1;
  9219.                   if (fndiags)
  9220.                     ckmakmsg(fnval,FNVALL,
  9221.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9222.                   goto fnend;
  9223.               }
  9224.           }
  9225.           s = bp[0] + start;            /* Source pointer */
  9226.           if (argn > 1 &&
  9227.               (int)strlen(bp[1]) > 0 &&
  9228.               start <= (int)strlen(bp[0])) {
  9229.               while (*s) {              /* Loop thru source string */
  9230.                   q = bp[1];            /* Span string */
  9231.                   c1 = *s;
  9232.                   if (!inpcas[cmdlvl])
  9233.                     if (islower(c1)) c1 = toupper(c1);
  9234.                   x = 0;
  9235.                   while ((c2 = *q++)) {
  9236.                       if (!inpcas[cmdlvl])
  9237.                         if (islower(c2)) c2 = toupper(c2);
  9238.                       if (c1 == c2) { x = 1; break; }
  9239.                   }
  9240.                   if (!x) break;
  9241.                   *p++ = *s++;
  9242.               }
  9243.               *p = NUL;                 /* Terminate and return the result */
  9244.               p = fnval;
  9245.           }
  9246.           goto fnend;
  9247.       }
  9248.     } /* Break up big switch... */
  9249.  
  9250.     switch (y) {
  9251.       case FN_TRM:                      /* \ftrim(s1[,s2]) */
  9252.       case FN_LTR:                      /* \fltrim(s1[,s2]) */
  9253.         if (argn < 1)
  9254.           goto fnend;
  9255.         if ((len1 = (int)strlen(bp[0])) > 0) {
  9256.             if (len1 > FNVALL)
  9257.               len1 = FNVALL;
  9258.             s = " \t\r\n";
  9259.             if (argn > 1)               /* Trim list given */
  9260.               s = bp[1];
  9261.             len2 = (int)strlen(s);
  9262.             if (len2 < 1) {             /* or not... */
  9263.                 s = " \t\r\n";          /* Default is to trim whitespace */
  9264.                 len2 = 2;
  9265.             }
  9266.             if (cx == FN_TRM) {         /* Trim from right */
  9267.                 char * q, p2, q2;
  9268.                 ckstrncpy(fnval,bp[0],FNVALL); /* Copy string to output */
  9269.                 p = fnval + len1 - 1;   /* Point to last character */
  9270.  
  9271.                 while (p >= (char *)fnval) { /* Go backwards */
  9272.                     q = s;              /* Point to trim list */
  9273.                     p2 = *p;
  9274.                     if (!inpcas[cmdlvl])
  9275.                       if (islower(p2)) p2 = toupper(p2);
  9276.                     while (*q) {        /* Is this char in trim list? */
  9277.                         q2 = *q;
  9278.                         if (!inpcas[cmdlvl])
  9279.                           if (islower(q2)) q2 = toupper(q2);
  9280.                         if (p2 == q2) { /* Yes, null it out */
  9281.                             *p = NUL;
  9282.                             break;
  9283.                         }
  9284.                         q++;
  9285.                     }
  9286.                     if (!*q)            /* Trim list exhausted */
  9287.                       break;            /* So we're done. */
  9288.                     p--;                /* Else keep trimming */
  9289.                 }
  9290.             } else {                    /* Trim from left */
  9291.                 char * q, p2, q2;
  9292.                 p = bp[0];              /* Source */
  9293.                 while (*p) {
  9294.                     p2 = *p;
  9295.                     if (!inpcas[cmdlvl])
  9296.                       if (islower(p2)) p2 = toupper(p2);
  9297.                     q = s;
  9298.                     while (*q) {        /* Is this char in trim list? */
  9299.                         q2 = *q;
  9300.                         if (!inpcas[cmdlvl])
  9301.                           if (islower(q2)) q2 = toupper(q2);
  9302.                         if (p2 == q2) { /* Yes, point past it */
  9303.                             p++;        /* and try next source character */
  9304.                             break;
  9305.                         }
  9306.                         q++;            /* No, try next trim character */
  9307.                     }
  9308.                     if (!*q)            /* Trim list exhausted */
  9309.                       break;            /* So we're done. */
  9310.                 }
  9311.                 ckstrncpy(fnval,p,FNVALL);
  9312.             }
  9313.             p = fnval;
  9314.         } else p = "";
  9315.         goto fnend;
  9316.  
  9317.       case FN_CAP:                      /* \fcapitalize(arg1) */
  9318.         if (argn < 1)
  9319.           goto fnend;
  9320.         s = bp[0];
  9321.         p = fnval;
  9322.         x = 0;
  9323.         while ((c = *s++)) {
  9324.             if (isalpha(c)) {
  9325.                 if (x == 0) {
  9326.                     x = 1;
  9327.                     if (islower(c))
  9328.                       c = toupper(c);
  9329.                 } else if (isupper(c))
  9330.                   c = tolower(c);
  9331.             }
  9332.             *p++ = c;
  9333.         }
  9334.         *p = NUL;
  9335.         p = fnval;
  9336.         goto fnend;
  9337.  
  9338. #ifdef COMMENT
  9339.       case FN_TOD:                      /* Time of day to secs since midnite */
  9340.         sprintf(fnval,"%ld",tod2sec(bp[0])); /* SAFE */
  9341.         goto fnend;
  9342. #endif /* COMMENT */
  9343.  
  9344.       case FN_FFN:                      /* Full pathname of file */
  9345.         zfnqfp(bp[0],FNVALL,p);
  9346.         if (!p) p = "";
  9347.         goto fnend;
  9348.  
  9349.       case FN_CHK: {                    /* \fchecksum() */
  9350.           long chk = 0;
  9351.           p = (argn > 0) ? bp[0] : "";
  9352.           while (*p) chk += *p++;
  9353.           sprintf(fnval,"%lu",chk);     /* SAFE */
  9354.           p = fnval;
  9355.           goto fnend;
  9356.       }
  9357.  
  9358. #ifndef NOXFER
  9359.       case FN_CRC:                      /* \fcrc16() */
  9360.         if (argn > 0)
  9361.           sprintf(fnval,"%u",           /* SAFE */
  9362.                   chk3((CHAR *)bp[0],(int)strlen(bp[0])));
  9363.         else
  9364.           p = "0";
  9365.         goto fnend;
  9366. #endif /* NOXFER */
  9367.  
  9368.       case FN_BSN:                      /* \fbasename() */
  9369.         zstrip(bp[0],&p);
  9370.         goto fnend;
  9371.  
  9372. #ifndef NOLOCAL
  9373. #ifdef OS2
  9374.       case FN_SCRN_CX:                  /* \fscrncurx() */
  9375.         p = fnval;
  9376.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->x); /* SAFE */
  9377.         goto fnend;
  9378.  
  9379.       case FN_SCRN_CY:                  /* \fscrncury() */
  9380.         p = fnval;
  9381.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->y); /* SAFE */
  9382.         goto fnend;
  9383.  
  9384.       case FN_SCRN_STR: {               /* \fscrnstr() */
  9385.           videoline * line = NULL;
  9386.           viocell * cells = NULL;
  9387.           int row = 0, col = 0, len = 0;
  9388.           /* NOTE: On Unicode systems, the screen contents are stored in */
  9389.           /* in Unicode.  Therefore, we should really be performing a    */
  9390.           /* conversion to the local character set.                      */
  9391.  
  9392.           /* 6/18/2000 - added the translation to lcs */
  9393.  
  9394.           if (bp[0] == NULL || bp[0][0] == '\0') {
  9395.               row = 0;
  9396.           } else {
  9397.               if (chknum(bp[0])) {
  9398.                   row = atoi(bp[0]);
  9399.                   if (row < 0)
  9400.                     row = 0;
  9401.               } else {
  9402.                   failed = 1;
  9403.                   if (fndiags)
  9404.                     ckmakmsg(fnval,FNVALL,
  9405.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9406.                   goto fnend;
  9407.               }
  9408.           }
  9409.           line = VscrnGetLineFromTop( VTERM, (USHORT) row );
  9410.           if (line != NULL) {
  9411.               if (bp[1] == NULL || bp[1][0] == '\0')
  9412.                 col = 0;
  9413.               else {
  9414.                   if (chknum(bp[0])) {
  9415.                       col = atoi(bp[1]);
  9416.                       if (col < 0 || col >= line->width)
  9417.                         col = 0;
  9418.                   } else {
  9419.                       failed = 1;
  9420.                       if (fndiags)
  9421.                         ckmakmsg(fnval,FNVALL,
  9422.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9423.                       goto fnend;
  9424.                   }
  9425.               }
  9426.               if (bp[2] == NULL || bp[2][0] == '\0') {
  9427.                   len = line->width - (col+1);
  9428.               } else {
  9429.                   if (!chknum(bp[2])) {
  9430.                       failed = 1;
  9431.                       if (fndiags)
  9432.                         ckmakmsg(fnval,FNVALL,
  9433.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9434.                       goto fnend;
  9435.                   }
  9436.                   len = atoi(bp[2]);
  9437.                   if (len < 0 || len > line->width)
  9438.                     len = line->width;
  9439.               }
  9440.               cells = line->cells;
  9441.               for (i = 0; i < len; i++) {
  9442.                   int pos = i + col;
  9443.                   if (pos < line->width) {
  9444.                       if (isunicode())
  9445.                         fnval[i] = (CHAR) utolxlat(cells[pos].c);
  9446.                       else
  9447.                         fnval[i] = (CHAR) (cells[pos].c & 0xFF);
  9448.                       if (fnval[i] == 0)
  9449.                         fnval[i] = SP;
  9450.                   } else
  9451.                     fnval[i] = SP;
  9452.               }
  9453.               fnval[i] = '\0';
  9454.           } else {
  9455.               fnval[0] = '\0';
  9456.           }
  9457.           p = fnval;
  9458.           goto fnend;
  9459.       }
  9460. #endif /* OS2 */
  9461. #endif /* NOLOCAL */
  9462.  
  9463. #ifndef NOPUSH
  9464.       case FN_RAW:                      /* \frawcommand() */
  9465.       case FN_CMD: {                    /* \fcommand() */
  9466.           int x, c, n = FNVALL;
  9467.           x = 0;                        /* Completion flag */
  9468. /*
  9469.   ZIFILE can be safely used because we can't possibly be transferring a file
  9470.   while executing this function.
  9471. */
  9472.           if (!nopush && zxcmd(ZIFILE,bp[0]) > 0) { /* Open the command */
  9473.               while (n-- > -1) {        /* Read from it */
  9474.                   if ((c = zminchar()) < 0) {
  9475.                       x = 1;             /* EOF - set completion flag */
  9476.                       if (cx == FN_CMD) { /* If not "rawcommand" */
  9477.                           p--;           /* remove trailing newlines */
  9478.                           while (*p == CR || *p == LF)
  9479.                             p--;
  9480.                           p++;
  9481.                       }
  9482.                       *p = NUL;         /* Terminate the string */
  9483.                       break;
  9484.                   } else                /* Command still running */
  9485.                     *p++ = c;           /* Copy the bytes */
  9486.               }
  9487.               zclose(ZIFILE);           /* Close the command */
  9488.           }
  9489.           /* Return null string if command's output was too long. */
  9490.           p = fnval;
  9491.           if (!x) {
  9492.               failed = 1;
  9493.               if (fndiags)
  9494.                 ckmakmsg(fnval,FNVALL,
  9495.                          "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  9496.           }
  9497.           goto fnend;
  9498.       }
  9499. #endif /* NOPUSH */
  9500.     } /* Break up big switch... */
  9501.  
  9502.     switch (y) {
  9503.       case FN_STX:                      /* \fstripx(string,c) */
  9504.         if (!(s = bp[0]))               /* Make sure there is a string */
  9505.           goto fnend;
  9506.         c = '.';                        /* Character to strip from */
  9507.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9508.         n = ckstrncpy(fnval,bp[0],FNVALL);
  9509.         while (--n >= 0) {
  9510.             if (fnval[n] == c) {
  9511.                 fnval[n] = NUL;
  9512.                 break;
  9513.             }
  9514.         }
  9515.         p = fnval;
  9516.         goto fnend;
  9517.  
  9518.       case FN_STL:                      /* \flop(string,c) */
  9519.       case FN_LOPX: {            /* \flopx(string,c) */
  9520.       int n = 1;
  9521.       if (!(s = bp[0]))        /* Make sure there is a string */
  9522.         goto fnend;
  9523.       c = '.';            /* Character to strip to */
  9524.       if (argn > 1) if (*bp[1]) c = *bp[1];
  9525.       if (argn > 2) if (*bp[2]) {
  9526. #ifndef NOFLOAT
  9527.           n = 0;
  9528.           if (isfloat(bp[2],0)) {
  9529.           n = (int)floatval;
  9530.           if (n < 0) n = 0;
  9531.           } else
  9532. #endif    /* NOFLOAT */
  9533.         n = atoi(bp[2]);
  9534.       }
  9535.       x = 0;
  9536.       if (cx == FN_LOPX) {        /* Lopx (from right) */
  9537.           if (n == 0)
  9538.         goto fnend;
  9539.           s += strlen(s) - 1;    /* We already know it's > 0 */
  9540.           while (s-- >= bp[0]) {
  9541.           if (*s == c) {
  9542.               n--;
  9543.               if (n == 0) {
  9544.               s++;
  9545.               x = 1;
  9546.               break;
  9547.               }
  9548.           }
  9549.           }
  9550.           if (!x) s = "";
  9551.       } else {            /* Lop (from left) */
  9552.           if (n == 0) {
  9553.           p = bp[0];
  9554.           goto fnend;
  9555.           }
  9556.           while (*s++) {
  9557.           if (*(s-1) == c) {
  9558.               if (--n == 0) {
  9559.               x = 1;
  9560.               break;
  9561.               }
  9562.           }
  9563.           }
  9564.           if (!x) s = bp[0];
  9565.       }
  9566.       ckstrncpy(fnval,s,FNVALL);
  9567.       p = fnval;
  9568.       goto fnend;
  9569.       }
  9570.       case FN_STN:                      /* \fstripn(string,n) */
  9571.         if (argn < 1)                   /* Remove n chars from right */
  9572.           goto fnend;
  9573.         val1 = "0";
  9574.         if (argn > 1)
  9575.           if (*(bp[1]))
  9576.             val1 = evalx(bp[1]);
  9577.         if (!chknum(val1)) {
  9578.             failed = 1;
  9579.             evalerr(fn);
  9580.             goto fnend;
  9581.         }
  9582.         n = atoi(val1);
  9583.         if (n < 0) n = 0;
  9584.         k = (int)strlen(s = bp[0]) - n;
  9585.         if (k < 0) k = 0;
  9586.         p = fnval;
  9587.         while (k-- > 0)
  9588.           *p++ = *s++;
  9589.         *p = NUL;
  9590.         p = fnval;
  9591.         goto fnend;
  9592.  
  9593.       case FN_STB: {                    /* \fstripb(string,c) */
  9594.           char c2 = NUL;
  9595.           int i, k = 0;
  9596.           char * gr_opn = "\"{'([<";    /* Group open brackets */
  9597.           char * gr_cls = "\"}')]>";    /* Group close brackets */
  9598.  
  9599.           p = fnval;
  9600.           *p = NUL;
  9601.           if (!(s = bp[0]))             /* Make sure there is a string */
  9602.             goto fnend;
  9603.           if ((x = strlen(s)) < 1)
  9604.             goto fnend;
  9605.           c = NUL;                      /* Brace/bracket kind */
  9606.           if (argn > 1) {
  9607.               if (*bp[1]) {
  9608.                   if (chknum(bp[1])) {
  9609.                       k = atoi(bp[1]);
  9610.                       if (k < 0) k = 63;
  9611.                       for (i = 0; i < 6; i++) {
  9612.                           if (k & (1<<i)) {
  9613.                               if (s[0] == gr_opn[i] && s[x-1] == gr_cls[i]) {
  9614.                                   ckstrncpy(fnval,s+1,FNVALL);
  9615.                                   fnval[x-2] = NUL;
  9616.                                   goto fnend;
  9617.                               }
  9618.                           }
  9619.                       }
  9620.                       ckstrncpy(fnval,s,FNVALL); /* No match */
  9621.                       goto fnend;
  9622.                   }
  9623.               }
  9624.           }
  9625.       c = !bp[1] ? 0 : *bp[1];
  9626.           if (!c) c = s[0];
  9627.           if (argn > 2) if (*bp[2]) c2 = *bp[2];
  9628.           if (*s == c) {
  9629.               if (!c2) {
  9630.                   switch (c) {
  9631.                     case '(': c2 = ')'; break;
  9632.                     case '[': c2 = ']'; break;
  9633.                     case '{': c2 = '}'; break;
  9634.                     case '<': c2 = '>'; break;
  9635.                     case '"': c2 = '"'; break;
  9636.                     case 39:  c2 = 39;  break;
  9637.                     case 96:  c2 = 39;  break;
  9638.                     default:
  9639.                       if (argn == 2) {
  9640.                           c2 = c;
  9641.                       } else {
  9642.                           strncpy(fnval,s,x); /* Leave it like this */
  9643.                           fnval[x] = NUL;
  9644.                           goto fnend;
  9645.                       }
  9646.                   }
  9647.               }
  9648.               if (s[x-1] == c2) {
  9649.                   strncpy(fnval,s+1,x-2); /* Leave it like this */
  9650.                   fnval[x-2] = NUL;
  9651.                   goto fnend;
  9652.               }
  9653.           }
  9654.           strncpy(fnval,s,x);
  9655.           fnval[x] = NUL;
  9656.           goto fnend;
  9657.       }
  9658.  
  9659.       case FN_2HEX:                     /* Number to hex */
  9660.       case FN_2OCT:                     /* Number to octal */
  9661.         val1 = evalx(bp[0]);
  9662.         if (!*val1) {
  9663.             failed = 1;
  9664.             evalerr(fn);
  9665.             goto fnend;
  9666.         }
  9667.         sprintf(fnval, cx == FN_2HEX ? "%lx" : "%lo", atol(val1)); /* SAFE */
  9668.         if (cx == FN_2HEX && (int)(strlen(fnval)&1))
  9669.           sprintf(fnval,"0%lx",atol(val1)); /* SAFE */
  9670.         p = fnval;
  9671.         goto fnend;
  9672.  
  9673.       case FN_DNAM: {                   /* Directory part of file name */
  9674.           char *s;
  9675.           zfnqfp(bp[0],FNVALL,p);       /* Get full name */
  9676.           if (!isdir(p)) {              /* Is it already a directory? */
  9677.               zstrip(p,&s);             /* No get basename */
  9678.               if (*s) {
  9679.                   x = ckindex(s,p,0,0,0); /* Pos of latter in former */
  9680.                   if (x > 0) p[x-1] = NUL;
  9681.               }
  9682.           }
  9683.           if (!p) p = "";
  9684.           goto fnend;
  9685.       }
  9686.  
  9687. #ifndef NORANDOM
  9688.       case FN_RAND:                     /* Random number */
  9689. #ifdef CK_SSL
  9690.         if (RAND_bytes((unsigned char *)&k,sizeof(k)) < 0)
  9691. #endif /* CK_SSL */
  9692.           k = rand();
  9693.         x = 0;
  9694.         if (argn > 0) {
  9695.             if (!chknum(bp[0])) {
  9696.                 failed = 1;
  9697.                 if (fndiags)
  9698.                   ckmakmsg(fnval,FNVALL,
  9699.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9700.                 goto fnend;
  9701.             }
  9702.             x = atoi(bp[0]);
  9703.         }
  9704. #ifdef COMMENT
  9705.         sprintf(fnval,"%d", (x > 0 && k > 0) || (x < 0 && k < 0) ? k % x : 
  9706.                 (x == 0 ? 0 : (0 - (k % (-x)))));
  9707. #else
  9708.         debug(F111,"rand",ckitoa(x),k);
  9709. #ifdef SUNOS4
  9710. /* This is really strange but on SunOS, if we are requesting random numbers */
  9711. /* between 0 and 4 or less, they always come out in sequence: 0 1 2 3 0 1 2 */
  9712. /* Shifting the result of rand() in this case gives a more random result.   */
  9713.         if (x < 5)
  9714.           k = k >> 5;
  9715. #endif /* SUNOS4 */
  9716.         if ((x > 0 && k > 0) || (x < 0 && k < 0))
  9717.           x = k % x;
  9718.         else if (x == 0)
  9719.           x = 0;
  9720.         else
  9721.           x = 0 - (k % (-x));
  9722.         debug(F101,"rand x","",x);
  9723.         sprintf(fnval,"%d", x);         /* SAFE */
  9724. #endif /* COMMENT */
  9725.         p = fnval;
  9726.         goto fnend;
  9727. #endif /* NORANDOM */
  9728.     } /* Break up big switch... */
  9729.  
  9730.     switch (y) {
  9731.       case FN_SPLIT:                    /* \fsplit(s1,a,s2,s3,mask) */
  9732.       case FN_WORD: {                   /* \fword(s1,n,s2,s3,mask) */
  9733.           int wordnum = 0;
  9734.           int splitting = 0;
  9735.           int x;
  9736.           int array = 0;
  9737.           int grouping = 0;
  9738.           int nocollapse = 0;
  9739.           char * sep = "";
  9740.           char * notsep = "";
  9741.           char * bp0 = NULL;
  9742.           char * bp1 = NULL;
  9743.           char   abuf[16];
  9744.           struct stringarray * q = NULL;
  9745.  
  9746.           splitting = (cx == FN_SPLIT); /* Our job */
  9747.       debug(F101,"FN_SPLIT splitting","",splitting);
  9748.  
  9749.           fnval[0] = splitting ? '0' : NUL; /* Initial return value */
  9750.           fnval[1] = NUL;
  9751.           p = fnval;
  9752.           bp0 = bp[0];                  /* Source string */
  9753.           if (!bp0) bp0 = "";
  9754.           debug(F111,"fsplit bp[0]",bp0,argn);
  9755.           if (argn < 1 || !*bp0)        /* If none, return default value */
  9756.             goto fnend;
  9757.  
  9758.           bp1 = bp[1];                  /* Function-dependent arg */
  9759.           if (!bp1) bp1 = "";           /* (array or number) */
  9760.           debug(F110,"fsplit bp[1]",bp1,0);
  9761.           if (bp[5]) {
  9762.               if (!chknum(bp[5])) {
  9763.                   failed = 1;
  9764.                   ckmakmsg(fnval,FNVALL,
  9765.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9766.                   goto fnend;
  9767.               }
  9768.               x = atoi(bp[5]);
  9769.               nocollapse = x;
  9770.           }
  9771.           if (!splitting) {             /* \fword(): n = desired word number */
  9772.               val1 = "1";               /* Default is first word */
  9773.               if (argn > 1)             /* Word number supplied */
  9774.                 if (*bp1)
  9775.                   val1 = evalx(bp1);
  9776.               if (!chknum(val1)) {
  9777.                   failed = 1;
  9778.                   ckmakmsg(fnval,FNVALL,
  9779.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9780.                   goto fnend;
  9781.               }
  9782.               n = atoi(val1);
  9783.           } else if (argn > 1 && *bp1) { /* \fsplit(): n = word count */
  9784.               ckstrncpy(abuf,bp1,16);   /* Get array reference */
  9785.               debug(F110,"fsplit abuf 1",abuf,0);
  9786.               failed = 1;               /* Assume it's bad */
  9787.               if (fndiags)              /* Default is this error message */
  9788.                 ckmakmsg(fnval,FNVALL,
  9789.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9790.               if (abuf[0] != '&')       /* "Address" of array */
  9791.                 goto fnend;             /* It's bad */
  9792.               if (abuf[2]) {            /* Check for brackets */
  9793.                   if (abuf[2] != '[' || abuf[3] != ']') {
  9794.                       goto fnend;       /* Bad */
  9795.                   }
  9796.               }
  9797.               debug(F110,"fsplit abuf 2",abuf,0);
  9798.               if (abuf[1] > 64 && abuf[1] < 91) /* Convert upper to lower */
  9799.                 abuf[1] += 32;
  9800.               if (abuf[1] < 97 || abuf[1] > 122) { /* Check for a-z */
  9801.                   goto fnend;
  9802.               }
  9803.               debug(F110,"fsplit abuf 3",abuf,0);
  9804.               array = 1;
  9805.               fnval[0] = NUL;           /* No error, erase message */
  9806.               failed = 0;               /* Unset failure flag */
  9807.               n = 0;                    /* Initialize word counter */
  9808.           }
  9809.           if (argn > 2)                 /* Have break set? */
  9810.             sep = bp[2];
  9811.           debug(F111,"fsplit sep",sep,argn);
  9812.           if (argn > 3)                 /* Have include set? */
  9813.             notsep = bp[3];
  9814.           debug(F111,"fsplit notsep",notsep,argn);
  9815.           if (argn > 4) {               /* Have grouping set? */
  9816.               char * bp4 = bp[4];
  9817.               debug(F111,"fsplit bp4",bp4,argn);
  9818.               if (!bp4) bp4 = "0";
  9819.               if (!*bp4) bp4 = "0";
  9820.               if (chknum(bp4)) {
  9821.                   grouping = atoi(bp4);
  9822.                   if (grouping == -1)
  9823.                     grouping = 127;
  9824.               } else {
  9825.                   failed = 1;
  9826.                   if (fndiags)
  9827.                     ckmakmsg(fnval,FNVALL,
  9828.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9829.                   goto fnend;
  9830.               }
  9831.           }
  9832.           /* Args parsed, now do the work */
  9833.  
  9834.           debug(F111,"fsplit bp0",bp0,n);
  9835.           q = cksplit(splitting,n,bp0,sep,notsep,grouping,0,nocollapse);
  9836.  
  9837.           wordnum = q ? q->a_size : -1; /* Check result */
  9838.           if (wordnum < 0) {
  9839.               failed = 1;               /* Failure */
  9840.               if (fndiags)
  9841.                 ckmakmsg(fnval,FNVALL,
  9842.                          (wordnum == -1) ?
  9843.                          "<ERROR:MALLOC_FAILURE:\\f" :
  9844.                          "<ERROR:TOO_MANY_WORDS:\\f",
  9845.                          fn,
  9846.                          "()>",
  9847.                          NULL
  9848.                          );
  9849.               goto fnend;
  9850.           }
  9851.           if (splitting) {              /* \fsplit() result */
  9852.               ckstrncpy(fnval,ckitoa(wordnum),FNVALL);
  9853.               if (array) {              /* Array was not declared. */
  9854.                   int i;
  9855.                   if ((x = dclarray(abuf[1],wordnum)) < 0) { /* Declare it. */
  9856.                       failed = 1;
  9857.                       if (fndiags)
  9858.                         ckmakmsg(fnval,FNVALL,
  9859.                                  "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  9860.                       goto fnend;
  9861.                   }
  9862.                   for (i = 1; i <= wordnum; i++) { /* Copy results */
  9863.                       makestr(&(a_ptr[x][i]),q->a_head[i]);
  9864.                   }
  9865.                   a_ptr[x][0] = NULL;   /* Array is 1-based */
  9866.                   makestr(&(a_ptr[x][0]),fnval); /* Element = size */
  9867.               }
  9868.           } else {                      /* \fword() result */
  9869.               char * s;
  9870.               s = q->a_head[1];
  9871.               if (!s) s = "";
  9872.               ckstrncpy(fnval,s,FNVALL);
  9873.           }
  9874.           goto fnend;                   /* Done */
  9875.       }
  9876.  
  9877.     } /* Break up big switch... */
  9878.  
  9879.     switch (y) {
  9880.  
  9881. #ifdef CK_KERBEROS
  9882.       case FN_KRB_TK:                   /* Kerberos tickets */
  9883.       case FN_KRB_NX:                   /* Kerberos next ticket */
  9884.       case FN_KRB_IV:                   /* Kerberos ticket is valid */
  9885.       case FN_KRB_FG:                   /* Kerberos Ticket flags */
  9886.       case FN_KRB_TT: {                 /* Kerberos ticket time */
  9887.           int kv = 0;                   /* Kerberos version */
  9888.           int n = 0;
  9889.           char * s = NULL;
  9890.           if (rdigits(bp[0])) {
  9891.               kv = atoi(bp[0]);
  9892.           } else {
  9893.               failed = 1;
  9894.               if (fndiags)
  9895.                 ckmakmsg(fnval,FNVALL,
  9896.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9897.               goto fnend;
  9898.           }
  9899.           if (kv != 4 && kv != 5) {
  9900.               failed = 1;
  9901.               if (fndiags)
  9902.                 ckmakmsg(fnval,FNVALL,
  9903.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9904.               goto fnend;
  9905.           }
  9906.           if ((cx == FN_KRB_IV || cx == FN_KRB_TT || cx == FN_KRB_FG) &&
  9907.                argn < 2) {
  9908.               failed = 1;
  9909.               if (fndiags)
  9910.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9911.               goto fnend;
  9912.           }
  9913.           switch (y) {
  9914.             case FN_KRB_TK:             /* Number of Kerberos tickets */
  9915. #ifdef CK_AUTHENTICATION
  9916.               switch (kv) {
  9917.                 case 4:
  9918.                   n = ck_krb4_get_tkts();
  9919.                   sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9920.                   goto fnend;
  9921.                 case 5: {
  9922.                     extern char * krb5_d_cc;
  9923.                     n = ck_krb5_get_tkts(krb5_d_cc);
  9924.                     sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9925.                     goto fnend;
  9926.                 }
  9927.               }
  9928. #else
  9929.               sprintf(fnval,"%d",0);    /* SAFE */
  9930. #endif /* CK_AUTHENTICATION */
  9931.               goto fnend;
  9932.  
  9933.             case FN_KRB_NX:             /* Kerberos next ticket */
  9934. #ifdef CK_AUTHENTICATION
  9935.               switch (kv) {
  9936.                 case 4:
  9937.                   s = ck_krb4_get_next_tkt();
  9938.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9939.                   goto fnend;
  9940.                 case 5:
  9941.                   s = ck_krb5_get_next_tkt();
  9942.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9943.                   goto fnend;
  9944.               }
  9945. #else
  9946.               sprintf(fnval,"k%d next-ticket-string",kv); /* SAFE */
  9947. #endif /* CK_AUTHENTICATION */
  9948.               goto fnend;
  9949.  
  9950.             case FN_KRB_IV:             /* Kerberos ticket is valid */
  9951. #ifdef CK_AUTHENTICATION
  9952.               /* Return 1 if valid, 0 if not */
  9953.               switch (kv) {
  9954.                 case 4:
  9955.                   n = ck_krb4_tkt_isvalid(bp[1]);
  9956.                   sprintf(fnval, "%d", n > 0 ? 1 : 0); /* SAVE */
  9957.                   goto fnend;
  9958.                 case 5: {
  9959.                     extern char * krb5_d_cc;
  9960.                     n = ck_krb5_tkt_isvalid(krb5_d_cc,bp[1]);
  9961.                     sprintf(fnval,"%d", n > 0 ? 1 : 0); /* SAFE */
  9962.                     goto fnend;
  9963.                 }
  9964.               }
  9965. #else
  9966.               sprintf(fnval,"%d",0);    /* SAFE */
  9967. #endif /* CK_AUTHENTICATION */
  9968.               goto fnend;
  9969.  
  9970.             case FN_KRB_TT:             /* Kerberos ticket time */
  9971. #ifdef CK_AUTHENTICATION
  9972.               switch (kv) {
  9973.                 case 4:
  9974.                   n = ck_krb4_tkt_time(bp[1]);
  9975.                   sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9976.                   goto fnend;
  9977.                 case 5: {
  9978.                     extern char * krb5_d_cc;
  9979.                     n = ck_krb5_tkt_time(krb5_d_cc,bp[1]);
  9980.                     sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9981.                     goto fnend;
  9982.                 }
  9983.               }
  9984. #else
  9985.               ckstrncpy(fnval,"600",FNVALL); /* Some time */
  9986. #endif /* CK_AUTHENTICATION */
  9987.               goto fnend;
  9988.  
  9989.             case FN_KRB_FG:             /* Kerberos ticket flags */
  9990. #ifdef CK_AUTHENTICATION
  9991.               switch (kv) {
  9992.                 case 4:
  9993.                   fnval[0] = '\0';
  9994.                   goto fnend;
  9995.                 case 5: {
  9996.                     extern char * krb5_d_cc;
  9997.                     ckstrncpy(fnval,ck_krb5_tkt_flags(krb5_d_cc,bp[1]),FNVALL);
  9998.                     goto fnend;
  9999.                 }
  10000.               }
  10001. #else
  10002.               fnval[0] = '\0';
  10003. #endif /* CK_AUTHENTICATION */
  10004.               goto fnend;
  10005.           }
  10006.           p = fnval;
  10007.           goto fnend;
  10008.       }
  10009. #endif /* CK_KERBEROS */
  10010.  
  10011. #ifdef FN_ERRMSG
  10012.       case FN_ERRMSG:
  10013.         if (rdigits(bp[0])) {
  10014.             k = atoi(bp[0]);
  10015.         } else {
  10016.             failed = 1;
  10017.             if (fndiags)
  10018.              ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10019.             goto fnend;
  10020.         }
  10021. #ifdef VMS
  10022.         ckstrncpy(fnval,ckvmserrstr(k),FNVALL);
  10023. #else
  10024.         x = errno;
  10025.         errno = k;
  10026.         ckstrncpy(fnval,ck_errstr(),FNVALL);
  10027.         errno = x;
  10028. #endif /* VMS */
  10029.         p = fnval;
  10030.         goto fnend;
  10031. #endif /* FN_ERRMSG */
  10032.  
  10033.       case FN_DIM: {
  10034.           int max;
  10035.           char abuf[16], *s;
  10036.           fnval[0] = NUL;               /* Initial return value */
  10037.           ckstrncpy(abuf,bp[0],16);     /* Get array reference */
  10038.           s = abuf;
  10039.           if (*s == CMDQ) s++;
  10040.           failed = 1;                   /* Assume it's bad */
  10041.           p = fnval;                    /* Point to result */
  10042.           if (fndiags)                  /* Default is this error message */
  10043.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10044.           if (s[0] != '&') {            /* "Address" of array */
  10045.               goto fnend;
  10046.           }
  10047.           if (s[2]) {
  10048.               if (s[2] != '[' || s[3] != ']') {
  10049.                   goto fnend;
  10050.               }
  10051.           }
  10052.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  10053.             s[1] += 32;
  10054.           if (s[1] < 95 || s[1] > 122) { /* Check for a-z */
  10055.               goto fnend;          /* Bad */
  10056.           }
  10057.           if ((max = chkarray(s[1],1)) < 1) /* (second arg was 1) */
  10058.             max = 0;
  10059.           failed = 0;                   /* Unset failure flag */
  10060.           sprintf(fnval,"%d",max);      /* SAFE */
  10061.           goto fnend;
  10062.       }
  10063.  
  10064.     } /* Break up big switch... */
  10065.  
  10066.     switch (y) {
  10067.       case FN_JDATE:
  10068.         if (argn < 1)                   /* Check number of args */
  10069.           p = ckdate();                 /* None, get today's date-time */
  10070.         else                            /* Some */
  10071.           p = bp[0];                    /* Use first */
  10072.         p = ckcvtdate(p,0);             /* Convert to standard form */
  10073.         ckstrncpy(fnval,zjdate(p),FNVALL); /* Convert to Julian */
  10074.         p = fnval;                      /* Point to result */
  10075.         failed = 0;
  10076.         if (*p == '-') {
  10077.             failed = 1;
  10078.             if (fndiags)                /* Default is this error message */
  10079.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  10080.         }
  10081.         goto fnend;
  10082.  
  10083.       case FN_DATEJ:
  10084.         ckstrncpy(fnval,jzdate(bp[0]),FNVALL); /* Convert to yyyy<dayofyear> */
  10085.         p = fnval;                      /* Point to result */
  10086.         failed = 0;
  10087.         if (*p == '-') {
  10088.             failed = 1;
  10089.             if (fndiags)                /* Default is this error message */
  10090.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  10091.         }
  10092.         goto fnend;
  10093.  
  10094.       case FN_DTIM:                     /* \fcvtdate() */
  10095.       case FN_TIME:                     /* Free-format time to hh:mm:ss */
  10096.       case FN_NTIM:                     /* Time to sec since midnight */
  10097.         s = (argn > 0) ? bp[0] : "";
  10098.         if (!s) s = "";
  10099.         if (!*s)
  10100.           p = ckdate();                 /* None, get today's date */
  10101.         else                            /* Some */
  10102.           p = bp[0];                    /* Use first */
  10103.     {
  10104.         char * s;
  10105.         s = p;
  10106.         while (*s) {
  10107.         if (*s < 32) {
  10108.             *s = NUL;
  10109.             break;
  10110.         }
  10111.         s++;
  10112.         }
  10113.         /* do { if (*s < '!') *s = NUL; break; } while (*s++); */
  10114.     }
  10115.         p = ckcvtdate(p,2);             /* Convert to standard form */
  10116.         if (*p == '<') {
  10117.             failed = 1;
  10118.             if (fndiags)                /* Default is this error message */
  10119.               ckmakmsg(fnval,FNVALL,
  10120.                        "<ERROR:ARG_BAD_DATE_OR_TIME:\\f",fn,"()>",NULL);
  10121.             p = fnval;
  10122.             goto fnend;
  10123.         }
  10124.         if (argn > 1) {            /* Format code */
  10125.             s = bp[1];
  10126.             if (!s) s = "";
  10127.             if (!*s) s = "0";
  10128.             if (!chknum(s)) {
  10129.                 failed = 1;
  10130.                 if (fndiags)
  10131.                   ckmakmsg(fnval,FNVALL,
  10132.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10133.                 p = fnval;
  10134.                 goto fnend;
  10135.             }
  10136.             x = atoi(s);
  10137.             /* if (x) */ p = shuffledate(p,x);
  10138.         }
  10139.         if (cx == FN_TIME) {
  10140.             p += 9;
  10141.         } else if (cx == FN_NTIM) {
  10142.             long sec = 0L;
  10143.             p[11] = NUL;
  10144.             p[14] = NUL;
  10145.             sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  10146.             sprintf(fnval,"%ld",sec);   /* SAFE */
  10147.             p = fnval;
  10148.         }
  10149.         goto fnend;
  10150.  
  10151.       case FN_MJD:                      /* Modified Julian Date */
  10152.         if (argn < 1)                   /* Check number of args */
  10153.           p = zzndate();                /* None, get today's date-time */
  10154.         else                            /* Some */
  10155.           p = bp[0];                    /* Use first */
  10156.         p = ckcvtdate(p,0);             /* Convert to standard form */
  10157.         if (*p == '-') {
  10158.             failed = 1;
  10159.             if (fndiags)                /* Default is this error message */
  10160.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  10161.             goto fnend;
  10162.         }
  10163.         /* Convert to modified Julian date */
  10164.         sprintf(fnval,"%ld",mjd(p));    /* SAFE */
  10165.         p = fnval;                      /* Point to result */
  10166.         goto fnend;
  10167.  
  10168.       case FN_MJD2: {
  10169.           long k = 0L;
  10170.           int n = 0;
  10171.           p = evalx(bp[0]);
  10172.           if (*p == '-') {
  10173.               p++;
  10174.               n = 1;
  10175.           }
  10176.           if (!rdigits(p)) {
  10177.               failed = 1;
  10178.               evalerr(fn);
  10179.               p = fnval;
  10180.               goto fnend;
  10181.           } else {
  10182.               k = atol(p);
  10183.               if (n) k = -k;
  10184.           }
  10185.           ckstrncpy(fnval,mjd2date(k),FNVALL); /* Convert to Date */
  10186.           p = fnval;                    /* Point to result */
  10187.           failed = 0;
  10188.           goto fnend;
  10189.       }
  10190.  
  10191. #ifndef NODIAL
  10192.       case FN_PNCVT: {                  /* Convert phone number */
  10193.           extern char * pncvt();
  10194.           failed = 0;
  10195.           p = pncvt(bp[0]);
  10196.           if (!p) p = "";
  10197.           if (!*p) {
  10198.             failed = 1;
  10199.             if (fndiags)                /* Default is this error message */
  10200.               ckmakmsg(fnval,FNVALL,
  10201.                        "<ERROR:ARG_BAD_PHONENUM:\\f",fn,"()>",NULL);
  10202.         }
  10203.         goto fnend;
  10204.       }
  10205. #endif /* NODIAL */
  10206.  
  10207.       case FN_DAY:
  10208.       case FN_NDAY:
  10209.         if (argn < 1)                   /* Check number of args */
  10210.           p = zzndate();                /* None, get today's date-time */
  10211.         else                            /* Some */
  10212.           p = bp[0];                    /* Use first */
  10213.         p = ckcvtdate(p,0);             /* Convert to standard form */
  10214.         if (*p == '-') {
  10215.             failed = 1;
  10216.             if (fndiags)                /* Default is this error message */
  10217.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  10218.             goto fnend;
  10219.         }
  10220.         failed = 0;
  10221.         z = mjd(p);                     /* Convert to modified Julian date */
  10222.         z = z % 7L;
  10223.         if (z < 0) {
  10224.             z = 0 - z;
  10225.             k = 6 - ((int)z + 3) % 7;
  10226.         } else {
  10227.             k = ((int)z + 3) % 7;    /* Day of week */
  10228.         }
  10229.         p = fnval;                      /* Point to result */
  10230.         if (cx == FN_NDAY)
  10231.           sprintf(fnval,"%d",k);        /* SAFE */
  10232.         else
  10233.           ckstrncpy(fnval,wkdays[k],FNVALL);
  10234.         goto fnend;
  10235.  
  10236.       case FN_N2TIM: {                  /* Sec since midnight to hh:mm:ss */
  10237.           long k = 0L;
  10238.           int n = 0, hh, mm, ss;
  10239.           char * s = bp[0];
  10240.           if (argn < 1)                 /* If no arg substitute 0 */
  10241.             s = "0";
  10242.           p = evalx(s);                 /* Evaluate expression silently */
  10243.           if (*p == '-') {              /* Check result for minus sign */
  10244.               p++;
  10245.               n = 1;
  10246.           }
  10247.           if (!rdigits(p)) { /* Check for numeric */
  10248.               failed = 1;
  10249.               ckmakmsg(fnval,FNVALL,
  10250.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10251.               p = fnval;
  10252.               goto fnend;
  10253.           } else {
  10254.               k = atol(p);
  10255.               if (n) k = -k;
  10256.           }
  10257.           if (k < 0) {                  /* Check for negative */
  10258.               failed = 1;
  10259.               if (fndiags)
  10260.                 ckmakmsg(fnval,FNVALL,
  10261.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10262.               p = fnval;
  10263.               goto fnend;
  10264.           }
  10265.           hh = k / 3600L;               /* Have positive number */
  10266.           mm = (k % 3600L) / 60L;       /* break it down... */
  10267.           ss = ((k % 3600L) % 60L);
  10268.  
  10269.           sprintf(fnval,"%02d:%02d:%02d",hh,mm,ss); /* SAFE */
  10270.           p = fnval;
  10271.           failed = 0;
  10272.           goto fnend;
  10273.       }
  10274.  
  10275.       case FN_PERM: {                   /* File permissions */
  10276.           p = fnval;
  10277.           z = zchki(bp[0]);
  10278.           if (z < 0) {
  10279.               failed = 1;
  10280.               if (fndiags) {
  10281.                   if (z == -1)
  10282.                     ckmakmsg(fnval,FNVALL,
  10283.                              "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  10284.                   else if (z == -2)
  10285.                     ckmakmsg(fnval,FNVALL,
  10286.                              "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  10287.                   else if (z == -3)
  10288.                     ckmakmsg(fnval,FNVALL,
  10289.                              "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  10290.                   else
  10291.                     ckmakmsg(fnval,FNVALL,
  10292.                              "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  10293.               }
  10294.               goto fnend;
  10295.           }
  10296. #ifdef CK_PERMS
  10297.           ckstrncpy(fnval,ziperm(bp[0]),FNVALL);
  10298. #else
  10299.           ckstrncpy(fnval,"(unknown)",FNVALL);
  10300. #endif /* CK_PERMS */
  10301.           goto fnend;
  10302.       }
  10303.       case FN_TLOOK:                    /* tablelook() */
  10304.       case FN_ALOOK: {                  /* arraylook() */
  10305.           int i, x, hi, lo, max, cmdlen;
  10306.           char abuf[16], *s, *pat;
  10307.           char kwbuf[256];
  10308.           char delim = ':';
  10309.           failed = 1;                   /* Assume failure */
  10310.           ckstrncpy(fnval,"-1",FNVALL);
  10311.           pat = bp[0];                  /* Point to search pattern */
  10312.           if (!pat) pat = "";           /* Watch out for NULL pointer */
  10313.           cmdlen = strlen(pat);         /* Get pattern length */
  10314.           if (argn < 2 /* || cmdlen < 1 */ ) { /* Need two args */
  10315.               if (fndiags)
  10316.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10317.               goto fnend;
  10318.           }
  10319.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  10320.           if (argn > 2)
  10321.             delim = *(bp[2]);
  10322.           s = abuf;
  10323.           if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Get index and bounds */
  10324.               if (fndiags)
  10325.                ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10326.               goto fnend;
  10327.           }
  10328.           p = fnval;                    /* Point to result */
  10329.           max = a_dim[x];               /* Size of array */
  10330.           if (lo < 0) lo = 0;           /* Use given range if any */
  10331.           if (lo > max) lo = max;
  10332.           if (hi < 0) hi = max;
  10333.           if (hi > max) hi = max;
  10334.           failed = 0;                   /* Unset failure flag */
  10335.           if (max < 1)
  10336.             goto fnend;
  10337.           kwbuf[255] = NUL;
  10338.           for (i = lo; i <= hi; i++) {
  10339.               if (!a_ptr[x][i])
  10340.                 continue;
  10341.               if (cx == FN_ALOOK) {
  10342.                   if (ckmatch(pat,a_ptr[x][i],inpcas[cmdlvl],1+4)) {
  10343.                       sprintf(fnval,"%d",i); /* SAFE */
  10344.                       goto fnend;
  10345.                   }
  10346.               } else if (cx == FN_TLOOK) {
  10347.                   char * aa;
  10348.                   int j = 0, v = 0, len;
  10349.                   if (i == hi)
  10350.                     break;
  10351.                   aa = a_ptr[x][i];     /* Point to this array element */
  10352.                   if (!aa) aa = "";
  10353.                   while (j < 254 && *aa) { /* Isolate keyword */
  10354.                       if (*aa == delim)
  10355.                         break;
  10356.                       kwbuf[j++] = *aa++;
  10357.                   }
  10358.                   kwbuf[j] = NUL;
  10359.                   len = j;
  10360.                   v = 0;
  10361.                   if ((len == cmdlen && !ckstrcmp(kwbuf,pat,len,0)) ||
  10362.                       ((v = !ckstrcmp(kwbuf,pat,cmdlen,0)) &&
  10363.                        ckstrcmp(a_ptr[x][i+1],pat,cmdlen,0))) {
  10364.                       sprintf(fnval,"%d",i); /* SAFE */
  10365.                       goto fnend;
  10366.                   }
  10367.                   if (v) {              /* Ambiguous */
  10368.                       ckstrncpy(fnval,"-2",FNVALL);
  10369.                       goto fnend;
  10370.                   }
  10371.               }
  10372.           }
  10373.           if (cx == FN_TLOOK) {         /* tablelook() last element */
  10374.               ckstrncpy(fnval,"-1",FNVALL);
  10375.               if (!ckstrcmp(a_ptr[x][hi],pat,cmdlen,0))
  10376.                 sprintf(fnval,"%d",hi); /* SAFE */
  10377.           }
  10378.           goto fnend;
  10379.       }
  10380.       case FN_TOB64:                    /* Base-64 conversion */
  10381.       case FN_FMB64:
  10382.         p = fnval;
  10383.         *p = NUL;
  10384.         if (argn < 1)
  10385.           goto fnend;
  10386.         if (cx == FN_TOB64) {
  10387.             x = b8tob64(bp[0],-1,fnval,FNVALL);
  10388.         } else {
  10389.             x = strlen(bp[0]);
  10390.             if (x % 4) {                /* length must be multiple of 4 */
  10391.                 failed = 1;
  10392.                 ckmakmsg(fnval,FNVALL,
  10393.                          "<ERROR:ARG_INCOMPLETE:\\f",fn,"()>",NULL);
  10394.                 goto fnend;
  10395.             }
  10396.             b64tob8(NULL,0,NULL,0);     /* Reset */
  10397.             x = b64tob8(bp[0],-1,fnval,FNVALL);
  10398.             b64tob8(NULL,0,NULL,0);     /* Reset again */
  10399.         }
  10400.         if (x < 0) {
  10401.             failed = 1;
  10402.             if (fndiags) {
  10403.                 char * m = "INTERNAL_ERROR";
  10404.                 switch (x) {
  10405.                   case -1: m = "ARG_TOO_LONG"; break;
  10406.                   case -2: m = "ARG_OUT_OF_RANGE"; break;
  10407.                 }
  10408.                 if (ckmakmsg(fnval,FNVALL,"<ERROR:",m,"\\f",fn) > 0)
  10409.                   ckstrncat(fnval,"()>",FNVALL);
  10410.             }
  10411.         }
  10412.         goto fnend;
  10413.  
  10414.       case FN_ABS: {
  10415.           char * s;
  10416.           s = bp[0];
  10417.           if (*s == '-' || *s == '+')
  10418.             s++;
  10419.           if (!rdigits(s)) {
  10420.               if (fndiags)
  10421.                 ckmakmsg(fnval,FNVALL,
  10422.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10423.               goto fnend;
  10424.           }
  10425.           ckstrncpy(fnval,s,FNVALL);
  10426.           goto fnend;
  10427.       }
  10428.  
  10429.       case FN_AADUMP: {
  10430.           char abuf[16], *s = NULL, **ap = NULL, **vp = NULL;
  10431.           char pattern[VNAML];
  10432.           int slen, i, j, k, first = -1;
  10433.           extern int xdelmac();
  10434.           p = fnval;
  10435.           if (argn < 2) {
  10436.               if (fndiags)
  10437.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG2:\\f",fn,"()>",NULL);
  10438.               goto fnend;
  10439.           }
  10440.           debug(F101,"aaconvert argn","",argn);
  10441.           s = bp[0];
  10442.           slen = strlen(s);
  10443.  
  10444.           /* Count elements so we can create the array */
  10445.  
  10446.           ckmakmsg(pattern,VNAML,s,"<*>",NULL,NULL);
  10447.           for (k = 0, i = 0; i < nmac; i++) {
  10448.               if (ckmatch(pattern,mactab[i].kwd,0,1)) {
  10449.                   if (first < 0)        /* Remember location of first match */
  10450.                     first = i;
  10451.                   k++;
  10452.               }
  10453.           }
  10454.           debug(F101,"aaconvert matches","",k);
  10455.           debug(F101,"aaconvert first","",first);
  10456.           fnval[0] = NUL;               /* Initial return value */
  10457.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  10458.           s = abuf;
  10459.           if (*s == CMDQ) s++;
  10460.           p = fnval;                    /* Point to result */
  10461.           if (fndiags)                  /* Default is this error message */
  10462.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10463.           if (s[0] != '&')              /* Address of array */
  10464.             goto fnend;
  10465.           if (s[2])
  10466.             if (s[2] != '[' || s[3] != ']')
  10467.               goto fnend;
  10468.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  10469.             s[1] += 32;
  10470.           if ((x = dclarray(s[1],k)) < 0) /* Declare array to size */
  10471.             goto fnend;
  10472.           ap = a_ptr[x];                /* Point to array we just declared */
  10473.           /* debug(F111,"aaconvert array 1",abuf,ap); */
  10474.           abuf[0] = NUL;
  10475.           if (argn > 2) {
  10476.               ckstrncpy(abuf,bp[2],16); /* Get value array reference */
  10477.               s = abuf;
  10478.               if (*s == CMDQ) s++;
  10479.               if (s[0] != '&')          /* Address of array */
  10480.                 goto fnend;
  10481.               if (s[2])
  10482.                 if (s[2] != '[' || s[3] != ']')
  10483.                   goto fnend;
  10484.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  10485.                 s[1] += 32;
  10486.               if ((x = dclarray(s[1],k)) < 0)
  10487.                 goto fnend;
  10488.               vp = a_ptr[x];            /* Point to array we just declared */
  10489.           }
  10490.           /* debug(F111,"aaconvert array 2",abuf,vp); */
  10491.           makestr(&ap[0],ckitoa(k));
  10492.           if (vp) makestr(&vp[0],ckitoa(k));
  10493.           if (fndiags)
  10494.            ckmakmsg(fnval,FNVALL,"<ERROR:ASSOCIATIVE_ARRAY:\\f",fn,"()>",NULL);
  10495.  
  10496.           /* Copy macro index & value to the arrays and then remove the */
  10497.           /* macro, so the 'first' pointer keeps indicating the next one. */
  10498.           /* We could combine the initial counting loop with this one but */
  10499.           /* then it would be harder to create the array and anyway this */
  10500.           /* function is plenty fast as it is. */
  10501.  
  10502.           for (i = 1; i <= k; ) {
  10503.               if (!ckmatch(pattern,mactab[first].kwd,0,1)) {
  10504.                   debug(F111,"aaconvert oddball",mactab[first].kwd,first);
  10505.                   first++;
  10506.                   continue;
  10507.               }
  10508.               ckstrncpy(tmpbuf,mactab[first].kwd,TMPBUFSIZ); /* Macro name */
  10509.               s = tmpbuf;                       /* Make writeable copy */
  10510.               s += slen;                        /* Isolate "index" */
  10511.               j = strlen(s) - 1;
  10512.               if (*s != '<' || *(s+j) != '>') { /* Check syntax */
  10513.                   /* This shouldn't happen */
  10514.                   debug(F111,"aaconvert ERROR",mactab[first].kwd,first);
  10515.                   goto fnend;
  10516.               }
  10517.               *(s+j) = NUL;             /* Remove final '>' */
  10518.               debug(F111,"aaconvert",s+1,i);
  10519.               makestr(&(ap[i]),s+1);    /* Set first array to index */
  10520.               if (vp)
  10521.                 makestr(&(vp[i]),mactab[first].mval); /* 2nd to value */
  10522.               if (xdelmac(first) < 0)
  10523.                 goto fnend;
  10524.               i++;
  10525.           }
  10526.           sprintf(fnval,"%d",k);        /* SAFE */
  10527.           p = fnval;                    /* Return size of array */
  10528.           debug(F110,"aaconvert return",p,0);
  10529.           failed = 0;                   /* Unset failure flag */
  10530.           goto fnend;
  10531.       }
  10532.  
  10533.     } /* End of switch() */
  10534.  
  10535. #ifdef FNFLOAT
  10536. /*
  10537.   Floating-point functions.  To be included only if FNFLOAT is defined, which
  10538.   should happen only if CKFLOAT is also defined, and if the math library is
  10539.   linked in.  Even then, we might have float-vs-double confusion as well as
  10540.   confusion about what the final "%f" format effector is supposed to reference
  10541.   (32 bits, 64 bits, etc).  Expect trouble if CKFLOAT does not match the data
  10542.   type of math library functions or args.
  10543. */
  10544.     if (cx == FN_FPABS ||               /* Floating-point functions */
  10545.         cx == FN_FPADD ||
  10546.         cx == FN_FPDIV ||
  10547.         cx == FN_FPEXP ||
  10548.         cx == FN_FPLOG ||
  10549.         cx == FN_FPLN  ||
  10550.         cx == FN_FPMOD ||
  10551.         cx == FN_FPMAX ||
  10552.         cx == FN_FPMIN ||
  10553.         cx == FN_FPMUL ||
  10554.         cx == FN_FPPOW ||
  10555.         cx == FN_FPSQR ||
  10556.         cx == FN_FPINT ||
  10557.         cx == FN_FPSUB ||
  10558.         cx == FN_FPROU ||
  10559.         cx == FN_FPSIN ||
  10560.         cx == FN_FPCOS ||
  10561.         cx == FN_FPTAN) {
  10562.         CKFLOAT farg[2], fpresult = 0.0;
  10563.         char fpbuf[64], * bp0;
  10564.         double dummy;
  10565.         /* int sign = 0; */
  10566.         int i, j, places = 0;
  10567.         int argcount = 1;
  10568.  
  10569.         failed = 1;
  10570.         p = fnval;
  10571.         bp0 = bp[0];
  10572.         if (!bp0)
  10573.           bp0 = "0";
  10574.         else if (!*bp0)
  10575.           bp0 = "0";
  10576.         if (!isfloat(bp0,0)) {
  10577.             k = mxlook(mactab,bp0,nmac);
  10578.             bp0 = (k > -1) ? mactab[k].mval : NULL;
  10579.             if (bp0) {
  10580.                 if (!isfloat(bp0,0)) {
  10581.                     if (fndiags)
  10582.                       ckmakmsg(fnval,FNVALL,
  10583.                                "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10584.                     goto fnend;
  10585.                 }
  10586.             }
  10587.         }
  10588.         if (cx == FN_FPINT) {           /* Float to int */
  10589.             failed = 0;
  10590.             ckstrncpy(fnval,bp0,FNVALL);
  10591.             for (i = 0; fnval[i]; i++) {
  10592.                 if (fnval[i] == '.') {
  10593.                     fnval[i] = NUL;
  10594.                     break;
  10595.                 }
  10596.             }
  10597.             goto fnend;
  10598.         }
  10599.         switch (y) {                    /* These need 2 args */
  10600.           case FN_FPADD:
  10601.           case FN_FPDIV:
  10602.           case FN_FPMOD:
  10603.           case FN_FPMAX:
  10604.           case FN_FPMIN:
  10605.           case FN_FPMUL:
  10606.           case FN_FPPOW:
  10607.           case FN_FPSUB:
  10608.             argcount = 2;
  10609.         }
  10610.         /* Missing arguments are supplied as 0.0 */
  10611.  
  10612.         debug(F111,fn,"argcount",argcount);
  10613.         for (i = 0; i < argcount; i++) { /* Get floating-point args */
  10614. #ifdef DEBUG
  10615.             if (deblog) {
  10616.                 ckmakmsg(fpbuf,
  10617.                          64,
  10618.                          "bp[",
  10619.                          ckitoa(i),
  10620.                          bp[i] ? bp[i] : "(null)",
  10621.                          "]"
  10622.                          );
  10623.                 debug(F100,fpbuf,"",0);
  10624.             }
  10625. #endif /* DEBUG */
  10626.             if (!bp[i]) {
  10627.                 farg[i] = 0.0;
  10628.             } else if (!*(bp[i])) {
  10629.                 farg[i] = 0.0;
  10630.             } else if (!isfloat(bp[i],0)) {
  10631.                 char * tmp;
  10632.                 k = mxlook(mactab,bp[i],nmac);
  10633.                 tmp = (k > -1) ? mactab[k].mval : NULL;
  10634.                 if (tmp) {
  10635.                     if (!isfloat(tmp,0)) {
  10636.                         if (fndiags)
  10637.                           ckmakmsg(fnval,FNVALL,
  10638.                                    "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10639.                         goto fnend;
  10640.                     }
  10641.                 }
  10642.             }
  10643.             farg[i] = floatval;
  10644.  
  10645. #ifdef DEBUG
  10646.             if (deblog) {
  10647.                 sprintf(fpbuf,"farg[%d]=%f",i,farg[i]); /* SAFE */
  10648.                 debug(F100,fpbuf,"",0);
  10649.             }
  10650. #endif /* DEBUG */
  10651.         }
  10652.         if (bp[argcount]) {             /* Get decimal places */
  10653.             char * s;
  10654.             s = bp[argcount];
  10655.             if (!s) s = "";
  10656.             if (!*s) s = "0";
  10657.             s = evalx(s);
  10658.             if (!s) s = "";
  10659.             if (!*s) {
  10660.                 evalerr(fn);
  10661.                 goto fnend;
  10662.             }
  10663.             places = atoi(s);
  10664.         }
  10665.         errno = 0;
  10666.         failed = 0;
  10667.         switch (y) {                    /* Now do the requested function */
  10668.           case FN_FPABS:                /* Floating-point absolute value */
  10669. #ifndef COMMENT
  10670.             fpresult = fabs(farg[0]);
  10671. #else
  10672.             if (farg[0] < 0.0)
  10673.               fpresult = 0.0 - farg[0];
  10674. #endif /* COMMENT */
  10675.             break;
  10676.           case FN_FPADD:                /* FP add */
  10677.             fpresult = farg[0] + farg[1];
  10678.             break;
  10679.           case FN_FPDIV:                /* FP divide */
  10680.           case FN_FPMOD:                /* FP modulus */
  10681.             if (!farg[1]) {
  10682.                 failed = 1;
  10683.                 if (fndiags)
  10684.                   ckmakmsg(fnval,FNVALL,
  10685.                            "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  10686.             } else
  10687.               fpresult = (cx == FN_FPDIV) ?
  10688.                 (farg[0] / farg[1]) :
  10689.                   fmod(farg[0],farg[1]);
  10690.             break;
  10691.           case FN_FPEXP:                /* FP e to the x */
  10692.             fpresult = (CKFLOAT) exp(farg[0]);
  10693.             break;
  10694.           case FN_FPLOG:                /* FP base-10 logarithm */
  10695.           case FN_FPLN:                 /* FP natural logarithm */
  10696.             if (farg[0] < 0.0) {
  10697.                 failed = 1;
  10698.                 if (fndiags)
  10699.                   ckmakmsg(fnval,FNVALL,
  10700.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10701.             } else
  10702.               fpresult = (cx == FN_FPLOG) ? log10(farg[0]) : log(farg[0]);
  10703.             break;
  10704.           case FN_FPMUL:                /* FP multiply */
  10705.             fpresult = farg[0] * farg[1];
  10706.             break;
  10707.           case FN_FPPOW:                /* FP raise to a power */
  10708.             fpresult = modf(farg[1],&dummy);
  10709.             if ((!farg[0] && farg[1] <= 0.0) ||
  10710.                 (farg[0] < 0.0 && fpresult)) {
  10711.                 failed = 1;
  10712.                 if (fndiags)
  10713.                   ckmakmsg(fnval,FNVALL,
  10714.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10715.             } else
  10716.               fpresult = pow(farg[0],farg[1]);
  10717.             break;
  10718.           case FN_FPSQR:                /* FP square root */
  10719.             if (farg[0] < 0.0) {
  10720.                 failed = 1;
  10721.                 if (fndiags)
  10722.                   ckmakmsg(fnval,FNVALL,
  10723.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10724.             } else
  10725.               fpresult = sqrt(farg[0]);
  10726.             break;
  10727.           case FN_FPSUB:                /* FP subtract */
  10728.             fpresult = farg[0] - farg[1];
  10729.             break;
  10730.           case FN_FPROU:                /* FP round */
  10731.             fpresult = farg[0];
  10732.             break;
  10733.           case FN_FPSIN:                /* FP sine */
  10734.             fpresult = (CKFLOAT) sin(farg[0]);
  10735.             break;
  10736.           case FN_FPCOS:                /* FP cosine */
  10737.             fpresult = (CKFLOAT) cos(farg[0]);
  10738.             break;
  10739.           case FN_FPTAN:                /* FP tangent */
  10740.             fpresult = (CKFLOAT) tan(farg[0]);
  10741.             break;
  10742.           case FN_FPMAX:
  10743.             fpresult = (farg[0] > farg[1]) ? farg[0] : farg[1];
  10744.             break;
  10745.           case FN_FPMIN:
  10746.             fpresult = (farg[0] < farg[1]) ? farg[0] : farg[1];
  10747.             break;
  10748.         }
  10749.  
  10750.         /* Get here with fpresult = function result */
  10751.  
  10752.         if (errno) {                    /* If range or domain error */
  10753.             failed = 1;
  10754.             if (fndiags)
  10755.               ckmakmsg(fnval,FNVALL,
  10756.                        "<ERROR:FLOATING-POINT-OP:\\f",fn,"()>",NULL);
  10757.         }
  10758.         if (failed)                     /* and/or any other kind of error, */
  10759.           goto fnend;                   /* fail. */
  10760. #ifndef COMMENT
  10761.         /* Call routine containing code that was formerly inline */
  10762.         ckstrncpy(fnval,fpformat(fpresult,places,cx == FN_FPROU),FNVALL);
  10763. #else
  10764.         {
  10765.             char fbuf[16];              /* For creating printf format */
  10766.             if (!fp_rounding &&         /* If printf doesn't round, */
  10767.                 (places > 0 ||          /* round result to decimal places. */
  10768.                  (places == 0 && cx == FN_FPROU)))
  10769.               fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  10770.             if (places > 0) {                   /* If places specified */
  10771.                 /* use specified places to write given number of digits */
  10772.                 sprintf(fbuf,"%%0.%df",places); /* SAFE */
  10773.                 sprintf(fnval,fbuf,fpresult);   /* SAFE */
  10774.             } else {                            /* Otherwise... */
  10775. #ifdef COMMENT
  10776. /*
  10777.   Here we want to print exactly fp_digits significant digits, no matter which
  10778.   side of the decimal point they are on.  That is, we want want the default
  10779.   format to show the maximum number of non-garbage digits, AND we want the last
  10780.   such digit to be rounded.  Of course there is no way to do that, since the
  10781.   digit after the last non-garbage digit is, well, garbage.  So the following
  10782.   clever ruse does no good.
  10783. */
  10784.                 int sign = 0, m = 0;
  10785.                 sprintf(fnval,"%f",fpresult);
  10786.                 if (fnval[0] == '-') sign = 1;
  10787.                 for (i = sign; i < FNVALL; i++) {
  10788.                     if (isdigit(fnval[i]))
  10789.                       m++;
  10790.                     else
  10791.                       break;
  10792.                 }
  10793.                 if (m > 1) {
  10794.                     int d = fp_digits - m;
  10795.                     if (d < 1) d = 1;
  10796.                     sprintf(fbuf,"%%%d.%df",fp_digits+sign+1,d);
  10797.                 } else {
  10798.                     sprintf(fbuf,"%%0.%df",fp_digits);
  10799.                 }
  10800.                 sprintf(fnval,fbuf,fpresult);
  10801. #else
  10802.                 /* Go for max precision */
  10803.                 sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  10804.                 sprintf(fnval,fbuf,fpresult); /* SAFE */
  10805.  
  10806. #endif /* COMMENT */
  10807.             }
  10808.             if (fnval[0] == '-') sign = 1;
  10809.         }
  10810.         debug(F111,"fpresult 1",fnval,errno); /* Check for over/underflow */
  10811.         for (i = sign; fnval[i]; i++) { /* Give requested decimal places */
  10812.             if (fnval[i] == '.')        /* First find the decimal point */
  10813.               break;
  10814.             else if (i > fp_digits + sign - 1) /* replacing garbage */
  10815.               fnval[i] = '0';           /* digits with 0... */
  10816.         }
  10817.         if (fnval[i] == '.') {          /* Have decimal point */
  10818.             int gotend = 0;
  10819.             /* d < 0 so truncate fraction */
  10820.             if (places < 0 || (places == 0 && cx == FN_FPROU)) {
  10821.                 fnval[i] = NUL;
  10822.             } else if (places > 0) {    /* d > 0 so this many decimal places */
  10823.                 i++;                           /* First digit after decimal */
  10824.                 for (j = 0; j < places; j++) { /* Truncate after d decimal */
  10825.                     if (!fnval[j+i])           /* places or extend to d  */
  10826.                       gotend = 1;              /* decimal places. */
  10827.                     if (gotend || j+i+sign > fp_digits)
  10828.                       fnval[j+i] = '0';
  10829.                 }
  10830.                 fnval[j+i] = NUL;
  10831.             } else {                    /* d == 0 so Do The Right Thing */
  10832.                 for (j = (int)strlen(fnval) - 1; j > i+1; j--) {
  10833.                     if ((j - sign) > fp_digits)
  10834.                       fnval[j] = '0';
  10835.                     if (fnval[j] == '0')
  10836.                       fnval[j] = NUL;   /* Strip useless trailing 0's. */
  10837.                     else
  10838.                       break;
  10839.                 }
  10840.             }
  10841.         }
  10842. #endif /* COMMENT */
  10843.         debug(F111,"fpresult 2",fnval,errno);
  10844.         goto fnend;
  10845.  
  10846.     }
  10847. #endif /* FNFLOAT */
  10848.  
  10849. #ifdef CKCHANNELIO
  10850.     if (cx == FN_FSTAT  ||              /* File functions */
  10851.         cx == FN_FPOS   ||
  10852.         cx == FN_FEOF   ||
  10853.         cx == FN_FGCHAR ||
  10854.         cx == FN_FGLINE ||
  10855.         cx == FN_FGBLK  ||
  10856.         cx == FN_FPCHAR ||
  10857.         cx == FN_FPLINE ||
  10858.         cx == FN_FPBLK  ||
  10859.         cx == FN_NLINE  ||
  10860.         cx == FN_FERMSG ||
  10861.         cx == FN_FILNO) {
  10862.         int x = 0, t = 0, channel;
  10863.         long z;
  10864.         extern int z_maxchan;
  10865.  
  10866.         failed = 1;                     /* Assume failure */
  10867.         p = fnval;                      /* until we validate args */
  10868.         if (cx == FN_FERMSG) {
  10869.             extern int z_error;
  10870.             if (argn < 1) {
  10871.                 x = z_error;
  10872.             } else if (chknum(bp[0])) {
  10873.                 x = atoi(bp[0]);
  10874.             } else if (fndiags)
  10875.               ckmakmsg(fnval,FNVALL,
  10876.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10877.             failed = 0;
  10878.             ckstrncpy(fnval,ckferror(x),FNVALL);
  10879.             goto fnend;
  10880.         }
  10881.         if (argn < 1) {                 /* All file functions need channel */
  10882.         if (cx == FN_FSTAT) {    /* Except f_status(), e.g. when */
  10883.         fnval[0] = '0';        /* called with a variable that */
  10884.         fnval[1] = NUL;        /* hasn't been defined yet. */
  10885.         failed = 0;
  10886.         } else {
  10887.         if (fndiags)
  10888.          ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10889.         }
  10890.             goto fnend;
  10891.         }
  10892.         if (rdigits(bp[0])) {           /* Channel must be numeric */
  10893.             channel = atoi(bp[0]);
  10894.         } else {                        /* Fail if it isn't */
  10895.             if (fndiags)
  10896.               ckmakmsg(fnval,FNVALL,
  10897.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10898.             goto fnend;
  10899.         }
  10900.         if (channel < 0 || channel > z_maxchan) { /* Check channel range */
  10901.             if (fndiags)
  10902.               ckmakmsg(fnval,FNVALL,
  10903.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10904.             goto fnend;
  10905.         }
  10906.         x = z_getmode(channel);         /* Find out about the channel */
  10907.  
  10908.         failed = 0;                     /* Assume success from here down */
  10909.         if (cx == FN_FSTAT) {           /* Status / modes of channel */
  10910.             if (x > -1)
  10911.               x &= FM_RWB;              /* Mask out irrelevant bits */
  10912.             else                        /* In this case not open is OK */
  10913.               x = 0;                    /* 0 if not open, 1-7 if open */
  10914.             sprintf(fnval,"%d",x);      /* SAFE */
  10915.             goto fnend;
  10916.         } else if (x < 1) {             /* Not \f_status() so must be open */
  10917.             failed = 1;
  10918.             if (fndiags)
  10919.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_OPEN:\\f",fn,"()>",NULL);
  10920.             goto fnend;
  10921.         }
  10922.         switch (y) {                    /* Do the requested function */
  10923.           case FN_FPOS:                 /* Get position */
  10924.             z = z_getpos(channel);    /* FIX THIS */
  10925.             sprintf(fnval,"%ld",z);     /* SAFE */
  10926.             goto fnend;
  10927.  
  10928.           case FN_NLINE:                /* Get line number */
  10929.             z = z_getline(channel);    /* FIX THIS */
  10930.             sprintf(fnval,"%ld",z);     /* SAFE */
  10931.             goto fnend;
  10932.  
  10933.           case FN_FEOF:                 /* Check EOF */
  10934.             t = 0;
  10935.             if (x & FM_EOF) t = 1;
  10936.             sprintf(fnval,"%d",t);      /* SAFE */
  10937.             goto fnend;
  10938.  
  10939.           case FN_FILNO:                /* Get file handle */
  10940.             x = z_getfnum(channel);
  10941.             sprintf(fnval,"%d",x);      /* SAFE */
  10942.             goto fnend;
  10943.  
  10944.           case FN_FPBLK:                /* Read or write block */
  10945.           case FN_FGBLK:
  10946.             if (argn < 2) {
  10947.                 if (fndiags)
  10948.                   ckmakmsg(fnval,FNVALL,
  10949.                            "<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10950.                 goto fnend;
  10951.             }
  10952.             if (rdigits(bp[1])) {
  10953.                 t = atoi(bp[1]);
  10954.             } else {
  10955.                 if (fndiags)
  10956.                   ckmakmsg(fnval,FNVALL,
  10957.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10958.                 goto fnend;
  10959.             }
  10960.           case FN_FGCHAR:               /* Read or write character or line */
  10961.           case FN_FPCHAR:
  10962.           case FN_FGLINE:
  10963.           case FN_FPLINE:
  10964.             fnval[0] = NUL;
  10965.             switch (y) {
  10966.               case FN_FGCHAR: t = z_in(channel,fnval,FNVALL,1,1); break;
  10967.               case FN_FGLINE: t = z_in(channel,fnval,FNVALL,FNVALL-1,0); break;
  10968.               case FN_FGBLK:
  10969.                 if (t >= FNVALL) t = FNVALL - 1;
  10970.                 t = z_in(channel,fnval,FNVALL,t,1);
  10971.                 break;
  10972.               case FN_FPCHAR: t = z_out(channel,bp[1],1,1);  break;
  10973.               case FN_FPLINE: t = z_out(channel,bp[1],-1,0); break;
  10974.               case FN_FPBLK:  t = z_out(channel,bp[1],-1,1); break;
  10975.             }
  10976.             if (t < 0) {                /* Handle read/write error */
  10977.                 failed = 1;
  10978.                 if (fndiags && t != FX_EOF)
  10979.                   ckmakmsg(fnval,FNVALL,
  10980.                            "<ERROR:FILE_ERROR_%d:\\f",fn,"()>",NULL);
  10981.                 goto fnend;
  10982.             }
  10983.             if (cx == FN_FGCHAR)        /* Null terminate char */
  10984.               fnval[1] = NUL;
  10985.             /* Write (put) functions return numeric status code */
  10986.             if (cx == FN_FPCHAR || cx == FN_FPLINE || cx == FN_FPBLK)
  10987.               sprintf(fnval,"%d",t);    /* SAFE */
  10988.             goto fnend;
  10989.         }
  10990.     }
  10991. #endif /* CKCHANNELIO */
  10992.  
  10993.     if (cx == FN_SQUEEZE) {        /* String function \fsqueeze() */
  10994.     /* Squeeze out whitespace */
  10995.     /* Add options later for whether to trim leading and trailing blanks */
  10996.         /* and what to do about control characters, 8-bit whitespace, etc */
  10997.     int started = 0;        /* Flag for first non-whitespace */
  10998.     int n = 0;            /* Blank/Tab counter */
  10999.         s = bp[0] ? bp[0] : "";
  11000.         p = fnval;            /* Result buffer */
  11001.     while (*s) {            /* While there is input */
  11002.         if (!started && (*s == ' ' || *s == '\011')) {
  11003.         s++;            /* Skip past leading whitespace */
  11004.         continue;
  11005.         }
  11006.         started++;            /* Leading whitespace was skipped */
  11007.         if (*s != ' ' && *s != '\011') { /* Have a nonspace char */
  11008.         n = 0;            /* reset space counter */
  11009.         *p++ = *s++;        /* copy char to destination */
  11010.         continue;
  11011.         }            
  11012.         if (n++ > 0) {        /* Have blank or tab */
  11013.         s++;            /* don't copy more than one */
  11014.         continue;
  11015.         }
  11016.         *p++ = ' ';            /* Deposit one space */
  11017.         s++;            /* and go to next source char */
  11018.     }
  11019.     if (*(p-1) == ' ') p--;        /* Remove trailing space */
  11020.         *p = NUL;            /* Terminate string */
  11021.         p = fnval;            /* point to beginning */
  11022.         goto fnend;            /* Done. */
  11023.     }
  11024.     if (cx == FN_PATTERN) {             /* \fpattern() for INPUT */
  11025.         itsapattern = 1;
  11026.         if (argn > 0) {
  11027.             p = fnval;
  11028.             ckstrncpy(fnval,bp[0],FNVALL);
  11029.         } else p = "";
  11030.         goto fnend;
  11031.     }
  11032.     if (cx == FN_HEX2N || cx == FN_OCT2N) { /* \fhex2n(), \foct2n() */
  11033.         p = "0";
  11034.         if (argn < 1)
  11035.           goto fnend;
  11036.         p = ckradix(bp[0], ((cx == FN_HEX2N) ? 16 : 8), 10);
  11037.         if (!p) {
  11038.             if (fndiags)
  11039.               ckmakmsg(fnval,FNVALL,
  11040.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11041.             goto fnend;
  11042.         }
  11043.         failed = 0;
  11044.         ckstrncpy(fnval,p,FNVALL);
  11045.         p = fnval;
  11046.         goto fnend;
  11047.     }
  11048.  
  11049.     if (cx == FN_HEX2IP) {
  11050.         int c[2], ip[4], i, k;
  11051.         p = "0";
  11052.         if (argn < 1)
  11053.           goto fnend;
  11054.         s = bp[0];
  11055.         if ((int)strlen(s) != 8) {
  11056.             failed = 1;
  11057.             if (fndiags)
  11058.               ckmakmsg(fnval,FNVALL,
  11059.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11060.             goto fnend;
  11061.         }
  11062.         p = fnval;
  11063.         for (k = 0; k < 8; k += 2) {
  11064.             for (i = 0; i < 2; i++) {
  11065.                 c[i] = *s++;
  11066.                 if (islower(c[i])) c[i] = toupper(c[i]);
  11067.                 if (c[i] >= '0' && c[i] <= '9') {
  11068.                     c[i] -= 0x30;
  11069.                 } else if (c[i] >= 'A' && c[i] <= 'F') {
  11070.                     c[i] -= 0x37;
  11071.                 } else {
  11072.                     failed = 1;
  11073.                     if (fndiags)
  11074.                       ckmakmsg(fnval,FNVALL,
  11075.                                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11076.                     goto fnend;
  11077.                 }
  11078.                 ip[k/2] = c[0] << 4 | c[1];
  11079.             }
  11080.             sprintf(p,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  11081.         }
  11082.         goto fnend;
  11083.     }
  11084.     if (cx == FN_IP2HEX) {
  11085.         int ip[4], i;
  11086.         char * q;
  11087.         p = "00000000";
  11088.         if (argn < 1)
  11089.           goto fnend;
  11090.         s = bp[0];
  11091.         p = fnval;
  11092.         for (i = 0; i < 3; i++) {
  11093.             q = ckstrchr(s,'.');
  11094.             if (q) {
  11095.                 *q++ = NUL;
  11096.                 ip[i] = atoi(s);
  11097.                 s = q;
  11098.             } else {
  11099.                 failed = 1;
  11100.                 if (fndiags)
  11101.                   ckmakmsg(fnval,FNVALL,
  11102.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11103.                 goto fnend;
  11104.             }
  11105.         }
  11106.         ip[3] = atoi(s);
  11107.         sprintf(p,"%02x%02x%02x%02x",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  11108.         goto fnend;
  11109.     }
  11110.     if (cx == FN_RADIX) {
  11111.         failed = 1;
  11112.         p = fnval;
  11113.         if (argn < 3) {
  11114.             if (fndiags)
  11115.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  11116.             goto fnend;
  11117.         }
  11118.         if (!rdigits(bp[1]) || !rdigits(bp[2])) {
  11119.             if (fndiags)
  11120.               ckmakmsg(fnval,FNVALL,
  11121.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11122.             goto fnend;
  11123.         }
  11124.         p = ckradix(bp[0],atoi(bp[1]),atoi(bp[2]));
  11125.         if (!p) {
  11126.             if (fndiags)
  11127.               ckmakmsg(fnval,FNVALL,
  11128.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11129.             goto fnend;
  11130.         }
  11131.         failed = 0;
  11132.         ckstrncpy(fnval,p,FNVALL);
  11133.         p = fnval;
  11134.         goto fnend;
  11135.     }
  11136.     if (cx == FN_JOIN) {
  11137.         int i, x, y, z, flag, hi, lo, max, seplen, grouping = 0;
  11138.         char abuf[16], c, *s, *q, *sep = NULL;
  11139.         char * gr_opn = "\"{'([<";      /* Group open brackets */
  11140.         char * gr_cls = "\"}')]>";      /* Group close brackets */
  11141.         char lb[2], rb[2];              /* Selected left and right brackets */
  11142.  
  11143.         failed = 1;                     /* Assume failure */
  11144.         fnval[0] = NUL;
  11145.         debug(F101,"FNJOIN ARGN","",argn);
  11146.  
  11147.         ckstrncpy(abuf,bp[0],16);       /* Get array reference */
  11148.         s = abuf;
  11149.         if ((x = arraybounds(s,&lo,&hi)) < 0) {  /* Get index and bounds */
  11150.             if (fndiags)
  11151.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  11152.             goto fnend;
  11153.         }
  11154.         p = fnval;                      /* Point to result */
  11155.         max = a_dim[x];                 /* Size of array */
  11156.         if (lo < 0) lo = 1;             /* Use given range if any */
  11157.         if (lo > max) lo = max;
  11158. #ifdef COMMENT
  11159.     hi = max;
  11160. #else
  11161. /*
  11162.   This is a workaround for the problem in which the dimension of the \&_[]
  11163.   array (but not its contents) grows upon entry to a SWITCH block.  But this
  11164.   code prevents the dimension from growing.  Go figure.
  11165. */
  11166.         if (hi < 0) {            /* Bounds not given */
  11167.             if (x)            /* Regular array */
  11168.           hi = max;
  11169.         else            /* Argument vector array */
  11170.           for (hi = max; hi >= lo; hi--) { /* ignore any trailing */
  11171.           if (!a_ptr[x][hi]) continue; /* empty elements */
  11172.           if (!*(a_ptr[x][hi])) continue;
  11173.           break;
  11174.           }
  11175.     }
  11176. #endif /* COMMENT */
  11177.         if (hi > max) hi = max;
  11178.         failed = 0;                     /* Unset failure flag */
  11179.         if (max < 1)
  11180.           goto fnend;
  11181.         sep = " ";                      /* Separator */
  11182.         if (argn > 1)
  11183.           if (bp[1])
  11184.             if (*bp[1])
  11185.               sep = bp[1];
  11186.         lb[0] = NUL;
  11187.         rb[0] = NUL;
  11188.         lb[1] = NUL;
  11189.         rb[1] = NUL;
  11190.         if (argn > 2) {                 /* Grouping? */
  11191.             char * bp2 = bp[2];
  11192.             if (!bp2) bp2 = "0";
  11193.             if (!*bp2) bp2 = "0";
  11194.             if (chknum(bp2)) {
  11195.                 grouping = atoi(bp2);
  11196.                 if (grouping < 0 || grouping > 63)
  11197.                   grouping = 1;
  11198.             } else {
  11199.                 failed = 1;
  11200.                 if (fndiags)
  11201.                   ckmakmsg(fnval,FNVALL,
  11202.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11203.                 goto fnend;
  11204.             }
  11205.             if (grouping) {             /* Take lowest-order one */
  11206.                 int j, k;               /* and set the others to 0 */
  11207.                 for (k = 0; k < 6; k++) {
  11208.                     j = 1 << k;
  11209.                     if (grouping & j) {
  11210.                         lb[0] = gr_opn[k];
  11211.                         rb[0] = gr_cls[k];
  11212.                         break;
  11213.                     }
  11214.                 }
  11215.             }
  11216.         }
  11217.         if (argn > 3)                   /* Nonzero 4th arg for no separator */
  11218.           if (chknum(bp[3]))
  11219.             if (atoi(bp[3]) > 0)
  11220.               sep = NULL;
  11221.         if (!sep) {
  11222.             sep = "";
  11223.             seplen = 0;
  11224.         } else
  11225.           seplen = strlen(sep);
  11226.         for (i = lo; i <= hi; i++) {    /* Loop thru selected array elements */
  11227.             s = a_ptr[x][i];            /* Get next element */
  11228.             if (!s)
  11229.               s = "";
  11230.             flag = 0;                   /* Buffer overrun flag */
  11231.             if (grouping) {             /* Does this element need quoting? */
  11232.                 q = s;                  /* Look for spaces */
  11233.                 while ((c = *q++)) { if (c == SP) { flag++; break; } }
  11234.             }
  11235.             y = strlen(s);              /* Get length of this element */
  11236.             if (cx == 0 && grouping)    /* If empty it might need quoting */
  11237.               flag = 1;
  11238.             if (flag) {                 /* Add grouping if needed */
  11239.                 char * s2 = NULL;
  11240.                 y += 2;
  11241.                 if ((q = (char *)malloc(y+1))) {
  11242.                     ckmakmsg(q,y+1,(char *)lb,s,(char *)rb,NULL);
  11243.                     makestr(&s2,q);
  11244.                     free(q);
  11245.                     s = s2;
  11246.                 }
  11247.             }
  11248.             z = 0;                      /* Number of chars copied */
  11249.             flag = 0;                   /* flag is now buffer-overrun flag */
  11250.             if (y > 0)                  /* If this string is not empty */
  11251.               z = ckstrncat(fnval,s,FNVALL); /* copy it. */
  11252.             if (z < y)                  /* Check for buffer overrun. */
  11253.               flag++;
  11254.             if (!flag && *sep && i < hi) { /* If buffer still has room */
  11255.                 z = ckstrncat(fnval,sep,FNVALL); /* copy delimiter */
  11256.                 if (z < seplen)
  11257.                   flag++;
  11258.             }
  11259.             if (flag) {
  11260.                 failed = 1;
  11261.                 if (fndiags)
  11262.                   ckmakmsg(fnval,FNVALL,
  11263.                            "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  11264.                 goto fnend;
  11265.             }
  11266.         }
  11267.     isjoin = 1;
  11268.         goto fnend;
  11269.     }
  11270.     if (cx == FN_SUBST) {               /* \fsubstitute() */
  11271.         CHAR c, * s, * r, * tp[2], buf1[256], buf2[256], buf3[256];
  11272.         int len, i, j, state = 0, lo = 0, hi = 0;
  11273.  
  11274.         failed = 0;
  11275.         p = fnval;                      /* Result pointer */
  11276.         *p = NUL;
  11277.         if (!bp[0])                     /* No target, no result*/
  11278.           goto fnend;
  11279.  
  11280.         len = strlen(bp[0]);            /* Length of source */
  11281.         if (len == 0)
  11282.           goto fnend;
  11283.         if (len > FNVALL) {
  11284.             failed = 1;
  11285.             if (fndiags)
  11286.               ckmakmsg(fnval,FNVALL,
  11287.                        "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  11288.             goto fnend;
  11289.         }
  11290.         if (!bp[1]) {
  11291.             ckstrncpy(bp[0],fnval,FNVALL);
  11292.             goto fnend;
  11293.         }
  11294.         tp[0] = buf1;                   /* For s2-s3 interpretation loop */
  11295.         tp[1] = buf2;
  11296.  
  11297.         for (i = 0; i < 256; i++) {     /* Initialize working buffers */
  11298.             buf1[i] = 0;                /* s2 expansion buffer */
  11299.             buf2[i] = 0;                /* s3 expansion buffer */
  11300.             buf3[i] = i;                /* Translation table */
  11301.         }
  11302.         for (i = 0; i < 2; i++) {       /* Interpret s2 and s3 */
  11303.             s = (CHAR *)bp[i+1];        /* Arg pointer */
  11304.             if (!s) s = (CHAR *)"";
  11305.             r = tp[i];                  /* To construct interpreted arg */
  11306.             j = 0;                      /* Output buf pointer */
  11307.             state = 0;                  /* Initial state */
  11308.             while (c = *s++) {          /* Loop thru arg chars */
  11309.                 if (j > 255)            /* Output buf full */
  11310.                   break;
  11311.                 switch (state) {
  11312.                   case 0:               /* Normal state */
  11313.                     switch (c) {
  11314.                       case '\\':        /* Have quote */
  11315.                         state = 1;
  11316.                         break;
  11317.                       case '[':         /* Have range starter */
  11318.                         state = 2;
  11319.                         break;
  11320.                       default:          /* Anything else */
  11321.                         r[j++] = c;
  11322.                         break;
  11323.                     }
  11324.                     continue;
  11325.                   case 1:               /* Quoted char */
  11326.                     r[j++] = c;
  11327.                     state = 0;
  11328.                     continue;
  11329.                   case 2:               /* Range bottom */
  11330.                     lo = c;
  11331.                     state++;
  11332.                     continue;
  11333.                   case 3:               /* Range separater */
  11334.                     if (c != '-') {
  11335.                         failed = 1;
  11336.                         if (fndiags)
  11337.                           ckmakmsg(fnval,FNVALL,
  11338.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  11339.                         goto fnend;
  11340.                     }
  11341.                     state++;
  11342.                     continue;
  11343.                   case 4:               /* Range top */
  11344.                     hi = c;
  11345.                     state++;
  11346.                     continue;
  11347.                   case 5:               /* Range end */
  11348.                     if (c != ']') {
  11349.                         failed = 1;
  11350.                         if (fndiags)
  11351.                           ckmakmsg(fnval,FNVALL,
  11352.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  11353.                         goto fnend;
  11354.                     }
  11355.                     for (k = lo; k <= hi && j < 255; k++) /* Fill in */
  11356.                       r[j++] = k;
  11357.                     lo = 0; hi = 0;     /* Reset */
  11358.                     state = 0;
  11359.                     continue;
  11360.                 }
  11361.             }
  11362.         }
  11363.         for (i = 0; i < 256 && buf1[i]; i++) {  /* Create translation table */
  11364.             k = (unsigned)buf1[i];
  11365.             buf3[k] = buf2[i];
  11366.         }
  11367.         s = (CHAR *)bp[0];              /* Point to source string */
  11368.         for (i = 0; i < len; i++) {     /* Translation loop */
  11369.             k = (unsigned)s[i];         /* Get next char */
  11370.             if (!buf3[k])               /* Remove this char */
  11371.               continue;
  11372.             *p++ = buf3[k];             /* Substitute this char */
  11373.         }
  11374.         *p = NUL;
  11375.         p = fnval;
  11376.         goto fnend;
  11377.     }
  11378.  
  11379. #ifndef NOSEXP
  11380.     if (cx == FN_SEXP) {                /* \fsexpression(arg1) */
  11381.         char * p2;
  11382.         fsexpflag++;
  11383.         p = (argn > 0) ? dosexp(bp[0]) : "";
  11384.         fsexpflag--;
  11385.         p2 = fnval;
  11386.         while ((*p2++ = *p++)) ;
  11387.         p = fnval;
  11388.         goto fnend;
  11389.     }
  11390. #endif /* NOSEXP */
  11391.  
  11392.     if (cx == FN_CMDSTK) {              /* \fcmdstack(n1,n2) */
  11393.         int i, j, k;
  11394.         char * s;
  11395.  
  11396.         if (bp[0])
  11397.           val1 = *(bp[0]) ? evalx(bp[0]) : ckitoa(cmdlvl);
  11398.         else
  11399.           val1 = ckitoa(cmdlvl);
  11400. #ifdef COMMENT
  11401.         free(bp[0]);                    /* (evalx() always uses same buffer) */
  11402.         bp[0] = NULL;                   /* (not any more!) */
  11403. #endif /* COMMENT */
  11404.         failed = 1;
  11405.         if (argn > 1) {
  11406. #ifdef COMMENT
  11407.             makestr(&(bp[0]),val1);
  11408.             val1 = bp[0];
  11409. #endif /* COMMENT */
  11410.             val2 = *(bp[1]) ? evalx(bp[1]) : "0";
  11411.             if (!(chknum(val1) && chknum(val2))) {
  11412.                 if (fndiags)
  11413.                   ckmakmsg(fnval,FNVALL,
  11414.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11415.                 goto fnend;
  11416.             }
  11417.         } else {
  11418.             val1 = ckitoa(cmdlvl);
  11419.             val2 = "0";
  11420.         }
  11421.         i = atoi(val1);                 /* Level */
  11422.         j = atoi(val2);                 /* Flags */
  11423.         if (i < 0 || i > cmdlvl) {
  11424.             if (fndiags)
  11425.               ckmakmsg(fnval,FNVALL,
  11426.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11427.             goto fnend;
  11428.         }
  11429.         failed = 0;
  11430.         p = fnval;
  11431.         k = cmdstk[i].src;              /* What (prompt, file, macro) */
  11432.         if (j) {
  11433.             ckstrncpy(fnval,ckitoa(k),FNVALL);
  11434.             goto fnend;
  11435.         }
  11436.         switch (k) {
  11437.           case CMD_KB:
  11438.             ckstrncpy(fnval,"(prompt)",FNVALL);
  11439.             break;
  11440.           case CMD_TF:
  11441.             s = tfnam[cmdstk[i].lvl];
  11442.             if (!zfnqfp(s,FNVALL,fnval))
  11443.               ckstrncpy(fnval,s,FNVALL);
  11444.             break;
  11445.           case CMD_MD:
  11446.             ckstrncpy(fnval,m_arg[cmdstk[i].lvl][0],FNVALL);
  11447.             break;
  11448.         }
  11449.         goto fnend;
  11450.     }
  11451. #ifdef CKFLOAT
  11452.     if (cx == FN_DIFDATE) {             /* \fdiffdates(d1,d2) */
  11453.         char * d1, * d2;
  11454.         d1 = bp[0] ? bp[0] : ckdate();
  11455.         d2 = bp[1] ? bp[1] : ckdate();
  11456.         p = (char *)cmdiffdate(d1,d2);
  11457.         if (!p) {
  11458.             failed = 1;
  11459.             if (fndiags) {
  11460.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11461.                 p = fnval;
  11462.             }
  11463.         }
  11464.         goto fnend;
  11465.     }
  11466. #endif /* CKFLOAT */
  11467.     if (cx == FN_CMPDATE) {             /* \fcmddates(d1,d2) */
  11468.         int x = 0;
  11469.         char d1[18], d2[18], * dp;
  11470.         failed = 0;
  11471.         d1[0] = NUL;
  11472.         d2[0] = NUL;
  11473.         p = fnval;
  11474.         dp = cmcvtdate(bp[0],1);
  11475.         if (dp) {
  11476.             ckstrncpy(d1,dp,18);
  11477.             if ((dp = cmcvtdate(bp[1],1))) {
  11478.                 ckstrncpy(d2,dp,18);
  11479.                 x = 1;
  11480.             }
  11481.         }
  11482.         if (x == 0) {
  11483.             failed = 1;
  11484.             if (fndiags)
  11485.               ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11486.         } else {
  11487.             x = strcmp(d1,d2);
  11488.             if (x > 0)
  11489.               x = 1;
  11490.             else if (x < 0)
  11491.               x = -1;
  11492.             sprintf(fnval,"%d",x);
  11493.         }
  11494.         goto fnend;
  11495.     }
  11496.     if (cx == FN_TOGMT) {               /* \futcdate(d1) */
  11497.         char * d1, * dp;
  11498.         char datebuf[32];
  11499.         char d2[32];
  11500.         p = fnval;
  11501.         failed = 1;
  11502.         if ((dp = cmcvtdate(bp[0],1))) { /* The given date */
  11503.             ckstrncpy(datebuf,dp,18);
  11504.             ckstrncpy(d2,dp,18);        /* local time */
  11505.             ckstrncat(datebuf,"Z",19);  /* Same time GMT */
  11506.             if ((dp = cmcvtdate(datebuf,1))) /* converted to local time */
  11507.               ckstrncpy(datebuf,dp,18);
  11508.             if ((p = (char *)cmdiffdate(d2,datebuf))) { /* Get offset */
  11509.                 ckstrncat(d2,p,32);     /* Append offset to local time */
  11510.                 if ((dp = cmcvtdate(d2,1))) {
  11511.                     failed = 0;
  11512.                     ckstrncpy(fnval,dp,FNVALL);
  11513.                     p = fnval;
  11514.                 }
  11515.             }
  11516.         }
  11517.         if (failed && fndiags)
  11518.           ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11519.         goto fnend;
  11520.     }
  11521.     if (cx == FN_DELSEC) {              /* \fdelta2secs(delta-time) */
  11522.         long secs;
  11523.         p = fnval;
  11524.         if ((x = delta2sec(bp[0],&secs)) < 0) {
  11525.             failed = 1;
  11526.             if (fndiags)
  11527.               ckmakmsg(fnval,FNVALL,
  11528.                        (x == -1) ?
  11529.                          "<ERROR:BAD_DELTA_TIME:\\f" :
  11530.                          "<ERROR:OVERFLOW:\\f",
  11531.                        fn,
  11532.                        "()>",
  11533.                        NULL
  11534.                        );
  11535.             goto fnend;
  11536.         }
  11537.         sprintf(p,"%ld",secs);
  11538.         goto fnend;
  11539.     }
  11540.     if (cx == FN_PC_DU) {
  11541.         char c, * s = bp[0];
  11542.         if (!s) s = "";
  11543.         p = fnval;
  11544.         while ((c = *s++)) {
  11545.             if (c == ':') {
  11546.                 if (*s != '\\')
  11547.                   *p++ = '/';
  11548.             } else if (c == '\\') {
  11549.                 *p++ = '/';
  11550.             } else {
  11551.                 *p++ = c;
  11552.             }
  11553.         }
  11554.         *p = NUL;
  11555.         p = fnval;
  11556.         goto fnend;
  11557.     }
  11558.     if (cx == FN_PC_UD) {               /* Unix to DOS path */
  11559.         char c, * s = bp[0];
  11560.         if (!s) s = "";
  11561.         if (*s == '~') {                /* Skip leading tilde */
  11562.             s++;
  11563.             if (*s == '/')
  11564.               s++;
  11565.         }
  11566.         p = fnval;
  11567.         while ((c = *s++))
  11568.           *p ++ = (c == '/') ? '\\' : c;
  11569.         *p = NUL;
  11570.         p = fnval;
  11571.         goto fnend;
  11572.     }
  11573.     if (cx == FN_KWVAL) {               /* Keyword=Value */
  11574.         p = dokwval(bp[0],bp[1]?bp[1]:"=");
  11575.         goto fnend;
  11576.     }
  11577. #ifdef COMMENT
  11578. /* Cute idea but doesn't work */
  11579.     if (cx == FN_SLEEP || cx == FN_MSLEEP) {
  11580.         p = "";
  11581.         if (chknum(bp[0])) {
  11582.             x = atoi(bp[0]);
  11583.         } else {
  11584.             failed = 1;
  11585.             if (fndiags) {
  11586.                 ckmakmsg(fnval,FNVALL,
  11587.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11588.                 p = fnval;
  11589.             }
  11590.             goto fnend;
  11591.         }
  11592.         if (cx == FN_SLEEP)
  11593.           x *= 1000;
  11594.         msleep(x);
  11595.         goto fnend;
  11596.     }
  11597. #endif /* COMMENT */
  11598.  
  11599. #ifdef NT
  11600.     if (cx == FN_SNAME) {
  11601.         GetShortPathName(bp[0],fnval,FNVALL);
  11602.         goto fnend;
  11603.     }
  11604.     if (cx == FN_LNAME) {
  11605.         ckGetLongPathName(bp[0],fnval,FNVALL);
  11606.         goto fnend;
  11607.     }
  11608. #endif /* NT */
  11609.  
  11610. /*
  11611.   \femailaddress():
  11612.   Picks the email address out of an RFC 2822 From: or Sender: header.
  11613.   Added 26 Nov 2005.  Handles all common, and some uncommon, cases but
  11614.   doesn't totally bother about nested comments.  Needed this for fetching
  11615.   email from a POP server and then constructing the BSD "From " line.
  11616.   Works with or without the "From: " or "Sender: " tag.
  11617. */
  11618.     if (cx == FN_EMAIL) {
  11619.         char c, * s = bp[0], * s2, * s3, * ap = "";
  11620.     int k, state = 0, quote = 0, infield = 0;
  11621.     int pc = 0;            /* For nested comments */
  11622.         if (!s) s = "";
  11623.     if (!*s) goto xemail;
  11624.  
  11625.     if (ckindex("From: ",s,0,0,0) == 1) s += 5;
  11626.     if (ckindex("Sender: ",s,0,0,0) == 1) s += 7;
  11627.  
  11628.     k = strlen(s);            /* Strip junk from end */
  11629.     if (k < 1) goto xemail;
  11630.     k--;
  11631.     while (k >= 0 && s[k] == CR || s[k] == LF)
  11632.       s[k--] = NUL;
  11633.     while (k >= 0 && s[k] == SP || s[k] == HT)
  11634.       s[k--] = NUL;
  11635.     if (k == 0)
  11636.       goto xemail;
  11637.  
  11638. #ifndef COMMENT                 /* Simple method if not 100% foolproof */
  11639.     k = 0;
  11640.     for (s2 = s; *s2; s2++) {    /* Find at-sign */
  11641.         if (*s2 == '@') {
  11642.         k++;            /* If more than one use rightmost */
  11643.         s3 = s2;
  11644.         }
  11645.     }
  11646.     if (k < 1)            /* No at-sign */
  11647.       goto xemail;
  11648.  
  11649.     for (ap = s3-1; ap >= s; ap--) { /* Back up to beginning of address */
  11650.         if (isspace(*ap) || *ap == '<') {
  11651.         ap++;
  11652.          break;
  11653.         }
  11654.         if (ap == s)
  11655.           break;
  11656.     }
  11657.     for (s2 = s3+1; *s2; s2++) {    /* Find end of address */
  11658.         if (isspace(*s2) || *s2 == '>')
  11659.           break;
  11660.     }
  11661.     *s2-- = NUL;
  11662.     if (*ap == '[' && *s2 == ']') {    /* Handle [blah@blah.blah] */
  11663.         ap++;
  11664.         *s2 = NUL;
  11665.     }
  11666.     if (!ckstrcmp(ap,"mailto:",7,0)) /* Handle mailto: URLs */
  11667.       ap += 7;
  11668.  
  11669. #else  /* Too complicated and error-prone */
  11670.  
  11671.     k = 0;
  11672.     for (s2 = s; *s2; s2++) {    /* Strip leading whitespace */
  11673.         if (*s2 == SP || *s2 == HT) {
  11674.         k = 1;
  11675.         break;
  11676.         }
  11677.     }
  11678.     if (!k) {            /* Simple address */
  11679.         ap = s;
  11680.         goto xemail;
  11681.     }
  11682.     do {                /* Not simple, have to extract it */
  11683.         if (quote) {
  11684.         quote = 0;
  11685.         continue;
  11686.         } else if (*s == '\\') {
  11687.         quote = 1;
  11688.         continue;
  11689.         }
  11690.         switch (state) {
  11691.           case 0:
  11692.         if (!infield && *s == '"') { /* Quoted string */
  11693.             infield = 1;
  11694.             c = '"';
  11695.             state = 1;
  11696.         } else if (!infield && *s == '(') { /* Comment in parens */
  11697.             pc++;
  11698.             infield = 1;
  11699.             c = ')';
  11700.             if (*ap) *s = NUL;
  11701.             state = 1;
  11702.         } else if (!infield && *s == '<') { /* Address */
  11703.             infield = 1;
  11704.             c = '>';
  11705.             ap = s+1;
  11706.             state = 2;
  11707.         } else if (infield && (*s == SP || *s == HT)) {
  11708.             infield = 0;
  11709.         } else {        /* One or more bare words */
  11710.             infield = 1;    /* Could be an address */
  11711.             if (!*ap) ap = s;    /* Could be comments */
  11712.         }
  11713.         continue;
  11714.           case 1:            /* In Quoted string or Comment */
  11715.         if (infield && *s == c) { /* Look for end */
  11716.             infield = 0;
  11717.             *s++ = NUL;
  11718.             while (*s == SP || *s == HT) s++;
  11719.             if (!*ap)
  11720.               ap = s;
  11721.             state = 0;
  11722.         }
  11723.         continue;
  11724.           case 2:            /* In address */
  11725.         if (infield && *s == c) { /* Looking for end */
  11726.             infield = 0;
  11727.             *s = NUL;
  11728.             break;
  11729.         }
  11730.         }
  11731.     } while (*s++);
  11732.  
  11733.       xemail:
  11734.     if (*ap) {
  11735.         while (*ap == SP || *ap == HT) ap++;
  11736.     }
  11737.     k = strlen(ap) - 1;
  11738.     while (k >= 0 && (ap[k] == SP || ap[k] == HT))
  11739.       ap[k--] = NUL;
  11740.     if (*ap) {
  11741.         failed = 0;
  11742.         if (*ap == '<') {
  11743.         k = strlen(ap);
  11744.         if (*(ap+k-1) == '>') {
  11745.             ap[k-1] = NUL;
  11746.             ap++;
  11747.         }
  11748.         }
  11749.     } else
  11750.       failed = 1;
  11751.     /* Here we might also want check against "*@*.*" */
  11752. #endif    /* COMMENt */
  11753.       xemail:
  11754.     ckstrncpy(fnval,ap,FNVALL);
  11755.     goto fnend;
  11756.     }
  11757.  
  11758. /*
  11759.    \fpicture():   Get dimensions of GIF or JPG image.
  11760.    fdc June 2006
  11761. */
  11762.     if (cx == FN_PICTURE) {
  11763.     FILE *fp = NULL;
  11764.     int c, x, w = 0, h = 0, eof = 0;
  11765.     unsigned int i, j, k;
  11766.     unsigned char buf[1024];
  11767.     char abuf[16], * p, * s;
  11768.     char ** ap = NULL;
  11769.  
  11770.     p = fnval;            /* Point to result */
  11771.     failed = 1;            /* Assume failure */
  11772.     if (argn > 1) {
  11773.         int xi;
  11774.         ckstrncpy(abuf,bp[1],16);    /* Get array reference */
  11775.         s = abuf;
  11776.         if (*s == CMDQ) s++;
  11777.         if (fndiags)        /* Default is this error message */
  11778.           ckmakmsg(fnval,FNVALL,
  11779.                "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  11780.         if (s[0] != '&')        /* "Address" of array */
  11781.           goto fnend;
  11782.         if (s[2])
  11783.           if (s[2] != '[' || s[3] != ']')
  11784.         goto fnend;
  11785.         if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  11786.           s[1] += 32;
  11787.         if ((xi = dclarray(s[1],2)) < 0) /* Two elements */
  11788.           goto fnend;
  11789.         ap = a_ptr[xi];        /* Point to array we just declared */
  11790.     }
  11791.     s = bp[0];            /* Filename */
  11792.     failed = 0;            /* From here on we don't fail */
  11793.     p[0] = '0';            /* Default return value */
  11794.     p[1] = NUL;
  11795.     if (!ckmatch("*.{jpg,jpeg,gif}$",s,0,1+4)) /* Appropriate name? */
  11796.       goto fnend;            /* No, fail */
  11797.     fp = fopen(s, "r");        /* Open it */
  11798.     if (fp == NULL) {        /* Can't, fail */
  11799.         p[0] = '-';
  11800.         p[1] = '1';
  11801.         p[2] = NUL;            /* Return -1 */
  11802.         goto fnend;
  11803.     }
  11804.     k = strlen(s);
  11805.     if (!ckstrcmp(&s[k-4],".gif",4,0)) { /* GIF file */
  11806.         if (fread(buf,1,10,fp) != 10) {
  11807.         fclose(fp);
  11808.         goto fnend;
  11809.         }
  11810.         /* Check signature */
  11811.         if (ckstrcmp((char *)buf,"GIF87a",6,0) &&
  11812.         ckstrcmp((char *)buf,"GIF89a",6,0)) {
  11813.         fclose(fp);
  11814.         goto fnend;
  11815.         }
  11816.         w = buf[6] + 256 * buf[7];
  11817.         h = buf[8] + 256 * buf[9];
  11818.         goto picend;
  11819.     } else if (!ckstrcmp(&s[k-4],".jpg",4,0) || /* JPEG file */
  11820.            !ckstrcmp(&s[k-5],".jpeg",5,0)) {
  11821.         if (fread(buf,1,2,fp) != 2) {
  11822.         fclose(fp);
  11823.         goto fnend;
  11824.         }
  11825.         if (buf[0] != 0xff || buf[1] != 0xd8) { /* Check signature */
  11826.         fclose(fp);
  11827.         goto fnend;
  11828.         }
  11829.         eof = 0;
  11830.         while (!eof) {        /* Loop for each marker */
  11831.         while (!eof) {        /* Find next marker */
  11832.             c = getc(fp);
  11833.             if (c == (unsigned int)EOF) {
  11834.             eof++;
  11835.             break;
  11836.             }
  11837.             if (c == 0xff) {
  11838.             buf[0] = c;
  11839.             c = getc(fp);
  11840.             if (c == (unsigned int)EOF) {
  11841.                 eof++;
  11842.                 break;
  11843.             }
  11844.             buf[1] = c;
  11845.             if (c == 0xd9)
  11846.               eof++;
  11847.             if (c >= 0xc0 && c <= 0xfe)
  11848.               break;
  11849.             }
  11850.         }
  11851.         if (eof) break;
  11852.         x = buf[1];
  11853.         if (x == 0xc0 || x == 0xc1 || x == 0xc2 || x == 0xc3 ||
  11854.             x == 0xc9 || x == 0xca || x == 0xcb) {
  11855.             if (fread(buf,1,7,fp) != 7) {
  11856.             fclose(fp);
  11857.             goto fnend;
  11858.             }
  11859.             h = buf[3] * 256 + buf[4];
  11860.             w = buf[5] * 256 + buf[6];
  11861.             goto picend;
  11862.         } else {        /* Not a desired field */
  11863.             if (feof(fp)) {
  11864.             eof++;
  11865.             break;
  11866.             }
  11867.             if (fread(buf,1,2,fp) != 2) { /* Length of this field */
  11868.             fclose(fp);
  11869.             goto fnend;
  11870.             }
  11871.             j = 256 * buf[0] + buf[1] - 2; /* Skip next field */
  11872.             if (CKFSEEK(fp,(CK_OFF_T)j,SEEK_CUR) != 0) {
  11873.             fclose(fp);
  11874.             goto fnend;
  11875.             }
  11876.         }
  11877.         } 
  11878.     }
  11879.       picend:
  11880.     fclose(fp);
  11881.     if (ap) {
  11882.         makestr(&(ap[0]),"2");
  11883.         makestr(&(ap[1]),ckitoa(w));
  11884.         makestr(&(ap[2]),ckitoa(h));
  11885.     }
  11886.     if (w > 0 && h > 0) {
  11887.         if (w > h) p[0] = '1';
  11888.         if (h >= w) p[0] = '2';
  11889.     }
  11890.     goto fnend;
  11891.     }
  11892.     if (cx == FN_PID) {
  11893.     int x = -1;
  11894.     if (chknum(bp[0])) {        /* Need numeric argument */
  11895.         int pid;
  11896.         pid = atoi(bp[0]);        /* Convert to int */
  11897. #ifdef UNIX
  11898.         if (kill(pid,0) < 0) {    /* Test it */
  11899.         if (errno ==
  11900. #ifdef ESRCH
  11901.             ESRCH        /* No such process */
  11902. #else
  11903.             3
  11904. #endif    /* ESRCH */
  11905.             )
  11906.           x = 0;
  11907.         } else            /* Process exists */
  11908.           x = 1;
  11909. #endif    /* UNIX */
  11910.     }
  11911.     sprintf(fnval,"%d",x);        /* SAFE */
  11912.     goto fnend;
  11913.     }
  11914.  
  11915.     if (cx == FN_FUNC) {
  11916.     char * s = bp[0];
  11917.     p = "0";
  11918.         debug(F111,"ffunc",s,argn);
  11919.     if (argn > 0) {
  11920.         int x, y;
  11921.         for (p = s; *p; p++) {    /* Chop off trailing parens if any */
  11922.         if (*p == '(') {
  11923.             *p = NUL;
  11924.             break;
  11925.         }
  11926.         }
  11927.         /* Chop off leading "\\f" or "\f" or "f" */
  11928.         p = s;
  11929.         if (*p == CMDQ)        /* Allow for \\f... */
  11930.           p++;
  11931.         if (*p == CMDQ && (*(p+1) == 'f' || *(p+1) == 'F')) { /* or \f */
  11932.         p += 2;
  11933.         } else if (*p == 'f' || *p == 'F') { /* or just f */
  11934.         p++;
  11935.         }
  11936.         y = lookup(fnctab,p,nfuncs,&x); /* Look up the result */
  11937.         debug(F111,"ffunc",p,y);
  11938.         p = (y > -1) ? "1" : "0";
  11939.     }
  11940.     goto fnend;
  11941.     }
  11942.  
  11943.     if (cx == FN_RECURSE) {
  11944.     int t, n; char *s, *s2;
  11945.     p = fnval;
  11946.         if (!*(bp[0]) && fndiags) {
  11947.             failed = 1;
  11948.             evalerr(fn);
  11949.         }
  11950.         n = FNVALL;            /* Space for result */
  11951.         s = fnval;            /* Location of result */
  11952.     {
  11953.         /* Force VARIABLE-EVALUATION SIMPLE RECURSIVE */
  11954.         /* NOTE: This is vulnerable to SIGINT and whatnot... */
  11955.         int tmp = vareval;        /* Save VARIABLE-EVALUATION setting */
  11956.         vareval = 1;        /* Force it to RECURSIVE */
  11957.         zzstring(bp[0],&s,&n);    /* Expand arg into result space */ 
  11958.         vareval = tmp;        /* Restore VARIABLE-EVALUATION */
  11959.     }
  11960.     goto fnend;
  11961.  
  11962.     }
  11963.  
  11964. /* Note: when adding new functions remember to update dohfunc in ckuus2.c. */
  11965.  
  11966.     failed = 1;
  11967.     if (fndiags)
  11968.       ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN_FUNCTION:\\f",fn,"()>",NULL);
  11969.  
  11970.   fnend:
  11971.     /* Free temporary storage for aguments */
  11972.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  11973.     fndepth--;
  11974.     if (failed) {                       /* Handle failure */
  11975.         debug(F111,"fnend",fnval,errno);
  11976.         if (!p) p = "";
  11977.         if (p[0]) {
  11978.             /* In case this wasn't caught above... */
  11979.             k = strlen(p);
  11980.             if (p[0] != '<' && p[k-1] != '>') {
  11981.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_ARG:\\f",fn,"()>",NULL);
  11982.                 p = fnval;
  11983.             }
  11984.         } else {
  11985.             ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN:\\f",fn,"()>",NULL);
  11986.             p = fnval;
  11987.         }
  11988.         if (fnerror)                    /* SET FUNCTION ERROR ON */
  11989.           fnsuccess = 0;                /* Make command fail (see ckuus5.c) */
  11990.         debug(F111,"fneval failed",p,fnsuccess);
  11991.         if (fndiags)                    /* SET FUNCTION DIAGNOSTICS ON */
  11992.           printf("?%s\n",p);            /* Print error message now. */
  11993.         else
  11994.           return("");                   /* Return nothing. */
  11995.     }
  11996.     return(p);
  11997. }
  11998. #endif /* NOSPL */
  11999.  
  12000. static char ckpidbuf[32] = "????";
  12001.  
  12002. #ifdef VMS
  12003. _PROTOTYP(long zgpid,(void));
  12004. #endif /* VMS */
  12005.  
  12006. char *
  12007. ckgetpid() {                            /* Return pid as string */
  12008. #ifdef CK_PID
  12009. #ifdef OS2
  12010. #define getpid _getpid
  12011.     unsigned long zz;
  12012. #else
  12013.     long zz;
  12014. #endif /* OS2 */
  12015. #ifdef VMS
  12016.     zz = zgpid();
  12017. #else
  12018.     zz = getpid();
  12019. #endif /* VMS */
  12020.     sprintf(ckpidbuf,"%ld",zz);         /* SAFE */
  12021. #endif /* CK_PID */
  12022.     return((char *)ckpidbuf);
  12023. }
  12024.  
  12025. #ifndef NOSPL
  12026. #define EMBUFLEN 128                    /* Error message buffer length */
  12027.  
  12028. static char embuf[EMBUFLEN+1];
  12029.  
  12030. char *                                  /* Evaluate builtin variable */
  12031. nvlook(s) char *s; {
  12032.     int x, y, cx;
  12033.     long z;
  12034.     char *p;
  12035. #ifndef NODIAL
  12036.     MDMINF * m;
  12037. #endif /* NODIAL */
  12038. #ifndef NOKVERBS                        /* Keyboard macro material */
  12039.     extern int keymac, keymacx;
  12040. #endif /* NOKVERBS */
  12041. #ifdef CK_LOGIN
  12042.     extern int isguest;
  12043. #endif /* CK_LOGIN */
  12044.     if (!s) s = "";
  12045.     x = strlen(s);
  12046.     if (fndiags) {                      /* FUNCTION DIAGNOSTIC ON */
  12047.         if (x + 32 < EMBUFLEN)
  12048.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE:\\v(%s)>",s); /* SAFE */
  12049.         else
  12050.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE>"); /* SAFE */
  12051.     } else                              /* FUNCTION DIAGNOSTIC OFF */
  12052.       embuf[0] = NUL;
  12053.     x = VVBUFL;
  12054.     p = vvbuf;
  12055.     if (zzstring(s,&p,&x) < 0) {        /* e.g. for \v(\%a) */
  12056.         y = -1;
  12057.     } else {
  12058.         s = vvbuf;
  12059.         y = lookup(vartab,s,nvars,&x);
  12060.     }
  12061.     cx = y;                             /* y is too generic */
  12062. #ifndef NODIAL
  12063.     m = (mdmtyp > 0) ? modemp[mdmtyp] : NULL; /* For \v(m_xxx) variables */
  12064. #endif /* NODIAL */
  12065.  
  12066.     debug(F101,"nvlook y","",y);
  12067.  
  12068.     switch (y) {
  12069.       case VN_ARGC:                     /* ARGC */
  12070.         sprintf(vvbuf,"%d",maclvl < 0 ? topargc : macargc[maclvl]); /* SAFE */
  12071.         return(vvbuf);
  12072.  
  12073.       case VN_ARGS:                     /* ARGS */
  12074.         sprintf(vvbuf,"%d",xargs);      /* SAFE */
  12075.         return(vvbuf);
  12076.  
  12077.       case VN_COUN:                     /* COUNT */
  12078.         sprintf(vvbuf,"%d",count[cmdlvl]); /* SAFE */
  12079.         return(vvbuf);
  12080.  
  12081.       case VN_DATE:                     /* DATE */
  12082.         ztime(&p);                      /* Get "asctime" string */
  12083.         if (p == NULL || *p == NUL) return(NULL);
  12084.         vvbuf[0] = p[8];                /* dd */
  12085.         vvbuf[1] = p[9];
  12086.         vvbuf[2] = SP;
  12087.         vvbuf[3] = p[4];                /* mmm */
  12088.         vvbuf[4] = p[5];
  12089.         vvbuf[5] = p[6];
  12090.         vvbuf[6] = SP;
  12091.         for (x = 20; x < 24; x++)       /* yyyy */
  12092.           vvbuf[x - 13] = p[x];
  12093.         vvbuf[11] = NUL;
  12094.         return(vvbuf);
  12095.  
  12096.       case VN_NDAT:                     /* Numeric date */
  12097.         ckstrncpy(vvbuf,zzndate(),VVBUFL);
  12098.         return(vvbuf);
  12099.  
  12100.       case VN_DIRE:                     /* DIRECTORY */
  12101.         s = zgtdir();                   /* Get current directory */
  12102.         if (!s)
  12103. #ifdef UNIXOROSK
  12104.           s = "./";
  12105. #else
  12106. #ifdef VMS
  12107.           s = "[]";
  12108. #else
  12109.           s = "";
  12110. #endif /* VMS */
  12111. #endif /* UNIXOROSK */
  12112.         ckstrncpy(vvbuf,s,VVBUFL);
  12113.         s = vvbuf;
  12114. #ifdef UNIXOROSK
  12115.         x = strlen(s);
  12116.         if (x < VVBUFL - 1) {
  12117.             if (s[x-1] != '/') {
  12118.                 s[x] = '/';
  12119.                 s[x+1] = NUL;
  12120.             }
  12121.         }
  12122. #endif /* UNIXOROSK */
  12123.         return(s);
  12124.  
  12125.       case VN_FILE:                     /* filespec */
  12126.         return(fspec);
  12127.  
  12128.       case VN_HOST:                     /* host name */
  12129.         if (*myhost) {                  /* If known */
  12130.             return(myhost);             /* return it. */
  12131.         } else {                        /* Otherwise */
  12132.             ckstrncpy(vvbuf,"unknown",VVBUFL); /* just say "unknown" */
  12133.             return(vvbuf);
  12134.         }
  12135.  
  12136.       case VN_SYST:                     /* System type */
  12137. #ifdef UNIX
  12138.         ckstrncpy(vvbuf,"UNIX",VVBUFL);
  12139. #else
  12140. #ifdef VMS
  12141.         ckstrncpy(vvbuf,"VMS",VVBUFL);
  12142. #else
  12143. #ifdef OSK
  12144.         ckstrncpy(vvbuf,"OS9/68K",VVBUFL);
  12145. #else
  12146. #ifdef AMIGA
  12147.         ckstrncpy(vvbuf,"Amiga",VVBUFL);
  12148. #else
  12149. #ifdef MAC
  12150.         ckstrncpy(vvbuf,"Macintosh",VVBUFL);
  12151. #else
  12152. #ifdef OS2
  12153. #ifdef NT
  12154.         ckstrncpy(vvbuf,"WIN32",VVBUFL) ;
  12155. #else /* NT */
  12156.         ckstrncpy(vvbuf,"OS/2",VVBUFL);
  12157. #endif /* NT */
  12158. #else
  12159. #ifdef datageneral
  12160.         ckstrncpy(vvbuf,"AOS/VS",VVBUFL);
  12161. #else
  12162. #ifdef GEMDOS
  12163.         ckstrncpy(vvbuf,"Atari_ST",VVBUFL);
  12164. #else
  12165. #ifdef STRATUS
  12166.         ckstrncpy(vvbuf,"Stratus_VOS",VVBUFL);
  12167. #else
  12168.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  12169. #endif /* STRATUS */
  12170. #endif /* GEMDOS */
  12171. #endif /* datageneral */
  12172. #endif /* OS2 */
  12173. #endif /* MAC */
  12174. #endif /* AMIGA */
  12175. #endif /* OSK */
  12176. #endif /* VMS */
  12177. #endif /* UNIX */
  12178.         return(vvbuf);
  12179.  
  12180.       case VN_SYSV:                     /* System herald */
  12181. #ifdef IKSD
  12182. #ifdef CK_LOGIN
  12183.         if (inserver && isguest)
  12184.           return("");
  12185. #endif /* CK_LOGIN */
  12186. #endif /* IKSD */
  12187.         for (x = y = 0; x < VVBUFL; x++) {
  12188.             if (ckxsys[x] == SP && y == 0) continue;
  12189.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  12190.         }
  12191.         vvbuf[y] = NUL;
  12192.         return(vvbuf);
  12193.     } /* Break up long switch statements... */
  12194.  
  12195.     switch(y) {
  12196.       case VN_TIME:                     /* TIME. Assumes that ztime returns */
  12197.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  12198.         if (p == NULL || *p == NUL)     /* like asctime()! */
  12199.           return("");
  12200.         for (x = 11; x < 19; x++)       /* copy hh:mm:ss */
  12201.           vvbuf[x - 11] = p[x];         /* to vvbuf */
  12202.         vvbuf[8] = NUL;                 /* terminate */
  12203.         return(vvbuf);                  /* and return it */
  12204.  
  12205.       case VN_NTIM:                     /* Numeric time */
  12206.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  12207.         if (p == NULL || *p == NUL)     /* like asctime()! */
  12208.           return(NULL);
  12209.         z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  12210.         sprintf(vvbuf,"%ld",z);         /* SAFE */
  12211.         return(vvbuf);
  12212.  
  12213. #ifdef CK_TTYFD
  12214.       case VN_TTYF:                     /* TTY file descriptor */
  12215.         sprintf(vvbuf,"%d",             /* SAFE */
  12216. #ifdef VMS
  12217.                 vmsttyfd()
  12218. #else
  12219.                 ttyfd
  12220. #endif /* VMS */
  12221.                 );
  12222.         return(vvbuf);
  12223. #endif /* CK_TTYFD */
  12224.  
  12225.       case VN_VERS:                     /* Numeric Kermit version number */
  12226.         sprintf(vvbuf,"%ld",vernum);    /* SAFE */
  12227.         return(vvbuf);
  12228.  
  12229.       case VN_XVNUM:                    /* Product-specific version number */
  12230.         sprintf(vvbuf,"%ld",xvernum);   /* SAFE */
  12231.         return(vvbuf);
  12232.  
  12233.       case VN_HOME:                     /* Home directory */
  12234.         return(homepath());
  12235.  
  12236.       case VN_IBUF:                     /* INPUT buffer */
  12237.         return((char *)inpbuf);
  12238.  
  12239.       case VN_ICHR:                     /* INPUT character */
  12240.         inchar[1] = NUL;
  12241.         return((char *)inchar);
  12242.  
  12243.       case VN_ICNT:                     /* INPUT character count */
  12244.         sprintf(vvbuf,"%d",incount);    /* SAFE */
  12245.         return(vvbuf);
  12246.  
  12247.       case VN_SPEE: {                   /* Transmission SPEED */
  12248.           long t;
  12249.           t = ttgspd();
  12250.           if (t < 0L)
  12251.             sprintf(vvbuf,"unknown");   /* SAFE */
  12252.           else
  12253.             sprintf(vvbuf,"%ld",t);     /* SAFE */
  12254.           return(vvbuf);
  12255.       }
  12256.  
  12257.       case VN_SUCC:                     /* SUCCESS flag */
  12258.         /* Note inverted sense */
  12259.         sprintf(vvbuf,"%d",(success == 0) ? 1 : 0); /* SAFE */
  12260.         return(vvbuf);
  12261.  
  12262.       case VN_LINE: {                   /* LINE */
  12263. #ifdef DEBUG
  12264.           if (deblog) {
  12265.               debug(F111,"\\v(line) local",ttname,local);
  12266.               debug(F111,"\\v(line) inserver","",inserver);
  12267. #ifdef TNCODE
  12268.               debug(F111,"\\v(line) tcp_incoming","",tcp_incoming);
  12269. #endif /* TNCODE */
  12270. #ifdef CK_TAPI
  12271.               debug(F111,"\\v(line) tttapi","",tttapi);
  12272. #endif /* CK_TAPI */
  12273.           }
  12274. #endif /* DEBUG */
  12275.  
  12276. #ifdef CK_TAPI
  12277.           if (tttapi) {                 /* If I have made a TAPI connection */
  12278.               int i;                    /* return the TAPI device name */
  12279.               for (i = 0; i < ntapiline; i++) {
  12280.                   if (!strcmp(ttname,tapilinetab[i].kwd)) {
  12281.                       p = _tapilinetab[i].kwd;
  12282.                       return(p);
  12283.                   }
  12284.               }
  12285.           }
  12286. #endif /* CK_TAPI */
  12287. #ifndef NOXFER
  12288.           if (inserver                  /* If I am a TCP server */
  12289. #ifdef TNCODE
  12290.               || tcp_incoming
  12291. #endif /* TNCODE */
  12292.               )
  12293. #ifdef TCPSOCKET
  12294.             p = ckgetpeer();            /* return peer name */
  12295.           else
  12296. #endif /* TCPSOCKET */
  12297. #endif /* NOXFER */
  12298.           if (local)                    /* Otherwise if in local mode */
  12299.             p = (char *) ttname;        /* return SET LINE / SET HOST name */
  12300.           else                          /* Otherwise */
  12301.             p = "";                     /* return empty string */
  12302.           if (!p)                       /* In case ckgetpeer() returns */
  12303.             p = "";                     /* null pointer... */
  12304.           debug(F110,"\\v(line) p",p,0);
  12305.           if (!*p)
  12306.             p = (char *) ttname;
  12307.           return(p);
  12308.       }
  12309.       case VN_PROG:                     /* Program name */
  12310.         return("C-Kermit");
  12311.  
  12312.     } /* Break up long switch statements... */
  12313.  
  12314.     switch(y) {
  12315.       case VN_RET:                      /* Value of most recent RETURN */
  12316.         debug(F111,"\\v(return)",mrval[maclvl+1],maclvl+1);
  12317.         p = mrval[maclvl+1];
  12318.         if (p == NULL) p = "";
  12319.         return(p);
  12320.  
  12321.       case VN_FFC:                      /* Size of most recent file */
  12322.         sprintf(vvbuf, "%s", ckfstoa(ffc)); /* SAFE */
  12323.         return(vvbuf);
  12324.  
  12325.       case VN_TFC:                      /* Size of most recent file group */
  12326.         sprintf(vvbuf, "%s", ckfstoa(tfc)); /* SAFE */
  12327.         return(vvbuf);
  12328.  
  12329.       case VN_CPU:                      /* CPU type */
  12330. #ifdef IKSD
  12331. #ifdef CK_LOGIN
  12332.         if (inserver && isguest)
  12333.           return("");
  12334. #endif /* CK_LOGIN */
  12335. #endif /* IKSD */
  12336. #ifdef OS2
  12337.          {
  12338.             char * getcpu(void) ;
  12339.             return getcpu();
  12340.          }
  12341. #else /* OS2 */
  12342. #ifdef CKCPU
  12343.         return(CKCPU);                  /* Traditionally, compile-time value */
  12344. #else
  12345. #ifdef CK_UTSNAME
  12346.         {                               /* But if none, try runtime value */
  12347.             extern char unm_mch[];
  12348.             return((char *)unm_mch);
  12349.         }
  12350. #else
  12351.         p = getenv("HOSTTYPE");        /* 20091116 */
  12352.     if (p) if (*p) return(p);
  12353.         return("unknown");
  12354. #endif /* CK_UTSNAME */
  12355. #endif /* CKCPU */
  12356. #endif /* OS2 */
  12357.  
  12358.       case VN_CMDL:                     /* Command level */
  12359.         sprintf(vvbuf, "%d", cmdlvl);   /* SAFE */
  12360.         return(vvbuf);
  12361.  
  12362.       case VN_DAY:                      /* Day of week */
  12363.         ztime(&p);
  12364.         if (p != NULL && *p != NUL)     /* ztime() succeeded. */
  12365.           ckstrncpy(vvbuf,p,4);
  12366.         else
  12367.           vvbuf[0] = NUL;               /* ztime() failed. */
  12368.         return(vvbuf);                  /* Return what we got. */
  12369.  
  12370.       case VN_NDAY: {                   /* Numeric day of week */
  12371.           long k;
  12372.           z = mjd(zzndate());           /* Get modified Julian date */
  12373.           k = (((int)(z % 7L)) + 3) % 7; /* Get day number */
  12374.           sprintf(vvbuf,"%ld",k);       /* SAFE */
  12375.           return(vvbuf);
  12376.       }
  12377.  
  12378.       case VN_LCL:                      /* Local (vs remote) mode */
  12379.         ckstrncpy(vvbuf, local ? "1" : "0",VVBUFL);
  12380.         return(vvbuf);
  12381.  
  12382.       case VN_CMDS:                     /* Command source */
  12383.         if (cmdstk[cmdlvl].src == CMD_KB)
  12384.           ckstrncpy(vvbuf,"prompt",VVBUFL);
  12385.         else if (cmdstk[cmdlvl].src == CMD_MD)
  12386.           ckstrncpy(vvbuf,"macro",VVBUFL);
  12387.         else if (cmdstk[cmdlvl].src == CMD_TF)
  12388.           ckstrncpy(vvbuf,"file",VVBUFL);
  12389.         else
  12390.           ckstrncpy(vvbuf,"unknown",VVBUFL);
  12391.         return(vvbuf);
  12392.  
  12393.       case VN_CMDF:                     /* Current command file name */
  12394. #ifdef COMMENT                          /* (see comments above) */
  12395.         if (tfnam[tlevel]) {            /* (near dblbs declaration) */
  12396.             dblbs(tfnam[tlevel],vvbuf,VVBUFL);
  12397.             return(vvbuf);
  12398.         } else return("");
  12399. #else
  12400.         if (tlevel < 0)
  12401.           return("");
  12402.         else
  12403.           return(tfnam[tlevel] ? tfnam[tlevel] : "");
  12404. #endif /* COMMENT */
  12405.  
  12406.       case VN_MAC:                      /* Current macro name */
  12407.         return((maclvl > -1) ? m_arg[maclvl][0] : "");
  12408.  
  12409.       case VN_EXIT:
  12410.         sprintf(vvbuf,"%d",xitsta);     /* SAFE */
  12411.         return(vvbuf);
  12412.  
  12413.     } /* Break up long switch statements... */
  12414.  
  12415.     switch(y) {
  12416.       case VN_PRTY: {                   /* Parity */
  12417.           char *ss;
  12418.           switch (parity) {
  12419.             case 0:   ss = "none";  break;
  12420.             case 'e': ss = "even";  break;
  12421.             case 'm': ss = "mark";  break;
  12422.             case 'o': ss = "odd";   break;
  12423.             case 's': ss = "space"; break;
  12424.             default:  ss = "unknown"; break;
  12425.           }
  12426.           ckstrncpy(vvbuf,ss,VVBUFL);
  12427.           return(vvbuf);
  12428.       }
  12429.  
  12430.       case VN_DIAL:
  12431.         sprintf(vvbuf,"%d",             /* SAFE */
  12432. #ifndef NODIAL
  12433.                 dialsta
  12434. #else
  12435.                 -1
  12436. #endif /* NODIAL */
  12437.                 );
  12438.         return(vvbuf);
  12439.  
  12440. #ifndef NODIAL
  12441.       case VN_DMSG:
  12442. #ifdef BIGBUFOK
  12443.     ckstrncpy(vvbuf,dialmsg[dialsta],VVBUFL); /* Safe if src == NULL */
  12444. #endif    /* BIGBUFOK */
  12445.     return((char *)vvbuf);
  12446. #endif    /* NODIAL */
  12447.  
  12448. #ifdef OS2
  12449.       case VN_KEYB:
  12450.         ckstrncpy(vvbuf,conkbg(),VVBUFL);
  12451.         return(vvbuf);
  12452.       case VN_SELCT: {
  12453. #ifndef NOLOCAL
  12454.           const char * selection = GetSelection();
  12455.           return( (char *) (selection ? selection : "" )) ;
  12456. #else
  12457.           return("");
  12458. #endif /* NOLOCAL */
  12459.       }
  12460. #endif /* OS2 */
  12461.  
  12462. #ifndef NOXFER
  12463.       case VN_CPS:
  12464.         sprintf(vvbuf,"%ld",tfcps);     /* SAFE */
  12465.         return(vvbuf);
  12466. #endif /* NOXFER */
  12467.  
  12468.       case VN_MODE:                     /* File transfer mode */
  12469.         switch (binary) {
  12470.           case XYFT_T: ckstrncpy(vvbuf,"text",VVBUFL); break;
  12471.           case XYFT_B:
  12472.           case XYFT_U: ckstrncpy(vvbuf,"binary",VVBUFL); break;
  12473.           case XYFT_I: ckstrncpy(vvbuf,"image",VVBUFL); break;
  12474.           case XYFT_L: ckstrncpy(vvbuf,"labeled",VVBUFL); break;
  12475.           case XYFT_M: ckstrncpy(vvbuf,"macbinary",VVBUFL); break;
  12476.           default:     ckstrncpy(vvbuf,"unknown",VVBUFL);
  12477.         }
  12478.         return(vvbuf);
  12479.  
  12480. #ifdef CK_REXX
  12481.       case VN_REXX:
  12482.         return(rexxbuf);
  12483. #endif /* CK_REXX */
  12484.  
  12485.       case VN_NEWL:                     /* System newline char or sequence */
  12486. #ifdef UNIX
  12487.         ckstrncpy(vvbuf,"\n",VVBUFL);
  12488. #else
  12489. #ifdef datageneral
  12490.         ckstrncpy(vvbuf,"\n",VVBUFL);
  12491. #else
  12492. #ifdef OSK
  12493.         ckstrncpy(vvbuf,"\15",VVBUFL);  /* Remember, these are octal... */
  12494. #else
  12495. #ifdef MAC
  12496.         ckstrncpy(vvbuf,"\15",VVBUFL);
  12497. #else
  12498. #ifdef OS2
  12499.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  12500. #else
  12501. #ifdef STRATUS
  12502.         ckstrncpy(vvbuf,"\n",VVBUFL);
  12503. #else
  12504. #ifdef VMS
  12505.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  12506. #else
  12507. #ifdef AMIGA
  12508.         ckstrncpy(vvbuf,"\n",VVBUFL);
  12509. #else
  12510. #ifdef GEMDOS
  12511.         ckstrncpy(vvbuf,"\n",VVBUFL);
  12512. #else
  12513.         ckstrncpy(vvbuf,"\n",VVBUFL);
  12514. #endif /* GEMDOS */
  12515. #endif /* AMIGA */
  12516. #endif /* VMS */
  12517. #endif /* STRATUS */
  12518. #endif /* OS2 */
  12519. #endif /* MAC */
  12520. #endif /* OSK */
  12521. #endif /* datageneral */
  12522. #endif /* UNIX */
  12523.         return(vvbuf);
  12524.  
  12525.       case VN_ROWS:                     /* ROWS */
  12526.       case VN_COLS:                     /* COLS */
  12527.         ckstrncpy(vvbuf,(cx == VN_ROWS) ? "24" : "80",VVBUFL); /* Default */
  12528. #ifdef CK_TTGWSIZ
  12529. #ifdef OS2
  12530.         if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  12531.           ttgwsiz();
  12532.         sprintf(vvbuf,"%d",             /* SAFE */
  12533.                 (cx == VN_ROWS) ? tt_rows[VTERM] : tt_cols[VTERM]);
  12534. #else /* OS2 */
  12535.         if (ttgwsiz() > 0)              /* Get window size */
  12536.           if (tt_cols > 0 && tt_rows > 0) /* sets tt_rows, tt_cols */
  12537.             sprintf(vvbuf,"%d",         /* SAFE */
  12538.                     (cx == VN_ROWS) ? tt_rows : tt_cols);
  12539. #endif /* OS2 */
  12540. #endif /* CK_TTGWSIZ */
  12541.         return(vvbuf);
  12542.  
  12543.       case VN_TTYP:
  12544. #ifdef NOTERM
  12545.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  12546. #else
  12547. #ifdef OS2
  12548.         sprintf(vvbuf, "%s",            /* SAFE */
  12549.                 (tt_type >= 0 && tt_type <= max_tt) ?
  12550.                 tt_info[tt_type].x_name :
  12551.                 "unknown"
  12552.                 );
  12553. #else
  12554. #ifdef MAC
  12555.         ckstrncpy(vvbuf,"vt320",VVBUFL);
  12556. #else
  12557.         p = getenv("TERM");
  12558.         ckstrncpy(vvbuf,p ? p : "unknown",VVBUFL+1);
  12559. #endif /* MAC */
  12560. #endif /* OS2 */
  12561. #endif /* NOTERM */
  12562.         return(vvbuf);
  12563.  
  12564.       case VN_MINP:                     /* MINPUT */
  12565.         sprintf(vvbuf, "%d", m_found);  /* SAFE */
  12566.         return(vvbuf);
  12567.     } /* Break up long switch statements... */
  12568.  
  12569.     switch(y) {
  12570.       case VN_CONN:                     /* CONNECTION */
  12571.         if (!local) {
  12572.           ckstrncpy(vvbuf,"remote",VVBUFL);
  12573.         } else {
  12574.             if (!network)
  12575.               ckstrncpy(vvbuf,"serial",VVBUFL);
  12576. #ifdef TCPSOCKET
  12577.             else if (nettype == NET_TCPB || nettype == NET_TCPA) {
  12578.                 if (ttnproto == NP_TELNET)
  12579.                   ckstrncpy(vvbuf,"tcp/ip_telnet",VVBUFL);
  12580. #ifdef CK_SSL
  12581.                 else if (ttnproto == NP_SSL || ttnproto == NP_SSL_RAW)
  12582.                   ckstrncpy(vvbuf,"tcp/ip_ssl",VVBUFL);
  12583.                 else if (ttnproto == NP_TLS || ttnproto == NP_SSL_RAW)
  12584.                   ckstrncpy(vvbuf,"tcp/ip_tls",VVBUFL);
  12585. #endif /* CK_SSL */
  12586.                 else
  12587.                   ckstrncpy(vvbuf,"tcp/ip",VVBUFL);
  12588.             }
  12589. #endif /* TCPSOCKET */
  12590. #ifdef SSHBUILTIN
  12591.             else if (nettype == NET_SSH)
  12592.                   ckstrncpy(vvbuf,"tcp/ip_ssh",VVBUFL);
  12593. #endif /* SSHBUILTIN */
  12594. #ifdef ANYX25
  12595.             else if (nettype == NET_SX25 ||
  12596.                      nettype == NET_VX25 ||
  12597.                      nettype == NET_IX25
  12598.                      )
  12599.               ckstrncpy(vvbuf,"x.25",VVBUFL);
  12600. #endif /* ANYX25 */
  12601. #ifdef DECNET
  12602.             else if (nettype == NET_DEC) {
  12603.                 if (ttnproto == NP_LAT)
  12604.                   ckstrncpy(vvbuf,"decnet_lat",VVBUFL);
  12605.                 else if ( ttnproto == NP_CTERM )
  12606.                   ckstrncpy(vvbuf,"decnet_cterm",VVBUFL);
  12607.                 else
  12608.                   ckstrncpy(vvbuf,"decnet",VVBUFL);
  12609.             }
  12610. #endif /* DECNET */
  12611. #ifdef SUPERLAT
  12612.             else if (nettype == NET_SLAT)
  12613.               ckstrncpy(vvbuf,"superlat",VVBUFL);
  12614. #endif /* SUPERLAT */
  12615. #ifdef NETFILE
  12616.             else if (nettype == NET_FILE)
  12617.               ckstrncpy(vvbuf,"local_file",VVBUFL);
  12618. #endif /* NETFILE */
  12619. #ifdef NETCMD
  12620.             else if (nettype == NET_CMD)
  12621.               ckstrncpy(vvbuf,"pipe",VVBUFL);
  12622. #endif /* NETCMD */
  12623. #ifdef NETPTY
  12624.             else if (nettype == NET_PTY)
  12625.               ckstrncpy(vvbuf,"pseudoterminal",VVBUFL);
  12626. #endif /* NETPTY */
  12627. #ifdef NETDLL
  12628.             else if (nettype == NET_DLL)
  12629.               ckstrncpy(vvbuf,"dynamic_link_library",VVBUFL);
  12630. #endif /* NETDLL */
  12631.  
  12632. #ifdef NPIPE
  12633.             else if (nettype == NET_PIPE)
  12634.               ckstrncpy(vvbuf,"named_pipe",VVBUFL);
  12635. #endif /* NPIPE */
  12636. #ifdef CK_NETBIOS
  12637.             else if (nettype == NET_BIOS)
  12638.               ckstrncpy(vvbuf,"netbios",VVBUFL);
  12639. #endif /* CK_NETBIOS */
  12640.             else
  12641.               ckstrncpy(vvbuf,"unknown",VVBUFL);
  12642.         }
  12643.         return(vvbuf);
  12644.  
  12645. #ifndef NOXFER
  12646.       case VN_SYSI:                     /* System ID, Kermit code */
  12647.         return((char *)cksysid);
  12648. #endif /* NOXFER */
  12649.  
  12650. #ifdef OS2
  12651.       case VN_SPA: {
  12652.           unsigned long space = zdskspace(0);
  12653.           if (space > 0 && space < 1024)
  12654.             sprintf(vvbuf,"-1");
  12655.           else
  12656.             sprintf(vvbuf,"%lu",space); /* SAFE */
  12657.           return(vvbuf);
  12658.       }
  12659. #endif /* OS2 */
  12660.  
  12661. #ifndef NOXFER
  12662.       case VN_QUE: {
  12663.           extern char querybuf[];
  12664.           return(querybuf);
  12665.       }
  12666. #endif /* NOXFER */
  12667.  
  12668. #ifndef NOCSETS
  12669.       case VN_CSET:
  12670. #ifdef OS2
  12671.         sprintf(vvbuf,"cp%d",os2getcp()); /* SAFE */
  12672. #else
  12673.         ckstrncpy(vvbuf,fcsinfo[fcharset].keyword,VVBUFL+1);
  12674. #endif /* OS2 */
  12675.         return(vvbuf);
  12676. #endif /* NOCSETS */
  12677.  
  12678. #ifdef OS2
  12679.       case VN_EXEDIR:
  12680.         return(exedir);
  12681.       case VN_STAR:
  12682.         return(startupdir);
  12683. #else
  12684.       case VN_EXEDIR:
  12685.         return(exedir ? exedir : "");
  12686. #ifdef VMSORUNIX
  12687.       case VN_STAR:
  12688.         return(startupdir);
  12689. #endif /* VMSORUNIX */
  12690. #endif /* OS2 */
  12691.  
  12692.       case VN_INI:
  12693.         return(inidir);
  12694.  
  12695.       case VN_MDM:
  12696.         return(gmdmtyp());
  12697.  
  12698.       case VN_EVAL:
  12699.         return(evalbuf);
  12700.  
  12701. #ifndef NODIAL
  12702.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  12703.         return(diallcc ? diallcc : "");
  12704.  
  12705.       case VN_D_AC:                     /* DIAL AREA-CODE */
  12706.         return(diallac ? diallac : "");
  12707.  
  12708.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  12709.         return(dialixp ? dialixp : "");
  12710.  
  12711.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  12712.         return(dialldp ? dialldp : "");
  12713.  
  12714.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  12715.         return(diallcp ? diallcp : "");
  12716.  
  12717.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE that matched */
  12718.         return(matchpxx ? matchpxx : "");
  12719. #else
  12720.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  12721.       case VN_D_AC:                     /* DIAL AREA-CODE */
  12722.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  12723.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  12724.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  12725.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE */
  12726.         return("");
  12727. #endif /* NODIAL */
  12728.       case VN_UID:
  12729. #ifdef UNIX
  12730.         {
  12731. #ifdef IKSD
  12732.             if (inserver)
  12733.               return((char *)uidbuf);
  12734.             else
  12735. #endif /* IKSD */
  12736.               if (uidbuf[0])
  12737.                 return((char *)uidbuf);
  12738.               else
  12739.                 return(whoami());
  12740.         }
  12741. #else
  12742.         return((char *)uidbuf);
  12743. #endif /* UNIX */
  12744.     } /* Break up long switch statements... */
  12745.  
  12746.     switch(y) {
  12747.       case VN_PWD:
  12748. #ifdef OS2
  12749.         if (activecmd == XXOUT || activecmd == XXLNOUT) {
  12750.             ckstrncpy(vvbuf,pwbuf,VVBUFL);
  12751.             ck_encrypt((char *)vvbuf);
  12752.             return((char *)vvbuf);
  12753.         } else
  12754. #endif /* OS2 */
  12755.           return((char *)pwbuf);
  12756.  
  12757.       case VN_PRM:
  12758.         return((char *)prmbuf);
  12759.  
  12760.       case VN_PROTO:
  12761. #ifdef NOXFER
  12762.         return("none");
  12763. #else
  12764. #ifdef CK_XYZ
  12765.         return(ptab[protocol].p_name);
  12766. #else
  12767.         return("kermit");
  12768. #endif /* CK_XYZ */
  12769. #endif /* NOXFER */
  12770.  
  12771. #ifndef NOXFER
  12772. #ifdef CK_TMPDIR
  12773.       case VN_DLDIR:
  12774.         return(dldir ? dldir : "");
  12775. #endif /* CK_TMPDIR */
  12776. #endif /* NOXFER */
  12777.  
  12778. #ifndef NODIAL
  12779.       case VN_M_INI:                    /* Modem init string */
  12780.         return(dialini ? dialini : (m ? m->wake_str : ""));
  12781.  
  12782.       case VN_M_DCM:                    /* Modem dial command */
  12783.         return(dialcmd ? dialcmd : (m ? m->dial_str : ""));
  12784.  
  12785.       case VN_M_DCO:                    /* Modem data compression on */
  12786.         return(dialdcon ? dialdcon : (m ? m->dc_on_str : ""));
  12787.  
  12788.       case VN_M_DCX:                    /* Modem data compression off */
  12789.         return(dialdcoff ? dialdcoff : (m ? m->dc_off_str : ""));
  12790.  
  12791.       case VN_M_ECO:                    /* Modem error correction on */
  12792.         return(dialecon ? dialecon : (m ? m->ec_on_str : ""));
  12793.  
  12794.       case VN_M_ECX:                    /* Modem error correction off */
  12795.         return(dialecoff ? dialecoff : (m ? m->ec_off_str : ""));
  12796.  
  12797.       case VN_M_AAO:                    /* Modem autoanswer on */
  12798.         return(dialaaon ? dialaaon : (m ? m->aa_on_str : ""));
  12799.  
  12800.       case VN_M_AAX:                    /* Modem autoanswer off */
  12801.         return(dialaaoff ? dialaaoff : (m ? m->aa_off_str : ""));
  12802.  
  12803.       case VN_M_HUP:                    /* Modem hangup command */
  12804.         return(dialhcmd ? dialhcmd : (m ? m->hup_str : ""));
  12805.  
  12806.       case VN_M_HWF:                    /* Modem hardware flow command */
  12807.         return(dialhwfc ? dialhwfc : (m ? m->hwfc_str : ""));
  12808.  
  12809.       case VN_M_SWF:                    /* Modem software flow command */
  12810.         return(dialswfc ? dialswfc : (m ? m->swfc_str : ""));
  12811.  
  12812.       case VN_M_NFC:                    /* Modem no flow-control command */
  12813.         return(dialnofc ? dialnofc : (m ? m->nofc_str : ""));
  12814.  
  12815.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  12816.         return(dialpulse ? dialpulse : (m ? m->pulse : ""));
  12817.  
  12818.       case VN_M_TDM:                    /* Modem tone dialing mode */
  12819.         return(dialtone ? dialtone : (m ? m->tone : ""));
  12820.  
  12821.       case VN_M_NAM:                    /* Modem full name */
  12822.         return(dialname ? dialname : (m ? m->name : ""));
  12823. #else
  12824.       case VN_M_INI:                    /* Modem init string */
  12825.       case VN_M_DCM:                    /* Modem dial command */
  12826.       case VN_M_DCO:                    /* Modem data compression on */
  12827.       case VN_M_DCX:                    /* Modem data compression off */
  12828.       case VN_M_ECO:                    /* Modem error correction on */
  12829.       case VN_M_ECX:                    /* Modem error correction off */
  12830.       case VN_M_AAO:                    /* Modem autoanswer on */
  12831.       case VN_M_AAX:                    /* Modem autoanswer off */
  12832.       case VN_M_HUP:                    /* Modem hangup command */
  12833.       case VN_M_HWF:                    /* Modem hardware flow command */
  12834.       case VN_M_SWF:                    /* Modem software flow command */
  12835.       case VN_M_NFC:                    /* Modem no flow-control command */
  12836.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  12837.       case VN_M_TDM:                    /* Modem tone dialing mode */
  12838.       case VN_M_NAM:
  12839.         return("");
  12840. #endif /* NODIAL */
  12841.  
  12842.       case VN_ISTAT:                    /* INPUT status */
  12843.         sprintf(vvbuf, "%d", instatus); /* SAFE */
  12844.         return(vvbuf);
  12845.  
  12846.       case VN_TEMP:                     /* Temporary directory */
  12847.         if (tempdir) {
  12848.             p = tempdir;
  12849.         } else {
  12850. #ifdef OS2
  12851. #ifdef NT
  12852.             p = getenv("K95TMP");
  12853. #else
  12854.             p = getenv("K2TMP");
  12855. #endif /* NT */
  12856.             if ( !p )
  12857. #endif /* OS2 */
  12858.               p = getenv("CK_TMP");
  12859.             if (!p) p = getenv("TMPDIR");
  12860.             if (!p) p = getenv("TEMP");
  12861.             if (!p) p = getenv("TMP");
  12862.  
  12863. #ifdef OS2ORUNIX
  12864.             if (p) {
  12865.                 int len = strlen(p);
  12866.                 if (p[len-1] != '/'
  12867. #ifdef OS2
  12868.                     && p[len-1] != '\\'
  12869. #endif /* OS2 */
  12870.                      ) {
  12871.                     static char foo[CKMAXPATH];
  12872.                     ckstrncpy(foo,p,CKMAXPATH);
  12873.                     ckstrncat(foo,"/",CKMAXPATH);
  12874.                     p = foo;
  12875.                 }
  12876.             } else
  12877. #else /* OS2ORUNIX */
  12878.             if (!p)
  12879. #endif /* OS2ORUNIX */
  12880. #ifdef UNIX                             /* Systems that have a standard */
  12881.               p = "/tmp/";              /* temporary directory... */
  12882. #else
  12883. #ifdef datageneral
  12884.               p = ":TMP:";
  12885. #else
  12886.               p = "";
  12887. #endif /* datageneral */
  12888. #endif /* UNIX */
  12889.         }
  12890.         ckstrncpy(vvbuf,p,VVBUFL);
  12891.         p = vvbuf;
  12892.  
  12893. /* This needs generalizing for VOS, AOS/VS, etc... */
  12894.  
  12895.         while (*p) {
  12896. #ifdef OS2
  12897.             if (*p == '\\') *p = '/';
  12898. #endif /* OS2 */
  12899.             p++;
  12900.         }
  12901. #ifndef VMS
  12902.         if (p > vvbuf) {
  12903.             char c =                    /* Directory termination character */
  12904. #ifdef MAC
  12905.               ':'
  12906. #else
  12907. #ifdef datageneral
  12908.               ':'
  12909. #else
  12910. #ifdef STRATUS
  12911.               '>'
  12912. #else
  12913.               '/'
  12914. #endif /* STRATUS */
  12915. #endif /* datageneral */
  12916. #endif /* MAC */
  12917.                 ;
  12918.  
  12919.             if (*(p-1) != c) {
  12920.                 *p++ = c;
  12921.                 *p = NUL;
  12922.             }
  12923.         }
  12924. #endif /* VMS */
  12925.         return(vvbuf);
  12926.     } /* Break up long switch statements... */
  12927.  
  12928.     switch(y) {
  12929.       case VN_ERRNO:                    /* Error number */
  12930. #ifdef VMS
  12931.         {
  12932.             extern int vms_lasterr;
  12933.             sprintf(vvbuf, "%d", vms_lasterr); /* SAFE */
  12934.         }
  12935. #else
  12936.         sprintf(vvbuf, "%d", errno);    /* SAFE */
  12937. #endif /* VMS */
  12938.         return(vvbuf);
  12939.  
  12940.       case VN_ERSTR:                    /* Error string */
  12941.         ckstrncpy(vvbuf,ck_errstr(),VVBUFL);
  12942.         return(vvbuf);
  12943.  
  12944. #ifndef NOXFER
  12945.       case VN_RPSIZ:                    /* RECEIVE packet-length */
  12946.         sprintf(vvbuf,"%d",urpsiz);     /* SAFE */
  12947.         return(vvbuf);
  12948.  
  12949.       case VN_WINDO:                    /* WINDOW slots */
  12950.         sprintf(vvbuf,"%d",wslotr);     /* SAFE */
  12951.         return(vvbuf);
  12952. #endif /* NOXFER */
  12953.  
  12954.       case VN_TFLN:                     /* TAKE-file line number */
  12955.         if (tlevel > -1) {
  12956.             sprintf(vvbuf, "%d", tfline[tlevel]); /* SAFE */
  12957.             return(vvbuf);
  12958.         } else
  12959.           return("0");
  12960.  
  12961.       case VN_MDMSG:                    /* DIALRESULT */
  12962. #ifndef NODIAL
  12963.         return((char *)modemmsg);
  12964. #else
  12965.         return("");
  12966. #endif /* NODIAL */
  12967.  
  12968.       case VN_DNUM:                     /* DIALNUMBER */
  12969. #ifndef NODIAL
  12970.         return(dialnum ? (char *) dialnum : "");
  12971. #else
  12972.         return("");
  12973. #endif /* NODIAL */
  12974.  
  12975.       case VN_APC:
  12976.         sprintf(vvbuf, "%d",            /* SAFE */
  12977. #ifdef CK_APC
  12978.                 apcactive
  12979. #else
  12980.                 0
  12981. #endif /* CK_APC */
  12982.                 );
  12983.         return((char *)vvbuf);
  12984.  
  12985. #ifdef OS2
  12986. #ifndef NOKVERBS
  12987.       case VN_TRMK:
  12988.           sprintf(vvbuf, "%d", keymac); /* SAFE */
  12989.         return((char *)vvbuf);
  12990. #endif /* NOKVERBS */
  12991. #endif /* OS2 */
  12992.  
  12993.       case VN_IPADDR:
  12994. #ifdef TCPSOCKET
  12995. #ifndef OSK
  12996.       /* This dumps core on OS-9 for some reason, but only if executed */
  12997.       /* before we have made a TCP connection.  This is obviously not */
  12998.       /* the ideal fix. */
  12999.         if (!myipaddr[0])
  13000.           getlocalipaddr();
  13001. #endif /* OSK */
  13002. #endif /* TCPSOCKET */
  13003.         ckstrncpy(vvbuf,
  13004. #ifdef TCPSOCKET
  13005.                 (char *)myipaddr,
  13006. #else
  13007.                 "",
  13008. #endif /* TCPSOCKET */
  13009.                 VVBUFL);
  13010.         return((char *)vvbuf);
  13011.  
  13012. #ifndef NOXFER
  13013.       case VN_CRC16:                    /* CRC-16 of most recent transfer */
  13014.         sprintf(vvbuf,"%d",crc16);      /* SAFE */
  13015.         return(vvbuf);
  13016. #endif /* NOXFER */
  13017.  
  13018. #ifdef CK_PID
  13019.       case VN_PID:
  13020. #ifdef IKSD
  13021. #ifdef CK_LOGIN
  13022.         if (inserver && isguest)
  13023.           return("");
  13024. #endif /* CK_LOGIN */
  13025. #endif /* IKSD */
  13026.         return(ckgetpid());
  13027. #endif /* CK_PID */
  13028.  
  13029. #ifndef NOXFER
  13030.       case VN_FNAM: {                   /* \v(filename) */
  13031.           extern char filnam[], ofn1[], *sfspec, *rrfspec;
  13032.           char * tmp;
  13033.           switch (what) {               /* File transfer is in progress */
  13034. #ifdef NEWFTP
  13035.             case (W_FTP|W_RECV):
  13036.             case (W_FTP|W_SEND):
  13037.               return((char *)filnam);
  13038. #endif /* NEWFTP */
  13039.             case W_RECV:
  13040.             case W_REMO:
  13041.               return((char *)ofn1);
  13042.             default:                    /* Most recent file transferred */
  13043.               if (filnam[0]) {          /* (if any) */
  13044.                   return((char *)filnam);
  13045.               } else if (lastxfer & W_SEND && sfspec) {
  13046.                   if (fnspath == PATH_OFF)
  13047.                     zstrip(sfspec,&tmp);
  13048.                   else
  13049.                     tmp = sfspec;
  13050.                   return(tmp);
  13051.               } else if (lastxfer & W_RECV && rrfspec) {
  13052.                   if (fnrpath == PATH_OFF)
  13053.                     zstrip(rrfspec,&tmp);
  13054.                   else
  13055.                     tmp = rrfspec;
  13056.                   return(tmp);
  13057.               } else
  13058.                 return("");
  13059.           }
  13060.       }
  13061.       case VN_FNUM:                     /* \v(filenum) */
  13062.         sprintf(vvbuf,"%ld",filcnt);    /* SAFE */
  13063.         return((char *)vvbuf);
  13064. #endif /* NOXFER */
  13065.  
  13066. #ifdef PEXITSTAT
  13067.       case VN_PEXIT: {
  13068.           extern int pexitstat;
  13069.           sprintf(vvbuf,"%d",pexitstat); /* SAFE */
  13070.           return((char *)vvbuf);
  13071.       }
  13072. #endif /* PEXITSTAT */
  13073.  
  13074. #ifndef NOXFER
  13075.       case VN_P_8BIT:
  13076.         vvbuf[0] = parity ? ebq : NUL;
  13077.         vvbuf[1] = NUL;
  13078.         return((char *)vvbuf);
  13079.  
  13080.       case VN_P_CTL: {
  13081.           extern CHAR myctlq;
  13082.           vvbuf[0] = myctlq;
  13083.           vvbuf[1] = NUL;
  13084.           return((char *)vvbuf);
  13085.       }
  13086.       case VN_P_RPT: {
  13087.           extern int rptena;
  13088.           vvbuf[0] = rptena ? rptq : NUL;
  13089.           vvbuf[1] = NUL;
  13090.           return((char *)vvbuf);
  13091.       }
  13092. #endif /* NOXFER */
  13093.  
  13094. #ifdef OS2
  13095.       case VN_REGN:
  13096.         return(get_reg_name());
  13097.       case VN_REGO:
  13098.         return(get_reg_corp());
  13099.       case VN_REGS:
  13100.         return(get_reg_sn());
  13101. #endif /* OS2 */
  13102.     } /* Break up long switch statements... */
  13103.  
  13104.     switch(y) {
  13105.       case VN_XPROG:
  13106. #ifdef OS2
  13107. #ifdef NT
  13108. #ifdef KUI
  13109.         return("K-95G");
  13110. #else
  13111.         return("K-95");
  13112. #endif /* KUI */
  13113. #else
  13114.         return("K/2");
  13115. #endif /* NT */
  13116. #else
  13117.         return("C-Kermit");
  13118. #endif /* OS2 */
  13119.  
  13120.       case VN_EDITOR:
  13121. #ifdef NOFRILLS
  13122.         return("");
  13123. #else
  13124. #ifdef NOPUSH
  13125.         return("");
  13126. #else
  13127.         {
  13128.             extern char editor[];
  13129.             char *ss;
  13130.             if (!editor[0]) {
  13131.                 ss = getenv("EDITOR");
  13132.                 if (ss) {
  13133.                     ckstrncpy(editor,ss,CKMAXPATH);
  13134.                 }
  13135.             }
  13136.             debug(F110,"\\v(editor)",editor,0);
  13137.             return(editor[0] ? (char *)editor : "");
  13138.         }
  13139. #endif /* NOPUSH */
  13140. #endif /* NOFRILLS */
  13141.  
  13142.       case VN_EDOPT:
  13143. #ifdef NOFRILLS
  13144.         return("");
  13145. #else
  13146. #ifdef NOPUSH
  13147.         return("");
  13148. #else
  13149.         {
  13150.             extern char editopts[];
  13151.             return(editopts[0] ? (char *)editopts : "");
  13152.         }
  13153. #endif /* NOPUSH */
  13154. #endif /* NOFRILLS */
  13155.  
  13156.       case VN_EDFILE:
  13157. #ifdef NOFRILLS
  13158.         return("");
  13159. #else
  13160. #ifdef NOPUSH
  13161.         return("");
  13162. #else
  13163.         {
  13164.             extern char editfile[];
  13165.             return(editfile[0] ? (char *)editfile : "");
  13166.         }
  13167. #endif /* NOPUSH */
  13168. #endif /* NOFRILLS */
  13169.  
  13170. #ifdef BROWSER
  13171.       case VN_BROWSR: {
  13172.           extern char browser[];
  13173.           if (!browser[0]) {
  13174.               s = getenv("BROWSER");
  13175.               if (s) ckstrncpy(browser,s,CKMAXPATH);
  13176.           }
  13177.           return(browser[0] ? (char *)browser : "");
  13178.       }
  13179.       case VN_BROPT: {
  13180.           extern char browsopts[];
  13181.           return(browsopts[0] ? (char *)browsopts : "");
  13182.       }
  13183.       case VN_URL: {
  13184.           extern char browsurl[];
  13185.           return(browsurl[0] ? (char *)browsurl : "");
  13186.       }
  13187. #endif /* BROWSER */
  13188.       case VN_HERALD:
  13189.         return((char *)versio);
  13190.  
  13191.       case VN_TEST: {                   /* test */
  13192.           extern char * ck_s_test, * ck_s_tver;
  13193.           if (!ck_s_test) ck_s_test = "";
  13194.           if (!ck_s_tver) ck_s_tver = "";
  13195.           if (*ck_s_test) {
  13196.               ckstrncpy(vvbuf,ck_s_test,VVBUFL);
  13197.               if (*ck_s_tver) {
  13198.                   ckstrncat(vvbuf,".",VVBUFL);
  13199.                   ckstrncat(vvbuf,ck_s_tver,VVBUFL);
  13200.               }
  13201.           } else
  13202.             ckstrncpy(vvbuf,"0",VVBUFL);
  13203.           return((char *)vvbuf);
  13204.       }
  13205.  
  13206. #ifndef NOXFER
  13207.       case VN_XFSTAT:                   /* xferstatus */
  13208.         x = xferstat;                   /* Like success */
  13209.         if (x > -1) x = (x == 0) ? 1 : 0; /* External value is reversed */
  13210.         sprintf(vvbuf,"%d",x);          /* SAFE */
  13211.         return((char *)vvbuf);
  13212.  
  13213.       case VN_XFMSG:                    /* xfermsg */
  13214.         return((char *)epktmsg);
  13215.  
  13216. #ifndef NOMSEND
  13217.       case VN_SNDL: {                   /* sendlist */
  13218.           extern int filesinlist;
  13219.           sprintf(vvbuf,"%d",filesinlist); /* SAFE */
  13220.           return((char *)vvbuf);
  13221.       }
  13222. #endif /* NOMSEND */
  13223. #endif /* NOXFER */
  13224.  
  13225. #ifdef CK_TRIGGER
  13226.       case VN_TRIG: {
  13227.           extern char * triggerval;
  13228.           return(triggerval ? triggerval : "");
  13229.       }
  13230. #endif /* CK_TRIGGER */
  13231. #ifdef OS2MOUSE
  13232. #ifdef OS2
  13233.       case VN_MOU_X: {
  13234.           extern int MouseCurX;
  13235.           sprintf(vvbuf,"%d",MouseCurX); /* SAFE */
  13236.           return((char *)vvbuf);
  13237.       }
  13238.       case VN_MOU_Y: {
  13239.           extern int MouseCurY;
  13240.           sprintf(vvbuf,"%d",MouseCurY); /* SAFE */
  13241.           return((char *)vvbuf);
  13242.       }
  13243. #endif /* OS2 */
  13244. #endif /* OS2MOUSE */
  13245.       case VN_PRINT: {
  13246.           extern int printpipe;
  13247.           extern char * printername;
  13248. #ifdef PRINTSWI
  13249.           extern int noprinter;
  13250.           if (noprinter) return("");
  13251. #endif /* PRINTSWI */
  13252.           ckmakmsg(vvbuf,VVBUFL,
  13253.                    printpipe ? "|" : "",
  13254.                    printername ? printername :
  13255. #ifdef OS2
  13256.                    "PRN",
  13257. #else
  13258.                    "(default)",
  13259. #endif /* OS2 */
  13260.                    NULL,
  13261.                    NULL
  13262.                    );
  13263.           return((char *)vvbuf);
  13264.       }
  13265.     } /* Break up long switch statements... */
  13266.  
  13267.     switch(y) {
  13268.       case VN_ESC:                      /* Escape character */
  13269.         sprintf(vvbuf,"%d",escape);     /* SAFE */
  13270.         return((char *)vvbuf);
  13271.  
  13272.       case VN_INTIME:
  13273.         sprintf(vvbuf,"%ld",inetime);   /* SAFE */
  13274.         return((char *)vvbuf);
  13275.  
  13276.       case VN_INTMO:
  13277.         sprintf(vvbuf,"%d",inwait);     /* SAFE */
  13278.         return((char *)vvbuf);
  13279.  
  13280.       case VN_SECURE:
  13281.         if (0
  13282. #ifdef SSHBUILTIN
  13283.             || IS_SSH()
  13284. #endif /* SSHBUILTIN */
  13285. #ifdef CK_ENCRYPTION
  13286.             || ck_tn_encrypting() && ck_tn_decrypting()
  13287. #endif /* CK_ENCRYPTION */
  13288. #ifdef CK_SSL
  13289.             || tls_active_flag || ssl_active_flag
  13290. #endif /* CK_SSL */
  13291.             )
  13292.           return("1");
  13293.         else
  13294.           return("0");
  13295.  
  13296.       case VN_AUTHN:
  13297. #ifdef CK_AUTHENTICATION
  13298.         {
  13299.             extern char szUserNameAuthenticated[];
  13300.             return((char *)szUserNameAuthenticated);
  13301.         }
  13302. #else /* CK_AUTHENTICATION */
  13303.         return((char *)"");
  13304. #endif /* CK_AUTHENTICATION */
  13305.  
  13306.       case VN_AUTHS:
  13307. #ifdef CK_AUTHENTICATION
  13308.         switch (ck_tn_auth_valid()) {
  13309.           case AUTH_UNKNOWN:
  13310.             return((char *)"unknown");
  13311.           case AUTH_OTHER:
  13312.             return((char *)"other");
  13313.           case AUTH_USER:
  13314.             return((char *)"user");
  13315.           case AUTH_VALID:
  13316.             return((char *)"valid");
  13317.           case AUTH_REJECT:
  13318.           default:
  13319.             return((char *)"rejected");
  13320.         }
  13321. #else /* CK_AUTHENTICATION */
  13322.         return((char *)"rejected");
  13323. #endif /* CK_AUTHENTICATION */
  13324.  
  13325.       case VN_AUTHT:
  13326. #ifdef CK_AUTHENTICATION
  13327. #ifdef CK_SSL
  13328.         if ((ssl_active_flag || tls_active_flag) &&
  13329.             ck_tn_auth_valid() == AUTH_VALID &&
  13330.             (sstelnet ? (!TELOPT_U(TELOPT_AUTHENTICATION)) :
  13331.                         (!TELOPT_ME(TELOPT_AUTHENTICATION))) ||
  13332.              ck_tn_authenticated() == AUTHTYPE_NULL ||
  13333.              ck_tn_authenticated() == AUTHTYPE_AUTO)
  13334.           return("X_509_CERTIFICATE");
  13335.         else
  13336. #endif /* CK_SSL */
  13337.           return(AUTHTYPE_NAME(ck_tn_authenticated()));
  13338. #else /* CK_AUTHENTICATION */
  13339.         return((char *)"NULL");
  13340. #endif /* CK_AUTHENTICATION */
  13341.  
  13342. #ifdef CK_KERBEROS
  13343.       case VN_K4PRN: {
  13344.           extern char * krb4_d_principal;
  13345.           if (krb4_d_principal)
  13346.             ckstrncpy(vvbuf,krb4_d_principal,VVBUFL+1);
  13347.           else
  13348.             *vvbuf = NUL;
  13349.           return((char *)vvbuf);
  13350.       }
  13351.       case VN_K5PRN: {
  13352.           extern char * krb5_d_principal;
  13353.           if (krb5_d_principal)
  13354.             ckstrncpy(vvbuf,krb5_d_principal,VVBUFL+1);
  13355.           else
  13356.             *vvbuf = NUL;
  13357.           return((char *)vvbuf);
  13358.       }
  13359.       case VN_K4RLM: {
  13360.           extern char * krb4_d_realm;
  13361.           if (krb4_d_realm) {
  13362.               ckstrncpy(vvbuf,krb4_d_realm,VVBUFL+1);
  13363.           } else {
  13364.               char * s = ck_krb4_getrealm();
  13365.               ckstrncpy(vvbuf,s ? s : "",VVBUFL+1);
  13366.           }
  13367.           return((char *)vvbuf);
  13368.       }
  13369.       case VN_K4SRV: {
  13370.           extern char * krb4_d_srv;
  13371.           if (krb4_d_srv)
  13372.             ckstrncpy(vvbuf,krb4_d_srv,VVBUFL+1);
  13373.           else
  13374.             ckstrncpy(vvbuf,"rcmd",VVBUFL);
  13375.           return((char *)vvbuf);
  13376.       }
  13377.       case VN_K5RLM: {
  13378.           extern char * krb5_d_realm;
  13379.           extern char * krb5_d_cc;
  13380.           if (krb5_d_realm) {
  13381.               ckstrncpy(vvbuf,krb5_d_realm,VVBUFL+1);
  13382.           } else {
  13383.               char * s = ck_krb5_getrealm(krb5_d_cc);
  13384.               ckstrncpy(vvbuf,s,VVBUFL+1);
  13385.           }
  13386.           return((char *)vvbuf);
  13387.       }
  13388.       case VN_K5CC: {
  13389.           extern char * krb5_d_cc;
  13390.           if (krb5_d_cc)
  13391.             ckstrncpy(vvbuf,krb5_d_cc,VVBUFL+1);
  13392.           else
  13393.             ckstrncpy(vvbuf,ck_krb5_get_cc_name(),VVBUFL+1);
  13394.           return((char *)vvbuf);
  13395.       }
  13396.       case VN_K5SRV: {
  13397.           extern char * krb5_d_srv;
  13398.           if (krb5_d_srv)
  13399.             ckstrncpy(vvbuf,krb5_d_srv,VVBUFL+1);
  13400.           else
  13401.             ckstrncpy(vvbuf,"host",VVBUFL);
  13402.           return((char *)vvbuf);
  13403.       }
  13404.       case VN_K4ENO: {
  13405.         extern char * krb4_errno;
  13406.         sprintf(vvbuf,"%d",krb4_errno); /* SAFE */
  13407.         return((char *)vvbuf);
  13408.       }
  13409.       case VN_K5ENO: {
  13410.         extern char * krb5_errno;
  13411.         sprintf(vvbuf,"%d",krb5_errno); /* SAFE */
  13412.         return((char *)vvbuf);
  13413.       }
  13414.       case VN_K4EMSG: {
  13415.         extern char * krb4_errmsg;
  13416.         ckstrncpy(vvbuf,krb4_errmsg?krb4_errmsg:"",VVBUFL+1);
  13417.         return((char *)vvbuf);
  13418.       }
  13419.       case VN_K5EMSG: {
  13420.         extern char * krb5_errmsg;
  13421.         ckstrncpy(vvbuf,krb5_errmsg,VVBUFL+1);
  13422.         return((char *)vvbuf);
  13423.       }
  13424. #endif /* CK_KERBEROS */
  13425. #ifdef CK_SSL
  13426.       case VN_X509_S:
  13427.         if (ssl_active_flag)
  13428.           ckstrncpy(vvbuf,ssl_get_subject_name(ssl_con),VVBUFL+1);
  13429.         else if (tls_active_flag)
  13430.           ckstrncpy(vvbuf,ssl_get_subject_name(tls_con),VVBUFL+1);
  13431.         else
  13432.           ckstrncpy(vvbuf,"",VVBUFL+1);
  13433.         return((char *)vvbuf);
  13434.       case VN_X509_I:
  13435.         if (ssl_active_flag)
  13436.           ckstrncpy(vvbuf,ssl_get_issuer_name(ssl_con),VVBUFL+1);
  13437.         else if (tls_active_flag)
  13438.           ckstrncpy(vvbuf,ssl_get_issuer_name(tls_con),VVBUFL+1);
  13439.         else
  13440.           ckstrncpy(vvbuf,"",VVBUFL+1);
  13441.         return((char *)vvbuf);
  13442. #endif /* CK_SSL */
  13443.  
  13444.       case VN_OSNAM:
  13445. #ifdef IKSD
  13446. #ifdef CK_LOGIN
  13447.         if (inserver && isguest)
  13448.           return("");
  13449. #endif /* CK_LOGIN */
  13450. #endif /* IKSD */
  13451. #ifdef CK_UTSNAME
  13452.         {
  13453.             extern char unm_nam[];
  13454.             return((char *)unm_nam);
  13455.         }
  13456. #else
  13457.         for (x = y = 0; x < VVBUFL; x++) {
  13458.             if (ckxsys[x] == SP && cx == 0) continue;
  13459.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  13460.         }
  13461.         vvbuf[y] = NUL;
  13462.         return(vvbuf);
  13463. #endif /* CK_UTSNAME */
  13464.  
  13465.       case VN_OSVER: {
  13466. #ifdef CK_UTSNAME
  13467.           extern char unm_ver[];
  13468. #ifdef IKSD
  13469. #ifdef CK_LOGIN
  13470.           if (inserver && isguest)
  13471.             return("");
  13472. #endif /* CK_LOGIN */
  13473. #endif /* IKSD */
  13474.           return((char *)unm_ver);
  13475. #else
  13476.           return("");
  13477. #endif /* CK_UTSNAME */
  13478.       }
  13479.  
  13480.       case VN_OSREL: {
  13481. #ifdef CK_UTSNAME
  13482.           extern char unm_rel[];
  13483. #ifdef IKSD
  13484. #ifdef CK_LOGIN
  13485.           if (inserver && isguest)
  13486.             return("");
  13487. #endif /* CK_LOGIN */
  13488. #endif /* IKSD */
  13489.           return((char *)unm_rel);
  13490. #else
  13491.           return("");
  13492. #endif /* CK_UTSNAME */
  13493.       }
  13494.     } /* Break up long switch statements... */
  13495.  
  13496.     switch(y) {
  13497.       case VN_NAME: {
  13498.           extern char * myname;
  13499.           return(myname);
  13500.       }
  13501.  
  13502.       case VN_MODL: {
  13503. #ifdef CK_UTSNAME
  13504.           extern char unm_mod[], unm_mch[];
  13505.           int y = VVBUFL - 1;
  13506.           char * s = unm_mod;
  13507. #endif /* CK_UTSNAME */
  13508. #ifdef IKSD
  13509. #ifdef CK_LOGIN
  13510.           if (inserver && isguest)
  13511.             return("");
  13512. #endif /* CK_LOGIN */
  13513. #endif /* IKSD */
  13514.  
  13515. #ifdef COMMENT                          /* was HPUX */
  13516.           if (!unm_mod[0] && !nopush)
  13517.             zzstring("\\fcommand(model)",&s,&y);
  13518. /*
  13519.    Another possibility would be:
  13520.      "\\fcommand(ksh -c 'whence model 1>&- && model || uname -m')"
  13521.    But that would depend on having ksh.
  13522. */
  13523. #else
  13524. #ifdef OSF32                            /* Digital UNIX 3.2 and higher... */
  13525. /* Note: Ultrix has /etc/sizer, but it is not publicly executable. */
  13526. /* sizer -c outputs 'cpu:<tab><tab>"DECxxxx"' */
  13527.           if (!unm_mod[0]) {
  13528.               char * p;
  13529.               int flag = 0;
  13530.               zzstring("\\fcommand(/usr/sbin/sizer -c)",&s,&y);
  13531.               debug(F110,"DU model",unm_mod,0);
  13532.               s = unm_mod;
  13533.               p = unm_mod;
  13534.               while (*p) {              /* Extract the part in quotes */
  13535.                   if (*p == '"') {
  13536.                       if (flag)
  13537.                         break;
  13538.                       flag = 1;
  13539.                       p++;
  13540.                       continue;
  13541.                   }
  13542.                   if (flag)
  13543.                     *s++ = *p;
  13544.                   p++;
  13545.               }
  13546.               *s = NUL;
  13547.           }
  13548. #endif /* OSF32 */
  13549. #endif /* COMMENT */
  13550.  
  13551. #ifdef CK_UTSNAME
  13552.           if (unm_mod[0])
  13553.             return((char *)unm_mod);
  13554.           else
  13555.             return((char *)unm_mch);
  13556. #else
  13557.           return("");
  13558. #endif /* CK_UTSNAME */
  13559.       }
  13560.  
  13561. #ifdef IBMX25
  13562.       /* X.25 variables (local and remote address) */
  13563.       case VN_X25LA:
  13564.         if (!local_nua[0] && !x25local_nua(local_nua))
  13565.           *vvbuf = NULL;
  13566.         else
  13567.           ckstrncpy(vvbuf,local_nua,VVBUFL+1);
  13568.         return((char *)vvbuf);
  13569.  
  13570.       case VN_X25RA:
  13571.         if (!remote_nua[0])
  13572.           *vvbuf = NULL;
  13573.         else
  13574.           ckstrncpy(vvbuf,remote_nua,VVBUFL+1);
  13575.         return((char *)vvbuf);
  13576. #endif /* IBMX25 */
  13577.  
  13578. #ifndef NODIAL
  13579.       case VN_PDSFX: {
  13580.           extern char pdsfx[];
  13581.           return((char *)pdsfx);
  13582.       }
  13583.       case VN_DTYPE: {
  13584.           extern int dialtype;
  13585.           sprintf(vvbuf,"%d",dialtype); /* SAFE */
  13586.           return((char *)vvbuf);
  13587.       }
  13588. #endif /* NODIAL */
  13589.  
  13590. #ifdef UNIX
  13591.       case VN_LCKPID: {
  13592.           extern char lockpid[];
  13593.           return((char *)lockpid);
  13594.       }
  13595. #endif /* UNIX */
  13596.  
  13597. #ifndef NOXFER
  13598.       case VN_BLK:
  13599.         sprintf(vvbuf,"%d",bctr);       /* SAFE */
  13600.         return((char *)vvbuf);
  13601.  
  13602.       case VN_TFTIM:
  13603.         sprintf(vvbuf,                  /* SAFE */
  13604. #ifdef GFTIMER
  13605.                 "%ld", (long)(fptsecs + 0.5)
  13606. #else
  13607.                 "%d", tsecs
  13608. #endif /* GFTIMER */
  13609.                 );
  13610.         return((char *)vvbuf);
  13611. #endif /* NOXFER */
  13612.  
  13613.       case VN_HWPAR:
  13614.       case VN_SERIAL: {
  13615.           int sb;
  13616.           char c, * ss;
  13617.           extern int stopbits;
  13618.           vvbuf[0] = NUL;
  13619.           if (hwparity && local && !network)
  13620.             ss = parnam((char)hwparity);
  13621.           else
  13622.             ss = parnam((char)parity);
  13623.           if (cx == VN_HWPAR) {
  13624.               ckstrncpy(vvbuf,ss,VVBUFL);
  13625.               return((char *)vvbuf);
  13626.           }
  13627.           c = ss[0];
  13628.           if (islower(c)) c = toupper(c);
  13629.           sb = stopbits;
  13630.           if (sb < 1)
  13631.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  13632.           if (hwparity)
  13633.             sprintf(vvbuf," 8%c%d",c,sb); /* SAFE */
  13634.           else if (parity)
  13635.             sprintf(vvbuf," 7%c%d",c,sb); /* SAFE */
  13636.           else
  13637.             sprintf(vvbuf," 8N%d",sb);  /* SAFE */
  13638.           return((char *)vvbuf);
  13639.       }
  13640.  
  13641. #ifdef UNIX
  13642.       case VN_LCKDIR: {
  13643. #ifndef NOUUCP
  13644.           extern char * uucplockdir;
  13645.           ckstrncpy(vvbuf,uucplockdir,VVBUFL);
  13646.           x = strlen(vvbuf);
  13647.           if (x > 0) {
  13648.               if (vvbuf[x-1] != '/') {
  13649.                   vvbuf[x] = '/';
  13650.                   vvbuf[x+1] = NUL;
  13651.               }
  13652.           }
  13653. #else
  13654.           vvbuf[0] = NUL;
  13655. #endif /* NOUUCP */
  13656.           return((char *)vvbuf);
  13657.       }
  13658. #endif /* UNIX */
  13659.     } /* Break up long switch statements... */
  13660.  
  13661.     switch(y) {
  13662. #ifndef NODIAL
  13663.       case VN_DM_LP:
  13664.       case VN_DM_SP:
  13665.       case VN_DM_PD:
  13666.       case VN_DM_TD:
  13667.       case VN_DM_WA:
  13668.       case VN_DM_WD:
  13669.       case VN_DM_HF:
  13670.       case VN_DM_WB:
  13671.       case VN_DM_RC: {
  13672.           extern char * getdm();
  13673.           ckstrncpy(vvbuf,getdm(y),VVBUFL);
  13674.           return((char *)vvbuf);
  13675.       }
  13676. #endif /* NODIAL */
  13677.  
  13678.       case VN_TY_LN:
  13679.       case VN_TY_LC: {
  13680.           extern int typ_lines;
  13681.           sprintf(vvbuf,"%d",typ_lines); /* SAFE */
  13682.           return((char *)vvbuf);
  13683.       }
  13684.       case VN_TY_LM: {
  13685.           extern int typ_mtchs;
  13686.           sprintf(vvbuf,"%d",typ_mtchs); /* SAFE */
  13687.           return((char *)vvbuf);
  13688.       }
  13689.       case VN_MACLVL:
  13690.         sprintf(vvbuf,"%d",maclvl);     /* SAFE */
  13691.         return((char *)vvbuf);
  13692.     } /* Break up long switch statements... */
  13693.  
  13694.     switch(y) {
  13695. #ifndef NOLASTFILE
  13696.       case VN_LASTFIL: {
  13697.       extern char * lastfile;
  13698.       return(lastfile ? lastfile : "");
  13699.       }
  13700. #endif    /* NOLASTFILE */
  13701. #ifndef NOXFER
  13702.       case VN_XF_BC:
  13703.         sprintf(vvbuf,"%d",crunched);   /* SAFE */
  13704.         return((char *)vvbuf);
  13705.  
  13706.       case VN_XF_TM:
  13707.         sprintf(vvbuf,"%d",timeouts);   /* SAFE */
  13708.         return((char *)vvbuf);
  13709.  
  13710.       case VN_XF_RX:
  13711.         sprintf(vvbuf,"%d",retrans);    /* SAFE */
  13712.         return((char *)vvbuf);
  13713. #endif /* NOXFER */
  13714.  
  13715.       case VN_MS_CD:                    /* Modem signals */
  13716.       case VN_MS_CTS:
  13717.       case VN_MS_DSR:
  13718.       case VN_MS_DTR:
  13719.       case VN_MS_RI:
  13720.       case VN_MS_RTS: {
  13721.           int x, z = -1;
  13722.           x = ttgmdm();                 /* Try to get them */
  13723.           if (x > -1) {
  13724.               switch (y) {
  13725.                 case VN_MS_CD:  z = (x & BM_DCD) ? 1 : 0; break;
  13726.                 case VN_MS_DSR: z = (x & BM_DSR) ? 1 : 0; break;
  13727.                 case VN_MS_CTS: z = (x & BM_CTS) ? 1 : 0; break;
  13728. #ifdef MAC
  13729.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  13730. #else
  13731. #ifndef STRATUS
  13732.                 case VN_MS_RI:  z = (x & BM_RNG) ? 1 : 0; break;
  13733. #ifndef NT
  13734.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  13735.                 case VN_MS_RTS: z = (x & BM_RTS) ? 1 : 0; break;
  13736. #endif /* NT */
  13737. #endif /* STRATUS */
  13738. #endif /* MAC */
  13739.               }
  13740.           }
  13741.           sprintf(vvbuf,"%d",z);        /* SAFE */
  13742.           return((char *)vvbuf);
  13743.       }
  13744.       case VN_MATCH:                    /* INPUT MATCH */
  13745.         return(inpmatch ? inpmatch : "");
  13746.  
  13747. #ifdef CKFLOAT
  13748.       case VN_ISCALE:            /* INPUT SCALE-FACTOR */
  13749.         return(inpscale ? inpscale : "1.0");
  13750. #endif    /* CKFLOAT */
  13751.  
  13752.       case VN_SLMSG: {                  /* SET LINE / HOST message */
  13753.           extern char * slmsg;
  13754.           vvbuf[0] = NUL;
  13755.           if (slmsg)
  13756.             ckstrncpy(vvbuf,slmsg,VVBUFL);
  13757.          return(vvbuf);
  13758.       }
  13759.  
  13760.       case VN_TXTDIR:                   /* TEXTDIR */
  13761.         return(k_info_dir ? k_info_dir : "");
  13762.  
  13763. #ifdef FNFLOAT
  13764.       case VN_MA_PI:
  13765.         return(math_pi);
  13766.  
  13767.       case VN_MA_E:
  13768.         return(math_e);
  13769.  
  13770.       case VN_MA_PR:
  13771.         sprintf(vvbuf,"%d",fp_digits);  /* SAFE */
  13772.         return(vvbuf);
  13773. #endif /* FNFLOAT */
  13774.  
  13775.       case VN_CMDBL:
  13776.         sprintf(vvbuf,"%d",CMDBL);      /* SAFE */
  13777.         return(vvbuf);
  13778.  
  13779. #ifdef CKCHANNELIO
  13780.       case VN_FERR: {
  13781.           extern int z_error;
  13782.           sprintf(vvbuf,"%d",z_error);  /* SAFE */
  13783.           return(vvbuf);
  13784.       }
  13785.       case VN_FMAX: {
  13786.           extern int z_maxchan;
  13787.           sprintf(vvbuf,"%d",z_maxchan); /* SAFE */
  13788.           return(vvbuf);
  13789.       }
  13790.       case VN_FCOU: {
  13791.           extern int z_filcount;
  13792.           sprintf(vvbuf,"%d",z_filcount); /* SAFE */
  13793.           return(vvbuf);
  13794.       }
  13795. #endif /* CKCHANNELIO */
  13796.  
  13797. #ifndef NODIAL
  13798.       case VN_DRTR: {
  13799.           extern int dialcount;
  13800.           sprintf(vvbuf,"%d",dialcount); /* SAFE */
  13801.           return(vvbuf);
  13802.       }
  13803. #endif /* NODIAL */
  13804.  
  13805. #ifndef NOLOGDIAL
  13806. #ifndef NOLOCAL
  13807.       case VN_CXTIME:
  13808.         sprintf(vvbuf,"%ld",dologshow(0)); /* SAFE */
  13809.         return(vvbuf);
  13810. #endif /* NOLOCAL */
  13811. #endif /* NOLOGDIAL */
  13812.  
  13813.       case VN_BYTE:
  13814.         sprintf(vvbuf,"%d",byteorder);  /* SAFE */
  13815.         return(vvbuf);
  13816.  
  13817.       case VN_KBCHAR:
  13818.         vvbuf[0] = NUL;
  13819.         vvbuf[1] = NUL;
  13820.         if (kbchar > 0)
  13821.           vvbuf[0] = (kbchar & 0xff);
  13822.         return(vvbuf);
  13823.  
  13824.       case VN_TTYNAM: {
  13825. #ifdef HAVECTTNAM
  13826.           extern char cttnam[];
  13827.           return((char *)cttnam);
  13828. #else
  13829.           return(CTTNAM);
  13830. #endif /* HAVECTTNAM */
  13831.       }
  13832.  
  13833.       case VN_PROMPT:
  13834.         return(cmgetp());
  13835.  
  13836.       case VN_BUILD: {
  13837.           extern char * buildid;
  13838.           return(buildid);
  13839.       }
  13840.  
  13841. #ifndef NOSEXP
  13842.       case VN_SEXP: {
  13843.           extern char * lastsexp;
  13844.           return(lastsexp ? lastsexp : "");
  13845.       }
  13846.       case VN_VSEXP: {
  13847.           extern char * sexpval;
  13848.           return(sexpval ? sexpval : "");
  13849.       }
  13850.       case VN_LSEXP: {
  13851.           extern int sexpdep;
  13852.           ckstrncpy(vvbuf,ckitoa(sexpdep),VVBUFL);
  13853.           return(vvbuf);
  13854.       }
  13855. #endif /* NOSEXP */
  13856.  
  13857. #ifdef GFTIMER
  13858.       case VN_FTIME: {
  13859.           CKFLOAT f;
  13860.           ztime(&p);
  13861.           if (p == NULL || *p == NUL)
  13862.             return(NULL);
  13863.           z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  13864.           f = (CKFLOAT)z + ((CKFLOAT)ztusec) / 1000000.0;
  13865.           sprintf(vvbuf,"%f",f);        /* SAFE */
  13866.           return(vvbuf);
  13867.       }
  13868. #endif /* GFTIMER */
  13869.  
  13870. #ifndef NOHTTP
  13871.       case VN_HTTP_C: {                 /* HTTP Code */
  13872.           extern int http_code;
  13873.           return(ckitoa(http_code));
  13874.       }
  13875.       case VN_HTTP_N:                   /* HTTP Connected */
  13876.         return( http_isconnected() ? "1" : "0");
  13877.       case VN_HTTP_H:                   /* HTTP Host */
  13878.         return( (char *)http_host() );
  13879.       case VN_HTTP_M: {                 /* HTTP Message */
  13880.           extern char http_reply_str[];
  13881.           return((char *)http_reply_str);
  13882.       }
  13883.       case VN_HTTP_S:                   /* HTTP Security */
  13884.         return((char *)http_security());
  13885. #endif /* NOHTTP */
  13886.  
  13887. #ifdef NEWFTP
  13888.       case VN_FTP_B:
  13889.         return((char *)ftp_cpl_mode());
  13890.       case VN_FTP_D:
  13891.         return((char *)ftp_dpl_mode());
  13892.       case VN_FTP_Z:
  13893.         return((char *)ftp_authtype());
  13894.       case VN_FTP_C: {
  13895.           extern int ftpcode;
  13896.           return(ckitoa(ftpcode));
  13897.       }
  13898.       case VN_FTP_M: {
  13899.           extern char ftp_reply_str[];
  13900.           if (isdigit(ftp_reply_str[0]) &&
  13901.               isdigit(ftp_reply_str[1]) &&
  13902.               isdigit(ftp_reply_str[2]) &&
  13903.               ftp_reply_str[3] == ' ')
  13904.             return(&ftp_reply_str[4]);
  13905.           else
  13906.             return(ftp_reply_str);
  13907.       }
  13908.       case VN_FTP_S: {
  13909.           extern char ftp_srvtyp[];
  13910.           return((char *)ftp_srvtyp);
  13911.       }
  13912.       case VN_FTP_H: {
  13913.           extern char * ftp_host;
  13914.           return(ftp_host ? ftp_host : "");
  13915.       }
  13916.       case VN_FTP_X: {                  /* FTP Connected */
  13917.           return(ftpisconnected() ? "1" : "0");
  13918.       }
  13919.       case VN_FTP_L: {                  /* FTP Logged in */
  13920.           return(ftpisloggedin() ? "1" : "0");
  13921.       }
  13922.       case VN_FTP_G: {                  /* FTP GET-PUT-REMOTE */
  13923.           extern int ftpget;
  13924.           char * s = "";
  13925.           switch (ftpget) {
  13926.             case 0: s = "kermit"; break;
  13927.             case 1: s = "ftp"; break;
  13928.             case 2: s = "auto"; break;
  13929.           }
  13930.           return(s);
  13931.       }
  13932. #endif /* NEWFTP */
  13933.  
  13934. #ifndef NOLOCAL
  13935.       case VN_CX_STA: {                 /* CONNECT status */
  13936.           extern int cx_status;
  13937.           return(ckitoa(cx_status));
  13938.       }
  13939. #endif /* NOLOCAL */
  13940.       case VN_NOW:                      /* Timestamp */
  13941.         return(ckcvtdate(p,0));
  13942.  
  13943.       case VN_HOUR:                     /* Hour of the day */
  13944.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  13945.         if (!p) p = "";
  13946.         if (!*p) return(p);
  13947.         vvbuf[0] = p[11];
  13948.         vvbuf[1] = p[12];
  13949.         vvbuf[2] = NUL;
  13950.         return(vvbuf);                  /* and return it */
  13951.  
  13952.       case VN_BITS:            /* Bits (16, 32, 64) */
  13953.     if (sizeof(long) > 4)
  13954.       return(ckitoa(8*sizeof(long)));
  13955.     else
  13956.       return(ckitoa(8*sizeof(int)));
  13957.  
  13958.       case VN_LASTKWV:            /* 212 */
  13959.     return(lastkwval ? lastkwval : "");
  13960.  
  13961.       case VN_HOSTIP: {            /* 212 */
  13962. #ifdef TCPSOCKET
  13963.       extern char hostipaddr[];
  13964.       return((char *)hostipaddr);
  13965. #else
  13966.       return("");
  13967. #endif    /* TCPSOCKET */
  13968.       }
  13969.       case VN_INPMSG:
  13970.     switch (instatus) {
  13971.       case INP_OK:  return("SUCCESS");
  13972.       case INP_TO:  return("Timed out");
  13973.       case INP_UI:  return("Keyboard interrupt");
  13974.       case INP_IE:  return("Internal error");
  13975.       case INP_IO:  return("I/O error or connection lost");
  13976.       case INP_IKS: return("INPUT disabled");
  13977.       case INP_BF:  return("Buffer filled and /NOWRAP set");
  13978.       default:      return("Unknown");
  13979.     }
  13980.  
  13981.       case VN_VAREVAL:            /* 212 */
  13982.     return(vareval ? "recursive" : "simple");
  13983.  
  13984.       case VN_LOG_CON:            /* \v(...) for log files */
  13985. #ifdef CKLOGDIAL
  13986.         return(diafil);
  13987. #else 
  13988.         return("");
  13989. #endif
  13990.       case VN_LOG_PKT:
  13991. #ifndef NOXFER
  13992.         return(pktfil);
  13993. #else
  13994.         return("");
  13995. #endif
  13996.       case VN_LOG_SES:
  13997. #ifndef NOLOCAL
  13998.         return(sesfil);
  13999. #else
  14000.         return("");
  14001. #endif
  14002.       case VN_LOG_TRA:
  14003. #ifdef TLOG
  14004.         return(trafil);
  14005. #else
  14006.         return("");
  14007. #endif
  14008.       case VN_LOG_DEB:
  14009. #ifdef DEBUG
  14010.         return(debfil);
  14011. #else
  14012.         return("");
  14013. #endif
  14014.     }
  14015.  
  14016. #ifndef NODIAL
  14017.     switch (y) {                        /* Caller ID values */
  14018.       extern char
  14019.         * callid_date, * callid_time, * callid_name,
  14020.         * callid_nmbr, * callid_mesg;
  14021.  
  14022.       case VN_CI_DA:
  14023.         return(callid_date ? callid_date : "");
  14024.  
  14025.       case VN_CI_TI:
  14026.         return(callid_time ? callid_time : "");
  14027.  
  14028.       case VN_CI_NA:
  14029.         return(callid_name ? callid_name : "");
  14030.  
  14031.       case VN_CI_NU:
  14032.         return(callid_nmbr ? callid_nmbr : "");
  14033.  
  14034.       case VN_CI_ME:
  14035.         return(callid_mesg ? callid_mesg : "");
  14036.  
  14037.     } /* End of variable-name switches */
  14038. #endif /* NODIAL */
  14039.  
  14040. #ifdef NT
  14041.     switch (y) {
  14042.       case VN_PERSONAL:
  14043.         p = (char *)GetPersonal();
  14044.         if (p) {
  14045.             GetShortPathName(p,vvbuf,VVBUFL);
  14046.             return(vvbuf);
  14047.         }
  14048.         return("");
  14049.       case VN_DESKTOP:
  14050.           p = (char *)GetDesktop();
  14051.           if (p) {
  14052.               GetShortPathName(p,vvbuf,VVBUFL);
  14053.               return(vvbuf);
  14054.           }
  14055.           return("");
  14056.       case VN_COMMON:
  14057.         p = (char *)GetAppData(1);
  14058.         if (p) {
  14059.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  14060.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  14061.             return(vvbuf);
  14062.         }
  14063.         return("");
  14064.       case VN_APPDATA:
  14065.         p = (char *)GetAppData(0);
  14066.         if (p) {
  14067.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  14068.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  14069.             return(vvbuf);
  14070.         }
  14071.         return("");
  14072.     }
  14073. #endif /* NT */
  14074.  
  14075. #ifdef TN_COMPORT
  14076.     switch (y) {
  14077.       case VN_TNC_SIG: {
  14078.         p = (char *) tnc_get_signature();
  14079.         ckstrncpy(vvbuf,p ? p : "",VVBUFL);
  14080.         return(vvbuf);
  14081.       }
  14082.     }
  14083. #endif /* TN_COMPORT */
  14084.  
  14085. #ifdef KUI
  14086.     switch (y) {
  14087.       case VN_GUI_RUN: {
  14088.       extern HWND getHwndKUI();
  14089.       if ( IsIconic(getHwndKUI()) )
  14090.             return("minimized");
  14091.       if ( IsZoomed(getHwndKUI()) )
  14092.             return("maximized");
  14093.       return("restored");
  14094.       }
  14095.       case VN_GUI_XP:
  14096.         sprintf(vvbuf,"%d",get_gui_window_pos_x());  /* SAFE */
  14097.         return(vvbuf);
  14098.       case VN_GUI_YP:
  14099.         sprintf(vvbuf,"%d",get_gui_window_pos_y());  /* SAFE */
  14100.         return(vvbuf);
  14101.       case VN_GUI_XR:
  14102.         sprintf(vvbuf,"%d",GetSystemMetrics(SM_CXSCREEN));  /* SAFE */
  14103.         return(vvbuf);
  14104.       case VN_GUI_YR:
  14105.         sprintf(vvbuf,"%d",GetSystemMetrics(SM_CYSCREEN));  /* SAFE */
  14106.         return(vvbuf);
  14107.       case VN_GUI_FNM:
  14108.           if ( ntermfont > 0 ) {
  14109.               int i;
  14110.               for (i = 0; i < ntermfont; i++) {
  14111.                   if (tt_font == term_font[i].kwval) {
  14112.                       ckstrncpy(vvbuf,term_font[i].kwd,VVBUFL);
  14113.                       return(vvbuf);
  14114.                   }
  14115.               }
  14116.           }
  14117.           return("(unknown)");
  14118.       case VN_GUI_FSZ:
  14119.           ckstrncpy(vvbuf,ckitoa(tt_font_size/2),VVBUFL);
  14120.           if ( tt_font_size % 2 )
  14121.               ckstrncat(vvbuf,".5",VVBUFL);
  14122.           return(vvbuf);
  14123.     }
  14124. #endif /* KUI */
  14125.  
  14126.     fnsuccess = 0;
  14127.     if (fnerror) {
  14128.         fnsuccess = 0;
  14129.     }
  14130.     if (fndiags) {
  14131.         if (!embuf[0])
  14132.           ckstrncpy(embuf,"<ERROR:NO_SUCH_VARIABLE>",EMBUFLEN);
  14133.         printf("?%s\n",embuf);
  14134.         return((char *)embuf);
  14135.     } else
  14136.       return("");
  14137. }
  14138. #endif /* NOSPL */
  14139.  
  14140.  
  14141. /*
  14142.   X X S T R I N G  --  Expand variables and backslash codes.
  14143.  
  14144.     int xxtstring(s,&s2,&n);
  14145.  
  14146.   Expands \ escapes via recursive descent.
  14147.   Argument s is a pointer to string to expand (source).
  14148.   Argument s2 is the address of where to put result (destination).
  14149.   Argument n is the length of the destination string (to prevent overruns).
  14150.   Returns -1 on failure, 0 on success,
  14151.     with destination string null-terminated and s2 pointing to the
  14152.     terminating null, so that subsequent characters can be added.
  14153.     Failure reasons include destination buffer is filled up.
  14154. */
  14155.  
  14156. #define XXDEPLIM 100                    /* Recursion depth limit */
  14157. /*
  14158.   In Windows the stack is limited to 256K so big character arrays like
  14159.   vnambuf can't be on the stack in recursive functions like zzstring().
  14160.   But that's no reason use malloc() in Unix or VMS, which don't have
  14161.   this kind of restriction.
  14162. */
  14163. #ifdef DVNAMBUF                /* Dynamic vnambuf[] */
  14164. #undef DVNAMBUF                /* Clean slate */
  14165. #endif /* DVNAMBUF */
  14166.  
  14167. #ifndef NOSPL                /* Only if SPL included */
  14168. #ifdef OS2                /* Only for K95 */
  14169. #define DVNAMBUF
  14170. #endif /* OS2 */
  14171. #endif /* NOSPL */
  14172.  
  14173. int
  14174. zzstring(s,s2,n) char *s; char **s2; int *n; {
  14175.     int x,                              /* Current character */
  14176.         y,                              /* Worker */
  14177.         pp,                             /* Paren level */
  14178.         kp,                             /* Brace level */
  14179.         argn,                           /* Function argument counter */
  14180.         n2,                             /* Local copy of n */
  14181.         d,                              /* Array dimension */
  14182.         vbi,                            /* Variable id (integer form) */
  14183.         argl,                           /* String argument length */
  14184.         nx;                             /* Save original length */
  14185.  
  14186.     char vb,                            /* Variable id (char form) */
  14187.         *vp,                            /* Pointer to variable definition */
  14188.         *new,                           /* Local pointer to target string */
  14189. #ifdef COMMENT
  14190.         *old,                           /* Save original target pointer */
  14191. #endif /* COMMENT */
  14192.         *p,                             /* Worker */
  14193.         *q,                             /* Worker */
  14194.         *s3;                            /* Worker */
  14195.     int  x3;                            /* Worker */
  14196.     char *r  = (char *)0;               /* For holding function args */
  14197.     char *r2 = (char *)0;
  14198.     char *r3p;
  14199.  
  14200. #ifndef NOSPL
  14201. #ifdef DVNAMBUF
  14202.     char * vnambuf = NULL;              /* Buffer for variable/function name */
  14203. #else /* DVNAMBUF */
  14204.     char vnambuf[VNAML];                /* Buffer for variable/function name */
  14205. #endif /* DVNAMBUF */
  14206.     char *argp[FNARGS];                 /* Pointers to function args */
  14207. #endif /* NOSPL */
  14208.  
  14209.     static int depth = 0;               /* Call depth, avoid overflow */
  14210.  
  14211.     n2 = *n;                            /* Make local copies of args */
  14212.     nx = n2;
  14213.  
  14214. #ifdef COMMENT
  14215.     /* This is always 32K in BIGBUFOK builds */
  14216.     if (depth == 0)
  14217.       debug(F101,"zzstring top-level n","",n2);
  14218. #endif    /* COMMENT */
  14219.  
  14220.     new = *s2;                          /* for one less level of indirection */
  14221. #ifdef COMMENT
  14222.     old = new;
  14223. #endif /* COMMENT */
  14224.  
  14225. #ifndef NOSPL
  14226.     itsapattern = 0;            /* For \fpattern() */
  14227.     isjoin = 0;                /* For \fjoin() */
  14228. #endif /* NOSPL */
  14229.     depth++;                            /* Sink to a new depth */
  14230.     if (depth > XXDEPLIM) {             /* Too deep? */
  14231.         printf("?definition is circular or too deep\n");
  14232.         debug(F101,"zzstring fail","",depth);
  14233.         depth = 0;
  14234.         *new = NUL;
  14235.         return(-1);
  14236.     }
  14237.     if (!s || !new) {                   /* Watch out for null pointers */
  14238.         debug(F101,"zzstring fail 2","",depth);
  14239.         if (new)
  14240.           *new = NUL;
  14241.         depth = 0;
  14242.         return(-1);
  14243.     }
  14244.     s3 = s;
  14245.     argl = 0;
  14246.     while (*s3++) argl++;              /* Get length of source string */
  14247.     debug(F010,"zzstring entry",s,0);
  14248.     if (argl == 0) {                    /* Empty string */
  14249.         debug(F111,"zzstring empty arg",s,argl);
  14250.         depth = 0;
  14251.         *new = NUL;
  14252.         return(0);
  14253.     }
  14254.     if (argl < 0) {                     /* Watch out for garbage */
  14255.         debug(F101,"zzstring fail 3","",depth);
  14256.         *new = NUL;
  14257.         depth = 0;
  14258.         return(-1);
  14259.     }
  14260. #ifdef DVNAMBUF
  14261.     debug(F100,"vnambuf malloc...","",0);
  14262.     vnambuf = malloc(VNAML);
  14263.     if (vnambuf == NULL) {
  14264.         printf("?Out of memory");
  14265.         return(-1);
  14266.     }
  14267.     debug(F100,"vnambuf malloc ok","",0);
  14268. #endif /* DVNAMBUF */
  14269.  
  14270.     while ((x = *s)) {                  /* Loop for all characters */
  14271.         if (x != CMDQ) {                /* Is it the command-quote char? */
  14272.             *new++ = *s++;              /* No, normal char, just copy */
  14273.             if (--n2 < 0) {             /* and count it, careful of overflow */
  14274.                 debug(F101,"zzstring overflow 1","",depth);
  14275.                 depth = 0;
  14276. #ifdef DVNAMBUF
  14277.                 if (vnambuf) free(vnambuf);
  14278. #endif /* DVNAMBUF */
  14279.                 return(-1);
  14280.             }
  14281.             continue;
  14282.         }
  14283.  
  14284. /* We have the command-quote character. */
  14285.  
  14286.         x = *(s+1);                     /* Get the following character. */
  14287.         if (isupper(x)) x = tolower(x);
  14288.         switch (x) {                    /* Act according to variable type */
  14289. #ifndef NOSPL
  14290.           case 0:                       /* It's a lone backslash */
  14291.             *new++ = *s++;
  14292.             if (--n2 < 0) {
  14293.                 debug(F101,"zzstring overflow 2","",0);
  14294. #ifdef DVNAMBUF
  14295.                 if (vnambuf) free(vnambuf);
  14296. #endif /* DVNAMBUF */
  14297.                 return(-1);
  14298.             }
  14299.             break;
  14300.           case '%':                     /* Variable */
  14301.             s += 2;                     /* Get the letter or digit */
  14302.             vb = *s++;                  /* and move source pointer past it */
  14303.             vp = NULL;                  /* Assume definition is empty */
  14304.             if (vb >= '0' && vb <= '9') { /* Digit for macro arg */
  14305.                 if (maclvl < 0)         /* Digit variables are global */
  14306.                   vp = g_var[vb];       /* if no macro is active */
  14307.                 else                    /* otherwise */
  14308.                   vp = m_arg[maclvl][vb - '0']; /* they're on the stack */
  14309.             } else if (vb == '*') {     /* Macro args string */
  14310. #ifdef COMMENT
  14311.                 /* This doesn't take changes into account */
  14312.                 vp = (maclvl >= 0) ? m_line[maclvl] : topline;
  14313.                 if (!vp) vp = "";
  14314. #else
  14315.         char * ss = new;
  14316.                 if (zzstring("\\fjoin(&_[],,1)",&new,&n2) < 0) {
  14317. #ifdef DVNAMBUF
  14318.             if (vnambuf) free(vnambuf);
  14319. #endif /* DVNAMBUF */
  14320.             return(-1);
  14321.         }
  14322.         debug(F110,"zzstring \\%*",ss,0);
  14323.                 break;
  14324. #endif /* COMMENT */
  14325.             } else {
  14326.                 if (isupper(vb)) vb += ('a'-'A');
  14327.                 vp = g_var[vb];         /* Letter for global variable */
  14328.             }
  14329.             if (!vp) vp = "";
  14330. #ifdef COMMENT
  14331.             if (vp) {                   /* If definition not empty */
  14332. #endif /* COMMENT */
  14333.         if (vareval) {
  14334.             debug(F010,"zzstring %n vp",vp,0);
  14335.             /* call self to evaluate it */
  14336.             if (zzstring(vp,&new,&n2) < 0) {
  14337.             debug(F101,"zzstring fail 6","",depth);
  14338. #ifdef DVNAMBUF
  14339.             if (vnambuf) free(vnambuf);
  14340. #endif /* DVNAMBUF */
  14341.             return(-1);    /* Pass along failure */
  14342.             }
  14343.         } else {
  14344.             while ((*new++ = *vp++)) /* copy it to output string. */
  14345.               if (--n2 < 0) {
  14346.               if (q) free(q);
  14347.               debug(F101,"zzstring overflow 4.5","",depth);
  14348. #ifdef DVNAMBUF
  14349.               if (vnambuf) free(vnambuf);
  14350. #endif /* DVNAMBUF */
  14351.               return(-1);
  14352.               }
  14353.             new--;        /* Back up over terminating null */
  14354.             n2++;        /* to allow for further deposits. */
  14355.         }
  14356. #ifdef COMMENT
  14357.             } else {
  14358.                 debug(F110,"zzstring %n vp","(NULL)",0);
  14359.                 n2 = nx;
  14360.                 new = old;
  14361.                 *new = NUL;
  14362.             }
  14363. #endif /* COMMENT */
  14364.             break;
  14365.           case '&':                     /* An array reference */
  14366.             x = arraynam(s,&vbi,&d);    /* Get name and subscript */
  14367.             debug(F111,"zzstring arraynam",s,x);
  14368.             if (x < 0) {
  14369.                 debug(F101,"zzstring fail 7","",depth);
  14370. #ifdef DVNAMBUF
  14371.                 if (vnambuf) free(vnambuf);
  14372. #endif /* DVNAMBUF */
  14373.                 return(-1);
  14374.             }
  14375.             pp = 0;                     /* Bracket counter */
  14376.             while (*s) {                /* Advance source pointer... */
  14377.                 if (*s == '[') pp++;
  14378.                 if (*s == ']' && --pp == 0) break;
  14379.                 s++;
  14380.             }
  14381.             if (*s == ']') s++;         /* ...past the closing bracket. */
  14382.  
  14383.             x = chkarray(vbi,d);        /* Array is declared? */
  14384.             debug(F101,"zzstring chkarray","",x);
  14385.             if (x > -1) {
  14386. #ifdef COMMENT
  14387.                 char * s1 = NULL;
  14388. #endif /* COMMENT */
  14389.                 vbi -= ARRAYBASE;       /* Convert name to index */
  14390.  
  14391.                   if (a_dim[vbi] >= d) { /* If subscript in range */
  14392.                     char **ap;
  14393.                     ap = a_ptr[vbi];    /* get data pointer */
  14394.                     if (ap) {           /* and if there is one */
  14395.                         if (ap[d]) {    /* If definition not empty */
  14396.                             debug(F111,"zzstring ap[d]",ap[d],d);
  14397.                 if (vareval) {
  14398.                 if (zzstring(ap[d],&new,&n2) < 0) {
  14399.                     debug(F101,"zzstring fail 8","",depth);
  14400. #ifdef DVNAMBUF
  14401.                     if (vnambuf) free(vnambuf);
  14402. #endif /* DVNAMBUF */
  14403.                     return(-1); /* Pass along failure */
  14404.                 }
  14405.                 } else {
  14406.                 vp = ap[d];
  14407.                 while ((*new++ = *vp++)) /* copy to result */
  14408.                   if (--n2 < 0) {
  14409.                       if (q) free(q);
  14410.                       debug(F101,
  14411.                         "zzstring overflow 8.5","",depth);
  14412. #ifdef DVNAMBUF
  14413.                       if (vnambuf) free(vnambuf);
  14414. #endif /* DVNAMBUF */
  14415.                       return(-1);
  14416.                   }
  14417.                 new--;    /* Back up over terminating null */
  14418.                 n2++;    /* to allow for further deposits. */
  14419.                 }
  14420.             }
  14421.  
  14422.                     } else {
  14423.                         /* old = new; */
  14424.                         n2 = nx;
  14425.                     }
  14426.                 }
  14427.         }
  14428.             break;
  14429.  
  14430.           case 'f':                     /* A builtin function */
  14431.             q = vnambuf;                /* Copy the name */
  14432.             y = 0;                      /* into a separate buffer */
  14433.             s += 2;                     /* point past 'F' */
  14434.             while (y++ < VNAML) {
  14435.                 if (*s == '(') { s++; break; } /* Look for open paren */
  14436.                 if ((*q = *s) == NUL) break;   /* or end of string */
  14437.                 s++; q++;
  14438.             }
  14439.             *q = NUL;                   /* Terminate function name */
  14440.             if (y >= VNAML) {           /* Handle pathological case */
  14441.                 while (*s && (*s != '(')) /* of very long string entered */
  14442.                   s++;                    /* as function name. */
  14443.                 if (*s == ')') s++;       /* Skip past it. */
  14444.             }
  14445.             r = r2 = malloc(argl+2);    /* And make a place to copy args */
  14446.             /* debug(F101,"zzstring r2","",r2); */
  14447.             if (!r2) {                  /* Watch out for malloc failure */
  14448.                 debug(F101,"zzstring fail 9","",depth);
  14449.                 *new = NUL;
  14450.                 depth = 0;
  14451. #ifdef DVNAMBUF
  14452.                 if (vnambuf) free(vnambuf);
  14453. #endif /* DVNAMBUF */
  14454.                 return(-1);
  14455.             }
  14456.             if (r3) free(r3); /* And another to copy literal arg string */
  14457.             r3 = malloc(argl+2);
  14458.             /* debug(F101,"zzstring r3","",r3); */
  14459.             if (!r3) {
  14460.                 debug(F101,"zzstring fail 10","",depth);
  14461.                 depth = 0;
  14462.                 *new = NUL;
  14463.                 if (r2) free(r2);
  14464. #ifdef DVNAMBUF
  14465.                 if (vnambuf) free(vnambuf);
  14466. #endif /* DVNAMBUF */
  14467.                 return(-1);
  14468.             } else
  14469.               r3p = r3;
  14470.             argn = 0;                   /* Argument counter */
  14471.             argp[argn++] = r;           /* Point to first argument */
  14472.             y = 0;                      /* Completion flag */
  14473.             pp = 1;                     /* Paren level (already have one). */
  14474.             kp = 0;
  14475.             while (1) {                 /* Copy each argument, char by char. */
  14476.                 *r3p++ = *s;            /* This is a literal copy for \flit */
  14477.                 if (!*s) break;
  14478.  
  14479.                 if (*s == '{') {        /* Left brace */
  14480.                     kp++;
  14481.                 }
  14482.                 if (*s == '}') {        /* Right brace */
  14483.                     kp--;
  14484.                 }
  14485.                 if (*s == '(' && kp <= 0) { /* Open paren not in brace */
  14486.                     pp++;               /* Count it */
  14487.                 }
  14488.                 *r = *s;                /* Now copy resulting byte */
  14489.                 if (!*r)                /* If NUL, done. */
  14490.                   break;
  14491.                 if (*r == ')' && kp <= 0) { /* Closing paren, count it. */
  14492.                     if (--pp == 0) {    /* Final one? */
  14493.                         *r = NUL;       /* Make it a terminating null */
  14494.                         *(r3p - 1) = NUL;
  14495.                         s++;            /* Point past it in source string */
  14496.                         y = 1;          /* Flag we've got all the args */
  14497.                         break;          /* Done with while loop */
  14498.                     }
  14499.                 }
  14500.                 if (*r == ',' && kp <= 0) { /* Comma */
  14501.                     if (pp == 1) {          /* If not within ()'s, */
  14502.                         if (argn >= FNARGS) { /* Too many args */
  14503.                             s++; r++;   /* Keep collecting flit() string */
  14504.                             continue;
  14505.                         }
  14506.                         *r = NUL;           /* New arg, skip past comma */
  14507.                         argp[argn++] = r+1; /* In range, point to new arg */
  14508.                     }                   /* Otherwise just skip past  */
  14509.                 }
  14510.                 s++; r++;               /* Advance pointers */
  14511.             }
  14512.             if (!y)                     /* If we didn't find closing paren */
  14513.               argn = -1;
  14514. #ifdef DEBUG
  14515.             if (deblog) {
  14516.                 char buf[24];
  14517.                 debug(F111,"zzstring function name",vnambuf,y);
  14518.                 debug(F010,"zzstring function r3",r3,0);
  14519.                 for (y = 0; y < argn; y++) {
  14520.                     sprintf(buf,"arg %2d ",y);
  14521.                     debug(F010,buf,argp[y],0);
  14522.                 }
  14523.             }
  14524. #endif /* DEBUG */
  14525.         {
  14526.          /* In case the function name itself is constructed */
  14527.         char buf[64]; char * p = buf; int n = 64; 
  14528.         if (zzstring(vnambuf,&p,&n) > -1)
  14529.           ckstrncpy(vnambuf,buf,64);
  14530.         }
  14531.             vp = fneval(vnambuf,argp,argn,r3); /* Evaluate the function. */
  14532.             if (vp) {                      /* If definition not empty */
  14533.                 while ((*new++ = *vp++)) { /* copy it to output string */
  14534.                     if (--n2 < 0) {        /* watch out for overflow */
  14535.                         debug(F101,"zzstring fail 12","",depth);
  14536.                         if (r2) { free(r2); r2 = NULL; }
  14537.                         if (r3) { free(r3); r3 = NULL; }
  14538. #ifdef DVNAMBUF
  14539.                         if (vnambuf) free(vnambuf);
  14540. #endif /* DVNAMBUF */
  14541.                         return(-1);
  14542.                     }
  14543.                 }
  14544.                 new--;                  /* Back up over terminating null */
  14545.                 n2++;                   /* to allow for further deposits. */
  14546.             }
  14547.             if (r2) { free(r2); r2 = NULL; }
  14548.             if (r3) { free(r3); r3 = NULL; }
  14549.             break;
  14550.           case '$':                     /* An environment variable */
  14551.           case 'v':                     /* Or a named builtin variable. */
  14552.           case 'm':                     /* Or a macro /long variable */
  14553.           case 's':                     /* 196 Macro substring */
  14554.           case ':':                     /* 196 \-variable substring */
  14555.             pp = 0;
  14556.             p = s+2;                    /* $/V/M must be followed by (name) */
  14557.             if (*p != '(') {            /* as in \$(HOME) or \V(count) */
  14558.                 *new++ = *s++;          /* If not, just copy it */
  14559.                 if (--n2 < 0) {
  14560.                     debug(F101,"zzstring overflow 3","",depth);
  14561. #ifdef DVNAMBUF
  14562.                     if (vnambuf) free(vnambuf);
  14563. #endif /* DVNAMBUF */
  14564.                     return(-1);
  14565.                 }
  14566.                 break;
  14567.             }
  14568.             pp++;
  14569.             p++;                        /* Point to 1st char of name */
  14570.             q = vnambuf;                /* Copy the name */
  14571.             y = 0;                      /* into a separate buffer */
  14572.             while (y++ < VNAML) {       /* Watch out for name too long */
  14573.                 if (*p == '(') {        /* Parens can be nested... */
  14574.                     pp++;
  14575.                 } else if (*p == ')') { /* Name properly terminated with ')' */
  14576.                     pp--;
  14577.                     if (pp == 0) {
  14578.                         p++;            /* Move source pointer past ')' */
  14579.                         break;
  14580.                     }
  14581.                 }
  14582.                 if ((*q = *p) == NUL)   /* String ends before ')' */
  14583.                   break;
  14584.                 p++; q++;               /* Advance pointers */
  14585.             }
  14586.             *q = NUL;                   /* Terminate the variable name */
  14587.             if (y >= VNAML) {           /* Handle pathological case */
  14588.                 while (*p && (*p != ')')) /* of very long string entered */
  14589.                   p++;                    /* as variable name. */
  14590.                 if (*p == ')') p++;       /* Skip ahead to the end of it. */
  14591.             }
  14592.             s = p;                      /* Adjust global source pointer */
  14593.             s3 = vnambuf;
  14594.             x3 = 0;
  14595.             while (*s3++) x3++;
  14596.             p = malloc(x3 + 1);         /* Make temporary space */
  14597.             if (p) {                    /* If we got the space */
  14598.                 vp = vnambuf;           /* Point to original */
  14599.                 strcpy(p,vp);           /* (safe) Make a copy of it */
  14600.                 y = VNAML;              /* Length of name buffer */
  14601.                 zzstring(p,&vp,&y);     /* Evaluate the copy */
  14602.                 free(p);                /* Free the temporary space */
  14603.                 p = NULL;
  14604.             }
  14605.             debug(F110,"zzstring vname",vnambuf,0);
  14606.             q = NULL;
  14607.             if (x == '$') {             /* Look up its value */
  14608.                 vp = getenv(vnambuf);   /* This way for environment variable */
  14609.             } else if (x == 'm' || x == 's' || x == ':') { /* Macro / substr */
  14610.                 int k, x1 = -1, x2 = -1;
  14611.         char c = NUL; 
  14612.                 k = strlen(vnambuf);
  14613.                 /* \s(name[n:m]) -- Compact substring notation */
  14614.                 if ((x == 's' || x == ':') && (k > 1)) { /* Substring wanted */
  14615.             int bprc;
  14616.                     if (vnambuf[k-1] == ']') {
  14617.                         int i;
  14618.                         for (i = 0; i < k-1; i++) {
  14619.                             if (vnambuf[i] == '[') {
  14620.                 bprc = boundspair(vnambuf,":_",&x1,&x2,&c);
  14621.                 debug(F111,"zzstring boundspair",vnambuf,bprc);
  14622.                 debug(F000,"zzstring boundspair c","",c);
  14623.                 if (bprc > -1) {
  14624.                     vnambuf[i] = NUL;
  14625.                     if (x1 < 1)
  14626.                       x1 = 1;
  14627.                     x1--;    /* Adjust to 0-base */
  14628.                 }
  14629.                 break;
  14630.                             }
  14631.                         }
  14632.             }
  14633.                 }
  14634.                 if (x == ':') {        /* Variable type (s or :) */
  14635.                     vp = vnambuf;
  14636.                 } else {
  14637.             y = isaarray(vnambuf) ?
  14638.             mxxlook(mactab,vnambuf,nmac) :
  14639.             mxlook(mactab,vnambuf,nmac);
  14640.                     if (y > -1) {    /* Got definition */
  14641.                         vp = mactab[y].mval;
  14642.                     } else {
  14643.                         vp = NULL;
  14644.                     }
  14645.                 }
  14646.         debug(F111,"zzstring vp",vp,(vp==NULL)?0:strlen(vp));
  14647.  
  14648.                 if (vp) {
  14649.                     if ((x == 's' || x == ':') && (k > 1)) {
  14650.                         /* Compact substring notation */
  14651.                         if (x2 == 0) {  /* Length */
  14652.                             vp = NULL;
  14653.                         } else if (x1 > -1) { /* Start */
  14654.                             k = strlen(vp);
  14655.                 debug(F101,">>> k","",k);
  14656.                 /* If it's off the end, result is empty */
  14657.                             if (x1 > k) {
  14658.                                 vp = NULL;
  14659.                             } else if (k > 0) {
  14660.                 /* Stay in bounds */
  14661.                 if (c == '_' && x2 > k)    /* startpos_endpos */
  14662.                   x2 = k;
  14663.                 if (c == ':' && x1 + x2 > k) /* start:length */
  14664.                   x2 = -1;
  14665.                 debug(F101,">>> x2","",x2);
  14666.                 debug(F000,">>> c","",c);
  14667.                                 if ((q = malloc(k+1))) {
  14668.                                     strcpy(q,vp); /* safe */
  14669.                     if (c == ':') { /* start:length */
  14670.                     if ((x2 > -1) && ((x1 + x2) <= k)) {
  14671.                         q[x1+x2] = NUL;
  14672.                     }
  14673.                     debug(F000,"XXX q",q,c);
  14674.                     } else if (c == '_') { /* start_endpos */
  14675.                     if (x1 >= x2) {
  14676.                         q[x1 = 0] = NUL;
  14677.                     } else if (x2 < k && x2 > -1) {
  14678.                         q[x2] = NUL;
  14679.                     }
  14680.                     debug(F000,"XXX q",q,c);
  14681.                     }
  14682.                     vp = q+x1;
  14683.                                 } else vp = NULL;
  14684.                             } else vp = NULL;
  14685.                         }
  14686.  
  14687.             debug(F110,"XXX vnambuf",vnambuf,0);
  14688.             debug(F000,"XXX c","",c);
  14689.             debug(F101,"XXX x1","",x1);
  14690.             debug(F101,"XXX x2","",x2);
  14691.             debug(F110,"XXX result",vp,0);
  14692. #ifdef DEBUG
  14693.                         if (deblog) {
  14694.                             if (!vp) {
  14695.                             } else {
  14696.                                 k = strlen(vp);
  14697.                             }
  14698.                         }
  14699. #endif /* DEBUG */
  14700.                     }
  14701.                 }
  14702.             } else {                    /* or */
  14703.                 vp = nvlook(vnambuf);   /* this way for builtin variable */
  14704.             }
  14705.             if (vp) {                   /* If definition not empty */
  14706.                 while ((*new++ = *vp++)) /* copy it to output string. */
  14707.                   if (--n2 < 0) {
  14708.                       if (q) free(q);
  14709.                       debug(F101,"zzstring overflow 4","",depth);
  14710. #ifdef DVNAMBUF
  14711.                       if (vnambuf) free(vnambuf);
  14712. #endif /* DVNAMBUF */
  14713.                       return(-1);
  14714.                   }
  14715.                 new--;                  /* Back up over terminating null */
  14716.                 n2++;                   /* to allow for further deposits. */
  14717.             }
  14718.             if (q) {
  14719.                 free(q);
  14720.                 q = NULL;
  14721.             }
  14722.             break;
  14723. #endif /* NOSPL */                      /* Handle \nnn even if NOSPL. */
  14724.  
  14725. #ifndef NOKVERBS
  14726.         case 'K':
  14727.         case 'k': {
  14728.             extern struct keytab kverbs[];
  14729.             extern int nkverbs;
  14730. #define K_BUFLEN 30
  14731.             char kbuf[K_BUFLEN + 1];    /* Key verb name buffer */
  14732.             int x, y, z, brace = 0;
  14733.             s += 2;
  14734. /*
  14735.   We assume that the verb name is {braced}, or it extends to the end of the
  14736.   string, s, or it ends with a space, control character, or backslash.
  14737. */
  14738.             p = kbuf;                   /* Copy verb name into local buffer */
  14739.             x = 0;
  14740.             if (*s == '{')  {
  14741.                 s++;
  14742.                 brace++;
  14743.             }
  14744.             while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  14745.                 if (brace && *s == '}') {
  14746.                     s++;
  14747.                     break;
  14748.                 }
  14749.                 *p++ = *s++;
  14750.             }
  14751.             brace = 0;
  14752.             *p = NUL;                   /* Terminate. */
  14753.             p = kbuf;                   /* Point back to beginning */
  14754.             debug(F110,"zzstring kverb",p,0);
  14755.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  14756.             debug(F101,"zzstring lookup",0,y);
  14757.             if (y > -1) {
  14758.                 dokverb(VCMD,y);
  14759. #ifndef NOSPL
  14760.             } else {                    /* Is it a macro? */
  14761.                 y = mxlook(mactab,p,nmac);
  14762.                 if (y > -1) {
  14763.                     debug(F111,"zzstring mxlook",p,y);
  14764.                     if ((z = dodo(y,NULL,cmdstk[cmdlvl].ccflgs)) > 0) {
  14765.                         if (cmpush() > -1) {  /* Push command parser state */
  14766.                             extern int ifc;
  14767.                             int ifcsav = ifc; /* Push IF condition on stack */
  14768.                             y = parser(1);    /* New parser to execute macro */
  14769.                             cmpop();          /* Pop command parser */
  14770.                             ifc = ifcsav;     /* Restore IF condition */
  14771.                             if (y == 0) {     /* No errors, ignore actions */
  14772.                                 p = mrval[maclvl+1]; /* If OK set return val */
  14773.                                 if (p == NULL) p = "";
  14774.                             }
  14775.                         } else {                /* Can't push any more */
  14776.                             debug(F101,"zzstring pushed too deep","",depth);
  14777.                             printf(
  14778.                                "\n?Internal error: zzstring stack overflow\n"
  14779.                                    );
  14780.                             while (cmpop() > -1);
  14781.                             p = "";
  14782.                         }
  14783.                     }
  14784.                 }
  14785. #endif /* NOSPL */
  14786.             }
  14787.             break;
  14788.         }
  14789. #endif /* NOKVERBS */
  14790.  
  14791.         default:                        /* Maybe it's a backslash code */
  14792.           y = xxesc(&s);                /* Go interpret it */
  14793.           if (y < 0) {                  /* Upon failure */
  14794.               *new++ = (char) x;        /* Just quote the next character */
  14795.               s += 2;                   /* Move past the pair */
  14796.               n2 -= 2;
  14797.               if (n2 < 0) {
  14798.                   debug(F101,"zzstring overflow 5","",depth);
  14799. #ifdef DVNAMBUF
  14800.                   if (vnambuf) free(vnambuf);
  14801. #endif /* DVNAMBUF */
  14802.                   return(-1);
  14803.               }
  14804.               continue;                 /* and go back for more */
  14805.           } else {
  14806.               *new++ = (char) y;        /* else deposit interpreted value */
  14807.               if (--n2 < 0) {
  14808.                   debug(F101,"zzstring overflow 6","",depth);
  14809. #ifdef DVNAMBUF
  14810.                   if (vnambuf) free(vnambuf);
  14811. #endif /* DVNAMBUF */
  14812.                   return(-1);
  14813.               }
  14814.           }
  14815.         }
  14816.     }
  14817.     *new = NUL;                         /* Terminate the new string */
  14818.     debug(F010,"zzstring while exit",*s2,0);
  14819.  
  14820.     depth--;                            /* Adjust stack depth gauge */
  14821.     *s2 = new;                          /* Copy results back into */
  14822.     *n = n2;                            /* the argument addresses */
  14823.     debug(F101,"zzstring ok","",depth);
  14824. #ifdef DVNAMBUF
  14825.     if (vnambuf) free(vnambuf);
  14826. #endif /* DVNAMBUF */
  14827.     return(0);                          /* and return. */
  14828. }
  14829. #endif /* NOICP */
  14830.