home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pub / public_html / debian / ckermit_211.orig.tar.gz / cku211.tar / ckuus4.c < prev    next >
C/C++ Source or Header  |  2004-04-11  |  472KB  |  14,090 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, 2004,
  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. char * xferfile = NULL;
  110. int xferlog = 0;
  111.  
  112. extern int local, xargc, stayflg, rcflag, bgset, backgrd, cfilef,
  113.   inserver, srvcdmsg, success;
  114.  
  115. #ifdef VMS
  116. extern int batch;
  117. #endif /* VMS */
  118.  
  119. extern char cmdfil[], *versio, *ckxsys, **xargv;
  120. #ifdef DEBUG
  121. extern char debfil[];                   /* Debug log file name */
  122. extern int debtim;
  123. #endif /* DEBUG */
  124.  
  125. extern int noinit;
  126.  
  127. static char ndatbuf[10];
  128.  
  129. char *months[] = {
  130.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  131.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  132. };
  133.  
  134. char *
  135. zzndate() {                             /* Returns today's date as yyyymmdd */
  136.     char * p = NULL;
  137.     int x;
  138.  
  139. /* WARNING - This will fail if asctime() returns non-English month names */
  140.  
  141.     ztime(&p);                          /* Get "asctime" string */
  142.     if (p == NULL || *p == NUL) return("");
  143.     for (x = 20; x < 24; x++)           /* yyyy */
  144.       ndatbuf[x - 20] = p[x];
  145.     ndatbuf[6] = (char) ((p[8] == ' ') ? '0' : p[8]);
  146.     ndatbuf[7] = p[9];                  /* dd */
  147.     for (x = 0; x < 12; x++)            /* mm */
  148.       if (!strncmp(p+4,months[x],3)) break;
  149.     if (x == 12) {
  150.         ndatbuf[4] = ndatbuf[5] = '?';
  151.     } else {
  152.         x++;
  153.         ndatbuf[4] = (char) ((x < 10) ? '0' : '1');
  154.         ndatbuf[5] = (char) ((x % 10) + 48);
  155.     }
  156.     ndatbuf[8] = NUL;
  157.     debug(F110,"zzndate return",ndatbuf,0);
  158.     return((char *)ndatbuf);
  159. }
  160.  
  161. #ifdef DCMDBUF
  162. extern struct cmdptr *cmdstk;
  163. extern char *line, *tmpbuf;
  164. #else
  165. extern struct cmdptr cmdstk[];
  166. extern char line[], tmpbuf[];
  167. #endif /* DCMDBUF */
  168.  
  169. #ifdef OS2
  170. extern char exedir[];
  171. #else
  172. extern char * exedir;
  173. #endif /* OS2 */
  174.  
  175. extern int nettype;
  176.  
  177. #ifndef NOICP                           /* Most of this file... */
  178. #ifdef CKLOGDIAL
  179. extern char diafil[];
  180. #endif /* CKLOGDIAL */
  181.  
  182. #ifndef AMIGA
  183. #ifndef MAC
  184. #include <signal.h>
  185. #endif /* MAC */
  186. #endif /* AMIGA */
  187.  
  188. #ifdef STRATUS                          /* Stratus Computer, Inc.  VOS */
  189. #ifdef putchar
  190. #undef putchar
  191. #endif /* putchar */
  192. #define putchar(x) conoc(x)
  193. #ifdef getchar
  194. #undef getchar
  195. #endif /* getchar */
  196. #define getchar(x) coninc(0)
  197. #endif /* STRATUS */
  198.  
  199.  
  200. #ifdef ANYX25
  201. extern int revcall, closgr, cudata;
  202. int x25ver;
  203. extern char udata[];
  204. #ifndef IBMX25
  205. extern int npadx3;
  206. extern CHAR padparms[];
  207. extern struct keytab padx3tab[];
  208. #endif /* !IBMX25 */
  209. #ifdef IBMX25
  210. /* global variables only available for IBM X.25 - possibly interesting for
  211.  * other implementations
  212.  */
  213. extern x25addr_t local_nua;
  214. extern x25addr_t remote_nua;
  215. #endif /* IBMX25 */
  216. #endif /* ANYX25 */
  217.  
  218. #ifdef NETCONN
  219. #ifndef NODIAL
  220. extern int nnetdir;
  221. extern char *netdir[];
  222. #endif /* NODIAL */
  223. extern char ipaddr[];
  224.  
  225. #ifdef CK_NETBIOS
  226. extern unsigned short netbiosAvail;
  227. extern unsigned long NetbeuiAPI;
  228. extern unsigned char NetBiosName[];
  229. extern unsigned char NetBiosAdapter;
  230. extern unsigned char NetBiosLSN;
  231. #endif /* CK_NETBIOS */
  232.  
  233. #ifdef TCPSOCKET
  234. extern char myipaddr[];
  235. extern int tcp_rdns;
  236. #ifdef CK_DNS_SRV
  237. extern int tcp_dns_srv;
  238. #endif /* CK_DNS_SRV */
  239. extern char * tcp_address;
  240. #ifndef NOHTTP
  241. extern char * tcp_http_proxy;
  242. #endif /* NOHTTP */
  243. #ifdef NT
  244. #ifdef CK_SOCKS
  245. extern char * tcp_socks_svr;
  246. #ifdef CK_SOCKS_NS
  247. extern char * tcp_socks_ns;
  248. #endif /* CK_SOCKS_NS */
  249. #endif /* CK_SOCKS */
  250. #endif /* NT */
  251.  
  252. #ifndef NOTCPOPTS
  253. #ifdef SOL_SOCKET
  254. #ifdef SO_LINGER
  255. extern int tcp_linger;
  256. extern int tcp_linger_tmo;
  257. #endif /* SO_LINGER */
  258. #ifdef SO_DONTROUTE
  259. extern int tcp_dontroute;
  260. #endif /* SO_DONTROUTE */
  261. #ifdef TCP_NODELAY
  262. extern int tcp_nodelay;
  263. #endif /* TCP_NODELAY */
  264. #ifdef SO_SNDBUF
  265. extern int tcp_sendbuf;
  266. #endif /* SO_SNDBUF */
  267. #ifdef SO_RCVBUF
  268. extern int tcp_recvbuf;
  269. #endif /* SO_RCVBUF */
  270. #ifdef SO_KEEPALIVE
  271. extern int tcp_keepalive;
  272. #endif /* SO_KEEPALIVE */
  273. #endif /* SOL_SOCKET */
  274. #endif /* NOTCPOPTS */
  275. #endif /* TCPSOCKET */
  276. #endif /* NETCONN */
  277.  
  278. extern char * floname[];
  279.  
  280. #ifndef NOSPL
  281. extern int fndiags;                     /* Function diagnostics on/off */
  282. extern int divbyzero;
  283. int ispattern = 0;
  284. int isjoin = 0;
  285. #ifdef CK_APC
  286. extern int apcactive;                   /* Nonzero = APC command was rec'd */
  287. extern int apcstatus;                   /* Are APC commands being processed? */
  288. #ifdef DCMDBUF
  289. extern char *apcbuf;                    /* APC command buffer */
  290. #else
  291. extern char apcbuf[];
  292. #endif /* DCMDBUF */
  293. #endif /* CK_APC */
  294.  
  295. extern char evalbuf[];                  /* EVALUATE result */
  296. extern char uidbuf[], pwbuf[], prmbuf[];
  297. _PROTOTYP( static char * fneval, (char *, char * [], int, char * ) );
  298. _PROTOTYP( static VOID myflsh, (void) );
  299. _PROTOTYP( static char * getip, (char *) );
  300. _PROTOTYP( int delta2sec, (char *, long *) );
  301.  
  302. #ifdef NEWFTP
  303. _PROTOTYP( char * ftp_cpl_mode, (void) );
  304. _PROTOTYP( char * ftp_dpl_mode, (void) );
  305. _PROTOTYP( char * ftp_authtype, (void) );
  306. #endif /* NEWFTP */
  307.  
  308. #ifndef NOHTTP
  309. _PROTOTYP( char * http_host, (void) );
  310. _PROTOTYP( int http_isconnected, (void) );
  311. _PROTOTYP( char * http_security, (void) );
  312. #endif /* NOHTTP */
  313.  
  314. #ifndef NOSEXP
  315. _PROTOTYP( char * dosexp, (char *) );
  316. int fsexpflag = 0;
  317. #endif /* NOSEXP */
  318.  
  319. static char hexdigits[16] = {
  320.     '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  321. };
  322. extern char * tempdir;
  323.  
  324. #ifdef CK_REXX
  325. extern char rexxbuf[];
  326. #endif /* CK_REXX */
  327.  
  328. extern int tfline[];
  329.  
  330. /* These need to be internationalized... */
  331.  
  332. static
  333. char *wkdays[] = {
  334.     "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  335. };
  336. #endif /* NOSPL */
  337.  
  338. #ifdef OS2
  339. extern char startupdir[], inidir[];
  340. #else
  341. #ifdef VMSORUNIX
  342. extern char startupdir[];
  343. #endif /* VMSORUNIX */
  344. #endif /* OS2 */
  345.  
  346. #ifdef OS2
  347. _PROTOTYP (int os2getcp, (void) );
  348. #ifdef TCPSOCKET
  349. extern char tcpname[];
  350. #endif /* TCPSOCKET */
  351. extern int tcp_avail;
  352. #ifdef DECNET
  353. extern int dnet_avail;
  354. #endif /* DECNET */
  355. #ifdef SUPERLAT
  356. extern int slat_avail;
  357. #endif /* SUPERLAT */
  358.  
  359. #ifndef NOTERM
  360. extern int tt_type, max_tt;
  361. extern struct tt_info_rec tt_info[];
  362. #endif /* NOTERM */
  363. extern int tt_rows[], tt_cols[];
  364. #else /* OS2 */
  365. extern int tt_rows, tt_cols;
  366. #endif /* OS2 */
  367.  
  368. #ifdef CK_TAPI
  369. extern int tttapi;
  370. extern int tapipass;
  371. extern struct keytab * tapilinetab;
  372. extern struct keytab * _tapilinetab;
  373. extern int ntapiline;
  374. #endif /* CK_TAPI */
  375.  
  376. extern struct keytab colxtab[];
  377. extern int ncolx;
  378.  
  379. extern char ttname[], *zinptr, *kermrc;
  380. extern char inidir[];
  381.  
  382. extern int activecmd, remonly, cmd_rows, cmd_cols, parity, seslog,
  383.   sessft, sosi, hwparity, tsecs, xargs, zincnt, tlevel, insilence, cmdmsk,
  384.   timint, timef, inbufsize, dialog, binary, carrier, cdtimo, cmask, duplex,
  385.   fmask, inecho, nmac, turnch, turn, kbchar;
  386.  
  387. #ifndef NOXFER
  388. extern CHAR eol,  mypadc, mystch, padch, seol, stchr, * epktmsg, feol;
  389. extern char *cksysid;
  390. extern struct ck_p ptab[];
  391. extern int
  392.   protocol, prefixing, xfrbel, xfrcan, xfrint, xfrchr, xfrnum, pktpaus,
  393.   lscapr, lscapu, xfermode, dest, slostart, maxrps, maxsps, maxtry, mypadn,
  394.   npad, pkttim, bigrbsiz, bigsbsiz, keep, atcapr, autopar, bctr, bctu,
  395.   crunched, ckdelay, ebq, ebqflg, pktlog, retrans, rpackets, rptflg, rptq,
  396.   rtimo, spackets, spsiz, spsizf, spsizr, timeouts, fncact, fncnv, urpsiz,
  397.   wmax, wslotn, wslotr, fdispla, spmax, fnrpath, fnspath, crc16;
  398. #endif /* NOXFER */
  399.  
  400. #ifdef OS2
  401. extern int zxpn;
  402. extern int viewonly;
  403. #endif /* OS2 */
  404.  
  405. #ifndef NOXFER
  406. #ifdef GFTIMER
  407. extern CKFLOAT fptsecs, fpxfsecs;
  408. #endif /* GFTIMER */
  409. extern long xfsecs, tfcps;
  410.  
  411. #ifdef CK_TMPDIR
  412. extern char *dldir;
  413. #endif /* CK_TMPDIR */
  414. #endif /* NOXFER */
  415.  
  416. #ifdef RECURSIVE
  417. extern int recursive;
  418. #endif /* RECURSIVE */
  419.  
  420. #ifdef VMS
  421.   extern int frecl;
  422. #endif /* VMS */
  423.  
  424. extern long
  425.   ffc, filcnt, rptn, speed, tfc, tlci, tlco, ccu, ccp, vernum, xvernum;
  426.  
  427. #ifndef NOSPL
  428. extern char fspec[], myhost[];
  429. #endif /* NOSPL */
  430.  
  431. extern char *tfnam[];                   /* Command file names */
  432.  
  433. extern char pktfil[],                   /* Packet log file name */
  434. #ifdef TLOG
  435.   trafil[],                             /* Transaction log file name */
  436. #endif /* TLOG */
  437.   sesfil[];                             /* Session log file name */
  438.  
  439. #ifndef NOXMIT                          /* TRANSMIT command variables */
  440. extern char xmitbuf[];
  441. extern int xmitf, xmitl, xmitx, xmits, xmitw, xmitt;
  442. #endif /* NOXMIT */
  443.  
  444. extern int cmdlvl;
  445.  
  446. #ifndef NOSPL
  447. /* Script programming language items */
  448. extern char **a_ptr[];                  /* Arrays */
  449. extern int a_dim[];
  450. static char * inpmatch = NULL;
  451. #ifdef CKFLOAT
  452. char * inpscale = NULL;
  453. #endif    /* CKFLOAT */
  454. extern char * inpbuf, inchar[];         /* Buffers for INPUT and REINPUT */
  455. extern char *inpbp;                     /* And pointer to same */
  456. static char *r3 = (char *)0;
  457. extern int incount;                     /* INPUT character count */
  458. extern int m_found;                     /* MINPUT result */
  459. extern int maclvl;                      /* Macro invocation level */
  460. extern struct mtab *mactab;             /* Macro table */
  461. extern char *mrval[];
  462. extern int macargc[], topargc;
  463.  
  464. #ifdef COMMENT
  465. extern char *m_line[];
  466. extern char *topline;
  467. #endif /* COMMENT */
  468.  
  469. extern char *m_arg[MACLEVEL][10]; /* You have to put in the dimensions */
  470. extern char *g_var[GVARS];        /* for external 2-dimensional arrays. */
  471. #ifdef DCMDBUF
  472. extern int *count, *inpcas;
  473. #else
  474. extern int count[], inpcas[];
  475. #endif /* DCMDBUF */
  476. #endif /* NOSPL */
  477.  
  478. #ifdef UNIX
  479. extern int haslock;                     /* For UUCP locks */
  480. extern char flfnam[];
  481. #ifndef USETTYLOCK
  482. extern char lock2[];
  483. #endif /* USETTYLOCK */
  484. #endif /* UNIX */
  485.  
  486. #ifdef OS2ORUNIX
  487. extern int maxnam, maxpath;             /* Longest name, path length */
  488. #endif /* OS2ORUNIX */
  489.  
  490. extern int mdmtyp, mdmsav;
  491.  
  492. #ifndef NODIAL
  493. /* DIAL-related variables */
  494. extern char modemmsg[];
  495. extern MDMINF *modemp[];                /* Pointers to modem info structs */
  496. extern int nmdm, dialhng, dialtmo, dialksp, dialdpy, dialsrt, dialsta;
  497. extern int dialrtr, dialint, dialrstr, dialcon, dialcq, dialfld;
  498. extern int mdmspd, dialec, dialdc, dialmth, dialmauto, dialesc;
  499. extern char *dialnum,   *dialini,  *dialdir[], *dialcmd,  *dialnpr,
  500.  *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd, *diallac,
  501.  *dialhwfc, *dialswfc,  *dialnofc, *dialpulse, *dialtone, *dialname,
  502.  *dialaaon, *dialaaoff, *dialmac;
  503. extern char *diallcc,   *dialixp,  *dialixs,   *dialldp,  *diallds,
  504.  *dialpxi,  *dialpxo,   *dialsfx,  *dialtfp;
  505. extern char *diallcp,   *diallcs;
  506. extern int ntollfree, ndialpxx, nlocalac;
  507. extern char *dialtfc[], *diallcac[], *dialpxx[], *matchpxx;
  508. extern int ndialpucc, ndialtocc;
  509. extern char *dialtocc[], *dialpucc[];
  510. extern int ndialdir, dialcnf, dialcvt, dialidt, dialpace;
  511. extern long dialmax, dialcapas;
  512.  
  513. extern struct keytab mdmtab[];
  514.  
  515. #ifdef BIGBUFOK
  516. #define ARGBUFSIZ 8191
  517. #else
  518. #define ARGBUFSIZ 1023
  519. #endif /* BIGBUFOK */
  520.  
  521. #ifdef BIGBUFOK
  522. extern char * dialmsg[];
  523. #endif /* BIGBUFOK */
  524.  
  525. #endif /* NODIAL */
  526.  
  527. #ifndef NOCSETS
  528. /* Translation stuff */
  529. extern int fcharset, tcharset, tslevel, language, nlng, tcsr, tcsl;
  530. extern int dcset7, dcset8;
  531. extern struct keytab lngtab[];
  532. extern struct csinfo fcsinfo[], tcsinfo[];
  533. extern struct langinfo langs[];
  534. #ifdef CK_ANSIC
  535. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  536. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  537. #else
  538. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(); /* Character set */
  539. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(); /* translation functions. */
  540. #endif /* CK_ANSIC */
  541. #ifdef UNICODE
  542.     extern int ucsbom, ucsorder;
  543. #endif /* UNICODE */
  544. #endif /* NOCSETS */
  545.  
  546. #ifndef NOSPL
  547. /* Built-in variable names, maximum length VNAML (20 characters) */
  548.  
  549. struct keytab vartab[] = {
  550.     { "_line",     VN_TFLN,  CM_INV},   /* 192 */
  551. #ifdef OS2
  552.     { "_regname",  VN_REGN,  CM_INV},   /* 1.1.12 */
  553.     { "_regorg",   VN_REGO,  CM_INV},   /* 1.1.12 */
  554.     { "_regnum",   VN_REGS,  CM_INV},   /* 1.1.12 */
  555. #endif /* OS2 */
  556.     { "apcactive", VN_APC,   CM_INV},   /* 192 */
  557. #ifdef NT
  558.     { "appdata",   VN_APPDATA, 0},      /* 201 */
  559. #endif /* NT */
  560.     { "argc",      VN_ARGC,  0},
  561.     { "args",      VN_ARGS,  0},
  562.     { "authname",  VN_AUTHN, 0},        /* 196 */
  563.     { "authstate", VN_AUTHS, 0},        /* 195 */
  564.     { "authtype",  VN_AUTHT, 0},        /* 195 */
  565.     { "blockcheck",VN_BLK,   0},        /* 195 */
  566. #ifdef BROWSER
  567.     { "browser",   VN_BROWSR,0},        /* 193 */
  568.     { "browsopts", VN_BROPT, 0},        /* 193 */
  569.     { "browsurl",  VN_URL,   0},        /* 193 */
  570.     { "buildid",   VN_BUILD, 0},        /* 199 */
  571. #endif /* BROWSER */
  572.     { "byteorder", VN_BYTE,  0},        /* 195 */
  573. #ifndef NOCSETS
  574.     { "charset",   VN_CSET,  0},        /* 192 */
  575. #endif /* NOCSETS */
  576.     { "cmdbufsize",VN_CMDBL, 0},        /* 195 */
  577.     { "cmdfile",   VN_CMDF,  0},
  578.     { "cmdlevel",  VN_CMDL,  0},
  579.     { "cmdsource", VN_CMDS,  0},
  580.     { "cols",      VN_COLS,  0},        /* 190 */
  581. #ifdef NT
  582.     { "common",    VN_COMMON, 0},       /* 201 */
  583. #endif /* NT */
  584.     { "connection",VN_CONN,  0},        /* 190 */
  585.     { "count",     VN_COUN,  0},
  586. #ifndef NOXFER
  587.     { "cps",       VN_CPS,   0},        /* 190 */
  588. #endif /* NOXFER */
  589.     { "cpu",       VN_CPU,   0},
  590. #ifndef NOXFER
  591.     { "crc16",     VN_CRC16, 0},        /* 192 */
  592.     { "ctty",      VN_TTYNAM,0},        /* 196 */
  593. #endif /* NOXFER */
  594. #ifndef NOLOGDIAL
  595. #ifndef NOLOCAL
  596.     { "cx_time",   VN_CXTIME,0},        /* 195 */
  597.     { "cx_status", VN_CX_STA,0},        /* 199 */
  598. #endif /* NOLOCAL */
  599. #endif /* NOLOGDIAL */
  600. #ifndef NODIAL
  601.     { "d$ac",      VN_D_AC,  0},        /* 192 */
  602.     { "d$cc",      VN_D_CC,  0},        /* 192 */
  603.     { "d$ip",      VN_D_IP,  0},        /* 192 */
  604.     { "d$lc",      VN_D_LCP, 0},        /* 193 */
  605.     { "d$lcp",     VN_D_LCP, CM_INV},   /* 193 */
  606.     { "d$lp",      VN_D_LP,  0},        /* 192 */
  607.     { "d$px",      VN_D_PXX, 0},        /* 195 */
  608.     { "d$pxx",     VN_D_PXX, CM_INV},   /* 195 */
  609. #endif /* NODIAL */
  610.     { "date",      VN_DATE,  0},
  611.     { "day",       VN_DAY,   0},
  612. #ifdef NT
  613.     { "desktop",   VN_DESKTOP, 0},     /* 201 */
  614. #endif /* NT */
  615. #ifndef NODIAL
  616.     { "dialcount", VN_DRTR,  0},        /* 195 */
  617.     { "dialnumber",VN_DNUM,  0},        /* 192 */
  618.     { "dialresult",VN_MDMSG, 0},        /* 192 */
  619.     { "dialstatus",VN_DIAL,  0},        /* 190 */
  620.     { "dialsuffix",VN_PDSFX, 0},        /* 193 */
  621.     { "dialtype",  VN_DTYPE, 0},        /* 193 */
  622. #endif /* NODIAL */
  623.     { "directory", VN_DIRE,  0},
  624. #ifndef NODIAL
  625.     { "dm_hf",     VN_DM_HF, 0},        /* 199 */
  626.     { "dm_lp",     VN_DM_LP, 0},        /* 195 */
  627.     { "dm_sp",     VN_DM_SP, 0},        /* 195 */
  628.     { "dm_pd",     VN_DM_PD, 0},        /* 195 */
  629.     { "dm_td",     VN_DM_TD, 0},        /* 195 */
  630.     { "dm_wa",     VN_DM_WA, 0},        /* 195 */
  631.     { "dm_wb",     VN_DM_WB, 0},        /* 199 */
  632.     { "dm_wd",     VN_DM_WD, 0},        /* 195 */
  633.     { "dm_rc",     VN_DM_RC, 0},        /* 195 */
  634. #endif /* NODIAL */
  635. #ifndef NOXFER
  636.     { "download",  VN_DLDIR, 0},        /* 192 */
  637. #endif /* NOXFER */
  638.     { "editor",    VN_EDITOR,0},
  639.     { "editfile",  VN_EDFILE,0},
  640.     { "editopts",  VN_EDOPT, 0},
  641.     { "errno",     VN_ERRNO, 0},        /* 192 */
  642.     { "errstring", VN_ERSTR, 0},        /* 192 */
  643.     { "escape",    VN_ESC,   0},        /* 193 */
  644.     { "evaluate",  VN_EVAL,  0},        /* 190 */
  645. #ifdef OS2ORUNIX
  646.     { "exedir",    VN_EXEDIR,0},        /* 192 */
  647. #endif /* OS2ORUNIX */
  648.     { "exitstatus",VN_EXIT,  0},
  649. #ifdef CKCHANNELIO
  650.     { "f_count",   VN_FCOU,  0},        /* 195 */
  651.     { "f_error",   VN_FERR,  0},        /* 195 */
  652.     { "f_max",     VN_FMAX,  0},        /* 195 */
  653.     { "fileerror", VN_FERR,  CM_INV},   /* 195 */
  654.     { "filemax",   VN_FERR,  CM_INV},   /* 195 */
  655. #endif /* CKCHANNELIO */
  656.     { "filename",  VN_FNAM,  0},        /* 193 */
  657.     { "filenumber",VN_FNUM,  0},        /* 193 */
  658.     { "filespec",  VN_FILE,  0},
  659.     { "fsize",     VN_FFC,   0},        /* 190 */
  660. #ifdef GFTIMER
  661.     { "ftime",     VN_FTIME, 0},        /* 199 */
  662. #else
  663.     { "ftime",     VN_NTIM,  CM_INV},
  664. #endif /* GFTIMER */
  665. #ifndef NOFTP
  666. #ifndef SYSFTP
  667.     { "ftp_code",         VN_FTP_C, 0}, /* 199 */
  668.     { "ftp_cpl",          VN_FTP_B, 0}, /* 199 */
  669.     { "ftp_connected",    VN_FTP_X, 0}, /* 199 */
  670.     { "ftp_dpl",          VN_FTP_D, 0}, /* 199 */
  671.     { "ftp_getputremote", VN_FTP_G, 0}, /* 199 */
  672.     { "ftp_host",         VN_FTP_H, 0}, /* 199 */
  673.     { "ftp_loggedin",     VN_FTP_L, 0}, /* 199 */
  674.     { "ftp_message",      VN_FTP_M, 0}, /* 199 */
  675.     { "ftp_msg",          VN_FTP_M, CM_INV}, /* 199 */
  676.     { "ftp_security",     VN_FTP_Z, 0}, /* 199 */
  677.     { "ftp_server",       VN_FTP_S, 0}, /* 199 */
  678. #endif /* SYSFTP */
  679. #endif /* NOFTP */
  680.     { "ftype",     VN_MODE,  0},        /* 190 */
  681. #ifdef KUI
  682.     { "gui_fontname", VN_GUI_FNM, 0},    /* 205 */
  683.     { "gui_fontsize", VN_GUI_FSZ, 0},    /* 205 */
  684.     { "gui_runmode", VN_GUI_RUN, 0},    /* 205 */
  685.     { "gui_xpos",    VN_GUI_XP,  0},    /* 205 */
  686.     { "gui_xres",    VN_GUI_XR,  0},    /* 205 */
  687.     { "gui_ypos",    VN_GUI_YP,  0},    /* 205 */
  688.     { "gui_yres",    VN_GUI_YR,  0},    /* 205 */
  689. #endif /* KUI */
  690.     { "herald",    VN_HERALD, 0},
  691.     { "home",      VN_HOME,   0},
  692.     { "host",      VN_HOST,   0},
  693.     { "hour",      VN_HOUR,   0},       /* 200 */
  694. #ifndef NOHTTP
  695.     { "http_code",      VN_HTTP_C, 0},  /* 199 */
  696.     { "http_connected", VN_HTTP_N, 0},  /* 199 */
  697.     { "http_host",      VN_HTTP_H, 0},  /* 199 */
  698.     { "http_message",   VN_HTTP_M, 0},  /* 199 */
  699.     { "http_security",  VN_HTTP_S, 0},  /* 199 */
  700. #endif /* NOHTTP */
  701.     { "hwparity",  VN_HWPAR, 0},        /* 195 */
  702.     { "input",     VN_IBUF,  0},
  703.     { "inchar",    VN_ICHR,  0},
  704.     { "incount",   VN_ICNT,  0},
  705.     { "inidir",    VN_INI,   0},        /* 192 */
  706.     { "inmatch",   VN_MATCH, 0},        /* 196 */
  707.     { "inscale",   VN_ISCALE,0},        /* 210 */
  708.     { "instatus",  VN_ISTAT, 0},        /* 192 */
  709.     { "intime",    VN_INTIME,0},        /* 193 */
  710.     { "inwait",    VN_INTMO, 0},        /* 195 */
  711.     { "ip",        VN_IPADDR, CM_ABR|CM_INV},
  712.     { "ipaddress", VN_IPADDR,0},        /* 192 */
  713.     { "iprompt",   VN_PROMPT,0},        /* 199 */
  714.     { "kbchar",    VN_KBCHAR,0},        /* 196 */
  715. #ifndef NOLOCAL
  716. #ifdef OS2
  717.     { "keyboard",  VN_KEYB,  0},
  718. #endif /* OS2 */
  719. #endif /* NOLOCAL */
  720. #ifdef CK_KERBEROS
  721.     { "krb4errmsg",    VN_K4EMSG,0},
  722.     { "krb4errno",     VN_K4ENO, 0},
  723.     { "krb4principal", VN_K4PRN, 0},
  724.     { "krb4realm",     VN_K4RLM, 0},
  725.     { "krb4service",   VN_K4SRV, 0},
  726.     { "krb5cc",        VN_K5CC,  0},
  727.     { "krb5errmsg",    VN_K5EMSG,0},
  728.     { "krb5errno",     VN_K5ENO, 0},
  729.     { "krb5principal", VN_K5PRN, 0},
  730.     { "krb5realm",     VN_K5RLM, 0},
  731.     { "krb5service",   VN_K5SRV, 0},
  732. #endif /* CK_KERBEROS */
  733.     { "line",      VN_LINE,  0},
  734.     { "local",     VN_LCL,   0},
  735. #ifdef UNIX
  736.     { "lockdir",   VN_LCKDIR,0},        /* 195 */
  737.     { "lockpid",   VN_LCKPID,0},        /* 195 */
  738. #endif /* UNIX */
  739.     { "log_connection", VN_LOG_CON, 0}, /* 206 */
  740.     { "log_debug", VN_LOG_DEB, 0},      /* 206 */
  741.     { "log_packet", VN_LOG_PKT, 0},     /* 206 */
  742.     { "log_session", VN_LOG_SES, 0},    /* 206 */
  743.     { "log_transaction", VN_LOG_TRA, 0},/* 206 */
  744.     { "maclevel",  VN_MACLVL,0},        /* 195 */
  745.     { "macro",     VN_MAC,   0},
  746. #ifdef FNFLOAT
  747.     { "math_e",    VN_MA_E,  0},        /* 195 */
  748.     { "math_pi",   VN_MA_PI, 0},        /* 195 */
  749.     { "math_precision", VN_MA_PR, 0},   /* 195 */
  750. #endif /* FNFLOAT */
  751.     { "minput",    VN_MINP,  0},        /* 192 */
  752.     { "model",     VN_MODL,  0},        /* 193 */
  753.     { "modem",     VN_MDM,   0},
  754. #ifndef NOLOCAL
  755. #ifdef OS2
  756.     { "mousecurx", VN_MOU_X, 0},        /* K95 1.1.14 */
  757.     { "mousecury", VN_MOU_Y, 0},        /* K95 1.1.14 */
  758. #endif /* OS2 */
  759. #endif /* NOLOCAL */
  760. #ifndef NODIAL
  761.     { "m_aa_off",  VN_M_AAX, 0},        /* all 192... */
  762.     { "m_aa_on",   VN_M_AAO, 0},
  763.     { "m_dc_off",  VN_M_DCX, 0},
  764.     { "m_dc_on",   VN_M_DCO, 0},
  765.     { "m_dial",    VN_M_DCM, 0},
  766.     { "m_ec_off",  VN_M_ECX, 0},
  767.     { "m_ec_on",   VN_M_ECO, 0},
  768.     { "m_fc_hw",   VN_M_HWF, 0},
  769.     { "m_fc_no",   VN_M_NFC, 0},
  770.     { "m_fc_sw",   VN_M_SWF, 0},
  771.     { "m_hup",     VN_M_HUP, 0},
  772.     { "m_init",    VN_M_INI, 0},
  773.     { "m_name",    VN_M_NAM, 0},        /* 195 */
  774.     { "m_pulse",   VN_M_PDM, 0},
  775.     { "m_sig_cd",  VN_MS_CD, 0},        /* 195 */
  776.     { "m_sig_cts", VN_MS_CTS,0},        /* 195 */
  777.     { "m_sig_dsr", VN_MS_DSR,0},        /* 195 */
  778.     { "m_sig_dtr", VN_MS_DTR,0},        /* 195 */
  779.     { "m_sig_ri",  VN_MS_RI, 0},        /* 195 */
  780.     { "m_sig_rts", VN_MS_RTS,0},        /* 195 */
  781.     { "m_tone",    VN_M_TDM, 0},
  782. #endif /* NODIAL */
  783.     { "name",      VN_NAME,  0},
  784.     { "ndate",     VN_NDAT,  0},
  785.     { "nday",      VN_NDAY,  0},
  786.     { "newline",   VN_NEWL,  0},
  787.     { "ntime",     VN_NTIM,  0},
  788.     { "osname",    VN_OSNAM, 0},        /* 193 */
  789.     { "osrelease", VN_OSREL, 0},        /* 193 */
  790.     { "osversion", VN_OSVER, 0},        /* 193 */
  791. #ifndef NOXFER
  792.     { "packetlen", VN_RPSIZ, 0},        /* 192 */
  793. #endif /* NOXFER */
  794.     { "parity",    VN_PRTY,  0},        /* 190 */
  795.     { "password",  VN_PWD,   CM_INV},   /* 192 */
  796. #ifdef NT
  797.     { "personal",  VN_PERSONAL, 0},     /* 201 */
  798. #endif /* NT */
  799. #ifdef PEXITSTAT
  800.     { "pexitstat", VN_PEXIT, 0},        /* 193 */
  801. #endif /* PEXITSTAT */
  802. #ifdef CK_PID
  803.     { "pid",       VN_PID,   0},        /* 193 */
  804. #endif /* CK_PID */
  805.     { "platform",  VN_SYSV,  0},
  806.     { "printer",   VN_PRINT, 0},        /* 193 */
  807.     { "program",   VN_PROG,  0},
  808.     { "prompt",    VN_PRM,   CM_INV},   /* 192 */
  809. #ifndef NOXFER
  810.     { "protocol",  VN_PROTO, 0},        /* 192 */
  811.     { "p_8bit",    VN_P_8BIT,0},        /* 193 */
  812.     { "p_ctl",     VN_P_CTL, 0},        /* 193 */
  813.     { "p_rpt",     VN_P_RPT, 0},        /* 193 */
  814.     { "query",     VN_QUE,   0},        /* 190 */
  815. #endif /* NOXFER */
  816.     { "return",    VN_RET,   0},
  817. #ifdef CK_REXX
  818.     { "rexx",      VN_REXX,  0},        /* 190 */
  819. #endif /* CK_REXX */
  820. #ifdef TN_COMPORT
  821.     { "rfc2217_signature", VN_TNC_SIG, 0}, /* 201 */
  822.     { "rfc2717_signature", VN_TNC_SIG, CM_INV}, /* 202 */
  823. #endif /* TN_COMPORT */
  824.     { "rows",      VN_ROWS,  0},        /* 190 */
  825. #ifndef NOSEXP
  826.     { "sdepth",    VN_LSEXP,0},         /* 199 */
  827. #endif /* NOSEXP */
  828.     { "secure",    VN_SECURE, 0},       /* 199 */
  829. #ifndef NOLOCAL
  830. #ifdef OS2
  831.     { "select",    VN_SELCT, 0},        /* 192 */
  832. #endif /* OS2 */
  833. #endif /* NOLOCAL */
  834.     { "sendlist",  VN_SNDL,  0},
  835.     { "serial",    VN_SERIAL,0},        /* 195 */
  836.     { "setlinemsg",VN_SLMSG, 0},        /* 195 */
  837. #ifndef NOSEXP
  838.     { "sexpression",VN_SEXP, 0},        /* 199 */
  839. #endif /* NOSEXP */
  840.     { "speed",     VN_SPEE,  0},
  841. #ifdef OS2
  842.     { "space",     VN_SPA,   0},
  843.     { "startup",   VN_STAR,  0},        /* 190 */
  844. #else
  845. #ifdef UNIX
  846.     { "startup",   VN_STAR,  0},        /* 193 */
  847. #else
  848. #ifdef VMS
  849.     { "startup",   VN_STAR,  0},        /* 193 */
  850. #endif /* VMS */
  851. #endif /* UNIX */
  852. #endif /* OS2 */
  853.     { "status",    VN_SUCC,  0},
  854. #ifndef NOSEXP
  855.     { "svalue",    VN_VSEXP, 0},        /* 199 */
  856. #endif /* NOSEXP */
  857. #ifndef NOXFER
  858.     { "sysid",     VN_SYSI,  0},
  859. #endif /* NOXFER */
  860.     { "system",    VN_SYST,  0},
  861.     { "terminal",  VN_TTYP,  0},
  862. #ifdef OS2
  863. #ifndef NOKVERBS
  864.     { "termkey",   VN_TRMK,  CM_INV},   /* 192 */
  865. #endif /* NOKVERBS */
  866. #endif /* OS2 */
  867.     { "test",      VN_TEST,  0},        /* 193 */
  868.     { "textdir",   VN_TXTDIR,0},        /* 195 */
  869. #ifndef NOXFER
  870.     { "tfsize",    VN_TFC,   0},
  871.     { "tftime",    VN_TFTIM, 0},        /* 195 */
  872. #endif /* NOXFER */
  873.     { "time",      VN_TIME,  0},
  874.     { "timestamp", VN_NOW,   0},        /* 200 */
  875.     { "tmpdir",    VN_TEMP,  0},        /* 192 */
  876. #ifdef CK_TRIGGER
  877.     { "trigger",   VN_TRIG,  0},        /* 193 */
  878. #endif /* CK_TRIGGER */
  879. #ifdef CK_TTYFD
  880.     { "ttyfd",     VN_TTYF,  0},
  881. #endif /* CK_TTYFD */
  882.     { "ty_ln",     VN_TY_LN, 0},        /* 195 */
  883.     { "ty_lc",     VN_TY_LC, 0},        /* 195 */
  884.     { "ty_lm",     VN_TY_LM, 0},        /* 195 */
  885. #ifdef BROWSER
  886.     { "url",       VN_URL,   CM_INV},   /* 193 */
  887. #endif /* BROWSER */
  888.     { "userid",    VN_UID,   0},        /* 192 */
  889.     { "version",   VN_VERS,  0},
  890. #ifndef NOXFER
  891.     { "window",    VN_WINDO, 0},        /* 192 */
  892. #endif /* NOXFER */
  893. #ifdef IBMX25
  894.     { "x25local_nua", VN_X25LA, 0},     /* 193 */
  895.     { "x25remote_nua", VN_X25RA, 0},    /* 193 */
  896. #endif /* IBMX25 */
  897. #ifdef CK_SSL
  898.     { "x509_issuer",  VN_X509_I, 0},
  899.     { "x509_subject", VN_X509_S, 0},
  900. #endif /* CK_SSL */
  901. #ifndef NOXFER
  902.     { "xferstatus",VN_XFSTAT,0},        /* 193 */
  903.     { "xfermsg",   VN_XFMSG, 0},        /* 193 */
  904.     { "xfer_badpackets", VN_XF_BC, 0},  /* 195 */
  905.     { "xfer_timeouts",   VN_XF_TM, 0},  /* 195 */
  906.     { "xfer_retransmits",VN_XF_RX, 0},  /* 195 */
  907. #endif /* NOXFER */
  908.     { "xprogram",  VN_XPROG, 0},        /* 193 */
  909.     { "xversion",  VN_XVNUM, 0}         /* 192 */
  910. };
  911. int nvars = (sizeof(vartab) / sizeof(struct keytab));
  912. #endif /* NOSPL */
  913.  
  914. #ifndef NOSPL
  915. struct keytab fnctab[] = {              /* Function names */
  916. #ifdef OS2
  917.     { ".oox",       FN_OOX, CM_INV},    /* ... */
  918. #endif /* OS2 */
  919.  
  920. #ifdef CKCHANNELIO
  921.     { "_eof",       FN_FEOF,   0},
  922.     { "_errmsg",    FN_FERMSG, 0},
  923.     { "_getblock",  FN_FGBLK,  0},
  924.     { "_getchar",   FN_FGCHAR, 0},
  925.     { "_getline",   FN_FGLINE, 0},
  926.     { "_handle",    FN_FILNO,  0},
  927.     { "_line",      FN_NLINE,  0},
  928.     { "_pos",       FN_FPOS,   0},
  929.     { "_putblock",  FN_FPBLK,  0},
  930.     { "_putchar",   FN_FPCHAR, 0},
  931.     { "_putline",   FN_FPLINE, 0},
  932.     { "_status",    FN_FSTAT,  0},
  933. #endif /* CKCHANNELIO */
  934.  
  935.     { "aaconvert",  FN_AADUMP, 0},      /* Associative Array conversion */
  936.     { "absolute",   FN_ABS,  0},        /* Absolute value */
  937. #ifdef TCPSOCKET
  938.     { "addr2name",  FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  939.     { "addrtoname", FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  940. #endif /* TCPSOCKET */
  941.     { "arraylook",  FN_ALOOK,0},        /* Array lookup */
  942.     { "b64decode",  FN_FMB64,0},        /* Base-64 conversion */
  943.     { "b64encode",  FN_TOB64,0},        /* ... */
  944.     { "basename",   FN_BSN,  0},        /* Basename */
  945.     { "break",      FN_BRK,  0},        /* Break (as in Snobol) */
  946.     { "ca",         FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  947.     { "cap",        FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  948.     { "capitalize", FN_CAP,  0},        /* First Letter -> uppercase */
  949.     { "caps",       FN_CAP,  CM_INV},   /* ditto */
  950.     { "character",  FN_CHR,  0},        /* Character from code */
  951.     { "checksum",   FN_CHK,  0},        /* Checksum */
  952.     { "cmdstack",   FN_CMDSTK,0},       /* Command stack */
  953.     { "cmpdates",   FN_CMPDATE,0},      /* Compare dates */
  954.     { "code",       FN_COD,  0},        /* Code from character */
  955. #ifndef NOPUSH
  956.     { "command",    FN_CMD,  0},        /* Output from a command */
  957. #endif /* NOPUSH */
  958.     { "contents",   FN_CON,  0},        /* Definition (contents) of variable */
  959.     { "crc16",      FN_CRC,  0},        /* CRC-16 */
  960. #ifdef OS2
  961.     { "crypt",      FN_CRY, CM_INV},
  962. #endif /* OS2 */
  963.     { "cvtdate",    FN_DTIM, 0},        /* Convert free date/time to std */
  964. #ifdef ZFCDAT
  965.     { "date",       FN_FD,   0},        /* File modification/creation date */
  966. #endif /* ZFCDAT */
  967.     { "day",        FN_DAY,  0},        /* Day of week */
  968.     { "dayofyear",  FN_JDATE,0},        /* Date to Day of Year */
  969.     { "definition", FN_DEF,  0},        /* Return definition of given macro */
  970.     { "delta2secs", FN_DELSEC, 0},      /* Delta time to seconds */
  971.     { "deltatosecs", FN_DELSEC, CM_INV}, /* Delta time to seconds */
  972. #ifndef NODIAL
  973.     { "dialconvert",FN_PNCVT,0},        /* Convert portable phone number */
  974. #endif /* NODIAL */
  975.     { "diffdates",  FN_DIFDATE,0},      /* Difference of two date-times */
  976.     { "dimension",  FN_DIM,  0},        /* Dimension of array */
  977.     { "directories",FN_DIR,  0},        /* List of directories */
  978.     { "dirname",    FN_DNAM, 0},        /* Directory part of filename */
  979.     { "dos2unixpath",FN_PC_DU, },       /* DOS to UNIX path */
  980.     { "dostounixpath",FN_PC_DU, CM_INV}, /* DOS to UNIX path */
  981.     { "doy",        FN_JDATE,CM_INV},   /* Date to Day of Year */
  982.     { "doy2date",   FN_DATEJ,0},        /* Day of Year to date */
  983.     { "doytodate",  FN_DATEJ,CM_INV},   /* Day of Year to date */
  984. #ifdef FN_ERRMSG
  985.     { "errstring",  FN_ERRMSG,0},       /* Error code to message */
  986. #endif /* FN_ERRMSG */
  987.     { "evaluate",   FN_EVA,  0},        /* Evaluate given arith expression */
  988.     { "execute",    FN_EXE,  0},        /* Execute given macro */
  989.     { "files",      FN_FC,   0},        /* File count */
  990. #ifdef FNFLOAT
  991.     { "fpabsolute", FN_FPABS, 0},       /* Floating-point absolute value */
  992.     { "fpadd",      FN_FPADD, 0},       /* FP add */
  993.     { "fpcosine",   FN_FPCOS, 0},       /* FP cosine */
  994.     { "fpdivide",   FN_FPDIV, 0},       /* FP divide */
  995.     { "fpexp",      FN_FPEXP, 0},       /* FP e to the x */
  996.     { "fpint",      FN_FPINT, 0},       /* FP to integer */
  997.     { "fplog10",    FN_FPLOG, 0},       /* FP base-10 logarithm */
  998.     { "fplogn",     FN_FPLN,  0},       /* FP natural logarithm */
  999.     { "fpmaximum",  FN_FPMAX, 0},       /* FP maxinum */
  1000.     { "fpminimum",  FN_FPMIN, 0},       /* FP mininum */
  1001.     { "fpmodulus",  FN_FPMOD, 0},       /* FP modulus */
  1002.     { "fpmultiply", FN_FPMUL, 0},       /* FP multiply */
  1003.     { "fpraise",    FN_FPPOW, 0},       /* FP raise to a power */
  1004.     { "fpround",    FN_FPROU, 0},       /* FP round */
  1005.     { "fpsine",     FN_FPSIN, 0},       /* FP sine */
  1006.     { "fpsqrt",     FN_FPSQR, 0},       /* FP square root */
  1007.     { "fpsubtract", FN_FPSUB, 0},       /* FP subtract */
  1008.     { "fptangent",  FN_FPTAN, 0},       /* FP tangent */
  1009. #endif /* FNFLOAT */
  1010.     { "hex2ip",     FN_HEX2IP,0},       /* Hex to IP address */
  1011.     { "hextoip",    FN_HEX2IP,CM_INV},  /* Hex to IP address */
  1012.     { "hex2n",      FN_HEX2N, CM_INV},  /* Hex to decimal number */
  1013.     { "hexify",     FN_HEX,   0},       /* Hexify (string) */
  1014.     { "index",      FN_IND,   0},       /* Index (string search) */
  1015.     { "ip2hex",     FN_IP2HEX,0},       /* IP address to hex */
  1016.     { "iptohex",    FN_IP2HEX,CM_INV},  /* IP address to hex */
  1017.     { "ipaddress",  FN_IPA,   0},       /* Find and return IP address */
  1018.     { "jdate",      FN_JDATE, CM_INV},  /* Date to Day of Year */
  1019.     { "join",       FN_JOIN,  0},       /* Join array elements */
  1020.     { "keywordvalue",  FN_KWVAL, 0},    /* Keyword=Value */
  1021. #ifdef CK_KERBEROS
  1022.     { "krbflags",      FN_KRB_FG, 0},   /* Kerberos functions */
  1023.     { "krbisvalid",    FN_KRB_IV, 0},
  1024.     { "krbnextticket", FN_KRB_NX, 0},
  1025.     { "krbtickets",    FN_KRB_TK, 0},
  1026.     { "krbtimeleft",   FN_KRB_TT, 0},
  1027. #endif /* CK_KERBEROS */
  1028.     { "left",       FN_LEF,  0},        /* Leftmost n characters of string */
  1029.     { "length",     FN_LEN,  0},        /* Return length of argument */
  1030.     { "literal",    FN_LIT,  0},        /* Return argument literally */
  1031. #ifdef NT
  1032.     { "longpathname",FN_LNAME,0},    /* GetLongPathName() */
  1033. #else
  1034.     { "longpathname",FN_FFN,CM_INV},
  1035. #endif /* NT */
  1036.     { "lop",        FN_STL,  0},        /* Lop */
  1037.     { "lower",      FN_LOW,  0},        /* Return lowercased argument */
  1038.     { "lpad",       FN_LPA,  0},        /* Return left-padded argument */
  1039.     { "ltrim",      FN_LTR,  0},        /* Left-Trim */
  1040.     { "maximum",    FN_MAX,  0},        /* Return maximum of two arguments */
  1041.     { "minimum",    FN_MIN,  0},        /* Return minimum of two arguments */
  1042.     { "mjd",        FN_MJD,  0},        /* Date to Modified Julian Date */
  1043.     { "mjd2date",   FN_MJD2, 0},        /* MJD to Date */
  1044.     { "mjdtodate",  FN_MJD2, CM_INV},   /* MJD to Date */
  1045.     { "modulus",    FN_MOD,  0},        /* Return modulus of two arguments */
  1046. #ifdef COMMENT
  1047.     { "msleep",     FN_MSLEEP,0},       /* Sleep for n milliseconds */
  1048. #endif /* COMMENT */
  1049.     { "n2hex",      FN_2HEX, CM_INV},   /* Number to hex */
  1050.     { "n2octal",    FN_2OCT, CM_INV},   /* Number to octal */
  1051.     { "n2time",     FN_N2TIM,0},        /* Number to hh:mm:ss */
  1052. #ifdef TCPSOCKET
  1053.     { "name2addr",  FN_HSTNAM,CM_INV},  /* Hostname to IP Address */
  1054. #endif /* TCPSOCKET */
  1055.     { "nday",       FN_NDAY, 0},        /* Numeric day of week */
  1056.     { "nextfile",   FN_FIL,  0},        /* Next file in list */
  1057.     { "ntime",      FN_NTIM, 0},        /* Time to seconds since midnight */
  1058.     { "ntohex",     FN_2HEX, CM_INV},   /* Number to hex */
  1059.     { "ntooctal",   FN_2OCT, CM_INV},   /* Number to octal */
  1060.     { "ntotime",    FN_N2TIM,CM_INV},   /* Number to hh:mm:ss */
  1061.     { "oct2n",      FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1062.     { "octton",     FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1063.     { "pathname",   FN_FFN,  0},        /* Full file name */
  1064.     { "pattern",    FN_PATTERN, 0},     /* Pattern (for INPUT) */
  1065. #ifdef CK_PERMS
  1066.     { "permissions",FN_PERM, 0},        /* Permissions of file */
  1067. #else
  1068.     { "permissions",FN_PERM, CM_INV},   /* Permissions of file */
  1069. #endif /* CK_PERMS */
  1070.     { "radix",      FN_RADIX,0},        /* Radix conversion */
  1071. #ifndef NORANDOM
  1072.     { "random",     FN_RAND, 0},        /* Random number */
  1073. #endif /* NORANDOM */
  1074. #ifndef NOPUSH
  1075.     { "rawcommand", FN_RAW,  0},        /* Output from a command (raw) */
  1076. #endif /* NOPUSH */
  1077. #ifdef RECURSIVE
  1078.     { "rdirectories", FN_RDIR, 0},      /* Recursive directory list */
  1079.     { "rfiles",       FN_RFIL, 0},      /* Recursive file list */
  1080. #endif /* RECURSIVE */
  1081.     { "rep",        FN_REP, CM_INV|CM_ABR},
  1082.     { "repeat",     FN_REP,  0},        /* Repeat argument given # of times */
  1083.     { "replace",    FN_RPL,  0},        /* Replace characters in string */
  1084.     { "reverse",    FN_REV,  0},        /* Reverse the argument string */
  1085.     { "right",      FN_RIG,  0},        /* Rightmost n characters of string */
  1086.     { "rindex",     FN_RIX,  0},        /* Right index */
  1087.     { "rpad",       FN_RPA,  0},        /* Right-pad the argument */
  1088.     { "rsearch",    FN_RSEARCH, 0},     /* R-L Search for pattern in string */
  1089. #ifdef OS2
  1090.     { "scrncurx",   FN_SCRN_CX,  0},    /* Screen Cursor X Pos */
  1091.     { "scrncury",   FN_SCRN_CY,  0},    /* Screen Cursor Y Pos */
  1092.     { "scrnstr",    FN_SCRN_STR, 0},    /* Screen String */
  1093. #endif /* OS2 */
  1094.     { "search",     FN_SEARCH, 0},      /* L-R Search for pattern in string */
  1095. #ifndef NOSEXP
  1096.     { "sexpression",FN_SEXP, 0},        /* S-Expression */
  1097. #endif /* NOSEXP */
  1098. #ifdef NT
  1099.     { "shortpathname",FN_SNAME,0},    /* GetShortPathName() */
  1100. #else
  1101.     { "shortpathname",FN_FFN,CM_INV},
  1102. #endif /* NT */
  1103.     { "size",       FN_FS,   0},        /* File size */
  1104. #ifdef COMMENT
  1105.     { "sleep",      FN_SLEEP,0},        /* Sleep for n seconds */
  1106. #endif /* COMMENT */
  1107.     { "span",       FN_SPN,  0},        /* Span - like Snobol */
  1108.     { "split",      FN_SPLIT,0},        /* Split string into words */
  1109.     { "stripb",     FN_STB,  0},        /* Strip enclosing braces/brackets */
  1110.     { "stripn",     FN_STN,  0},        /* Strip n chars */
  1111.     { "stripx",     FN_STX,  0},        /* Strip suffix */
  1112.     { "su",         FN_SUB,  CM_INV|CM_ABR},
  1113.     { "sub",        FN_SUB,  CM_INV|CM_ABR},
  1114.     { "subs",       FN_SUB,  CM_INV|CM_ABR},
  1115.     { "subst",      FN_SUB,  CM_INV|CM_ABR},
  1116.     { "substitute", FN_SUBST,0},        /* Substitute chars */
  1117.     { "substring",  FN_SUB,  0},        /* Extract substring from argument */
  1118.     { "tablelook",  FN_TLOOK,0},        /* Table lookup */
  1119.     { "time",       FN_TIME, 0},        /* Free-format time to hh:mm:ss */
  1120.     { "tod2secs",   FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1121.     { "todtosecs",  FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1122.     { "trim",       FN_TRM,  0},        /* Trim */
  1123.     { "unhexify",   FN_UNH,  0},        /* Unhexify */
  1124.     { "unix2dospath",FN_PC_UD, 0},      /* UNIX to DOS path */
  1125.     { "unixtodospath",FN_PC_UD, CM_INV}, /* UNIX to DOS path */
  1126.     { "untabify",   FN_UNTAB,0},        /* Untabify */
  1127.     { "upper",      FN_UPP,  0},        /* Return uppercased argument */
  1128.     { "utcdate",    FN_TOGMT,0},        /* Date-time to UTC (GMT) */
  1129.     { "verify",     FN_VER,  0},        /* Verify */
  1130.     { "word",       FN_WORD, 0},        /* Extract a word */
  1131.     { "", 0, 0}
  1132. };
  1133. int nfuncs = (sizeof(fnctab) / sizeof(struct keytab)) - 1;
  1134. #endif /* NOSPL */
  1135.  
  1136. #ifndef NOSPL                           /* Buffer for expansion of */
  1137. #ifdef BIGBUFOK                         /* built-in variables. */
  1138. #define VVBUFL 1024
  1139. #else
  1140. #define VVBUFL 256
  1141. #endif /* BIGBUFOK */
  1142. char vvbuf[VVBUFL+1];
  1143. #endif /* NOSPL */
  1144.  
  1145. struct keytab disptb[] = {              /* Log file disposition */
  1146.     { "append",    1,  0},
  1147.     { "new",       0,  0}
  1148. };
  1149.  
  1150. #ifdef CKFLOAT
  1151.  
  1152. /* I N I T F L O A T  --  Deduce floating-point precision by inspection */
  1153.  
  1154. int fp_rounding = 0;                /* Nonzero if printf("%f") rounds */
  1155. int fp_digits = 0;                  /* Digits of floating point precision */
  1156.  
  1157. #ifdef COMMENT
  1158. /* For looking at internal floating-point representations */
  1159. static char fp_xbuf[128];
  1160. static char *
  1161. tohex(s, n) CHAR * s; int n; {
  1162.     int x;
  1163.     char * p = fp_xbuf;
  1164.     while (n-- > 0) {
  1165.         x = (*s >> 4) & 0x0f;
  1166.         *p++ = hexdigits[x];
  1167.         x = *s++ & 0x0f;
  1168.         *p++ = hexdigits[x];
  1169.     }
  1170.     *p = NUL;
  1171.     return((char *)fp_xbuf);
  1172. }
  1173. #endif /* COMMENT */
  1174.  
  1175. char math_pi[] = "3.1415926535897932384626433832795";
  1176. char math_e[] =  "2.7182818284590452353602874713527";
  1177.  
  1178. VOID
  1179. initfloat() {
  1180.     char * buf = NULL;
  1181.     int i, x, y;
  1182. /*
  1183.   We malloc a big temporary buffer for sprintf() to minimize likelihood of
  1184.   (and damage from) sprintf buffer overflows.  In any case, the only way this
  1185.   could happen would be if sprintf() itself had bugs, since the format
  1186.   descriptor says to cut it off at 250 decimal places.
  1187. */
  1188.     if ((buf = (char *)malloc(4096))) {
  1189.         sprintf(buf,"%0.250f",(10.0 / 3.0));
  1190.         for (i = 2; i < 250 && buf[i] == '3'; i++) ;
  1191.         x = i - 1;
  1192.         debug(F111,"initfloat 10.0/3.0",buf,x);
  1193.         sprintf(buf,"%0.250f",(4.0 / 9.0));
  1194.         for (i = 2; i < 250 && buf[i] == '4'; i++) ;
  1195.         y = i - 1;
  1196.         debug(F111,"initfloat 4.0/9.0",buf,y);
  1197.         fp_digits = (x < y) ? x : y;
  1198.         if (fp_digits < sizeof(math_pi) - 1) {
  1199.             math_pi[fp_digits+1] = NUL;
  1200.             math_e[fp_digits+1] = NUL;
  1201.         }
  1202.         sprintf(buf,"%0.6f",(7.0 / 9.0));
  1203.         if (buf[7] == '8') fp_rounding = 1;
  1204.         debug(F111,"initfloat 7.0/9.0",buf,fp_rounding);
  1205.         debug(F101,"initfloat precision","",fp_digits);
  1206.         free(buf);
  1207.     }
  1208. }
  1209. #endif /* CKFLOAT */
  1210.  
  1211. /*
  1212.   P R E S C A N -- A quick look through the command-line options for
  1213.   items that must be handled before the initialization file is executed.
  1214. */
  1215. #ifdef NT
  1216. extern int StartedFromDialer;
  1217. #endif /* NT */
  1218. #ifdef OS2
  1219. extern int k95stdio;
  1220. unsigned long startflags = 0L;
  1221. #endif /* OS2 */
  1222.  
  1223. static char *
  1224. findinpath(arg) char * arg; {
  1225. #ifdef OS2
  1226.     char * scriptenv, * keymapenv;
  1227.     int len;
  1228. #endif /* OS2 */
  1229. #ifdef DCMDBUF
  1230.     extern char * cmdbuf;
  1231. #else
  1232.     extern char cmdbuf[];
  1233. #endif /* DCMDBUF */
  1234.     char takepath[4096];
  1235.     char * s;
  1236.     int x, z;
  1237.  
  1238.     /* Set up search path... */
  1239. #ifdef OS2
  1240.     char * appdata0 = NULL, *appdata1 = NULL;
  1241. #ifdef NT
  1242.     scriptenv = getenv("K95SCRIPTS");
  1243.     keymapenv = getenv("K95KEYMAPS");
  1244.     makestr(&appdata0,(char *)GetAppData(0));
  1245.     makestr(&appdata1,(char *)GetAppData(1));
  1246. #else /* NT */
  1247.     scriptenv = getenv("K2SCRIPTS");
  1248.     keymapenv = getenv("K2KEYMAPS");
  1249. #endif /* NT */
  1250.     if (!scriptenv)
  1251.       scriptenv = getenv("CK_SCRIPTS");
  1252.     if (!scriptenv)
  1253.       scriptenv = "";
  1254.     if (!keymapenv)
  1255.       keymapenv = getenv("CK_KEYMAPS");
  1256.     if (!keymapenv)
  1257.       keymapenv = "";
  1258.  
  1259.     debug(F110,"startupdir",startupdir,0);
  1260.     debug(F110,"common appdata directory",appdata1,0);
  1261.     debug(F110,"appdata directory",appdata0,0);
  1262.     debug(F110,"inidir",inidir,0);
  1263.     debug(F110,"home",zhome(),0);
  1264.     debug(F110,"exedir",exedir,0);
  1265.  
  1266.     len = strlen(scriptenv) + strlen(keymapenv) + 3*strlen(startupdir)
  1267.         + 3*strlen(inidir) + 3*strlen(zhome()) + 3*strlen(exedir)
  1268.         + (appdata0 ? 3*strlen(appdata0) : 0) 
  1269.         + (appdata1 ? 3*strlen(appdata1) : 0)
  1270.         + 6*strlen("SCRIPTS/") + 6*strlen("KEYMAPS/") + 16;
  1271.  
  1272.     if (len >= 4096) {                  /* SAFE (length is checked) */
  1273.         takepath[0] = '\0';
  1274.         debug(F111,"findinpath error - path length too long","len",len);
  1275.     } else
  1276.       sprintf(takepath,
  1277.               /* semicolon-separated path list */
  1278.     "%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",
  1279.               scriptenv,
  1280.               (scriptenv[0] && scriptenv[strlen(scriptenv)-1]==';')?"":";",
  1281.               keymapenv,
  1282.               (keymapenv[0] && keymapenv[strlen(keymapenv)-1]==';')?"":";",
  1283.               startupdir,
  1284.               startupdir, "SCRIPTS/",
  1285.               startupdir, "KEYMAPS/",
  1286.               appdata1 ? appdata1 : "", 
  1287.               appdata1 ? "Kermit 95;" : "",
  1288.               appdata1 ? appdata1 : "",
  1289.               appdata1 ? "Kermit 95/SCRIPTS/;" : "",
  1290.               appdata1 ? appdata1 : "",
  1291.               appdata1 ? "Kermit 95/KEYMAPS/;" : "",
  1292.               appdata0 ? appdata0 : "",
  1293.               appdata0 ? "Kermit 95;" : "",
  1294.               appdata0 ? appdata0 : "",
  1295.               appdata0 ? "Kermit 95/SCRIPTS/;" : "",
  1296.               appdata0 ? appdata0 : "",
  1297.               appdata0 ? "Kermit 95/KEYMAPS/;" : "",
  1298.               inidir,
  1299.               inidir, "SCRIPTS/",
  1300.               inidir, "KEYMAPS/",
  1301.               zhome(),
  1302.               zhome(), "SCRIPTS/",
  1303.               zhome(), "KEYMAPS/",
  1304.               exedir,
  1305.               exedir, "SCRIPTS/",
  1306.               exedir, "KEYMAPS/"
  1307.               );
  1308.     debug(F110,"findinpath takepath",takepath,0);
  1309. #ifdef NT
  1310.     makestr(&appdata0,NULL);
  1311.     makestr(&appdata1,NULL);
  1312. #endif /* NT */
  1313. #else /* not OS2 */
  1314. #ifndef NOSPL
  1315.     z = 1024;                           /* Look in home directory */
  1316.     s = takepath;
  1317.     zzstring("\\v(home)",&s,&z);
  1318. #else
  1319.     takepath[0] = '\0';
  1320. #endif /* NOSPL */
  1321. #endif /* OS2 */
  1322. /*
  1323.   All the logic for searching the take path is in the command parser.
  1324.   So even though we aren't parsing commands, we initialize and call the
  1325.   parser from here, with the purported filename stuffed into the command
  1326.   buffer, followed by some carriage returns to make the parser return.
  1327.   If the file is not found, or otherwise not accessible, the parser prints
  1328.   an appropriate message, and then we just exit.
  1329. */
  1330.     cmdini();                           /* Allocate command buffers etc */
  1331.     cmini(0);                           /* Initialize them */
  1332.     /* Stuff filename into command buf with braces in case of spaces */
  1333.     ckmakmsg(cmdbuf,CMDBL,"{",arg,"}",NULL);
  1334.     debug(F110,"findinpath cmdbuf",cmdbuf,0);
  1335.     ckstrncat(cmdbuf,"\r\r",CMDBL);     /* And some carriage returns */
  1336.     if (cmifip("","",&s,&x,0,takepath,xxstring) < 0)
  1337.       return(NULL);
  1338.     cmres();
  1339.     return(s);
  1340. }
  1341.  
  1342. static int tr_int;                      /* Flag if TRANSMIT interrupted */
  1343.  
  1344. #ifndef MAC
  1345. SIGTYP
  1346. #ifdef CK_ANSIC
  1347. trtrap(int foo)                         /* TRANSMIT interrupt trap */
  1348. #else
  1349. trtrap(foo) int foo;                    /* TRANSMIT interrupt trap */
  1350. #endif /* CK_ANSIC */
  1351. /* trtrap */ {
  1352. #ifdef __EMX__
  1353.     signal(SIGINT, SIG_ACK);
  1354. #endif
  1355.     tr_int = 1;                         /* (Need arg for ANSI C) */
  1356.     SIGRETURN;
  1357. }
  1358. #endif /* MAC */
  1359. #endif /* NOICP */
  1360.  
  1361. #ifdef UNIX
  1362. VOID
  1363. getexedir() {
  1364.     extern char * xarg0;
  1365.     long xx;
  1366.   /*
  1367.     Unix provides no standard service for this.  We look in argv[0], and if
  1368.     we're lucky there's a full pathname.  If not we do a PATH search.
  1369.   */
  1370.     if (ckstrchr(xarg0,'/')) {          /* Global copy of argv[0] */
  1371.         int i, k;
  1372.         char * p = NULL;
  1373.         if ((k = ckstrncpy(tmpbuf,xarg0,TMPBUFSIZ-2)) > 0) {
  1374.             p = tmpbuf;
  1375.             /* Convert to fully qualified pathname */
  1376.             if (tmpbuf[0]) if (tmpbuf[0] != '/') {
  1377.                 line[0] = NUL;
  1378.                 zfnqfp(tmpbuf,LINBUFSIZ-2,(char *)line);
  1379.                 if (line[0])
  1380.                   p = line;
  1381.             }
  1382.             xx = zchki(p);
  1383.             if (xx > -1) {        /* Is the result an existing file? */
  1384.                 k = strlen(p);
  1385.                 for (i = k-1; i > 0; i--) { /* Yes, strip name part */
  1386.                     if (p[i] == '/') {
  1387.                         if (i < k-1)
  1388.                           p[i+1] = NUL;
  1389.                         break;
  1390.                     }
  1391.                 }
  1392.             }
  1393.         makestr(&exedir,p);        /* Save the result */
  1394.         }
  1395.     }
  1396.     if (!exedir && xarg0) {             /* Not found? */
  1397.         char * p;
  1398.         p = getenv("PATH");             /* Search the PATH */
  1399.         if (p) {                        /* If there is one... */
  1400.             char * q, * PATH = NULL;
  1401.             int k;
  1402.             makestr(&PATH,p);           /* Pokeable copy of PATH string */
  1403.             if (PATH) {                 /* If malloc succeeded... */
  1404.                 p = PATH;
  1405.                 while (p && *p) {        /* Loop through segments */
  1406.                     q = ckstrchr(p,':'); /* End of this segment */
  1407.                     if (q == p) {       /* Null PATH segment */
  1408.                         p++;            /* Skip over colon */
  1409.                         continue;
  1410.                     }
  1411.                     if (q)              /* If not at end of PATH string */
  1412.                       *q++ = NUL;       /* zero out the colon */
  1413.                     if ((k = ckstrncpy(tmpbuf,p,TMPBUFSIZ)) > 0) {
  1414.                         if (tmpbuf[k-1] != '/') { /* Copy this PATH segment */
  1415.                             tmpbuf[k++] = '/';    /* Append '/' if needed */
  1416.                             tmpbuf[k] = NUL;
  1417.                         }
  1418.                         /* Append the argv[0] value */
  1419.                         if (ckstrncpy(&tmpbuf[k],xarg0,TMPBUFSIZ) > 0) {
  1420.                             if (zchki(tmpbuf) > -1) { /* File exists? */
  1421.                                 tmpbuf[k] = NUL;      /* Yes, we're done */
  1422.                                 zfnqfp(tmpbuf,LINBUFSIZ,(char *)line);
  1423.                                 makestr(&exedir,line);
  1424.                                 break;
  1425.                             }
  1426.                         } else break;
  1427.                     } else break;
  1428.                     p = q;              /* Not found, go to next segment  */
  1429.                 } /* while */
  1430.                 free(PATH);             /* Free PATH copy */
  1431.             }
  1432.         }
  1433.         if (!exedir) {                  /* Still nothing? */
  1434.             if (zchki(xarg0) > -1) {    /* Maybe it's in the current dir */
  1435.                 zfnqfp(zgtdir(),LINBUFSIZ,(char *)line);
  1436.                 makestr(&exedir,line);
  1437.             }
  1438.         }
  1439.     }
  1440.     if (!exedir) {                      /* Still nothing? */
  1441.         makestr(&exedir,"/");           /* Fake it with with root. */
  1442.     }
  1443. }
  1444. #endif /* UNIX */
  1445.  
  1446. int arg_x = 0;
  1447. static int x_prescan = 0;
  1448.  
  1449. /*
  1450.   The argument y once meant something but I can't imagine what so now
  1451.   it's ignored.  (Prior to 22 Aug 98, prescan() was called twice by main(),
  1452.   and the arg differentiated the two calls.  But this caused all sorts of
  1453.   problems & confusion, so I commented out the second call.  This issue might
  1454.   need to be revisited.)
  1455. */
  1456. VOID
  1457. prescan(dummy) int dummy; {             /* Arg is ignored. */
  1458.     extern int howcalled;
  1459.     int yargc; char **yargv;
  1460.     char x;
  1461.     char *yp, *yy;
  1462. #ifdef DEBUG
  1463.     int debcount = 0;
  1464. #endif /* DEBUG */
  1465.     int z;
  1466.  
  1467.     if (x_prescan)                      /* Only run once */
  1468.       return;
  1469.     x_prescan = 1;
  1470.  
  1471.     yargc = xargc;                      /* Make copy of arg vector */
  1472.     yargv = xargv;
  1473.  
  1474. #ifndef NOICP
  1475. #ifdef DCMDBUF
  1476.     if (!kermrc)
  1477.       if (!(kermrc = (char *) malloc(KERMRCL+1)))
  1478.         fatal("prescan: no memory for kermrc");
  1479. #endif /* DCMDBUF */
  1480.     ckstrncpy(kermrc,KERMRC,KERMRCL);   /* Default init file name */
  1481. #endif /* NOICP */
  1482.  
  1483.  
  1484. #ifdef IKSD
  1485.     if (howcalled == I_AM_IKSD)         /* Internet Kermit Service daemon */
  1486.       inserver = 1;                     /* (See inserver section of ckcmai) */
  1487. #endif /* IKSD */
  1488.  
  1489. /* Command line options for Kermit */
  1490.  
  1491. #ifndef NOCMDL
  1492.     if (yargc > 1
  1493.         && *yargv[1] != '-'
  1494.         && (yargv[1][0] != '=')
  1495. #ifdef KERBANG
  1496.         && (yargv[1][0] != '+')
  1497. #endif /* KERBANG */
  1498. #ifdef IKSD
  1499.         && (howcalled != I_AM_IKSD)
  1500. #endif /* IKSD */
  1501.         ) {                             /* Filename as 1st argument */
  1502. #ifndef NOICP
  1503.         char *s;
  1504. #endif /* NOICP */
  1505. #ifndef NOURL
  1506.         extern int haveurl;
  1507.         extern struct urldata g_url;
  1508.         if (urlparse(yargv[1],&g_url)) {
  1509.             if (!ckstrcmp(g_url.svc,"ftp",-1,0) ||
  1510.                 !ckstrcmp(g_url.svc,"ftps",-1,0)) {
  1511.                 haveurl = 1;
  1512.                 howcalled = I_AM_FTP;
  1513.             } else if (!ckstrcmp(g_url.svc,"telnet",-1,0) ||
  1514.                        !ckstrcmp(g_url.svc,"telnets",-1,0)) {
  1515.                 haveurl = 1;
  1516.                 howcalled = I_AM_TELNET;
  1517.             } else if (!ckstrcmp(g_url.svc,"ssh",-1,0)) {
  1518.                 haveurl = 1;
  1519.                 howcalled = I_AM_SSH;
  1520.             } else if (!ckstrcmp(g_url.svc,"iksd",-1,0) ||
  1521.                        !ckstrcmp(g_url.svc,"kermit",-1,0)) {
  1522.                 haveurl = 1;
  1523.                 howcalled = I_AM_KERMIT;
  1524.             } else if (!ckstrcmp(g_url.svc,"http",-1,0) ||
  1525.                        !ckstrcmp(g_url.svc,"https",-1,0)) {
  1526.                 haveurl = 1;
  1527.                 howcalled = I_AM_HTTP;
  1528.             }
  1529.             if (haveurl) {
  1530.                 while (--yargc > 0) {   /* Go through command-line args */
  1531.                     yargv++;            /* looking for -Y and -d */
  1532.                     yp = *yargv+1;
  1533.                     if (**yargv == '-') {
  1534.                         x = *(*yargv+1);
  1535.                         while (x) {
  1536.                             switch (x) {
  1537. #ifndef NOICP
  1538.                   case '+':
  1539.                   case '-':
  1540.                                 if (doxarg(yargv,1) < 0) {
  1541.                                     fatal("Extended argument error");
  1542.                                 }
  1543.                                 yp = "";
  1544.                                 break;
  1545. #endif /* NOICP */
  1546.                               case 'Y':
  1547.                                 noinit++;
  1548.                                 break;
  1549.                               case 'h':
  1550.                                   noinit = 1;
  1551. #ifdef OS2
  1552.                                   startflags |= 2;    /* No network DLLs */
  1553.                                   startflags |= 4;    /* No TAPI DLLs */
  1554.                                   startflags |= 8;    /* No Security DLLs */
  1555.                                   startflags |= 16;   /* No Zmodem DLLs */
  1556.                                   startflags |= 32;   /* Stdin */
  1557.                                   startflags |= 64;   /* Stdout */
  1558. #endif /* OS2 */
  1559.                                   break;
  1560.                               case 'd': /* = SET DEBUG ON */
  1561. #ifdef DEBUG
  1562.                                 if (debcount++ > 0)
  1563.                                   debtim = 1;
  1564.                                 if (!deblog)
  1565.                                   deblog = debopn("debug.log",0);
  1566. #endif /* DEBUG */
  1567.                                 break;
  1568. #ifdef OS2
  1569.                               case 'W':
  1570.                                 if (*(yp+1))
  1571.                                   fatal("invalid argument bundling after -W");
  1572.                                 yargv++, yargc--;
  1573.                                 if (yargc < 1)
  1574.                                   fatal("Window handle missing");
  1575.                                 hwndDialer = (HWND) atol(*yargv);
  1576.                                 StartedFromDialer = 1;
  1577.                                 yargv++, yargc--;
  1578.                                 KermitDialerID = atol(*yargv) ;
  1579.                                 break;
  1580.                               case '#': /* K95 initialization options */
  1581.                                 if (*(yp+1)) {
  1582.                                     fatal("invalid argument bundling");
  1583.                                 }
  1584.                                 yargv++, yargc--;
  1585.                                 if (yargc < 1)
  1586.                                   fatal("-# argument missing");
  1587.                                 startflags |= atol(*yargv);
  1588.                                 break;
  1589. #endif /* OS2 */
  1590.                             }
  1591.                             if (!yp)
  1592.                               break;
  1593.                             x = *++yp;
  1594.                         }
  1595.                     }
  1596.                 }
  1597.                 return;
  1598.             }
  1599.         }
  1600.         /* after this point non-Kermit personalities must return */
  1601.         switch (howcalled) {
  1602.       case I_AM_KERMIT:
  1603.       case I_AM_IKSD:
  1604.       case I_AM_SSHSUB:
  1605.             break;
  1606.       default:
  1607.             return;
  1608.         }
  1609. #endif /* NOURL */
  1610.  
  1611. #ifndef NOICP
  1612.         /* If it is not a URL that we recognize, try to treat it as a file */
  1613.  
  1614.         if (!isabsolute(yargv[1]))      /* If not absolute */
  1615.           s = findinpath(yargv[1]);     /* Look in PATH */
  1616.         else
  1617.           s = yargv[1];
  1618.         if (!s)
  1619.           doexit(BAD_EXIT,xitsta);
  1620.         zfnqfp(s,CKMAXPATH,cmdfil);     /* In case of CD in file */
  1621.         yargc -= 1;                     /* Skip past the filename */
  1622.         yargv += 1;                     /* Otherwise we'll get an error */
  1623. #endif /* NOICP */
  1624.     }
  1625.  
  1626. #ifndef NOCMDL
  1627. #ifdef NEWFTP
  1628.     if (howcalled == I_AM_FTP) {        /* Kermit's FTP client personality */
  1629.         while (--yargc > 0) {           /* Go through command-line args */
  1630.             yargv++;                    /* looking for -Y and -d */
  1631.             yp = *yargv+1;
  1632.             if (**yargv == '-') {
  1633.                 x = *(*yargv+1);
  1634.                 while (x) {
  1635.                     switch (x) {
  1636. #ifndef NOICP
  1637.               case '+':
  1638.               case '-':
  1639.                         if (doxarg(yargv,1) < 0) {
  1640.                             fatal("Extended argument error");
  1641.                         }
  1642.                         yp = "";
  1643.                         break;
  1644. #endif /* NOICP */
  1645.                       case 'Y':
  1646.                         noinit++;
  1647.                         break;
  1648.                       case 'h':
  1649.                         noinit = 1;
  1650. #ifdef OS2
  1651.                         startflags |= 2;    /* No network DLLs */
  1652.                         startflags |= 4;    /* No TAPI DLLs */
  1653.                         startflags |= 8;    /* No Security DLLs */
  1654.                         startflags |= 16;   /* No Zmodem DLLs */
  1655.                         startflags |= 32;   /* Stdin */
  1656.                         startflags |= 64;   /* Stdout */
  1657. #endif /* OS2 */
  1658.                         break;
  1659.                       case 'd':             /* = SET DEBUG ON */
  1660. #ifdef DEBUG
  1661.                         if (debcount++ > 0)
  1662.                           debtim = 1;
  1663.                         if (!deblog)
  1664.                           deblog = debopn("debug.log",0);
  1665. #endif /* DEBUG */
  1666.                         break;
  1667. #ifdef OS2
  1668.                       case 'W':
  1669.                         if (*(yp+1))
  1670.                           fatal("invalid argument bundling after -W");
  1671.                         yargv++, yargc--;
  1672.                         if (yargc < 1)
  1673.                           fatal("Window handle missing");
  1674.                         hwndDialer = (HWND) atol(*yargv);
  1675.                         StartedFromDialer = 1;
  1676.                         yargv++, yargc--;
  1677.                         KermitDialerID = atol(*yargv) ;
  1678.                         break;
  1679.                       case '#':         /* K95 initialization options */
  1680.                         if (*(yp+1)) {
  1681.                             fatal("invalid argument bundling");
  1682.                         }
  1683.                         yargv++, yargc--;
  1684.                         if (yargc < 1)
  1685.                           fatal("-# argument missing");
  1686.                         startflags |= atol(*yargv);
  1687.                         break;
  1688. #endif /* OS2 */
  1689.                     }
  1690.                     if (!yp)
  1691.                       break;
  1692.                     x = *++yp;
  1693.                 }
  1694.             }
  1695.         }
  1696.         return;
  1697.     }
  1698. #endif /* NEWFTP */
  1699. #endif /* NOCMDL */
  1700.  
  1701.     while (--yargc > 0) {               /* Go through command-line args */
  1702.         yargv++;
  1703.         yp = *yargv+1;                  /* Pointer for bundled args */
  1704.         if (**yargv == '=')             /* Same rules as cmdlin()... */
  1705.           return;
  1706.         debug(F110,"prescan *yargv",*yargv,0);
  1707.  
  1708. #ifndef NOICP
  1709. #ifdef KERBANG
  1710.         yy = *yargv;
  1711.         if (!strcmp(yy,"+") || (*yy == '+' && *(yy+1) < (char)33)) {
  1712.             char * s;
  1713.             yargv++;
  1714.             noinit = 1;
  1715.             if (!*yargv)
  1716.               return;
  1717.             cfilef = 1;
  1718.             s = findinpath(*yargv);
  1719.             if (s) {
  1720.                 zfnqfp(s,CKMAXPATH,cmdfil);
  1721.                 return;
  1722.             } else
  1723.               doexit(BAD_EXIT,xitsta);
  1724.         }
  1725. #endif /* KERBANG */
  1726. #endif /* NOICP */
  1727.         if (!strcmp(*yargv,"--"))       /* getopt() conformance */
  1728.           return;
  1729. #ifdef VMS
  1730.         else if (**yargv == '/')
  1731.           continue;
  1732. #endif /* VMS */
  1733.         else if (**yargv == '-') {      /* Got an option (begins with dash) */
  1734.             x = *(*yargv+1);            /* Get option letter */
  1735.             while (x) {                 /* Allow for bundled options */
  1736.                 debug(F000,"prescan arg","",x);
  1737.                 switch (x) {
  1738. #ifndef NOICP
  1739.                   case '+':
  1740.                   case '-':
  1741.                     if (doxarg(yargv,1) < 0) {
  1742.                         fatal("Extended argument error");
  1743.                     }
  1744. #ifndef COMMENT                /* Jeff 28 Apr 2003 */
  1745.                     yp = NULL;        /* (not "") */
  1746. #else
  1747.                     yargv++, yargc--;
  1748.                     yp = *yargv;
  1749. #endif /* COMMENT */
  1750.                     break;
  1751. #endif /* NOICP */
  1752.  
  1753.                   case '7':             /* Undocumented... */
  1754.                     sstelnet = 1;       /* (because it doesn't work) */
  1755.                     break;
  1756. #ifdef IKSD
  1757.                   case 'A': {
  1758.                       char * p;
  1759.                       inserver = 1;     /* Flag that we are doing this */
  1760.                       srvcdmsg = 2;     /* Preset this */
  1761.                       /* See inserver section of ckcmai.c for more settings */
  1762. #ifdef OS2
  1763.                       if (*(yp+1)) {
  1764.                           fatal("invalid argument bundling after -A");
  1765.                       }
  1766. #ifdef NT
  1767.                       /* Support for Pragma Systems Telnet/Terminal Servers */
  1768.                       p = getenv("PRAGMASYS_INETD_SOCK");
  1769.                       if (p && atoi(p) != 0) {
  1770.                           ttname[0] = '$';
  1771.                           ckstrncpy(&ttname[1],p,TTNAMLEN-1);
  1772.                           break;
  1773.                       }
  1774. #endif /* NT */
  1775.                       yargv++, yargc--;
  1776.                       if (yargc < 1 || **yargv == '-') {
  1777.                           fatal("-A argument missing");
  1778.                       } else {
  1779.                           ttname[0] = '$';
  1780.                           ckstrncpy(&ttname[1],*yargv,TTNAMLEN-1);
  1781.                       }
  1782. #endif /* OS2 */
  1783.                       break;
  1784.                   }
  1785. #endif /* IKSD */
  1786.  
  1787. #ifdef OS2
  1788.                   case 'W':
  1789.                     if (*(yp+1))
  1790.                       fatal("invalid argument bundling after -W");
  1791.                     yargv++, yargc--;
  1792.                     if (yargc < 1)
  1793.                       fatal("Window handle missing");
  1794. #ifdef COMMENT
  1795.                     if (dummy) {
  1796.                         yargv++, yargc--;
  1797.                         break;
  1798.                     } else {
  1799. #endif /* COMMENT */
  1800.                         hwndDialer = (HWND) atol(*yargv);
  1801.                         StartedFromDialer = 1;
  1802.                         yargv++, yargc--;
  1803.                         KermitDialerID = atol(*yargv) ;
  1804. #ifdef COMMENT
  1805.                     }
  1806. #endif /* COMMENT */
  1807.                     break;
  1808.  
  1809.                   case '#':             /* K95 initialization options */
  1810.                     if (*(yp+1)) {
  1811.                         fatal("invalid argument bundling");
  1812.                     }
  1813.                     yargv++, yargc--;
  1814.                     if (yargc < 1)
  1815.                       fatal("-# argument missing");
  1816.                     startflags |= atol(*yargv);
  1817.                     break;
  1818. #endif /* OS2 */
  1819.  
  1820. #ifndef NOSPL
  1821.                   case 'M':                             /* My User Name */
  1822.                     if (*(yp+1)) {
  1823.                         fatal("invalid argument bundling");
  1824.                     }
  1825.                     yargv++, yargc--;
  1826.                     if ((yargc < 1) || (**yargv == '-')) {
  1827.                         fatal("missing username");
  1828.                     }
  1829.                     if ((int)strlen(*yargv) > UIDBUFLEN) {
  1830.                         fatal("username too long");
  1831.                     }
  1832. #ifdef COMMENT
  1833. /*
  1834.   This can't work.  uidbuf is overwritten in sysinit() which has yet to be
  1835.   called.  This cannot be set in prescan().
  1836. */
  1837. #ifdef IKSD
  1838.                     if (!inserver)
  1839. #endif /* IKSD */
  1840.                       ckstrncpy(uidbuf,*yargv,UIDBUFLEN);
  1841. #endif /* COMMENT */
  1842.                     break;
  1843. #endif /* NOSPL */
  1844.                   case 'R':             /* Remote-only advisory */
  1845. #ifdef CK_IFRO
  1846.                     remonly = 1;
  1847. #endif /* CK_IFRO */
  1848.                     break;
  1849.                   case 'S':             /* STAY */
  1850.                     stayflg = 1;
  1851.                     break;
  1852.                   case 'h':
  1853.                     noinit = 1;
  1854. #ifdef OS2
  1855.                     startflags |= 2;    /* No network DLLs */
  1856.                     startflags |= 4;    /* No TAPI DLLs */
  1857.                     startflags |= 8;    /* No Security DLLs */
  1858.                     startflags |= 16;   /* No Zmodem DLLs */
  1859.                     startflags |= 32;   /* Stdin */
  1860.                     startflags |= 64;   /* Stdout */
  1861. #endif /* OS2 */
  1862.                     break;
  1863. #ifndef NOICP
  1864.                   case 'Y':             /* No init file */
  1865.                     noinit = 1;
  1866.                     break;
  1867. #endif /* NOICP */
  1868.                   case 'd':             /* = SET DEBUG ON */
  1869. #ifdef DEBUG
  1870.                     if (debcount++ > 0)
  1871.                       debtim = 1;
  1872.                     if (!deblog)
  1873.                       deblog = debopn("debug.log",0);
  1874. #endif /* DEBUG */
  1875.                     break;
  1876.  
  1877.                   case 'x':             /* Server */
  1878.                     arg_x = 1;          /* Note in advance */
  1879.                     break;
  1880. #ifndef NOICP
  1881.                   case 'y':             /* Alternative init file */
  1882.                     noinit = 0;
  1883.                     yargv++, yargc--;
  1884.                     if (yargc < 1) fatal("missing name in -y");
  1885.                     /* Replace init file name */
  1886.                     ckstrncpy(kermrc,*yargv,KERMRCL);
  1887.                     rcflag = 1;         /* Flag that this has been done */
  1888.                     debug(F111,"prescan kermrc",kermrc,rcflag);
  1889.                     break;
  1890. #endif /* NOICP */
  1891.                   case 'z':             /* = SET BACKGROUND OFF */
  1892.                     bgset = 0;
  1893.                     backgrd = 0;
  1894. #ifdef VMS
  1895.                     batch = 0;
  1896. #endif /* VMS */
  1897.                     break;
  1898.  
  1899.                   case 'B':             /* Force background (batch) */
  1900.                     bgset = 1;
  1901.                     backgrd = 1;
  1902. #ifdef VMS
  1903.                     batch = 1;
  1904. #endif /* VMS */
  1905.                     break;
  1906.  
  1907. #ifdef CK_NETBIOS
  1908.                   case 'N':
  1909.                     {
  1910.                         int n ;
  1911.                         yargv++, yargc--;
  1912. #ifdef COMMENT
  1913.                         if (y)
  1914.                           break;
  1915. #endif /* COMMENT */
  1916.                         if (strlen(*yargv) != 1 || (*yargv)[0] == 'X') {
  1917.                             NetBiosAdapter = -1;
  1918.                         } else {
  1919.                             n = atoi(*yargv);
  1920.                             if (n >= 0 && n <= 9)
  1921.                               NetBiosAdapter = n;
  1922.                             else
  1923.                               NetBiosAdapter = -1;
  1924.                         }
  1925.                     }
  1926.                     break;
  1927. #endif /* CK_NETBIOS */
  1928.                   default:
  1929.                     break;
  1930.                 }
  1931.                 if (!yp)
  1932.                   break;
  1933.                 x = *++yp;              /* See if options are bundled */
  1934.             }
  1935.         }
  1936.     }
  1937. #endif /* NOCMDL */
  1938. }
  1939.  
  1940. /*  G E T T C S  --  Get Transfer (Intermediate) Character Set  */
  1941.  
  1942. /*
  1943.   Given two file character sets, this routine picks out the appropriate
  1944.   "transfer" character set to use for translating between them.
  1945.   The transfer character set number is returned.
  1946.  
  1947.   Translation between two file character sets is done, for example,
  1948.   by the CONNECT, TRANSMIT, and TRANSLATE commands.
  1949.  
  1950.   Translation between Kanji character sets is not yet supported.
  1951. */
  1952. int
  1953. gettcs(cs1,cs2) int cs1, cs2; {
  1954. #ifdef NOCSETS                          /* No character-set support */
  1955.     return(0);                          /* so no translation */
  1956. #else
  1957.     int tcs = TC_TRANSP;
  1958. #ifdef KANJI
  1959. /* Kanji not supported yet */
  1960.     if (fcsinfo[cs1].alphabet == AL_JAPAN ||
  1961.         fcsinfo[cs2].alphabet == AL_JAPAN )
  1962.       tcs = TC_TRANSP;
  1963.     else
  1964. #endif /* KANJI */
  1965. #ifdef CYRILLIC
  1966. /*
  1967.   I can't remember why we don't test both sets here, but I think there
  1968.   must have been a reason...
  1969. */
  1970.       if (fcsinfo[cs2].alphabet == AL_CYRIL)
  1971.         tcs = TC_CYRILL;
  1972.       else
  1973. #endif /* CYRILLIC */
  1974. #ifdef HEBREW
  1975.           if (fcsinfo[cs1].alphabet == AL_HEBREW ||
  1976.               fcsinfo[cs2].alphabet == AL_HEBREW )
  1977.             tcs = TC_HEBREW;
  1978.           else
  1979. #endif /* HEBREW */
  1980. #ifdef GREEK
  1981.           if (fcsinfo[cs1].alphabet == AL_GREEK ||
  1982.               fcsinfo[cs2].alphabet == AL_GREEK )
  1983.             tcs = TC_GREEK;
  1984.           else
  1985. #endif /* GREEK */
  1986.  
  1987.             /* Roman sets ... */
  1988.  
  1989. #ifdef LATIN2                           /* East European */
  1990.         if (cs1 == FC_2LATIN  || cs2 == FC_2LATIN || /* Latin-2 */
  1991.             cs1 == FC_CP852   || cs2 == FC_CP852  || /* CP852 */
  1992.             cs1 == FC_CP1250  || cs2 == FC_CP1250 || /* Windows Latin-2 */
  1993.             cs1 == FC_MAZOVIA || cs2 == FC_MAZOVIA)  /* Polish Mazovia */
  1994.           tcs = TC_2LATIN;
  1995.         else
  1996. #endif /* LATIN2 */
  1997.                                         /* West European Euro-aware */
  1998.           if (cs1 == FC_CP858 || cs1 == FC_9LATIN ||
  1999.               cs2 == FC_CP858 || cs2 == FC_9LATIN)
  2000.             tcs = TC_9LATIN;
  2001.           else                          /* Traditional West European */
  2002.             tcs = TC_1LATIN;
  2003.     return(tcs);
  2004. #endif /* NOCSETS */
  2005. }
  2006.  
  2007. #ifndef NOLOCAL
  2008. /*  D O C O N E C T  --  Do the connect command  */
  2009. /*
  2010.   q = 0 means issue normal informational message about how to get back, etc.
  2011.   q != 0 means to skip the message.
  2012. */
  2013.  
  2014. int
  2015. doconect(q,async) int q, async; {
  2016.     int x;                              /* Return code */
  2017. #ifdef CK_AUTODL
  2018.     extern CHAR ksbuf[];
  2019. #endif /* CK_AUTODL */
  2020. #ifndef NOKVERBS                        /* Keyboard macro material */
  2021.     extern int keymac, keymacx;
  2022. #endif /* NOKVERBS */
  2023.     extern int justone, adl_err;
  2024.     int qsave;                          /* For remembering "quiet" value */
  2025. #ifdef OS2
  2026.     extern int term_io;
  2027.     extern int display_demo;
  2028.     int term_io_save;
  2029. #ifdef KUI
  2030.     extern int kui_async;
  2031. #endif /* KUI */
  2032. #endif /* OS2 */
  2033.     int is_tn = 0;
  2034.  
  2035. #ifdef IKSD
  2036.     if (inserver) {
  2037.         if (!quiet)
  2038.           printf("?Sorry, IKSD cannot CONNECT.\r\n");
  2039.         return(success = 0);
  2040.     }
  2041. #endif /* IKSD */
  2042.  
  2043.     is_tn =
  2044. #ifdef TNCODE
  2045.       (local && network && IS_TELNET()) || (!local && sstelnet)
  2046. #else
  2047.         0
  2048. #endif /* TNCODE */
  2049.           ;
  2050. /*
  2051.   Saving, changing, and restoring the global "quiet" variable around calls
  2052.   to conect() to control whether the verbose CONNECT message is printed is
  2053.   obviously less elegant than passing a parameter to conect(), but we do it
  2054.   this way to avoid the need to change all of the ck?con.c modules.  NOTE:
  2055.   it is important to restore the value immediately upon return in case there
  2056.   is an autodownload or APC.
  2057. */
  2058.     qsave = quiet;                      /* Save it */
  2059.     if (!quiet && q > -1)
  2060.       quiet = q;                        /* Use argument temporarily */
  2061.     conres();                           /* Put console back to normal */
  2062.     debug(F101,"doconect justone 1","",justone);
  2063. #ifdef CK_AUTODL
  2064.     ksbuf[0] = NUL;                     /* Autodownload packet buffer */
  2065. #endif /* CK_AUTODL */
  2066. #ifdef OS2
  2067.     display_demo = 1;                   /* Remember to display demo */
  2068. #endif /* OS2 */
  2069.  
  2070. #ifdef IKS_OPTION
  2071.     if (is_tn && TELOPT_U(TELOPT_KERMIT) && ttchk() >= 0
  2072. #ifdef OS2
  2073.        && !viewonly
  2074. #endif /* OS2 */
  2075.         ) {
  2076.         /* If the remote side is in a state of IKS START-SERVER    */
  2077.         /* we request that the state be changed.  We will detect   */
  2078.         /* a failure to adhere to the request when we call ttinc() */
  2079.         if (!iks_wait(KERMIT_REQ_STOP,0) && !tcp_incoming) {
  2080.             if (!quiet) {
  2081.                 printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2082.                 printf(
  2083. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2084.                 printf(" SEND and GET for file transfer.\r\n");
  2085.                 printf(" REMOTE commands for file management.\r\n");
  2086.                 printf(" FINISH to terminate Client/Server mode.\r\n");
  2087.                 printf(" BYE to terminate and close connection.\r\n");
  2088.                 printf(" REMOTE HELP for additional information.\r\n\r\n");
  2089.             }
  2090.             quiet = qsave;
  2091.             return(0);      /* Failure */
  2092.         }
  2093.     }
  2094.  
  2095.     /* Let our peer know our state. */
  2096. #ifdef CK_AUTODL
  2097.     if (is_tn && TELOPT_ME(TELOPT_KERMIT)
  2098. #ifdef OS2
  2099.         && !viewonly
  2100. #endif /* OS2 */
  2101.          ) {
  2102.         if (autodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2103.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  2104.         } else if (!autodl && TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2105.             tn_siks(KERMIT_STOP);
  2106.         }
  2107.     }
  2108. #else /* CK_AUTODL */
  2109.     if (is_tn && TELOPT_ME(TELOPT_KERMIT) &&
  2110.     TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  2111.         tn_siks(KERMIT_STOP);
  2112. #endif /* CK_AUTODL */
  2113. #endif /* IKS_OPTION */
  2114.  
  2115.     debug(F101,"doconect flow","",flow);
  2116. #ifdef OS2
  2117.     debug(F101,"doconect async","",async);
  2118. #ifdef KUI
  2119.     if (kui_async)
  2120.       async = 1;;
  2121. #endif /* KUI */
  2122.     x = conect(async);                  /* Connect the first time */
  2123. #else /* OS2 */
  2124.     x = conect();
  2125. #endif /* OS2 */
  2126.     debok = 1;
  2127.  
  2128. #ifdef IKS_OPTION
  2129.     if (TELOPT_U(TELOPT_KERMIT) &&
  2130.         TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  2131.         !tcp_incoming && !quiet && ttchk() >= 0
  2132.         ) {
  2133.         printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2134.         printf(
  2135. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2136.         printf(" SEND and GET for file transfer.\r\n");
  2137.         printf(" REMOTE commands for file management.\r\n");
  2138.         printf(" FINISH to terminate Client/Server mode.\r\n");
  2139.         printf(" BYE to terminate and close connection.\r\n");
  2140.         printf(" REMOTE HELP for additional information.\r\n\r\n");
  2141.     }
  2142. #endif /* IKS_OPTION */
  2143.  
  2144.     quiet = qsave;                      /* Restore "quiet" value */
  2145.     debug(F101,"doconect justone 2","",justone);
  2146.  
  2147. #ifdef NETCONN
  2148.     if (network && tn_exit && ttchk() < 0)
  2149.       doexit(GOOD_EXIT,xitsta);         /* Exit with good status */
  2150. #endif /* NETCONN */
  2151.  
  2152. #ifdef OS2ORUNIX
  2153.     /* Exit on disconnect if the port is not open or carrier detect */
  2154.     if (exitonclose && (ttchk() < 0))
  2155.       doexit(GOOD_EXIT,xitsta);
  2156. #endif /* OS2ORUNIX */
  2157.  
  2158. #ifdef CKCONINTB4CB
  2159.     /* The order makes a difference in HP-UX 8.00. */
  2160.     /* The other order makes it think it's in the background when it */
  2161.     /* returns from CONNECT (Apr 1999). */
  2162.     setint();
  2163.     concb((char)escape);                /* Restore console for commands */
  2164. #else
  2165.     /* This is how it has always been so better leave it */
  2166.     /* this way for all non-HP-UX-8.00 builds. */
  2167.     concb((char)escape);                /* Restore console for commands */
  2168.     setint();
  2169. #endif /* CKCONINTB4CB */
  2170.  
  2171. #ifdef OS2
  2172.     if (!async) {
  2173.         term_io_save = term_io;         /* Disable I/O by emulator */
  2174.         term_io = 0;
  2175. #endif /* OS2 */
  2176.  
  2177. #ifdef CK_APC
  2178. /*
  2179.   If an APC command was received during CONNECT mode, we define it now
  2180.   as a macro, execute the macro, and then return to CONNECT mode.
  2181.   We do this in a WHILE loop in case additional APCs come during subsequent
  2182.   CONNECT sessions.
  2183. */
  2184.         debug(F101,"doconect apcactive","",apcactive);
  2185.         debug(F101,"doconect success","",success);
  2186.  
  2187.         while (x > 0 && (apcactive == APC_LOCAL ||
  2188.                          (apcactive == APC_REMOTE && apcstatus != APC_OFF))) {
  2189.             debug(F101,"doconect justone 3","",justone);
  2190.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  2191.                 debug(F110,"doconect about to execute APC",apcbuf,0);
  2192.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  2193.                 delmac("_apc_commands",1);
  2194. #ifdef DEBUG
  2195.             } else {
  2196.                 debug(F100,"doconect APC in progress","",0);
  2197. #endif /* DEBUG */
  2198.             }
  2199.             debug(F101,"doconect apcactive after domac","",apcactive);
  2200.             if (!apcactive) {               /* In case CLEAR APC was in APC */
  2201.                 debug(F101,"doconect quit APC loop: apcactive","",apcactive);
  2202.                 break;
  2203.             }
  2204.             /* Also don't reconnect if autodownload failed - very confusing! */
  2205.             /* Let them view the local screen to see what happened. - fdc */
  2206.  
  2207.             /* This should be conditional.  If someone is relying on the */
  2208.             /* connect mode autodownload for the kermit server to use with */
  2209.             /* a remotely executed script we should be able to return to */
  2210.             /* connect mode on the failure.  What we really need to do is */
  2211.             /* report the status of the transfer and then return to CONNECT. */
  2212.             /* In unix this would simply be a printf(), but in K95 it could */
  2213.             /* use a popup dialog to report the status. - Jeff */
  2214.  
  2215. #ifndef NOXFER
  2216.             debug(F101,"doconect xferstat","",xferstat);
  2217.             if (apcactive == APC_LOCAL && !xferstat && adl_err != 0) {
  2218.                 debug(F101,"doconect quit APC loop: xferstat","",xferstat);
  2219.                 apcactive = APC_INACTIVE;
  2220.                 break;
  2221.             }
  2222. #endif /* NOXFER */
  2223. #ifdef OS2
  2224.             msleep(250);
  2225. #endif /* OS2 */
  2226.             debug(F101,"doconect justone 4","",justone);
  2227.             qsave = quiet;              /* Do this again... */
  2228.             if (!quiet && q > -1)
  2229.               quiet = q;
  2230. #ifdef CK_AUTODL
  2231.             ksbuf[0] = NUL;
  2232. #endif /* CK_AUTODL */
  2233. #ifdef IKS_OPTION
  2234. #ifdef CK_AUTODL
  2235.             if (is_tn &&
  2236.                 TELOPT_ME(TELOPT_KERMIT) &&
  2237.                 !TELOPT_SB(TELOPT_KERMIT).kermit.me_start &&
  2238.                 autodl
  2239. #ifdef CK_APC
  2240.                 && !apcactive
  2241. #endif /* CK_APC */
  2242. #ifdef OS2
  2243.                 && !viewonly
  2244. #endif /* OS2 */
  2245.                 ) {
  2246.                 tn_siks(KERMIT_START);  /* Send Kermit-Server Start */
  2247.             }
  2248. #endif /* CK_AUTODL */
  2249. #endif /* IKS_OPTION */
  2250. #ifndef OS2
  2251.             x = conect();               /* Re-CONNECT. */
  2252. #else /* OS2 */
  2253.             x = conect(0);
  2254.             term_io = term_io_save;
  2255. #endif /* OS2 */
  2256.             debok = 1;
  2257.             quiet = qsave;
  2258.             debug(F101,"doconect justone 5","",justone);
  2259. #ifdef NETCONN
  2260.             if (network && ttchk() < 0) {
  2261.                 if (tn_exit || exitonclose)
  2262.                   doexit(GOOD_EXIT,xitsta);
  2263.                 else
  2264.                   break;
  2265.             }
  2266. #endif /* NETCONN */
  2267.  
  2268. #ifdef OS2ORUNIX
  2269.             /* If connection dropped */
  2270.             if (ttchk() < 0) {
  2271.                 concb((char)escape);    /* Restore console. */
  2272.                 if (exitonclose)
  2273.                   doexit(GOOD_EXIT,xitsta);
  2274.                 else
  2275.                   break;
  2276.             }
  2277. #endif /* OS2ORUNIX */
  2278.         } /* Loop back for more. */
  2279. #endif /* CK_APC */
  2280.  
  2281. #ifndef NOKVERBS
  2282.         if ((keymac > 0) && (keymacx > -1)) { /* Executing a keyboard macro? */
  2283.             /* Set up the macro and return */
  2284.             /* Do not clear the keymac flag */
  2285. #ifdef OS2
  2286.         term_io = term_io_save;
  2287. #endif /* OS2 */
  2288.             return(dodo(keymacx,NULL,CF_KMAC|cmdstk[cmdlvl].ccflgs));
  2289.         }
  2290. #endif /* NOKVERBS */
  2291. #ifdef OS2
  2292.         term_io = term_io_save;
  2293.     } /* if (!async) */
  2294. #endif /* OS2 */
  2295.  
  2296. #ifdef CKCONINTB4CB
  2297.     /* The order makes a difference in HP-UX 8.00. */
  2298.     /* The other order makes it think it's in the background when it */
  2299.     /* returns from CONNECT (Apr 1999). */
  2300.     setint();
  2301.     concb((char)escape);                /* Restore console for commands */
  2302. #else
  2303.     /* This is how it has always been so better leave it */
  2304.     /* this way for all non-HP-UX-8.00 builds. */
  2305.     concb((char)escape);                /* Restore console for commands */
  2306.     setint();
  2307. #endif /* CKCONINTB4CB */
  2308. #ifdef OS2
  2309.     if (!async)
  2310. #endif /* OS2 */
  2311.       what = W_COMMAND;                 /* Back in command mode. */
  2312.     return(x);                          /* Done. */
  2313. }
  2314. #endif /* NOLOCAL */
  2315.  
  2316. #ifndef NOICP
  2317. #ifdef COMMENT
  2318. /*
  2319.   It seemed that this was needed for OS/2, in which \v(cmdfile) and other
  2320.   file-oriented variables or functions can return filenames containing
  2321.   backslashes, which are subsequently interpreted as quotes rather than
  2322.   directory separators (e.g. see commented section for VN_CMDF below).
  2323.   But the problem can't be cured at this level.  Example:
  2324.  
  2325.     type \v(cmdfile)
  2326.  
  2327.   Without doubling, the filename is parsed correctly, but then when passed
  2328.   to UNIX 'cat' through the shell, the backslash is removed, and then cat
  2329.   can't open the file.  With doubling, the filename is not parsed correctly
  2330.   and the TYPE command fails immediately with a "file not found" error.
  2331. */
  2332. /*
  2333.   Utility routine to double all backslashes in a string.
  2334.   s1 is pointer to source string, s2 is pointer to destination string,
  2335.   n is length of destination string, both NUL-terminated.
  2336.   Returns 0 if OK, -1 if not OK (destination string too short).
  2337. */
  2338. int
  2339. dblbs(s1,s2,n) char *s1, *s2; int n; {
  2340.     int i = 0;
  2341.     while (*s1) {
  2342.         if (*s1 == '\\') {
  2343.             if (++i > n) return(-1);
  2344.             *s2++ = '\\';
  2345.         }
  2346.         if (++i > n) return(-1);
  2347.         *s2++ = *s1++;
  2348.     }
  2349.     *s2 = NUL;
  2350.     return(0);
  2351. }
  2352. #endif /* COMMENT */
  2353.  
  2354. char *
  2355. gmdmtyp() {                             /* Get modem type */
  2356. #ifndef NODIAL
  2357.     int i, x;
  2358.  
  2359.     debug(F111,"gmdmtyp","mdmtyp",mdmtyp);
  2360.     debug(F111,"gmdmtyp","mdmsav",mdmsav);
  2361.  
  2362.     x = mdmtyp;
  2363.     if (x < 0)                          /* In case of network dialing */
  2364.       x = mdmsav;
  2365.     if (x < 1)
  2366.       return("none");
  2367.     else
  2368.       for (i = 0; i < nmdm; i++)
  2369.         if ((mdmtab[i].kwval == x) && (mdmtab[i].flgs == 0))
  2370.           return(mdmtab[i].kwd);
  2371. #endif /* NODIAL */
  2372.     return("none");
  2373. }
  2374.  
  2375. #ifndef NOXMIT
  2376. #ifndef NOLOCAL
  2377. /*  T R A N S M I T  --  Raw upload  */
  2378.  
  2379. /*  Obey current line, duplex, parity, flow, text/binary settings. */
  2380. /*  Returns 0 upon apparent success, 1 on obvious failure.  */
  2381.  
  2382. /***
  2383.  Things to add:
  2384.  . Make both text and binary mode obey set file bytesize.
  2385.  . Maybe allow user to specify terminators other than CR?
  2386.  . Maybe allow user to specify prompts other than single characters?
  2387.  . Make STATISTICS also work for TRANSMIT.
  2388.  . If TRANSMIT is done without echo, make some kind of (optional) display.
  2389.  . Make the same optimization for binary-mode transmit that was done for
  2390.    text-mode (in the no-echo / no-prompt / no-pause case).
  2391. ***/
  2392.  
  2393. /*  T R A N S M I T  --  Raw upload  */
  2394.  
  2395. /*  s is the filename, t is the turnaround (prompt) character  */
  2396.  
  2397. /*
  2398.   Maximum number of characters to buffer.
  2399.   Must be less than LINBUFSIZ
  2400. */
  2401. #ifdef OS2
  2402. #define XMBUFS 4096                     /* For compatibility with XYZmodem */
  2403. #else /* OS2 */
  2404. #define XMBUFS 1024
  2405. #endif /* OS2 */
  2406.  
  2407. #ifdef TNCODE
  2408. #ifndef IAC
  2409. #define IAC 255
  2410. #endif /* IAC */
  2411. #endif /* TNCODE */
  2412.  
  2413. #define OUTXBUFSIZ 15
  2414. static CHAR inxbuf[OUTXBUFSIZ+1];       /* Host-to-screen expansion buffer */
  2415. static int inxcount = 0;                /* and count */
  2416. static CHAR outxbuf[OUTXBUFSIZ+1];      /* Keyboard-to-host expansion buf */
  2417. static int outxcount = 0;               /* and count */
  2418.  
  2419. /*  T R A N S M I T  --  Unguarded non-protocol file transmission  */
  2420. /*
  2421.   Call with:
  2422.     char * s:   Name of file to transmit.
  2423.     char t:     Turnaround char for text-mode transmission (normally LF).
  2424.     int xlate:  nonzero = charset translation for text-mode xfer, 0 = skip.
  2425.     int binary: nonzero = transmit in binary mode, 0 = in text mode.
  2426. */
  2427. #define XBBUFSIZ 252                    /* For binary blasting */
  2428. static CHAR xbbuf[XBBUFSIZ+4];
  2429.  
  2430. int
  2431. #ifdef CK_ANSIC
  2432. transmit(char * s, char t, int xlate, int binary, int xxecho)
  2433. #else
  2434. transmit(s,t,xlate,binary,xxecho) char *s; char t; int xlate, binary, xxecho;
  2435. #endif /* CK_ANSIC */
  2436. /* transmit */ {
  2437. #ifdef MAC
  2438.     extern char sstate;
  2439.     int count = 100;
  2440. #else
  2441.     int count = 0;
  2442. #ifdef OS2
  2443. #ifdef NT
  2444.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  2445. #else /* NT */
  2446.     SIGTYP (* volatile oldsig)(int);
  2447. #endif /* NT */
  2448.  
  2449. #else /* OS2 */
  2450.     SIGTYP (* oldsig)();
  2451. #endif /* OS2 */
  2452. #endif /* MAC */
  2453.     int eof = 0;                        /* End of File flag */
  2454.     int eol = 0;                        /* End of Line flag */
  2455.     int rc = 1;                         /* Return code. 0=fail, 1=succeed. */
  2456.     int myflow;                         /* Local copy of global flow... */
  2457.     int is_tn = 0;                      /* Do Telnet negotiations */
  2458.     int xbufsiz = XMBUFS;               /* Size of TRANSMIT buffer */
  2459.     int x, y, c, i;                     /* Int workers... */
  2460.     int control = 0;                    /* Echo loop control */
  2461.     long nbytes = 0;                    /* File byte count */
  2462.     long zz;                            /* Long worker */
  2463.     char *p;                            /* Char * worker */
  2464.  
  2465. #ifdef PIPESEND
  2466.     extern int pipesend;
  2467. #endif /* PIPESEND */
  2468.  
  2469. #ifndef NOCSETS
  2470.     int tcs = TC_TRANSP;                /* Intermediate (xfer) char set */
  2471.     int langsv = L_USASCII;             /* Save current language */
  2472.     int unicode = 0;
  2473.     int tcssize = 0;
  2474.  
  2475. #ifdef CK_ANSIC /* ANSI C prototypes... */
  2476.     CHAR (*sxo)(CHAR);
  2477.     CHAR (*rxo)(CHAR);
  2478.     CHAR (*sxi)(CHAR);
  2479.     CHAR (*rxi)(CHAR);
  2480. #else /* Not ANSI C... */
  2481.     CHAR (*sxo)();
  2482.     CHAR (*rxo)();
  2483.     CHAR (*sxi)();
  2484.     CHAR (*rxi)();
  2485. #endif /* CK_ANSIC */
  2486. #ifdef UNICODE
  2487.     union ck_short uc;
  2488.     int bomorder = 0;
  2489. #ifdef CK_ANSIC
  2490.     extern int (*xl_ufc[MAXFCSETS+1])(USHORT);  /* Unicode to FCS */
  2491.     extern USHORT (*xl_fcu[MAXFCSETS+1])(CHAR); /* FCS to Unicode */
  2492.     extern int (*xuf)(USHORT);
  2493.     extern USHORT (*xfu)(CHAR);
  2494. #else
  2495.     extern int (*xl_ufc[MAXFCSETS+1])();
  2496.     extern USHORT (*xl_fcu[MAXFCSETS+1])();
  2497.     extern int (*xuf)();
  2498.     extern USHORT (*xfu)();
  2499. #endif /* CK_ANSIC */
  2500. #endif /* UNICODE */
  2501. #endif /* NOCSETS */
  2502.  
  2503.     debug(F101,"xmit t","",t);
  2504.     debug(F101,"xmit xlate","",xlate);
  2505.     debug(F101,"xmit binary","",binary);
  2506.  
  2507. #ifdef PIPESEND
  2508.     if (pipesend) {
  2509.         if (nopush) return(-2);
  2510.         if (zxcmd(ZIFILE,s) < 1) {
  2511.             printf("?Can't start command: %s\n",s);
  2512.             return(0);
  2513.         }
  2514.     } else
  2515. #endif /* PIPESEND */
  2516.     if (zopeni(ZIFILE,s) == 0) {        /* Open the file to be transmitted */
  2517.         printf("?Can't open file %s\n",s);
  2518.         return(0);
  2519.     }
  2520.     x = -1;                             /* Open the communication channel */
  2521.     if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) {  /* (no harm if already open) */
  2522.         printf("Can't open device %s\n",ttname);
  2523.         return(0);
  2524.     }
  2525.     zz = x ? speed : -1L;
  2526.     if (binary) {                       /* Binary file transmission */
  2527.         myflow = (flow == FLO_XONX) ? FLO_NONE : flow;
  2528.  
  2529.         if (ttvt(zz,myflow) < 0) {      /* So no Xon/Xoff! */
  2530.             printf("Can't condition line\n");
  2531.             return(0);
  2532.         }
  2533.     } else {
  2534.         if (ttpkt(zz,flow,parity) < 0) { /* Put the line in "packet mode" */
  2535.             printf("Can't condition line\n"); /* so Xon/Xoff will work, etc. */
  2536.             return(0);
  2537.         }
  2538.     }
  2539.     is_tn =
  2540. #ifdef TNCODE
  2541.       (local && network && IS_TELNET()) || (!local && sstelnet)
  2542. #else
  2543.         0
  2544. #endif /* TNCODE */
  2545.           ;
  2546.  
  2547. #ifndef NOCSETS
  2548. /* Set up character set translations */
  2549.  
  2550.     tcs = 0;                            /* "Transfer" or "Other" charset */
  2551.     sxo = rxo = NULL;                   /* Initialize byte-to-byte functions */
  2552.     sxi = rxi = NULL;
  2553.     unicode = 0;                        /* Assume Unicode won't be involved */
  2554.     if (!binary && xlate) {             /* Set up charset translations */
  2555. /*
  2556.   In the SENDING direction, we are converting from the local file's
  2557.   character-set (fcharset) to the remote terminal charset (tcsr).  In the
  2558.   RECEIVING direction (echoing) we are converting from the remote end of the
  2559.   terminal charset (tcsr) to its local end (tcsl), which is not necessarily
  2560.   the same as the file character-set.  Especially when the file character
  2561.   set is UCS-2, which is not a valid terminal character set.  The various
  2562.   combinations are represented in this table:
  2563.  
  2564.   FCS = File Character Set
  2565.   RCS = Remote Terminal Character Set
  2566.   CCS = Console (Local Terminal) Character Set
  2567.  
  2568.    8   4   2   1
  2569.   FCS FCS RCS CCS
  2570.   UCS UTF UTF UTF
  2571.    0   0   0   0   =   0   =   No translation
  2572.    0   0   0   1   =   1   =   FCS -> RCS, Echo RCS -> UTF
  2573.    0   0   1   0   =   2   =   FCS -> UTF, Echo UTF -> CCS
  2574.    0   0   1   1   =   3   =   FCS -> UTF, Echo no translation
  2575.  
  2576.    0   1   0   0   =   4   =   UTF -> RCS, Echo RCS -> CCS
  2577.    0   1   0   1   =   5   =   UTF -> RCS, Echo RCS -> UTF
  2578.    0   1   1   0   =   6   =   UTF -> UTF, Echo UTF -> CCS
  2579.    0   1   1   1   =   7   =   No translation
  2580.  
  2581.    1   0   0   0   =   8   =   UCS -> RCS, Echo RCS -> CCS
  2582.    1   0   0   1   =   9   =   UCS -> RCS, Echo RCS -> UTF
  2583.    1   0   1   0   =  10   =   UCS -> UTF, Echo UTF -> CCS
  2584.    1   0   1   1   =  11   =   UCS -> UTF, Echo no translation
  2585. */
  2586. #ifdef UNICODE
  2587.         xfu = NULL;                     /* Unicode translation functions */
  2588.         xuf = NULL;
  2589.         bomorder = ucsorder;            /* UCS-2 byte order */
  2590.  
  2591.         if (fcharset == FC_UCS2)        /* File charset is UCS-2 */
  2592.           unicode |= 8;
  2593.         else if (fcharset == FC_UTF8)   /* File charset is UTF-8 */
  2594.           unicode |= 4;
  2595.         if (tcsr == FC_UTF8)            /* Remote term charset is UTF-8 */
  2596.           unicode |= 2;
  2597.         if (tcsl == FC_UTF8)            /* Local term charset is UTF-8 */
  2598.           unicode |= 1;
  2599. #endif /* UNICODE */
  2600. /*
  2601.   When Unicode not involved -- TCS is the intermediate (xfer) set, and:
  2602.   sxo = File-to-Intermediate charset function
  2603.   rxo = Intermediate-to-Remote-Terminal charset function
  2604.   sxi = Remote-Terminal-to-Intermediate
  2605.   rxi = Intermediate-to-Local-Terminal
  2606. */
  2607.         tcs = gettcs(tcsr,fcharset);    /* Get intermediate set. */
  2608.         sxo = xls[tcs][fcharset];       /* translation function */
  2609.         rxo = xlr[tcs][tcsr];           /* pointers for output functions */
  2610.         sxi = xls[tcs][tcsr];           /* and for input functions. */
  2611.         rxi = xlr[tcs][tcsl];
  2612. /*
  2613.   At this point we have unicode nonzero if Unicode is involved in the
  2614.   conversion, and to 0 if it is not.
  2615.   The following is to prevent use of zmstuff() and zdstuff() by translation
  2616.   functions (stuffing works with file i/o, not with communication i/o).
  2617. */
  2618.         langsv = language;              /* Save current SET LANGUAGE */
  2619.         language = L_USASCII;           /* No language-specific translations */
  2620.     }
  2621. #endif /* NOCSETS */
  2622.  
  2623.     i = 0;                              /* Beginning of buffer. */
  2624. #ifndef MAC
  2625. #ifndef AMIGA
  2626.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  2627. #endif /* AMIGA */
  2628. #endif /* MAC */
  2629.     tr_int = 0;                         /* Have not been interrupted (yet). */
  2630.     rc = 1;                             /* Return code presumed good. */
  2631. #ifdef VMS
  2632.     conres();
  2633. #endif /* VMS */
  2634.  
  2635. #ifndef NOCSETS
  2636.     debug(F101,"XMIT unicode","",unicode);
  2637. #ifdef UNICODE
  2638.     debug(F101,"XMIT bomorder","",bomorder);
  2639. #endif /* UNICODE */
  2640. #endif /* NOCSETS */
  2641.  
  2642.     c = 0;                              /* Initial condition */
  2643.     while (c > -1 && !eof) {            /* Loop for all characters in file */
  2644.         eol = 0;
  2645. #ifdef MAC
  2646.         /*
  2647.          * It is expensive to run the miniparser so don't do it for
  2648.          * every character.
  2649.          */
  2650.         if (--count < 0) {
  2651.             count = 100;
  2652.             miniparser(1);
  2653.             if (sstate == 'a') {
  2654.                 sstate = '\0';
  2655.                 goto xmitfail;
  2656.             }
  2657.         }
  2658. #else /* Not MAC */
  2659.         if (tr_int) {                   /* Interrupted? */
  2660.             printf("^C...\n");          /* Print message */
  2661.             goto xmitfail;
  2662.         }
  2663. #endif /* MAC */
  2664.         c = zminchar();                 /* Get a file character */
  2665. #ifdef COMMENT
  2666. /* too much */
  2667. #ifdef DEBUG
  2668.         if (deblog) {
  2669.             if (c < 0)
  2670.               debug(F101,"XMIT zminchar","",c);
  2671.             else
  2672.               debug(F000,"XMIT zminchar","",c);
  2673.         }
  2674. #endif /* DEBUG */
  2675. #endif /* COMMENT */
  2676.         if (c < -1) {                   /* Other error */
  2677.             printf("?TRANSMIT file read error: %s\n",ck_errstr());
  2678.             goto xmitfail;
  2679.         } else if (c > -1) {
  2680.             nbytes++;
  2681.             c &= fmask;                 /* Apply SET FILE BYTESIZE mask */
  2682.         } else if (c == -1) {
  2683.             eof = 1;
  2684.             debug(F101,"XMIT eof","",eof);
  2685.         }
  2686.         if (binary) {                   /* Binary... */
  2687.             if (c == -1) {              /* If EOF */
  2688.                 rc = 1;                 /* Success */
  2689.                 eof = 1;
  2690.                 goto xmitexit;          /* Done */
  2691.             }
  2692.             if (!xmitw && !xxecho) {    /* Special "blast" mode */
  2693.                 if (count == XBBUFSIZ) { /* File input buffer full... */
  2694.                     while (count > 0) {
  2695.                         errno = 0;
  2696.                         y = ttol(xbbuf,count);
  2697.                         if (y < 0) {    /* try to send it. */
  2698.                             printf("?TRANSMIT output error: %s\n",
  2699.                                    ck_errstr());
  2700.                             debug(F111,"XMIT binary ttol error",
  2701.                                   ck_errstr(),errno);
  2702.                             rc = 0;
  2703.                             break;
  2704.                         }
  2705.                         if (y < 0) break;
  2706.                         count -= y;
  2707.                     }
  2708.                     count = 0;
  2709.                 }
  2710.                 xbbuf[count++] = c;
  2711. #ifdef TNCODE
  2712.                 if (c == IAC && is_tn)  /* Telnet IAC */
  2713.                   xbbuf[count++] = IAC; /* must be doubled */
  2714. #endif /* TNCODE */
  2715.                 continue;
  2716.             }
  2717.             if (ttoc(dopar((char) c)) < 0) { /* else just send the char */
  2718.                 printf("?Can't transmit character\n");
  2719.                 goto xmitfail;
  2720.             }
  2721. #ifdef TNCODE
  2722.             if (c == IAC && is_tn)      /* Quote Telnet IAC */
  2723.               ttoc((char)IAC);
  2724. #endif /* TNCODE */
  2725.  
  2726.             if (xmitw)                  /* Pause if requested */
  2727.               msleep(xmitw);
  2728.  
  2729.             if (xxecho) {               /* SET TRANSMIT ECHO ON? */
  2730.                 if (duplex) {           /* Yes, for half duplex */
  2731. #ifndef NOLOCAL
  2732. #ifdef OS2
  2733.                     /* Echo to emulator */
  2734.                     scriptwrtbuf((USHORT)(c & cmdmsk));
  2735. #endif /* OS2 */
  2736. #endif /* NOLOCAL */
  2737.                     if (conoc((char)(c & cmdmsk)) < 0) /* echo locally. */
  2738.                       goto xmitfail;
  2739.                 } else {                /* For full duplex, */
  2740.                     int i, n;           /* display whatever is there. */
  2741.                     n = ttchk();        /* See how many chars are waiting */
  2742.                     if (n < 0) {        /* Connection dropped? */
  2743.                         printf("?Connection lost\n");
  2744.                         goto xmitfail;
  2745.                     }
  2746.                     for (i = 0; i < n; i++) { /* Read and echo that many. */
  2747.                         x = ttinc(xmitt); /* Timed read just in case. */
  2748.                         if (x > -1) {   /* If no timeout */
  2749.                             if (parity) x &= 0x7f; /* display the char, */
  2750. #ifndef NOLOCAL
  2751. #ifdef OS2
  2752.                             /* Echo to emulator */
  2753.                             scriptwrtbuf((USHORT)x);
  2754. #endif /* OS2 */
  2755. #endif /* NOLOCAL */
  2756.                             if (conoc((char)(x & cmdmsk)) < 0) {
  2757.                                 printf("?Output error\n");
  2758.                                 goto xmitfail;
  2759.                             }
  2760.                         } else if (x == -2) {
  2761.                             printf("Connection closed.\n");
  2762.                             ttclos(1);
  2763.                             goto xmitfail;
  2764.                         } else if (x == -3) {
  2765.                             printf(
  2766.                             "Session Limit exceeded - closing connection.\n"
  2767.                                    );
  2768.                             ttclos(1);
  2769.                             goto xmitfail;
  2770.                         } else {
  2771.                             printf("?Communications error\n");
  2772.                             goto xmitfail;
  2773.                         }
  2774.                     }
  2775.                 }
  2776.             } else ttflui();            /* Not echoing, just flush input. */
  2777.  
  2778.         } else {                        /* Text mode, line at a time. */
  2779. #ifdef UNICODE
  2780.             if (fcharset == FC_UCS2 && xlate) { /* Special for UCS-2 */
  2781.                 char xbuf[8];
  2782.                 x = 1 - (nbytes & 1);   /* Odd or even byte */
  2783.                 if (x == 0)             /* Note: 1 = the 1st, 0 = 2nd, etc */
  2784.                   uc.x_short = 0;
  2785.                 if (bomorder)           /* Little Endian */
  2786.                   x = 1 - x;            /* Save byte in appropriate half */
  2787.                 debug(F101,"XMIT UCS2 x","",x);
  2788.                 uc.x_char[x] = (CHAR) (c & 0xff);
  2789.                 if (nbytes & 1)         /* First byte, go back for next */
  2790.                   continue;
  2791.                 if (nbytes == 2) {      /* UCS-2 Byte Order Mark */
  2792.                     if (uc.x_short == (USHORT) 0xfeff) {
  2793.                         debug(F100,"XMIT UCS2 BOM FEFF","",bomorder);
  2794.                         continue;
  2795.                     } else if (uc.x_short == (USHORT) 0xfffe) {
  2796.                         bomorder = 1 - bomorder;
  2797.                         debug(F100,"XMIT UCS2 BOM FFFE (swap)","",bomorder);
  2798.                         continue;
  2799.                     }
  2800.                 }
  2801.                 sprintf(xbuf,"%04X",uc.x_short); /* SAFE */
  2802.                 debug(F111,"XMIT UCS2",xbuf,uc.x_short);
  2803.                 if (nbytes & 1)         /* Special eol test for UCS-2 */
  2804.                   if (uc.x_short == '\n')
  2805.                     eol = 1;
  2806. #ifdef COMMENT
  2807.                 if (uc.x_short == 0x2028 || uc.x_short == 0x2029)
  2808.                     eol = 1;
  2809. #endif /* COMMENT */
  2810.             } else
  2811. #endif /* UNICODE */
  2812.               if (c == '\n') {          /* Normal eol test otherwise */
  2813.                   eol = 1;
  2814.             }
  2815.             if (eol) {                  /* End of line? */
  2816.                 int stuff = -1;
  2817.                 debug(F101,"XMIT eol length","",i);
  2818.                 if (i == 0) {           /* Blank line? */
  2819.                     if (xmitf)          /* Yes, insert fill if asked. */
  2820.                       line[i++] = dopar((char) xmitf);
  2821.                 }
  2822.                 if (i == 0 || ((char) line[i-1]) != ((char) dopar(CR)))
  2823.                   line[i++] = dopar(CR); /* Terminate it with CR */
  2824.                 if (xmitl) {
  2825.                     stuff = LF;
  2826. #ifdef TNCODE
  2827.                 } else if (is_tn && (tn_nlm != TNL_CR)) {
  2828.                     /* TELNET NEWLINE ON/OFF/RAW */
  2829.                     stuff = (tn_nlm == TNL_CRLF) ? LF : NUL;
  2830. #endif /* TNCODE */
  2831.                 }
  2832.                 if (stuff > -1)
  2833.                   line[i++] = dopar((char)stuff);
  2834.                 line[i] = NUL;
  2835.                 debug(F111,"XMIT eol line",line,i);
  2836.  
  2837.             } else if (c != -1) {       /* Not a newline, regular character */
  2838.                 int k, x;
  2839.                 outxbuf[0] = c;         /* In case of no translation */
  2840.                 outxcount = 1;          /* Assume result is one byte */
  2841. #ifndef NOCSETS
  2842.                 switch (unicode) {
  2843.                   case 0:               /* No Unicode involved */
  2844.                   case 1:
  2845.                     if (xlate) {        /* If not /TRANSPARENT */
  2846.                         /* Local-to-intermediate */
  2847.                         if (sxo) c = (*sxo)((char)c);
  2848.                         /* Intermediate-to-remote */
  2849.                         if (rxo) c = (*rxo)((char)c);
  2850.                         outxbuf[0] = c;
  2851.                     }
  2852.                     break;
  2853. #ifdef UNICODE
  2854.                   case 2:               /* Local byte to UTF-8 */
  2855.                   case 3:
  2856.                     xfu = xl_fcu[fcharset];
  2857.                     tcssize = fcsinfo[fcharset].size;
  2858.                     outxcount =
  2859.                       b_to_u((CHAR)c,outxbuf,OUTXBUFSIZ,tcssize);
  2860.                     break;
  2861.                   case 4:               /* Local UTF-8 to remote byte */
  2862.                   case 5:
  2863.                     xuf = xl_ufc[tcsr];
  2864.                     x = u_to_b((CHAR)c); /* Convert to byte */
  2865.                     if (x == -1) {      /* If more input bytes needed */
  2866.                         continue;       /* go back and get them */
  2867.                     } else if (x == -2) { /* LS or PS (shouldn't happen) */
  2868.                         outxbuf[0] = CR;
  2869.                     } else if (x == -9) { /* UTF-8 error */
  2870.                         outxbuf[0] = '?'; /* Insert error char */
  2871.                         outxbuf[1] = u_to_b2(); /* Insert next char */
  2872.                         outxcount = 2;
  2873.                     } else {
  2874.                         outxbuf[0] =    /* Otherwise store result */
  2875.                           (unsigned)(x & 0xff);
  2876.                     }
  2877.                     break;
  2878.                   case 6:               /* UTF-8 to UTF-8 */
  2879.                   case 7:
  2880.                     break;
  2881.                   case 8:               /* UCS-2 to byte */
  2882.                   case 9:
  2883.                     xuf = xl_ufc[tcsr];
  2884.                     outxbuf[0] = (*xuf)(uc.x_short);
  2885.                     break;
  2886.                   case 10:
  2887.                   case 11: {            /* UCS-2 to UTF-8 */
  2888.                       int j;
  2889.                       CHAR * buf = NULL;
  2890.                       x = ucs2_to_utf8(uc.x_short,&buf);
  2891.                       if (x < 0) {
  2892.                           outxbuf[0] = 0xff; /* (= U+FFFD) */
  2893.                           outxbuf[1] = 0xbd;
  2894.                           x = 2;
  2895.                       }
  2896.                       for (j = 0; j < x; j++)
  2897.                         outxbuf[j] = buf[j];
  2898.                       outxcount = x;
  2899.                       break;
  2900.                   }
  2901. #endif /* UNICODE */
  2902.                 }
  2903. #endif /* NOCSETS */
  2904.                 outxbuf[outxcount] = NUL;
  2905.                 debug(F111,"XMIT outxbuf",outxbuf,outxcount);
  2906. /*
  2907.   Now the input character (1 or more bytes) is translated into the output
  2908.   expansion buffer (1 or more bytes); outxcount = number of bytes to add to
  2909.   the TRANSMIT line buffer, which we do here, taking care of parity, SI/SO
  2910.   processing, and quoting Telnet IACs.
  2911. */
  2912.                 for (k = 0; k < outxcount; k++) {
  2913.                     c = outxbuf[k];
  2914.                     if (xmits && parity && (c & 0200)) { /* If shifting */
  2915.                         line[i++] = dopar(SO); /* needs to be done, */
  2916.                         line[i++] = dopar((char)c); /* do it here, */
  2917.                         line[i++] = dopar(SI); /* crudely. */
  2918.                     } else {
  2919.                         line[i++] = dopar((char)c);
  2920. #ifdef TNCODE
  2921.                         if (c == IAC && is_tn)
  2922.                           line[i++] = IAC;
  2923. #endif /* TNCODE */
  2924.                     }
  2925.                 }
  2926.             }
  2927. /*
  2928.   Send characters if buffer full, or at end of line, or at end of file.
  2929.   (End of line only if echoing, waiting for a prompt, or pausing.)
  2930. */
  2931.             debug(F000,"XMIT c",ckitoa(i),c);
  2932.             if (i >= xbufsiz || eof || (eol && (xxecho || xmitw || t))) {
  2933.                 p = line;
  2934.                 line[i] = '\0';
  2935.                 debug(F111,"transmit buf",p,i);
  2936.                 if (ttol((CHAR *)p,i) < 0) { /* try to send it. */
  2937.                     printf("?TRANSMIT output error: %s\n",ck_errstr());
  2938.                     rc = 0;
  2939.                     break;
  2940.                 }
  2941.                 i = 0;                  /* Reset buffer pointer. */
  2942. /*
  2943.   Now we handle the echo.  If the user wants to see it, or if we have to
  2944.   wait for the turnaround character, t.  If the echo is being displayed,
  2945.   and terminal character-set translation is required, we do it here.
  2946. */
  2947.                 if (duplex && xxecho) {  /* If local echo, echo it */
  2948.                     if (parity || cmdmsk == 0x7f) { /* Strip hi bits */
  2949.                         char *ss = line;             /* if necessary */
  2950.                         while (*ss) {
  2951.                             *ss &= 0x7f;
  2952.                             ss++;
  2953.                         }
  2954.                     }
  2955. #ifndef NOLOCAL
  2956. #ifdef OS2
  2957.                     {                   /* Echo to emulator */
  2958.                         char *ss = p;
  2959.                         while (*ss) {
  2960.                             scriptwrtbuf((USHORT)*ss);
  2961.                             ss++;
  2962.                         }
  2963.                     }
  2964. #endif /* OS2 */
  2965. #endif /* NOLOCAL */
  2966.                     if (conoll(p) < 0)
  2967.                       goto xmitfail;
  2968.                 }
  2969.                 if (xmitw)              /* Sleep TRANSMIT PAUSE interval */
  2970.                   msleep(xmitw);
  2971.  
  2972.                 control = 0;            /* Readback loop control */
  2973.                 if (t != 0 && eol)      /* TRANSMIT PROMPT given and at EOL */
  2974.                   control |= 1;
  2975.                 if (xxecho && !duplex)   /* Echo desired and is remote */
  2976.                   control |= 2;
  2977.  
  2978.                 if (control) {          /* Do this if reading back the echo */
  2979.                     int n;
  2980.                     x = 0;
  2981.                     while (1) {
  2982.                         if (control & 1) { /* Termination criterion */
  2983.                             if (x == t)    /* for turnaround */
  2984.                               break;
  2985.                         } else if (control & 2) { /* And for echoing */
  2986.                             if ((n = ttchk()) < 1)
  2987.                               break;
  2988.                         }
  2989.                         if ((x = ttinc(xmitt)) < 0) { /* Read with timeout */
  2990.                             switch (x) {
  2991.                               case -2:
  2992.                                 printf("Connection closed.\n");
  2993.                                 ttclos(1);
  2994.                                 goto xmitfail;
  2995.                               case -3:
  2996.                                 printf(
  2997.                               "Session Limit exceeded - closing connection.\n"
  2998.                                        );
  2999.                                 ttclos(1); /* full thru... */
  3000.                                 goto xmitfail;
  3001.                               default:
  3002.                                 printf("?Timeout\n");
  3003.                                 goto xmitfail;
  3004.                             }
  3005.                         }
  3006.                         if (x > -1 && (control & 2)) { /* Echo any echoes */
  3007.                             if (parity)
  3008.                               x &= 0x7f;
  3009.                             c = x;
  3010. #ifndef NOLOCAL
  3011. #ifdef OS2
  3012.                             scriptwrtbuf((USHORT)x);
  3013. #endif /* OS2 */
  3014. #endif /* NOLOCAL */
  3015.                             inxbuf[0] = c;
  3016.                             inxcount = 1;
  3017. #ifndef NOCSETS
  3018.                             switch (unicode & 3) { /* Remote bits */
  3019.                               case 0:
  3020.                                 if (xlate) {
  3021.                                     if (sxi) c = (*sxi)((CHAR)c);
  3022.                                     if (rxi) c = (*rxi)((CHAR)c);
  3023.                                     inxbuf[0] = c;
  3024.                                 }
  3025.                                 break;
  3026. #ifdef UNICODE
  3027.                               case 1:   /* Remote Byte to local UTF-8 */
  3028.                                 xfu = xl_fcu[tcsr];
  3029.                                 tcssize = fcsinfo[tcsr].size;
  3030.                                 inxcount =
  3031.                                   b_to_u((CHAR)c,
  3032.                                          inxbuf,
  3033.                                          OUTXBUFSIZ,
  3034.                                          tcssize
  3035.                                          );
  3036.                                 break;
  3037.                               case 2:   /* Remote UTF-8 to local Byte */
  3038.                                 xuf = xl_ufc[tcsl];
  3039.                                 x = u_to_b((CHAR)c);
  3040.                                 if (x < 0)
  3041.                                   continue;
  3042.                                 inxbuf[0] = (unsigned)(x & 0xff);
  3043.                                 break;
  3044.                               case 3:   /* UTF-8 to UTF-8 */
  3045.                                 break;
  3046. #endif /* UNICODE */
  3047.                             }
  3048. #endif /* NOCSETS */
  3049.                             inxbuf[inxcount] = NUL;
  3050.                             if (conxo(inxcount,(char *)inxbuf) < 0)
  3051.                               goto xmitfail;
  3052.                         }
  3053.                     }
  3054.                 } else                  /* Not echoing */
  3055.                   ttflui();             /* Just flush input buffer */
  3056.             } /* End of buffer-dumping block */
  3057.         } /* End of text mode */
  3058.         if (eof) {
  3059.             rc = 1;
  3060.             goto xmitexit;
  3061.         }
  3062.     } /* End of character-reading loop */
  3063.  
  3064.   xmitfail:                             /* Failure exit point */
  3065.     rc = 0;
  3066.  
  3067.   xmitexit:                             /* General exit point */
  3068.     if (rc > 0) {
  3069.         if (binary && !xmitw && !xxecho) { /* "blasting"? */
  3070.             while (count > 0) {            /* Partial buffer still to go? */
  3071.                 errno = 0;
  3072.                 y = ttol(xbbuf,count);
  3073.                 if (y < 0) {
  3074.                     printf("?TRANSMIT output error: %s\n",
  3075.                            ck_errstr());
  3076.                     debug(F111,"XMIT binary eof ttol error",
  3077.                           ck_errstr(),errno);
  3078.                     rc = 0;
  3079.                     break;
  3080.                 }
  3081.                 count -= y;
  3082.             }
  3083.         } else if (!binary && *xmitbuf) { /* Anything to send at EOF? */
  3084.             p = xmitbuf;                /* Yes, point to string. */
  3085.             while (*p)                  /* Send it. */
  3086.               ttoc(dopar(*p++));        /* Don't worry about echo here. */
  3087.         }
  3088.     }
  3089.  
  3090. #ifndef AMIGA
  3091. #ifndef MAC
  3092.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3093. #endif /* MAC */
  3094. #endif /* AMIGA */
  3095. #ifdef VMS
  3096.     concb(escape);                      /* Put terminal back, */
  3097. #endif /* VMS */
  3098.     zclose(ZIFILE);                     /* Close file, */
  3099. #ifndef NOCSETS
  3100.     language = langsv;                  /* restore language, */
  3101. #endif /* NOCSETS */
  3102.     ttres();                            /* and terminal modes, */
  3103.     return(rc);                         /* and return successfully. */
  3104. }
  3105. #endif /* NOLOCAL */
  3106. #endif /* NOXMIT */
  3107.  
  3108. #ifndef NOCSETS
  3109.  
  3110. _PROTOTYP( CHAR (*sxx), (CHAR) );       /* Local translation function */
  3111. _PROTOTYP( CHAR (*rxx), (CHAR) );       /* Local translation function */
  3112. _PROTOTYP( CHAR zl1as, (CHAR) );        /* Latin-1 to ascii */
  3113. _PROTOTYP( CHAR xl1as, (CHAR) );        /* ditto */
  3114.  
  3115. /*  X L A T E  --  Translate a local file from one character set to another */
  3116.  
  3117. /*
  3118.   Translates input file (fin) from character set csin to character set csout
  3119.   and puts the result in the output file (fout).  The two character sets are
  3120.   file character sets from fcstab.
  3121. */
  3122.  
  3123. int
  3124. xlate(fin, fout, csin, csout) char *fin, *fout; int csin, csout; {
  3125.  
  3126. #ifndef MAC
  3127. #ifdef OS2
  3128.     extern int k95stdout;
  3129.     extern int wherex[], wherey[];
  3130.     extern unsigned char colorcmd;
  3131. #ifdef NT
  3132.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  3133. #else /* NT */
  3134.     SIGTYP (* volatile oldsig)(int);    /* For saving old interrupt trap. */
  3135. #endif /* NT */
  3136. #else /* OS2 */
  3137.     SIGTYP (* oldsig)();
  3138. #endif /* OS2 */
  3139. #endif /* MAC */
  3140. #ifdef CK_ANSIC
  3141.     int (*fn)(char);                    /* Output function pointer */
  3142. #else
  3143.     int (*fn)();
  3144. #endif /* CK_ANSIC */
  3145.     extern int xlatype;
  3146.     int filecode;                       /* Code for output file */
  3147.     int scrnflg = 0;
  3148.  
  3149.     int z = 1;                          /* Return code. */
  3150.     int x, c, c2;                       /* Workers */
  3151. #ifndef UNICODE
  3152.     int tcs;
  3153. #endif /* UNICODE */
  3154.  
  3155.     ffc = 0L;
  3156.  
  3157.     if (zopeni(ZIFILE,fin) == 0) {      /* Open the file to be translated */
  3158. #ifdef COMMENT
  3159.         /* An error message was already printed by zopeni() */
  3160.         printf("?Can't open input file %s\n",fin);
  3161. #endif /* COMMENT */
  3162.         return(0);
  3163.     }
  3164. #ifdef MAC
  3165. /*
  3166.   If user specified no output file, it goes to the screen.  For the Mac,
  3167.   this must be done a special way (result goes to a new window); the Mac
  3168.   doesn't have a "controlling terminal" device name.
  3169. */
  3170.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZOFILE;
  3171. #else
  3172. #ifdef VMS
  3173.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZMFILE;
  3174. #else
  3175. #ifdef OS2
  3176.     filecode = (!stricmp(fout,"con") || !stricmp(fout,"con:")) ?
  3177.         ZCTERM : ZMFILE;
  3178.     if ((filecode == ZCTERM) && !k95stdout && !inserver)
  3179.         csout = FC_UCS2;
  3180. #else /* OS2 */
  3181.     filecode = ZOFILE;
  3182. #endif /* OS2 */
  3183. #endif /* VMS */
  3184. #endif /* MAC */
  3185.     if (zopeno(filecode,fout,NULL,NULL) == 0) { /* And the output file */
  3186.         printf("?Can't open output file %s\n",fout);
  3187.         return(0);
  3188.     }
  3189. #ifndef AMIGA
  3190. #ifndef MAC
  3191.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  3192. #endif /* MAC */
  3193. #endif /* AMIGA */
  3194.  
  3195.     scrnflg = (filecode == ZCTERM);     /* Set output function */
  3196.     if (scrnflg)
  3197.       fn = NULL;
  3198.     else if (filecode == ZMFILE)
  3199.       fn = putmfil;
  3200.     else
  3201.       fn = putfil;
  3202.  
  3203.     tr_int = 0;                         /* Have not been interrupted (yet). */
  3204.     z = 1;                              /* Return code presumed good. */
  3205.  
  3206.     if (!scrnflg && !quiet)
  3207.       printf(" %s (%s) => %s (%s)\n",   /* Say what we're doing. */
  3208.              fin, fcsinfo[csin].keyword,
  3209.              fout,fcsinfo[csout].keyword
  3210.              );
  3211.  
  3212. #ifndef UNICODE
  3213. /*
  3214.   Non-Unicode picks the "most appropriate" transfer character set as the
  3215.   intermediate set, which results in loss of any characters that the source
  3216.   and target sets have in common, but are lacking from the intermediate set.
  3217. */
  3218. #ifdef KANJI
  3219.     /* Special handling for Japanese... */
  3220.  
  3221.     if (fcsinfo[csin].alphabet == AL_JAPAN ||
  3222.          fcsinfo[csout].alphabet == AL_JAPAN) {
  3223.         USHORT eu;
  3224.         int c, x, y;
  3225.  
  3226.         xpnbyte(-1,0,0,NULL);           /* Reset output machine */
  3227.         xlatype = XLA_JAPAN;
  3228.  
  3229.         while ((c = xgnbyte(FC_JEUC,csin,NULL)) > -1) { /* Get an EUC byte */
  3230.             if (tr_int) {               /* Interrupted? */
  3231.                 printf("^C...\n");      /* Print message */
  3232.                 z = 0;
  3233.                 break;
  3234.             }
  3235.             /* Send EUC byte to output machine */
  3236.             if ((x = xpnbyte(c,TC_JEUC,csout,fn)) < 0) {
  3237.                 z = -1;
  3238.                 break;
  3239.             }
  3240.         }
  3241.         goto xxlate;
  3242.     }
  3243. #endif /* KANJI */
  3244.  
  3245.     /* Regular bytewise conversion... */
  3246.  
  3247.     tcs = gettcs(csin,csout);           /* Get intermediate set. */
  3248.     if (csin == csout) {                /* Input and output sets the same? */
  3249.         sxx = rxx = NULL;               /* If so, no translation. */
  3250.     } else {                            /* Otherwise, set up */
  3251.         if (tcs < 0 || tcs > MAXTCSETS ||
  3252.             csin < 0 || csin > MAXFCSETS ||
  3253.             csout < 0 || csout > MAXFCSETS) {
  3254.             debug(F100,"XLATE csets out of range","",0);
  3255.             sxx = rxx = NULL;
  3256.         } else {
  3257.             sxx = xls[tcs][csin];       /* translation function */
  3258.             rxx = xlr[tcs][csout];      /* pointers. */
  3259.             if (rxx == zl1as) rxx = xl1as;
  3260.         }
  3261.     }
  3262.     while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3263.         if (tr_int) {                   /* Interrupted? */
  3264.             printf("^C...\n");          /* Print message */
  3265.             z = 0;
  3266.             break;
  3267.         }
  3268.         if (sxx) c = (*sxx)((CHAR)c);   /* From fcs1 to tcs */
  3269.         if (rxx) c = (*rxx)((CHAR)c);   /* from tcs to fcs2 */
  3270.         if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3271.             z = -1;
  3272.             break;
  3273.         }
  3274.     }
  3275.     goto xxlate;                        /* Done. */
  3276.  
  3277. #else  /* UNICODE */
  3278. /*
  3279.    Use Unicode as the intermediate character set.  It's simple and gives
  3280.    little or no loss, but the overhead is a bit higher.
  3281. */
  3282.     initxlate(csin,csout);              /* Set up translation functions */
  3283.  
  3284.     if (xlatype == XLA_NONE) {
  3285.         while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3286.             if (tr_int) {               /* Interrupted? */
  3287.                 printf("^C...\n");      /* Print message */
  3288.                 z = 0;
  3289.                 break;
  3290.             }
  3291.             if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3292.                 z = -1;
  3293.                 break;
  3294.             }
  3295.         }
  3296.         goto xxlate;                    /* Done. */
  3297.     }
  3298.  
  3299.  
  3300. #ifndef NOLOCAL
  3301. #ifdef OS2
  3302.     if (csout == FC_UCS2 &&             /* we're translating to UCS-2 */
  3303.         filecode == ZCTERM &&           /* for the real screen... */
  3304.         !k95stdout && !inserver
  3305.         ) {
  3306.         union {
  3307.             USHORT ucs2;
  3308.             UCHAR  bytes[2];
  3309.         } output;
  3310.  
  3311.         while (1) {                     /* In this case we go two-by-two. */
  3312.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3313.               break;
  3314.             output.bytes[0] = c;
  3315.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3316.               break;
  3317.             output.bytes[1] = c;
  3318.  
  3319.             if (tr_int) {               /* Interrupted? */
  3320.                 printf("^C...\n");      /* Print message */
  3321.                 z = 0;
  3322.                 break;
  3323.             }
  3324.  
  3325.             VscrnWrtUCS2StrAtt(VCMD,
  3326.                                &output.ucs2,
  3327.                                1,
  3328.                                wherey[VCMD],
  3329.                                wherex[VCMD],
  3330.                                &colorcmd
  3331.                                );
  3332.         }
  3333.     } else
  3334. #endif /* OS2 */
  3335. #endif /* NOLOCAL */
  3336.  
  3337.       /* General case: Get next byte translated from fcs to UCS-2 */
  3338.  
  3339. #ifdef COMMENT
  3340.       while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1 &&
  3341.               (c2 = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3342.           extern int fileorder;
  3343.  
  3344.           if (tr_int) {                 /* Interrupted? */
  3345.               printf("^C...\n");        /* Print message */
  3346.               z = 0;
  3347.               break;
  3348.           }
  3349.           debug(F001,"XLATE c","",c);
  3350.           debug(F001,"XLATE c2","",c2);
  3351.  
  3352.           /* And then send UCS-2 byte to translate-and-output machine */
  3353.  
  3354.           if ((x = xpnbyte(fileorder?c2:c,TC_UCS2,csout,fn)) < 0) {
  3355.               z = -1;
  3356.               break;
  3357.           }
  3358.           if ((x = xpnbyte(fileorder?c:c2,TC_UCS2,csout,fn)) < 0) {
  3359.               z = -1;
  3360.               break;
  3361.           }
  3362.       }
  3363. #else
  3364.     while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3365.           if (tr_int) {                 /* Interrupted? */
  3366.               printf("^C...\n");        /* Print message */
  3367.               z = 0;
  3368.               break;
  3369.           }
  3370.           if ((x = xpnbyte(c,TC_UCS2,csout,fn)) < 0) {
  3371.               z = -1;
  3372.               break;
  3373.           }
  3374.       }
  3375. #endif /* COMMENT */
  3376.  
  3377. #endif /* UNICODE */
  3378.  
  3379.   xxlate:                               /* Common exit point */
  3380.  
  3381. #ifndef AMIGA
  3382. #ifndef MAC
  3383.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3384. #endif /* MAC */
  3385. #endif /* AMIGA */
  3386.     tr_int = 0;
  3387.     if (z < 0) {
  3388.         if (z == -1)
  3389.           printf("?File output error: %s\n",ck_errstr());
  3390.         z = 0;
  3391.     }
  3392.     zclose(ZIFILE);                     /* Close files */
  3393.     zclose(filecode);                   /* ... */
  3394.     return(success = z);                /* and return status. */
  3395. }
  3396.  
  3397. int
  3398. doxlate() {
  3399. #ifdef OS2ONLY
  3400.     extern int tt_font;
  3401. #endif /* OS2ONLY */
  3402. #ifdef UNIX
  3403.     extern char ** mtchs;               /* zxpand() file list */
  3404. #endif /* UNIX */
  3405.     extern int nfilc;
  3406.     extern struct keytab fcstab[];
  3407.     int x, y, incs, outcs, multiple = 0, wild = 0, fc = 0, len = 0;
  3408.     int ofisdir = 0;
  3409.     char * s, * tocs = "";
  3410.  
  3411.     if ((x = cmifi("File(s) to translate","",&s,&wild,xxstring)) < 0) {
  3412.         if (x == -3) {
  3413.             printf("?Name of an existing file\n");
  3414.             return(-9);
  3415.         } else
  3416.           return(x);
  3417.     }
  3418.     ckstrncpy(line,s,LINBUFSIZ);        /* Save copy of string just parsed. */
  3419.  
  3420.     if ((incs = cmkey(fcstab,nfilc,"from character-set","",xxstring)) < 0)
  3421.       return(incs);
  3422.  
  3423. #ifdef OS2
  3424.     if (isunicode())
  3425.       tocs = "ucs2";
  3426.     else
  3427. #endif /* OS2 */
  3428.       tocs = getdcset();
  3429.  
  3430.     if ((outcs = cmkey(fcstab,nfilc,"to character-set",tocs,xxstring)) < 0)
  3431.       return(outcs);
  3432.     if ((x = cmofi("output file",CTTNAM,&s,xxstring)) < 0) return(x);
  3433.     if (x > 1)
  3434.       ofisdir = 1;
  3435.  
  3436.     len = ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  3437.     if ((y = cmcfm()) < 0) return(y);   /* Confirm the command */
  3438.  
  3439.     if (len < 1)
  3440.       return(-2);
  3441.  
  3442.     if (ofisdir)
  3443.       multiple = 2;
  3444.     else if (wild) {
  3445.         if (isdir(tmpbuf))
  3446.           multiple = 2;
  3447.         else if (!strcmp(tmpbuf,CTTNAM))
  3448.           multiple = 1;
  3449. #ifdef OS2
  3450.         else if (!stricmp(tmpbuf,"con") || !stricmp(tmpbuf,"con:"))
  3451.           multiple = 1;
  3452. #else
  3453. #ifdef UNIXOROSK
  3454.         else if (!strncmp(tmpbuf,"/dev/",4))
  3455.           multiple = 1;
  3456. #endif /* UNIXOROSK */
  3457. #endif /* OS2 */
  3458.         if (!multiple) {
  3459.             printf("?A single file please\n");
  3460.             return(-9);
  3461.         }
  3462.     }
  3463.     if (!multiple) {                    /* Just one file */
  3464.         return(success = xlate(line,tmpbuf,incs,outcs));
  3465.     } else {                            /* Translate multiple files */
  3466.         char dirbuf[CKMAXPATH+4];
  3467.         int k;
  3468. #ifndef ZXREWIND
  3469.         int flags = ZX_FILONLY;
  3470. #endif /* ZXREWIND */
  3471.  
  3472.         if (multiple == 2) {            /* Target is a directory */
  3473.             k = ckstrncpy(dirbuf,tmpbuf,CKMAXPATH+1) - 1;
  3474.             if (k < 0)
  3475.               return(-2);
  3476. #ifdef OS2ORUNIX
  3477.             if (dirbuf[k] != '/') {
  3478.                 dirbuf[k+1] = '/';
  3479.                 dirbuf[k+2] = NUL;
  3480.             }
  3481. #else
  3482. #ifdef OSK
  3483.             if (dirbuf[k] != '/') {
  3484.                 dirbuf[k+1] = '/';
  3485.                 dirbuf[k+2] = NUL;
  3486.             }
  3487. #else
  3488. #ifdef VMS
  3489.             if (ckmatch("*.DIR;1",s,0,0))
  3490.               k = cvtdir(tmpbuf,dirbuf,TMPBUFSIZ);
  3491.             if (dirbuf[k] != ']' &&
  3492.                 dirbuf[k] != '>' &&
  3493.                 dirbuf[k] != ':')
  3494.               return(-2);
  3495. #else
  3496. #ifdef datageneral
  3497.             if (dirbuf[k] != ':') {
  3498.                 dirbuf[k+1] = ':';
  3499.                 dirbuf[k+2] = NUL;
  3500.             }
  3501. #else
  3502. #ifdef STRATUS
  3503.             if (dirbuf[k] != '>') {
  3504.                 dirbuf[k+1] = '>';
  3505.                 dirbuf[k+2] = NUL;
  3506.             }
  3507. #endif /* STRATUS */
  3508. #endif /* datageneral */
  3509. #endif /* VMS */
  3510. #endif /* OSK */
  3511. #endif /* OS2ORUNIX */
  3512.         }
  3513.  
  3514. #ifdef ZXREWIND
  3515.         fc = zxrewind();                /* Rewind the file list */
  3516. #else
  3517.         if (matchdot)  flags |= ZX_MATCHDOT;
  3518.         fc = nzxpand(line,flags);
  3519. #endif /* ZXREWIND */
  3520.  
  3521.         if (fc < 1) {
  3522.             printf("?Wildcard expansion error\n");
  3523.             return(-9);
  3524.         }
  3525. #ifdef UNIX
  3526.         sh_sort(mtchs,NULL,fc,0,0,filecase); /* Sort the file list */
  3527. #endif /* UNIX */
  3528.  
  3529.         while (1) {                     /* Loop through the files */
  3530.             znext(line);
  3531.             if (!line[0])
  3532.               break;
  3533.             if (multiple == 2)
  3534.               ckmakmsg(tmpbuf,TMPBUFSIZ,dirbuf,line,NULL,NULL);
  3535.             if (xlate(line,tmpbuf,incs,outcs) < 1)
  3536.               return(success = 0);
  3537.         }
  3538.     }
  3539.     return(success = 1);
  3540. }
  3541. #endif /* NOCSETS */
  3542.  
  3543. static char hompthbuf[CKMAXPATH+1];
  3544.  
  3545. char *
  3546. homepath() {
  3547.     int x;
  3548.     extern char * myhome;
  3549.     char * h;
  3550.  
  3551.     h = myhome ? myhome : zhome();
  3552.     hompthbuf[0] = NUL;
  3553. #ifdef UNIXOROSK
  3554.     x = ckstrncpy(hompthbuf,h,CKMAXPATH+1);
  3555.     if (x <= 0) {
  3556.         hompthbuf[0] = '/';
  3557.         hompthbuf[1] = NUL;
  3558.     } else if (x < CKMAXPATH - 2 && hompthbuf[x-1] != '/') {
  3559.         hompthbuf[x] = '/';
  3560.         hompthbuf[x+1] = NUL;
  3561.     }
  3562.     return(hompthbuf);
  3563. #else
  3564. #ifdef STRATUS
  3565.     if (strlen(h) < CKMAXPATH)
  3566.       sprintf(hompthbuf,"%s>",h);    /* SAFE */
  3567.     return(hompthbuf);
  3568. #else
  3569.     return(h);
  3570. #endif /* STRATUS */
  3571. #endif /* UNIXOROSK */
  3572. }
  3573.  
  3574. /*  D O L O G  --  Do the log command  */
  3575.  
  3576. int
  3577. dolog(x) int x; {
  3578.     int y, disp; char *s = NULL, * p = NULL, * q = NULL;
  3579.     extern int isguest;
  3580. #ifdef ZFNQFP
  3581.     struct zfnfp * fnp;
  3582. #endif /* ZFNQFP */
  3583.  
  3584.     if (isguest) {
  3585.         printf("?Anonymous log creation not allowed\n");
  3586.         return(-9);
  3587.     }
  3588.     switch (x) {                        /* Which log... */
  3589.  
  3590. #ifdef DEBUG
  3591.       case LOGD:
  3592.         q = "debug.log";
  3593.         y = cmofi("Name of debugging log file",q,&s,xxstring);
  3594.         break;
  3595. #endif /* DEBUG */
  3596.  
  3597.       case LOGP:
  3598.         q = "packet.log";
  3599.         y = cmofi("Name of packet log file",q,&s,xxstring);
  3600.         break;
  3601.  
  3602. #ifndef NOLOCAL
  3603.       case LOGS:
  3604.         q = "session.log";
  3605.         y = cmofi("Name of session log file",q,&s,xxstring);
  3606.         break;
  3607. #endif /* NOLOCAL */
  3608.  
  3609. #ifdef TLOG
  3610.       case LOGT:
  3611.         q = "transact.log";
  3612.         y = cmofi("Name of transaction log file",q,&s,xxstring);
  3613.         break;
  3614. #endif /* TLOG */
  3615.  
  3616. #ifdef CKLOGDIAL
  3617.       case LOGM: {
  3618.           int m, n;
  3619.           char mypath[CKMAXPATH+1];
  3620.           q = CXLOGFILE;
  3621.           m = ckstrncpy(mypath,homepath(),CKMAXPATH);
  3622.           n = strlen(CXLOGFILE);
  3623.           if (m + n < CKMAXPATH)
  3624.             ckstrncat(mypath,CXLOGFILE,CKMAXPATH);
  3625.           else
  3626.             ckstrncpy(mypath,CXLOGFILE,CKMAXPATH);
  3627.           y = cmofi("Name of connection log file",mypath,&s,xxstring);
  3628.           break;
  3629.       }
  3630. #endif /* CKLOGDIAL */
  3631.  
  3632.       default:
  3633.         printf("\n?Unknown log designator - %d\n",x);
  3634.         return(-2);
  3635.     }
  3636.     if (y < 0) return(y);
  3637.     if (y == 2) {                       /* If they gave a directory name */
  3638.         int k;
  3639.         char * ds = "/";
  3640.         k = strlen(s);
  3641.         if (k > 0 && s[k-1] == '/') ds = "";
  3642.         ckmakmsg(tmpbuf,TMPBUFSIZ,s,ds,q,NULL);
  3643.         s = tmpbuf;
  3644.     }
  3645. #ifdef ZFNQFP
  3646. #ifdef OS2ORUNIX
  3647.     if (*s != '|')                      /* Allow for pipes */
  3648. #else
  3649. #ifdef OSK
  3650.     if (*s != '|')
  3651. #endif /* OSK */
  3652. #endif /* OS2ORUNIX */
  3653.       if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3654.           if (fnp->fpath)
  3655.             if ((int) strlen(fnp->fpath) > 0)
  3656.               s = fnp->fpath;
  3657.       } /* else if error keep original string */
  3658. #endif /* ZFNQFP */
  3659.  
  3660.     ckstrncpy(line,s,LINBUFSIZ);
  3661.     s = line;
  3662. #ifdef MAC
  3663.     y = 0;
  3664. #else
  3665.  
  3666.     p = "new";
  3667. #ifdef TLOG
  3668.     if ((x == LOGT && tlogfmt == 2) || x == LOGM)
  3669.       p = "append";
  3670. #endif /* TLOG */
  3671.  
  3672.     if ((y = cmkey(disptb,2,"Disposition",p,xxstring)) < 0)
  3673.       return(y);
  3674. #endif /* MAC */
  3675.     disp = y;
  3676.     if ((y = cmcfm()) < 0) return(y);
  3677.  
  3678.     switch (x) {
  3679.  
  3680. #ifdef DEBUG
  3681.       case LOGD:
  3682.         return(deblog = debopn(s,disp));
  3683. #endif /* DEBUG */
  3684.  
  3685. #ifndef NOXFER
  3686.       case LOGP:
  3687.         return(pktlog = pktopn(s,disp));
  3688. #endif /* NOXFER */
  3689.  
  3690. #ifndef NOLOCAL
  3691.       case LOGS:
  3692.         setseslog(sesopn(s,disp));
  3693.         return(seslog);
  3694. #endif /* NOLOCAL */
  3695.  
  3696. #ifdef TLOG
  3697.       case LOGT:
  3698.         return(tralog = traopn(s,disp));
  3699. #endif /* TLOG */
  3700.  
  3701. #ifdef CKLOGDIAL
  3702.       case LOGM:
  3703.         return(dialog = diaopn(s,disp,0));
  3704. #endif /* CKLOGDIAL */
  3705.  
  3706.       default:
  3707.         return(-2);
  3708.     }
  3709. }
  3710.  
  3711. #ifndef NOXFER
  3712. int
  3713. pktopn(s,disp) char *s; int disp; {
  3714.     static struct filinfo xx;
  3715.  
  3716.     if (!s)
  3717.       s = "";
  3718.     if (!*s)
  3719.       return(0);
  3720.  
  3721.     debug(F111,"pktopn",s,disp);
  3722.  
  3723.     zclose(ZPFILE);
  3724.  
  3725. #ifdef OS2ORUNIX
  3726.     if (s[0] == '|') {                  /* Pipe */
  3727.         char * p = s + 1;
  3728.         debug(F110,"pktopn p",p,0);
  3729.         while (*p) {
  3730.             if (*p != ' ')
  3731.               break;
  3732.             else
  3733.               p++;
  3734.         }
  3735.         debug(F110,"pktopn pipe",p,0);
  3736.         pktlog = zxcmd(ZPFILE,p);
  3737.         debug(F101,"pktopn seslog","",seslog);
  3738.     } else {                            /* File */
  3739. #endif /* OS2ORUNIX */
  3740.         if (disp) {
  3741.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3742.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3743.             xx.lblopts = 0;
  3744.             pktlog = zopeno(ZPFILE,s,NULL,&xx);
  3745.         } else pktlog = zopeno(ZPFILE,s,NULL,NULL);
  3746.         if (!pktlog)
  3747.           printf("?%s - %s\n",s,ck_errstr());
  3748. #ifdef OS2ORUNIX
  3749.     }
  3750. #endif /* OS2ORUNIX */
  3751.     if (pktlog > 0)
  3752.       ckstrncpy(pktfil,s,CKMAXPATH+1);
  3753.     else
  3754.       *pktfil = '\0';
  3755.     return(pktlog);
  3756. }
  3757. #endif /* NOXFER */
  3758.  
  3759. int
  3760. traopn(s,disp) char *s; int disp; {
  3761. #ifdef TLOG
  3762.     static struct filinfo xx;
  3763.  
  3764.     if (!s)
  3765.       s = "";
  3766.     if (!*s)
  3767.       return(0);
  3768.  
  3769.     debug(F111,"traopn",s,disp);
  3770.     debug(F101,"traopn tlogfmt","",tlogfmt);
  3771.  
  3772.     zclose(ZTFILE);
  3773.  
  3774. #ifdef OS2ORUNIX
  3775.     if (tlogfmt == 2) {                 /* FTP format is special... */
  3776.         VOID doiklog();
  3777.         if (!disp)                      /* Append? */
  3778.           if (zchki(s) > -1)            /* No - does file exist? */
  3779.             (VOID) zdelet(s);           /* Yes - delete it. */
  3780.         xferlog = 1;
  3781.         ckstrncpy(trafil,s,CKMAXPATH);
  3782.         makestr(&xferfile,s);
  3783.         doiklog();
  3784.         return(1);
  3785.     }
  3786.     if (s[0] == '|') {                  /* Pipe */
  3787.         char * p = s + 1;
  3788.         debug(F110,"traopn p",p,0);
  3789.         while (*p) {
  3790.             if (*p != ' ')
  3791.               break;
  3792.             else
  3793.               p++;
  3794.         }
  3795.         debug(F110,"traopn pipe",p,0);
  3796.         tralog = zxcmd(ZTFILE,p);
  3797.         debug(F101,"traopn tralog","",tralog);
  3798.     }
  3799. #endif /* OS2ORUNIX */
  3800.  
  3801.     if (s[0] != '|') {                  /* File */
  3802.         if (disp) {
  3803.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3804.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3805.             xx.lblopts = 0;
  3806.             tralog = zopeno(ZTFILE,s,NULL,&xx);
  3807.         } else tralog = zopeno(ZTFILE,s,NULL,NULL);
  3808.     }
  3809.     if (!tralog)
  3810.       printf("?%s - %s\n",s,ck_errstr());
  3811.     if (tralog > 0 && tlogfmt > 0) {
  3812.         ckstrncpy(trafil,s,CKMAXPATH);
  3813.         tlog(F110,"Transaction Log:",versio,0L);
  3814. #ifndef MAC
  3815.         tlog(F100,ckxsys,"",0L);
  3816. #endif /* MAC */
  3817.         ztime(&s);
  3818.         tlog(F100,s,"",0L);
  3819.     } else
  3820.       *trafil = '\0';
  3821.     return(tralog);
  3822. #else
  3823.     return(0);
  3824. #endif /* TLOG */
  3825. }
  3826.  
  3827. #ifndef NOLOCAL
  3828. int
  3829. sesopn(s,disp) char * s; int disp; {
  3830.     static struct filinfo xx;
  3831.     extern int tsstate;
  3832.  
  3833.     tsstate = 0;                        /* Session log timestamp state */
  3834.  
  3835.     if (!s)
  3836.       s = "";
  3837.     if (!*s)
  3838.       return(0);
  3839.  
  3840.     debug(F111,"sesopn",s,disp);
  3841.  
  3842.     zclose(ZSFILE);
  3843.  
  3844. #ifdef OS2ORUNIX
  3845.     if (s[0] == '|') {                  /* Pipe */
  3846.         char * p = s + 1;
  3847.         debug(F110,"sesopn p",p,0);
  3848.         while (*p) {
  3849.             if (*p != ' ')
  3850.               break;
  3851.             else
  3852.               p++;
  3853.         }
  3854.         debug(F110,"sesopn pipe",p,0);
  3855.         setseslog(zxcmd(ZSFILE,p));
  3856.         debug(F101,"sesopn seslog","",seslog);
  3857.     } else {                            /* File */
  3858. #endif /* OS2ORUNIX */
  3859.         if (disp) {
  3860.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3861.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3862.             xx.lblopts = 0;
  3863.             setseslog(zopeno(ZSFILE,s,NULL,&xx));
  3864.         } else
  3865.           setseslog(zopeno(ZSFILE,s,NULL,NULL));
  3866.         if (!seslog)
  3867.           printf("?%s - %s\n",s,ck_errstr());
  3868. #ifdef OS2ORUNIX
  3869.     }
  3870. #endif /* OS2ORUNIX */
  3871.     if (seslog > 0)
  3872.       ckstrncpy(sesfil,s,CKMAXPATH+1);
  3873.     else
  3874.       *sesfil = '\0';
  3875.     return(seslog);
  3876. }
  3877. #endif /* NOLOCAL */
  3878. #endif /* NOICP */
  3879.  
  3880. int
  3881. debopn(s,disp) char *s; int disp; {
  3882. #ifdef DEBUG
  3883. #ifdef CK_UTSNAME
  3884.     extern char unm_mch[], unm_nam[], unm_rel[], unm_ver[], unm_mod[];
  3885. #endif /* CK_UTSNAME */
  3886. #ifdef OS2
  3887.     extern char ckxsystem[];
  3888. #endif /* OS2 */
  3889.     char *tp;
  3890.     static struct filinfo xx;
  3891.  
  3892.     if (!s)
  3893.       s = "";
  3894.     if (!*s)
  3895.       return(0);
  3896.  
  3897.     zclose(ZDFILE);
  3898.  
  3899. #ifdef OS2ORUNIX
  3900.     if (s[0] == '|') {                  /* Pipe */
  3901.         char * p = s + 1;
  3902.         debug(F110,"debopn p",p,0);
  3903.         while (*p) {
  3904.             if (*p != ' ')
  3905.               break;
  3906.             else
  3907.               p++;
  3908.         }
  3909.         debug(F110,"debopn pipe",p,0);
  3910.         deblog = zxcmd(ZDFILE,p);
  3911.         debug(F101,"debopn deblog","",deblog);
  3912.     } else {                            /* File */
  3913. #endif /* OS2ORUNIX */
  3914.         if (disp) {
  3915.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3916.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3917.             xx.lblopts = 0;
  3918.             deblog = zopeno(ZDFILE,s,NULL,&xx);
  3919.         } else
  3920.           deblog = zopeno(ZDFILE,s,NULL,NULL);
  3921.         if (!deblog)
  3922.           printf("?%s - %s\n",s,ck_errstr());
  3923. #ifdef OS2ORUNIX
  3924.     }
  3925. #endif /* OS2ORUNIX */
  3926.     if (deblog > 0) {
  3927.         ckstrncpy(debfil,s,CKMAXPATH+1);
  3928.         debug(F110,"Debug Log ",versio,0);
  3929. #ifndef MAC
  3930. #ifdef OS2
  3931.         debug(F110,ckxsys,ckxsystem,0);
  3932. #else /* OS2 */
  3933.         debug(F100,ckxsys,"",0);
  3934. #endif /* OS2 */
  3935. #endif /* MAC */
  3936. #ifdef CK_UTSNAME
  3937.         if (unm_mch[0]) {
  3938.             debug(F110,"uname machine",unm_mch,0);
  3939.             if (unm_mod[0])
  3940.               debug(F110,"uname model  ",unm_mod,0);
  3941.             debug(F110,"uname sysname",unm_nam,0);
  3942.             debug(F110,"uname release",unm_rel,0);
  3943.             debug(F110,"uname version",unm_ver,0);
  3944.         }
  3945. #ifdef KTARGET
  3946.         {
  3947.             char * s;                   /* Makefile target */
  3948.             s = KTARGET;
  3949.             if (!s) s = "";
  3950.             if (!*s) s = "(unknown)";
  3951.             debug(F110,"build target",s,0);
  3952.         }
  3953. #endif /* KTARGET */
  3954.         deblog = 0;
  3955.         ztime(&tp);
  3956.         deblog = 1;
  3957.         debug(F100,tp,"",0);
  3958. #endif /* UTSNAME */
  3959.         debug(F101,"byteorder","",byteorder);
  3960. #ifndef NOICP
  3961. #ifndef NOLOCAL
  3962.         if (local) {
  3963.             debug(F110,"Active connection: ",ttname,0);
  3964.             if (!network) {
  3965.                 debug(F101,"Speed","",speed);
  3966.                 if (hwparity)
  3967.                   debug(F110,"Parity[hardware]",parnam((char)hwparity),0);
  3968.                 else
  3969.                   debug(F110,"Parity",parnam((char)parity),0);
  3970.                 deblog = 0;
  3971.                 debug(F110,"Modem",gmdmtyp(),0);
  3972.                 deblog = 1;
  3973.             }
  3974.         } else {
  3975.             debug(F110,"Active connection: ","none",0);
  3976.         }
  3977. #endif /* NOLOCAL */
  3978. #endif /* NOICP */
  3979.     } else *debfil = '\0';
  3980.     return(deblog);
  3981. #else
  3982.     return(0);
  3983. #endif /* MAC */
  3984. }
  3985.  
  3986.  
  3987. /*  C K D A T E  --  Returns current date/time in standard format  */
  3988.  
  3989. static char nowbuf[18];
  3990.  
  3991. char *
  3992. ckdate() {
  3993.     extern struct keytab cmonths[];
  3994.     int x;
  3995.     char * t;                   /* Substitute today's date */
  3996.     char dbuf[32];
  3997.     ztime(&t);
  3998.  
  3999. /*  012345678901234567890123 */
  4000. /*  Sat Jul  4 12:16:43 1998 */
  4001.  
  4002.     ckstrncpy(dbuf,t,32);
  4003.     t = dbuf;
  4004.     debug(F110,"ckdate dbuf",dbuf,0);
  4005.     nowbuf[0] = t[20];
  4006.     nowbuf[1] = t[21];
  4007.     nowbuf[2] = t[22];
  4008.     nowbuf[3] = t[23];
  4009.  
  4010.     nowbuf[4] = NUL;
  4011.     debug(F110,"ckdate nowbuf",nowbuf,0);
  4012.  
  4013.     t[7] = NUL;
  4014.     if ((x = lookup(cmonths,t+4,12,NULL)) < 0) {
  4015.         debug(F110,"ckdate bad month",t,0);
  4016.         return("<BAD_MONTH>");
  4017.     }
  4018.     sprintf(nowbuf+4,"%02d",x);         /* SAFE */
  4019.     nowbuf[6] = (t[8] == SP) ? '0' : t[8];
  4020.     nowbuf[7] = t[9];
  4021.     nowbuf[8] = ' ';
  4022.  
  4023.     nowbuf[9] = NUL;
  4024.     debug(F110,"ckdate nowbuf",nowbuf,0);
  4025.  
  4026.     for (x = 11; x < 19; x++) nowbuf[x-2] = t[x];
  4027.     nowbuf[17] = NUL;
  4028.     debug(F110,"ckdate nowbuf",nowbuf,0);
  4029.  
  4030.     return((char *)nowbuf);
  4031. }
  4032.  
  4033. #ifndef NOICP
  4034. #ifdef CKLOGDIAL
  4035.  
  4036. /*
  4037.   fc = 0 for initial open, meaning open, then close immediately.
  4038.   fc > 0 for subsequent opens, meaning open for use, leave open.
  4039. */
  4040. int
  4041. diaopn(s,disp,fc) char *s; int disp, fc; {
  4042.     static struct filinfo xx;
  4043.  
  4044.     if (!s)
  4045.       s = "";
  4046.     if (!*s)
  4047.       return(0);
  4048.  
  4049.     debug(F110,"diaopn log",s,0);
  4050.     debug(F101,"diaopn fc",s,fc);
  4051.     debug(F101,"diaopn disp 1",s,disp);
  4052.     if (fc) disp = 1;                   /* Force append if open for use */
  4053.     debug(F101,"diaopn disp 2",s,disp);
  4054.  
  4055.     zclose(ZDIFIL);                     /* In case a log was already open */
  4056.  
  4057. #ifdef OS2ORUNIX
  4058.     if (s[0] == '|') {                  /* Pipe */
  4059.         char * p = s + 1;
  4060.         debug(F110,"diaopn p",p,0);
  4061.         while (*p) {
  4062.             if (*p != ' ')
  4063.               break;
  4064.             else
  4065.               p++;
  4066.         }
  4067.         debug(F110,"diaopn pipe",p,0);
  4068.         dialog = zxcmd(ZDIFIL,p);
  4069.         debug(F101,"diaopn dialog","",dialog);
  4070.     } else {                            /* File */
  4071. #endif /* OS2ORUNIX */
  4072.         if (disp) {
  4073.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  4074.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  4075.             xx.lblopts = 0;
  4076.             dialog = zopeno(ZDIFIL,s,NULL,&xx);
  4077.         } else dialog = zopeno(ZDIFIL,s,NULL,NULL);
  4078.         if (!dialog)
  4079.           printf("?%s - %s\n",s,ck_errstr());
  4080. #ifdef OS2ORUNIX
  4081.     }
  4082. #endif /* OS2ORUNIX */
  4083.     if (dialog > 0)
  4084.       ckstrncpy(diafil,s,CKMAXPATH+1);
  4085.     else
  4086.       *diafil = '\0';
  4087.     if (fc == 0)                        /* Initial open */
  4088.       zclose(ZDIFIL);                   /* close it */
  4089.     return(dialog);
  4090. }
  4091. #endif /* CKLOGDIAL */
  4092.  
  4093. #ifndef NOSHOW
  4094.  
  4095. /*  SHOW command routines */
  4096.  
  4097. char *
  4098. shoxm() {
  4099.     char * s;
  4100.     switch (binary) {
  4101.       case XYFT_T: s = "text";         break;
  4102. #ifdef VMS
  4103.       case XYFT_B: s = "binary fixed"; break;
  4104.       case XYFT_I: s = "image";        break;
  4105.       case XYFT_L: s = "labeled";      break;
  4106.       case XYFT_U: s = "binary undef"; break;
  4107. #else
  4108. #ifdef MAC
  4109.       case XYFT_B: s = "binary";       break;
  4110.       case XYFT_M: s = "macbinary";    break;
  4111. #else
  4112.       case XYFT_B: s = "binary";       break;
  4113. #ifdef CK_LABELED
  4114.       case XYFT_L: s = "labeled";      break;
  4115. #endif /* CK_LABELED */
  4116. #endif /* MAC */
  4117. #endif /* VMS */
  4118.       default: s = "unknown"; break;
  4119.     }
  4120.     return(s);
  4121. }
  4122.  
  4123. #ifndef NOXFER
  4124. VOID                                    /* SHOW TRANSFER */
  4125. shoxfer() {
  4126.     extern int docrc, usepipes, xfrxla, whereflg;
  4127.     extern char * xfrmsg;
  4128.     printf("\n");
  4129.     printf(" Transfer Bell: %s\n",showoff(xfrbel));
  4130.     printf(" Transfer Interruption: %s\n",showoff(xfrint));
  4131.     printf(" Transfer Cancellation: %s\n",showoff(xfrcan));
  4132. #ifndef NOCSETS
  4133.     printf(" Transfer Translation:  %s\n",showoff(xfrxla));
  4134.     printf(" Transfer Character-set: ");
  4135.     if (tcharset == TC_TRANSP)
  4136.       printf("Transparent\n");
  4137.     else
  4138.       printf("%s\n",tcsinfo[tcharset].keyword);
  4139. #endif /* NOCSETS */
  4140.     printf(" Transfer CRC-calculation: %s\n",showoff(docrc));
  4141.     printf(" Transfer Display: ");
  4142.     switch (fdispla) {
  4143.       case XYFD_N: printf("%s\n","none"); break;
  4144.       case XYFD_R: printf("%s\n","serial"); break;
  4145.       case XYFD_C: printf("%s\n","fullscreen"); break;
  4146.       case XYFD_S: printf("%s\n","crt"); break;
  4147.       case XYFD_B: printf("%s\n","brief"); break;
  4148.       case XYFD_G: printf("%s\n","gui"); break;
  4149.     }
  4150.     printf(" Transfer Message: %s\n", xfrmsg ? xfrmsg : "(none)");
  4151.     printf(" Transfer Locking-shift: ");
  4152.     if (lscapu == 2) {
  4153.         printf("forced");
  4154.     } else {
  4155.         printf("%s", (lscapr ? "enabled" : "disabled"));
  4156.         if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  4157.     }
  4158.     printf("\n Transfer Mode: %s\n",
  4159.            xfermode == XMODE_A ?
  4160.            "automatic" :
  4161.            "manual"
  4162.            );
  4163.     printf(" Transfer Pipes: %s\n", showoff(usepipes));
  4164.     printf(" Transfer Protocol: %s\n",ptab[protocol].p_name);
  4165.     printf(" Transfer Report: %s\n",showoff(whereflg));
  4166.     printf(" Transfer Slow-start: %s\n",showoff(slostart));
  4167.     printf("\n");
  4168. }
  4169. #endif /* NOXFER */
  4170.  
  4171. VOID
  4172. shoflow() {
  4173.     int i, x;
  4174.     extern int cxflow[], cxtype, ncxname, nfloname, autoflow;
  4175.     extern char * cxname[];
  4176.     printf("\nConnection type:        %s\n",cxname[cxtype]);
  4177.     if (autoflow) {
  4178.         printf("Current flow-control:   %s\n", floname[cxflow[cxtype]]);
  4179.         printf("Switches automatically: yes\n");
  4180.     } else {
  4181.         printf("Current flow-control:   %s\n", floname[flow]);
  4182.         printf("Switches automatically: no\n");
  4183.     }
  4184.     printf("\nDefaults by connection type:\n");
  4185.     debug(F111,"shoflow cxtype",cxname[cxtype],cxtype);
  4186.     debug(F101,"shoflow flow","",flow);
  4187.     for (i = 0; i < ncxname; i++) {
  4188. #ifdef NOLOCAL
  4189.         if (i > 0) break;
  4190. #endif /* NOLOCAL */
  4191. #ifndef NETCONN
  4192.         if (i > 2) break;
  4193. #endif /* NETCONN */
  4194. #ifndef DECNET
  4195.         if (i == CXT_DECNET) continue;
  4196. #endif /* DECNET */
  4197. #ifndef DECNET
  4198. #ifndef SUPERLAT
  4199.         if (i == CXT_LAT) continue;
  4200. #endif /* SUPERLAT */
  4201. #endif /* DECNET */
  4202. #ifndef CK_NETBIOS
  4203.         if (i == CXT_NETBIOS) continue;
  4204. #endif /* CK_NETBIOS */
  4205. #ifndef NPIPE
  4206.         if (i == CXT_NPIPE) continue;
  4207. #endif /* NPIPE */
  4208. #ifndef NETCMD
  4209.         if (i == CXT_PIPE) continue;
  4210. #endif /* NETCMD */
  4211. #ifndef ANYX25
  4212.         if (i == CXT_X25) continue;
  4213. #endif /* ANYX25 */
  4214.         x = cxflow[i];
  4215.         debug(F101,"shoflow x","",x);
  4216.         if (x < nfloname)
  4217.           printf("  %-14s: %s\n",cxname[i],floname[x]);
  4218.         else
  4219.           printf("  %-14s: (%d)\n",cxname[i],x);
  4220.     }
  4221.     printf("\n");
  4222. }
  4223.  
  4224. #ifndef NOLOCAL
  4225. #ifdef ANYX25
  4226. int
  4227. shox25(n) int n; {
  4228.     if (nettype == NET_SX25) {
  4229.         printf("SunLink X.25 V%d.%d",x25ver / 10,x25ver % 10);
  4230.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4231.         printf("\n");
  4232.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4233.         printf(" Reverse charge call %s",
  4234.                revcall ? "selected" : "not selected");
  4235.         printf (", Closed user group ");
  4236.         if (closgr > -1)
  4237.           printf ("%d",closgr);
  4238.         else
  4239.           printf ("not selected");
  4240.         printf("\n");
  4241.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4242.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4243.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4244.     } else if (nettype == NET_VX25) {
  4245.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4246.         printf("\n");
  4247.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4248.         printf(" Reverse charge call %s",
  4249.                revcall ? "selected" : "not selected");
  4250.         printf (", Closed user group [unsupported]");
  4251.         if (closgr > -1)
  4252.           printf ("%d",closgr);
  4253.         else
  4254.           printf ("not selected");
  4255.         printf (",");
  4256.         printf("\n");
  4257.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4258.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4259.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4260.     } else if (nettype == NET_IX25) {
  4261.         printf("AIX NPI X.25\n");
  4262.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4263.         printf("\n Reverse charge call %s",
  4264.                revcall ? "selected" : "not selected");
  4265.         printf (", Closed user group [unsupported]");
  4266.         if (closgr > -1)
  4267.           printf ("%d",closgr);
  4268.         else
  4269.           printf ("not selected");
  4270.         printf (",");
  4271.         printf("\n Call user data %s.\n", cudata ? udata : "not selected");
  4272.     }
  4273.     return(n);
  4274. }
  4275.  
  4276. #ifndef IBMX25
  4277. int
  4278. shopad(n) int n; {
  4279.     int i;
  4280.     printf("\nX.3 PAD Parameters:\n");
  4281.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4282.     for (i = 0; i < npadx3; i++) {
  4283.         printf(" [%d] %s %d\n",padx3tab[i].kwval,padx3tab[i].kwd,
  4284.                padparms[padx3tab[i].kwval]);
  4285.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4286.     }
  4287.     return(n);
  4288. }
  4289. #endif /* IBMX25 */
  4290. #endif /* ANYX25 */
  4291.  
  4292. VOID
  4293. shoparc() {
  4294.     extern int reliable, stopbits, clsondisc;
  4295.     int i; char *s;
  4296.     long zz;
  4297.  
  4298. #ifdef NEWFTP
  4299.     if (ftpisconnected()) {
  4300.         shoftp(1);
  4301.         printf("\n");
  4302.     }
  4303. #endif /* NEWFTP */
  4304.  
  4305.     printf("Communications Parameters:\n");
  4306.  
  4307.     if (network
  4308. #ifdef IKSD
  4309.          || inserver
  4310. #endif /* IKSD */
  4311.          ) {
  4312.         printf(" Network Host: %s%s",ttname,
  4313.                (reliable == SET_ON || (reliable == SET_AUTO && !local)
  4314. #ifdef TN_COMPORT
  4315.                && !istncomport()
  4316. #endif /* TN_COMPORT */
  4317. #ifdef IKSD
  4318.                || inserver
  4319. #endif /* IKSD */
  4320.                ) ? " (reliable)" : "");
  4321. #ifdef TN_COMPORT
  4322.         if (istncomport()) {
  4323.             int modemstate;
  4324.             char * oflow, * iflow = "", * parity, * stopsize, * signature;
  4325.             int baud = tnc_get_baud();
  4326.  
  4327.             switch (tnc_get_oflow()) {
  4328.               case TNC_CTL_OFLOW_NONE:
  4329.                 oflow = "none";
  4330.                 break;
  4331.               case TNC_CTL_OFLOW_XON_XOFF:
  4332.                 oflow = "xon/xoff";
  4333.                 break;
  4334.               case TNC_CTL_OFLOW_RTS_CTS:
  4335.                 oflow = "rts/cts";
  4336.                 break;
  4337.               case TNC_CTL_OFLOW_DCD:
  4338.                 oflow = "dcd";
  4339.                 break;
  4340.               case TNC_CTL_OFLOW_DSR:
  4341.                 oflow = "dsr";
  4342.                 break;
  4343.               default:
  4344.                 oflow = "(unknown)";
  4345.             }
  4346.             switch (tnc_get_iflow()) {
  4347.               case TNC_CTL_IFLOW_NONE:
  4348.                 iflow = "none";
  4349.                 break;
  4350.               case TNC_CTL_IFLOW_XON_XOFF:
  4351.                 iflow = "xon/xoff";
  4352.                 break;
  4353.               case TNC_CTL_IFLOW_RTS_CTS:
  4354.                 iflow = "rts/cts";
  4355.                 break;
  4356.               case TNC_CTL_IFLOW_DTR:
  4357.                 break;
  4358.               default:
  4359.                 iflow = oflow;
  4360.             }
  4361.             switch (tnc_get_parity()) {
  4362.               case TNC_PAR_NONE:
  4363.                 parity = "none";
  4364.                 break;
  4365.               case TNC_PAR_ODD:
  4366.                 parity = "odd";
  4367.                 break;
  4368.               case TNC_PAR_EVEN:
  4369.                 parity = "even";
  4370.                 break;
  4371.               case TNC_PAR_MARK:
  4372.                 parity = "mark";
  4373.                 break;
  4374.               case TNC_PAR_SPACE:
  4375.                 parity = "space";
  4376.                 break;
  4377.               default:
  4378.                 parity = "(unknown)";
  4379.             }
  4380.             switch (tnc_get_stopsize()) {
  4381.               case TNC_SB_1:
  4382.                 stopsize = "1";
  4383.                 break;
  4384.               case TNC_SB_1_5:
  4385.                 stopsize = "1.5";
  4386.                 break;
  4387.               case TNC_SB_2:
  4388.                 stopsize = "2";
  4389.                 break;
  4390.               default:
  4391.                 stopsize = "(unknown)";
  4392.             }
  4393.         signature = (char *)tnc_get_signature();
  4394.             printf("\n  Signature            : %s\n",signature?signature:"");
  4395.             if (baud <= 0)
  4396.               printf("  Speed                : (unknown)\n");
  4397.             else
  4398.               printf("  Speed                : %d\n", baud);
  4399.             printf("  Outbound Flow Control: %s\n", oflow);
  4400.             printf("  Inbound Flow Control : %s\n", iflow);
  4401.             printf("  Parity               : %s\n", parity);
  4402.             printf("  Data Size            : %d\n", tnc_get_datasize());
  4403.             printf("  Stop Bits            : %s\n", stopsize);
  4404.             printf("  DTR Signal           : %d\n", tnc_get_dtr_state());
  4405.             printf("  RTS Signal           : %d\n", tnc_get_rts_state());
  4406.             printf("  Modem State:\n");
  4407.             modemstate = tnc_get_ms();
  4408.             if (modemstate & TNC_MS_EDGE_RING)
  4409.               printf("    Trailing Edge Ring Detector On\n");
  4410.             else
  4411.               printf("    Trailing Edge Ring Detector Off\n");
  4412.             if (modemstate & TNC_MS_CTS_SIG)
  4413.               printf("    CTS Signal On\n");
  4414.             else
  4415.               printf("    CTS Signal Off\n");
  4416.             if (modemstate & TNC_MS_DSR_SIG)
  4417.               printf("    DSR Signal On\n");
  4418.             else
  4419.               printf("    DSR Signal Off\n");
  4420.             if (modemstate & TNC_MS_RI_SIG)
  4421.               printf("    Ring Indicator On\n");
  4422.             else
  4423.               printf("    Ring Indicator Off\n");
  4424.             if (modemstate & TNC_MS_RLSD_SIG)
  4425.               printf("    RLSD (CD) Signal On\n");
  4426.             else
  4427.               printf("    RLSD (CD) Signal Off\n");
  4428.             printf("\n");
  4429.         }
  4430. #endif /* TN_COMPORT */
  4431.     } else {
  4432.  
  4433.         printf(" %s: %s%s, speed: ",
  4434. #ifdef OS2
  4435.                "Port",
  4436. #else
  4437.                "Line",
  4438. #endif /* OS2 */
  4439.                ttname,
  4440. #ifdef CK_TTYFD
  4441.                (local &&
  4442. #ifdef VMS
  4443.                 vmsttyfd() < 0
  4444. #else
  4445.                 ttyfd == -1
  4446. #endif /* VMS */
  4447.                 ) ?
  4448.                  " (closed)" :
  4449.                    (reliable == SET_ON ? " (reliable)" : "")
  4450. #else
  4451.                ""
  4452. #endif /* CK_TTYFD */
  4453.                );
  4454.         if (
  4455. #ifdef CK_TTYFD
  4456. #ifdef VMS
  4457.             vmsttyfd() < 0
  4458. #else
  4459.             ttyfd == -1
  4460. #endif /* VMS */
  4461.             ||
  4462. #endif /* CK_TTYFD */
  4463.             (zz = ttgspd()) < 0) {
  4464.             printf("unknown");
  4465.         } else {
  4466.             if (speed == 8880) printf("75/1200");
  4467.             else if (speed == 134) printf("134.5");
  4468.             else printf("%ld",zz);
  4469.         }
  4470.     }
  4471.     if (network
  4472. #ifdef IKSD
  4473.          || inserver
  4474. #endif /* IKSD */
  4475.          )
  4476.       printf("\n Mode: ");
  4477.     else
  4478.       printf(", mode: ");
  4479.     if (local) printf("local"); else printf("remote");
  4480.     if (network == 0
  4481. #ifdef IKSD
  4482.          && !inserver
  4483. #endif/* IKSD */
  4484.          ) {
  4485. #ifdef CK_TAPI
  4486.         if (tttapi && !tapipass )
  4487.           printf(", modem: %s","TAPI");
  4488.         else
  4489. #endif /* CK_TAPI */
  4490.         printf(", modem: %s",gmdmtyp());
  4491.     } else {
  4492. #ifdef NETCONN
  4493.        if (nettype == NET_TCPA) printf(", TCP/IP");
  4494.        if (nettype == NET_TCPB) printf(", TCP/IP");
  4495.        if (nettype == NET_DEC) {
  4496.            if (ttnproto == NP_LAT) printf(", DECnet LAT");
  4497.            else if ( ttnproto == NP_CTERM ) printf(", DECnet CTERM");
  4498.            else printf(", DECnet");
  4499.        }
  4500.        if (nettype == NET_SLAT) printf(", Meridian Technologies' SuperLAT");
  4501. #ifdef NETFILE
  4502.        if (nettype == NET_FILE) printf(", local file");
  4503. #endif /* NETFILE */
  4504. #ifdef NETCMD
  4505.        if (nettype == NET_CMD) printf(", pipe");
  4506. #endif /* NETCMD */
  4507. #ifdef NETPTY
  4508.        if (nettype == NET_PTY) printf(", pseudoterminal");
  4509. #endif /* NETPTY */
  4510. #ifdef NETDLL
  4511.        if (nettype == NET_DLL) printf(", dynamic load library");
  4512. #endif /* NETDLL */
  4513.        if (nettype == NET_PIPE) printf(", Named Pipes");
  4514. #ifdef SSHBUILTIN
  4515.        if (nettype == NET_SSH)
  4516.          printf(", Secure Shell protocol (SECURE)");
  4517. #endif /* SSHBUILTIN */
  4518. #ifdef ANYX25
  4519.        if (shox25(0) < 0) return;
  4520. #endif /* ANYX25 */
  4521.        if (IS_TELNET()) {
  4522.            printf(", telnet protocol");
  4523.            if (0
  4524. #ifdef CK_ENCRYPTION
  4525.                || ck_tn_encrypting() && ck_tn_decrypting()
  4526. #endif /* CK_ENCRYPTION */
  4527. #ifdef CK_SSL
  4528.                || tls_active_flag || ssl_active_flag
  4529. #endif /* CK_SSL */
  4530.                )
  4531.              printf(" (SECURE)");
  4532.        }
  4533. #ifdef RLOGCODE
  4534.        else if (ttnproto == NP_RLOGIN || ttnproto == NP_K4LOGIN ||
  4535.                 ttnproto == NP_K5LOGIN)
  4536.          printf(", rlogin protocol");
  4537.        else if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN)
  4538.          printf(", rlogin protocol (SECURE)");
  4539. #endif /* RLOGCODE */
  4540. #ifdef CK_KERBEROS
  4541. #ifdef KRB5
  4542.        else if (ttnproto == NP_K5U2U)
  4543.          printf(", Kerberos 5 User to User protocol (SECURE)");
  4544. #endif /* KRB5 */
  4545. #endif /* CK_KERBEROS */
  4546. #endif /* NETCONN */
  4547.     }
  4548.     printf("\n");
  4549.     if (hwparity && local && !network)
  4550.       s = parnam((char)hwparity);
  4551.     else
  4552.       s = parnam((char)parity);
  4553.     printf(" Parity: %s%s",hwparity ? "hardware " : "", s);
  4554. #ifndef NOLOCAL
  4555.     if (local && !network) {
  4556.         int sb;
  4557.         char c;
  4558.         c = s[0];
  4559.         if (islower(c)) c = toupper(c);
  4560.         sb = stopbits;
  4561.         if (sb < 1) {
  4562.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  4563.             printf(", stop-bits: (default)");
  4564.         } else {
  4565.             printf(", stop-bits: %d",sb);
  4566.         }
  4567.         if (hwparity)
  4568.           printf(" (8%c%d)",c,sb);
  4569.         else if (parity)
  4570.           printf(" (7%c%d)",c,sb);
  4571.         else
  4572.           printf(" (8N%d)",sb);
  4573.         printf("\n D");
  4574.     } else
  4575.       printf(", d");
  4576. #endif /* NOLOCAL */
  4577.  
  4578.     printf("uplex: %s, ", duplex ? "half" : "full");
  4579.     debug(F101,"shoparp flow","",flow);
  4580.     printf("flow: %s", floname[flow]);
  4581.     printf(", handshake: ");
  4582.     if (turn) printf("%d\n",turnch); else printf("none\n");
  4583. #ifdef COMMENT
  4584.     if (local && !network) {            /* SET CARRIER-WATCH */
  4585. #endif /* COMMENT */
  4586.         if (carrier == CAR_OFF) s = "off";
  4587.         else if (carrier == CAR_ON) s = "on";
  4588.         else if (carrier == CAR_AUT) s = "auto";
  4589.         else s = "unknown";
  4590.         printf(" Carrier-watch: %s", s);
  4591.         if (carrier == CAR_ON) {
  4592.             if (cdtimo) printf(", timeout: %d sec", cdtimo);
  4593.             else printf(", timeout: none");
  4594.         }
  4595. #ifdef COMMENT
  4596.     }
  4597. #endif /* COMMENT */
  4598.     printf(", close-on-disconnect: %s\n",showoff(clsondisc));
  4599.  
  4600. #ifdef UNIX                             /* UUCP lockfile, UNIX only */
  4601.     if (local) {
  4602. #ifndef NOUUCP
  4603.         if (!network && haslock && *flfnam)
  4604.           printf(" Lockfile: %s",flfnam);
  4605. #ifndef USETTYLOCK
  4606.         if (!network && haslock && lock2[0])
  4607.           printf("\n Secondary lockfile: %s",lock2);
  4608. #endif /* USETTYLOCK */
  4609. #else
  4610. #ifdef QNX
  4611.         {
  4612.             extern int qnxportlock, qnxopencount();
  4613.             if (local)
  4614.               printf(" Qnx-port-lock: %s, Open count: %d",
  4615.                      showoff(qnxportlock),
  4616.                      qnxopencount()
  4617.                      );
  4618.             else
  4619.               printf(" Qnx-port-lock: %s", showoff(qnxportlock));
  4620.         }
  4621. #endif /* QNX */
  4622. #endif /* NOUUCP */
  4623.         printf("\n");
  4624.     } else {
  4625.         char * s, * ttglckdir();
  4626.         s = ttglckdir();
  4627.         if (!s) s = "";
  4628.         printf(" Lockfile directory: %s\n", *s ? s : "(none)");
  4629.     }
  4630. #endif /* UNIX */
  4631.     if (!local) {
  4632.         printf(" Typical port device name: %s\n",ttgtpn());
  4633.     }
  4634.     if (local) {
  4635.         int i;
  4636.         i = parity ? 7 : 8;
  4637.         if (i == 8) i = (cmask == 0177) ? 7 : 8;
  4638.         printf(" Terminal bytesize: %d,",i);
  4639.         printf(" escape character: %d (^%c)\n",escape,ctl(escape));
  4640.     }
  4641. }
  4642.  
  4643. int
  4644. shotcp(n) int n; {
  4645. #ifdef TCPSOCKET
  4646.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  4647.         printf("SET TCP parameters:\n");
  4648.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4649.         printf(" Reverse DNS lookup: %s\n", showooa(tcp_rdns));
  4650.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4651.  
  4652. #ifdef CK_DNS_SRV
  4653.         printf(" DNS Service Records lookup: %s\n", showooa(tcp_dns_srv));
  4654.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4655. #endif /* CK_DNS_SRV */
  4656.  
  4657. #ifndef NOTCPOPTS
  4658. #ifdef SOL_SOCKET
  4659. #ifdef SO_KEEPALIVE
  4660.         printf(" Keepalive: %s\n", showoff(tcp_keepalive));
  4661.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4662. #endif /* SO_KEEPALIVE */
  4663.  
  4664. #ifdef SO_LINGER
  4665.         printf(" Linger: %s", tcp_linger ? "on, " : "off\n" );
  4666.         if (tcp_linger) {
  4667.             if (tcp_linger_tmo)
  4668.               printf("%d x 10 milliseconds\n",tcp_linger_tmo);
  4669.             else
  4670.               printf("no timeout\n");
  4671.         }
  4672.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4673. #endif /* SO_LINGER */
  4674.  
  4675. #ifdef SO_DONTROUTE
  4676.         printf(" DontRoute: %s\n", tcp_dontroute ? "on" : "off" );
  4677.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4678. #endif /* SO_DONTROUTE */
  4679.  
  4680. #ifdef TCP_NODELAY
  4681.         printf(" Nodelay: %s\n", showoff(tcp_nodelay));
  4682.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4683. #endif /* TCP_NODELAY */
  4684.  
  4685. #ifdef SO_SNDBUF
  4686.         if (tcp_sendbuf <= 0)
  4687.           printf(" Send buffer: (default size)\n");
  4688.         else
  4689.           printf(" Send buffer: %d bytes\n", tcp_sendbuf);
  4690.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4691. #endif /* SO_SNDBUF */
  4692. #ifdef SO_RCVBUF
  4693.         if (tcp_recvbuf <= 0)
  4694.           printf(" Receive buffer: (default size)\n");
  4695.         else
  4696.           printf(" Receive buffer: %d bytes\n", tcp_recvbuf);
  4697.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4698. #endif /* SO_RCVBUF */
  4699. #endif /* SOL_SOCKET */
  4700. #endif /* NOTCPOPTS */
  4701.         printf(" address: %s\n",tcp_address ? tcp_address : "(none)");
  4702.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4703. #ifndef NOHTTP
  4704.         printf(" http-proxy: %s\n",tcp_http_proxy ? tcp_http_proxy : "(none)");
  4705.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4706. #endif /* NOHTTP */
  4707. #ifdef NT
  4708. #ifdef CK_SOCKS
  4709.         printf(" socks-server: %s\n",tcp_socks_svr ? tcp_socks_svr : "(none)");
  4710.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4711. #ifdef CK_SOCKS_NS
  4712.         printf(" socks-name-server: %s\n",
  4713.                tcp_socks_ns ? tcp_socks_ns : "(none)");
  4714.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4715. #endif /* CK_SOCKS_NS */
  4716. #endif /* CK_SOCKS */
  4717. #endif /* NT */
  4718.     }
  4719. #endif /* TCPSOCKET */
  4720.     return(n);
  4721. }
  4722.  
  4723. #ifdef TNCODE
  4724. int
  4725. shotopt(n) int n; {
  4726.     int opt;
  4727.  
  4728.     printf("%-21s %12s %12s %12s %12s\n\n",
  4729.            "Telnet Option","Me (client)","U (client)",
  4730.            "Me (server)","U (server)");
  4731.     n += 2;
  4732.     if (n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4733.  
  4734.     for ( opt = TELOPT_FIRST; opt <= TELOPT_LAST; opt++) {
  4735.         switch (opt) {
  4736.           case TELOPT_AUTHENTICATION:
  4737.           case TELOPT_ENCRYPTION:
  4738.           case TELOPT_TTYPE:
  4739.           case TELOPT_NAWS:
  4740.           case TELOPT_BINARY:
  4741.           case TELOPT_NEWENVIRON:
  4742.           case TELOPT_SNDLOC:
  4743.           case TELOPT_XDISPLOC:
  4744.           case TELOPT_SGA:
  4745.           case TELOPT_ECHO:
  4746.           case TELOPT_KERMIT:
  4747.           case TELOPT_START_TLS:
  4748.           case TELOPT_FORWARD_X:
  4749.           case TELOPT_COMPORT:
  4750.             break;
  4751.           default:
  4752.             continue;
  4753.         }
  4754.         printf("%03d %-17s ",
  4755.                opt, TELOPT(opt)
  4756.                );
  4757.         printf("%12s %12s ",
  4758.                TELOPT_MODE(TELOPT_DEF_C_ME_MODE(opt)),
  4759.                TELOPT_MODE(TELOPT_DEF_C_U_MODE(opt))
  4760.                );
  4761.         printf("%12s %12s\n",
  4762.                TELOPT_MODE(TELOPT_DEF_S_ME_MODE(opt)),
  4763.                TELOPT_MODE(TELOPT_DEF_S_U_MODE(opt))
  4764.                );
  4765.  
  4766.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4767.         if (sstelnet)
  4768.           printf("%21s %12s %12s %12s %12s\n",
  4769.                  "",
  4770.                  "",
  4771.                  "",
  4772.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4773.                  (TELOPT_U(opt)?"DO":"DONT")
  4774.                  );
  4775.         else
  4776.           printf("%21s %12s %12s %12s %12s\n",
  4777.                  "",
  4778.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4779.                  (TELOPT_U(opt)?"DO":"DONT"),
  4780.                  "",
  4781.                  ""
  4782.                  );
  4783.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4784.     }
  4785.     return(n);
  4786. }
  4787.  
  4788. int
  4789. shotel(n) int n; {
  4790.     extern int tn_duplex;
  4791. #ifdef CK_ENVIRONMENT
  4792.     extern int tn_env_flg;
  4793.     extern char tn_env_acct[];
  4794.     extern char tn_env_job[];
  4795.     extern char tn_env_prnt[];
  4796.     extern char tn_env_sys[];
  4797.     extern char * tn_env_uservar[8][2];
  4798.     int x;
  4799. #endif /* CK_ENVIRONMENT */
  4800. #ifdef CK_SNDLOC
  4801.     extern char * tn_loc;
  4802. #endif /* CK_SNDLOC */
  4803.     printf("SET TELNET parameters:\n echo: %s\n NVT newline-mode: ",
  4804.            tn_duplex ? "local" : "remote");
  4805.     switch (tn_nlm) {
  4806.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4807.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4808.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4809.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4810.     }
  4811.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4812. #ifdef CK_AUTHENTICATION
  4813.     {
  4814.         int type = ck_tn_authenticated();
  4815.         printf(" authentication: ");
  4816.         switch (sstelnet ?
  4817.                 TELOPT_U_MODE(TELOPT_AUTHENTICATION) :
  4818.                  TELOPT_ME_MODE(TELOPT_AUTHENTICATION)
  4819.                 ) {
  4820.           case TN_NG_AC: printf( "accepted " ); break;
  4821.           case TN_NG_RF: printf( "refused  " ); break;
  4822.           case TN_NG_RQ: printf( "requested"); break;
  4823.           case TN_NG_MU: printf( "required "); break;
  4824.         }
  4825.  
  4826. #ifdef CK_SSL
  4827.         if ((ssl_active_flag || tls_active_flag) &&
  4828.              ck_tn_auth_valid() == AUTH_VALID &&
  4829.              (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  4830.                type == AUTHTYPE_NULL ||
  4831.                type == AUTHTYPE_AUTO))
  4832.             printf("   in use: X.509 certificate\n");
  4833.         else
  4834. #endif /* CK_SSL */
  4835.           printf("   in use: %s\n",AUTHTYPE_NAME(type));
  4836.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4837.         if (forward_flag)
  4838.           printf("  credentials forwarding requested %s\n",
  4839.                  forwarded_tickets ? "and completed" :
  4840.                  "but not completed");
  4841.         else
  4842.           printf("  credentials forwarding disabled\n");
  4843.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4844.     }
  4845. #endif /* CK_AUTHENTICATION */
  4846. #ifdef CK_ENCRYPTION
  4847.     {
  4848.         int i,x;
  4849.         int e_type = ck_tn_encrypting();
  4850.         int d_type = ck_tn_decrypting();
  4851.         char * e_str = NULL, * d_str = NULL;
  4852.         static struct keytab * tnetbl = NULL;
  4853.         static int ntnetbl = 0;
  4854.  
  4855.         x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  4856.  
  4857.         for (i = 0; i < ntnetbl; i++) {
  4858.             if (e_type == tnetbl[i].kwval)
  4859.               e_str = tnetbl[i].kwd;
  4860.             if (d_type == tnetbl[i].kwval)
  4861.               d_str = tnetbl[i].kwd;
  4862.         }
  4863.         printf(" encryption: ");
  4864.         switch (TELOPT_ME_MODE(TELOPT_ENCRYPTION)) {
  4865.           /* This should be changed to report both ME and U modes */
  4866.           case TN_NG_AC: printf( "accepted " ); break;
  4867.           case TN_NG_RF: printf( "refused  " ); break;
  4868.           case TN_NG_RQ: printf( "requested"); break;
  4869.           case TN_NG_MU: printf( "required "); break;
  4870.         }
  4871.         printf("       in use: ");
  4872.         switch ((e_type ? 1 : 0) | (d_type ? 2 : 0)) {
  4873.           case 0:
  4874.             printf("plain text in both directions");
  4875.             break;
  4876.           case 1:
  4877.             printf("%s output, plain text input",e_str);
  4878.             break;
  4879.           case 2:
  4880.             printf("plain text output, %s input",d_str);
  4881.             break;
  4882.           case 3:
  4883.             printf("%s output, %s input",e_str,d_str);
  4884.             break;
  4885.         }
  4886.         printf("\n");
  4887.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4888.     }
  4889. #endif /* CK_ENCRYPTION */
  4890. #ifdef IKS_OPTION
  4891.     printf(" kermit: ");
  4892.     switch (TELOPT_U_MODE(TELOPT_KERMIT)) {
  4893.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4894.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4895.       case TN_NG_RQ: printf( "u, requested; "); break;
  4896.       case TN_NG_MU: printf( "u, required;  "); break;
  4897.     }
  4898.     switch (TELOPT_ME_MODE(TELOPT_KERMIT)) {
  4899.       case TN_NG_AC: printf( "me, accepted;  " ); break;
  4900.       case TN_NG_RF: printf( "me, refused;   " ); break;
  4901.       case TN_NG_RQ: printf( "me, requested; "); break;
  4902.       case TN_NG_MU: printf( "me, required;  "); break;
  4903.     }
  4904.     if (TELOPT_U(TELOPT_KERMIT))
  4905.       printf(" u, %s",
  4906.              TELOPT_SB(TELOPT_KERMIT).kermit.u_start ?
  4907.              "started" :
  4908.              "stopped"
  4909.              );
  4910.     else
  4911.       printf(" u, n/a");
  4912.     if (TELOPT_ME(TELOPT_KERMIT))
  4913.       printf(" me, %s;",
  4914.              TELOPT_SB(TELOPT_KERMIT).kermit.me_start ?
  4915.              "started" :
  4916.              "stopped"
  4917.              );
  4918.     else
  4919.       printf(" me, n/a;");
  4920.     printf("\n");
  4921.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4922. #endif /* IKS_OPTION */
  4923.     printf(" BINARY newline-mode: ");
  4924.     switch (tn_b_nlm) {
  4925.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4926.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4927.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4928.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4929.     }
  4930.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4931.     printf(" binary-mode: ");
  4932.     switch (TELOPT_U_MODE(TELOPT_BINARY)) {
  4933.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4934.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4935.       case TN_NG_RQ: printf( "u, requested; "); break;
  4936.       case TN_NG_MU: printf( "u, required;  "); break;
  4937.     }
  4938.     switch (TELOPT_ME_MODE(TELOPT_BINARY)) {
  4939.       case TN_NG_AC: printf( "me, accepted; " ); break ;
  4940.       case TN_NG_RF: printf( "me, refused; " ); break;
  4941.       case TN_NG_RQ: printf( "me, requested; "); break;
  4942.       case TN_NG_MU: printf( "me, required;  "); break;
  4943.     }
  4944.     printf("u, %s; me, %s\n",
  4945.            TELOPT_U(TELOPT_BINARY) ? "BINARY" : "NVT",
  4946.            TELOPT_ME(TELOPT_BINARY) ? "BINARY" : "NVT"
  4947.            );
  4948.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4949.     printf(" binary-transfer-mode: %s\n",showoff(tn_b_xfer));
  4950.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4951.     printf(" bug binary-me-means-u-too: %s\n",showoff(tn_b_meu));
  4952.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4953.     printf(" bug binary-u-means-me-too: %s\n",showoff(tn_b_ume));
  4954.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4955.     printf(" bug sb-implies-will-do: %s\n",showoff(tn_sb_bug));
  4956.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4957.     printf(" bug auth-krb5-des: %s\n",showoff(tn_auth_krb5_des_bug));
  4958.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4959.     printf(" terminal-type: ");
  4960.     if (tn_term) {
  4961.         printf("%s\n",tn_term);
  4962.     } else {
  4963.         char *p;
  4964. #ifdef OS2
  4965.         p = (tt_type >= 0 && tt_type <= max_tt) ?
  4966.           tt_info[tt_type].x_name :
  4967.             "UNKNOWN";
  4968. #else
  4969.         p = getenv("TERM");
  4970. #endif /* OS2 */
  4971.         if (p)
  4972.           printf("none (%s will be used)\n",p);
  4973.         else printf("none\n");
  4974.     }
  4975.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4976. #ifdef CK_ENVIRONMENT
  4977.     printf(" environment: %s\n", showoff(tn_env_flg));
  4978.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4979.     printf("   ACCOUNT: %s\n",tn_env_acct);
  4980.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4981.     printf("   DISPLAY: %s\n",(char *)tn_get_display() ?
  4982.             (char *)tn_get_display() : "");
  4983.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4984.     printf("   JOB    : %s\n",tn_env_job);
  4985.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4986.     printf("   PRINTER: %s\n",tn_env_prnt);
  4987.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4988. #ifndef NOSPL
  4989.     printf("   USER   : %s\n",uidbuf);
  4990.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4991. #endif /* NOSPL */
  4992.     printf("   SYSTEM : %s\n",tn_env_sys);
  4993.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4994.     for (x = 0; x < 8; x++) {
  4995.         if (tn_env_uservar[x][0] && tn_env_uservar[x][1]) {
  4996.             printf("   %-7s: %s\n",tn_env_uservar[x][0],
  4997.                    tn_env_uservar[x][1]);
  4998.             if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4999.         }
  5000.     }
  5001. #endif /* CK_ENVIRONMENT */
  5002. #ifdef CK_SNDLOC
  5003.     printf("  LOCATION: %s\n", tn_loc ? tn_loc : "");
  5004.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5005. #endif /* CK_SNDLOC */
  5006. #ifdef CK_FORWARD_X
  5007.     printf(" .Xauthority-file: %s\n", (char *)XauFileName() ?
  5008.             (char *)XauFileName() : "(none)");
  5009.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5010. #endif /* CK_FORWARD_X */
  5011.     return(n);
  5012. }
  5013. #endif /* TNCODE */
  5014.  
  5015. #ifdef CK_NETBIOS
  5016. static int
  5017. shonb(n) int n; {
  5018.     printf("NETBIOS parameters:\n");
  5019.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5020.     printf(" API       : %s\n",
  5021.            NetbeuiAPI ?
  5022.            "NETAPI.DLL - IBM Extended Services or Novell Netware Requester"
  5023.            : "ACSNETB.DLL - IBM Network Transport Services/2" ) ;
  5024.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5025.     printf(" Local Name: [%s]\n", NetBiosName);
  5026.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5027.     printf(" Adapter   : %d\n", NetBiosAdapter);
  5028.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5029.     if (NetBiosLSN > 0xFF) {
  5030.         printf(" Session   : %d\n", NetBiosLSN);
  5031.     } else {
  5032.         printf(" Session   : none active\n");
  5033.     }
  5034.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  5035.     return(n);
  5036. }
  5037. #endif /* CK_NETBIOS */
  5038.  
  5039. #ifndef NONET
  5040. int
  5041. shonet() {
  5042.  
  5043. #ifndef NETCONN
  5044.     printf("\nNo networks are supported in this version of C-Kermit\n");
  5045.  
  5046. #else
  5047. #ifdef NOLOCAL
  5048.     printf("\nNo networks are supported in this version of C-Kermit\n");
  5049.  
  5050. #else /* rest of this routine */
  5051.  
  5052.     int i, n = 4;
  5053.  
  5054. #ifndef NODIAL
  5055.     if (nnetdir <= 1) {
  5056.         printf("\nNetwork directory: %s\n",netdir[0] ? netdir[0] : "(none)");
  5057.         n++;
  5058.     } else {
  5059.         int i;
  5060.         printf("\nNetwork directories:\n");
  5061.         for (i = 0; i < nnetdir; i++) {
  5062.             printf("%2d. %s\n",i,netdir[i]);
  5063.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5064.         }
  5065.     }
  5066. #endif /* NODIAL */
  5067.  
  5068. #ifdef SSHCMD
  5069.     {
  5070.         extern char * sshcmd;
  5071.         printf("SSH COMMAND: %s\n",sshcmd ? sshcmd : "ssh -e none");
  5072.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5073.     }
  5074. #endif /* SSHCMD */
  5075.  
  5076. #ifdef OS2
  5077.     printf("\nNetwork availability:\n");
  5078. #else
  5079.     printf("\nSupported networks:\n");
  5080. #endif /* OS2 */
  5081.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5082.  
  5083. #ifdef VMS
  5084.  
  5085. #ifdef TCPWARE
  5086.     printf(" Process Software Corporation TCPware for OpenVMS");
  5087. #else
  5088. #ifdef MULTINET
  5089.     printf(" TGV MultiNet TCP/IP");
  5090. #else
  5091. #ifdef WINTCP
  5092.     printf(" WOLLONGONG WIN/TCP");
  5093. #else
  5094. #ifdef DEC_TCPIP
  5095.     {
  5096.         static $DESCRIPTOR(tcp_desc,"_TCP0:");
  5097.         int status;
  5098.         long devclass;
  5099.         static int itmcod = DVI$_DEVCLASS;
  5100.  
  5101. #ifdef COMMENT
  5102.         status = LIB$GETDVI(&itmcod, 0, &tcp_desc, &devclass);
  5103. #else
  5104.         /* Martin Zinser 9/96 */
  5105.         status = lib$getdvi(&itmcod, 0, &tcp_desc, &devclass);
  5106. #endif /* COMMENT */
  5107.         if ((status & 1) && (devclass == DC$_SCOM))
  5108.           printf(" Process Software Corporation TCPware for OpenVMS");
  5109.         else
  5110. #ifdef UCX50
  5111.           printf(" DEC TCP/IP Services for (Open)VMS 5.0");
  5112. #else
  5113.           printf(" DEC TCP/IP Services for (Open)VMS");
  5114. #endif /* UCX50 */
  5115.     }
  5116. #else
  5117. #ifdef CMU_TCPIP
  5118.     printf(" CMU-OpenVMS/IP");
  5119. #else
  5120.     printf(" None");
  5121. #endif /* CMU_TCPIP */
  5122. #endif /* DEC_TCPIP */
  5123. #endif /* WINTCP */
  5124. #endif /* MULTINET */
  5125. #endif /* TCPWARE */
  5126.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5127. #ifdef TNCODE
  5128.     printf(", TELNET protocol\n\n");
  5129.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5130.     n = shotel(n);
  5131.     if (n < 0) return(0);
  5132.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5133. #endif /* TNCODE */
  5134.     printf("\n");
  5135.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5136.     printf("\n");
  5137.     n = shotcp(++n);
  5138.     if (n < 0) return(0);
  5139. #else /* Not VMS */
  5140.  
  5141. #ifdef SUNX25
  5142.     printf(" SunLink X.25\n");
  5143.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5144. #endif /* SUNX25 */
  5145.  
  5146. #ifdef STRATUSX25
  5147.     printf(" Stratus VOS X.25\n");
  5148.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5149. #endif /* STRATUSX25 */
  5150.  
  5151. #ifdef IBMX25
  5152.     printf(" IBM AIX X.25\n");
  5153.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5154. #endif /* IBMX25 */
  5155.  
  5156. #ifdef HPX25
  5157.     printf(" HP-UX X.25\n");
  5158.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5159. #endif /* HPX25 */
  5160.  
  5161. #ifdef SSHBUILTIN
  5162.     if (ck_ssleay_is_installed())
  5163.         printf(" SSH V1 and V2 protocols\n");
  5164.     else
  5165.         printf(" SSH V1 and V2 protocols - not available\n");
  5166. #endif /* SSHBUILTIN */
  5167.  
  5168. #ifdef DECNET
  5169. #ifdef OS2
  5170. #ifdef NT
  5171.     if (dnet_avail)
  5172.       printf(" DECnet, LAT and CTERM protocols\n");
  5173.     else
  5174.       printf(" DECnet, LAT and CTERM protocols - not available\n");
  5175.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5176. #else /* NT */
  5177.     if (dnet_avail)
  5178.       printf(" DECnet, LAT protocol\n");
  5179.     else
  5180.       printf(" DECnet, LAT protocol - not available\n");
  5181.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5182. #endif /* NT */
  5183. #else
  5184.     printf(" DECnet\n");
  5185.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5186. #endif /* OS2 */
  5187. #endif /* DECNET */
  5188.  
  5189. #ifdef NPIPE
  5190.     printf(" Named Pipes\n");
  5191.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5192. #endif /* NPIPE */
  5193.  
  5194. #ifdef CK_NETBIOS
  5195.     if (netbiosAvail)
  5196.       printf(" NETBIOS\n");
  5197.     else
  5198.       printf(" NETBIOS - not available\n");
  5199.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5200. #endif /* CK_NETBIOS */
  5201.  
  5202. #ifdef SUPERLAT
  5203.     if (slat_avail)
  5204.       printf(" SuperLAT\n");
  5205.     else
  5206.       printf(" SuperLAT - not available\n") ;
  5207.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5208. #endif /* SUPERLAT */
  5209.  
  5210. #ifdef TCPSOCKET
  5211.     if (
  5212. #ifdef OS2
  5213.         tcp_avail
  5214. #else
  5215.         1
  5216. #endif /* OS2 */
  5217.         ) {
  5218.         char ipaddr[16];
  5219.  
  5220.         if (getlocalipaddrs(ipaddr,16,0) < 0) {
  5221. #ifdef OS2ONLY
  5222.             printf(" TCP/IP via %s\n", tcpname);
  5223. #else
  5224.             printf(" TCP/IP\n");
  5225. #endif /* OS2ONLY */
  5226.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5227.         } else {
  5228.             int i = 1;
  5229. #ifdef OS2ONLY
  5230.           printf(" TCP/IP [%16s] via %s\n", ipaddr, tcpname);
  5231. #else
  5232.           printf(" TCP/IP [%16s]\n",ipaddr);
  5233. #endif /* OS2ONLY */
  5234.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5235.  
  5236.             while (getlocalipaddrs(ipaddr,16,i++) >= 0) {
  5237.                 printf("        [%16s]\n",ipaddr);
  5238.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5239.             }
  5240.         }
  5241.         if (nettype == NET_TCPB) {
  5242.             printf("\n");
  5243.             n = shotcp(++n);
  5244.             if (n < 0) return(0);
  5245. #ifdef TNCODE
  5246.             printf("\n");
  5247.             n = shotel(++n);
  5248.             if (n < 0) return(0);
  5249. #endif /* TNCODE */
  5250.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5251.         }
  5252. #ifdef OS2
  5253.     } else {
  5254.         printf(" TCP/IP - not available%s\n",tcpname[0] ? tcpname : "" );
  5255.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5256. #endif /* OS2 */
  5257.     }
  5258. #endif /* TCPSOCKET */
  5259.  
  5260. #ifdef CK_NETBIOS
  5261.     if (netbiosAvail && nettype == NET_BIOS) {
  5262.        printf("\n") ;
  5263.        if ((n = shonb(++n)) < 0) return(0);
  5264.        if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5265.     }
  5266. #endif /* CK_NETBIOS */
  5267.  
  5268. #endif /* VMS */
  5269.  
  5270.     printf("\nActive network connection:\n");
  5271.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5272.  
  5273.     if (network) {
  5274.         printf(" Host: %s",ttname);
  5275.         if ((nettype == NET_TCPA || nettype == NET_TCPB) && *ipaddr)
  5276.           printf(" [%s]",ipaddr);
  5277.     } else
  5278.       printf(" Host: none");
  5279.     printf(", via: ");
  5280.     if (nettype == NET_TCPA || nettype == NET_TCPB)
  5281.       printf("tcp/ip\n");
  5282.     else if (nettype == NET_SX25)
  5283.       printf("SunLink X.25\n");
  5284.     else if (nettype == NET_VX25)
  5285.       printf("Stratus VOS X.25\n");
  5286.     else if (nettype == NET_IX25)
  5287.       printf("IBM AIX X.25\n");
  5288.     else if (nettype == NET_HX25)
  5289.       printf("HP-UX X.25\n");
  5290.     else if (nettype == NET_DEC) {
  5291.         if ( ttnproto == NP_LAT )
  5292.           printf("DECnet LAT\n");
  5293.         else if ( ttnproto == NP_CTERM )
  5294.           printf("DECnet CTERM\n");
  5295.         else
  5296.           printf("DECnet\n");
  5297.     } else if (nettype == NET_PIPE)
  5298.       printf("Named Pipes\n");
  5299.     else if (nettype == NET_BIOS)
  5300.       printf("NetBIOS\n");
  5301.     else if (nettype == NET_SLAT)
  5302.       printf("SuperLAT\n");
  5303.  
  5304. #ifdef NETFILE
  5305.     else if ( nettype == NET_FILE )
  5306.       printf("local file\n");
  5307. #endif /* NETFILE */
  5308. #ifdef NETCMD
  5309.     else if ( nettype == NET_CMD )
  5310.       printf("pipe\n");
  5311. #endif /* NETCMD */
  5312. #ifdef NETPTY
  5313.     else if ( nettype == NET_PTY )
  5314.         printf("pseudoterminal\n");
  5315. #endif /* NETPTY */
  5316. #ifdef NETDLL
  5317.     else if ( nettype == NET_DLL )
  5318.       printf("dynamic link library\n");
  5319. #endif /* NETDLL */
  5320.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5321.  
  5322. #ifdef ANYX25
  5323.     if ((nettype == NET_SX25) ||
  5324.         (nettype == NET_VX25) ||
  5325.         (nettype == NET_IX25))
  5326.       if ((n = shox25(n)) < 0) return(0);
  5327. #endif /* ANYX25 */
  5328.  
  5329. #ifdef SSHBUILTIN
  5330.     if (nettype == NET_SSH) {
  5331.         printf("Secure Shell protocol\n");
  5332.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5333.     }
  5334. #endif /* SSHBUILTIN */
  5335.  
  5336.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  5337. #ifdef RLOGCODE
  5338.         if (ttnproto == NP_RLOGIN) {
  5339.             printf(" LOGIN (rlogin) protocol\n");
  5340.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5341.         }
  5342. #ifdef CK_KERBEROS
  5343.         else if (ttnproto == NP_K4LOGIN) {
  5344.             printf(" Kerberos 4 LOGIN (klogin) protocol\n");
  5345.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5346.         }
  5347.         else if (ttnproto == NP_EK4LOGIN) {
  5348.             printf(" Encrypted Kerberos 4 LOGIN (eklogin) protocol\n");
  5349.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5350.         }
  5351.         else if (ttnproto == NP_K5LOGIN) {
  5352.             printf(" Kerberos 5 LOGIN (klogin) protocol\n");
  5353.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5354.         }
  5355.         else if (ttnproto == NP_EK5LOGIN) {
  5356.             printf(" Encrypted Kerberos 5 LOGIN (eklogin) protocol\n");
  5357.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5358.         }
  5359. #endif /* CK_KERBEROS */
  5360. #endif /* RLOGCODE */
  5361. #ifdef CK_KERBEROS
  5362.         if (ttnproto == NP_K5U2U) {
  5363.             printf(" Kerberos 5 User to User protocol\n");
  5364.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5365.         }
  5366. #endif /* CK_KERBEROS */
  5367.  
  5368. #ifdef TNCODE
  5369.         if (IS_TELNET()) {
  5370.             printf(" TELNET protocol\n");
  5371.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5372.             printf(" Echoing is currently %s\n",duplex ? "local" : "remote");
  5373.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5374.         }
  5375. #endif /* TNCODE */
  5376.         if (ttnproto == NP_TCPRAW) {
  5377.             printf(" Raw TCP socket\n");
  5378.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5379.         }
  5380.     }
  5381.     printf("\n");
  5382. #endif /* NOLOCAL */
  5383. #endif /* NETCONN */
  5384.     return(0);
  5385. }
  5386. #endif /* NONET */
  5387.  
  5388. #ifndef NODIAL
  5389. VOID
  5390. shodial() {
  5391.     if (mdmtyp >= 0 || local != 0) doshodial();
  5392. }
  5393.  
  5394. VOID
  5395. shods(s) char *s; {                     /* Show a dial-related string */
  5396.     char c;
  5397.     if (s == NULL || !(*s)) {           /* Empty? */
  5398.         printf("(none)\n");
  5399.     } else {                            /* Not empty. */
  5400.         while ((c = *s++))              /* Can contain controls */
  5401.           if (c == '\\')                /* a backslash */
  5402.             printf("\\\\");
  5403.           else if (c > 31 && c < 127) {
  5404.               putchar(c);
  5405.           } else
  5406.             printf("\\{%d}",c);
  5407.         printf("\n");
  5408.     }
  5409. }
  5410.  
  5411. int
  5412. doshodial() {
  5413.  
  5414.     int i, n = 2;
  5415.  
  5416.     printf(" Dial status:  %d", dialsta);
  5417.  
  5418. #ifdef BIGBUFOK
  5419.     if (dialsta > 90)
  5420.       printf(" = Unknown error");
  5421.     else if (dialsta < 0)
  5422.       printf(" = (none)");
  5423.     else if (dialsta < 35 && dialmsg[dialsta])
  5424.       printf(" = %s", dialmsg[dialsta]);
  5425. #endif /* BIGBUFOK */
  5426.     n++;
  5427.     if (ndialdir <= 1) {
  5428.         printf("\n Dial directory: %s\n",dialdir[0] ? dialdir[0] : "(none)");
  5429.     } else {
  5430.         int i;
  5431.         printf("\n Dial directories:\n");
  5432.         for (i = 0; i < ndialdir; i++)
  5433.           printf("%2d. %s\n",i+1,dialdir[i]);
  5434.         n += ndialdir;
  5435.     }
  5436.     printf(" Dial method:  ");
  5437.     if      (dialmauto)         printf("auto   ");
  5438.     else if (dialmth == XYDM_D) printf("default");
  5439.     else if (dialmth == XYDM_P) printf("pulse  ");
  5440.     else if (dialmth == XYDM_T) printf("tone   ");
  5441.     printf("         Dial sort: %s\n",dialsrt ? "on" : "off");
  5442.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5443.     printf(" Dial hangup:  %s             Dial display: %s\n",
  5444.            dialhng ? "on " : "off", dialdpy ? "on" : "off");
  5445.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5446.     if (dialrtr > 0) {
  5447.         printf(" Dial retries: %-12d    Dial interval: %d\n",
  5448.                dialrtr, dialint);
  5449.     } else {
  5450.         printf(" Dial retries: (auto)          Dial interval: %d\n", dialint);
  5451.     }
  5452.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5453.     printf(" Dial timeout: ");
  5454. #ifdef CK_TAPI
  5455.     if (tttapi && !tapipass)
  5456.         printf("(tapi)");
  5457.     else
  5458. #endif /* CK_TAPI */
  5459.     if (dialtmo > 0)
  5460.       printf("%4d sec", dialtmo);
  5461.     else
  5462.       printf("0 (auto)");
  5463.     printf("        Redial number: %s\n",dialnum ? dialnum : "(none)");
  5464.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5465.     printf(" Dial confirmation: %s        Dial convert-directory: %s\n",
  5466.            dialcnf ? "on " : "off",
  5467.            dialcvt ? ((dialcvt == 1) ? "on" : "ask") : "off");
  5468.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5469.     printf(" Dial ignore-dialtone: %s", dialidt ? "on " : "off");
  5470.     printf("     Dial pacing: %d\n",dialpace);
  5471.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5472.     printf(
  5473. " Dial prefix:                  %s\n", dialnpr ? dialnpr : "(none)");
  5474.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5475.     printf(
  5476. " Dial suffix:                  %s\n", dialsfx ? dialsfx : "(none)");
  5477.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5478.     printf(
  5479. " Dial country-code:            %-12s", diallcc ? diallcc : "(none)");
  5480.     printf("Dial connect:  %s", dialcon ? ((dialcon == 1) ? "on" : "auto")
  5481.            : "off");
  5482.     if (dialcon != CAR_OFF)
  5483.       printf(" %s", dialcq ? "quiet" : "verbose");
  5484.     printf(
  5485. "\n Dial area-code:               %-12s", diallac ? diallac : "(none)");
  5486.     n++;
  5487.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5488.     printf("Dial restrict: ");
  5489.     if (dialrstr == 5) printf("international\n");
  5490.     else if (dialrstr == 4) printf("long-distance\n");
  5491.     else if (dialrstr == 2) printf("local\n");
  5492.     else if (dialrstr == 6) printf("none\n");
  5493.     else printf("?\n");
  5494.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5495.     printf(" Dial lc-area-codes:           ");
  5496.     if (nlocalac == 0)
  5497.       printf("(none)");
  5498.     else
  5499.       for (i = 0; i < nlocalac; i++)
  5500.         printf("%s ", diallcac[i]);
  5501.     printf(
  5502. "\n Dial lc-prefix:               %s\n", diallcp ? diallcp : "(none)");
  5503.     n++;
  5504.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5505.     printf(
  5506. " Dial lc-suffix:               %s\n", diallcs ? diallcs : "(none)");
  5507.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5508.     printf(
  5509. " Dial ld-prefix:               %s\n", dialldp ? dialldp : "(none)");
  5510.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5511.     printf(
  5512. " Dial ld-suffix:               %s\n", diallds ? diallds : "(none)");
  5513.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5514.     printf(
  5515. " Dial force-long-distance      %s\n", showoff(dialfld));
  5516.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5517.     printf(
  5518. " Dial intl-prefix:             %s\n", dialixp ? dialixp : "(none)");
  5519.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5520.     printf(
  5521. " Dial intl-suffix:             %s\n", dialixs ? dialixs : "(none)");
  5522.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5523.     printf(
  5524. " Dial toll-free-area-code:     ");
  5525.     if (ntollfree == 0)
  5526.       printf("(none)");
  5527.     else
  5528.       for (i = 0; i < ntollfree; i++)
  5529.         printf("%s ", dialtfc[i]);
  5530.     printf("\n");
  5531.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5532.  
  5533.     printf(
  5534. " Dial pulse-countries:         ");
  5535.     if (ndialpucc == 0)
  5536.       printf("(none)");
  5537.     else
  5538.       for (i = 0; i < ndialpucc; i++)
  5539.         printf("%s ", dialpucc[i]);
  5540.     printf("\n");
  5541.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5542.  
  5543.     printf(
  5544. " Dial tone-countries:          ");
  5545.     if (ndialtocc == 0)
  5546.       printf("(none)");
  5547.     else
  5548.       for (i = 0; i < ndialtocc; i++)
  5549.         printf("%s ", dialtocc[i]);
  5550.     printf("\n");
  5551.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5552.  
  5553.     printf(
  5554.     " Dial toll-free-prefix:        %s\n",
  5555.     dialtfp ? dialtfp :
  5556.     (dialldp ? dialldp : "(none)")
  5557.     );
  5558.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5559.     printf(" Dial pbx-exchange:            ");
  5560.     if (ndialpxx == 0)
  5561.       printf("(none)");
  5562.     else
  5563.       for (i = 0; i < ndialpxx; i++)
  5564.         printf("%s ", dialpxx[i]);
  5565.     printf("\n");
  5566.  
  5567.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5568.     printf(
  5569. " Dial pbx-inside-prefix:       %s\n", dialpxi ? dialpxi : "(none)");
  5570.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5571.     printf(
  5572. " Dial pbx-outside-prefix:      %s\n", dialpxo ? dialpxo : "(none)");
  5573.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5574.     printf(
  5575. " Dial macro:                   %s\n", dialmac ? dialmac : "(none)");
  5576.     return(0);
  5577. }
  5578. #endif /* NODIAL */
  5579. #endif /* NOLOCAL */
  5580.  
  5581. /*  Show File Parameters */
  5582.  
  5583. static char *
  5584. pathval(x) int x; {
  5585.     switch (x) {
  5586.       case PATH_OFF:  return("off");
  5587.       case PATH_ABS:  return("absolute");
  5588.       case PATH_REL:  return("relative");
  5589.       case PATH_AUTO: return("auto");
  5590.       default: return("unknown");
  5591.     }
  5592. }
  5593.  
  5594. VOID
  5595. shofil() {
  5596.     char *s; int i = 0, n = 1;
  5597.     extern char * ifdnam[];
  5598. #ifdef UNIX
  5599.     extern int wildxpand;
  5600. #endif /* UNIX */
  5601.     extern char * snd_move, * snd_rename, * rcv_move, * rcv_rename;
  5602. #ifdef PATTERNS
  5603.     extern int patterns;
  5604. #endif /* PATTERNS */
  5605.     extern char * rfspec, * sfspec;
  5606. #ifdef UNIX
  5607.     extern int zobufsize, zofbuffer, zofblock;
  5608. #endif /* UNIX */
  5609. #ifdef CK_CTRLZ
  5610.     extern int eofmethod;
  5611. #endif /* CK_CTRLZ */
  5612.  
  5613.     printf("\n");
  5614.  
  5615. #ifdef VMS
  5616.     printf(" File record-Length:      %5d\n",frecl);
  5617.     n++;
  5618. #endif /* VMS */
  5619.  
  5620. #ifndef NOXFER
  5621.     printf(" Transfer mode:           %s\n",
  5622.            xfermode == XMODE_A ?
  5623.            "automatic" :
  5624.            "manual"
  5625.            );
  5626.     n++;
  5627. #ifdef PATTERNS
  5628.     printf(" File patterns:           %s", showooa(patterns));
  5629.     if (xfermode == XMODE_M && patterns)
  5630.       printf(" (but disabled by TRANSFER-MODE MANUAL)");
  5631.     else if (patterns)
  5632.       printf(" (SHOW PATTERNS for list)");
  5633.     printf("\n");
  5634.     n++;
  5635. #endif /* PATTERNS */
  5636.     if (filepeek)
  5637.       printf(" File scan:               on %d\n", nscanfile);
  5638.     else
  5639.       printf(" File scan:               off\n");
  5640.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5641.     if (xfermode == XMODE_A)
  5642.       printf(" Default file type:       %s\n",shoxm());
  5643.     else
  5644.       printf(" File type:               %s\n",shoxm());
  5645.     n++;
  5646.     if (fncnv == XYFN_L)
  5647.       s = "literal";
  5648.     else if (fncnv == XYFN_C)
  5649.       s = "converted";
  5650.     else
  5651.       s = "(unknown)";
  5652.     printf(" File names:              %s\n",s);
  5653.     n++;
  5654.     printf(" Send pathnames:          %s\n", pathval(fnspath));
  5655.     n++;
  5656.     printf(" Receive pathnames:       %s\n", pathval(fnrpath));
  5657.     n++;
  5658. #ifdef UNIXOROSK
  5659.     printf(" Match dot files:         %s\n", matchdot ? "yes" : "no");
  5660.     n++;
  5661. #ifdef UNIX
  5662.     printf(" Wildcard-expansion:      %s\n", wildxpand ? "shell" : "kermit");
  5663.     n++;
  5664. #endif /* UNIX */
  5665. #endif /* UNIXOROSK */
  5666.     printf(" File collision:          ");
  5667.     for (i = 0; i < ncolx; i++)
  5668.       if (colxtab[i].kwval == fncact) break;
  5669.     printf("%s\n", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5670.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5671.     printf(" File destination:        %s\n",
  5672.            (dest == DEST_D) ? "disk" :
  5673.            ((dest == DEST_S) ? "screen" :
  5674.             ((dest == DEST_N) ? "nowhere" :
  5675.             "printer"))
  5676.            );
  5677.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5678.     s = (keep >= 0 && keep <= 2) ? ifdnam[keep] : "keep";
  5679.     printf(" File incomplete:         %s\n",s);
  5680.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5681.     printf(" File bytesize:           %d\n",(fmask == 0177) ? 7 : 8);
  5682.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5683. #ifndef NOCSETS
  5684.     printf(" File character-set:      %s\n",fcsinfo[fcharset].keyword);
  5685.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5686.     printf(" File default 7-bit:      %s\n",fcsinfo[dcset7].keyword);
  5687.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5688.     printf(" File default 8-bit:      %s\n",fcsinfo[dcset8].keyword);
  5689.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5690. #ifdef UNICODE
  5691.     printf(" File UCS bom:            %s\n",showoff(ucsbom));
  5692.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5693.     printf(" File UCS byte-order:     %s-endian\n",
  5694.            ucsorder ? "little" : "big");
  5695.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5696.     printf(" Computer byteorder:      %s-endian\n",
  5697.            byteorder ? "little" : "big");
  5698.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5699. #endif /* UNICODE */
  5700. #endif /* NOCSETS */
  5701.  
  5702.     printf(" File end-of-line:        ");
  5703.     i = feol;
  5704.     switch (feol) {
  5705.       case XYFA_C: printf("%s\n","cr"); break;
  5706.       case XYFA_L: printf("%s\n","lf"); break;
  5707.       case XYFA_2: printf("%s\n","crlf"); break;
  5708.       default: printf("%d\n",i);
  5709.     }
  5710.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5711. #endif /* NOXFER */
  5712.  
  5713. #ifdef CK_CTRLZ
  5714.     printf(" File eof:                %s\n", eofmethod ? "ctrl-z" : "length");
  5715.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5716. #endif /* CK_CTRLZ */
  5717. #ifndef NOXFER
  5718. #ifdef CK_TMPDIR
  5719.     printf(" File download-directory: %s\n", dldir ? dldir : "(none)");
  5720.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5721. #ifdef COMMENT
  5722.     i = 256;
  5723.     s = line;
  5724.     zzstring("\\v(tmpdir)",&s,&i);
  5725.     printf(" Temporary directory:     %s\n", line);
  5726.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5727. #endif /* COMMENT */
  5728. #endif /* CK_TMPDIR */
  5729. #ifdef VMS
  5730.     {
  5731.         extern int vmssversions, vmsrversions;
  5732.         printf(" Send version-numbers:    %s\n",showoff(vmssversions));
  5733.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5734.         printf(" Receive version-numbers: %s\n",showoff(vmsrversions));
  5735.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5736.     }
  5737. #endif /* VMS */
  5738.     printf(" Send move-to:            %s\n",
  5739.            snd_move ? snd_move : "(none)");
  5740.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5741.     printf(" Send rename-to:          %s\n",
  5742.            snd_rename ? snd_rename : "(none)");
  5743.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5744.     printf(" Receive move-to:         %s\n",
  5745.            rcv_move ? rcv_move : "(none)");
  5746.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5747.     printf(" Receive rename-to:       %s\n",
  5748.            rcv_rename ? rcv_rename : "(none)");
  5749.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5750. #endif /* NOXFER */
  5751. #ifdef KERMRC
  5752.     printf(" Initialization file:     %s\n", noinit ? "(none)" :
  5753. #ifdef CK_SYSINI
  5754.            CK_SYSINI
  5755. #else
  5756.            kermrc
  5757. #endif /* CK_SYSINI */
  5758.            );
  5759. #endif /* KERMRC */
  5760.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5761.  
  5762.     if (k_info_dir) {
  5763.         printf(" Kermit doc files:        %s\n", k_info_dir);
  5764.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5765.     }
  5766.  
  5767. #ifdef CKROOT
  5768.     s = zgetroot();
  5769.     printf(" Root set:                %s\n", s ? s : "(none)");
  5770. #endif /* CKROOT */
  5771.  
  5772. #ifdef UNIX
  5773.     printf(" Disk output buffer:      %d (writes are %s, %s)\n",
  5774.            zobufsize,
  5775.            zofbuffer ? "buffered" : "unbuffered",
  5776.            zofblock ? "blocking" : "nonblocking"
  5777.            );
  5778.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5779. #ifdef DYNAMIC
  5780.     printf(" Stringspace:             %d\n", zsetfil(0,2));
  5781.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5782.     printf(" Listsize:                %d\n", zsetfil(0,4));
  5783.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5784. #endif /* DYNAMIC */
  5785. #endif /* UNIX */
  5786. #ifdef OS2ORUNIX
  5787.     printf(" Longest filename:        %d\n", maxnam);
  5788.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5789.     printf(" Longest pathname:        %d\n", maxpath);
  5790.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5791. #endif /* OS2ORUNIX */
  5792.  
  5793.     printf(" Last file sent:          %s\n", sfspec ? sfspec : "(none)");
  5794.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5795.     printf(" Last file received:      %s\n", rfspec ? rfspec : "(none)");
  5796.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5797.     printf("\n Also see:\n");
  5798.     n++;
  5799.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5800.     printf(" SHOW PROTOCOL, SHOW XFER");
  5801. #ifdef CK_LABELED
  5802.     printf(", SHOW LABELED");
  5803. #endif /* CK_LABELED */
  5804. #ifdef PATTERNS
  5805.     printf(", SHOW PATTERNS");
  5806. #endif /* PATTERNS */
  5807. #ifdef STREAMING
  5808.     printf(", SHOW STREAMING");
  5809. #endif /* STREAMING */
  5810. #ifndef NOCSETS
  5811.     printf(", SHOW CHARACTER-SETS");
  5812. #endif /* NOCSETS */
  5813.     printf("\n\n");
  5814. }
  5815.  
  5816. #ifndef NOXFER
  5817. VOID
  5818. shoparp() {                             /* Protocol */
  5819.     extern int docrc, skipbup;
  5820.     char *s;
  5821.  
  5822. #ifdef CK_TIMERS
  5823.     extern int rttflg;
  5824. #endif /* CK_TIMERS */
  5825.  
  5826.     printf("Protocol: %s\n",ptab[protocol].p_name);
  5827.  
  5828.     if (protocol == PROTO_K) {
  5829.         printf("\nProtocol Parameters:   Send    Receive");
  5830.         if (timef)
  5831.           printf("\n Timeout (used=%2d):%7d*%8d ", timint, rtimo, pkttim);
  5832.         else
  5833.           printf("\n Timeout (used=%2d):%7d%9d ",  timint, rtimo, pkttim);
  5834. #ifdef XFRCAN
  5835.         printf("       Cancellation:    %s",showoff(xfrcan));
  5836.         if (xfrcan)
  5837.           printf(" %d %d", xfrchr, xfrnum);
  5838. #endif /* XFRCAN */
  5839.         printf("\n Padding:      %11d%9d", npad,   mypadn);
  5840.         if (bctr == 4)
  5841.           printf("        Block Check: blank-free-2\n");
  5842.         else
  5843.           printf("        Block Check: %6d\n",bctr);
  5844.         printf(  " Pad Character:%11d%9d", padch,  mypadc);
  5845.         printf("        Delay:       %6d\n",ckdelay);
  5846.         printf(  " Pause:        %11d%9d", pktpaus, pktpaus);
  5847.         printf("        Attributes:      %s\n",showoff(atcapr));
  5848.         printf(  " Packet Start: %11d%9d", mystch, stchr);
  5849.         printf("        Max Retries: %6d%s\n",
  5850.                maxtry,
  5851.                (maxtry == 0) ? " (unlimited)" : ""
  5852.                );
  5853.         printf(  " Packet End:   %11d%9d", seol,   eol);
  5854.         if (ebqflg)
  5855.           printf("        8th-Bit Prefix: '%c'",ebq);
  5856.         else
  5857.           printf("        8th-Bit Prefix: ('%c' but not used)",ebq);
  5858.         printf(  "\n Packet Length:%11d ", spmax);
  5859.         printf("%8d     ",  urpsiz);
  5860.         if (rptflg)
  5861.           printf("   Repeat Prefix:  '%c'",rptq);
  5862.         else
  5863.           printf("   Repeat Prefix:  ('%c' but not used)",rptq);
  5864.         printf(  "\n Maximum Length: %9d%9d", maxsps, maxrps);
  5865.         printf("        Window Size:%7d set, %d used\n",wslotr,wmax);
  5866.         printf(    " Buffer Size:  %11d%9d", bigsbsiz, bigrbsiz);
  5867.         printf("        Locking-Shift:    ");
  5868.         if (lscapu == 2) {
  5869.             printf("forced");
  5870.         } else {
  5871.             printf("%s", (lscapr ? "enabled" : "disabled"));
  5872.             if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  5873.         }
  5874.         printf("\n\n");
  5875.  
  5876.         if (!(s = ptab[protocol].h_b_init)) s = "";
  5877.         printf(" Auto-upload command (binary): ");
  5878.         if (*s) {
  5879.             shostrdef((CHAR *)s);
  5880.             printf("\n");
  5881.         } else {
  5882.             printf("(none)\n");
  5883.         }
  5884.         if (!(s = ptab[protocol].h_t_init)) s = "";
  5885.         printf(" Auto-upload command (text):   ");
  5886.         if (*s) {
  5887.             shostrdef((CHAR *)s);
  5888.             printf("\n");
  5889.         } else {
  5890.             printf("(none)\n");
  5891.         }
  5892.         if (!(s = ptab[protocol].h_x_init)) s = "";
  5893.         printf(" Auto-server command:          ");
  5894.         if (*s) {
  5895.             shostrdef((CHAR *)s);
  5896.             printf("\n");
  5897.         } else {
  5898.             printf("(none)\n");
  5899.         }
  5900.         tmpbuf[0] = NUL;
  5901. #ifdef CK_TIMERS
  5902.         if (rttflg) {
  5903.             extern int mintime, maxtime;
  5904.             sprintf(tmpbuf," Packet timeouts: dynamic %d:%d", /* SAFE */
  5905.                     mintime,
  5906.                     maxtime);
  5907.         } else {
  5908.             sprintf(tmpbuf," Packet timeouts: fixed"); /* SAFE */
  5909.         }
  5910. #endif /* CK_TIMERS */
  5911.         if (tmpbuf[0])
  5912.           printf("%-31s",tmpbuf);
  5913.         printf("Send backup: %s\n",showoff(!skipbup));
  5914.  
  5915.         printf(" Transfer mode:   %s", xfermode == XMODE_A ?
  5916.                "automatic   " :
  5917.                "manual      "
  5918.                );
  5919.         printf(" Transfer slow-start: %s, crc: %s\n",
  5920.                showoff(slostart),
  5921.                showoff(docrc)
  5922.                );
  5923. #ifdef PIPESEND
  5924.         {
  5925.             extern int usepipes;
  5926.             printf(" Transfer pipes:  %s         ",usepipes ? "on " : "off");
  5927.         }
  5928. #endif /* PIPESEND */
  5929. #ifndef NOCSETS
  5930.         printf(" Transfer character-set: ");
  5931.         if (tcharset == TC_TRANSP)
  5932.           printf("transparent\n");
  5933.         else
  5934.           printf("%s\n", tcsinfo[tcharset].keyword );
  5935. #endif /* NOCSETS */
  5936. #ifdef PIPESEND
  5937.         {
  5938.             extern char * sndfilter, * rcvfilter;
  5939.             printf(" Send filter:     %s\n", sndfilter ? sndfilter : "(none)");
  5940.             printf(" Receive filter:  %s\n", rcvfilter ? rcvfilter : "(none)");
  5941.         }
  5942. #endif /* PIPESEND */
  5943.         printf("\nAlso see:\n");
  5944.         printf(" SHOW FILE, SHOW XFER");
  5945.  
  5946. #ifdef CK_LABELED
  5947.         printf(", SHOW LABELED");
  5948. #endif /* CK_LABELED */
  5949. #ifdef PATTERNS
  5950.         printf(", SHOW PATTERNS");
  5951. #endif /* PATTERNS */
  5952. #ifdef STREAMING
  5953.         printf(", SHOW STREAMING");
  5954. #endif /* STREAMING */
  5955. #ifndef NOCSETS
  5956.         printf(", SHOW CHARACTER-SETS");
  5957. #endif /* NOCSETS */
  5958.     }
  5959.  
  5960. #ifdef CK_XYZ
  5961. #ifdef XYZ_INTERNAL
  5962.     if (protocol != PROTO_K) {
  5963.         int i;
  5964.         int x;
  5965.         printf(" File type: %s\n", binary ? "binary" : "text");
  5966.         if (protocol == PROTO_Z) {              /* Zmodem */
  5967.             printf(" Window size:   ");
  5968.             if (ptab[protocol].winsize < 1)
  5969.               printf("none\n");
  5970.             else
  5971.               printf("%d\n",wslotr);
  5972. #ifdef COMMENT
  5973.             printf(" Packet (frame) length: ");
  5974.             if (ptab[protocol].spktlen < 0)
  5975.               printf("none\n");
  5976.             else
  5977.               printf("%d\n",spmax);
  5978. #endif /* COMMENT */
  5979.         } else {
  5980.             if (ptab[protocol].spktlen >= 1000)
  5981.               printf(" 1K packets\n");
  5982.             else
  5983.               printf(" 128-byte packets\n");
  5984.         }
  5985.         printf(" Pathname stripping when sending:   %s\n",
  5986.                showoff(ptab[protocol].fnsp)
  5987.                );
  5988.         printf(" Pathname stripping when receiving: %s\n",
  5989.                showoff(ptab[protocol].fnrp)
  5990.                );
  5991.         printf(" Filename collision action:         ");
  5992.         for (i = 0; i < ncolx; i++)
  5993.           if (colxtab[i].kwval == fncact) break;
  5994.         printf("%-12s", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5995.  
  5996.         printf("\n Escape control characters:          ");
  5997.         x = ptab[protocol].prefix;
  5998.         if (x == PX_ALL)
  5999.           printf("all\n");
  6000.         else if (x == PX_CAU || x==PX_WIL)
  6001.           printf("minimal\n");
  6002.         else
  6003.           printf("none\n");
  6004.         if (!(s = ptab[protocol].h_b_init))
  6005.           s = "";
  6006.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  6007.         if (!(s = ptab[protocol].h_t_init))
  6008.           s = "";
  6009.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  6010.     }
  6011. #else
  6012.     if (protocol != PROTO_K) {
  6013.         printf("\nExecuted by external commands:\n\n");
  6014.         s = ptab[protocol].p_b_scmd;
  6015.         if (!s) s = "";
  6016.         printf(" SEND command (binary):        %s\n", *s ? s : "(none)");
  6017.         s = ptab[protocol].p_t_scmd;
  6018.         if (!s) s = "";
  6019.         printf(" SEND command (text):          %s\n", *s ? s : "(none)");
  6020.         s = ptab[protocol].p_b_rcmd;
  6021.         if (!s) s = "";
  6022.         printf(" RECEIVE command (binary):     %s\n", *s ? s : "(none)");
  6023.         s = ptab[protocol].p_t_rcmd;
  6024.         if (!s) s = "";
  6025.         printf(" RECEIVE command (text):       %s\n", *s ? s : "(none)");
  6026.         s = ptab[protocol].h_b_init;
  6027.         if (!s) s = "";
  6028.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  6029.         s = ptab[protocol].h_t_init;
  6030.         if (!s) s = "";
  6031.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  6032.     }
  6033. #endif /* XYZ_INTERNAL */
  6034. #endif /* CK_XYZ */
  6035. }
  6036. #endif /* NOXFER */
  6037.  
  6038. #ifndef NOCSETS
  6039. /* Character-set items */
  6040.  
  6041. extern int s_cset, r_cset, axcset[], afcset[];
  6042. extern struct keytab xfrmtab[];
  6043.  
  6044. VOID
  6045. shoparl() {
  6046. #ifdef COMMENT
  6047.     int i;
  6048. /* Misleading... */
  6049.     printf("\nAvailable Languages:\n");
  6050.     for (i = 0; i < MAXLANG; i++) {
  6051.         printf(" %s\n",langs[i].description);
  6052.     }
  6053. #else
  6054.     printf("\nLanguage-specific translation rules: %s\n",
  6055.            language == L_USASCII ? "none" : langs[language].description);
  6056.     shocharset();
  6057.     printf("\n\n");
  6058. #endif /* COMMENT */
  6059. }
  6060.  
  6061. VOID
  6062. shocharset() {
  6063.     int x;
  6064. #ifdef COMMENT
  6065.     char * s = "Unknown";
  6066.     extern int xlatype;
  6067. #endif /* COMMENT */
  6068.  
  6069. #ifndef NOXFER
  6070.     extern int xfrxla;
  6071. #endif /* NOXFER */
  6072.  
  6073.     debug(F101,"SHOW FILE CHAR","",fcharset);
  6074.     printf("\n");
  6075. #ifndef NOXFER
  6076.     printf(" Transfer Translation: %s\n", showoff(xfrxla));
  6077.     if (!xfrxla) {
  6078.         printf(
  6079.       " Because transfer translation is off, the following are ignored:\n\n");
  6080.     }
  6081. #endif /* NOXFER */
  6082.     printf(" File Character-Set: %s (%s), ",
  6083.            fcsinfo[fcharset].keyword,
  6084.            fcsinfo[fcharset].name
  6085.            );
  6086.     if ((x = fcsinfo[fcharset].size) == 128)
  6087.       printf("7-bit");
  6088.     else if (x == 256)
  6089.       printf("8-bit");
  6090.     else
  6091.       printf("multibyte");
  6092.     printf("\n");
  6093.     printf(" File Scan: %s\n",showoff(filepeek));
  6094.     printf("   Default 7bit-Character-Set: %s\n",fcsinfo[dcset7].keyword);
  6095.     printf("   Default 8bit-Character-Set: %s\n",fcsinfo[dcset8].keyword);
  6096.     printf(" Transfer Character-Set");
  6097. #ifdef COMMENT
  6098.     if (tslevel == TS_L2)
  6099.       printf(": (international)");
  6100.     else
  6101. #endif /* COMMENT */
  6102.     if (tcharset == TC_TRANSP)
  6103.       printf(": Transparent");
  6104.     else
  6105.       printf(": %s (%s)",tcsinfo[tcharset].keyword, tcsinfo[tcharset].name);
  6106.     printf("\n");
  6107. #ifdef COMMENT
  6108.     switch (xlatype) {
  6109.       case XLA_NONE: s = "None"; break;
  6110.       case XLA_BYTE: s = "Byte"; break;
  6111.       case XLA_JAPAN: s = "Japanese"; break;
  6112.       case XLA_UNICODE: s = "Unicode"; break;
  6113.     }
  6114.     printf("\n Translation type: %s\n",s);
  6115. #endif /* COMMENT */
  6116.     printf(" SEND character-set-selection: %s\n",xfrmtab[s_cset].kwd);
  6117.     printf(" RECEIVE character-set-selection: %s\n",xfrmtab[r_cset].kwd);
  6118.     if (s_cset == XMODE_A || r_cset == XMODE_A)
  6119.       printf(
  6120.       " (Use SHOW ASSOCIATIONS to list automatic character-set selections.)\n"
  6121.              );
  6122. }
  6123.  
  6124. VOID
  6125. showassoc() {
  6126.     int i, k, n = 4;
  6127.     char * s;
  6128.     printf("\nFor incoming files:\n\n");
  6129.     printf("Transfer Character-Set   File Character-Set\n");
  6130.     for (i = 1; i <= MAXTCSETS; i++) {
  6131.         k = axcset[i];
  6132.         if (k < 0 || k > MAXFCSETS)
  6133.           s = "(none)";
  6134.         else
  6135.           s = fcsinfo[k].keyword;
  6136.         if (!s) s = "";
  6137.         if (!*s) s = "(none)";
  6138.         printf(" %-25s%s\n",tcsinfo[i].keyword,s);
  6139.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6140.     }
  6141.     printf("\nFor outbound files:\n\n");
  6142.     n += 2;
  6143.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6144.     printf("File Character-Set       Transfer Character-Set\n");
  6145.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6146.     for (i = 0; i <= MAXFCSETS; i++) {
  6147.         k = afcset[i];
  6148.         if (k < 0 || k > MAXTCSETS)
  6149.           s = "(none)";
  6150.         else
  6151.           s = tcsinfo[k].keyword;
  6152.         if (!s) s = "";
  6153.         if (!*s) s = "(none)";
  6154.         printf(" %-25s%s\n",fcsinfo[i].keyword,s);
  6155.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6156.     }
  6157. }
  6158. #endif /* NOCSETS */
  6159.  
  6160. VOID
  6161. shopar() {
  6162.     printf("Show what?  (Type \"show ?\" for a list of possibilities.)\n");
  6163. }
  6164. #endif /* NOSHOW */
  6165.  
  6166. #ifndef NOXFER
  6167. /*  D O S T A T  --  Display file transfer statistics.  */
  6168.  
  6169. int
  6170. dostat(brief) int brief; {
  6171.     extern long filrej, peakcps;
  6172.     extern int lastspmax, streamed, cleared, streamok;
  6173.     extern char whoareu[];
  6174.     int n = 0, ftp = 0;
  6175.     extern int docrc, interrupted, fatalio;
  6176.  
  6177.     ftp = lastxfer & W_FTP;
  6178.  
  6179. #ifdef CK_TTGWSIZ
  6180. #ifdef OS2
  6181.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  6182.       ttgwsiz();
  6183. #else /* OS2 */
  6184.     if (ttgwsiz() > 0) {
  6185.         if (tt_rows > 0 && tt_cols > 0) {
  6186.             cmd_rows = tt_rows;
  6187.             cmd_cols = tt_cols;
  6188.         }
  6189.     }
  6190. #endif /* OS2 */
  6191. #endif /* CK_TTGWSIZ */
  6192.  
  6193.     debug(F101,"dostat xferstat","",xferstat);
  6194.     if (xferstat < 0) {
  6195.         printf(" No file transfers yet.\n");
  6196.         return(1);
  6197.     }
  6198.     n = 0;
  6199.     if (brief) { printf("\n"); n++; };
  6200.     printf(" protocol               : %s\n",
  6201.            ftp ? "ftp" : ptab[protocol].p_name);
  6202.     n++;
  6203.     printf(" status                 : ");
  6204.     if (xferstat) printf("SUCCESS\n");
  6205.     else if (interrupted) printf("FAILURE (interrupted)\n");
  6206.     else if (fatalio) printf("FAILURE (i/o error)\n");
  6207.     else printf("FAILURE\n");
  6208. #ifndef XYZ_INTERNAL
  6209.     if (!ftp && protocol != PROTO_K) {
  6210.         printf("\n external protocol statistics not available\n");
  6211.         return(1);
  6212.     }
  6213. #endif /* XYZ_INTERNAL */
  6214.     n++;
  6215.     if (!ftp) {
  6216.         if (!xferstat > 0) {
  6217.             if (docrc)
  6218.               printf(" crc-16 of file(s)      : %ld\n", crc16);
  6219.             else
  6220.               printf(" crc-16 of file(s)      : (disabled)\n");
  6221.             n++;
  6222.         }
  6223.         if (!xferstat && *epktmsg) {
  6224.             printf(" reason                 : %s\n", epktmsg);
  6225.             n++;
  6226.         }
  6227.     }
  6228.     if (!brief) {
  6229. #ifdef NEWFTP
  6230.         if (ftp) {
  6231.             extern char ftp_srvtyp[];
  6232.             printf(" remote system type     : %s\n",ftp_srvtyp);
  6233.         } else
  6234. #endif /* NEWFTP */
  6235.           if (whoareu[0]) {
  6236.             printf(" remote system type     : %s\n",
  6237.                    getsysid((char *)whoareu));
  6238.             n++;
  6239.         }
  6240.         printf(" files transferred      : %ld\n",filcnt - filrej);
  6241.         if (!ftp)
  6242.           printf(" files not transferred  : %ld\n",filrej);
  6243.         printf(" characters last file   : %ld\n",ffc);
  6244.         printf(" total file characters  : %ld\n",tfc);
  6245.         n += ftp ? 3 : 4;
  6246.         if (!ftp) {
  6247.             printf(" communication line in  : %ld\n",tlci);
  6248.             printf(" communication line out : %ld\n",tlco);
  6249.             printf(" packets sent           : %d\n", spackets);
  6250.             printf(" packets received       : %d\n", rpackets);
  6251.             n += 4;
  6252.         }
  6253.     }
  6254.     if (ftp) goto dotimes;
  6255.  
  6256.     printf(" damaged packets rec'd  : %d\n", crunched);
  6257.     printf(" timeouts               : %d\n", timeouts);
  6258.     printf(" retransmissions        : %d\n", retrans);
  6259.     n += 3;
  6260.  
  6261.     if (!brief) {
  6262.         if (filcnt > 0) {
  6263.             printf(" parity                 : %s",parnam((char)parity));
  6264.             n++;
  6265.             if (autopar) { printf(" (detected automatically)"); n++; }
  6266.             printf(
  6267.                  "\n control characters     : %ld prefixed, %ld unprefixed\n",
  6268.                    ccp, ccu);
  6269.             n++;
  6270.             printf(" 8th bit prefixing      : ");
  6271.             n++;
  6272.             if (ebqflg) printf("yes [%c]\n",ebq); else printf("no\n");
  6273.             n++;
  6274.             printf(" locking shifts         : %s\n", lscapu ? "yes" : "no");
  6275.             n++;
  6276.         }
  6277.     }
  6278.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6279.     if (streamed > 0)
  6280.       printf(" window slots used      : (streaming)\n");
  6281.     else
  6282.       printf(" window slots used      : %d of %d\n", wmax, wslotr);
  6283.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6284.     printf(" reliable:              : %s%s\n",
  6285.            streamok ? "" : "not ", "negotiated");
  6286.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6287.     printf(" clearchannel:          : %s%s\n",
  6288.            cleared  ? "" : "not ", "negotiated");
  6289.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6290.  
  6291.     if (!brief) {
  6292.         printf(" packet length          : %d (send), %d (receive)\n",
  6293.                lastspmax, urpsiz);
  6294.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6295.         printf(" compression            : ");
  6296.         if (rptflg)
  6297.           printf("yes [%c] (%ld)\n",(char) rptq,rptn);
  6298.         else
  6299.           printf("no\n");
  6300.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6301.         if (bctu == 4)
  6302.           printf(" block check type used  : blank-free-2\n");
  6303.         else
  6304.           printf(" block check type used  : %d\n",bctu);
  6305.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6306.     }
  6307.  
  6308.   dotimes:
  6309.  
  6310. #ifdef GFTIMER
  6311. #ifdef COMMENT
  6312.     printf(" elapsed time           : %0.3f sec, %s\n", fptsecs,hhmmss(tsecs));
  6313. #endif /* COMMENT */
  6314.     printf(" elapsed time           : %s (%0.3f sec)\n",
  6315.            hhmmss((long)(fptsecs + 0.5)),fptsecs);
  6316. #else
  6317. #ifdef COMMENT
  6318.     printf(" elapsed time           : %s (%d sec)\n",hhmmss(tsecs),tsecs);
  6319. #endif /* COMMENT */
  6320.     printf(" elapsed time           : %d sec, %s\n",tsecs,hhmmss(tsecs));
  6321. #endif /* GFTIMER */
  6322.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6323.     if (!ftp && local && !network && !brief) {
  6324.         if (speed <= 0L) speed = ttgspd();
  6325.         if (speed > 0L) {
  6326.             if (speed == 8880)
  6327.               printf(" transmission rate      : 75/1200 bps\n");
  6328.             else
  6329.               printf(" transmission rate      : %ld bps\n",speed);
  6330.             if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6331.         }
  6332.     }
  6333.     if (!ftp && local && !network &&    /* Only makes sense for */
  6334.         mdmtyp == 0 &&                  /* direct serial connections */
  6335.         speed > 99L &&                  /* when we really know the speed */
  6336.         speed != 8880L
  6337.         ) {
  6338.         int eff;
  6339.         eff = (((tfcps * 100L) / (speed / 100L)) + 5L) / 10L;
  6340.         printf(" effective data rate    : %ld cps (%d%%)\n",tfcps,eff);
  6341.     } else
  6342.       printf(" effective data rate    : %ld cps\n", tfcps);
  6343.     if (!ftp && peakcps > 0L && peakcps > tfcps)
  6344.       printf(" peak data rate         : %ld cps\n", peakcps);
  6345.     if (brief)
  6346.       printf("\nUse STATISTICS /VERBOSE for greater detail.\n\n");
  6347.     return(1);
  6348. }
  6349. #endif /* NOXFER */
  6350.  
  6351. #ifndef NOSPL
  6352.  
  6353. /* The INPUT command */
  6354.  
  6355. /*
  6356.   NOTE: An INPUT timeout of 0 means to perform a nonblocking read of the
  6357.   material that has already arrived and is waiting to be read, and perform
  6358.   matches against it, without doing any further reads.  It should succeed
  6359.   or fail instantaneously.
  6360. */
  6361.  
  6362. /* Output buffering for "doinput" */
  6363.  
  6364. #ifdef pdp11
  6365. #define MAXBURST 16             /* Maximum size of input burst */
  6366. #else
  6367. #define MAXBURST 1024
  6368. #endif /* pdp11 */
  6369. #ifdef OSK
  6370. static CHAR *conbuf;            /* Buffer to hold output for console */
  6371. #else
  6372. static CHAR conbuf[MAXBURST];   /* Buffer to hold output for console */
  6373. #endif /* OSK */
  6374. static int concnt = 0;          /* Number of characters buffered */
  6375. #ifdef OSK
  6376. static CHAR *sesbuf;            /* Buffer to hold output for session log */
  6377. #else
  6378. static CHAR sesbuf[MAXBURST];   /* Buffer to hold output for session log */
  6379. #endif /* OSK */
  6380. static int sescnt = 0;          /* Number of characters buffered */
  6381.  
  6382. extern int debses;                      /* TERMINAL DEBUG ON/OFF */
  6383.  
  6384. static VOID                             /* Flush INPUT echoing */
  6385. myflsh() {                              /* and session log output. */
  6386.     if (concnt > 0) {
  6387.         if (debses) {                   /* Terminal debugging? */
  6388.             int i;
  6389.             for (i = 0; i < concnt; i++)
  6390.               conol(dbchr(conbuf[i]));
  6391.         } else
  6392.           conxo(concnt, (char *) conbuf);
  6393.         concnt = 0;
  6394.     }
  6395.     if (sescnt > 0) {
  6396.         logstr((char *) sesbuf, sescnt);
  6397.         sescnt = 0;
  6398.     }
  6399. }
  6400.  
  6401. /* Execute the INPUT and MINPUT commands */
  6402.  
  6403. int instatus = -1;
  6404. long inetime = -1L;
  6405. int inwait = 0;
  6406.  
  6407. /* For returning the input sequence that matched */
  6408.  
  6409. #ifdef BIGBUFOK
  6410. #define MATCHBUFSIZ 8191
  6411. #else
  6412. #define MATCHBUFSIZ 1023
  6413. #endif /* BIGBUFOK */
  6414. static char * matchbuf = NULL;
  6415. static int matchindex = 0;
  6416. /*
  6417.   timo = How long to wait:
  6418.          < 0 = Wait forever
  6419.            0 = Don't wait
  6420.          > 0 = Wait this many seconds
  6421.   ms   = Array of strings to wait for.
  6422.   mp   = Array of flags.
  6423.          If mp[i] == 0, ms[i] is literal, else it's a pattern.
  6424.   flags = for now, 1 or 0.  If 1, then don't match anything.
  6425. */
  6426. int
  6427. doinput(timo,ms,mp,flags) int timo; char *ms[]; int mp[]; int flags; {
  6428.     extern int inintr;
  6429. #ifdef CK_AUTODL
  6430.     extern int inautodl;
  6431. #endif /* CK_AUTODL */
  6432.     int x, y, i, t, rt, icn, anychar, mi[MINPMAX];
  6433. #ifdef GFTIMER
  6434.     CKFLOAT fpt = 0.0;
  6435. #endif /* GFTIMER */
  6436.     int nomatch = 0;
  6437.     int lastchar = 0;
  6438.     int waiting = 0;
  6439.     int imask = 0;
  6440.     char ch, *xp, *s;
  6441.     CHAR c;
  6442. #ifndef NOLOCAL
  6443. #ifdef OS2
  6444.     extern int term_io;
  6445.     int term_io_save;
  6446. #endif /* OS2 */
  6447. #endif /* NOLOCAL */
  6448. #ifdef TNCODE
  6449.     static int cr = 0;
  6450. #endif /* TNCODE */
  6451.     int is_tn = 0;
  6452.     int wrapped = 0;
  6453. #ifdef SSHBUILTIN
  6454.     extern int ssh_cas;
  6455.     extern char * ssh_cmd;
  6456. #endif /* SSHBUILTIN */
  6457.  
  6458. #define CK_BURST
  6459. /*
  6460.   This enables the INPUT speedup code, which depends on ttchk() returning
  6461.   accurate information.  If INPUT fails with this code enabled, change the
  6462.   above "#define" to "#undef".
  6463. */
  6464. #ifdef CK_BURST
  6465.     int burst = 0;                      /* Chars remaining in input burst */
  6466. #endif /* CK_BURST */
  6467.  
  6468.     imask = cmask;
  6469.     if (parity) imask = 0x7f;
  6470.     inwait = timo;                      /* For \v(inwait) */
  6471.     nomatch = flags & 1;
  6472.     makestr(&inpmatch,NULL);
  6473.  
  6474.     if (!matchbuf) {
  6475.         matchbuf = malloc(MATCHBUFSIZ+1);
  6476.         matchbuf[0] = NUL;
  6477.     }
  6478.     matchindex = 0;
  6479.  
  6480.     is_tn =
  6481. #ifdef TNCODE
  6482.         (local && network && IS_TELNET()) || (!local && sstelnet)
  6483. #else
  6484.          0
  6485. #endif /* TNCODE */
  6486.           ;
  6487.  
  6488.     instatus = INP_IE;                  /* 3 = internal error */
  6489.     kbchar = 0;
  6490.  
  6491. #ifdef OSK
  6492.     if (conbuf == NULL) {
  6493.         if ((conbuf = (CHAR *)malloc(MAXBURST*2)) == NULL) {
  6494.             return(0);
  6495.         }
  6496.         sesbuf = conbuf + MAXBURST;
  6497.     }
  6498. #endif /* OSK */
  6499.  
  6500. #ifndef NOLOCAL
  6501.     if (local) {                        /* In local mode... */
  6502.         if ((waiting = ttchk()) < 0) {  /* check that connection is open */
  6503.         if (!quiet) {
  6504.         if ((!network 
  6505. #ifdef TN_COMPORT
  6506.               || istncomport()
  6507. #endif /* TN_COMPORT */
  6508.               ) && carrier != CAR_OFF)
  6509.             printf("?Carrier detect failure on %s.\n", ttname);
  6510.         else
  6511.             printf("?Connection %s %s is not open.\n",
  6512.                network ? "to" : "on",
  6513.                ttname
  6514.                );
  6515.         }
  6516.             instatus = INP_IO;
  6517.             return(0);
  6518.         }
  6519.         debug(F101,"doinput waiting","",waiting);
  6520.         y = ttvt(speed,flow);           /* Put line in "ttvt" mode */
  6521.         if (y < 0) {
  6522.             printf("?INPUT initialization error\n");
  6523.             instatus = INP_IO;
  6524.             return(0);                  /* Watch out for failure. */
  6525.         }
  6526.     }
  6527. #endif /* NOLOCAL */
  6528.  
  6529. #ifdef SSHBUILTIN
  6530.     if ( network && nettype == NET_SSH && ssh_cas && ssh_cmd && 
  6531.          !(strcmp(ssh_cmd,"kermit") && strcmp(ssh_cmd,"sftp"))) {
  6532.         if (!quiet)
  6533.       printf("?SSH Subsystem active: %s\n", ssh_cmd);
  6534.         instatus = INP_IKS;
  6535.         return(0);
  6536.     }
  6537. #endif /* SSHBUILTIN */
  6538.  
  6539.     debug(F111,"doinput ms[0]",ms[0],waiting);
  6540.  
  6541.     if (!ms[0]) {                       /* If we were passed a NULL pointer */
  6542.         anychar = 1;                    /*  ... */
  6543.     } else {
  6544.         y = (int)strlen(ms[0]);         /* Or if search string is empty */
  6545.         anychar = (y < 1);              /* any input character will do. */
  6546.     }
  6547.     if (flags & 1) anychar = 0;        /* Don't match anything */
  6548.  
  6549.     if (!anychar && waiting == 0 && timo == 0)
  6550.       return(0);
  6551.  
  6552.  
  6553. #ifndef NODEBUG
  6554.     if (deblog) {
  6555.         char xbuf[24];
  6556.         debug(F101,"doinput anychar","",anychar);
  6557.         debug(F101,"doinput timo","",timo);
  6558.         debug(F101,"doinput echo","",inecho);
  6559.         debug(F101,"doinput burst","",burst);
  6560.         y = -1;
  6561.         while (ms[++y]) {
  6562.             sprintf(xbuf,"doinput string %2d",y); /* SAFE (24) */
  6563.             debug(F111,xbuf,ms[y],mp[y]);
  6564.         }
  6565.     }
  6566. #endif /* NODEBUG */
  6567.  
  6568. #ifdef IKS_OPTION
  6569.     if (is_tn) {
  6570.         /* If the remote side is in a state of IKS START-SERVER    */
  6571.         /* we request that the state be changed.  We will detect   */
  6572.         /* a failure to adhere to the request when we call ttinc() */
  6573.         if (TELOPT_U(TELOPT_KERMIT) &&
  6574.             TELOPT_SB(TELOPT_KERMIT).kermit.u_start)
  6575.           iks_wait(KERMIT_REQ_STOP,0);  /* Send Request-Stop */
  6576. #ifdef CK_AUTODL
  6577.         /* If we are processing packets during INPUT and we have not */
  6578.         /* sent a START message, do so now.                          */
  6579.         if (inautodl && TELOPT_ME(TELOPT_KERMIT) &&
  6580.             !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  6581.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  6582.         }
  6583. #endif /* CK_AUTODL */
  6584.     }
  6585. #endif /* IKS_OPTION */
  6586.     x = 0;                              /* Return code, assume failure */
  6587.     instatus = INP_TO;                  /* Status, assume timeout */
  6588.  
  6589.     for (y = 0; y < MINPMAX; y++)
  6590.       mi[y] = 0;                        /* String pattern match position */
  6591.  
  6592.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  6593.         y = -1;
  6594.  
  6595.         while ((xp = ms[++y])) {
  6596.             while (*xp) {               /* Convert to lowercase */
  6597.                 if (isupper(*xp)) *xp = (char) tolower(*xp);
  6598.                 xp++;
  6599.             }
  6600.         }
  6601.     }
  6602.     rtimer();                           /* Reset timer. */
  6603. #ifdef GFTIMER
  6604.     rftimer();                          /* Floating-point timer too. */
  6605. #endif /* GFTIMER */
  6606.     inetime = -1L;                      /* Initialize elapsed time. */
  6607.     t = 0;                              /* Time now is 0. */
  6608.     m_found = 0;                        /* Default to timed-out */
  6609.     incount = 0;                        /* Character counter */
  6610.     rt = (timo == 0) ? 0 : 1;           /* Character-read timeout interval */
  6611.  
  6612. #ifndef NOLOCAL
  6613. #ifdef OS2
  6614.     term_io_save = term_io;             /* Disable I/O by emulator */
  6615.     term_io = 0;
  6616. #endif /* OS2 */
  6617. #endif /* NOLOCAL */
  6618.  
  6619.     while (1) {                         /* Character-getting loop */
  6620. #ifdef CK_APC
  6621.         /* Check to see if there is an Autodown or other APC command */
  6622.         if (apcactive == APC_LOCAL ||
  6623.             (apcactive == APC_REMOTE && apcstatus != APC_OFF)) {
  6624.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  6625.                 debug(F110,"doinput about to execute APC",apcbuf,0);
  6626.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  6627.                 delmac("_apc_commands",1);
  6628.                 apcactive = APC_INACTIVE;
  6629. #ifdef DEBUG
  6630.             } else {
  6631.                 debug(F100,"doinput APC in progress","",0);
  6632. #endif /* DEBUG */
  6633.             }
  6634.         }
  6635. #endif /* CK_APC */
  6636.  
  6637.         if (timo == 0 && waiting < 1) { /* Special exit criterion */
  6638.             instatus = INP_TO;          /* for timeout == 0 */
  6639.             break;
  6640.         }
  6641.         if (local) {                    /* One case for local */
  6642.             y = ttinc(rt);              /* Get character from comm device */
  6643.             debug(F101,"doinput ttinc(rt) returns","",y);
  6644.             if (y < -1) {               /* Connection failed. */
  6645.                 instatus = INP_IO;      /* Status = i/o error */
  6646. #ifndef NOLOCAL
  6647. #ifdef OS2
  6648.                 term_io = term_io_save;
  6649. #endif /* OS2 */
  6650. #endif /* NOLOCAL */
  6651.                 switch (y) {
  6652.                   case -2:              /* Connection lost */
  6653.                     if (local && !network && carrier != CAR_OFF) {
  6654.                         dologend();
  6655.                         printf("Connection closed.\n");
  6656.                         ttclos(1);
  6657.                     }
  6658.                     break;
  6659.                   case -3:
  6660.                     dologend();
  6661.                     printf("Session Limit exceeded - closing connection.\n");
  6662.                     ttclos(1);
  6663.                   default:
  6664.                     break;
  6665.                 }
  6666.                 debug(F111,"doinput Connection failed","returning 0",y);
  6667.                 return(0);
  6668.             }
  6669.             if (inintr) {
  6670.                 debug(F111,"doinput","inintr",inintr);
  6671.                 if ((icn = conchk()) > 0) { /* Interrupted from keyboard? */
  6672.                     debug(F101,"input interrupted from keyboard","",icn);
  6673.                     kbchar = coninc(0);
  6674.                     if (kbchar >= 0) {
  6675.                         while (--icn > 0) {
  6676.                             debug(F110,"doinput","absorbing",0);
  6677.                             coninc(0);      /* Yes, absorb what was typed. */
  6678.                         }
  6679.                         instatus = INP_UI;  /* Fail and remember why. */
  6680.                         break;
  6681.                     }
  6682.                 }
  6683.             }
  6684.         } else {                        /* Another for remote */
  6685.             y = coninc(rt);
  6686.             debug(F101,"doinput coninc(rt) returns","",y);
  6687.         }
  6688.         if (y > -1) {                   /* A character arrived */
  6689.             debug(F111,"doinput","a character arrived",y);
  6690.             if (timo == 0)
  6691.               waiting--;
  6692. #ifndef OS2
  6693. #define TN_NOLO
  6694. #endif /* OS2 */
  6695. #ifdef NOLOCAL
  6696. #define TN_NOLO
  6697. #endif /* NOLOCAL */
  6698.  
  6699. #ifdef TN_NOLO
  6700.             debug(F100,"doinput TN_NOLO","",0);
  6701. #ifdef TNCODE
  6702.             /* Check for telnet protocol negotiation */
  6703.             if (is_tn) {
  6704.                 switch (y & 0xff) {
  6705.                   case IAC:
  6706.                     cr = 0;
  6707.                     myflsh();   /* Break from input burst for tn_doop() */
  6708. #ifdef CK_BURST
  6709.                     burst = 0;
  6710. #endif /* CK_BURST */
  6711.                     waiting -= 2;       /* (not necessarily...) */
  6712.                     switch (tn_doop((CHAR)(y & 0xff),duplex,ttinc)) {
  6713.                       case 2: duplex = 0; continue;
  6714.                       case 1: duplex = 1; continue;
  6715. #ifdef IKS_OPTION
  6716.                       case 4:
  6717.                         if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6718.                              !tcp_incoming) {
  6719.                             instatus = INP_IKS;
  6720.                             printf(
  6721.  " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6722.                                    );
  6723.                             break;
  6724.                         }
  6725.                         continue;
  6726. #endif /* IKS_OPTION */
  6727.                       case 6:           /* TELNET DO LOGOUT received */
  6728.                       default: continue;
  6729.                     }
  6730.                   case CR:
  6731.                     cr = 1;
  6732.                     break;
  6733.                   case NUL:
  6734.                     if (!TELOPT_U(TELOPT_BINARY) && cr) {
  6735.                         cr = 0;
  6736.                         continue;
  6737.                     }
  6738.                     cr = 0;
  6739.                     break;
  6740.                   default:
  6741.                     cr = 0;
  6742.                 }
  6743.                 /* I'm echoing remote chars */
  6744.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6745.                   ttoc((char)y);
  6746.             }
  6747. #endif /* TNCODE */
  6748. #ifdef CK_AUTODL
  6749.             /* Check for file transfer packets */
  6750.             if (inautodl) autodown(y);
  6751. #endif /* CK_AUTODL */
  6752. #else  /* TN_NOLO */
  6753.             debug(F100,"doinput !TN_NOLO","",0);
  6754. #ifdef TNCODE
  6755.             /* Check for telnet protocol negotiation */
  6756.             if (is_tn) {
  6757.                 int tx;
  6758.                 switch (y & 0xff) {
  6759.                   case IAC:
  6760.                     myflsh();   /* Break from input burst for tn_doop() */
  6761. #ifdef CK_BURST
  6762.                     burst = 0;
  6763. #endif /* CK_BURST */
  6764. #ifdef IKS_OPTION
  6765.                     tx = scriptwrtbuf((USHORT)y);
  6766.                     if (tx == 4) {
  6767.                         if (TELOPT_U(TELOPT_KERMIT) && 
  6768.                 TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6769.                             !tcp_incoming
  6770.                             ) {
  6771.                             instatus = INP_IKS;
  6772.                             printf(
  6773.   " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6774.                                    );
  6775.                             break;
  6776.                         }
  6777.                     } else if (tx == 6) {
  6778.                         /* TELNET DO LOGOUT received */
  6779.  
  6780.                     }
  6781. #else /* IKS_OPTION */
  6782.                     /* Handles Telnet negotiations */
  6783.                     tx = scriptwrtbuf((USHORT)y);
  6784.                     if (tx == 6) {
  6785.                         /* TELNET DO LOGOUT received */
  6786.                     }
  6787. #endif /* IKS_OPTION */
  6788.                     waiting -= 2;       /* (not necessarily...) */
  6789.                     cr = 0;
  6790.                     continue;           /* and autodownload check */
  6791.                   case CR:
  6792.                     cr = 1;
  6793.                     tx = scriptwrtbuf((USHORT)y);
  6794.                     if (tx == 6) {
  6795.                         /* TELNET DO LOGOUT received */
  6796.                     }
  6797.                     break;
  6798.                   case NUL:
  6799.                     cr = 0;
  6800.                     if (!TELOPT_U(TELOPT_BINARY) && cr)
  6801.                       continue;
  6802.                     tx = scriptwrtbuf((USHORT)y);
  6803.                     if (tx == 6) {
  6804.                         /* TELNET DO LOGOUT received */
  6805.                     }
  6806.                     break;
  6807.                   default:
  6808.                     cr = 0;
  6809.                     tx = scriptwrtbuf((USHORT)y);
  6810.                     if (tx == 6) {
  6811.                         /* TELNET DO LOGOUT received */
  6812.                     }
  6813.                 }
  6814.                 /* I'm echoing remote chars */
  6815.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6816.                   ttoc((CHAR)y);
  6817.             } else
  6818. #endif /* TNCODE */
  6819.               /* Handles terminal emulation responses */
  6820.               scriptwrtbuf((USHORT)y);
  6821. #endif /* TN_NOLO */
  6822.  
  6823.             /* Real input character to be checked */
  6824.  
  6825. #ifdef CK_BURST
  6826.             burst--;                    /* One less character waiting */
  6827.             debug(F101,"doinput burst","",burst);
  6828. #endif /* CK_BURST */
  6829.             c = (CHAR) (imask & (CHAR) y); /* Mask off any parity */
  6830.             inchar[0] = c;              /* Remember character for \v(inchar) */
  6831. #ifdef COMMENT
  6832. #ifdef CK_BURST
  6833.             /* Update "lastchar" time only once during input burst */
  6834.             if (burst <= 0)
  6835. #endif /* CK_BURST */
  6836. #endif /* COMMENT */
  6837.               lastchar = gtimer();      /* Remember when it came */
  6838.  
  6839.             if (c == '\0') {            /* NUL, we can't use it */
  6840.                 if (anychar) {          /* Except if any character will do? */
  6841.                     x = 1;              /* Yes, done. */
  6842.                     incount = 1;        /* This must be the first and only. */
  6843.                     break;
  6844.                 } else goto refill;     /* Otherwise continue INPUTting */
  6845.             }
  6846.             *inpbp++ = c;               /* Store char in circular buffer */
  6847.             incount++;                  /* Count it for \v(incount) */
  6848.  
  6849.             /* Don't NUL-terminate here - it's a circular buffer. */
  6850.  
  6851.             if (inpbp >= inpbuf + inbufsize) { /* Time to wrap around? */
  6852.                 wrapped++;
  6853.                 *inpbp = NUL ;          /* Make it null-terminated */
  6854.                 inpbp = inpbuf;         /* Yes. */
  6855.             }
  6856.             if (matchbuf) {
  6857.                 if (matchindex < MATCHBUFSIZ) {
  6858.                     matchbuf[matchindex++] = c;
  6859.                     matchbuf[matchindex] = NUL;
  6860.                 }
  6861.             }
  6862. #ifdef MAC
  6863.             {
  6864.                 extern char *ttermw;    /* fake pointer cast */
  6865.                 if (inecho) {
  6866.                     outchar(ttermw, c); /* echo to terminal window */
  6867.                     /* this might be too much overhead to do here ? */
  6868.                     updatecommand(ttermw);
  6869.                 }
  6870.             }
  6871. #else /* Not MAC */
  6872.             if (inecho) {               /* Buffer console output */
  6873.                 conbuf[concnt++] = c;
  6874.             }
  6875. #endif /* MAC */
  6876. #ifndef OS2
  6877.             if (seslog) {
  6878. #ifdef UNIX
  6879.                 if (sessft != 0 || c != '\r')
  6880. #else
  6881. #ifdef OSK
  6882.                 if (sessft != 0 || c != '\012')
  6883. #endif /* OSK */
  6884. #endif /* UNIX */
  6885.                   sesbuf[sescnt++] = c; /* Buffer session log output */
  6886.             }
  6887. #endif /* OS2 */
  6888.             if (anychar) {              /* Any character will do? */
  6889.                 x = 1;
  6890.                 break;
  6891.             }
  6892.             if (!inpcas[cmdlvl]) {      /* Ignore alphabetic case? */
  6893.                 if (isupper(c))         /* Yes, convert input char to lower */
  6894.                   c = (CHAR) tolower(c);
  6895.             }
  6896.             debug(F000,"doinput char","",c);
  6897.  
  6898.             /* Here is the matching section */
  6899.  
  6900.             y = -1;                     /* Loop thru search strings */
  6901.             while (!nomatch && (s = ms[++y])) {    /* ...as many as we have. */
  6902.                 if (mp[y]) {            /* Pattern match? */
  6903. #ifdef COMMENT
  6904.                     int j;
  6905.                     /* This is gross but it works... */
  6906.                     /* We could just as easily have prepended '*' to the  */
  6907.                     /* pattern and skipped the loop, except then we would */
  6908.                     /* not have any way to identify the matching string.  */
  6909.                     for (j = 0; j < matchindex; j++) {
  6910.                         if (ckmatch(s,&matchbuf[j],1,1)) {
  6911.                             matchindex = j;
  6912.                             x = 1;
  6913.                             break;
  6914.                         }
  6915.                     }
  6916.                     if (x > 0)
  6917.                       break;
  6918. #else
  6919.                     /* July 2001 - ckmatch() returns match position. */
  6920.                     /* It works and it's not gross. */
  6921.             /* (4 = floating pattern) */
  6922.                     x = ckmatch(s,matchbuf,inpcas[cmdlvl],1+4);
  6923.                     if (x > 0) {
  6924.                         matchindex = x - 1;
  6925.                         x = 1;
  6926.                         break;
  6927.                     }
  6928. #endif /* COMMENT */
  6929.                     continue;
  6930.                 }                       /* Literal match. */
  6931.                 i = mi[y];              /* Match-position in search string. */
  6932.                 debug(F000,"compare char","",(CHAR)s[i]);
  6933.                 if (c == (CHAR) s[i]) { /* Check for match */
  6934.                     i++;                /* Got one, go to next character */
  6935.                 } else {                /* Don't have a match */
  6936.                     int j;
  6937.                     for (j = i; i > 0; ) { /* Back up in search string */
  6938.                         i--; /* (Do this here to prevent compiler foulup) */
  6939.                         /* j is the length of the substring that matched */
  6940.                         if (c == (CHAR) s[i]) {
  6941.                             if (!strncmp(s,&s[j-i],i)) {
  6942.                                 i++;          /* c actually matches -- cfk */
  6943.                                 break;
  6944.                             }
  6945.                         }
  6946.                     }
  6947.                 }
  6948.                 if ((CHAR) s[i] == (CHAR) '\0') { /* Matched to end? */
  6949.                     ckstrncpy(matchbuf,ms[y],MATCHBUFSIZ);
  6950.                     matchindex = 0;
  6951.                     x = 1;              /* Yes, */
  6952.                     break;              /* done. */
  6953.                 }
  6954.                 mi[y] = i;              /* No, remember match-position */
  6955.             }
  6956.             if (x == 1) {               /* Set \v(minput) result */
  6957.                 m_found = y + 1;
  6958.                 break;
  6959.             }
  6960.         }
  6961. #ifdef CK_BURST
  6962.         else if (y <= -1 && burst > 0) {
  6963.             debug(F111,"doinput (y<=-1&&burst>0)","burst",burst);
  6964.                                         /* a timo occurred so there can't   */
  6965.             burst = 0;                  /* be data waiting; must check timo */
  6966.         }
  6967.       refill:
  6968.         if (burst <= 0) {               /* No buffered chars remaining... */
  6969.             myflsh();                   /* Flush buffered output */
  6970.             if (local) {                /* Get size of next input burst */
  6971.                 burst = ttchk();
  6972.                 if (burst < 0) {        /* ttchk() says connection is closed */
  6973.                     instatus = INP_IO;  /* Status = i/o error */
  6974. #ifndef NOLOCAL
  6975. #ifdef OS2
  6976.                     term_io = term_io_save;
  6977. #endif /* OS2 */
  6978. #endif /* NOLOCAL */
  6979.  
  6980.             if ((!network 
  6981. #ifdef TN_COMPORT
  6982.                  || istncomport()
  6983. #endif /* TN_COMPORT */
  6984.              ) && carrier != CAR_OFF) {
  6985.     /* The test is written this way because the Microsoft compiler
  6986.      * is producing bad code if written:
  6987.      *
  6988.      *  if (network && (!istncomport() || carrier == CAR_OFF) )
  6989.      */
  6990.             break;
  6991.                      } else {
  6992.              printf("Fatal error - disconnected.\n");
  6993.              ttclos(1);
  6994.              break;
  6995.              }
  6996.                 }
  6997.                 if (inintr) {
  6998.                     if ((icn = conchk()) > 0) { /* Interrupt from keyboard? */
  6999.                         kbchar = coninc(0);
  7000.                         debug(F101,"input interrupted from keyboard","",icn);
  7001.                         while (--icn > 0) coninc(0); /* Yes, absorb chars. */
  7002.                         break;          /* And fail. */
  7003.                     }
  7004.                 }
  7005.             } else {
  7006.                 burst = conchk();
  7007.             }
  7008.             debug(F101,"doinput burst","",burst);
  7009.             /* Prevent overflow of "conbuf" and "sesbuf" */
  7010.             if (burst > MAXBURST)
  7011.               burst = MAXBURST;
  7012.  
  7013.             /* Did not match, timer exceeded? */
  7014.             t = gtimer();
  7015.             debug(F111,"doinput gtimer","burst",t);
  7016.             debug(F101,"doinput timo","",timo);
  7017.             if ((t >= timo) && (timo > 0))
  7018.               break;
  7019.             else if (insilence > 0 && (t - lastchar) > insilence)
  7020.               break;
  7021.         } else {
  7022.             debug(F111,"doinput (burst > 0)","burst",burst);
  7023.         }
  7024. #else
  7025.         myflsh();                       /* Flush buffered output */
  7026.         /* Did not match, timer exceeded? */
  7027.         t = gtimer();
  7028.         debug(F111,"doinput gtimer","no burst",t);
  7029.         debug(F101,"doinput timo","",timo);
  7030.         if ((t >= timo) && (timo > -1))
  7031.           break;
  7032.         else if (insilence > 0 && (t - lastchar) > insilence)
  7033.           break;
  7034. #endif /* CK_BURST */
  7035.     }                                   /* Still have time left, continue. */
  7036.     if (nomatch) x = 1;            /* Succeed if nomatch and timed out. */
  7037.     myflsh();                           /* Flush buffered output. */
  7038.     if (x > 0 && !nomatch)
  7039.       instatus = 0;
  7040. #ifndef NOLOCAL
  7041. #ifdef OS2
  7042.     term_io = term_io_save;
  7043. #endif /* OS2 */
  7044. #endif /* NOLOCAL */
  7045. #ifdef COMMENT
  7046. #ifdef IKS_OPTION
  7047. #ifdef CK_AUTODL
  7048.     if (is_tn && TELOPT_ME(TELOPT_KERMIT) && inautodl) {
  7049.         tn_siks(KERMIT_STOP);           /* Send Kermit-Server Stop */
  7050.     }
  7051. #endif /* CK_AUTODL */
  7052. #endif /* IKS_OPTION */
  7053. #endif /* COMMENT */
  7054.  
  7055. #ifdef GFTIMER
  7056.     fpt = gftimer();                    /* Get elapsed time */
  7057.  
  7058. /* If a long is 32 bits, it would take about 50 days for this to overflow. */
  7059.  
  7060.     inetime = (int)(fpt * (CKFLOAT)1000.0);
  7061. #else
  7062.     inetime = (int)(gtimer() * 1000);
  7063. #endif /* GFTIMER */
  7064.  
  7065.     if (!nomatch)
  7066.       makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  7067.     return(x);                          /* Return the return code. */
  7068. }
  7069. #endif /* NOSPL */
  7070.  
  7071. #ifndef NOSPL
  7072. /* REINPUT Command */
  7073.  
  7074. /*
  7075.   Note, the timeout parameter is required, but ignored.  Syntax is compatible
  7076.   with MS-DOS Kermit except timeout can't be omitted.  This function only
  7077.   looks at the characters already received and does not read any new
  7078.   characters from the connection.
  7079. */
  7080. int
  7081. doreinp(timo,s,pat) int timo; char *s; int pat; {
  7082.     int x, y, i;
  7083.     char *xx, *xp, *xq = (char *)0;
  7084.     CHAR c;
  7085.  
  7086.     if (!s) s = "";
  7087.     debug(F101,"doreinput pat","",pat);
  7088.  
  7089.     y = (int)strlen(s);
  7090.     debug(F111,"doreinput search",s,y);
  7091.  
  7092.     if (y > inbufsize) {                /* If search string longer than */
  7093.         debug(F101,"doreinput inbufsize","",inbufsize);
  7094.         return(0);                      /* input buffer, fail. */
  7095.     }
  7096.     makestr(&inpmatch,NULL);
  7097.     if (!matchbuf)
  7098.       matchbuf = malloc(MATCHBUFSIZ+1);
  7099.     matchindex = 0;
  7100.  
  7101.     x = 0;                              /* Return code, assume failure */
  7102.     i = 0;                              /* String pattern match position */
  7103.  
  7104.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  7105.         xp = malloc(y+2);               /* Make a separate copy of the */
  7106.         if (!xp) {                      /* search string. */
  7107.             printf("?malloc error 6\n");
  7108.             return(x);
  7109.         } else xq = xp;                 /* Keep pointer to beginning. */
  7110.         while (*s) {                    /* Yes, convert to lowercase */
  7111.             *xp = *s;
  7112.             if (isupper(*xp)) *xp = (char) tolower(*xp);
  7113.             xp++; s++;
  7114.         }
  7115.         *xp = NUL;                      /* Terminate it! */
  7116.         s = xq;                         /* Move search pointer to it. */
  7117.     }
  7118.     xx = *inpbp ? inpbp : inpbuf;       /* Current INPUT buffer pointer */
  7119.     do {
  7120.         c = *xx++;                      /* Get next character */
  7121.         if (!c) break;
  7122.         if (xx >= inpbuf + inbufsize)   /* Wrap around if necessary */
  7123.           xx = inpbuf;
  7124.         if (!inpcas[cmdlvl]) {          /* Ignore alphabetic case? */
  7125.             if (isupper(c)) c = (CHAR) tolower(c); /* Yes */
  7126.         }
  7127.         if (pat) {
  7128.             int j;
  7129.             if (matchbuf) {
  7130.                 if (matchindex < MATCHBUFSIZ) {
  7131.                     matchbuf[matchindex++] = c;
  7132.                     matchbuf[matchindex] = NUL;
  7133.                 }
  7134.                 for (j = 0; j < matchindex; j++) { /* Gross but effective */
  7135.                     if (ckmatch(s,&matchbuf[j],1,1)) {
  7136.                         debug(F101,"GOT IT","",j);
  7137.                         matchindex = j;
  7138.                         x = 1;
  7139.                         break;
  7140.                     }
  7141.                 }
  7142.             }
  7143.             if (x > 0)
  7144.               break;
  7145.             continue;
  7146.         }
  7147.         debug(F000,"doreinp char","",c);
  7148.         debug(F000,"compare char","",(CHAR) s[i]);
  7149.         if (((char) c) == ((char) s[i])) { /* Check for match */
  7150.             i++;                        /* Got one, go to next character */
  7151.         } else {                        /* Don't have a match */
  7152.             int j;
  7153.             for (j = i; i > 0; ) {      /* [jrs] search backwards for it  */
  7154.                 i--;
  7155.                 if (((char) c) == ((char) s[i])) {
  7156.                     if (!strncmp(s,&s[j-i],i)) {
  7157.                         i++;
  7158.                         break;
  7159.                     }
  7160.                 }
  7161.             }
  7162.         }                               /* [jrs] or return to zero from -1 */
  7163.         if (s[i] == '\0') {             /* Matched all the way to end? */
  7164.             ckstrncpy(matchbuf,s,MATCHBUFSIZ);
  7165.             matchindex = 0;
  7166.             x = 1;                      /* Yes, */
  7167.             break;                      /* done. */
  7168.         }
  7169.     } while (xx != inpbp && x < 1);     /* Until back where we started. */
  7170.  
  7171.     if (!inpcas[cmdlvl]) if (xq) free(xq); /* Free this if it was malloc'd. */
  7172.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  7173.     return(x);                          /* Return search result. */
  7174. }
  7175.  
  7176. /*  X X S T R I N G  --  Interpret strings containing backslash escapes  */
  7177. /*  Z Z S T R I N G  --  (new name...)  */
  7178. /*
  7179.  Copies result to new string.
  7180.   strips enclosing braces or doublequotes.
  7181.   interprets backslash escapes.
  7182.   returns 0 on success, nonzero on failure.
  7183.   tries to be compatible with MS-DOS Kermit.
  7184.  
  7185.  Syntax of input string:
  7186.   string = chars | "chars" | {chars}
  7187.   chars = (c*e*)*
  7188.   where c = any printable character, ascii 32-126
  7189.   and e = a backslash escape
  7190.   and * means 0 or more repetitions of preceding quantity
  7191.   backslash escape = \operand
  7192.   operand = {number} | number | fname(operand) | v(name) | $(name) | m(name)
  7193.   number = [r]n[n[n]]], i.e. an optional radix code followed by 1-3 digits
  7194.   radix code is oO (octal), xX (hex), dD or none (decimal) (see xxesc()).
  7195. */
  7196.  
  7197. #ifndef NOFRILLS
  7198. int
  7199. yystring(s,s2) char *s; char **s2; {    /* Reverse a string */
  7200.     int x;
  7201.     static char *new;
  7202.     new = *s2;
  7203.     if (!s || !new) return(-1);         /* Watch out for null pointers. */
  7204.     if ((x = (int)strlen(s)) == 0) {    /* Recursion done. */
  7205.         *new = '\0';
  7206.         return(0);
  7207.     }
  7208.     x--;                                /* Otherwise, call self */
  7209.     *new++ = s[x];                      /* to reverse rest of string. */
  7210.     s[x] = 0;
  7211.     return(yystring(s,&new));
  7212. }
  7213. #endif /* NOFRILLS */
  7214.  
  7215. static char ipabuf[16] = { NUL };       /* IP address buffer */
  7216.  
  7217. static char *
  7218. getip(s) char *s; {
  7219.     char c=NUL;                         /* Workers... */
  7220.     int i=0, p=0, d=0;
  7221.     int state = 0;                      /* State of 2-state FSA */
  7222.  
  7223.     while ((c = *s++)) {
  7224.         switch(state) {
  7225.           case 0:                       /* Find first digit */
  7226.             i = 0;                      /* Output buffer index */
  7227.             ipabuf[i] = NUL;            /* Initialize output buffer */
  7228.             p = 0;                      /* Period counter */
  7229.             d = 0;                      /* Digit counter */
  7230.             if (isdigit(c)) {           /* Have first digit */
  7231.                 d = 1;                  /* Count it */
  7232.                 ipabuf[i++] = c;        /* Copy it */
  7233.                 state = 1;              /* Change state */
  7234.             }
  7235.             break;
  7236.  
  7237.           case 1:                       /* In numeric field */
  7238.             if (isdigit(c)) {           /* Have digit */
  7239.                 if (++d > 3)            /* Too many */
  7240.                   state = 0;            /* Start over */
  7241.                 else                    /* Not too many */
  7242.                   ipabuf[i++] = c;      /* Keep it */
  7243.             } else if (c == '.' && p < 3) { /* Have a period */
  7244.                 p++;                    /* Count it */
  7245.                 if (d == 0)             /* Not preceded by a digit */
  7246.                   state = 0;            /* Start over */
  7247.                 else                    /* OK */
  7248.                   ipabuf[i++] = c;      /* Keep it */
  7249.                 d = 0;                  /* Reset digit counter */
  7250.             } else if (p == 3 && d > 0) { /* Not part of address */
  7251.                 ipabuf[i] = NUL;        /* If we have full IP address */
  7252.                 return((char *)ipabuf); /* Return it */
  7253.             } else {                    /* Otherwise */
  7254.                 state = 0;              /* Start over */
  7255.                 ipabuf[0] = NUL;        /* (in case no more chars left) */
  7256.             }
  7257.         }
  7258.     }                                   /* Fall thru at end of string */
  7259.     ipabuf[i] = NUL;                    /* Maybe we have one */
  7260.     return((p == 3 && d > 0) ? (char *)ipabuf : "");
  7261. }
  7262. #endif /* NOSPL */
  7263.  
  7264. /* Date Routines */
  7265.  
  7266. /* Z J D A T E  --  Convert yyyymmdd date to Day of Year */
  7267.  
  7268. static int jdays[12] = {  0,31,59,90,120,151,181,212,243,273,304,334 };
  7269. static int ldays[12] = {  0,31,60,91,121,152,182,213,244,274,305,335 };
  7270. static char zjdbuf[12] = { NUL, NUL };
  7271. /*
  7272.   Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat,
  7273.   statuimus bissextum quarto quoque anno (uti mos est) continuari debere,
  7274.   praeterquam in centesimis annis; qui, quamvis bissextiles antea semper
  7275.   fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps
  7276.   consequentur centesimi non omnes bissextiles sint, sed in quadringentis
  7277.   quibusque annis primi quique tres centesimi sine bissexto transigantur,
  7278.   quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC,
  7279.   MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus
  7280.   intercaletur, februario dies XXIX continente, idemque ordo intermittendi
  7281.   intercalandique bissextum diem in quadringentis quibusque annis perpetuo
  7282.   conservetur.  - Gregorius XIII, Anno Domini MDLXXXII.
  7283. */
  7284. char *
  7285. zjdate(date) char * date; {             /* date = yyyymmdd */
  7286.     char year[5];
  7287.     char month[3];
  7288.     char day[3];
  7289.     int d, m, x, y;
  7290.     int leapday, j;
  7291.     char * time = NULL;
  7292.  
  7293.     if (!date) date = "";               /* Validate arg */
  7294.     x = strlen(date);
  7295.     if (x < 1) return("0");
  7296.     if (x < 8) return("-1");
  7297.     for (x = 0; x < 8; x++)
  7298.       if (!isdigit(date[x]))
  7299.         return("-1");
  7300.  
  7301.     if (date[8]) if (date[9])
  7302.       time = date + 9;
  7303.  
  7304.     year[0] = date[0];                  /* Isolate year */
  7305.     year[1] = date[1];
  7306.     year[2] = date[2];
  7307.     year[3] = date[3];
  7308.     year[4] = '\0';
  7309.  
  7310.     month[0] = date[4];                 /* Month */
  7311.     month[1] = date[5];
  7312.     month[2] = '\0';;
  7313.  
  7314.     day[0] = date[6];                   /* And day */
  7315.     day[1] = date[7];
  7316.     day[2] = '\0';
  7317.  
  7318.     leapday = 0;                        /* Assume no leap day */
  7319.     y = atoi(year);
  7320.     m = atoi(month);
  7321.     d = atoi(day);
  7322.     if (m > 2) {                        /* No Leap day before March */
  7323.         if (y % 4 == 0) {               /* If year is divisible by 4 */
  7324.             leapday = 1;                /* It's a Leap year */
  7325.             if (y % 100 == 0) {         /* Except if divisible by 100 */
  7326.                 if (y % 400 != 0)       /* but not by 400 */
  7327.                   leapday = 0;
  7328.             }
  7329.         }
  7330.     }
  7331.     j = jdays[m - 1] + d + leapday;     /* Day of year */
  7332.     if (time)
  7333.       sprintf(zjdbuf,"%04d%03d %s",y,j,time); /* SAFE */
  7334.     else
  7335.       sprintf(zjdbuf,"%04d%03d",y,j);   /* SAFE */
  7336.     return((char *)zjdbuf);
  7337. }
  7338.  
  7339. static char jzdbuf[32];
  7340.  
  7341. /* J Z D A T E  --  Convert Day of Year to yyyyddmm date */
  7342.  
  7343. char *
  7344. jzdate(date) char * date; {             /* date = yyyyddd */
  7345.     char year[5];                       /* with optional time */
  7346.     char day[4];
  7347.     char * time = NULL, * p;
  7348.     int d, m, x, y;
  7349.     int leapday, j;
  7350.     int * zz;
  7351.  
  7352.     if (!date) date = "";               /* Validate arg */
  7353.     x = strlen(date);
  7354.  
  7355.     debug(F111,"jzdate len",date,x);
  7356.  
  7357.     if (x < 1) return("0");
  7358.     if (x < 7) return("-1");
  7359.     if (x > 8) time = date + 8;
  7360.  
  7361.     for (x = 0; x < 7; x++)
  7362.       if (!isdigit(date[x]))
  7363.         return("-1");
  7364.  
  7365.     year[0] = date[0];                  /* Isolate year */
  7366.     year[1] = date[1];
  7367.     year[2] = date[2];
  7368.     year[3] = date[3];
  7369.     year[4] = '\0';
  7370.  
  7371.     debug(F110,"jzdate year",year,0);
  7372.  
  7373.     day[0] = date[4];                   /* And day */
  7374.     day[1] = date[5];
  7375.     day[2] = date[6];
  7376.     day[3] = '\0';
  7377.  
  7378.     debug(F110,"jzdate day",day,0);
  7379.  
  7380.     j = atoi(day);
  7381.     if (j > 366)
  7382.       return("-1");
  7383.  
  7384.     leapday = 0;                        /* Assume no leap day */
  7385.     y = atoi(year);
  7386.     if (y % 4 == 0) {                   /* If year is divisible by 4 */
  7387.         leapday = 1;                    /* It's a Leap year */
  7388.         if (y % 100 == 0) {             /* Except if divisible by 100 */
  7389.             if (y % 400 != 0)           /* but not by 400 */
  7390.               leapday = 0;
  7391.         }
  7392.     }
  7393.     debug(F101,"jzdate leapday","",leapday);
  7394.     zz = leapday ? ldays : jdays;
  7395.  
  7396.     for (x = 0; x < 11; x++)
  7397.       if (j > zz[x] && j <= zz[x+1])
  7398.         break;
  7399.     m = x + 1;
  7400.  
  7401.     debug(F101,"jzdate m","",m);
  7402.  
  7403.     d = j - zz[x];
  7404.  
  7405.     debug(F101,"jzdate d","",d);
  7406.  
  7407.     if (time)
  7408.       sprintf(jzdbuf,"%04d%02d%02d %s",y,m,d,time); /* SAFE */
  7409.     else
  7410.       sprintf(jzdbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7411.  
  7412.     debug(F101,"jzdate jzdbuf",jzdbuf,0);
  7413.  
  7414.     p = ckcvtdate((char *)jzdbuf, 0);   /* Convert to standard form */
  7415.     ckstrncpy(jzdbuf,p,32);
  7416.     if (!time) jzdbuf[8] = NUL;         /* Remove time if not wanted */
  7417.     return((char *)jzdbuf);
  7418. }
  7419.  
  7420. /* M J D  --  Modified Julian Date */
  7421. /*
  7422.   Call with:
  7423.     Standard-format date-time string: yyyymmdd[ hh:mm:ss].
  7424.     The time, if any, is ignored.
  7425.  
  7426.   Returns:
  7427.     -1L on error, otherwise:
  7428.     The number of days since 17 Nov 1858 as a whole number:
  7429.     16 Nov 1858 = -1, 17 Nov 1858 = 0, 18 Nov 1858 = 1, 19 Nov 1858 = 2, ...
  7430.  
  7431.   The Modified Julian Date is defined by the International Astronomical
  7432.   Union as the true Julian date minus 2400000.5 days.  The true Julian
  7433.   date is the number days since since noon of 1 January 4713 BCE of the
  7434.   Julian proleptic calendar.  Conversions between calendar dates and
  7435.   Julian dates, however, assume Gregorian dating.
  7436. */
  7437. long
  7438. mjd(date) char * date; {
  7439.     char year[5];
  7440.     char month[3];
  7441.     char day[3];
  7442.     int x, a, d, m, y;
  7443.     long z;
  7444.  
  7445.     if (!date) date = "";               /* Validate arg */
  7446.     x = strlen(date);
  7447.     if (x < 1) return(0L);
  7448.     if (x < 8) return(-1L);
  7449.     for (x = 0; x < 8; x++)
  7450.       if (!isdigit(date[x]))
  7451.         return(-1L);
  7452.  
  7453.     year[0] = date[0];                  /* Isolate year */
  7454.     year[1] = date[1];
  7455.     year[2] = date[2];
  7456.     year[3] = date[3];
  7457.     year[4] = '\0';
  7458.  
  7459.     month[0] = date[4];                 /* Month */
  7460.     month[1] = date[5];
  7461.     month[2] = '\0';;
  7462.     m = atoi(month);
  7463.  
  7464.     day[0] = date[6];                   /* And day */
  7465.     day[1] = date[7];
  7466.     day[2] = '\0';
  7467.     d = atoi(day);
  7468.  
  7469.     a = (14-m)/12;                      /* Calculate true Julian date */
  7470.     y = atoi(year) + 4800 - a;
  7471.     m = m + 12 * a - 3;
  7472.     z = d + (long)(306*m+5)/10 + (long)(y*365) + y/4 - y/100 + y/400 - 32045L;
  7473.  
  7474.     z -= 2400001L;                      /* Convert JD to MJD */
  7475.  
  7476.     return(z);
  7477. }
  7478.  
  7479. static char mjd2dbuf[32];
  7480.  
  7481. /*  M J D 2 D A T E  --  Converts MJD to yyyymmdd  */
  7482.  
  7483. char *
  7484. #ifdef CK_ANSIC
  7485. mjd2date(long mjd)
  7486. #else
  7487. mjd2date(mjd) long mjd;
  7488. #endif /* CK_ANSIC */
  7489. /* mjd2date */ {
  7490.     long jd, l, n;
  7491.     int d, m, y;
  7492.     jd = (long)(mjd + 2400001L);
  7493.     l = jd + 68569;
  7494.     n = 4 * l / 146097L;
  7495.     l = l - (146097 * n + 3) / 4;
  7496.     y = 4000 * (l + 1) / 1461001L;
  7497.     l = l - 1461 * y / 4 + 31;
  7498.     m = 80 * l / 2447;
  7499.     d = l - 2447 * m / 80;
  7500.     l = m / 11;
  7501.     m = m + 2 - 12 * l;
  7502.     y = 100 * (n - 49) + y + l;
  7503.     sprintf(mjd2dbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7504.     return((char *)mjd2dbuf);
  7505. }
  7506.  
  7507. #ifndef NOSPL
  7508. static char ** flist = (char **) NULL;  /* File list for \fnextfile() */
  7509. static int flistn = 0;                  /* Number of items in file list */
  7510.  
  7511. /*
  7512.   The function return-value buffer must be global, since fneval() returns a
  7513.   pointer to it.  fneval() is called only by zzstring(), which always copies
  7514.   the result out of this buffer to somewhere else, so it's OK to have only
  7515.   one buffer for this in most cases.  However, since function calls can be
  7516.   nested -- e.g. functions whose arguments are functions, or recursive
  7517.   functions, at some point we should convert this to an array of buffers,
  7518.   indexed by function depth (which might or might not be the same as the
  7519.   "depth" variable).  Also, since function results are potentially quite big,
  7520.   we'd need to allocate and deallocate dynamically as we descend and ascend
  7521.   function depth.  Left for a future release...
  7522. */
  7523. char fnval[FNVALL+2];                   /* Function return value  */
  7524. static int fndepth = 0;                 /* (we don't actually use this yet) */
  7525. int fnsuccess = 1;
  7526. extern int fnerror;
  7527.  
  7528. /* f p f o r m a t  --  Floating-point number nicely formatted.  */
  7529. /*
  7530.    Returns results from a circular 1K buffer.
  7531.    Don't count on too many results remaining available at once; it could
  7532.    be anywhere from 5 to maybe 100, depending on the sizes of the results.
  7533. */
  7534. #ifdef CKFLOAT
  7535. #define FPFMTSIZ 1024
  7536. static char fpfmtbuf[FPFMTSIZ] = { NUL, NUL };
  7537. static int fpfbufpos = 0;               /* (why was this char before?) */
  7538.  
  7539. char *
  7540. fpformat(fpresult,places,round) CKFLOAT fpresult; int places, round; {
  7541.     char fbuf[16];                      /* For creating printf format */
  7542.     int nines = 0, sign = 0, x, y, i, j, size = 0;
  7543.     char * buf;
  7544.     CKFLOAT ftmp;
  7545.  
  7546.     x = places ? places : (fp_digits ? fp_digits : 6);
  7547.  
  7548.     debug(F101,"fpformat fpresult","",fpresult);
  7549.     debug(F101,"fpformat places","",places);
  7550.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7551.  
  7552.     ftmp = fpresult;
  7553.     if (ftmp < 0.0) ftmp = 0.0 - fpresult;
  7554.  
  7555. #ifdef FNFLOAT
  7556.     if (!fp_rounding &&                 /* If printf doesn't round, */
  7557.         (places > 0 ||                  /* round result to decimal places. */
  7558.          (places == 0 && round)))
  7559.       fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  7560.     y = (ftmp == 0.0) ? 1 : (int)log10(ftmp);
  7561.     size = y + x + 3;                   /* Estimated length of result */
  7562.     if (fpresult < 0.0) size++;
  7563. #else
  7564.     size = 200;                         /* No way to estimate, be generous */
  7565. #endif /* FNFLOAT */
  7566.  
  7567.     debug(F101,"fpformat size","",size);
  7568.  
  7569.     if (fpfbufpos > (FPFMTSIZ - size))  /* Wrap around if necessary */
  7570.       fpfbufpos = 0;
  7571.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7572.  
  7573.     buf = &fpfmtbuf[fpfbufpos];
  7574.  
  7575.     if (places > 0) {                   /* If places specified */
  7576.         /* use specified places to write given number of digits */
  7577.         sprintf(fbuf,"%%0.%df",places); /* SAFE */
  7578.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7579.     } else {                            /* Otherwise... */
  7580.         /* Go for max precision */
  7581.         sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  7582.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7583.     }
  7584.     if (buf[0] == '-') sign = 1;
  7585.     debug(F111,"fpresult 1 errno",buf,errno); /* Check for over/underflow */
  7586.     debug(F111,"fpresult 1 fpfbufpos",buf,fpfbufpos);
  7587.     /* Give requested decimal places */
  7588.     for (i = sign; i < FPFMTSIZ && buf[i]; i++) {
  7589.         if (buf[i] == '.')              /* First find the decimal point */
  7590.           break;
  7591.         else if (i > fp_digits + sign - 1) /* replacing garbage */
  7592.           buf[i] = '0';                 /* digits with 0... */
  7593.     }
  7594.     if (buf[i] == '.') {                /* Have decimal point */
  7595.         int gotend = 0;
  7596.         /* places < 0 so truncate fraction */
  7597.         if (places < 0 || (places == 0 && round)) {
  7598.             buf[i] = NUL;
  7599.         } else if (places > 0) {        /* d > 0 so this many decimal places */
  7600.             i++;                           /* First digit after decimal */
  7601.             for (j = 0; j < places; j++) { /* Truncate after d decimal */
  7602.                 if (!buf[j+i])        /* places or extend to d  */
  7603.                   gotend = 1;              /* decimal places. */
  7604.                 if (gotend || j+i+sign > fp_digits)
  7605.                   buf[j+i] = '0';
  7606.             }
  7607.             buf[j+i] = NUL;
  7608.         } else {                        /* places == 0 so Do The Right Thing */
  7609.             for (j = (int)strlen(buf) - 1; j > i+1; j--) {
  7610.                 if ((j - sign) > fp_digits)
  7611.                   buf[j] = '0';
  7612.                 if (buf[j] == '0')
  7613.                   buf[j] = NUL; /* Strip useless trailing 0's. */
  7614.                 else
  7615.                   break;
  7616.             }
  7617.         }
  7618.     }
  7619.     fpfmtbuf[FPFMTSIZ-1] = NUL;
  7620.     j = strlen(buf);
  7621.     sign = 0;
  7622.     for (i = j-1; i >= 0; i--) {
  7623.         if (buf[i] == '9')
  7624.           nines++;
  7625.         else
  7626.           break;
  7627.     }
  7628.     /* Do something about xx.xx99999999... */
  7629.     if (nines > 5) {
  7630.         if (isdigit(buf[i]) && i < FPFMTSIZ - 2) {
  7631.             buf[i] = buf[i] + 1;
  7632.             buf[i+1] = '0';
  7633.             buf[i+2] = '\0';
  7634.         }
  7635.     }
  7636.     if (!strncmp(buf,"-0.0",FPFMTSIZ))
  7637.       ckstrncpy(buf,"0.0",FPFMTSIZ);
  7638.     fpfbufpos += (int)strlen(buf) + 1;
  7639.     return((char *)buf);
  7640. }
  7641. #endif /* CKFLOAT */
  7642.  
  7643. static VOID
  7644. evalerr(fn) char * fn; {
  7645.     if (fndiags) {
  7646.         if (divbyzero)
  7647.           ckmakmsg(fnval,FNVALL,"<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  7648.         else
  7649.           ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  7650.     }
  7651. }
  7652.  
  7653. char *
  7654. dokwval(s,sep) char * s, sep; {
  7655.     char c = '\0', * p, * kw = NULL, * vp = NULL;
  7656.     int x;
  7657.     if (!s) return("0");
  7658.     if (!*s) return("0");
  7659.     debug(F110,"kwval arg",s,0);
  7660.     debug(F110,"kwval sep",ckctoa(sep),0);
  7661.     p = (char *)malloc((int)strlen(s)+1);
  7662.     if (!p) return("0");
  7663.     strcpy(p,s);                        /* SAFE */
  7664.     s = p;
  7665.     while (*s < '!' && *s > '\0')       /* Get first nonblank */
  7666.       s++;
  7667.     if (!*s) return("0");
  7668.     if (*s == sep) return("0");
  7669.     kw = s;                             /* Keyword */
  7670.     while (*s > ' ') {
  7671.         if (*s == sep) {                /* keyword=... */
  7672.             c = *s;
  7673.             break;
  7674.         }
  7675.         s++;
  7676.     }
  7677.     *s++ = NUL;                         /* Terminate keyword */
  7678.     while (*s < '!' && *s > '\0')       /* Skip blanks */
  7679.       s++;
  7680.     if (!c && *s == sep) {
  7681.         c = *s++;                       /* Have separator */
  7682.         while (*s < '!' && *s > '\0')   /* Skip blanks */
  7683.           s++;
  7684.     }
  7685.     if (c) {
  7686.         vp = s;
  7687.         while (*s > ' ')                /* Skip to end */
  7688.           s++;
  7689.         *s = NUL;                       /* Terminate value */
  7690.     }
  7691.     debug(F110,"kwval c",ckctoa(c),0);
  7692.     debug(F110,"kwval keyword",kw,0);
  7693.     debug(F110,"kwval value",vp,0);
  7694.     x = c ? addmac(kw,vp) : -1;
  7695.     free(p);
  7696.     return((x < 0) ? "0" : "1");
  7697. }
  7698.  
  7699. static int
  7700. isaarray(s) char * s; {            /* Is s an associative array element */
  7701.     int state = 0;
  7702.     CHAR c;
  7703.     if (!s) return(0);
  7704.     while ((c = *s++)) {
  7705.     if (!isprint(c)) {
  7706.         return(0);
  7707.     } else if (c == '<') {
  7708.         if (state != 0)
  7709.           return(0);
  7710.         state = 1;
  7711.     } else if (c == '>') {
  7712.         return((state != 1 || *s) ? 0 : 1);
  7713.     }
  7714.     }
  7715.     return(0);
  7716. }
  7717.  
  7718. static char *                           /* Evaluate builtin functions */
  7719. fneval(fn,argp,argn,xp) char *fn, *argp[]; int argn; char * xp; {
  7720.     int i=0, j=0, k=0, len1=0, len2=0, len3=0, n=0, t=0, x=0, y=0;
  7721.     int cx, failed = 0;                 /* Return code, 0 = ok */
  7722.     long z = 0L;
  7723.     char *bp[FNARGS + 1];               /* Pointers to malloc'd strings */
  7724.     char c = NUL;
  7725.     char *p = NULL, *s = NULL;
  7726.     char *val1 = NULL, *val2 = NULL;    /* Pointers to numeric string values */
  7727.  
  7728. #ifdef RECURSIVE
  7729.     int rsave = recursive;
  7730. #endif /* RECURSIVE */
  7731. #ifdef OS2
  7732.     int zsave = zxpn;
  7733. #endif /* OS2 */
  7734.  
  7735.     if (!fn) fn = "";                   /* Protect against null pointers */
  7736.     if (!*fn) return("");
  7737.  
  7738.     for (i = 0; i < FNARGS; i++)        /* Initialize argument pointers */
  7739.       bp[i] = NULL;
  7740. /*
  7741.   IMPORTANT: Note that argn is not an accurate count of the number of
  7742.   arguments.  We can't really tell if an argument is null until after we
  7743.   execute the code below.  So argn is really the maximum number of arguments
  7744.   we might have.  Argn should always be at least 1, even if the function is
  7745.   called with empty parentheses (but don't count on it).
  7746. */
  7747.     debug(F111,"fneval",fn,argn);
  7748.     debug(F110,"fneval",argp[0],0);
  7749.     if (argn > FNARGS)                  /* Discard excess arguments */
  7750.       argn = FNARGS;
  7751.  
  7752.     fndepth++;
  7753.     debug(F101,"fneval fndepth","",fndepth);
  7754.     p = fnval;
  7755.     fnval[0] = NUL;
  7756.     y = lookup(fnctab,fn,nfuncs,&x);    /* Look up the function name */
  7757.     cx = y;                             /* Because y is too generic... */
  7758.     if (cx < 0) {                        /* Not found */
  7759.         failed = 1;
  7760.         if (fndiags) {                  /* FUNCTION DIAGNOSTIC ON */
  7761.             int x;
  7762.             x = strlen(fn);
  7763.             /* The following sprintf's are safe */
  7764.             switch (cx) {
  7765.               case -1:
  7766.                 if (x + 32 < FNVALL)
  7767.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION:\\f%s()>",fn);
  7768.                 else
  7769.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION>");
  7770.                 break;
  7771.               case -2:
  7772.                 if (x + 26 < FNVALL)
  7773.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS:\\f%s()>",fn);
  7774.                 else
  7775.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS>");
  7776.                 break;
  7777.               case -3:
  7778.                 sprintf(fnval,"<ERROR:FUNCTION_NAME_MISSING:\\f()>");
  7779.                 break;
  7780.               default:
  7781.                 if (x + 26 < FNVALL)
  7782.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE:\\f%s()>",fn);
  7783.                 else
  7784.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE>");
  7785.                 break;
  7786.             }
  7787.         }
  7788.         goto fnend;                     /* Always leave via common exit */
  7789.     }
  7790.     fn = fnctab[x].kwd;                 /* Full name of function */
  7791.  
  7792.     if (argn < 0) {
  7793.         failed = 1;
  7794.         p = fnval;
  7795.         if (fndiags)
  7796.           sprintf(fnval,"<ERROR:MISSING_ARG:\\f%s()>",fn);
  7797.         goto fnend;
  7798.     }
  7799.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7800.         debug(F010,"flit",xp,0);
  7801.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7802.         goto fnend;
  7803.     }
  7804.  
  7805. #ifdef DEBUG
  7806.     if (deblog) {
  7807.         int j;
  7808.         for (j = 0; j < argn; j++)
  7809.           debug(F111,"fneval arg",argp[j],j);
  7810.     }
  7811. #endif /* DEBUG */
  7812.     for (j = argn-1; j >= 0; j--) {     /* Uncount empty trailing args */
  7813.         if (!argp[j])
  7814.           argn--;
  7815.         else if (!*(argp[j]))
  7816.           argn--;
  7817.         else break;
  7818.     }
  7819.     debug(F111,"fneval argn",fn,argn);
  7820. /*
  7821.   \fliteral() and \fcontents() are special functions that do not evaluate
  7822.   their arguments, and are treated specially here.  After these come the
  7823.   functions whose arguments are evaluated in the normal way.
  7824. */
  7825. #ifdef COMMENT
  7826.     /* (moved up) */
  7827.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7828.         debug(F110,"flit",xp,0);
  7829.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7830.         goto fnend;
  7831.     }
  7832. #endif /* COMMENT */
  7833.     if (cx == FN_CON) {                 /* Contents of variable, unexpanded. */
  7834.         char c;
  7835.         if (!(p = argp[0]) || !*p) {
  7836.             failed = 1;
  7837.             p = fnval;
  7838.             if (fndiags)
  7839.               sprintf(fnval,"<ERROR:MISSING_ARG:\\fcontents()>");
  7840.             goto fnend;
  7841.         }
  7842.         p = brstrip(p);
  7843.         if (*p == CMDQ) p++;
  7844.         if ((c = *p) == '%') {          /* Scalar variable. */
  7845.             c = *++p;                   /* Get ID character. */
  7846.             p = "";                     /* Assume definition is empty */
  7847.             if (!c) {                   /* Double paranoia */
  7848.                 failed = 1;
  7849.                 p = fnval;
  7850.                 if (fndiags)
  7851.                   sprintf(fnval,"<ERROR:ARG_BAD_VARIABLE:\\fcontents()>");
  7852.                 goto fnend;
  7853.             }
  7854.             if (c >= '0' && c <= '9') { /* Digit for macro arg */
  7855.                 if (maclvl < 0)         /* Digit variables are global */
  7856.                   p = g_var[c];         /* if no macro is active */
  7857.                 else                    /* otherwise */
  7858.                   p = m_arg[maclvl][c - '0']; /* they're on the stack */
  7859.             } else if (c == '*') {
  7860. #ifdef COMMENT
  7861.                 p = (maclvl > -1) ? m_line[maclvl] : topline;
  7862.                 if (!p) p = "";
  7863. #else
  7864.                 int nx = FNVALL;
  7865.                 char * sx = fnval;
  7866.                 p = fnval;
  7867. #ifdef COMMENT
  7868.                 if (cmdsrc() == 0 && topline)
  7869.                   p = topline;
  7870.                 else
  7871. #endif /* COMMENT */
  7872.                   if (zzstring("\\fjoin(&_[],{ },1)",&sx,&nx) < 0) {
  7873.                     failed = 1;
  7874.                     p = fnval;
  7875.                     if (fndiags)
  7876.                       sprintf(fnval,"<ERROR:OVERFLOW:\\fcontents()>");
  7877.             debug(F110,"zzstring fcontents(\\%*)",p,0);
  7878.                 }
  7879. #endif /* COMMENT */
  7880.             } else {
  7881.                 if (isupper(c)) c -= ('a'-'A');
  7882.                 p = g_var[c];           /* Letter for global variable */
  7883.             }
  7884.             if (!p) p = "";
  7885.             goto fnend;
  7886.         } else if (c == '&') {          /* Array reference. */
  7887.             int vbi, d;
  7888.             if (arraynam(p,&vbi,&d) < 0) { /* Get name and subscript */
  7889.                 failed = 1;
  7890.                 p = fnval;
  7891.                 if (fndiags)
  7892.                   sprintf(fnval,"<ERROR:ARG_BAD_ARRAY:\\fcontents()>");
  7893.                 goto fnend;
  7894.             }
  7895.             if (chkarray(vbi,d) > 0) {  /* Array is declared? */
  7896.                 vbi -= ARRAYBASE;       /* Convert name to index */
  7897.                 if (a_dim[vbi] >= d) {  /* If subscript in range */
  7898.                     char **ap;
  7899.                     ap = a_ptr[vbi];    /* get data pointer */
  7900.                     if (ap) {           /* and if there is one */
  7901.                         p = ap[d];
  7902.                         goto fnend;
  7903.                     }
  7904.                 }
  7905.             } else {
  7906.                 failed = 1;
  7907.                 p = fnval;
  7908.                 if (fndiags)
  7909.                   sprintf(fnval,"<ERROR:ARG_NOT_ARRAY:\\fcontents()>");
  7910.                 goto fnend;
  7911.             }
  7912.         } else {
  7913.             failed = 1;
  7914.             p = fnval;
  7915.             if (fndiags)
  7916.               sprintf(fnval,"<ERROR:ARG_NOT_VARIABLE:\\fcontents()>");
  7917.             goto fnend;
  7918.         }
  7919.     }
  7920.     p = fnval;                          /* Default result pointer */
  7921.     fnval[0] = NUL;                     /* Default result = empty string */
  7922.  
  7923.  
  7924.     for (i = 0; i < argn; i++) {        /* Loop to expand each argument */
  7925.         n = MAXARGLEN;                  /* Allow plenty of space */
  7926.         bp[i] = s = malloc(n+1);        /* Allocate space for this argument */
  7927.         if (bp[i] == NULL) {            /* Handle failure to get space */
  7928.             failed = 1;
  7929.             if (fndiags)
  7930.               ckmakmsg(fnval,FNVALL,"<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  7931.             goto fnend;
  7932.         }
  7933.         p = argp[i] ? argp[i] : "";     /* Point to this argument */
  7934.  
  7935. /*
  7936.   Trim leading and trailing spaces from the original argument, before
  7937.   evaluation.  This code new to edit 184.  Fixed in edit 199 to trim
  7938.   blanks BEFORE stripping braces.
  7939.  
  7940. */
  7941.         {
  7942.             int x, j;
  7943.             x = strlen(p);
  7944.             j = x - 1;                  /* Trim trailing whitespace */
  7945.             while (j > 0 && (*(p + j) == SP || *(p + j) == HT))
  7946.               *(p + j--) = NUL;
  7947.             while (*p == SP || *p == HT) /* Strip leading whitespace */
  7948.               p++;
  7949.             x = strlen(p);
  7950.             if (*p == '{' && *(p+x-1) == '}') { /* NOW strip braces */
  7951.                 p[x-1] = NUL;
  7952.                 p++;
  7953.                 x -= 2;
  7954.             }
  7955.         }
  7956.  
  7957. /* Now evaluate the argument */
  7958.  
  7959.         debug(F111,"fneval calling zzstring",p,n);
  7960.         t = zzstring(p,&s,&n);          /* Expand arg into new space */
  7961.         debug(F101,"fneval zzstring","",t);
  7962.         debug(F101,"fneval zzstring","",n);
  7963.         if (t < 0) {
  7964.             debug(F101,"fneval zzstring fails, arg","",i);
  7965.             failed = 1;
  7966.             if (fndiags) {
  7967.                 if (n == 0)
  7968.                   ckmakmsg(fnval,FNVALL,
  7969.                            "<ERROR:ARG_TOO_LONG:\\f",fn,"()>",NULL);
  7970.                 else
  7971.                   ckmakmsg(fnval,FNVALL,
  7972.                            "<ERROR:ARG_EVAL_FAILURE:\\f",fn,"()>",NULL);
  7973.             }
  7974.             goto fnend;
  7975.         }
  7976.         debug(F111,"fneval arg",bp[i],i);
  7977.     }
  7978.  
  7979. #ifdef DEBUG
  7980.     if (deblog) {
  7981.         int j;
  7982.         for (j = 0; j < argn; j++) {
  7983.             debug(F111,"fneval arg post eval",argp[j],j);
  7984.             debug(F111,"fneval evaluated arg",bp[j],j);
  7985.         }
  7986.     }
  7987. #endif /* DEBUG */
  7988. /*
  7989.   From this point on, bp[0..argn-1] are not NULL and all must be freed
  7990.   before returning.
  7991. */
  7992.     if (argn < 1) {                     /* Catch required args missing */
  7993.         switch (cx) {
  7994.           case FN_DEF:
  7995.           case FN_EVA:
  7996.           case FN_EXE:
  7997.           case FN_CHR:
  7998.           case FN_COD:
  7999.           case FN_MAX:
  8000.           case FN_MIN:
  8001.           case FN_MOD:
  8002.           case FN_FD:
  8003.           case FN_FS:
  8004.           case FN_TOD:
  8005.           case FN_FFN:
  8006.           case FN_BSN:
  8007.           case FN_RAW:
  8008.           case FN_CMD:
  8009.           case FN_2HEX:
  8010.           case FN_2OCT:
  8011.           case FN_DNAM:
  8012. #ifdef FN_ERRMSG
  8013.           case FN_ERRMSG:
  8014. #endif /* FN_ERRMSG */
  8015. #ifdef CK_KERBEROS
  8016.           case FN_KRB_TK:
  8017.           case FN_KRB_NX:
  8018.           case FN_KRB_IV:
  8019.           case FN_KRB_TT:
  8020.           case FN_KRB_FG:
  8021. #endif /* CK_KERBEROS */
  8022.           case FN_MJD2:
  8023.           case FN_N2TIM:
  8024.           case FN_DIM:
  8025.           case FN_DATEJ:
  8026.           case FN_PNCVT:
  8027.           case FN_PERM:
  8028.           case FN_ALOOK:
  8029.           case FN_TLOOK:
  8030.           case FN_ABS:
  8031.           case FN_AADUMP:
  8032.           case FN_JOIN:
  8033. #ifdef CKFLOAT
  8034.           case FN_FPABS:
  8035.           case FN_FPEXP:
  8036.           case FN_FPLOG:
  8037.           case FN_FPLN:
  8038.           case FN_FPMOD:
  8039.           case FN_FPSQR:
  8040.           case FN_FPADD:
  8041.           case FN_FPDIV:
  8042.           case FN_FPMUL:
  8043.           case FN_FPPOW:
  8044.           case FN_FPSUB:
  8045.           case FN_FPINT:
  8046.           case FN_FPROU:
  8047.           case FN_FPSIN:
  8048.           case FN_FPCOS:
  8049.           case FN_FPTAN:
  8050. #endif /* CKFLOAT */
  8051. #ifdef TCPSOCKET
  8052.           case FN_HSTADD:
  8053.           case FN_HSTNAM:
  8054. #endif /* TCPSOCKET */
  8055.           case FN_DELSEC:
  8056.           case FN_KWVAL:
  8057. #ifdef COMMENT
  8058.           case FN_SLEEP:
  8059.           case FN_MSLEEP:
  8060. #endif /* COMMENT */
  8061. #ifdef NT
  8062.           case FN_SNAME:
  8063.           case FN_LNAME:
  8064. #endif /* NT */
  8065.             failed = 1;
  8066.             p = fnval;
  8067.             if (fndiags)
  8068.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  8069.             goto fnend;
  8070.         }
  8071.     }
  8072.     p = fnval;                          /* Reset these again. */
  8073.     fnval[0] = NUL;
  8074.  
  8075.     switch (cx) {                       /* Do function on expanded args. */
  8076. #ifdef TCPSOCKET
  8077.       case FN_HSTADD:
  8078.         p = ckaddr2name(bp[0]);
  8079.         goto fnend;
  8080.       case FN_HSTNAM:
  8081.         p = ckname2addr(bp[0]);
  8082.         goto fnend;
  8083. #endif /* TCPSOCKET */
  8084.  
  8085.       case FN_DEF:                      /* \fdefinition(arg1) */
  8086.         k = isaarray(bp[0]) ?
  8087.         mxxlook(mactab,bp[0],nmac) :
  8088.         mxlook(mactab,bp[0],nmac);
  8089.         p = (k > -1) ? mactab[k].mval : "";
  8090.         goto fnend;
  8091.  
  8092.       case FN_EVA:                      /* \fevaluate(arg1) */
  8093.         p = *(bp[0]) ? evalx(bp[0]) : "";
  8094.         if (!*p && fndiags) {
  8095.             failed = 1;
  8096.             p = fnval;
  8097.             evalerr(fn);
  8098.         }
  8099.         goto fnend;
  8100.  
  8101.       case FN_EXE:                      /* \fexecute(arg1) */
  8102.         j = (int)strlen(s = bp[0]);     /* Length of macro invocation */
  8103.         p = "";                         /* Initialize return value to null */
  8104.         if (j) {                        /* If there is a macro to execute */
  8105.             while (*s == SP) s++,j--;   /* strip leading spaces */
  8106.             p = s;                      /* remember beginning of macro name */
  8107.             for (i = 0; i < j; i++) {   /* find end of macro name */
  8108.                 if (*s == SP)
  8109.                   break;
  8110.                 s++;
  8111.             }
  8112.             if (*s == SP)       {       /* if there was a space after */
  8113.                 *s++ = NUL;             /* terminate the macro name */
  8114.                 while (*s == SP) s++;   /* skip past any extra spaces */
  8115.             } else
  8116.               s = "";                   /* maybe there are no arguments */
  8117.             if (p && *p) {
  8118.                 k = mlook(mactab,p,nmac); /* Look up the macro name */
  8119.                 debug(F111,"fexec mlook",p,k);
  8120.             } else
  8121.               k = -1;
  8122.             if (k < 0) {
  8123.                 char * p2 = p;
  8124.                 failed = 1;
  8125.                 p = fnval;
  8126.                 if (fndiags)
  8127.                   ckmakxmsg(fnval,FNVALL,
  8128.                             "<ERROR:NO_SUCH_MACRO:\\f",fn,"(",p2,")>",
  8129.                             NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  8130.                 goto fnend;
  8131.             }
  8132. /*
  8133.   This is just a WEE bit dangerous because we are copying up to 9 arguments
  8134.   into the space reserved for one.  It won't overrun the buffer, but if there
  8135.   are lots of long arguments we might lose some.  The other problem is that if
  8136.   the macro has more than 3 arguments, the 4th through last are all
  8137.   concatenated onto the third.  (The workaround is to use spaces rather than
  8138.   commas to separate them.)  Leaving it like this to avoid having to allocate
  8139.   tons more buffers.
  8140. */
  8141.             if (argn > 1) {             /* Commas used instead of spaces */
  8142.                 int i;
  8143.                 char *p = bp[0];        /* Reuse this space */
  8144.                 *p = NUL;               /* Make into dodo() arg list */
  8145.                 for (i = 1; i < argn; i++) {
  8146.                     strncat(p,bp[i],MAXARGLEN);
  8147.                     strncat(p," ",MAXARGLEN);
  8148.                 }
  8149.                 s = bp[0];              /* Point to new list */
  8150.             }
  8151.             p = "";                     /* Initialize return value */
  8152.             if (k >= 0) {               /* If macro found in table */
  8153.                 /* Go set it up (like DO cmd) */
  8154.                 if ((j = dodo(k,s,cmdstk[cmdlvl].ccflgs)) > 0) {
  8155.                     if (cmpush() > -1) { /* Push command parser state */
  8156.                         extern int ifc;
  8157.                         int ifcsav = ifc; /* Push IF condition on stack */
  8158.                         k = parser(1);  /* Call parser to execute the macro */
  8159.                         cmpop();        /* Pop command parser */
  8160.                         ifc = ifcsav;   /* Restore IF condition */
  8161.                         if (k == 0) {   /* No errors, ignore action cmds. */
  8162.                             p = mrval[maclvl+1]; /* If OK, set return value. */
  8163.                             if (p == NULL) p = "";
  8164.                         }
  8165.                     } else {            /* Can't push any more */
  8166.                         debug(F100,"zzstring fneval fexec failure","",0);
  8167.                         printf("\n?\\fexec() too deeply nested\n");
  8168.                         while (cmpop() > -1) ;
  8169.                         p = "";
  8170.                     }
  8171.                 }
  8172.             }
  8173.         }
  8174.         debug(F110,"zzstring fneval fexecute final p",p,0);
  8175.         goto fnend;
  8176.  
  8177. #ifdef RECURSIVE
  8178.       case FN_RDIR:                     /* \frdir..() - Recursive dir count */
  8179.       case FN_RFIL:                     /* \frfiles() - Recursive file count */
  8180.         /* recursive = 2; */            /* fall thru... */
  8181. #endif /* RECURSIVE */
  8182.       case FN_FC:                       /* \ffiles() - File count. */
  8183.       case FN_DIR: {                    /* \ffdir.() - Directory count. */
  8184.           char abuf[16], *s;
  8185.           char ** ap = NULL;
  8186.           int x, xflags = 0;
  8187.           if (matchdot)
  8188.             xflags |= ZX_MATCHDOT;
  8189.           if (cx == FN_RDIR || cx == FN_RFIL) {
  8190.               xflags |= ZX_RECURSE;
  8191. #ifdef CKSYMLINK
  8192.               /* Recursive - don't follow symlinks */
  8193.               xflags |= ZX_NOLINKS;
  8194. #endif /* CKSYMLINK */
  8195.           }
  8196.           failed = 0;
  8197.           if (argn < 1) {
  8198.               p = "0";
  8199.               goto fnend;
  8200.           }
  8201.           if (cx == FN_DIR || cx == FN_RDIR) { /* Only list directories */
  8202.               xflags |= ZX_DIRONLY;
  8203. #ifdef OS2
  8204.               zxpn = 1;                 /* Use the alternate list */
  8205. #endif /* OS2 */
  8206.           } else {                      /* List only files */
  8207.               xflags |= ZX_FILONLY;
  8208. #ifdef OS2
  8209.               zxpn = 1;                 /* Use the alternate list */
  8210. #endif /* OS2 */
  8211.           }
  8212.           if (*(bp[0])) {
  8213.               k = nzxpand(bp[0],xflags);
  8214.               if (k < 0) k = 0;
  8215.               sprintf(fnval,"%d",k);    /* SAFE */
  8216.               p = fnval;
  8217.           } else
  8218.             p = "0";
  8219.  
  8220.           if (argn > 1) {               /* Assign list to array */
  8221.               fnval[0] = NUL;           /* Initial return value */
  8222.               ckstrncpy(abuf,bp[1],16); /* Get array reference */
  8223.               s = abuf;
  8224.               if (*s == CMDQ) s++;
  8225.               failed = 1;               /* Assume it's bad */
  8226.               p = fnval;                /* Point to result */
  8227.               if (fndiags)              /* Default is this error message */
  8228.                 ckmakmsg(fnval,FNVALL,
  8229.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  8230.               if (s[0] != '&')          /* "Address" of array */
  8231.                 goto fnend;
  8232.               if (s[2])
  8233.                 if (s[2] != '[' || s[3] != ']')
  8234.                   goto fnend;
  8235.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  8236.                 s[1] += 32;
  8237.               if ((x = dclarray(s[1],k)) < 0) /* File list plus count */
  8238.                 goto fnend;
  8239.               failed = 0;               /* Unset failure flag */
  8240.               ap = a_ptr[x];            /* Point to array we just declared */
  8241.               sprintf(fnval,"%d",k);    /* SAFE */
  8242.           }
  8243. #ifdef OS2
  8244.           if (ap) {                     /* We are making an array */
  8245.               int i;
  8246.               char tmp[16];
  8247.               ap[0] = NULL;             /* Containing number of files    */
  8248.               makestr(&(ap[0]),ckitoa(k));
  8249.  
  8250.               ckstrncpy(tmp,fnval,16);  /* Save return value */
  8251.  
  8252.               for (i = 1; i <= k; i++) { /* Fill it */
  8253.                   ap[i] = NULL;
  8254.                   znext(fnval);         /* Next filename */
  8255.                   if (!*fnval)          /* No more, done */
  8256.                     break;              /* In case a premature end */
  8257.                   makestr(&(ap[i]),fnval);
  8258.               }
  8259. #ifdef ZXREWIND
  8260.               k = zxrewind();           /* Reset the file expansion */
  8261. #else
  8262.               k = nzxpand(bp[0],xflags);
  8263. #endif /* ZXREWIND */
  8264.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8265.           }
  8266. #else /* OS2 */
  8267.           {                             /* Make copies of the list */
  8268.               int i; char tmp[16];
  8269.               if (flist) {              /* Free old file list, if any */
  8270.                   for (i = 0; flist[i]; i++) { /* and each string */
  8271.                       free(flist[i]);
  8272.                       flist[i] = NULL;
  8273.                   }
  8274.                   free((char *)flist);
  8275.               }
  8276.               ckstrncpy(tmp,fnval,16);  /* Save our return value */
  8277.               flist = (char **) malloc((k+1) * sizeof(char *)); /* New array */
  8278.               if (flist) {
  8279.                   for (i = 0; i <= k; i++) { /* Fill it */
  8280.                       flist[i] = NULL;
  8281.                       znext(fnval);     /* Next filename */
  8282.                       if (!*fnval)      /* No more, done */
  8283.                         break;
  8284.                       makestr(&(flist[i]),fnval);
  8285.                   }
  8286.                   if (ap) {             /* If array pointer given */
  8287.                       ap[0] = NULL;
  8288.                       makestr(&(ap[0]),ckitoa(k));
  8289.                       for (i = 0; i < k; i++) { /* Copy file list to array */
  8290.                           ap[i+1] = NULL;
  8291.                           makestr(&(ap[i+1]),flist[i]);
  8292.                       }
  8293.                   }
  8294.               }
  8295.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8296.               flistn = 0;               /* Reset global list pointer */
  8297.           }
  8298. #endif /* OS2 */
  8299. #ifdef RECURSIVE
  8300.           recursive = rsave;
  8301. #endif /* RECURSIVE */
  8302. #ifdef OS2
  8303.           zxpn = zsave;
  8304. #endif /* OS2 */
  8305.       }
  8306.       goto fnend;
  8307.  
  8308.       case FN_FIL:                      /* \fnextfile() - Next file in list. */
  8309.         p = fnval;                      /* (no args) */
  8310.         *p = NUL;
  8311. #ifdef OS2
  8312.         zxpn = 1;                       /* OS/2 - use the alternate list */
  8313.         znext(p);                       /* Call system-dependent function */
  8314.         zxpn = zsave;                   /* Restore original list */
  8315. #else
  8316.         if (flist)                      /* Others, use our own list. */
  8317.           if (flist[flistn])
  8318.             p = flist[flistn++];
  8319. #endif /* OS2 */
  8320.         goto fnend;
  8321.  
  8322.     } /* Break up big switch... */
  8323.  
  8324.     switch (cx) {
  8325.       case FN_IND:                      /* \findex(s1,s2,start) */
  8326.       case FN_RIX:                      /* \frindex(s1,s2,start) */
  8327.       case FN_SEARCH:                   /* \fsearch(pat,string,start) */
  8328.       case FN_RSEARCH: {                /* \frsearch(pat,string,start) */
  8329.         int i = 0, right = 0, search = 0;
  8330.         right = (cx == FN_RIX || cx == FN_RSEARCH);
  8331.         search = (cx == FN_SEARCH || cx == FN_RSEARCH);
  8332.         p = "0";
  8333.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8334.             int start = 0;
  8335.             char * pat = NULL;
  8336.             len1 = (int)strlen(pat = bp[0]); /* length of string to look for */
  8337.             len2 = (int)strlen(s = bp[1]); /* length of string to look in */
  8338.             if (len1 < 1 || len2 < 1)   /* Watch out for empty strings */
  8339.               goto fnend;
  8340.             start = right ? -1 : 0;     /* Default starting position */
  8341.             if (argn > 2) {
  8342.                 val1 = *(bp[2]) ? evalx(bp[2]) : "1";
  8343.                 if (chknum(val1)) {
  8344.                     int t;
  8345.                     t = atoi(val1);
  8346.                     if (!search) {      /* Index or Rindex */
  8347.                         j = len2 - len1; /* Length difference */
  8348.                         t--;             /* Convert position to 0-based */
  8349.                         if (t < 0) t = 0;
  8350.                         start = t;
  8351.                         if (!right && start < 0) start = 0;
  8352.                     } else {            /* Search or Rsearch */
  8353.                         int x;
  8354.                         if (t < 0) t = 0;
  8355.                         if (right) {    /* Right to left */
  8356.                             if (t > len2) t = len2;
  8357.                             start = len2 - t - 1;
  8358.                             if (start < 0)
  8359.                               goto fnend;
  8360.                             x = len2 - t;
  8361.                             s[x] = NUL;
  8362.                         } else {        /* Left to right */
  8363.                             start = t - 1;
  8364.                             if (start < 0) start = 0;
  8365.                             if (start >= len2)
  8366.                               goto fnend;
  8367.                         }
  8368.                     }
  8369.                 } else {
  8370.                     failed = 1;
  8371.                     evalerr(fn);
  8372.                     p = fnval;
  8373.                     goto fnend;
  8374.                 }
  8375.             }
  8376.             if (search) {               /* \fsearch() or \frsearch() */
  8377.                 if (right && pat[0] == '^') {
  8378.                     right = 0;
  8379.                     start = 0;
  8380.                 }
  8381.                 if (right) {
  8382.                     if (start < 0) start = len2 - 1;
  8383.                     for (i = start;
  8384.                          i >= 0 && !ckmatch(pat,s+i,inpcas[cmdlvl],1+4);
  8385.                          i--) ;
  8386.                     if (i < 0) i = 0; else i++;
  8387.                 } else {
  8388.                     i = ckmatch(pat,&s[start],inpcas[cmdlvl],1+4);
  8389.                     if (start > 0) i += start;
  8390.                 }
  8391.             } else {
  8392.                 i = ckindex(pat,bp[1],start,right,inpcas[cmdlvl]);
  8393.             }
  8394.             sprintf(fnval,"%d",i);      /* SAFE */
  8395.             p = fnval;
  8396.         }
  8397.         goto fnend;
  8398.       }
  8399.  
  8400.       case FN_RPL:                      /* \freplace(s1,s2,s3) */
  8401.       /*
  8402.         s = bp[0] = source string
  8403.             bp[1] = match string
  8404.             bp[2] = replacement string
  8405.             bp[3] = which occurrence (default = all);
  8406.         p = fnval = destination (result) string
  8407.       */
  8408.         if (argn < 1)                   /* Nothing */
  8409.           goto fnend;
  8410.         if (argn < 2) {                 /* Only works if we have 2 or 3 args */
  8411.             ckstrncpy(p,bp[0],FNVALL);
  8412.         } else {
  8413.             int occur = 0, xx = 0, j2;
  8414.             len1 = (int)strlen(bp[0]);  /* length of string to look in */
  8415.             len2 = (int)strlen(bp[1]);  /* length of string to look for */
  8416.             len3 = (argn < 3) ? 0 : (int)strlen(bp[2]); /* Len of replacemnt */
  8417.             j = len1 - len2 + 1;
  8418.             j2 = j;
  8419.             if (argn > 3) {
  8420.                 if (chknum(bp[3])) {
  8421.                     occur = atoi(bp[3]);
  8422.                 } else {
  8423.                     failed = 1;
  8424.                     if (fndiags)
  8425.                       ckmakmsg(fnval,FNVALL,
  8426.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8427.                     goto fnend;
  8428.                 }
  8429.             }
  8430.             /* If args out of whack... */
  8431.             if (j < 1 || len1 == 0 || len2 == 0) {
  8432.                 ckstrncpy(p,bp[0],FNVALL); /* just return original string */
  8433.                 p[FNVALL] = NUL;
  8434.             } else {
  8435.               ragain:
  8436.                 s = bp[0];              /* Point to beginning of string */
  8437.                 while (j-- > 0) {       /* For each character */
  8438.                     if (!ckstrcmp(bp[1],s,len2,inpcas[cmdlvl]) &&
  8439.                         (occur == 0 || occur == ++xx)) {
  8440.                         if (len3) {
  8441.                             ckstrncpy(p,bp[2],FNVALL);
  8442.                             p += len3;
  8443.                         }
  8444.                         s += len2;      /* and skip past it. */
  8445.                     } else {            /* No, */
  8446.                         *p++ = *s++;    /* just copy this character */
  8447.                     }
  8448.                 }
  8449.                 *p = NUL;
  8450.                 while ((*p++ = *s++));
  8451.                 if (occur < 0) {        /* cheap... */
  8452.                     occur = xx + occur + 1;
  8453.                     xx = 0;
  8454.                     p = fnval;
  8455.                     j = j2;
  8456.                     if (occur > 0)
  8457.                       goto ragain;
  8458.                 }
  8459.             }
  8460.         }
  8461.         p = fnval;
  8462.         goto fnend;
  8463.  
  8464.       case FN_CHR:                      /* \fcharacter(arg1) */
  8465.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8466.         if (chknum(val1)) {             /* Must be numeric */
  8467.             i = atoi(val1);
  8468.             if (i >= 0 && i < 256) {    /* Must be an 8-bit value */
  8469.                 p = fnval;
  8470.                 *p++ = (char) i;
  8471.                 *p = NUL;
  8472.                 p = fnval;
  8473.             } else {
  8474.                 failed = 1;
  8475.                 if (fndiags)
  8476.                   ckmakmsg(fnval,FNVALL,
  8477.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  8478.             }
  8479.         } else {
  8480.             failed = 1;
  8481.             evalerr(fn);
  8482.         }
  8483.         goto fnend;
  8484.  
  8485.       case FN_COD:                      /* \fcode(char) */
  8486.         if ((int)strlen(bp[0]) > 0) {
  8487.             p = fnval;
  8488.             i = *bp[0];
  8489.             sprintf(p,"%d",(i & 0xff)); /* SAFE */
  8490.         } else p = "0";            /* Can't happen */
  8491.         goto fnend;
  8492.  
  8493.       case FN_LEN:                      /* \flength(arg1) */
  8494.         if (argn > 0) {
  8495.             p = fnval;
  8496.             sprintf(p,"%d",(int)strlen(bp[0])); /* SAFE */
  8497.         } else p = "0";
  8498.         goto fnend;
  8499.  
  8500.       case FN_LOW:                      /* \flower(arg1) */
  8501.         s = bp[0] ? bp[0] : "";
  8502.         p = fnval;
  8503.         while (*s) {
  8504.             if (isupper(*s))
  8505.               *p = (char) tolower(*s);
  8506.             else
  8507.               *p = *s;
  8508.             p++; s++;
  8509.         }
  8510.         *p = NUL;
  8511.         p = fnval;
  8512.         goto fnend;
  8513.  
  8514.       case FN_MAX:                      /* \fmax(arg1,arg2) */
  8515.       case FN_MIN:                      /* \fmin(arg1,arg2) */
  8516.       case FN_MOD:                      /* \fmod(arg1,arg2) */
  8517.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8518. #ifdef COMMENT
  8519.         /* No longer necessary because evalx() no longer overwrites its */
  8520.         /* result every time it's called (2000/09/23). */
  8521.         free(bp[0]);
  8522.         bp[0] = NULL;
  8523. #endif /* COMMENT */
  8524.         if (argn > 1) {
  8525. #ifdef COMMENT
  8526.             /* Ditto... */
  8527.             bp[0] = malloc((int)strlen(val1)+1);
  8528.             if (bp[0])
  8529.               strcpy(bp[0],val1);       /* safe */
  8530.             val1 = bp[0];
  8531. #endif /* COMMENT */
  8532.             val2 = *(bp[1]) ? evalx(bp[1]) : "";
  8533.             if (chknum(val1) && chknum(val2)) {
  8534.                 i = atoi(val1);
  8535.                 j = atoi(val2);
  8536.                 switch (y) {
  8537.                   case FN_MAX:
  8538.                     if (j < i) j = i;
  8539.                     break;
  8540.                   case FN_MIN:
  8541.                     if (j > i) j = i;
  8542.                     break;
  8543.                   case FN_MOD:
  8544.                     if (j == 0) {
  8545.                         failed = 1;
  8546.                         if (fndiags)
  8547.                           ckmakmsg(fnval,FNVALL,
  8548.                                    "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  8549.                         else
  8550.                           fnval[0] = NUL;
  8551.                         goto fnend;
  8552.                     } else
  8553.                       j = i % j;
  8554.                 }
  8555.                 p = fnval;
  8556.                 sprintf(p,"%d",j);      /* SAFE */
  8557.             } else {
  8558.                 failed = 1;
  8559.                 evalerr(fn);
  8560.             }
  8561.         } else p = val1;
  8562.         goto fnend;
  8563.     } /* Break up big switch... */
  8564.  
  8565.     switch (y) {
  8566.       case FN_SUB:                      /* \fsubstr(arg1,arg2,arg3) */
  8567.       case FN_RIG:                      /* \fright(arg1,arg2) */
  8568.       case FN_LEF:                      /* \fleft(arg1,arg2) */
  8569.         if (argn < 1)
  8570.           goto fnend;
  8571.         val1 = "";
  8572.         if (argn > 1)
  8573.           if (*(bp[1]))
  8574.             val1 =  evalx(bp[1]);
  8575. #ifdef COMMENT
  8576.         if (bp[1]) free(bp[1]);         /* Have to copy this */
  8577.         bp[1] = malloc((int)strlen(val1)+1);
  8578.         if (!bp[1]) {
  8579.             failed = 1;
  8580.             if (fndiags) {
  8581.                 p = fnval;
  8582.                 ckmakmsg(fnval,FNVALL,
  8583.                          "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  8584.             }
  8585.             goto fnend;
  8586.         }
  8587.         strcpy(bp[1],val1);             /* safe */
  8588.         val1 = bp[1];
  8589. #endif /* COMMENT */
  8590.         val2 = "";
  8591.         if (argn > 2)
  8592.           if (*(bp[2]))
  8593.             val2 = evalx(bp[2]);
  8594.         if (
  8595.             ((argn > 1) && (int)strlen(val1) && !rdigits(val1)) ||
  8596.             ((cx == FN_SUB) &&
  8597.               ((argn > 2) && (int)strlen(val2) && !rdigits(val2)))
  8598.             ) {
  8599.             failed = 1;
  8600.             evalerr(fn);
  8601.         } else {
  8602.             int lx;
  8603.             p = fnval;                  /* pointer to result */
  8604.             lx = strlen(bp[0]);         /* length of arg1 */
  8605.             if (cx == FN_SUB) {         /* substring */
  8606.                 k = (argn > 2) ? atoi(val2) : MAXARGLEN; /* length */
  8607.                 j = (argn > 1) ? atoi(val1) : 1; /* start pos for substr */
  8608.             } else if (cx == FN_LEF) {  /* left */
  8609.                 k = (argn > 1) ? atoi(val1) : lx;
  8610.                 j = 1;
  8611.             } else {                             /* right */
  8612.                 k = (argn > 1) ? atoi(val1) : lx; /* length */
  8613.                 j = lx - k + 1;                  /* start pos for right */
  8614.                 if (j < 1) j = 1;
  8615.             }
  8616.             if (k > 0 && j <= lx) {              /* if start pos in range */
  8617.                 s = bp[0]+j-1;                   /* point to source string */
  8618.                 for (i = 0; (i < k) && (*p++ = *s++); i++) ;  /* copy */
  8619.             }
  8620.             *p = NUL;                   /* terminate the result */
  8621.             p = fnval;                  /* and point to it. */
  8622.         }
  8623.         goto fnend;
  8624.  
  8625.       case FN_UPP:                      /* \fupper(arg1) */
  8626.         s = bp[0] ? bp[0] : "";
  8627.         p = fnval;
  8628.         while (*s) {
  8629.             if (islower(*s))
  8630.               *p = (char) toupper(*s);
  8631.             else
  8632.               *p = *s;
  8633.             p++; s++;
  8634.         }
  8635.         *p = NUL;
  8636.         p = fnval;
  8637.         goto fnend;
  8638.  
  8639.       case FN_REP:                      /* \frepeat(text,number) */
  8640.         if (argn < 1)
  8641.           goto fnend;
  8642.         val1 = "1";
  8643.         if (argn > 1)
  8644.           if (*(bp[1]))
  8645.             val1 = evalx(bp[1]);
  8646.         if (chknum(val1)) {             /* Repeat count */
  8647.             n = atoi(val1);
  8648.             debug(F111,"SUNDAY frepeat n",val1,n);
  8649.             if (n > 0) {                /* Make n copies */
  8650.                 p = fnval;
  8651.                 *p = '\0';
  8652.                 k = (int)strlen(bp[0]); /* Make sure string has some length */
  8653.                 debug(F111,"SUNDAY frepeat k","",k);
  8654.                 debug(F111,"SUNDAY frepeat FNVALL","",FNVALL);
  8655.                 if (k * n >= FNVALL) {  /* But not too much... */
  8656.                     failed = 1;
  8657.                     if (fndiags)
  8658.                       ckmakmsg(fnval,FNVALL,
  8659.                                "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  8660.                     else
  8661.                       fnval[0] = NUL;
  8662.                     p = fnval;
  8663.                     goto fnend;
  8664.                 }
  8665.                 if (k > 0) {            /* If there is something to copy */
  8666.                     for (i = 0; i < n; i++) { /* Copy loop */
  8667.                         s = bp[0];
  8668.                         for (j = 0; j < k; j++) {
  8669.                             if ((p - fnval) >= FNVALL)
  8670.                               break;    /* shouldn't happen... */
  8671.                             else
  8672.                               *p++ = *s++;
  8673.                         }
  8674.                     }
  8675.                     *p = NUL;
  8676.                 }
  8677.             }
  8678.         } else {
  8679.             failed = 1;
  8680.             evalerr(fn);
  8681.         }
  8682.         p = fnval;
  8683.         goto fnend;
  8684.  
  8685. #ifndef NOFRILLS
  8686.       case FN_REV:                      /* \freverse() */
  8687.         if (argn < 1)
  8688.           goto fnend;
  8689.         yystring(bp[0],&p);
  8690.         goto fnend;
  8691. #endif /* NOFRILLS */
  8692.  
  8693.       case FN_RPA:                      /* \frpad() and \flpad() */
  8694.       case FN_LPA:
  8695.         if (argn < 1)
  8696.           goto fnend;
  8697.         val1 = "";
  8698.         if (argn > 1)
  8699.           if (*(bp[1]))
  8700.             val1 = evalx(bp[1]);
  8701.         if (argn == 1) {                /* If a number wasn't given */
  8702.             p = fnval;                  /* just return the original string */
  8703.             ckstrncpy(p,bp[0],FNVALL);
  8704.         } else if (argn > 1 &&  !*val1) {
  8705.             failed = 1;
  8706.             evalerr(fn);
  8707.         } else /* if (chknum(val1)) */ { /* Repeat count */
  8708.             char pc;
  8709.             n = atoi(val1);
  8710.             if (n >= 0) {
  8711.                 p = fnval;
  8712.                 k = (int)strlen(bp[0]); /* Length of string to be padded */
  8713.                 if (k >= n) {           /* It's already long enough */
  8714.                     ckstrncpy(p,bp[0],FNVALL);
  8715.                 } else {
  8716.                     if (n + k <= FNVALL) {
  8717.                         pc = (char) ((argn < 3) ? SP : *bp[2]);
  8718.                         if (!pc) pc = SP;
  8719.                         if (cx == FN_RPA) { /* RPAD */
  8720.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8721.                             p[k] = NUL;
  8722.                             p += k;
  8723.                             for (i = k; i < n; i++)
  8724.                               *p++ = pc;
  8725.                         } else {        /* LPAD */
  8726.                             n -= k;
  8727.                             for (i = 0; i < n; i++)
  8728.                               *p++ = pc;
  8729.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8730.                             p[k] = NUL;
  8731.                             p += k;
  8732.                         }
  8733.                     }
  8734.                     *p = NUL;
  8735.                 }
  8736.             }
  8737.         }
  8738.         p = fnval;
  8739.         goto fnend;
  8740.  
  8741. #ifdef ZFCDAT
  8742.       case FN_FD:                       /* \fdate(filename) */
  8743.         p = fnval;
  8744.         s = zfcdat(bp[0]);
  8745.         if (!s) s = "";
  8746.         if (!*s) {
  8747.             failed = 1;
  8748.             if (fndiags)
  8749.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8750.             goto fnend;
  8751.         }
  8752.         ckstrncpy(fnval,s,FNVALL);
  8753. #endif /* ZFCDAT */
  8754.         goto fnend;
  8755.  
  8756.     } /* Break up big switch... */
  8757.  
  8758.     switch (y) {
  8759.       case FN_FS:                       /* \fsize(filename) */
  8760.         p = fnval;
  8761.         z = zchki(bp[0]);
  8762.         if (z < 0) {
  8763.             failed = 1;
  8764.             if (fndiags) {
  8765.                 if (z == -1)
  8766.                   ckmakmsg(fnval,FNVALL,
  8767.                            "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8768.                 else if (z == -2)
  8769.                   ckmakmsg(fnval,FNVALL,
  8770.                            "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  8771.                 else if (z == -3)
  8772.                   ckmakmsg(fnval,FNVALL,
  8773.                            "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  8774.                 else
  8775.                   ckmakmsg(fnval,FNVALL,
  8776.                            "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  8777.             }
  8778.             goto fnend;
  8779.         }
  8780.         sprintf(fnval,"%ld",z);         /* SAFE */
  8781.         goto fnend;
  8782.  
  8783.       case FN_VER:                      /* \fverify() */
  8784.     p = "-1";
  8785.     if (argn == 1)            /* No second arg */
  8786.       goto fnend;
  8787.     else if (!bp[1])        /* Or second arg null */
  8788.       goto fnend;
  8789.     else if (!*(bp[1]))        /* or empty. */
  8790.       goto fnend;
  8791.         p = "0";
  8792.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8793.             int start;
  8794.             char *s2, ch1, ch2;
  8795.             start = 0;
  8796.             if (argn > 2) {             /* Starting position specified */
  8797.                 val1 = *(bp[2]) ? evalx(bp[2]) : "0";
  8798.                 if (chknum(val1)) {
  8799.                     start = atoi(val1) /* - 1 */;
  8800.                     if (start < 0) start = 0;
  8801.                     if (start > (int)strlen(bp[1]))
  8802.                       goto verfin;
  8803.                 } else {
  8804.                     failed = 1;
  8805.                     evalerr(fn);
  8806.                     goto fnend;
  8807.                 }
  8808.             }
  8809.             i = start;
  8810.             p = "0";
  8811.             for (s = bp[1] + start; *s; s++,i++) {
  8812.                 ch1 = *s;
  8813.                 if (!inpcas[cmdlvl]) if (islower(ch1)) ch1 = toupper(ch1);
  8814.                 j = 0;
  8815.                 for (s2 = bp[0]; *s2; s2++) {
  8816.                     ch2 = *s2;
  8817.                     if (!inpcas[cmdlvl]) if (islower(ch2)) ch2 = toupper(ch2);
  8818.                     if (ch1 == ch2) {
  8819.                         j = 1;
  8820.                         break;
  8821.                     }
  8822.                 }
  8823.                 if (j == 0) {
  8824.                     sprintf(fnval,"%d",i+1); /* SAFE */
  8825.                     p = fnval;
  8826.                     break;
  8827.                 }
  8828.             }
  8829.         }
  8830.       verfin:
  8831.         goto fnend;
  8832.  
  8833.       case FN_IPA:                      /* Find and return IP address */
  8834.         if (argn > 0) {                 /* in argument string. */
  8835.             int start = 0;
  8836.             if (argn > 1) {             /* Starting position specified */
  8837.                 if (chknum(bp[1])) {
  8838.                     start = atoi(bp[1]) - 1;
  8839.                     if (start < 0) start = 0;
  8840.                 } else {
  8841.                     failed = 1;
  8842.                     if (fndiags)
  8843.                       ckmakmsg(fnval,FNVALL,
  8844.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8845.                     goto fnend;
  8846.                 }
  8847.             }
  8848.             p = getip(bp[0]+start);
  8849.         } else p = "";
  8850.         goto fnend;
  8851.  
  8852. #ifdef OS2
  8853.       case FN_CRY:
  8854.         p = "";
  8855.         if (argn > 0) {
  8856.             p = fnval;
  8857.             ckstrncpy(p,bp[0],FNVALL);
  8858.             ck_encrypt(p);
  8859.         }
  8860.         goto fnend;
  8861.  
  8862.       case FN_OOX:
  8863.         p = "";
  8864.         if (argn > 0)
  8865.           p = (char *) ck_oox(bp[0], (argn > 1) ? bp[1] : "");
  8866.         goto fnend;
  8867. #endif /* OS2 */
  8868.  
  8869.       case FN_HEX:                      /* \fhexify(arg1) */
  8870.         if (argn < 1)
  8871.           goto fnend;
  8872.         if ((int)strlen(bp[0]) < (FNVALL / 2)) {
  8873.             s = bp[0];
  8874.             p = fnval;
  8875.             while (*s) {
  8876.                 x = (*s >> 4) & 0x0f;
  8877.                 *p++ = hexdigits[x];
  8878.                 x = *s++ & 0x0f;
  8879.                 *p++ = hexdigits[x];
  8880.             }
  8881.             *p = NUL;
  8882.             p = fnval;
  8883.         }
  8884.         goto fnend;
  8885.  
  8886.       case FN_UNTAB:            /* \funtab(arg1) */
  8887.     if (argn < 1)
  8888.       goto fnend;
  8889.     if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  8890.         s = bp[0];
  8891.         p = fnval;
  8892.         if (untabify(bp[0],p,FNVALL) < 0) {
  8893.         failed = 1;
  8894.         if (fndiags)
  8895.           ckmakmsg(fnval,FNVALL,
  8896.                "<ERROR:OVERFLOW:\\f",fn,"()>",NULL);
  8897.         }
  8898.         goto fnend;
  8899.     }
  8900.  
  8901.       case FN_UNH: {                    /* \funhex(arg1) */
  8902.           int c[2], i;
  8903.           if (argn < 1)
  8904.             goto fnend;
  8905.           if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  8906.               s = bp[0];
  8907.               p = fnval;
  8908.               while (*s) {
  8909.                   for (i = 0; i < 2; i++) {
  8910.                       c[i] = *s++;
  8911.                       if (!c[i]) { p = ""; goto unhexfin; }
  8912.                       if (islower(c[i])) c[i] = toupper(c[i]);
  8913.                       if (c[i] >= '0' && c[i] <= '9') {
  8914.                           c[i] -= 0x30;
  8915.                       } else if (c[i] >= 'A' && c[i] <= 'F') {
  8916.                           c[i] -= 0x37;
  8917.                       } else {
  8918.                           failed = 1;
  8919.                           if (fndiags)
  8920.                             ckmakmsg(fnval,
  8921.                                      FNVALL,
  8922.                                      "<ERROR:ARG_OUT_OF_RANGE:\\f",
  8923.                                      fn,
  8924.                                      "()>",
  8925.                                      NULL
  8926.                                      );
  8927.                           goto fnend;
  8928.                       }
  8929.                   }
  8930.                   *p++ = ((c[0] << 4) & 0xf0) | (c[1] & 0x0f);
  8931.               }
  8932.               *p = NUL;
  8933.               p = fnval;
  8934.           }
  8935.         unhexfin:
  8936.           goto fnend;
  8937.       }
  8938.  
  8939.       case FN_BRK: {                    /* \fbreak() */
  8940.           char * c;                     /* Characters to break on */
  8941.           char c2, s2;
  8942.           int start = 0;
  8943.           int done = 0;
  8944.           if (argn < 1)
  8945.             goto fnend;
  8946.           if (argn > 2) {
  8947.               s = bp[2] ? bp[2] : "0";
  8948.               if (chknum(s)) {
  8949.                   start = atoi(s);
  8950.                   if (start < 0) start = 0;
  8951.                   if (start > (int)strlen(bp[0]))
  8952.                     goto brkfin;
  8953.               } else {
  8954.                   failed = 1;
  8955.                   if (fndiags)
  8956.                     ckmakmsg(fnval,FNVALL,
  8957.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8958.                   goto fnend;
  8959.               }
  8960.           }
  8961.           s = bp[0] + start;            /* Source pointer */
  8962.  
  8963.           while (*s && !done) {
  8964.               s2 = *s;
  8965.               if (!inpcas[cmdlvl] && islower(s2)) s2 = toupper(s2);
  8966.               c = bp[1] ? bp[1] : "";   /* Character to break on */
  8967.               while (*c) {
  8968.                   c2 = *c;
  8969.                   if (!inpcas[cmdlvl] && islower(c2)) c2 = toupper(c2);
  8970.                   if (c2 == s2) {
  8971.                       done = 1;
  8972.                       break;
  8973.                   }
  8974.                   c++;
  8975.               }
  8976.               if (done) break;
  8977.               *p++ = *s++;
  8978.           }
  8979.           *p = NUL;                     /* terminate the result */
  8980.           p = fnval;                    /* and point to it. */
  8981.         brkfin:
  8982.           goto fnend;
  8983.       }
  8984.  
  8985.       case FN_SPN: {                    /* \fspan() */
  8986.           char *q;
  8987.           char c1, c2;
  8988.           int start = 0;
  8989.           if (argn < 1)
  8990.             goto fnend;
  8991.           if (argn > 2) {               /* Starting position */
  8992.               s = bp[2] ? bp[2] : "0";
  8993.               if (chknum(s)) {
  8994.                   start = atoi(s);
  8995.                   if (start < 0) start = 0;
  8996.               } else {
  8997.                   failed = 1;
  8998.                   if (fndiags)
  8999.                     ckmakmsg(fnval,FNVALL,
  9000.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9001.                   goto fnend;
  9002.               }
  9003.           }
  9004.           s = bp[0] + start;            /* Source pointer */
  9005.           if (argn > 1 &&
  9006.               (int)strlen(bp[1]) > 0 &&
  9007.               start <= (int)strlen(bp[0])) {
  9008.               while (*s) {              /* Loop thru source string */
  9009.                   q = bp[1];            /* Span string */
  9010.                   c1 = *s;
  9011.                   if (!inpcas[cmdlvl])
  9012.                     if (islower(c1)) c1 = toupper(c1);
  9013.                   x = 0;
  9014.                   while ((c2 = *q++)) {
  9015.                       if (!inpcas[cmdlvl])
  9016.                         if (islower(c2)) c2 = toupper(c2);
  9017.                       if (c1 == c2) { x = 1; break; }
  9018.                   }
  9019.                   if (!x) break;
  9020.                   *p++ = *s++;
  9021.               }
  9022.               *p = NUL;                 /* Terminate and return the result */
  9023.               p = fnval;
  9024.           }
  9025.           goto fnend;
  9026.       }
  9027.     } /* Break up big switch... */
  9028.  
  9029.     switch (y) {
  9030.       case FN_TRM:                      /* \ftrim(s1[,s2]) */
  9031.       case FN_LTR:                      /* \fltrim(s1[,s2]) */
  9032.         if (argn < 1)
  9033.           goto fnend;
  9034.         if ((len1 = (int)strlen(bp[0])) > 0) {
  9035.             if (len1 > FNVALL)
  9036.               len1 = FNVALL;
  9037.             s = " \t\r\n";
  9038.             if (argn > 1)               /* Trim list given */
  9039.               s = bp[1];
  9040.             len2 = (int)strlen(s);
  9041.             if (len2 < 1) {             /* or not... */
  9042.                 s = " \t\r\n";          /* Default is to trim whitespace */
  9043.                 len2 = 2;
  9044.             }
  9045.             if (cx == FN_TRM) {         /* Trim from right */
  9046.                 char * q, p2, q2;
  9047.                 ckstrncpy(fnval,bp[0],FNVALL); /* Copy string to output */
  9048.                 p = fnval + len1 - 1;   /* Point to last character */
  9049.  
  9050.                 while (p >= (char *)fnval) { /* Go backwards */
  9051.                     q = s;              /* Point to trim list */
  9052.                     p2 = *p;
  9053.                     if (!inpcas[cmdlvl])
  9054.                       if (islower(p2)) p2 = toupper(p2);
  9055.                     while (*q) {        /* Is this char in trim list? */
  9056.                         q2 = *q;
  9057.                         if (!inpcas[cmdlvl])
  9058.                           if (islower(q2)) q2 = toupper(q2);
  9059.                         if (p2 == q2) { /* Yes, null it out */
  9060.                             *p = NUL;
  9061.                             break;
  9062.                         }
  9063.                         q++;
  9064.                     }
  9065.                     if (!*q)            /* Trim list exhausted */
  9066.                       break;            /* So we're done. */
  9067.                     p--;                /* Else keep trimming */
  9068.                 }
  9069.             } else {                    /* Trim from left */
  9070.                 char * q, p2, q2;
  9071.                 p = bp[0];              /* Source */
  9072.                 while (*p) {
  9073.                     p2 = *p;
  9074.                     if (!inpcas[cmdlvl])
  9075.                       if (islower(p2)) p2 = toupper(p2);
  9076.                     q = s;
  9077.                     while (*q) {        /* Is this char in trim list? */
  9078.                         q2 = *q;
  9079.                         if (!inpcas[cmdlvl])
  9080.                           if (islower(q2)) q2 = toupper(q2);
  9081.                         if (p2 == q2) { /* Yes, point past it */
  9082.                             p++;        /* and try next source character */
  9083.                             break;
  9084.                         }
  9085.                         q++;            /* No, try next trim character */
  9086.                     }
  9087.                     if (!*q)            /* Trim list exhausted */
  9088.                       break;            /* So we're done. */
  9089.                 }
  9090.                 ckstrncpy(fnval,p,FNVALL);
  9091.             }
  9092.             p = fnval;
  9093.         } else p = "";
  9094.         goto fnend;
  9095.  
  9096.       case FN_CAP:                      /* \fcapitalize(arg1) */
  9097.         if (argn < 1)
  9098.           goto fnend;
  9099.         s = bp[0];
  9100.         p = fnval;
  9101.         x = 0;
  9102.         while ((c = *s++)) {
  9103.             if (isalpha(c)) {
  9104.                 if (x == 0) {
  9105.                     x = 1;
  9106.                     if (islower(c))
  9107.                       c = toupper(c);
  9108.                 } else if (isupper(c))
  9109.                   c = tolower(c);
  9110.             }
  9111.             *p++ = c;
  9112.         }
  9113.         *p = NUL;
  9114.         p = fnval;
  9115.         goto fnend;
  9116.  
  9117. #ifdef COMMENT
  9118.       case FN_TOD:                      /* Time of day to secs since midnite */
  9119.         sprintf(fnval,"%ld",tod2sec(bp[0])); /* SAFE */
  9120.         goto fnend;
  9121. #endif /* COMMENT */
  9122.  
  9123.       case FN_FFN:                      /* Full pathname of file */
  9124.         zfnqfp(bp[0],FNVALL,p);
  9125.         if (!p) p = "";
  9126.         goto fnend;
  9127.  
  9128.       case FN_CHK: {                    /* \fchecksum() */
  9129.           long chk = 0;
  9130.           p = (argn > 0) ? bp[0] : "";
  9131.           while (*p) chk += *p++;
  9132.           sprintf(fnval,"%lu",chk);     /* SAFE */
  9133.           p = fnval;
  9134.           goto fnend;
  9135.       }
  9136.  
  9137. #ifndef NOXFER
  9138.       case FN_CRC:                      /* \fcrc16() */
  9139.         if (argn > 0)
  9140.           sprintf(fnval,"%u",           /* SAFE */
  9141.                   chk3((CHAR *)bp[0],(int)strlen(bp[0])));
  9142.         else
  9143.           p = "0";
  9144.         goto fnend;
  9145. #endif /* NOXFER */
  9146.  
  9147.       case FN_BSN:                      /* \fbasename() */
  9148.         zstrip(bp[0],&p);
  9149.         goto fnend;
  9150.  
  9151. #ifndef NOLOCAL
  9152. #ifdef OS2
  9153.       case FN_SCRN_CX:                  /* \fscrncurx() */
  9154.         p = fnval;
  9155.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->x); /* SAFE */
  9156.         goto fnend;
  9157.  
  9158.       case FN_SCRN_CY:                  /* \fscrncury() */
  9159.         p = fnval;
  9160.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->y); /* SAFE */
  9161.         goto fnend;
  9162.  
  9163.       case FN_SCRN_STR: {               /* \fscrnstr() */
  9164.           videoline * line = NULL;
  9165.           viocell * cells = NULL;
  9166.           int row = 0, col = 0, len = 0;
  9167.           /* NOTE: On Unicode systems, the screen contents are stored in */
  9168.           /* in Unicode.  Therefore, we should really be performing a    */
  9169.           /* conversion to the local character set.                      */
  9170.  
  9171.           /* 6/18/2000 - added the translation to lcs */
  9172.  
  9173.           if (bp[0] == NULL || bp[0][0] == '\0') {
  9174.               row = 0;
  9175.           } else {
  9176.               if (chknum(bp[0])) {
  9177.                   row = atoi(bp[0]);
  9178.                   if (row < 0)
  9179.                     row = 0;
  9180.               } else {
  9181.                   failed = 1;
  9182.                   if (fndiags)
  9183.                     ckmakmsg(fnval,FNVALL,
  9184.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9185.                   goto fnend;
  9186.               }
  9187.           }
  9188.           line = VscrnGetLineFromTop( VTERM, (USHORT) row );
  9189.           if (line != NULL) {
  9190.               if (bp[1] == NULL || bp[1][0] == '\0')
  9191.                 col = 0;
  9192.               else {
  9193.                   if (chknum(bp[0])) {
  9194.                       col = atoi(bp[1]);
  9195.                       if (col < 0 || col >= line->width)
  9196.                         col = 0;
  9197.                   } else {
  9198.                       failed = 1;
  9199.                       if (fndiags)
  9200.                         ckmakmsg(fnval,FNVALL,
  9201.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9202.                       goto fnend;
  9203.                   }
  9204.               }
  9205.               if (bp[2] == NULL || bp[2][0] == '\0') {
  9206.                   len = line->width - (col+1);
  9207.               } else {
  9208.                   if (!chknum(bp[2])) {
  9209.                       failed = 1;
  9210.                       if (fndiags)
  9211.                         ckmakmsg(fnval,FNVALL,
  9212.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9213.                       goto fnend;
  9214.                   }
  9215.                   len = atoi(bp[2]);
  9216.                   if (len < 0 || len > line->width)
  9217.                     len = line->width;
  9218.               }
  9219.               cells = line->cells;
  9220.               for (i = 0; i < len; i++) {
  9221.                   int pos = i + col;
  9222.                   if (pos < line->width) {
  9223.                       if (isunicode())
  9224.                         fnval[i] = (CHAR) utolxlat(cells[pos].c);
  9225.                       else
  9226.                         fnval[i] = (CHAR) (cells[pos].c & 0xFF);
  9227.                       if (fnval[i] == 0)
  9228.                         fnval[i] = SP;
  9229.                   } else
  9230.                     fnval[i] = SP;
  9231.               }
  9232.               fnval[i] = '\0';
  9233.           } else {
  9234.               fnval[0] = '\0';
  9235.           }
  9236.           p = fnval;
  9237.           goto fnend;
  9238.       }
  9239. #endif /* OS2 */
  9240. #endif /* NOLOCAL */
  9241.  
  9242. #ifndef NOPUSH
  9243.       case FN_RAW:                      /* \frawcommand() */
  9244.       case FN_CMD: {                    /* \fcommand() */
  9245.           int x, c, n = FNVALL;
  9246.           x = 0;                        /* Completion flag */
  9247. /*
  9248.   ZIFILE can be safely used because we can't possibly be transferring a file
  9249.   while executing this function.
  9250. */
  9251.           if (!nopush && zxcmd(ZIFILE,bp[0]) > 0) { /* Open the command */
  9252.               while (n-- > -1) {        /* Read from it */
  9253.                   if ((c = zminchar()) < 0) {
  9254.                       x = 1;             /* EOF - set completion flag */
  9255.                       if (cx == FN_CMD) { /* If not "rawcommand" */
  9256.                           p--;           /* remove trailing newlines */
  9257.                           while (*p == CR || *p == LF)
  9258.                             p--;
  9259.                           p++;
  9260.                       }
  9261.                       *p = NUL;         /* Terminate the string */
  9262.                       break;
  9263.                   } else                /* Command still running */
  9264.                     *p++ = c;           /* Copy the bytes */
  9265.               }
  9266.               zclose(ZIFILE);           /* Close the command */
  9267.           }
  9268.           /* Return null string if command's output was too long. */
  9269.           p = fnval;
  9270.           if (!x) {
  9271.               failed = 1;
  9272.               if (fndiags)
  9273.                 ckmakmsg(fnval,FNVALL,
  9274.                          "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  9275.           }
  9276.           goto fnend;
  9277.       }
  9278. #endif /* NOPUSH */
  9279.     } /* Break up big switch... */
  9280.  
  9281.     switch (y) {
  9282.       case FN_STX:                      /* \fstripx(string,c) */
  9283.         if (!(s = bp[0]))               /* Make sure there is a string */
  9284.           goto fnend;
  9285.         c = '.';                        /* Character to strip from */
  9286.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9287.         n = ckstrncpy(fnval,bp[0],FNVALL);
  9288.         while (--n >= 0) {
  9289.             if (fnval[n] == c) {
  9290.                 fnval[n] = NUL;
  9291.                 break;
  9292.             }
  9293.         }
  9294.         p = fnval;
  9295.         goto fnend;
  9296.  
  9297.       case FN_STL:                      /* \flop(string,c) */
  9298.         if (!(s = bp[0]))               /* Make sure there is a string */
  9299.           goto fnend;
  9300.         c = '.';                        /* Character to strip to */
  9301.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9302.         x = 0;
  9303.         while (*s++) {
  9304.             if (*(s-1) == c) {
  9305.                 x = 1;
  9306.                 break;
  9307.             }
  9308.         }
  9309.         if (!x) s = bp[0];
  9310.         ckstrncpy(fnval,s,FNVALL);
  9311.         p = fnval;
  9312.         goto fnend;
  9313.  
  9314.       case FN_STN:                      /* \fstripn(string,n) */
  9315.         if (argn < 1)                   /* Remove n chars from right */
  9316.           goto fnend;
  9317.         val1 = "0";
  9318.         if (argn > 1)
  9319.           if (*(bp[1]))
  9320.             val1 = evalx(bp[1]);
  9321.         if (!chknum(val1)) {
  9322.             failed = 1;
  9323.             evalerr(fn);
  9324.             goto fnend;
  9325.         }
  9326.         n = atoi(val1);
  9327.         if (n < 0) n = 0;
  9328.         k = (int)strlen(s = bp[0]) - n;
  9329.         if (k < 0) k = 0;
  9330.         p = fnval;
  9331.         while (k-- > 0)
  9332.           *p++ = *s++;
  9333.         *p = NUL;
  9334.         p = fnval;
  9335.         goto fnend;
  9336.  
  9337.       case FN_STB: {                    /* \fstripb(string,c) */
  9338.           char c2 = NUL;
  9339.           int i, k = 0;
  9340.           char * gr_opn = "\"{'([<";    /* Group open brackets */
  9341.           char * gr_cls = "\"}')]>";    /* Group close brackets */
  9342.  
  9343.           p = fnval;
  9344.           *p = NUL;
  9345.           if (!(s = bp[0]))             /* Make sure there is a string */
  9346.             goto fnend;
  9347.           if ((x = strlen(s)) < 1)
  9348.             goto fnend;
  9349.           c = NUL;                      /* Brace/bracket kind */
  9350.           if (argn > 1) {
  9351.               if (*bp[1]) {
  9352.                   if (chknum(bp[1])) {
  9353.                       k = atoi(bp[1]);
  9354.                       if (k < 0) k = 63;
  9355.                       for (i = 0; i < 6; i++) {
  9356.                           if (k & (1<<i)) {
  9357.                               if (s[0] == gr_opn[i] && s[x-1] == gr_cls[i]) {
  9358.                                   ckstrncpy(fnval,s+1,FNVALL);
  9359.                                   fnval[x-2] = NUL;
  9360.                                   goto fnend;
  9361.                               }
  9362.                           }
  9363.                       }
  9364.                       ckstrncpy(fnval,s,FNVALL); /* No match */
  9365.                       goto fnend;
  9366.                   }
  9367.               }
  9368.           }
  9369.           c = *bp[1];
  9370.           if (!c) c = s[0];
  9371.           if (argn > 2) if (*bp[2]) c2 = *bp[2];
  9372.           if (*s == c) {
  9373.               if (!c2) {
  9374.                   switch (c) {
  9375.                     case '(': c2 = ')'; break;
  9376.                     case '[': c2 = ']'; break;
  9377.                     case '{': c2 = '}'; break;
  9378.                     case '<': c2 = '>'; break;
  9379.                     case '"': c2 = '"'; break;
  9380.                     case 39:  c2 = 39;  break;
  9381.                     case 96:  c2 = 39;  break;
  9382.                     default:
  9383.                       if (argn == 2) {
  9384.                           c2 = c;
  9385.                       } else {
  9386.                           strncpy(fnval,s,x); /* Leave it like this */
  9387.                           fnval[x] = NUL;
  9388.                           goto fnend;
  9389.                       }
  9390.                   }
  9391.               }
  9392.               if (s[x-1] == c2) {
  9393.                   strncpy(fnval,s+1,x-2); /* Leave it like this */
  9394.                   fnval[x-2] = NUL;
  9395.                   goto fnend;
  9396.               }
  9397.           }
  9398.           strncpy(fnval,s,x);
  9399.           fnval[x] = NUL;
  9400.           goto fnend;
  9401.       }
  9402.  
  9403.       case FN_2HEX:                     /* Number to hex */
  9404.       case FN_2OCT:                     /* Number to octal */
  9405.         val1 = evalx(bp[0]);
  9406.         if (!*val1) {
  9407.             failed = 1;
  9408.             evalerr(fn);
  9409.             goto fnend;
  9410.         }
  9411.         sprintf(fnval, cx == FN_2HEX ? "%lx" : "%lo", atol(val1)); /* SAFE */
  9412.         if (cx == FN_2HEX && (int)(strlen(fnval)&1))
  9413.           sprintf(fnval,"0%lx",atol(val1)); /* SAFE */
  9414.         p = fnval;
  9415.         goto fnend;
  9416.  
  9417.       case FN_DNAM: {                   /* Directory part of file name */
  9418.           char *s;
  9419.           zfnqfp(bp[0],FNVALL,p);       /* Get full name */
  9420.           if (!isdir(p)) {              /* Is it already a directory? */
  9421.               zstrip(p,&s);             /* No get basename */
  9422.               if (*s) {
  9423.                   x = ckindex(s,p,0,0,0); /* Pos of latter in former */
  9424.                   if (x > 0) p[x-1] = NUL;
  9425.               }
  9426.           }
  9427.           if (!p) p = "";
  9428.           goto fnend;
  9429.       }
  9430.  
  9431. #ifndef NORANDOM
  9432.       case FN_RAND:                     /* Random number */
  9433. #ifdef CK_SSL
  9434.         if (RAND_bytes((unsigned char *)&k,sizeof(k)) < 0)
  9435. #endif /* CK_SSL */
  9436.           k = rand();
  9437.         x = 0;
  9438.         if (argn > 0) {
  9439.             if (!chknum(bp[0])) {
  9440.                 failed = 1;
  9441.                 if (fndiags)
  9442.                   ckmakmsg(fnval,FNVALL,
  9443.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9444.                 goto fnend;
  9445.             }
  9446.             x = atoi(bp[0]);
  9447.         }
  9448. #ifdef COMMENT
  9449.         sprintf(fnval,"%d", (x > 0 && k > 0) || (x < 0 && k < 0) ? k % x : 
  9450.                 (x == 0 ? 0 : (0 - (k % (-x)))));
  9451. #else
  9452.         debug(F111,"rand",ckitoa(x),k);
  9453. #ifdef SUNOS4
  9454. /* This is really strange but on SunOS, if we are requesting random numbers */
  9455. /* between 0 and 4 or less, they always come out in sequence: 0 1 2 3 0 1 2 */
  9456. /* Shifting the result of rand() in this case gives a more random result.   */
  9457.         if (x < 5)
  9458.           k = k >> 5;
  9459. #endif /* SUNOS4 */
  9460.         if ((x > 0 && k > 0) || (x < 0 && k < 0))
  9461.           x = k % x;
  9462.         else if (x == 0)
  9463.           x = 0;
  9464.         else
  9465.           x = 0 - (k % (-x));
  9466.         debug(F101,"rand x","",x);
  9467.         sprintf(fnval,"%d", x);         /* SAFE */
  9468. #endif /* COMMENT */
  9469.         p = fnval;
  9470.         goto fnend;
  9471. #endif /* NORANDOM */
  9472.     } /* Break up big switch... */
  9473.  
  9474.     switch (y) {
  9475.       case FN_SPLIT:                    /* \fsplit(s1,a,s2,s3,mask) */
  9476.       case FN_WORD: {                   /* \fword(s1,n,s2,s3,mask) */
  9477.           int wordnum = 0;
  9478.           int splitting = 0;
  9479.           int x;
  9480.           int array = 0;
  9481.           int grouping = 0;
  9482.           int nocollapse = 0;
  9483.           char * sep = "";
  9484.           char * notsep = "";
  9485.           char * bp0 = NULL;
  9486.           char * bp1 = NULL;
  9487.           char   abuf[16];
  9488.           struct stringarray * q = NULL;
  9489.  
  9490.           splitting = (cx == FN_SPLIT); /* Our job */
  9491.  
  9492.           fnval[0] = splitting ? '0' : NUL; /* Initial return value */
  9493.           fnval[1] = NUL;
  9494.           p = fnval;
  9495.           bp0 = bp[0];                  /* Source string */
  9496.           if (!bp0) bp0 = "";
  9497.           debug(F111,"fsplit bp[0]",bp0,argn);
  9498.           if (argn < 1 || !*bp0)        /* If none, return default value */
  9499.             goto fnend;
  9500.  
  9501.           bp1 = bp[1];                  /* Function-dependent arg */
  9502.           if (!bp1) bp1 = "";           /* (array or number) */
  9503.           debug(F110,"fsplit bp[1]",bp1,0);
  9504.           if (bp[5]) {
  9505.               if (!chknum(bp[5])) {
  9506.                   failed = 1;
  9507.                   ckmakmsg(fnval,FNVALL,
  9508.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9509.                   goto fnend;
  9510.               }
  9511.               x = atoi(bp[5]);
  9512.               nocollapse = x;
  9513.           }
  9514.           if (!splitting) {             /* \fword(): n = desired word number */
  9515.               val1 = "1";               /* Default is first word */
  9516.               if (argn > 1)             /* Word number supplied */
  9517.                 if (*bp1)
  9518.                   val1 = evalx(bp1);
  9519.               if (!chknum(val1)) {
  9520.                   failed = 1;
  9521.                   ckmakmsg(fnval,FNVALL,
  9522.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9523.                   goto fnend;
  9524.               }
  9525.               n = atoi(val1);
  9526.           } else if (argn > 1 && *bp1) { /* \fsplit(): n = word count */
  9527.               ckstrncpy(abuf,bp1,16);   /* Get array reference */
  9528.               debug(F110,"fsplit abuf 1",abuf,0);
  9529.               failed = 1;               /* Assume it's bad */
  9530.               if (fndiags)              /* Default is this error message */
  9531.                 ckmakmsg(fnval,FNVALL,
  9532.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9533.               if (abuf[0] != '&')       /* "Address" of array */
  9534.                 goto fnend;             /* It's bad */
  9535.               if (abuf[2]) {            /* Check for brackets */
  9536.                   if (abuf[2] != '[' || abuf[3] != ']') {
  9537.                       goto fnend;       /* Bad */
  9538.                   }
  9539.               }
  9540.               debug(F110,"fsplit abuf 2",abuf,0);
  9541.               if (abuf[1] > 64 && abuf[1] < 91) /* Convert upper to lower */
  9542.                 abuf[1] += 32;
  9543.               if (abuf[1] < 97 || abuf[1] > 122) { /* Check for a-z */
  9544.                   goto fnend;
  9545.               }
  9546.               debug(F110,"fsplit abuf 3",abuf,0);
  9547.               array = 1;
  9548.               fnval[0] = NUL;           /* No error, erase message */
  9549.               failed = 0;               /* Unset failure flag */
  9550.               n = 0;                    /* Initialize word counter */
  9551.           }
  9552.           if (argn > 2)                 /* Have break set? */
  9553.             sep = bp[2];
  9554.           debug(F111,"fsplit sep",sep,argn);
  9555.           if (argn > 3)                 /* Have include set? */
  9556.             notsep = bp[3];
  9557.           debug(F111,"fsplit notsep",notsep,argn);
  9558.           if (argn > 4) {               /* Have grouping set? */
  9559.               char * bp4 = bp[4];
  9560.               debug(F111,"fsplit bp4",bp4,argn);
  9561.               if (!bp4) bp4 = "0";
  9562.               if (!*bp4) bp4 = "0";
  9563.               if (chknum(bp4)) {
  9564.                   grouping = atoi(bp4);
  9565.                   if (grouping == -1)
  9566.                     grouping = 127;
  9567.               } else {
  9568.                   failed = 1;
  9569.                   if (fndiags)
  9570.                     ckmakmsg(fnval,FNVALL,
  9571.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9572.                   goto fnend;
  9573.               }
  9574.           }
  9575.           /* Args parsed, now do the work */
  9576.  
  9577.           debug(F111,"fsplit bp0",bp0,n);
  9578.           q = cksplit(splitting,n,bp0,sep,notsep,grouping,0,nocollapse);
  9579.  
  9580.           wordnum = q ? q->a_size : -1; /* Check result */
  9581.           if (wordnum < 0) {
  9582.               failed = 1;               /* Failure */
  9583.               if (fndiags)
  9584.                 ckmakmsg(fnval,FNVALL,
  9585.                          (wordnum == -1) ?
  9586.                          "<ERROR:MALLOC_FAILURE:\\f" :
  9587.                          "<ERROR:TOO_MANY_WORDS:\\f",
  9588.                          fn,
  9589.                          "()>",
  9590.                          NULL
  9591.                          );
  9592.               goto fnend;
  9593.           }
  9594.           if (splitting) {              /* \fsplit() result */
  9595.               ckstrncpy(fnval,ckitoa(wordnum),FNVALL);
  9596.               if (array) {              /* Array was not declared. */
  9597.                   int i;
  9598.                   if ((x = dclarray(abuf[1],wordnum)) < 0) { /* Declare it. */
  9599.                       failed = 1;
  9600.                       if (fndiags)
  9601.                         ckmakmsg(fnval,FNVALL,
  9602.                                  "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  9603.                       goto fnend;
  9604.                   }
  9605.                   for (i = 1; i <= wordnum; i++) { /* Copy results */
  9606.                       makestr(&(a_ptr[x][i]),q->a_head[i]);
  9607.                   }
  9608.                   a_ptr[x][0] = NULL;   /* Array is 1-based */
  9609.                   makestr(&(a_ptr[x][0]),fnval); /* Element = size */
  9610.               }
  9611.           } else {                      /* \fword() result */
  9612.               char * s;
  9613.               s = q->a_head[1];
  9614.               if (!s) s = "";
  9615.               ckstrncpy(fnval,s,FNVALL);
  9616.           }
  9617.           goto fnend;                   /* Done */
  9618.       }
  9619.  
  9620.     } /* Break up big switch... */
  9621.  
  9622.     switch (y) {
  9623.  
  9624. #ifdef CK_KERBEROS
  9625.       case FN_KRB_TK:                   /* Kerberos tickets */
  9626.       case FN_KRB_NX:                   /* Kerberos next ticket */
  9627.       case FN_KRB_IV:                   /* Kerberos ticket is valid */
  9628.       case FN_KRB_FG:                   /* Kerberos Ticket flags */
  9629.       case FN_KRB_TT: {                 /* Kerberos ticket time */
  9630.           int kv = 0;                   /* Kerberos version */
  9631.           int n = 0;
  9632.           char * s = NULL;
  9633.           if (rdigits(bp[0])) {
  9634.               kv = atoi(bp[0]);
  9635.           } else {
  9636.               failed = 1;
  9637.               if (fndiags)
  9638.                 ckmakmsg(fnval,FNVALL,
  9639.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9640.               goto fnend;
  9641.           }
  9642.           if (kv != 4 && kv != 5) {
  9643.               failed = 1;
  9644.               if (fndiags)
  9645.                 ckmakmsg(fnval,FNVALL,
  9646.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9647.               goto fnend;
  9648.           }
  9649.           if ((cx == FN_KRB_IV || cx == FN_KRB_TT || cx == FN_KRB_FG) &&
  9650.                argn < 2) {
  9651.               failed = 1;
  9652.               if (fndiags)
  9653.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9654.               goto fnend;
  9655.           }
  9656.           switch (y) {
  9657.             case FN_KRB_TK:             /* Number of Kerberos tickets */
  9658. #ifdef CK_AUTHENTICATION
  9659.               switch (kv) {
  9660.                 case 4:
  9661.                   n = ck_krb4_get_tkts();
  9662.                   sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9663.                   goto fnend;
  9664.                 case 5: {
  9665.                     extern char * krb5_d_cc;
  9666.                     n = ck_krb5_get_tkts(krb5_d_cc);
  9667.                     sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9668.                     goto fnend;
  9669.                 }
  9670.               }
  9671. #else
  9672.               sprintf(fnval,"%d",0);    /* SAFE */
  9673. #endif /* CK_AUTHENTICATION */
  9674.               goto fnend;
  9675.  
  9676.             case FN_KRB_NX:             /* Kerberos next ticket */
  9677. #ifdef CK_AUTHENTICATION
  9678.               switch (kv) {
  9679.                 case 4:
  9680.                   s = ck_krb4_get_next_tkt();
  9681.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9682.                   goto fnend;
  9683.                 case 5:
  9684.                   s = ck_krb5_get_next_tkt();
  9685.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9686.                   goto fnend;
  9687.               }
  9688. #else
  9689.               sprintf(fnval,"k%d next-ticket-string",kv); /* SAFE */
  9690. #endif /* CK_AUTHENTICATION */
  9691.               goto fnend;
  9692.  
  9693.             case FN_KRB_IV:             /* Kerberos ticket is valid */
  9694. #ifdef CK_AUTHENTICATION
  9695.               /* Return 1 if valid, 0 if not */
  9696.               switch (kv) {
  9697.                 case 4:
  9698.                   n = ck_krb4_tkt_isvalid(bp[1]);
  9699.                   sprintf(fnval, "%d", n > 0 ? 1 : 0); /* SAVE */
  9700.                   goto fnend;
  9701.                 case 5: {
  9702.                     extern char * krb5_d_cc;
  9703.                     n = ck_krb5_tkt_isvalid(krb5_d_cc,bp[1]);
  9704.                     sprintf(fnval,"%d", n > 0 ? 1 : 0); /* SAFE */
  9705.                     goto fnend;
  9706.                 }
  9707.               }
  9708. #else
  9709.               sprintf(fnval,"%d",0);    /* SAFE */
  9710. #endif /* CK_AUTHENTICATION */
  9711.               goto fnend;
  9712.  
  9713.             case FN_KRB_TT:             /* Kerberos ticket time */
  9714. #ifdef CK_AUTHENTICATION
  9715.               switch (kv) {
  9716.                 case 4:
  9717.                   n = ck_krb4_tkt_time(bp[1]);
  9718.                   sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9719.                   goto fnend;
  9720.                 case 5: {
  9721.                     extern char * krb5_d_cc;
  9722.                     n = ck_krb5_tkt_time(krb5_d_cc,bp[1]);
  9723.                     sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9724.                     goto fnend;
  9725.                 }
  9726.               }
  9727. #else
  9728.               ckstrncpy(fnval,"600",FNVALL); /* Some time */
  9729. #endif /* CK_AUTHENTICATION */
  9730.               goto fnend;
  9731.  
  9732.             case FN_KRB_FG:             /* Kerberos ticket flags */
  9733. #ifdef CK_AUTHENTICATION
  9734.               switch (kv) {
  9735.                 case 4:
  9736.                   fnval[0] = '\0';
  9737.                   goto fnend;
  9738.                 case 5: {
  9739.                     extern char * krb5_d_cc;
  9740.                     ckstrncpy(fnval,ck_krb5_tkt_flags(krb5_d_cc,bp[1]),FNVALL);
  9741.                     goto fnend;
  9742.                 }
  9743.               }
  9744. #else
  9745.               fnval[0] = '\0';
  9746. #endif /* CK_AUTHENTICATION */
  9747.               goto fnend;
  9748.           }
  9749.           p = fnval;
  9750.           goto fnend;
  9751.       }
  9752. #endif /* CK_KERBEROS */
  9753.  
  9754. #ifdef FN_ERRMSG
  9755.       case FN_ERRMSG:
  9756.         if (rdigits(bp[0])) {
  9757.             k = atoi(bp[0]);
  9758.         } else {
  9759.             failed = 1;
  9760.             if (fndiags)
  9761.              ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9762.             goto fnend;
  9763.         }
  9764. #ifdef VMS
  9765.         ckstrncpy(fnval,ckvmserrstr(k),FNVALL);
  9766. #else
  9767.         x = errno;
  9768.         errno = k;
  9769.         ckstrncpy(fnval,ck_errstr(),FNVALL);
  9770.         errno = x;
  9771. #endif /* VMS */
  9772.         p = fnval;
  9773.         goto fnend;
  9774. #endif /* FN_ERRMSG */
  9775.  
  9776.       case FN_DIM: {
  9777.           int max;
  9778.           char abuf[16], *s;
  9779.           fnval[0] = NUL;               /* Initial return value */
  9780.           ckstrncpy(abuf,bp[0],16);     /* Get array reference */
  9781.           s = abuf;
  9782.           if (*s == CMDQ) s++;
  9783.           failed = 1;                   /* Assume it's bad */
  9784.           p = fnval;                    /* Point to result */
  9785.           if (fndiags)                  /* Default is this error message */
  9786.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9787.           if (s[0] != '&') {            /* "Address" of array */
  9788.               goto fnend;
  9789.           }
  9790.           if (s[2]) {
  9791.               if (s[2] != '[' || s[3] != ']') {
  9792.                   goto fnend;
  9793.               }
  9794.           }
  9795.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  9796.             s[1] += 32;
  9797.           if (s[1] < 95 || s[1] > 122) { /* Check for a-z */
  9798.               goto fnend;                       /* Bad */
  9799.           }
  9800.           if ((max = chkarray(s[1],1)) < 1)
  9801.             max = 0;
  9802.           failed = 0;                   /* Unset failure flag */
  9803.           sprintf(fnval,"%d",max);      /* SAFE */
  9804.           goto fnend;
  9805.       }
  9806.  
  9807.     } /* Break up big switch... */
  9808.  
  9809.     switch (y) {
  9810.       case FN_JDATE:
  9811.         if (argn < 1)                   /* Check number of args */
  9812.           p = ckdate();                 /* None, get today's date-time */
  9813.         else                            /* Some */
  9814.           p = bp[0];                    /* Use first */
  9815.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9816.         ckstrncpy(fnval,zjdate(p),FNVALL); /* Convert to Julian */
  9817.         p = fnval;                      /* Point to result */
  9818.         failed = 0;
  9819.         if (*p == '-') {
  9820.             failed = 1;
  9821.             if (fndiags)                /* Default is this error message */
  9822.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9823.         }
  9824.         goto fnend;
  9825.  
  9826.       case FN_DATEJ:
  9827.         ckstrncpy(fnval,jzdate(bp[0]),FNVALL); /* Convert to yyyy<dayofyear> */
  9828.         p = fnval;                      /* Point to result */
  9829.         failed = 0;
  9830.         if (*p == '-') {
  9831.             failed = 1;
  9832.             if (fndiags)                /* Default is this error message */
  9833.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9834.         }
  9835.         goto fnend;
  9836.  
  9837.       case FN_DTIM:                     /* \fcvtdate() */
  9838.       case FN_TIME:                     /* Free-format time to hh:mm:ss */
  9839.       case FN_NTIM:                     /* Time to sec since midnight */
  9840.         s = (argn > 0) ? bp[0] : "";
  9841.         if (!s) s = "";
  9842.         if (!*s)
  9843.           p = ckdate();                 /* None, get today's date */
  9844.         else                            /* Some */
  9845.           p = bp[0];                    /* Use first */
  9846.         p = ckcvtdate(p,2);             /* Convert to standard form */
  9847.         if (*p == '<') {
  9848.             failed = 1;
  9849.             if (fndiags)                /* Default is this error message */
  9850.               ckmakmsg(fnval,FNVALL,
  9851.                        "<ERROR:ARG_BAD_DATE_OR_TIME:\\f",fn,"()>",NULL);
  9852.             p = fnval;
  9853.             goto fnend;
  9854.         }
  9855.         if (argn > 1) {
  9856.             s = bp[1];
  9857.             if (!s) s = "";
  9858.             if (!*s) s = "0";
  9859.             if (!chknum(s)) {
  9860.                 failed = 1;
  9861.                 if (fndiags)
  9862.                   ckmakmsg(fnval,FNVALL,
  9863.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9864.                 p = fnval;
  9865.                 goto fnend;
  9866.             }
  9867.             x = atoi(s);
  9868.             if (x) p = shuffledate(p,x);
  9869.         }
  9870.         if (cx == FN_TIME) {
  9871.             p += 9;
  9872.         } else if (cx == FN_NTIM) {
  9873.             long sec = 0L;
  9874.             p[11] = NUL;
  9875.             p[14] = NUL;
  9876.             sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  9877.             sprintf(fnval,"%ld",sec);   /* SAFE */
  9878.             p = fnval;
  9879.         }
  9880.         goto fnend;
  9881.  
  9882.       case FN_MJD:                      /* Modified Julian Date */
  9883.         if (argn < 1)                   /* Check number of args */
  9884.           p = zzndate();                /* None, get today's date-time */
  9885.         else                            /* Some */
  9886.           p = bp[0];                    /* Use first */
  9887.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9888.         if (*p == '-') {
  9889.             failed = 1;
  9890.             if (fndiags)                /* Default is this error message */
  9891.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9892.             goto fnend;
  9893.         }
  9894.         /* Convert to modified Julian date */
  9895.         sprintf(fnval,"%ld",mjd(p));    /* SAFE */
  9896.         p = fnval;                      /* Point to result */
  9897.         goto fnend;
  9898.  
  9899.       case FN_MJD2: {
  9900.           long k = 0L;
  9901.           int n = 0;
  9902.           p = evalx(bp[0]);
  9903.           if (*p == '-') {
  9904.               p++;
  9905.               n = 1;
  9906.           }
  9907.           if (!rdigits(p)) {
  9908.               failed = 1;
  9909.               evalerr(fn);
  9910.               p = fnval;
  9911.               goto fnend;
  9912.           } else {
  9913.               k = atol(p);
  9914.               if (n) k = -k;
  9915.           }
  9916.           ckstrncpy(fnval,mjd2date(k),FNVALL); /* Convert to Date */
  9917.           p = fnval;                    /* Point to result */
  9918.           failed = 0;
  9919.           goto fnend;
  9920.       }
  9921.  
  9922. #ifndef NODIAL
  9923.       case FN_PNCVT: {                  /* Convert phone number */
  9924.           extern char * pncvt();
  9925.           failed = 0;
  9926.           p = pncvt(bp[0]);
  9927.           if (!p) p = "";
  9928.           if (!*p) {
  9929.             failed = 1;
  9930.             if (fndiags)                /* Default is this error message */
  9931.               ckmakmsg(fnval,FNVALL,
  9932.                        "<ERROR:ARG_BAD_PHONENUM:\\f",fn,"()>",NULL);
  9933.         }
  9934.         goto fnend;
  9935.       }
  9936. #endif /* NODIAL */
  9937.  
  9938.       case FN_DAY:
  9939.       case FN_NDAY:
  9940.         if (argn < 1)                   /* Check number of args */
  9941.           p = zzndate();                /* None, get today's date-time */
  9942.         else                            /* Some */
  9943.           p = bp[0];                    /* Use first */
  9944.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9945.         if (*p == '-') {
  9946.             failed = 1;
  9947.             if (fndiags)                /* Default is this error message */
  9948.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9949.             goto fnend;
  9950.         }
  9951.         failed = 0;
  9952.         z = mjd(p);                     /* Convert to modified Julian date */
  9953.         z = z % 7L;
  9954.         if (z < 0) {
  9955.             z = 0 - z;
  9956.             k = 6 - ((int)z + 3) % 7;
  9957.         } else {
  9958.             k = ((int)z + 3) % 7;    /* Day of week */
  9959.         }
  9960.         p = fnval;                      /* Point to result */
  9961.         if (cx == FN_NDAY)
  9962.           sprintf(fnval,"%d",k);        /* SAFE */
  9963.         else
  9964.           ckstrncpy(fnval,wkdays[k],FNVALL);
  9965.         goto fnend;
  9966.  
  9967.       case FN_N2TIM: {                  /* Sec since midnight to hh:mm:ss */
  9968.           long k = 0L;
  9969.           int n = 0, hh, mm, ss;
  9970.           char * s = bp[0];
  9971.           if (argn < 1)                 /* If no arg substitute 0 */
  9972.             s = "0";
  9973.           p = evalx(s);                 /* Evaluate expression silently */
  9974.           if (*p == '-') {              /* Check result for minus sign */
  9975.               p++;
  9976.               n = 1;
  9977.           }
  9978.           if (!rdigits(p)) { /* Check for numeric */
  9979.               failed = 1;
  9980.               ckmakmsg(fnval,FNVALL,
  9981.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9982.               p = fnval;
  9983.               goto fnend;
  9984.           } else {
  9985.               k = atol(p);
  9986.               if (n) k = -k;
  9987.           }
  9988.           if (k < 0) {                  /* Check for negative */
  9989.               failed = 1;
  9990.               if (fndiags)
  9991.                 ckmakmsg(fnval,FNVALL,
  9992.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9993.               p = fnval;
  9994.               goto fnend;
  9995.           }
  9996.           hh = k / 3600L;               /* Have positive number */
  9997.           mm = (k % 3600L) / 60L;       /* break it down... */
  9998.           ss = ((k % 3600L) % 60L);
  9999.  
  10000.           sprintf(fnval,"%02d:%02d:%02d",hh,mm,ss); /* SAFE */
  10001.           p = fnval;
  10002.           failed = 0;
  10003.           goto fnend;
  10004.       }
  10005.  
  10006.       case FN_PERM: {                   /* File permissions */
  10007.           p = fnval;
  10008.           z = zchki(bp[0]);
  10009.           if (z < 0) {
  10010.               failed = 1;
  10011.               if (fndiags) {
  10012.                   if (z == -1)
  10013.                     ckmakmsg(fnval,FNVALL,
  10014.                              "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  10015.                   else if (z == -2)
  10016.                     ckmakmsg(fnval,FNVALL,
  10017.                              "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  10018.                   else if (z == -3)
  10019.                     ckmakmsg(fnval,FNVALL,
  10020.                              "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  10021.                   else
  10022.                     ckmakmsg(fnval,FNVALL,
  10023.                              "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  10024.               }
  10025.               goto fnend;
  10026.           }
  10027. #ifdef CK_PERMS
  10028.           ckstrncpy(fnval,ziperm(bp[0]),FNVALL);
  10029. #else
  10030.           ckstrncpy(fnval,"(unknown)",FNVALL);
  10031. #endif /* CK_PERMS */
  10032.           goto fnend;
  10033.       }
  10034.       case FN_TLOOK:                    /* tablelook() */
  10035.       case FN_ALOOK: {                  /* arraylook() */
  10036.           int i, x, hi, lo, max, cmdlen;
  10037.           char abuf[16], *s, *pat;
  10038.           char kwbuf[256];
  10039.           char delim = ':';
  10040.           failed = 1;                   /* Assume failure */
  10041.           ckstrncpy(fnval,"-1",FNVALL);
  10042.           pat = bp[0];                  /* Point to search pattern */
  10043.           if (!pat) pat = "";           /* Watch out for NULL pointer */
  10044.           cmdlen = strlen(pat);         /* Get pattern length */
  10045.           if (argn < 2 /* || cmdlen < 1 */ ) { /* Need two args */
  10046.               if (fndiags)
  10047.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10048.               goto fnend;
  10049.           }
  10050.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  10051.           if (argn > 2)
  10052.             delim = *(bp[2]);
  10053.           s = abuf;
  10054.           if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Get index and bounds */
  10055.               if (fndiags)
  10056.                ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10057.               goto fnend;
  10058.           }
  10059.           p = fnval;                    /* Point to result */
  10060.           max = a_dim[x];               /* Size of array */
  10061.           if (lo < 0) lo = 0;           /* Use given range if any */
  10062.           if (lo > max) lo = max;
  10063.           if (hi < 0) hi = max;
  10064.           if (hi > max) hi = max;
  10065.           failed = 0;                   /* Unset failure flag */
  10066.           if (max < 1)
  10067.             goto fnend;
  10068.           kwbuf[255] = NUL;
  10069.           for (i = lo; i <= hi; i++) {
  10070.               if (!a_ptr[x][i])
  10071.                 continue;
  10072.               if (cx == FN_ALOOK) {
  10073.                   if (ckmatch(pat,a_ptr[x][i],inpcas[cmdlvl],1+4)) {
  10074.                       sprintf(fnval,"%d",i); /* SAFE */
  10075.                       goto fnend;
  10076.                   }
  10077.               } else if (cx == FN_TLOOK) {
  10078.                   char * aa;
  10079.                   int j = 0, v = 0, len;
  10080.                   if (i == hi)
  10081.                     break;
  10082.                   aa = a_ptr[x][i];     /* Point to this array element */
  10083.                   if (!aa) aa = "";
  10084.                   while (j < 254 && *aa) { /* Isolate keyword */
  10085.                       if (*aa == delim)
  10086.                         break;
  10087.                       kwbuf[j++] = *aa++;
  10088.                   }
  10089.                   kwbuf[j] = NUL;
  10090.                   len = j;
  10091.                   v = 0;
  10092.                   if ((len == cmdlen && !ckstrcmp(kwbuf,pat,len,0)) ||
  10093.                       ((v = !ckstrcmp(kwbuf,pat,cmdlen,0)) &&
  10094.                        ckstrcmp(a_ptr[x][i+1],pat,cmdlen,0))) {
  10095.                       sprintf(fnval,"%d",i); /* SAFE */
  10096.                       goto fnend;
  10097.                   }
  10098.                   if (v) {              /* Ambiguous */
  10099.                       ckstrncpy(fnval,"-2",FNVALL);
  10100.                       goto fnend;
  10101.                   }
  10102.               }
  10103.           }
  10104.           if (cx == FN_TLOOK) {         /* tablelook() last element */
  10105.               ckstrncpy(fnval,"-1",FNVALL);
  10106.               if (!ckstrcmp(a_ptr[x][hi],pat,cmdlen,0))
  10107.                 sprintf(fnval,"%d",hi); /* SAFE */
  10108.           }
  10109.           goto fnend;
  10110.       }
  10111.       case FN_TOB64:                    /* Base-64 conversion */
  10112.       case FN_FMB64:
  10113.         p = fnval;
  10114.         *p = NUL;
  10115.         if (argn < 1)
  10116.           goto fnend;
  10117.         if (cx == FN_TOB64) {
  10118.             x = b8tob64(bp[0],-1,fnval,FNVALL);
  10119.         } else {
  10120.             x = strlen(bp[0]);
  10121.             if (x % 4) {                /* length must be multiple of 4 */
  10122.                 failed = 1;
  10123.                 ckmakmsg(fnval,FNVALL,
  10124.                          "<ERROR:ARG_INCOMPLETE:\\f",fn,"()>",NULL);
  10125.                 goto fnend;
  10126.             }
  10127.             b64tob8(NULL,0,NULL,0);     /* Reset */
  10128.             x = b64tob8(bp[0],-1,fnval,FNVALL);
  10129.             b64tob8(NULL,0,NULL,0);     /* Reset again */
  10130.         }
  10131.         if (x < 0) {
  10132.             failed = 1;
  10133.             if (fndiags) {
  10134.                 char * m = "INTERNAL_ERROR";
  10135.                 switch (x) {
  10136.                   case -1: m = "ARG_TOO_LONG"; break;
  10137.                   case -2: m = "ARG_OUT_OF_RANGE"; break;
  10138.                 }
  10139.                 if (ckmakmsg(fnval,FNVALL,"<ERROR:",m,"\\f",fn) > 0)
  10140.                   ckstrncat(fnval,"()>",FNVALL);
  10141.             }
  10142.         }
  10143.         goto fnend;
  10144.  
  10145.       case FN_ABS: {
  10146.           char * s;
  10147.           s = bp[0];
  10148.           if (*s == '-' || *s == '+')
  10149.             s++;
  10150.           if (!rdigits(s)) {
  10151.               if (fndiags)
  10152.                 ckmakmsg(fnval,FNVALL,
  10153.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10154.               goto fnend;
  10155.           }
  10156.           ckstrncpy(fnval,s,FNVALL);
  10157.           goto fnend;
  10158.       }
  10159.  
  10160.       case FN_AADUMP: {
  10161.           char abuf[16], *s = NULL, **ap = NULL, **vp = NULL;
  10162.           char pattern[VNAML];
  10163.           int slen, i, j, k, first = -1;
  10164.           extern int xdelmac();
  10165.           p = fnval;
  10166.           if (argn < 2) {
  10167.               if (fndiags)
  10168.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG2:\\f",fn,"()>",NULL);
  10169.               goto fnend;
  10170.           }
  10171.           debug(F101,"aaconvert argn","",argn);
  10172.           s = bp[0];
  10173.           slen = strlen(s);
  10174.  
  10175.           /* Count elements so we can create the array */
  10176.  
  10177.           ckmakmsg(pattern,VNAML,s,"<*>",NULL,NULL);
  10178.           for (k = 0, i = 0; i < nmac; i++) {
  10179.               if (ckmatch(pattern,mactab[i].kwd,0,1)) {
  10180.                   if (first < 0)        /* Remember location of first match */
  10181.                     first = i;
  10182.                   k++;
  10183.               }
  10184.           }
  10185.           debug(F101,"aaconvert matches","",k);
  10186.           debug(F101,"aaconvert first","",first);
  10187.           fnval[0] = NUL;               /* Initial return value */
  10188.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  10189.           s = abuf;
  10190.           if (*s == CMDQ) s++;
  10191.           p = fnval;                    /* Point to result */
  10192.           if (fndiags)                  /* Default is this error message */
  10193.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10194.           if (s[0] != '&')              /* Address of array */
  10195.             goto fnend;
  10196.           if (s[2])
  10197.             if (s[2] != '[' || s[3] != ']')
  10198.               goto fnend;
  10199.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  10200.             s[1] += 32;
  10201.           if ((x = dclarray(s[1],k)) < 0) /* Declare array to size */
  10202.             goto fnend;
  10203.           ap = a_ptr[x];                /* Point to array we just declared */
  10204.           debug(F111,"aaconvert array 1",abuf,ap);
  10205.           abuf[0] = NUL;
  10206.           if (argn > 2) {
  10207.               ckstrncpy(abuf,bp[2],16); /* Get value array reference */
  10208.               s = abuf;
  10209.               if (*s == CMDQ) s++;
  10210.               if (s[0] != '&')          /* Address of array */
  10211.                 goto fnend;
  10212.               if (s[2])
  10213.                 if (s[2] != '[' || s[3] != ']')
  10214.                   goto fnend;
  10215.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  10216.                 s[1] += 32;
  10217.               if ((x = dclarray(s[1],k)) < 0)
  10218.                 goto fnend;
  10219.               vp = a_ptr[x];            /* Point to array we just declared */
  10220.           }
  10221.           debug(F111,"aaconvert array 2",abuf,vp);
  10222.           makestr(&ap[0],ckitoa(k));
  10223.           if (vp) makestr(&vp[0],ckitoa(k));
  10224.           if (fndiags)
  10225.            ckmakmsg(fnval,FNVALL,"<ERROR:ASSOCIATIVE_ARRAY:\\f",fn,"()>",NULL);
  10226.  
  10227.           /* Copy macro index & value to the arrays and then remove the */
  10228.           /* macro, so the 'first' pointer keeps indicating the next one. */
  10229.           /* We could combine the initial counting loop with this one but */
  10230.           /* then it would be harder to create the array and anyway this */
  10231.           /* function is plenty fast as it is. */
  10232.  
  10233.           for (i = 1; i <= k; ) {
  10234.               if (!ckmatch(pattern,mactab[first].kwd,0,1)) {
  10235.                   debug(F111,"aaconvert oddball",mactab[first].kwd,first);
  10236.                   first++;
  10237.                   continue;
  10238.               }
  10239.               ckstrncpy(tmpbuf,mactab[first].kwd,TMPBUFSIZ); /* Macro name */
  10240.               s = tmpbuf;                       /* Make writeable copy */
  10241.               s += slen;                        /* Isolate "index" */
  10242.               j = strlen(s) - 1;
  10243.               if (*s != '<' || *(s+j) != '>') { /* Check syntax */
  10244.                   /* This shouldn't happen */
  10245.                   debug(F111,"aaconvert ERROR",mactab[first].kwd,first);
  10246.                   goto fnend;
  10247.               }
  10248.               *(s+j) = NUL;             /* Remove final '>' */
  10249.               debug(F111,"aaconvert",s+1,i);
  10250.               makestr(&(ap[i]),s+1);    /* Set first array to index */
  10251.               if (vp)
  10252.                 makestr(&(vp[i]),mactab[first].mval); /* 2nd to value */
  10253.               if (xdelmac(first) < 0)
  10254.                 goto fnend;
  10255.               i++;
  10256.           }
  10257.           sprintf(fnval,"%d",k);        /* SAFE */
  10258.           p = fnval;                    /* Return size of array */
  10259.           debug(F110,"aaconvert return",p,0);
  10260.           failed = 0;                   /* Unset failure flag */
  10261.           goto fnend;
  10262.       }
  10263.  
  10264.     } /* End of switch() */
  10265.  
  10266. #ifdef FNFLOAT
  10267. /*
  10268.   Floating-point functions.  To be included only if FNFLOAT is defined, which
  10269.   should happen only if CKFLOAT is also defined, and if the math library is
  10270.   linked in.  Even then, we might have float-vs-double confusion as well as
  10271.   confusion about what the final "%f" format effector is supposed to reference
  10272.   (32 bits, 64 bits, etc).  Expect trouble if CKFLOAT does not match the data
  10273.   type of math library functions or args.
  10274. */
  10275.     if (cx == FN_FPABS ||               /* Floating-point functions */
  10276.         cx == FN_FPADD ||
  10277.         cx == FN_FPDIV ||
  10278.         cx == FN_FPEXP ||
  10279.         cx == FN_FPLOG ||
  10280.         cx == FN_FPLN  ||
  10281.         cx == FN_FPMOD ||
  10282.         cx == FN_FPMAX ||
  10283.         cx == FN_FPMIN ||
  10284.         cx == FN_FPMUL ||
  10285.         cx == FN_FPPOW ||
  10286.         cx == FN_FPSQR ||
  10287.         cx == FN_FPINT ||
  10288.         cx == FN_FPSUB ||
  10289.         cx == FN_FPROU ||
  10290.         cx == FN_FPSIN ||
  10291.         cx == FN_FPCOS ||
  10292.         cx == FN_FPTAN) {
  10293.         CKFLOAT farg[2], fpresult = 0.0;
  10294.         char fpbuf[64], * bp0;
  10295.         double dummy;
  10296.         /* int sign = 0; */
  10297.         int i, j, places = 0;
  10298.         int argcount = 1;
  10299.  
  10300.         failed = 1;
  10301.         p = fnval;
  10302.         bp0 = bp[0];
  10303.         if (!bp0)
  10304.           bp0 = "0";
  10305.         else if (!*bp0)
  10306.           bp0 = "0";
  10307.         if (!isfloat(bp0,0)) {
  10308.             k = mxlook(mactab,bp0,nmac);
  10309.             bp0 = (k > -1) ? mactab[k].mval : NULL;
  10310.             if (bp0) {
  10311.                 if (!isfloat(bp0,0)) {
  10312.                     if (fndiags)
  10313.                       ckmakmsg(fnval,FNVALL,
  10314.                                "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10315.                     goto fnend;
  10316.                 }
  10317.             }
  10318.         }
  10319.         if (cx == FN_FPINT) {           /* Float to int */
  10320.             failed = 0;
  10321.             ckstrncpy(fnval,bp0,FNVALL);
  10322.             for (i = 0; fnval[i]; i++) {
  10323.                 if (fnval[i] == '.') {
  10324.                     fnval[i] = NUL;
  10325.                     break;
  10326.                 }
  10327.             }
  10328.             goto fnend;
  10329.         }
  10330.         switch (y) {                    /* These need 2 args */
  10331.           case FN_FPADD:
  10332.           case FN_FPDIV:
  10333.           case FN_FPMOD:
  10334.           case FN_FPMAX:
  10335.           case FN_FPMIN:
  10336.           case FN_FPMUL:
  10337.           case FN_FPPOW:
  10338.           case FN_FPSUB:
  10339.             argcount = 2;
  10340.         }
  10341.         /* Missing arguments are supplied as 0.0 */
  10342.  
  10343.         debug(F111,fn,"argcount",argcount);
  10344.         for (i = 0; i < argcount; i++) { /* Get floating-point args */
  10345. #ifdef DEBUG
  10346.             if (deblog) {
  10347.                 ckmakmsg(fpbuf,
  10348.                          64,
  10349.                          "bp[",
  10350.                          ckitoa(i),
  10351.                          bp[i] ? bp[i] : "(null)",
  10352.                          "]"
  10353.                          );
  10354.                 debug(F100,fpbuf,"",0);
  10355.             }
  10356. #endif /* DEBUG */
  10357.             if (!bp[i]) {
  10358.                 farg[i] = 0.0;
  10359.             } else if (!*(bp[i])) {
  10360.                 farg[i] = 0.0;
  10361.             } else if (!isfloat(bp[i],0)) {
  10362.                 char * tmp;
  10363.                 k = mxlook(mactab,bp[i],nmac);
  10364.                 tmp = (k > -1) ? mactab[k].mval : NULL;
  10365.                 if (tmp) {
  10366.                     if (!isfloat(tmp,0)) {
  10367.                         if (fndiags)
  10368.                           ckmakmsg(fnval,FNVALL,
  10369.                                    "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10370.                         goto fnend;
  10371.                     }
  10372.                 }
  10373.             }
  10374.             farg[i] = floatval;
  10375.  
  10376. #ifdef DEBUG
  10377.             if (deblog) {
  10378.                 sprintf(fpbuf,"farg[%d]=%f",i,farg[i]); /* SAFE */
  10379.                 debug(F100,fpbuf,"",0);
  10380.             }
  10381. #endif /* DEBUG */
  10382.         }
  10383.         if (bp[argcount]) {             /* Get decimal places */
  10384.             char * s;
  10385.             s = bp[argcount];
  10386.             if (!s) s = "";
  10387.             if (!*s) s = "0";
  10388.             s = evalx(s);
  10389.             if (!s) s = "";
  10390.             if (!*s) {
  10391.                 evalerr(fn);
  10392.                 goto fnend;
  10393.             }
  10394.             places = atoi(s);
  10395.         }
  10396.         errno = 0;
  10397.         failed = 0;
  10398.         switch (y) {                    /* Now do the requested function */
  10399.           case FN_FPABS:                /* Floating-point absolute value */
  10400. #ifndef COMMENT
  10401.             fpresult = fabs(farg[0]);
  10402. #else
  10403.             if (farg[0] < 0.0)
  10404.               fpresult = 0.0 - farg[0];
  10405. #endif /* COMMENT */
  10406.             break;
  10407.           case FN_FPADD:                /* FP add */
  10408.             fpresult = farg[0] + farg[1];
  10409.             break;
  10410.           case FN_FPDIV:                /* FP divide */
  10411.           case FN_FPMOD:                /* FP modulus */
  10412.             if (!farg[1]) {
  10413.                 failed = 1;
  10414.                 if (fndiags)
  10415.                   ckmakmsg(fnval,FNVALL,
  10416.                            "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  10417.             } else
  10418.               fpresult = (cx == FN_FPDIV) ?
  10419.                 (farg[0] / farg[1]) :
  10420.                   fmod(farg[0],farg[1]);
  10421.             break;
  10422.           case FN_FPEXP:                /* FP e to the x */
  10423.             fpresult = (CKFLOAT) exp(farg[0]);
  10424.             break;
  10425.           case FN_FPLOG:                /* FP base-10 logarithm */
  10426.           case FN_FPLN:                 /* FP natural logarithm */
  10427.             if (farg[0] < 0.0) {
  10428.                 failed = 1;
  10429.                 if (fndiags)
  10430.                   ckmakmsg(fnval,FNVALL,
  10431.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10432.             } else
  10433.               fpresult = (cx == FN_FPLOG) ? log10(farg[0]) : log(farg[0]);
  10434.             break;
  10435.           case FN_FPMUL:                /* FP multiply */
  10436.             fpresult = farg[0] * farg[1];
  10437.             break;
  10438.           case FN_FPPOW:                /* FP raise to a power */
  10439.             fpresult = modf(farg[1],&dummy);
  10440.             if ((!farg[0] && farg[1] <= 0.0) ||
  10441.                 (farg[0] < 0.0 && fpresult)) {
  10442.                 failed = 1;
  10443.                 if (fndiags)
  10444.                   ckmakmsg(fnval,FNVALL,
  10445.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10446.             } else
  10447.               fpresult = pow(farg[0],farg[1]);
  10448.             break;
  10449.           case FN_FPSQR:                /* FP square root */
  10450.             if (farg[0] < 0.0) {
  10451.                 failed = 1;
  10452.                 if (fndiags)
  10453.                   ckmakmsg(fnval,FNVALL,
  10454.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10455.             } else
  10456.               fpresult = sqrt(farg[0]);
  10457.             break;
  10458.           case FN_FPSUB:                /* FP subtract */
  10459.             fpresult = farg[0] - farg[1];
  10460.             break;
  10461.           case FN_FPROU:                /* FP round */
  10462.             fpresult = farg[0];
  10463.             break;
  10464.           case FN_FPSIN:                /* FP sine */
  10465.             fpresult = (CKFLOAT) sin(farg[0]);
  10466.             break;
  10467.           case FN_FPCOS:                /* FP cosine */
  10468.             fpresult = (CKFLOAT) cos(farg[0]);
  10469.             break;
  10470.           case FN_FPTAN:                /* FP tangent */
  10471.             fpresult = (CKFLOAT) tan(farg[0]);
  10472.             break;
  10473.           case FN_FPMAX:
  10474.             fpresult = (farg[0] > farg[1]) ? farg[0] : farg[1];
  10475.             break;
  10476.           case FN_FPMIN:
  10477.             fpresult = (farg[0] < farg[1]) ? farg[0] : farg[1];
  10478.             break;
  10479.         }
  10480.  
  10481.         /* Get here with fpresult = function result */
  10482.  
  10483.         if (errno) {                    /* If range or domain error */
  10484.             failed = 1;
  10485.             if (fndiags)
  10486.               ckmakmsg(fnval,FNVALL,
  10487.                        "<ERROR:FLOATING-POINT-OP:\\f",fn,"()>",NULL);
  10488.         }
  10489.         if (failed)                     /* and/or any other kind of error, */
  10490.           goto fnend;                   /* fail. */
  10491. #ifndef COMMENT
  10492.         /* Call routine containing code that was formerly inline */
  10493.         ckstrncpy(fnval,fpformat(fpresult,places,cx == FN_FPROU),FNVALL);
  10494. #else
  10495.         {
  10496.             char fbuf[16];              /* For creating printf format */
  10497.             if (!fp_rounding &&         /* If printf doesn't round, */
  10498.                 (places > 0 ||          /* round result to decimal places. */
  10499.                  (places == 0 && cx == FN_FPROU)))
  10500.               fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  10501.             if (places > 0) {                   /* If places specified */
  10502.                 /* use specified places to write given number of digits */
  10503.                 sprintf(fbuf,"%%0.%df",places); /* SAFE */
  10504.                 sprintf(fnval,fbuf,fpresult);   /* SAFE */
  10505.             } else {                            /* Otherwise... */
  10506. #ifdef COMMENT
  10507. /*
  10508.   Here we want to print exactly fp_digits significant digits, no matter which
  10509.   side of the decimal point they are on.  That is, we want want the default
  10510.   format to show the maximum number of non-garbage digits, AND we want the last
  10511.   such digit to be rounded.  Of course there is no way to do that, since the
  10512.   digit after the last non-garbage digit is, well, garbage.  So the following
  10513.   clever ruse does no good.
  10514. */
  10515.                 int sign = 0, m = 0;
  10516.                 sprintf(fnval,"%f",fpresult);
  10517.                 if (fnval[0] == '-') sign = 1;
  10518.                 for (i = sign; i < FNVALL; i++) {
  10519.                     if (isdigit(fnval[i]))
  10520.                       m++;
  10521.                     else
  10522.                       break;
  10523.                 }
  10524.                 if (m > 1) {
  10525.                     int d = fp_digits - m;
  10526.                     if (d < 1) d = 1;
  10527.                     sprintf(fbuf,"%%%d.%df",fp_digits+sign+1,d);
  10528.                 } else {
  10529.                     sprintf(fbuf,"%%0.%df",fp_digits);
  10530.                 }
  10531.                 sprintf(fnval,fbuf,fpresult);
  10532. #else
  10533.                 /* Go for max precision */
  10534.                 sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  10535.                 sprintf(fnval,fbuf,fpresult); /* SAFE */
  10536.  
  10537. #endif /* COMMENT */
  10538.             }
  10539.             if (fnval[0] == '-') sign = 1;
  10540.         }
  10541.         debug(F111,"fpresult 1",fnval,errno); /* Check for over/underflow */
  10542.         for (i = sign; fnval[i]; i++) { /* Give requested decimal places */
  10543.             if (fnval[i] == '.')        /* First find the decimal point */
  10544.               break;
  10545.             else if (i > fp_digits + sign - 1) /* replacing garbage */
  10546.               fnval[i] = '0';           /* digits with 0... */
  10547.         }
  10548.         if (fnval[i] == '.') {          /* Have decimal point */
  10549.             int gotend = 0;
  10550.             /* d < 0 so truncate fraction */
  10551.             if (places < 0 || (places == 0 && cx == FN_FPROU)) {
  10552.                 fnval[i] = NUL;
  10553.             } else if (places > 0) {    /* d > 0 so this many decimal places */
  10554.                 i++;                           /* First digit after decimal */
  10555.                 for (j = 0; j < places; j++) { /* Truncate after d decimal */
  10556.                     if (!fnval[j+i])           /* places or extend to d  */
  10557.                       gotend = 1;              /* decimal places. */
  10558.                     if (gotend || j+i+sign > fp_digits)
  10559.                       fnval[j+i] = '0';
  10560.                 }
  10561.                 fnval[j+i] = NUL;
  10562.             } else {                    /* d == 0 so Do The Right Thing */
  10563.                 for (j = (int)strlen(fnval) - 1; j > i+1; j--) {
  10564.                     if ((j - sign) > fp_digits)
  10565.                       fnval[j] = '0';
  10566.                     if (fnval[j] == '0')
  10567.                       fnval[j] = NUL;   /* Strip useless trailing 0's. */
  10568.                     else
  10569.                       break;
  10570.                 }
  10571.             }
  10572.         }
  10573. #endif /* COMMENT */
  10574.         debug(F111,"fpresult 2",fnval,errno);
  10575.         goto fnend;
  10576.  
  10577.     }
  10578. #endif /* FNFLOAT */
  10579.  
  10580. #ifdef CKCHANNELIO
  10581.     if (cx == FN_FSTAT  ||              /* File functions */
  10582.         cx == FN_FPOS   ||
  10583.         cx == FN_FEOF   ||
  10584.         cx == FN_FGCHAR ||
  10585.         cx == FN_FGLINE ||
  10586.         cx == FN_FGBLK  ||
  10587.         cx == FN_FPCHAR ||
  10588.         cx == FN_FPLINE ||
  10589.         cx == FN_FPBLK  ||
  10590.         cx == FN_NLINE  ||
  10591.         cx == FN_FERMSG ||
  10592.         cx == FN_FILNO) {
  10593.         int x = 0, t = 0, channel;
  10594.         long z;
  10595.         extern int z_maxchan;
  10596.  
  10597.         failed = 1;                     /* Assume failure */
  10598.         p = fnval;                      /* until we validate args */
  10599.         if (cx == FN_FERMSG) {
  10600.             extern int z_error;
  10601.             if (argn < 1) {
  10602.                 x = z_error;
  10603.             } else if (chknum(bp[0])) {
  10604.                 x = atoi(bp[0]);
  10605.             } else if (fndiags)
  10606.               ckmakmsg(fnval,FNVALL,
  10607.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10608.             failed = 0;
  10609.             ckstrncpy(fnval,ckferror(x),FNVALL);
  10610.             goto fnend;
  10611.         }
  10612.         if (argn < 1) {                 /* All file functions need channel */
  10613.             if (fndiags)
  10614.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10615.             goto fnend;
  10616.         }
  10617.         if (rdigits(bp[0])) {           /* Channel must be numeric */
  10618.             channel = atoi(bp[0]);
  10619.         } else {                        /* Fail if it isn't */
  10620.             if (fndiags)
  10621.               ckmakmsg(fnval,FNVALL,
  10622.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10623.             goto fnend;
  10624.         }
  10625.         if (channel < 0 || channel > z_maxchan) { /* Check channel range */
  10626.             if (fndiags)
  10627.               ckmakmsg(fnval,FNVALL,
  10628.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10629.             goto fnend;
  10630.         }
  10631.         x = z_getmode(channel);         /* Find out about the channel */
  10632.  
  10633.         failed = 0;                     /* Assume success from here down */
  10634.         if (cx == FN_FSTAT) {           /* Status / modes of channel */
  10635.             if (x > -1)
  10636.               x &= FM_RWB;              /* Mask out irrelevant bits */
  10637.             else                        /* In this case not open is OK */
  10638.               x = 0;                    /* 0 if not open, 1-7 if open */
  10639.             sprintf(fnval,"%d",x);      /* SAFE */
  10640.             goto fnend;
  10641.         } else if (x < 1) {             /* Not \f_status() so must be open */
  10642.             failed = 1;
  10643.             if (fndiags)
  10644.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_OPEN:\\f",fn,"()>",NULL);
  10645.             goto fnend;
  10646.         }
  10647.         switch (y) {                    /* Do the requested function */
  10648.           case FN_FPOS:                 /* Get position */
  10649.             z = z_getpos(channel);
  10650.             sprintf(fnval,"%ld",z);     /* SAFE */
  10651.             goto fnend;
  10652.  
  10653.           case FN_NLINE:                /* Get line number */
  10654.             z = z_getline(channel);
  10655.             sprintf(fnval,"%ld",z);     /* SAFE */
  10656.             goto fnend;
  10657.  
  10658.           case FN_FEOF:                 /* Check EOF */
  10659.             t = 0;
  10660.             if (x & FM_EOF) t = 1;
  10661.             sprintf(fnval,"%d",t);      /* SAFE */
  10662.             goto fnend;
  10663.  
  10664.           case FN_FILNO:                /* Get file handle */
  10665.             x = z_getfnum(channel);
  10666.             sprintf(fnval,"%d",x);      /* SAFE */
  10667.             goto fnend;
  10668.  
  10669.           case FN_FPBLK:                /* Read or write block */
  10670.           case FN_FGBLK:
  10671.             if (argn < 2) {
  10672.                 if (fndiags)
  10673.                   ckmakmsg(fnval,FNVALL,
  10674.                            "<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10675.                 goto fnend;
  10676.             }
  10677.             if (rdigits(bp[1])) {
  10678.                 t = atoi(bp[1]);
  10679.             } else {
  10680.                 if (fndiags)
  10681.                   ckmakmsg(fnval,FNVALL,
  10682.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10683.                 goto fnend;
  10684.             }
  10685.           case FN_FGCHAR:               /* Read or write character or line */
  10686.           case FN_FPCHAR:
  10687.           case FN_FGLINE:
  10688.           case FN_FPLINE:
  10689.             fnval[0] = NUL;
  10690.             switch (y) {
  10691.               case FN_FGCHAR: t = z_in(channel,fnval,FNVALL,1,1); break;
  10692.               case FN_FGLINE: t = z_in(channel,fnval,FNVALL,FNVALL-1,0); break;
  10693.               case FN_FGBLK:
  10694.                 if (t >= FNVALL) t = FNVALL - 1;
  10695.                 t = z_in(channel,fnval,FNVALL,t,1);
  10696.                 break;
  10697.               case FN_FPCHAR: t = z_out(channel,bp[1],1,1);  break;
  10698.               case FN_FPLINE: t = z_out(channel,bp[1],-1,0); break;
  10699.               case FN_FPBLK:  t = z_out(channel,bp[1],-1,1); break;
  10700.             }
  10701.             if (t < 0) {                /* Handle read/write error */
  10702.                 failed = 1;
  10703.                 if (fndiags && t != FX_EOF)
  10704.                   ckmakmsg(fnval,FNVALL,
  10705.                            "<ERROR:FILE_ERROR_%d:\\f",fn,"()>",NULL);
  10706.                 goto fnend;
  10707.             }
  10708.             if (cx == FN_FGCHAR)        /* Null terminate char */
  10709.               fnval[1] = NUL;
  10710.             /* Write (put) functions return numeric status code */
  10711.             if (cx == FN_FPCHAR || cx == FN_FPLINE || cx == FN_FPBLK)
  10712.               sprintf(fnval,"%d",t);    /* SAFE */
  10713.             goto fnend;
  10714.         }
  10715.     }
  10716. #endif /* CKCHANNELIO */
  10717.  
  10718.     if (cx == FN_PATTERN) {             /* \fpattern() */
  10719.         ispattern = 1;
  10720.         if (argn > 0) {
  10721.             p = fnval;
  10722.             ckstrncpy(fnval,bp[0],FNVALL);
  10723.         } else p = "";
  10724.         goto fnend;
  10725.     }
  10726.  
  10727.     if (cx == FN_HEX2N || cx == FN_OCT2N) { /* \fhex2n(), \foct2n() */
  10728.         p = "0";
  10729.         if (argn < 1)
  10730.           goto fnend;
  10731.         p = ckradix(bp[0], ((cx == FN_HEX2N) ? 16 : 8), 10);
  10732.         if (!p) {
  10733.             if (fndiags)
  10734.               ckmakmsg(fnval,FNVALL,
  10735.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10736.             goto fnend;
  10737.         }
  10738.         failed = 0;
  10739.         ckstrncpy(fnval,p,FNVALL);
  10740.         p = fnval;
  10741.         goto fnend;
  10742.     }
  10743.  
  10744.     if (cx == FN_HEX2IP) {
  10745.         int c[2], ip[4], i, k;
  10746.         p = "0";
  10747.         if (argn < 1)
  10748.           goto fnend;
  10749.         s = bp[0];
  10750.         if ((int)strlen(s) != 8) {
  10751.             failed = 1;
  10752.             if (fndiags)
  10753.               ckmakmsg(fnval,FNVALL,
  10754.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10755.             goto fnend;
  10756.         }
  10757.         p = fnval;
  10758.         for (k = 0; k < 8; k += 2) {
  10759.             for (i = 0; i < 2; i++) {
  10760.                 c[i] = *s++;
  10761.                 if (islower(c[i])) c[i] = toupper(c[i]);
  10762.                 if (c[i] >= '0' && c[i] <= '9') {
  10763.                     c[i] -= 0x30;
  10764.                 } else if (c[i] >= 'A' && c[i] <= 'F') {
  10765.                     c[i] -= 0x37;
  10766.                 } else {
  10767.                     failed = 1;
  10768.                     if (fndiags)
  10769.                       ckmakmsg(fnval,FNVALL,
  10770.                                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10771.                     goto fnend;
  10772.                 }
  10773.                 ip[k/2] = c[0] << 4 | c[1];
  10774.             }
  10775.             sprintf(p,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10776.         }
  10777.         goto fnend;
  10778.     }
  10779.     if (cx == FN_IP2HEX) {
  10780.         int ip[4], i;
  10781.         char * q;
  10782.         p = "00000000";
  10783.         if (argn < 1)
  10784.           goto fnend;
  10785.         s = bp[0];
  10786.         p = fnval;
  10787.         for (i = 0; i < 3; i++) {
  10788.             q = ckstrchr(s,'.');
  10789.             if (q) {
  10790.                 *q++ = NUL;
  10791.                 ip[i] = atoi(s);
  10792.                 s = q;
  10793.             } else {
  10794.                 failed = 1;
  10795.                 if (fndiags)
  10796.                   ckmakmsg(fnval,FNVALL,
  10797.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10798.                 goto fnend;
  10799.             }
  10800.         }
  10801.         ip[3] = atoi(s);
  10802.         sprintf(p,"%02x%02x%02x%02x",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10803.         goto fnend;
  10804.     }
  10805.     if (cx == FN_RADIX) {
  10806.         failed = 1;
  10807.         p = fnval;
  10808.         if (argn < 3) {
  10809.             if (fndiags)
  10810.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10811.             goto fnend;
  10812.         }
  10813.         if (!rdigits(bp[1]) || !rdigits(bp[2])) {
  10814.             if (fndiags)
  10815.               ckmakmsg(fnval,FNVALL,
  10816.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10817.             goto fnend;
  10818.         }
  10819.         p = ckradix(bp[0],atoi(bp[1]),atoi(bp[2]));
  10820.         if (!p) {
  10821.             if (fndiags)
  10822.               ckmakmsg(fnval,FNVALL,
  10823.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10824.             goto fnend;
  10825.         }
  10826.         failed = 0;
  10827.         ckstrncpy(fnval,p,FNVALL);
  10828.         p = fnval;
  10829.         goto fnend;
  10830.     }
  10831.     if (cx == FN_JOIN) {
  10832.         int i, x, y, z, flag, hi, lo, max, seplen, grouping = 0;
  10833.         char abuf[16], c, *s, *q, *sep = NULL;
  10834.         char * gr_opn = "\"{'([<";      /* Group open brackets */
  10835.         char * gr_cls = "\"}')]>";      /* Group close brackets */
  10836.         char lb[2], rb[2];              /* Selected left and right brackets */
  10837.  
  10838.         failed = 1;                     /* Assume failure */
  10839.         fnval[0] = NUL;
  10840.         debug(F101,"FNJOIN ARGN","",argn);
  10841.  
  10842.         ckstrncpy(abuf,bp[0],16);       /* Get array reference */
  10843.         s = abuf;
  10844.         if ((x = arraybounds(s,&lo,&hi)) < 0) {  /* Get index and bounds */
  10845.             if (fndiags)
  10846.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10847.             goto fnend;
  10848.         }
  10849.         p = fnval;                      /* Point to result */
  10850.         max = a_dim[x];                 /* Size of array */
  10851.         if (lo < 0) lo = 1;             /* Use given range if any */
  10852.         if (lo > max) lo = max;
  10853. #ifdef COMMENT
  10854.     hi = max;
  10855. #else
  10856. /*
  10857.   This is a workaround for the problem in which the dimension of the \&_[]
  10858.   array (but not its contents) grows upon entry to a SWITCH block.  But this
  10859.   code prevents the dimension from growing.  Go figure.
  10860. */
  10861.         if (hi < 0) {            /* Bounds not given */
  10862.             if (x)            /* Regular array */
  10863.           hi = max;
  10864.         else            /* Argument vector array */
  10865.           for (hi = max; hi >= lo; hi--) { /* ignore any trailing */
  10866.           if (!a_ptr[x][hi]) continue; /* empty elements */
  10867.           if (!*(a_ptr[x][hi])) continue;
  10868.           break;
  10869.           }
  10870.     }
  10871. #endif /* COMMENT */
  10872.         if (hi > max) hi = max;
  10873.         failed = 0;                     /* Unset failure flag */
  10874.         if (max < 1)
  10875.           goto fnend;
  10876.         sep = " ";                      /* Separator */
  10877.         if (argn > 1)
  10878.           if (bp[1])
  10879.             if (*bp[1])
  10880.               sep = bp[1];
  10881.         lb[0] = NUL;
  10882.         rb[0] = NUL;
  10883.         lb[1] = NUL;
  10884.         rb[1] = NUL;
  10885.         if (argn > 2) {                 /* Grouping? */
  10886.             char * bp2 = bp[2];
  10887.             if (!bp2) bp2 = "0";
  10888.             if (!*bp2) bp2 = "0";
  10889.             if (chknum(bp2)) {
  10890.                 grouping = atoi(bp2);
  10891.                 if (grouping < 0 || grouping > 63)
  10892.                   grouping = 1;
  10893.             } else {
  10894.                 failed = 1;
  10895.                 if (fndiags)
  10896.                   ckmakmsg(fnval,FNVALL,
  10897.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10898.                 goto fnend;
  10899.             }
  10900.             if (grouping) {             /* Take lowest-order one */
  10901.                 int j, k;               /* and set the others to 0 */
  10902.                 for (k = 0; k < 6; k++) {
  10903.                     j = 1 << k;
  10904.                     if (grouping & j) {
  10905.                         lb[0] = gr_opn[k];
  10906.                         rb[0] = gr_cls[k];
  10907.                         break;
  10908.                     }
  10909.                 }
  10910.             }
  10911.         }
  10912.         if (argn > 3)                   /* Nonzero 4th arg for no separator */
  10913.           if (chknum(bp[3]))
  10914.             if (atoi(bp[3]) > 0)
  10915.               sep = NULL;
  10916.         if (!sep) {
  10917.             sep = "";
  10918.             seplen = 0;
  10919.         } else
  10920.           seplen = strlen(sep);
  10921.         for (i = lo; i <= hi; i++) {    /* Loop thru selected array elements */
  10922.             s = a_ptr[x][i];            /* Get next element */
  10923.             if (!s)
  10924.               s = "";
  10925.             flag = 0;                   /* Buffer overrun flag */
  10926.             if (grouping) {             /* Does this element need quoting? */
  10927.                 q = s;                  /* Look for spaces */
  10928.                 while ((c = *q++)) { if (c == SP) { flag++; break; } }
  10929.             }
  10930.             y = strlen(s);              /* Get length of this element */
  10931.             if (cx == 0 && grouping)    /* If empty it might need quoting */
  10932.               flag = 1;
  10933.             if (flag) {                 /* Add grouping if needed */
  10934.                 char * s2 = NULL;
  10935.                 y += 2;
  10936.                 if ((q = (char *)malloc(y+1))) {
  10937.                     ckmakmsg(q,y+1,(char *)lb,s,(char *)rb,NULL);
  10938.                     makestr(&s2,q);
  10939.                     free(q);
  10940.                     s = s2;
  10941.                 }
  10942.             }
  10943.             z = 0;                      /* Number of chars copied */
  10944.             flag = 0;                   /* flag is now buffer-overrun flag */
  10945.             if (y > 0)                  /* If this string is not empty */
  10946.               z = ckstrncat(fnval,s,FNVALL); /* copy it. */
  10947.             if (z < y)                  /* Check for buffer overrun. */
  10948.               flag++;
  10949.             if (!flag && *sep && i < hi) { /* If buffer still has room */
  10950.                 z = ckstrncat(fnval,sep,FNVALL); /* copy delimiter */
  10951.                 if (z < seplen)
  10952.                   flag++;
  10953.             }
  10954.             if (flag) {
  10955.                 failed = 1;
  10956.                 if (fndiags)
  10957.                   ckmakmsg(fnval,FNVALL,
  10958.                            "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10959.                 goto fnend;
  10960.             }
  10961.         }
  10962.     isjoin = 1;
  10963.         goto fnend;
  10964.     }
  10965.     if (cx == FN_SUBST) {               /* \fsubstitute() */
  10966.         CHAR c, * s, * r, * tp[2], buf1[256], buf2[256], buf3[256];
  10967.         int len, i, j, state = 0, lo = 0, hi = 0;
  10968.  
  10969.         failed = 0;
  10970.         p = fnval;                      /* Result pointer */
  10971.         *p = NUL;
  10972.         if (!bp[0])                     /* No target, no result*/
  10973.           goto fnend;
  10974.  
  10975.         len = strlen(bp[0]);            /* Length of source */
  10976.         if (len == 0)
  10977.           goto fnend;
  10978.         if (len > FNVALL) {
  10979.             failed = 1;
  10980.             if (fndiags)
  10981.               ckmakmsg(fnval,FNVALL,
  10982.                        "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10983.             goto fnend;
  10984.         }
  10985.         if (!bp[1]) {
  10986.             ckstrncpy(bp[0],fnval,FNVALL);
  10987.             goto fnend;
  10988.         }
  10989.         tp[0] = buf1;                   /* For s2-s3 interpretation loop */
  10990.         tp[1] = buf2;
  10991.  
  10992.         for (i = 0; i < 256; i++) {     /* Initialize working buffers */
  10993.             buf1[i] = 0;                /* s2 expansion buffer */
  10994.             buf2[i] = 0;                /* s3 expansion buffer */
  10995.             buf3[i] = i;                /* Translation table */
  10996.         }
  10997.         for (i = 0; i < 2; i++) {       /* Interpret s2 and s3 */
  10998.             s = (CHAR *)bp[i+1];        /* Arg pointer */
  10999.             if (!s) s = (CHAR *)"";
  11000.             r = tp[i];                  /* To construct interpreted arg */
  11001.             j = 0;                      /* Output buf pointer */
  11002.             state = 0;                  /* Initial state */
  11003.             while (c = *s++) {          /* Loop thru arg chars */
  11004.                 if (j > 255)            /* Output buf full */
  11005.                   break;
  11006.                 switch (state) {
  11007.                   case 0:               /* Normal state */
  11008.                     switch (c) {
  11009.                       case '\\':        /* Have quote */
  11010.                         state = 1;
  11011.                         break;
  11012.                       case '[':         /* Have range starter */
  11013.                         state = 2;
  11014.                         break;
  11015.                       default:          /* Anything else */
  11016.                         r[j++] = c;
  11017.                         break;
  11018.                     }
  11019.                     continue;
  11020.                   case 1:               /* Quoted char */
  11021.                     r[j++] = c;
  11022.                     state = 0;
  11023.                     continue;
  11024.                   case 2:               /* Range bottom */
  11025.                     lo = c;
  11026.                     state++;
  11027.                     continue;
  11028.                   case 3:               /* Range separater */
  11029.                     if (c != '-') {
  11030.                         failed = 1;
  11031.                         if (fndiags)
  11032.                           ckmakmsg(fnval,FNVALL,
  11033.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  11034.                         goto fnend;
  11035.                     }
  11036.                     state++;
  11037.                     continue;
  11038.                   case 4:               /* Range top */
  11039.                     hi = c;
  11040.                     state++;
  11041.                     continue;
  11042.                   case 5:               /* Range end */
  11043.                     if (c != ']') {
  11044.                         failed = 1;
  11045.                         if (fndiags)
  11046.                           ckmakmsg(fnval,FNVALL,
  11047.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  11048.                         goto fnend;
  11049.                     }
  11050.                     for (k = lo; k <= hi && j < 255; k++) /* Fill in */
  11051.                       r[j++] = k;
  11052.                     lo = 0; hi = 0;     /* Reset */
  11053.                     state = 0;
  11054.                     continue;
  11055.                 }
  11056.             }
  11057.         }
  11058.         for (i = 0; i < 256 && buf1[i]; i++) {  /* Create translation table */
  11059.             k = (unsigned)buf1[i];
  11060.             buf3[k] = buf2[i];
  11061.         }
  11062.         s = (CHAR *)bp[0];              /* Point to source string */
  11063.         for (i = 0; i < len; i++) {     /* Translation loop */
  11064.             k = (unsigned)s[i];         /* Get next char */
  11065.             if (!buf3[k])               /* Remove this char */
  11066.               continue;
  11067.             *p++ = buf3[k];             /* Substitute this char */
  11068.         }
  11069.         *p = NUL;
  11070.         p = fnval;
  11071.         goto fnend;
  11072.     }
  11073.  
  11074. #ifndef NOSEXP
  11075.     if (cx == FN_SEXP) {                /* \fsexpression(arg1) */
  11076.         char * p2;
  11077.         fsexpflag++;
  11078.         p = (argn > 0) ? dosexp(bp[0]) : "";
  11079.         fsexpflag--;
  11080.         p2 = fnval;
  11081.         while ((*p2++ = *p++)) ;
  11082.         p = fnval;
  11083.         goto fnend;
  11084.     }
  11085. #endif /* NOSEXP */
  11086.  
  11087.     if (cx == FN_CMDSTK) {              /* \fcmdstack(n1,n2) */
  11088.         int i, j, k;
  11089.         char * s;
  11090.  
  11091.         if (bp[0])
  11092.           val1 = *(bp[0]) ? evalx(bp[0]) : ckitoa(cmdlvl);
  11093.         else
  11094.           val1 = ckitoa(cmdlvl);
  11095. #ifdef COMMENT
  11096.         free(bp[0]);                    /* (evalx() always uses same buffer) */
  11097.         bp[0] = NULL;                   /* (not any more!) */
  11098. #endif /* COMMENT */
  11099.         failed = 1;
  11100.         if (argn > 1) {
  11101. #ifdef COMMENT
  11102.             makestr(&(bp[0]),val1);
  11103.             val1 = bp[0];
  11104. #endif /* COMMENT */
  11105.             val2 = *(bp[1]) ? evalx(bp[1]) : "0";
  11106.             if (!(chknum(val1) && chknum(val2))) {
  11107.                 if (fndiags)
  11108.                   ckmakmsg(fnval,FNVALL,
  11109.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11110.                 goto fnend;
  11111.             }
  11112.         } else {
  11113.             val1 = ckitoa(cmdlvl);
  11114.             val2 = "0";
  11115.         }
  11116.         i = atoi(val1);                 /* Level */
  11117.         j = atoi(val2);                 /* Flags */
  11118.         if (i < 0 || i > cmdlvl) {
  11119.             if (fndiags)
  11120.               ckmakmsg(fnval,FNVALL,
  11121.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11122.             goto fnend;
  11123.         }
  11124.         failed = 0;
  11125.         p = fnval;
  11126.         k = cmdstk[i].src;              /* What (prompt, file, macro) */
  11127.         if (j) {
  11128.             ckstrncpy(fnval,ckitoa(k),FNVALL);
  11129.             goto fnend;
  11130.         }
  11131.         switch (k) {
  11132.           case CMD_KB:
  11133.             ckstrncpy(fnval,"(prompt)",FNVALL);
  11134.             break;
  11135.           case CMD_TF:
  11136.             s = tfnam[cmdstk[i].lvl];
  11137.             if (!zfnqfp(s,FNVALL,fnval))
  11138.               ckstrncpy(fnval,s,FNVALL);
  11139.             break;
  11140.           case CMD_MD:
  11141.             ckstrncpy(fnval,m_arg[cmdstk[i].lvl][0],FNVALL);
  11142.             break;
  11143.         }
  11144.         goto fnend;
  11145.     }
  11146. #ifdef CKFLOAT
  11147.     if (cx == FN_DIFDATE) {             /* \fdiffdates(d1,d2) */
  11148.         char * d1, * d2;
  11149.         d1 = bp[0] ? bp[0] : ckdate();
  11150.         d2 = bp[1] ? bp[1] : ckdate();
  11151.         p = (char *)cmdiffdate(d1,d2);
  11152.         if (!p) {
  11153.             failed = 1;
  11154.             if (fndiags) {
  11155.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11156.                 p = fnval;
  11157.             }
  11158.         }
  11159.         goto fnend;
  11160.     }
  11161. #endif /* CKFLOAT */
  11162.     if (cx == FN_CMPDATE) {             /* \fcmddates(d1,d2) */
  11163.         int x = 0;
  11164.         char d1[18], d2[18], * dp;
  11165.         failed = 0;
  11166.         d1[0] = NUL;
  11167.         d2[0] = NUL;
  11168.         p = fnval;
  11169.         dp = cmcvtdate(bp[0],1);
  11170.         if (dp) {
  11171.             ckstrncpy(d1,dp,18);
  11172.             if ((dp = cmcvtdate(bp[1],1))) {
  11173.                 ckstrncpy(d2,dp,18);
  11174.                 x = 1;
  11175.             }
  11176.         }
  11177.         if (x == 0) {
  11178.             failed = 1;
  11179.             if (fndiags)
  11180.               ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11181.         } else {
  11182.             x = strcmp(d1,d2);
  11183.             if (x > 0)
  11184.               x = 1;
  11185.             else if (x < 0)
  11186.               x = -1;
  11187.             sprintf(fnval,"%d",x);
  11188.         }
  11189.         goto fnend;
  11190.     }
  11191.     if (cx == FN_TOGMT) {               /* \futcdate(d1) */
  11192.         char * d1, * dp;
  11193.         char datebuf[32];
  11194.         char d2[32];
  11195.         p = fnval;
  11196.         failed = 1;
  11197.         if ((dp = cmcvtdate(bp[0],1))) { /* The given date */
  11198.             ckstrncpy(datebuf,dp,18);
  11199.             ckstrncpy(d2,dp,18);        /* local time */
  11200.             ckstrncat(datebuf,"Z",19);  /* Same time GMT */
  11201.             if ((dp = cmcvtdate(datebuf,1))) /* converted to local time */
  11202.               ckstrncpy(datebuf,dp,18);
  11203.             if ((p = (char *)cmdiffdate(d2,datebuf))) { /* Get offset */
  11204.                 ckstrncat(d2,p,32);     /* Append offset to local time */
  11205.                 if ((dp = cmcvtdate(d2,1))) {
  11206.                     failed = 0;
  11207.                     ckstrncpy(fnval,dp,FNVALL);
  11208.                     p = fnval;
  11209.                 }
  11210.             }
  11211.         }
  11212.         if (failed && fndiags)
  11213.           ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11214.         goto fnend;
  11215.     }
  11216.     if (cx == FN_DELSEC) {              /* \fdelta2secs(delta-time) */
  11217.         long secs;
  11218.         p = fnval;
  11219.         if ((x = delta2sec(bp[0],&secs)) < 0) {
  11220.             failed = 1;
  11221.             if (fndiags)
  11222.               ckmakmsg(fnval,FNVALL,
  11223.                        (x == -1) ?
  11224.                          "<ERROR:BAD_DELTA_TIME:\\f" :
  11225.                          "<ERROR:OVERFLOW:\\f",
  11226.                        fn,
  11227.                        "()>",
  11228.                        NULL
  11229.                        );
  11230.             goto fnend;
  11231.         }
  11232.         sprintf(p,"%ld",secs);
  11233.         goto fnend;
  11234.     }
  11235.     if (cx == FN_PC_DU) {
  11236.         char c, * s = bp[0];
  11237.         if (!s) s = "";
  11238.         p = fnval;
  11239.         while ((c = *s++)) {
  11240.             if (c == ':') {
  11241.                 if (*s != '\\')
  11242.                   *p++ = '/';
  11243.             } else if (c == '\\') {
  11244.                 *p++ = '/';
  11245.             } else {
  11246.                 *p++ = c;
  11247.             }
  11248.         }
  11249.         *p = NUL;
  11250.         p = fnval;
  11251.         goto fnend;
  11252.     }
  11253.     if (cx == FN_PC_UD) {               /* Unix to DOS path */
  11254.         char c, * s = bp[0];
  11255.         if (!s) s = "";
  11256.         if (*s == '~') {                /* Skip leading tilde */
  11257.             s++;
  11258.             if (*s == '/')
  11259.               s++;
  11260.         }
  11261.         p = fnval;
  11262.         while ((c = *s++))
  11263.           *p ++ = (c == '/') ? '\\' : c;
  11264.         *p = NUL;
  11265.         p = fnval;
  11266.         goto fnend;
  11267.     }
  11268.     if (cx == FN_KWVAL) {               /* Keyword=Value */
  11269.         p = dokwval(bp[0],bp[1]?*(bp[1]):'=');
  11270.         goto fnend;
  11271.     }
  11272. #ifdef COMMENT
  11273. /* Cute idea but doesn't work */
  11274.     if (cx == FN_SLEEP || cx == FN_MSLEEP) {
  11275.         p = "";
  11276.         if (chknum(bp[0])) {
  11277.             x = atoi(bp[0]);
  11278.         } else {
  11279.             failed = 1;
  11280.             if (fndiags) {
  11281.                 ckmakmsg(fnval,FNVALL,
  11282.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11283.                 p = fnval;
  11284.             }
  11285.             goto fnend;
  11286.         }
  11287.         if (cx == FN_SLEEP)
  11288.           x *= 1000;
  11289.         msleep(x);
  11290.         goto fnend;
  11291.     }
  11292. #endif /* COMMENT */
  11293.  
  11294. #ifdef NT
  11295.     if (cx == FN_SNAME) {
  11296.         GetShortPathName(bp[0],fnval,FNVALL);
  11297.         goto fnend;
  11298.     }
  11299.     if (cx == FN_LNAME) {
  11300.         ckGetLongPathName(bp[0],fnval,FNVALL);
  11301.         goto fnend;
  11302.     }
  11303. #endif /* NT */
  11304.  
  11305. /* Note: when adding new functions remember to update dohfunc in ckuus2.c. */
  11306.  
  11307.     failed = 1;
  11308.     if (fndiags)
  11309.       ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN_FUNCTION:\\f",fn,"()>",NULL);
  11310.  
  11311.   fnend:
  11312.     /* Free temporary storage for aguments */
  11313.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  11314.     fndepth--;
  11315.     if (failed) {                       /* Handle failure */
  11316.         debug(F111,"fnend",fnval,errno);
  11317.         if (!p) p = "";
  11318.         if (p[0]) {
  11319.             /* In case this wasn't caught above... */
  11320.             k = strlen(p);
  11321.             if (p[0] != '<' && p[k-1] != '>') {
  11322.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_ARG:\\f",fn,"()>",NULL);
  11323.                 p = fnval;
  11324.             }
  11325.         } else {
  11326.             ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN:\\f",fn,"()>",NULL);
  11327.             p = fnval;
  11328.         }
  11329.         if (fnerror)                    /* SET FUNCTION ERROR ON */
  11330.           fnsuccess = 0;                /* Make command fail (see ckuus5.c) */
  11331.         debug(F111,"fneval failed",p,fnsuccess);
  11332.         if (fndiags)                    /* SET FUNCTION DIAGNOSTICS ON */
  11333.           printf("?%s\n",p);            /* Print error message now. */
  11334.         else
  11335.           return("");                   /* Return nothing. */
  11336.     }
  11337.     return(p);
  11338. }
  11339. #endif /* NOSPL */
  11340.  
  11341. static char ckpidbuf[32] = "????";
  11342.  
  11343. #ifdef VMS
  11344. _PROTOTYP(long zgpid,(void));
  11345. #endif /* VMS */
  11346.  
  11347. char *
  11348. ckgetpid() {                            /* Return pid as string */
  11349. #ifdef CK_PID
  11350. #ifdef OS2
  11351. #define getpid _getpid
  11352.     unsigned long zz;
  11353. #else
  11354.     long zz;
  11355. #endif /* OS2 */
  11356. #ifdef VMS
  11357.     zz = zgpid();
  11358. #else
  11359.     zz = getpid();
  11360. #endif /* VMS */
  11361.     sprintf(ckpidbuf,"%ld",zz);         /* SAFE */
  11362. #endif /* CK_PID */
  11363.     return((char *)ckpidbuf);
  11364. }
  11365.  
  11366. #ifndef NOSPL
  11367. #define EMBUFLEN 128                    /* Error message buffer length */
  11368.  
  11369. static char embuf[EMBUFLEN+1];
  11370.  
  11371. char *                                  /* Evaluate builtin variable */
  11372. nvlook(s) char *s; {
  11373.     int x, y, cx;
  11374.     long z;
  11375.     char *p;
  11376. #ifndef NODIAL
  11377.     MDMINF * m;
  11378. #endif /* NODIAL */
  11379. #ifndef NOKVERBS                        /* Keyboard macro material */
  11380.     extern int keymac, keymacx;
  11381. #endif /* NOKVERBS */
  11382. #ifdef CK_LOGIN
  11383.     extern int isguest;
  11384. #endif /* CK_LOGIN */
  11385.     if (!s) s = "";
  11386.     x = strlen(s);
  11387.     if (fndiags) {                      /* FUNCTION DIAGNOSTIC ON */
  11388.         if (x + 32 < EMBUFLEN)
  11389.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE:\\v(%s)>",s); /* SAFE */
  11390.         else
  11391.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE>"); /* SAFE */
  11392.     } else                              /* FUNCTION DIAGNOSTIC OFF */
  11393.       embuf[0] = NUL;
  11394.     x = VVBUFL;
  11395.     p = vvbuf;
  11396.     if (zzstring(s,&p,&x) < 0) {        /* e.g. for \v(\%a) */
  11397.         y = -1;
  11398.     } else {
  11399.         s = vvbuf;
  11400.         y = lookup(vartab,s,nvars,&x);
  11401.     }
  11402.     cx = y;                             /* y is too generic */
  11403. #ifndef NODIAL
  11404.     m = (mdmtyp > 0) ? modemp[mdmtyp] : NULL; /* For \v(m_xxx) variables */
  11405. #endif /* NODIAL */
  11406.  
  11407.     debug(F101,"nvlook y","",y);
  11408.  
  11409.     switch (y) {
  11410.       case VN_ARGC:                     /* ARGC */
  11411.         sprintf(vvbuf,"%d",maclvl < 0 ? topargc : macargc[maclvl]); /* SAFE */
  11412.         return(vvbuf);
  11413.  
  11414.       case VN_ARGS:                     /* ARGS */
  11415.         sprintf(vvbuf,"%d",xargs);      /* SAFE */
  11416.         return(vvbuf);
  11417.  
  11418.       case VN_COUN:                     /* COUNT */
  11419.         sprintf(vvbuf,"%d",count[cmdlvl]); /* SAFE */
  11420.         return(vvbuf);
  11421.  
  11422.       case VN_DATE:                     /* DATE */
  11423.         ztime(&p);                      /* Get "asctime" string */
  11424.         if (p == NULL || *p == NUL) return(NULL);
  11425.         vvbuf[0] = p[8];                /* dd */
  11426.         vvbuf[1] = p[9];
  11427.         vvbuf[2] = SP;
  11428.         vvbuf[3] = p[4];                /* mmm */
  11429.         vvbuf[4] = p[5];
  11430.         vvbuf[5] = p[6];
  11431.         vvbuf[6] = SP;
  11432.         for (x = 20; x < 24; x++)       /* yyyy */
  11433.           vvbuf[x - 13] = p[x];
  11434.         vvbuf[11] = NUL;
  11435.         return(vvbuf);
  11436.  
  11437.       case VN_NDAT:                     /* Numeric date */
  11438.         ckstrncpy(vvbuf,zzndate(),VVBUFL);
  11439.         return(vvbuf);
  11440.  
  11441.       case VN_DIRE:                     /* DIRECTORY */
  11442.         s = zgtdir();                   /* Get current directory */
  11443.         if (!s)
  11444. #ifdef UNIXOROSK
  11445.           s = "./";
  11446. #else
  11447. #ifdef VMS
  11448.           s = "[]";
  11449. #else
  11450.           s = "";
  11451. #endif /* VMS */
  11452. #endif /* UNIXOROSK */
  11453.         ckstrncpy(vvbuf,s,VVBUFL);
  11454.         s = vvbuf;
  11455. #ifdef UNIXOROSK
  11456.         x = strlen(s);
  11457.         if (x < VVBUFL - 1) {
  11458.             if (s[x-1] != '/') {
  11459.                 s[x] = '/';
  11460.                 s[x+1] = NUL;
  11461.             }
  11462.         }
  11463. #endif /* UNIXOROSK */
  11464.         return(s);
  11465.  
  11466.       case VN_FILE:                     /* filespec */
  11467.         return(fspec);
  11468.  
  11469.       case VN_HOST:                     /* host name */
  11470.         if (*myhost) {                  /* If known */
  11471.             return(myhost);             /* return it. */
  11472.         } else {                        /* Otherwise */
  11473.             ckstrncpy(vvbuf,"unknown",VVBUFL); /* just say "unknown" */
  11474.             return(vvbuf);
  11475.         }
  11476.  
  11477.       case VN_SYST:                     /* System type */
  11478. #ifdef UNIX
  11479.         ckstrncpy(vvbuf,"UNIX",VVBUFL);
  11480. #else
  11481. #ifdef VMS
  11482.         ckstrncpy(vvbuf,"VMS",VVBUFL);
  11483. #else
  11484. #ifdef OSK
  11485.         ckstrncpy(vvbuf,"OS9/68K",VVBUFL);
  11486. #else
  11487. #ifdef AMIGA
  11488.         ckstrncpy(vvbuf,"Amiga",VVBUFL);
  11489. #else
  11490. #ifdef MAC
  11491.         ckstrncpy(vvbuf,"Macintosh",VVBUFL);
  11492. #else
  11493. #ifdef OS2
  11494. #ifdef NT
  11495.         ckstrncpy(vvbuf,"WIN32",VVBUFL) ;
  11496. #else /* NT */
  11497.         ckstrncpy(vvbuf,"OS/2",VVBUFL);
  11498. #endif /* NT */
  11499. #else
  11500. #ifdef datageneral
  11501.         ckstrncpy(vvbuf,"AOS/VS",VVBUFL);
  11502. #else
  11503. #ifdef GEMDOS
  11504.         ckstrncpy(vvbuf,"Atari_ST",VVBUFL);
  11505. #else
  11506. #ifdef STRATUS
  11507.         ckstrncpy(vvbuf,"Stratus_VOS",VVBUFL);
  11508. #else
  11509.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11510. #endif /* STRATUS */
  11511. #endif /* GEMDOS */
  11512. #endif /* datageneral */
  11513. #endif /* OS2 */
  11514. #endif /* MAC */
  11515. #endif /* AMIGA */
  11516. #endif /* OSK */
  11517. #endif /* VMS */
  11518. #endif /* UNIX */
  11519.         return(vvbuf);
  11520.  
  11521.       case VN_SYSV:                     /* System herald */
  11522. #ifdef IKSD
  11523. #ifdef CK_LOGIN
  11524.         if (inserver && isguest)
  11525.           return("");
  11526. #endif /* CK_LOGIN */
  11527. #endif /* IKSD */
  11528.         for (x = y = 0; x < VVBUFL; x++) {
  11529.             if (ckxsys[x] == SP && y == 0) continue;
  11530.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  11531.         }
  11532.         vvbuf[y] = NUL;
  11533.         return(vvbuf);
  11534.     } /* Break up long switch statements... */
  11535.  
  11536.     switch(y) {
  11537.       case VN_TIME:                     /* TIME. Assumes that ztime returns */
  11538.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11539.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11540.           return("");
  11541.         for (x = 11; x < 19; x++)       /* copy hh:mm:ss */
  11542.           vvbuf[x - 11] = p[x];         /* to vvbuf */
  11543.         vvbuf[8] = NUL;                 /* terminate */
  11544.         return(vvbuf);                  /* and return it */
  11545.  
  11546.       case VN_NTIM:                     /* Numeric time */
  11547.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11548.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11549.           return(NULL);
  11550.         z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  11551.         sprintf(vvbuf,"%ld",z);         /* SAFE */
  11552.         return(vvbuf);
  11553.  
  11554. #ifdef CK_TTYFD
  11555.       case VN_TTYF:                     /* TTY file descriptor */
  11556.         sprintf(vvbuf,"%d",             /* SAFE */
  11557. #ifdef VMS
  11558.                 vmsttyfd()
  11559. #else
  11560.                 ttyfd
  11561. #endif /* VMS */
  11562.                 );
  11563.         return(vvbuf);
  11564. #endif /* CK_TTYFD */
  11565.  
  11566.       case VN_VERS:                     /* Numeric Kermit version number */
  11567.         sprintf(vvbuf,"%ld",vernum);    /* SAFE */
  11568.         return(vvbuf);
  11569.  
  11570.       case VN_XVNUM:                    /* Product-specific version number */
  11571.         sprintf(vvbuf,"%ld",xvernum);   /* SAFE */
  11572.         return(vvbuf);
  11573.  
  11574.       case VN_HOME:                     /* Home directory */
  11575.         return(homepath());
  11576.  
  11577.       case VN_IBUF:                     /* INPUT buffer */
  11578.         return((char *)inpbuf);
  11579.  
  11580.       case VN_ICHR:                     /* INPUT character */
  11581.         inchar[1] = NUL;
  11582.         return((char *)inchar);
  11583.  
  11584.       case VN_ICNT:                     /* INPUT character count */
  11585.         sprintf(vvbuf,"%d",incount);    /* SAFE */
  11586.         return(vvbuf);
  11587.  
  11588.       case VN_SPEE: {                   /* Transmission SPEED */
  11589.           long t;
  11590.           t = ttgspd();
  11591.           if (t < 0L)
  11592.             sprintf(vvbuf,"unknown");   /* SAFE */
  11593.           else
  11594.             sprintf(vvbuf,"%ld",t);     /* SAFE */
  11595.           return(vvbuf);
  11596.       }
  11597.  
  11598.       case VN_SUCC:                     /* SUCCESS flag */
  11599.         /* Note inverted sense */
  11600.         sprintf(vvbuf,"%d",(success == 0) ? 1 : 0); /* SAFE */
  11601.         return(vvbuf);
  11602.  
  11603.       case VN_LINE: {                   /* LINE */
  11604. #ifdef DEBUG
  11605.           if (deblog) {
  11606.               debug(F111,"\\v(line) local",ttname,local);
  11607.               debug(F111,"\\v(line) inserver","",inserver);
  11608. #ifdef TNCODE
  11609.               debug(F111,"\\v(line) tcp_incoming","",tcp_incoming);
  11610. #endif /* TNCODE */
  11611. #ifdef CK_TAPI
  11612.               debug(F111,"\\v(line) tttapi","",tttapi);
  11613. #endif /* CK_TAPI */
  11614.           }
  11615. #endif /* DEBUG */
  11616.  
  11617. #ifdef CK_TAPI
  11618.           if (tttapi) {                 /* If I have made a TAPI connection */
  11619.               int i;                    /* return the TAPI device name */
  11620.               for (i = 0; i < ntapiline; i++) {
  11621.                   if (!strcmp(ttname,tapilinetab[i].kwd)) {
  11622.                       p = _tapilinetab[i].kwd;
  11623.                       return(p);
  11624.                   }
  11625.               }
  11626.           }
  11627. #endif /* CK_TAPI */
  11628. #ifndef NOXFER
  11629.           if (inserver                  /* If I am a TCP server */
  11630. #ifdef TNCODE
  11631.               || tcp_incoming
  11632. #endif /* TNCODE */
  11633.               )
  11634. #ifdef TCPSOCKET
  11635.             p = ckgetpeer();            /* return peer name */
  11636.           else
  11637. #endif /* TCPSOCKET */
  11638. #endif /* NOXFER */
  11639.           if (local)                    /* Otherwise if in local mode */
  11640.             p = (char *) ttname;        /* return SET LINE / SET HOST name */
  11641.           else                          /* Otherwise */
  11642.             p = "";                     /* return empty string */
  11643.           if (!p)                       /* In case ckgetpeer() returns */
  11644.             p = "";                     /* null pointer... */
  11645.           debug(F110,"\\v(line) p",p,0);
  11646.           if (!*p)
  11647.             p = (char *) ttname;
  11648.           return(p);
  11649.       }
  11650.       case VN_PROG:                     /* Program name */
  11651.         return("C-Kermit");
  11652.  
  11653.     } /* Break up long switch statements... */
  11654.  
  11655.     switch(y) {
  11656.       case VN_RET:                      /* Value of most recent RETURN */
  11657.         debug(F111,"\\v(return)",mrval[maclvl+1],maclvl+1);
  11658.         p = mrval[maclvl+1];
  11659.         if (p == NULL) p = "";
  11660.         return(p);
  11661.  
  11662.       case VN_FFC:                      /* Size of most recent file */
  11663.         sprintf(vvbuf, "%ld", ffc);     /* SAFE */
  11664.         return(vvbuf);
  11665.  
  11666.       case VN_TFC:                      /* Size of most recent file group */
  11667.         sprintf(vvbuf, "%ld", tfc);     /* SAFE */
  11668.         return(vvbuf);
  11669.  
  11670.       case VN_CPU:                      /* CPU type */
  11671. #ifdef IKSD
  11672. #ifdef CK_LOGIN
  11673.         if (inserver && isguest)
  11674.           return("");
  11675. #endif /* CK_LOGIN */
  11676. #endif /* IKSD */
  11677. #ifdef OS2
  11678.          {
  11679.             char * getcpu(void) ;
  11680.             return getcpu();
  11681.          }
  11682. #else /* OS2 */
  11683. #ifdef CKCPU
  11684.         return(CKCPU);                  /* Traditionally, compile-time value */
  11685. #else
  11686. #ifdef CK_UTSNAME
  11687.         {                               /* But if none, try runtime value */
  11688.             extern char unm_mch[];
  11689.             return((char *)unm_mch);
  11690.         }
  11691. #else
  11692.         return("unknown");
  11693. #endif /* CK_UTSNAME */
  11694. #endif /* CKCPU */
  11695. #endif /* OS2 */
  11696.  
  11697.       case VN_CMDL:                     /* Command level */
  11698.         sprintf(vvbuf, "%d", cmdlvl);   /* SAFE */
  11699.         return(vvbuf);
  11700.  
  11701.       case VN_DAY:                      /* Day of week */
  11702.         ztime(&p);
  11703.         if (p != NULL && *p != NUL)     /* ztime() succeeded. */
  11704.           ckstrncpy(vvbuf,p,4);
  11705.         else
  11706.           vvbuf[0] = NUL;               /* ztime() failed. */
  11707.         return(vvbuf);                  /* Return what we got. */
  11708.  
  11709.       case VN_NDAY: {                   /* Numeric day of week */
  11710.           long k;
  11711.           z = mjd(zzndate());           /* Get modified Julian date */
  11712.           k = (((int)(z % 7L)) + 3) % 7; /* Get day number */
  11713.           sprintf(vvbuf,"%ld",k);       /* SAFE */
  11714.           return(vvbuf);
  11715.       }
  11716.  
  11717.       case VN_LCL:                      /* Local (vs remote) mode */
  11718.         ckstrncpy(vvbuf, local ? "1" : "0",VVBUFL);
  11719.         return(vvbuf);
  11720.  
  11721.       case VN_CMDS:                     /* Command source */
  11722.         if (cmdstk[cmdlvl].src == CMD_KB)
  11723.           ckstrncpy(vvbuf,"prompt",VVBUFL);
  11724.         else if (cmdstk[cmdlvl].src == CMD_MD)
  11725.           ckstrncpy(vvbuf,"macro",VVBUFL);
  11726.         else if (cmdstk[cmdlvl].src == CMD_TF)
  11727.           ckstrncpy(vvbuf,"file",VVBUFL);
  11728.         else
  11729.           ckstrncpy(vvbuf,"unknown",VVBUFL);
  11730.         return(vvbuf);
  11731.  
  11732.       case VN_CMDF:                     /* Current command file name */
  11733. #ifdef COMMENT                          /* (see comments above) */
  11734.         if (tfnam[tlevel]) {            /* (near dblbs declaration) */
  11735.             dblbs(tfnam[tlevel],vvbuf,VVBUFL);
  11736.             return(vvbuf);
  11737.         } else return("");
  11738. #else
  11739.         if (tlevel < 0)
  11740.           return("");
  11741.         else
  11742.           return(tfnam[tlevel] ? tfnam[tlevel] : "");
  11743. #endif /* COMMENT */
  11744.  
  11745.       case VN_MAC:                      /* Current macro name */
  11746.         return((maclvl > -1) ? m_arg[maclvl][0] : "");
  11747.  
  11748.       case VN_EXIT:
  11749.         sprintf(vvbuf,"%d",xitsta);     /* SAFE */
  11750.         return(vvbuf);
  11751.  
  11752.     } /* Break up long switch statements... */
  11753.  
  11754.     switch(y) {
  11755.       case VN_PRTY: {                   /* Parity */
  11756.           char *ss;
  11757.           switch (parity) {
  11758.             case 0:   ss = "none";  break;
  11759.             case 'e': ss = "even";  break;
  11760.             case 'm': ss = "mark";  break;
  11761.             case 'o': ss = "odd";   break;
  11762.             case 's': ss = "space"; break;
  11763.             default:  ss = "unknown"; break;
  11764.           }
  11765.           ckstrncpy(vvbuf,ss,VVBUFL);
  11766.           return(vvbuf);
  11767.       }
  11768.  
  11769.       case VN_DIAL:
  11770.         sprintf(vvbuf,"%d",             /* SAFE */
  11771. #ifndef NODIAL
  11772.                 dialsta
  11773. #else
  11774.                 -1
  11775. #endif /* NODIAL */
  11776.                 );
  11777.         return(vvbuf);
  11778.  
  11779. #ifdef OS2
  11780.       case VN_KEYB:
  11781.         ckstrncpy(vvbuf,conkbg(),VVBUFL);
  11782.         return(vvbuf);
  11783.       case VN_SELCT: {
  11784. #ifndef NOLOCAL
  11785.           const char * selection = GetSelection();
  11786.           return( (char *) (selection ? selection : "" )) ;
  11787. #else
  11788.           return("");
  11789. #endif /* NOLOCAL */
  11790.       }
  11791. #endif /* OS2 */
  11792.  
  11793. #ifndef NOXFER
  11794.       case VN_CPS:
  11795.         sprintf(vvbuf,"%ld",tfcps);     /* SAFE */
  11796.         return(vvbuf);
  11797. #endif /* NOXFER */
  11798.  
  11799.       case VN_MODE:                     /* File transfer mode */
  11800.         switch (binary) {
  11801.           case XYFT_T: ckstrncpy(vvbuf,"text",VVBUFL); break;
  11802.           case XYFT_B:
  11803.           case XYFT_U: ckstrncpy(vvbuf,"binary",VVBUFL); break;
  11804.           case XYFT_I: ckstrncpy(vvbuf,"image",VVBUFL); break;
  11805.           case XYFT_L: ckstrncpy(vvbuf,"labeled",VVBUFL); break;
  11806.           case XYFT_M: ckstrncpy(vvbuf,"macbinary",VVBUFL); break;
  11807.           default:     ckstrncpy(vvbuf,"unknown",VVBUFL);
  11808.         }
  11809.         return(vvbuf);
  11810.  
  11811. #ifdef CK_REXX
  11812.       case VN_REXX:
  11813.         return(rexxbuf);
  11814. #endif /* CK_REXX */
  11815.  
  11816.       case VN_NEWL:                     /* System newline char or sequence */
  11817. #ifdef UNIX
  11818.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11819. #else
  11820. #ifdef datageneral
  11821.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11822. #else
  11823. #ifdef OSK
  11824.         ckstrncpy(vvbuf,"\15",VVBUFL);  /* Remember, these are octal... */
  11825. #else
  11826. #ifdef MAC
  11827.         ckstrncpy(vvbuf,"\15",VVBUFL);
  11828. #else
  11829. #ifdef OS2
  11830.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11831. #else
  11832. #ifdef STRATUS
  11833.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11834. #else
  11835. #ifdef VMS
  11836.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11837. #else
  11838. #ifdef AMIGA
  11839.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11840. #else
  11841. #ifdef GEMDOS
  11842.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11843. #else
  11844.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11845. #endif /* GEMDOS */
  11846. #endif /* AMIGA */
  11847. #endif /* VMS */
  11848. #endif /* STRATUS */
  11849. #endif /* OS2 */
  11850. #endif /* MAC */
  11851. #endif /* OSK */
  11852. #endif /* datageneral */
  11853. #endif /* UNIX */
  11854.         return(vvbuf);
  11855.  
  11856.       case VN_ROWS:                     /* ROWS */
  11857.       case VN_COLS:                     /* COLS */
  11858.         ckstrncpy(vvbuf,(cx == VN_ROWS) ? "24" : "80",VVBUFL); /* Default */
  11859. #ifdef CK_TTGWSIZ
  11860. #ifdef OS2
  11861.         if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  11862.           ttgwsiz();
  11863.         sprintf(vvbuf,"%d",             /* SAFE */
  11864.                 (cx == VN_ROWS) ? tt_rows[VTERM] : tt_cols[VTERM]);
  11865. #else /* OS2 */
  11866.         if (ttgwsiz() > 0)              /* Get window size */
  11867.           if (tt_cols > 0 && tt_rows > 0) /* sets tt_rows, tt_cols */
  11868.             sprintf(vvbuf,"%d",         /* SAFE */
  11869.                     (cx == VN_ROWS) ? tt_rows : tt_cols);
  11870. #endif /* OS2 */
  11871. #endif /* CK_TTGWSIZ */
  11872.         return(vvbuf);
  11873.  
  11874.       case VN_TTYP:
  11875. #ifdef NOTERM
  11876.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11877. #else
  11878. #ifdef OS2
  11879.         sprintf(vvbuf, "%s",            /* SAFE */
  11880.                 (tt_type >= 0 && tt_type <= max_tt) ?
  11881.                 tt_info[tt_type].x_name :
  11882.                 "unknown"
  11883.                 );
  11884. #else
  11885. #ifdef MAC
  11886.         ckstrncpy(vvbuf,"vt320",VVBUFL);
  11887. #else
  11888.         p = getenv("TERM");
  11889.         ckstrncpy(vvbuf,p ? p : "unknown",VVBUFL+1);
  11890. #endif /* MAC */
  11891. #endif /* OS2 */
  11892. #endif /* NOTERM */
  11893.         return(vvbuf);
  11894.  
  11895.       case VN_MINP:                     /* MINPUT */
  11896.         sprintf(vvbuf, "%d", m_found);  /* SAFE */
  11897.         return(vvbuf);
  11898.     } /* Break up long switch statements... */
  11899.  
  11900.     switch(y) {
  11901.       case VN_CONN:                     /* CONNECTION */
  11902.         if (!local) {
  11903.           ckstrncpy(vvbuf,"remote",VVBUFL);
  11904.         } else {
  11905.             if (!network)
  11906.               ckstrncpy(vvbuf,"serial",VVBUFL);
  11907. #ifdef TCPSOCKET
  11908.             else if (nettype == NET_TCPB || nettype == NET_TCPA) {
  11909.                 if (ttnproto == NP_TELNET)
  11910.                   ckstrncpy(vvbuf,"tcp/ip_telnet",VVBUFL);
  11911. #ifdef CK_SSL
  11912.                 else if (ttnproto == NP_SSL)
  11913.                   ckstrncpy(vvbuf,"tcp/ip_ssl",VVBUFL);
  11914.                 else if (ttnproto == NP_TLS)
  11915.                   ckstrncpy(vvbuf,"tcp/ip_tls",VVBUFL);
  11916. #endif /* CK_SSL */
  11917.                 else
  11918.                   ckstrncpy(vvbuf,"tcp/ip",VVBUFL);
  11919.             }
  11920. #endif /* TCPSOCKET */
  11921. #ifdef SSHBUILTIN
  11922.             else if (nettype == NET_SSH)
  11923.                   ckstrncpy(vvbuf,"tcp/ip_ssh",VVBUFL);
  11924. #endif /* SSHBUILTIN */
  11925. #ifdef ANYX25
  11926.             else if (nettype == NET_SX25 ||
  11927.                      nettype == NET_VX25 ||
  11928.                      nettype == NET_IX25
  11929.                      )
  11930.               ckstrncpy(vvbuf,"x.25",VVBUFL);
  11931. #endif /* ANYX25 */
  11932. #ifdef DECNET
  11933.             else if (nettype == NET_DEC) {
  11934.                 if (ttnproto == NP_LAT)
  11935.                   ckstrncpy(vvbuf,"decnet_lat",VVBUFL);
  11936.                 else if ( ttnproto == NP_CTERM )
  11937.                   ckstrncpy(vvbuf,"decnet_cterm",VVBUFL);
  11938.                 else
  11939.                   ckstrncpy(vvbuf,"decnet",VVBUFL);
  11940.             }
  11941. #endif /* DECNET */
  11942. #ifdef SUPERLAT
  11943.             else if (nettype == NET_SLAT)
  11944.               ckstrncpy(vvbuf,"superlat",VVBUFL);
  11945. #endif /* SUPERLAT */
  11946. #ifdef NETFILE
  11947.             else if (nettype == NET_FILE)
  11948.               ckstrncpy(vvbuf,"local_file",VVBUFL);
  11949. #endif /* NETFILE */
  11950. #ifdef NETCMD
  11951.             else if (nettype == NET_CMD)
  11952.               ckstrncpy(vvbuf,"pipe",VVBUFL);
  11953. #endif /* NETCMD */
  11954. #ifdef NETPTY
  11955.             else if (nettype == NET_PTY)
  11956.               ckstrncpy(vvbuf,"pseudoterminal",VVBUFL);
  11957. #endif /* NETPTY */
  11958. #ifdef NETDLL
  11959.             else if (nettype == NET_DLL)
  11960.               ckstrncpy(vvbuf,"dynamic_link_library",VVBUFL);
  11961. #endif /* NETDLL */
  11962.  
  11963. #ifdef NPIPE
  11964.             else if (nettype == NET_PIPE)
  11965.               ckstrncpy(vvbuf,"named_pipe",VVBUFL);
  11966. #endif /* NPIPE */
  11967. #ifdef CK_NETBIOS
  11968.             else if (nettype == NET_BIOS)
  11969.               ckstrncpy(vvbuf,"netbios",VVBUFL);
  11970. #endif /* CK_NETBIOS */
  11971.             else
  11972.               ckstrncpy(vvbuf,"unknown",VVBUFL);
  11973.         }
  11974.         return(vvbuf);
  11975.  
  11976. #ifndef NOXFER
  11977.       case VN_SYSI:                     /* System ID, Kermit code */
  11978.         return((char *)cksysid);
  11979. #endif /* NOXFER */
  11980.  
  11981. #ifdef OS2
  11982.       case VN_SPA: {
  11983.           unsigned long space = zdskspace(0);
  11984.           if (space > 0 && space < 1024)
  11985.             sprintf(vvbuf,"-1");
  11986.           else
  11987.             sprintf(vvbuf,"%lu",space); /* SAFE */
  11988.           return(vvbuf);
  11989.       }
  11990. #endif /* OS2 */
  11991.  
  11992. #ifndef NOXFER
  11993.       case VN_QUE: {
  11994.           extern char querybuf[];
  11995.           return(querybuf);
  11996.       }
  11997. #endif /* NOXFER */
  11998.  
  11999. #ifndef NOCSETS
  12000.       case VN_CSET:
  12001. #ifdef OS2
  12002.         sprintf(vvbuf,"cp%d",os2getcp()); /* SAFE */
  12003. #else
  12004.         ckstrncpy(vvbuf,fcsinfo[fcharset].keyword,VVBUFL+1);
  12005. #endif /* OS2 */
  12006.         return(vvbuf);
  12007. #endif /* NOCSETS */
  12008.  
  12009. #ifdef OS2
  12010.       case VN_EXEDIR:
  12011.         return(exedir);
  12012.       case VN_STAR:
  12013.         return(startupdir);
  12014. #else
  12015.       case VN_EXEDIR:
  12016.         return(exedir ? exedir : "");
  12017. #ifdef VMSORUNIX
  12018.       case VN_STAR:
  12019.         return(startupdir);
  12020. #endif /* VMSORUNIX */
  12021. #endif /* OS2 */
  12022.  
  12023.       case VN_INI:
  12024.         return(inidir);
  12025.  
  12026.       case VN_MDM:
  12027.         return(gmdmtyp());
  12028.  
  12029.       case VN_EVAL:
  12030.         return(evalbuf);
  12031.  
  12032. #ifndef NODIAL
  12033.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  12034.         return(diallcc ? diallcc : "");
  12035.  
  12036.       case VN_D_AC:                     /* DIAL AREA-CODE */
  12037.         return(diallac ? diallac : "");
  12038.  
  12039.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  12040.         return(dialixp ? dialixp : "");
  12041.  
  12042.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  12043.         return(dialldp ? dialldp : "");
  12044.  
  12045.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  12046.         return(diallcp ? diallcp : "");
  12047.  
  12048.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE that matched */
  12049.         return(matchpxx ? matchpxx : "");
  12050. #else
  12051.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  12052.       case VN_D_AC:                     /* DIAL AREA-CODE */
  12053.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  12054.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  12055.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  12056.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE */
  12057.         return("");
  12058. #endif /* NODIAL */
  12059.       case VN_UID:
  12060. #ifdef UNIX
  12061.         {
  12062.             extern char * whoami();     /* From ckufio.c... */
  12063. #ifdef IKSD
  12064.             if (inserver)
  12065.               return((char *)uidbuf);
  12066.             else
  12067. #endif /* IKSD */
  12068.               if (uidbuf[0])
  12069.                 return((char *)uidbuf);
  12070.               else
  12071.                 return(whoami());
  12072.         }
  12073. #else
  12074.         return((char *)uidbuf);
  12075. #endif /* UNIX */
  12076.     } /* Break up long switch statements... */
  12077.  
  12078.     switch(y) {
  12079.       case VN_PWD:
  12080. #ifdef OS2
  12081.         if (activecmd == XXOUT || activecmd == XXLNOUT) {
  12082.             ckstrncpy(vvbuf,pwbuf,VVBUFL);
  12083.             ck_encrypt((char *)vvbuf);
  12084.             return((char *)vvbuf);
  12085.         } else
  12086. #endif /* OS2 */
  12087.           return((char *)pwbuf);
  12088.  
  12089.       case VN_PRM:
  12090.         return((char *)prmbuf);
  12091.  
  12092.       case VN_PROTO:
  12093. #ifdef NOXFER
  12094.         return("none");
  12095. #else
  12096. #ifdef CK_XYZ
  12097.         return(ptab[protocol].p_name);
  12098. #else
  12099.         return("kermit");
  12100. #endif /* CK_XYZ */
  12101. #endif /* NOXFER */
  12102.  
  12103. #ifndef NOXFER
  12104. #ifdef CK_TMPDIR
  12105.       case VN_DLDIR:
  12106.         return(dldir ? dldir : "");
  12107. #endif /* CK_TMPDIR */
  12108. #endif /* NOXFER */
  12109.  
  12110. #ifndef NODIAL
  12111.       case VN_M_INI:                    /* Modem init string */
  12112.         return(dialini ? dialini : (m ? m->wake_str : ""));
  12113.  
  12114.       case VN_M_DCM:                    /* Modem dial command */
  12115.         return(dialcmd ? dialcmd : (m ? m->dial_str : ""));
  12116.  
  12117.       case VN_M_DCO:                    /* Modem data compression on */
  12118.         return(dialdcon ? dialdcon : (m ? m->dc_on_str : ""));
  12119.  
  12120.       case VN_M_DCX:                    /* Modem data compression off */
  12121.         return(dialdcoff ? dialdcoff : (m ? m->dc_off_str : ""));
  12122.  
  12123.       case VN_M_ECO:                    /* Modem error correction on */
  12124.         return(dialecon ? dialecon : (m ? m->ec_on_str : ""));
  12125.  
  12126.       case VN_M_ECX:                    /* Modem error correction off */
  12127.         return(dialecoff ? dialecoff : (m ? m->ec_off_str : ""));
  12128.  
  12129.       case VN_M_AAO:                    /* Modem autoanswer on */
  12130.         return(dialaaon ? dialaaon : (m ? m->aa_on_str : ""));
  12131.  
  12132.       case VN_M_AAX:                    /* Modem autoanswer off */
  12133.         return(dialaaoff ? dialaaoff : (m ? m->aa_off_str : ""));
  12134.  
  12135.       case VN_M_HUP:                    /* Modem hangup command */
  12136.         return(dialhcmd ? dialhcmd : (m ? m->hup_str : ""));
  12137.  
  12138.       case VN_M_HWF:                    /* Modem hardware flow command */
  12139.         return(dialhwfc ? dialhwfc : (m ? m->hwfc_str : ""));
  12140.  
  12141.       case VN_M_SWF:                    /* Modem software flow command */
  12142.         return(dialswfc ? dialswfc : (m ? m->swfc_str : ""));
  12143.  
  12144.       case VN_M_NFC:                    /* Modem no flow-control command */
  12145.         return(dialnofc ? dialnofc : (m ? m->nofc_str : ""));
  12146.  
  12147.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  12148.         return(dialpulse ? dialpulse : (m ? m->pulse : ""));
  12149.  
  12150.       case VN_M_TDM:                    /* Modem tone dialing mode */
  12151.         return(dialtone ? dialtone : (m ? m->tone : ""));
  12152.  
  12153.       case VN_M_NAM:                    /* Modem full name */
  12154.         return(dialname ? dialname : (m ? m->name : ""));
  12155. #else
  12156.       case VN_M_INI:                    /* Modem init string */
  12157.       case VN_M_DCM:                    /* Modem dial command */
  12158.       case VN_M_DCO:                    /* Modem data compression on */
  12159.       case VN_M_DCX:                    /* Modem data compression off */
  12160.       case VN_M_ECO:                    /* Modem error correction on */
  12161.       case VN_M_ECX:                    /* Modem error correction off */
  12162.       case VN_M_AAO:                    /* Modem autoanswer on */
  12163.       case VN_M_AAX:                    /* Modem autoanswer off */
  12164.       case VN_M_HUP:                    /* Modem hangup command */
  12165.       case VN_M_HWF:                    /* Modem hardware flow command */
  12166.       case VN_M_SWF:                    /* Modem software flow command */
  12167.       case VN_M_NFC:                    /* Modem no flow-control command */
  12168.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  12169.       case VN_M_TDM:                    /* Modem tone dialing mode */
  12170.       case VN_M_NAM:
  12171.         return("");
  12172. #endif /* NODIAL */
  12173.  
  12174.       case VN_ISTAT:                    /* INPUT status */
  12175.         sprintf(vvbuf, "%d", instatus); /* SAFE */
  12176.         return(vvbuf);
  12177.  
  12178.       case VN_TEMP:                     /* Temporary directory */
  12179.         if (tempdir) {
  12180.             p = tempdir;
  12181.         } else {
  12182. #ifdef OS2
  12183. #ifdef NT
  12184.             p = getenv("K95TMP");
  12185. #else
  12186.             p = getenv("K2TMP");
  12187. #endif /* NT */
  12188.             if ( !p )
  12189. #endif /* OS2 */
  12190.               p = getenv("CK_TMP");
  12191.             if (!p) p = getenv("TMPDIR");
  12192.             if (!p) p = getenv("TEMP");
  12193.             if (!p) p = getenv("TMP");
  12194.  
  12195. #ifdef OS2ORUNIX
  12196.             if (p) {
  12197.                 int len = strlen(p);
  12198.                 if (p[len-1] != '/'
  12199. #ifdef OS2
  12200.                     && p[len-1] != '\\'
  12201. #endif /* OS2 */
  12202.                      ) {
  12203.                     static char foo[CKMAXPATH];
  12204.                     ckstrncpy(foo,p,CKMAXPATH);
  12205.                     ckstrncat(foo,"/",CKMAXPATH);
  12206.                     p = foo;
  12207.                 }
  12208.             } else
  12209. #else /* OS2ORUNIX */
  12210.             if (!p)
  12211. #endif /* OS2ORUNIX */
  12212. #ifdef UNIX                             /* Systems that have a standard */
  12213.               p = "/tmp/";              /* temporary directory... */
  12214. #else
  12215. #ifdef datageneral
  12216.               p = ":TMP:";
  12217. #else
  12218.               p = "";
  12219. #endif /* datageneral */
  12220. #endif /* UNIX */
  12221.         }
  12222.         ckstrncpy(vvbuf,p,VVBUFL);
  12223.         p = vvbuf;
  12224.  
  12225. /* This needs generalizing for VOS, AOS/VS, etc... */
  12226.  
  12227.         while (*p) {
  12228. #ifdef OS2
  12229.             if (*p == '\\') *p = '/';
  12230. #endif /* OS2 */
  12231.             p++;
  12232.         }
  12233. #ifndef VMS
  12234.         if (p > vvbuf) {
  12235.             char c =                    /* Directory termination character */
  12236. #ifdef MAC
  12237.               ':'
  12238. #else
  12239. #ifdef datageneral
  12240.               ':'
  12241. #else
  12242. #ifdef STRATUS
  12243.               '>'
  12244. #else
  12245.               '/'
  12246. #endif /* STRATUS */
  12247. #endif /* datageneral */
  12248. #endif /* MAC */
  12249.                 ;
  12250.  
  12251.             if (*(p-1) != c) {
  12252.                 *p++ = c;
  12253.                 *p = NUL;
  12254.             }
  12255.         }
  12256. #endif /* VMS */
  12257.         return(vvbuf);
  12258.     } /* Break up long switch statements... */
  12259.  
  12260.     switch(y) {
  12261.       case VN_ERRNO:                    /* Error number */
  12262. #ifdef VMS
  12263.         {
  12264.             extern int vms_lasterr;
  12265.             sprintf(vvbuf, "%d", vms_lasterr); /* SAFE */
  12266.         }
  12267. #else
  12268.         sprintf(vvbuf, "%d", errno);    /* SAFE */
  12269. #endif /* VMS */
  12270.         return(vvbuf);
  12271.  
  12272.       case VN_ERSTR:                    /* Error string */
  12273.         ckstrncpy(vvbuf,ck_errstr(),VVBUFL);
  12274.         return(vvbuf);
  12275.  
  12276. #ifndef NOXFER
  12277.       case VN_RPSIZ:                    /* RECEIVE packet-length */
  12278.         sprintf(vvbuf,"%d",urpsiz);     /* SAFE */
  12279.         return(vvbuf);
  12280.  
  12281.       case VN_WINDO:                    /* WINDOW slots */
  12282.         sprintf(vvbuf,"%d",wslotr);     /* SAFE */
  12283.         return(vvbuf);
  12284. #endif /* NOXFER */
  12285.  
  12286.       case VN_TFLN:                     /* TAKE-file line number */
  12287.         if (tlevel > -1) {
  12288.             sprintf(vvbuf, "%d", tfline[tlevel]); /* SAFE */
  12289.             return(vvbuf);
  12290.         } else
  12291.           return("0");
  12292.  
  12293.       case VN_MDMSG:                    /* DIALRESULT */
  12294. #ifndef NODIAL
  12295.         return((char *)modemmsg);
  12296. #else
  12297.         return("");
  12298. #endif /* NODIAL */
  12299.  
  12300.       case VN_DNUM:                     /* DIALNUMBER */
  12301. #ifndef NODIAL
  12302.         return(dialnum ? (char *) dialnum : "");
  12303. #else
  12304.         return("");
  12305. #endif /* NODIAL */
  12306.  
  12307.       case VN_APC:
  12308.         sprintf(vvbuf, "%d",            /* SAFE */
  12309. #ifdef CK_APC
  12310.                 apcactive
  12311. #else
  12312.                 0
  12313. #endif /* CK_APC */
  12314.                 );
  12315.         return((char *)vvbuf);
  12316.  
  12317. #ifdef OS2
  12318. #ifndef NOKVERBS
  12319.       case VN_TRMK:
  12320.           sprintf(vvbuf, "%d", keymac); /* SAFE */
  12321.         return((char *)vvbuf);
  12322. #endif /* NOKVERBS */
  12323. #endif /* OS2 */
  12324.  
  12325.       case VN_IPADDR:
  12326. #ifdef TCPSOCKET
  12327. #ifndef OSK
  12328.       /* This dumps core on OS-9 for some reason, but only if executed */
  12329.       /* before we have made a TCP connection.  This is obviously not */
  12330.       /* the ideal fix. */
  12331.         if (!myipaddr[0])
  12332.           getlocalipaddr();
  12333. #endif /* OSK */
  12334. #endif /* TCPSOCKET */
  12335.         ckstrncpy(vvbuf,
  12336. #ifdef TCPSOCKET
  12337.                 (char *)myipaddr,
  12338. #else
  12339.                 "",
  12340. #endif /* TCPSOCKET */
  12341.                 VVBUFL);
  12342.         return((char *)vvbuf);
  12343.  
  12344. #ifndef NOXFER
  12345.       case VN_CRC16:                    /* CRC-16 of most recent transfer */
  12346.         sprintf(vvbuf,"%d",crc16);      /* SAFE */
  12347.         return(vvbuf);
  12348. #endif /* NOXFER */
  12349.  
  12350. #ifdef CK_PID
  12351.       case VN_PID:
  12352. #ifdef IKSD
  12353. #ifdef CK_LOGIN
  12354.         if (inserver && isguest)
  12355.           return("");
  12356. #endif /* CK_LOGIN */
  12357. #endif /* IKSD */
  12358.         return(ckgetpid());
  12359. #endif /* CK_PID */
  12360.  
  12361. #ifndef NOXFER
  12362.       case VN_FNAM: {                   /* \v(filename) */
  12363.           extern char filnam[], ofn1[], *sfspec, *rrfspec;
  12364.           char * tmp;
  12365.           switch (what) {               /* File transfer is in progress */
  12366. #ifdef NEWFTP
  12367.             case (W_FTP|W_RECV):
  12368.             case (W_FTP|W_SEND):
  12369.               return((char *)filnam);
  12370. #endif /* NEWFTP */
  12371.             case W_RECV:
  12372.             case W_REMO:
  12373.               return((char *)ofn1);
  12374.             default:                    /* Most recent file transferred */
  12375.               if (filnam[0]) {          /* (if any) */
  12376.                   return((char *)filnam);
  12377.               } else if (lastxfer & W_SEND && sfspec) {
  12378.                   if (fnspath == PATH_OFF)
  12379.                     zstrip(sfspec,&tmp);
  12380.                   else
  12381.                     tmp = sfspec;
  12382.                   return(tmp);
  12383.               } else if (lastxfer & W_RECV && rrfspec) {
  12384.                   if (fnrpath == PATH_OFF)
  12385.                     zstrip(rrfspec,&tmp);
  12386.                   else
  12387.                     tmp = rrfspec;
  12388.                   return(tmp);
  12389.               } else
  12390.                 return("");
  12391.           }
  12392.       }
  12393.       case VN_FNUM:                     /* \v(filenum) */
  12394.         sprintf(vvbuf,"%ld",filcnt);    /* SAFE */
  12395.         return((char *)vvbuf);
  12396. #endif /* NOXFER */
  12397.  
  12398. #ifdef PEXITSTAT
  12399.       case VN_PEXIT: {
  12400.           extern int pexitstat;
  12401.           sprintf(vvbuf,"%d",pexitstat); /* SAFE */
  12402.           return((char *)vvbuf);
  12403.       }
  12404. #endif /* PEXITSTAT */
  12405.  
  12406. #ifndef NOXFER
  12407.       case VN_P_8BIT:
  12408.         vvbuf[0] = parity ? ebq : NUL;
  12409.         vvbuf[1] = NUL;
  12410.         return((char *)vvbuf);
  12411.  
  12412.       case VN_P_CTL: {
  12413.           extern CHAR myctlq;
  12414.           vvbuf[0] = myctlq;
  12415.           vvbuf[1] = NUL;
  12416.           return((char *)vvbuf);
  12417.       }
  12418.       case VN_P_RPT: {
  12419.           extern int rptena;
  12420.           vvbuf[0] = rptena ? rptq : NUL;
  12421.           vvbuf[1] = NUL;
  12422.           return((char *)vvbuf);
  12423.       }
  12424. #endif /* NOXFER */
  12425.  
  12426. #ifdef OS2
  12427.       case VN_REGN:
  12428.         return(get_reg_name());
  12429.       case VN_REGO:
  12430.         return(get_reg_corp());
  12431.       case VN_REGS:
  12432.         return(get_reg_sn());
  12433. #endif /* OS2 */
  12434.     } /* Break up long switch statements... */
  12435.  
  12436.     switch(y) {
  12437.       case VN_XPROG:
  12438. #ifdef OS2
  12439. #ifdef NT
  12440. #ifdef KUI
  12441.         return("K-95G");
  12442. #else
  12443.         return("K-95");
  12444. #endif /* KUI */
  12445. #else
  12446.         return("K/2");
  12447. #endif /* NT */
  12448. #else
  12449.         return("C-Kermit");
  12450. #endif /* OS2 */
  12451.  
  12452.       case VN_EDITOR:
  12453. #ifdef NOFRILLS
  12454.         return("");
  12455. #else
  12456. #ifdef NOPUSH
  12457.         return("");
  12458. #else
  12459.         {
  12460.             extern char editor[];
  12461.             char *ss;
  12462.             if (!editor[0]) {
  12463.                 ss = getenv("EDITOR");
  12464.                 if (ss) {
  12465.                     ckstrncpy(editor,ss,CKMAXPATH);
  12466.                 }
  12467.             }
  12468.             debug(F110,"\\v(editor)",editor,0);
  12469.             return(editor[0] ? (char *)editor : "");
  12470.         }
  12471. #endif /* NOPUSH */
  12472. #endif /* NOFRILLS */
  12473.  
  12474.       case VN_EDOPT:
  12475. #ifdef NOFRILLS
  12476.         return("");
  12477. #else
  12478. #ifdef NOPUSH
  12479.         return("");
  12480. #else
  12481.         {
  12482.             extern char editopts[];
  12483.             return(editopts[0] ? (char *)editopts : "");
  12484.         }
  12485. #endif /* NOPUSH */
  12486. #endif /* NOFRILLS */
  12487.  
  12488.       case VN_EDFILE:
  12489. #ifdef NOFRILLS
  12490.         return("");
  12491. #else
  12492. #ifdef NOPUSH
  12493.         return("");
  12494. #else
  12495.         {
  12496.             extern char editfile[];
  12497.             return(editfile[0] ? (char *)editfile : "");
  12498.         }
  12499. #endif /* NOPUSH */
  12500. #endif /* NOFRILLS */
  12501.  
  12502. #ifdef BROWSER
  12503.       case VN_BROWSR: {
  12504.           extern char browser[];
  12505.           if (!browser[0]) {
  12506.               s = getenv("BROWSER");
  12507.               if (s) ckstrncpy(browser,s,CKMAXPATH);
  12508.           }
  12509.           return(browser[0] ? (char *)browser : "");
  12510.       }
  12511.       case VN_BROPT: {
  12512.           extern char browsopts[];
  12513.           return(browsopts[0] ? (char *)browsopts : "");
  12514.       }
  12515.       case VN_URL: {
  12516.           extern char browsurl[];
  12517.           return(browsurl[0] ? (char *)browsurl : "");
  12518.       }
  12519. #endif /* BROWSER */
  12520.       case VN_HERALD:
  12521.         return((char *)versio);
  12522.  
  12523.       case VN_TEST: {                   /* test */
  12524.           extern char * ck_s_test, * ck_s_tver;
  12525.           if (!ck_s_test) ck_s_test = "";
  12526.           if (!ck_s_tver) ck_s_tver = "";
  12527.           if (*ck_s_test) {
  12528.               ckstrncpy(vvbuf,ck_s_test,VVBUFL);
  12529.               if (*ck_s_tver) {
  12530.                   ckstrncat(vvbuf,".",VVBUFL);
  12531.                   ckstrncat(vvbuf,ck_s_tver,VVBUFL);
  12532.               }
  12533.           } else
  12534.             ckstrncpy(vvbuf,"0",VVBUFL);
  12535.           return((char *)vvbuf);
  12536.       }
  12537.  
  12538. #ifndef NOXFER
  12539.       case VN_XFSTAT:                   /* xferstatus */
  12540.         x = xferstat;                   /* Like success */
  12541.         if (x > -1) x = (x == 0) ? 1 : 0; /* External value is reversed */
  12542.         sprintf(vvbuf,"%d",x);          /* SAFE */
  12543.         return((char *)vvbuf);
  12544.  
  12545.       case VN_XFMSG:                    /* xfermsg */
  12546.         return((char *)epktmsg);
  12547.  
  12548. #ifndef NOMSEND
  12549.       case VN_SNDL: {                   /* sendlist */
  12550.           extern int filesinlist;
  12551.           sprintf(vvbuf,"%d",filesinlist); /* SAFE */
  12552.           return((char *)vvbuf);
  12553.       }
  12554. #endif /* NOMSEND */
  12555. #endif /* NOXFER */
  12556.  
  12557. #ifdef CK_TRIGGER
  12558.       case VN_TRIG: {
  12559.           extern char * triggerval;
  12560.           return(triggerval ? triggerval : "");
  12561.       }
  12562. #endif /* CK_TRIGGER */
  12563. #ifdef OS2MOUSE
  12564. #ifdef OS2
  12565.       case VN_MOU_X: {
  12566.           extern int MouseCurX;
  12567.           sprintf(vvbuf,"%d",MouseCurX); /* SAFE */
  12568.           return((char *)vvbuf);
  12569.       }
  12570.       case VN_MOU_Y: {
  12571.           extern int MouseCurY;
  12572.           sprintf(vvbuf,"%d",MouseCurY); /* SAFE */
  12573.           return((char *)vvbuf);
  12574.       }
  12575. #endif /* OS2 */
  12576. #endif /* OS2MOUSE */
  12577.       case VN_PRINT: {
  12578.           extern int printpipe;
  12579.           extern char * printername;
  12580. #ifdef PRINTSWI
  12581.           extern int noprinter;
  12582.           if (noprinter) return("");
  12583. #endif /* PRINTSWI */
  12584.           ckmakmsg(vvbuf,VVBUFL,
  12585.                    printpipe ? "|" : "",
  12586.                    printername ? printername :
  12587. #ifdef OS2
  12588.                    "PRN",
  12589. #else
  12590.                    "(default)",
  12591. #endif /* OS2 */
  12592.                    NULL,
  12593.                    NULL
  12594.                    );
  12595.           return((char *)vvbuf);
  12596.       }
  12597.     } /* Break up long switch statements... */
  12598.  
  12599.     switch(y) {
  12600.       case VN_ESC:                      /* Escape character */
  12601.         sprintf(vvbuf,"%d",escape);     /* SAFE */
  12602.         return((char *)vvbuf);
  12603.  
  12604.       case VN_INTIME:
  12605.         sprintf(vvbuf,"%ld",inetime);   /* SAFE */
  12606.         return((char *)vvbuf);
  12607.  
  12608.       case VN_INTMO:
  12609.         sprintf(vvbuf,"%d",inwait);     /* SAFE */
  12610.         return((char *)vvbuf);
  12611.  
  12612.       case VN_SECURE:
  12613.         if (0
  12614. #ifdef SSHBUILTIN
  12615.             || IS_SSH()
  12616. #endif /* SSHBUILTIN */
  12617. #ifdef CK_ENCRYPTION
  12618.             || ck_tn_encrypting() && ck_tn_decrypting()
  12619. #endif /* CK_ENCRYPTION */
  12620. #ifdef CK_SSL
  12621.             || tls_active_flag || ssl_active_flag
  12622. #endif /* CK_SSL */
  12623.             )
  12624.           return("1");
  12625.         else
  12626.           return("0");
  12627.  
  12628.       case VN_AUTHN:
  12629. #ifdef CK_AUTHENTICATION
  12630.         {
  12631.             extern char szUserNameAuthenticated[];
  12632.             return((char *)szUserNameAuthenticated);
  12633.         }
  12634. #else /* CK_AUTHENTICATION */
  12635.         return((char *)"");
  12636. #endif /* CK_AUTHENTICATION */
  12637.  
  12638.       case VN_AUTHS:
  12639. #ifdef CK_AUTHENTICATION
  12640.         switch (ck_tn_auth_valid()) {
  12641.           case AUTH_UNKNOWN:
  12642.             return((char *)"unknown");
  12643.           case AUTH_OTHER:
  12644.             return((char *)"other");
  12645.           case AUTH_USER:
  12646.             return((char *)"user");
  12647.           case AUTH_VALID:
  12648.             return((char *)"valid");
  12649.           case AUTH_REJECT:
  12650.           default:
  12651.             return((char *)"rejected");
  12652.         }
  12653. #else /* CK_AUTHENTICATION */
  12654.         return((char *)"rejected");
  12655. #endif /* CK_AUTHENTICATION */
  12656.  
  12657.       case VN_AUTHT:
  12658. #ifdef CK_AUTHENTICATION
  12659. #ifdef CK_SSL
  12660.         if ((ssl_active_flag || tls_active_flag) &&
  12661.             ck_tn_auth_valid() == AUTH_VALID &&
  12662.             (sstelnet ? (!TELOPT_U(TELOPT_AUTHENTICATION)) :
  12663.                         (!TELOPT_ME(TELOPT_AUTHENTICATION))) ||
  12664.              ck_tn_authenticated() == AUTHTYPE_NULL ||
  12665.              ck_tn_authenticated() == AUTHTYPE_AUTO)
  12666.           return("X_509_CERTIFICATE");
  12667.         else
  12668. #endif /* CK_SSL */
  12669.           return(AUTHTYPE_NAME(ck_tn_authenticated()));
  12670. #else /* CK_AUTHENTICATION */
  12671.         return((char *)"NULL");
  12672. #endif /* CK_AUTHENTICATION */
  12673.  
  12674. #ifdef CK_KERBEROS
  12675.       case VN_K4PRN: {
  12676.           extern char * krb4_d_principal;
  12677.           if (krb4_d_principal)
  12678.             ckstrncpy(vvbuf,krb4_d_principal,VVBUFL+1);
  12679.           else
  12680.             *vvbuf = NUL;
  12681.           return((char *)vvbuf);
  12682.       }
  12683.       case VN_K5PRN: {
  12684.           extern char * krb5_d_principal;
  12685.           if (krb5_d_principal)
  12686.             ckstrncpy(vvbuf,krb5_d_principal,VVBUFL+1);
  12687.           else
  12688.             *vvbuf = NUL;
  12689.           return((char *)vvbuf);
  12690.       }
  12691.       case VN_K4RLM: {
  12692.           extern char * krb4_d_realm;
  12693.           if (krb4_d_realm) {
  12694.               ckstrncpy(vvbuf,krb4_d_realm,VVBUFL+1);
  12695.           } else {
  12696.               char * s = ck_krb4_getrealm();
  12697.               ckstrncpy(vvbuf,s ? s : "",VVBUFL+1);
  12698.           }
  12699.           return((char *)vvbuf);
  12700.       }
  12701.       case VN_K4SRV: {
  12702.           extern char * krb4_d_srv;
  12703.           if (krb4_d_srv)
  12704.             ckstrncpy(vvbuf,krb4_d_srv,VVBUFL+1);
  12705.           else
  12706.             ckstrncpy(vvbuf,"rcmd",VVBUFL);
  12707.           return((char *)vvbuf);
  12708.       }
  12709.       case VN_K5RLM: {
  12710.           extern char * krb5_d_realm;
  12711.           extern char * krb5_d_cc;
  12712.           if (krb5_d_realm) {
  12713.               ckstrncpy(vvbuf,krb5_d_realm,VVBUFL+1);
  12714.           } else {
  12715.               char * s = ck_krb5_getrealm(krb5_d_cc);
  12716.               ckstrncpy(vvbuf,s,VVBUFL+1);
  12717.           }
  12718.           return((char *)vvbuf);
  12719.       }
  12720.       case VN_K5CC: {
  12721.           extern char * krb5_d_cc;
  12722.           if (krb5_d_cc)
  12723.             ckstrncpy(vvbuf,krb5_d_cc,VVBUFL+1);
  12724.           else
  12725.             ckstrncpy(vvbuf,ck_krb5_get_cc_name(),VVBUFL+1);
  12726.           return((char *)vvbuf);
  12727.       }
  12728.       case VN_K5SRV: {
  12729.           extern char * krb5_d_srv;
  12730.           if (krb5_d_srv)
  12731.             ckstrncpy(vvbuf,krb5_d_srv,VVBUFL+1);
  12732.           else
  12733.             ckstrncpy(vvbuf,"host",VVBUFL);
  12734.           return((char *)vvbuf);
  12735.       }
  12736.       case VN_K4ENO: {
  12737.         extern char * krb4_errno;
  12738.         sprintf(vvbuf,"%d",krb4_errno); /* SAFE */
  12739.         return((char *)vvbuf);
  12740.       }
  12741.       case VN_K5ENO: {
  12742.         extern char * krb5_errno;
  12743.         sprintf(vvbuf,"%d",krb5_errno); /* SAFE */
  12744.         return((char *)vvbuf);
  12745.       }
  12746.       case VN_K4EMSG: {
  12747.         extern char * krb4_errmsg;
  12748.         ckstrncpy(vvbuf,krb4_errmsg?krb4_errmsg:"",VVBUFL+1);
  12749.         return((char *)vvbuf);
  12750.       }
  12751.       case VN_K5EMSG: {
  12752.         extern char * krb5_errmsg;
  12753.         ckstrncpy(vvbuf,krb5_errmsg,VVBUFL+1);
  12754.         return((char *)vvbuf);
  12755.       }
  12756. #endif /* CK_KERBEROS */
  12757. #ifdef CK_SSL
  12758.       case VN_X509_S:
  12759.         if (ssl_active_flag)
  12760.           ckstrncpy(vvbuf,ssl_get_subject_name(ssl_con),VVBUFL+1);
  12761.         else if (tls_active_flag)
  12762.           ckstrncpy(vvbuf,ssl_get_subject_name(tls_con),VVBUFL+1);
  12763.         else
  12764.           ckstrncpy(vvbuf,"",VVBUFL+1);
  12765.         return((char *)vvbuf);
  12766.       case VN_X509_I:
  12767.         if (ssl_active_flag)
  12768.           ckstrncpy(vvbuf,ssl_get_issuer_name(ssl_con),VVBUFL+1);
  12769.         else if (tls_active_flag)
  12770.           ckstrncpy(vvbuf,ssl_get_issuer_name(tls_con),VVBUFL+1);
  12771.         else
  12772.           ckstrncpy(vvbuf,"",VVBUFL+1);
  12773.         return((char *)vvbuf);
  12774. #endif /* CK_SSL */
  12775.  
  12776.       case VN_OSNAM:
  12777. #ifdef IKSD
  12778. #ifdef CK_LOGIN
  12779.         if (inserver && isguest)
  12780.           return("");
  12781. #endif /* CK_LOGIN */
  12782. #endif /* IKSD */
  12783. #ifdef CK_UTSNAME
  12784.         {
  12785.             extern char unm_nam[];
  12786.             return((char *)unm_nam);
  12787.         }
  12788. #else
  12789.         for (x = y = 0; x < VVBUFL; x++) {
  12790.             if (ckxsys[x] == SP && cx == 0) continue;
  12791.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  12792.         }
  12793.         vvbuf[y] = NUL;
  12794.         return(vvbuf);
  12795. #endif /* CK_UTSNAME */
  12796.  
  12797.       case VN_OSVER: {
  12798. #ifdef CK_UTSNAME
  12799.           extern char unm_ver[];
  12800. #ifdef IKSD
  12801. #ifdef CK_LOGIN
  12802.           if (inserver && isguest)
  12803.             return("");
  12804. #endif /* CK_LOGIN */
  12805. #endif /* IKSD */
  12806.           return((char *)unm_ver);
  12807. #else
  12808.           return("");
  12809. #endif /* CK_UTSNAME */
  12810.       }
  12811.  
  12812.       case VN_OSREL: {
  12813. #ifdef CK_UTSNAME
  12814.           extern char unm_rel[];
  12815. #ifdef IKSD
  12816. #ifdef CK_LOGIN
  12817.           if (inserver && isguest)
  12818.             return("");
  12819. #endif /* CK_LOGIN */
  12820. #endif /* IKSD */
  12821.           return((char *)unm_rel);
  12822. #else
  12823.           return("");
  12824. #endif /* CK_UTSNAME */
  12825.       }
  12826.     } /* Break up long switch statements... */
  12827.  
  12828.     switch(y) {
  12829.       case VN_NAME: {
  12830.           extern char * myname;
  12831.           return(myname);
  12832.       }
  12833.  
  12834.       case VN_MODL: {
  12835. #ifdef CK_UTSNAME
  12836.           extern char unm_mod[], unm_mch[];
  12837.           int y = VVBUFL - 1;
  12838.           char * s = unm_mod;
  12839. #endif /* CK_UTSNAME */
  12840. #ifdef IKSD
  12841. #ifdef CK_LOGIN
  12842.           if (inserver && isguest)
  12843.             return("");
  12844. #endif /* CK_LOGIN */
  12845. #endif /* IKSD */
  12846.  
  12847. #ifdef COMMENT                          /* was HPUX */
  12848.           if (!unm_mod[0] && !nopush)
  12849.             zzstring("\\fcommand(model)",&s,&y);
  12850. /*
  12851.    Another possibility would be:
  12852.      "\\fcommand(ksh -c 'whence model 1>&- && model || uname -m')"
  12853.    But that would depend on having ksh.
  12854. */
  12855. #else
  12856. #ifdef OSF32                            /* Digital UNIX 3.2 and higher... */
  12857. /* Note: Ultrix has /etc/sizer, but it is not publicly executable. */
  12858. /* sizer -c outputs 'cpu:<tab><tab>"DECxxxx"' */
  12859.           if (!unm_mod[0]) {
  12860.               char * p;
  12861.               int flag = 0;
  12862.               zzstring("\\fcommand(/usr/sbin/sizer -c)",&s,&y);
  12863.               debug(F110,"DU model",unm_mod,0);
  12864.               s = unm_mod;
  12865.               p = unm_mod;
  12866.               while (*p) {              /* Extract the part in quotes */
  12867.                   if (*p == '"') {
  12868.                       if (flag)
  12869.                         break;
  12870.                       flag = 1;
  12871.                       p++;
  12872.                       continue;
  12873.                   }
  12874.                   if (flag)
  12875.                     *s++ = *p;
  12876.                   p++;
  12877.               }
  12878.               *s = NUL;
  12879.           }
  12880. #endif /* OSF32 */
  12881. #endif /* COMMENT */
  12882.  
  12883. #ifdef CK_UTSNAME
  12884.           if (unm_mod[0])
  12885.             return((char *)unm_mod);
  12886.           else
  12887.             return((char *)unm_mch);
  12888. #else
  12889.           return("");
  12890. #endif /* CK_UTSNAME */
  12891.       }
  12892.  
  12893. #ifdef IBMX25
  12894.       /* X.25 variables (local and remote address) */
  12895.       case VN_X25LA:
  12896.         if (!local_nua[0] && !x25local_nua(local_nua))
  12897.           *vvbuf = NULL;
  12898.         else
  12899.           ckstrncpy(vvbuf,local_nua,VVBUFL+1);
  12900.         return((char *)vvbuf);
  12901.  
  12902.       case VN_X25RA:
  12903.         if (!remote_nua[0])
  12904.           *vvbuf = NULL;
  12905.         else
  12906.           ckstrncpy(vvbuf,remote_nua,VVBUFL+1);
  12907.         return((char *)vvbuf);
  12908. #endif /* IBMX25 */
  12909.  
  12910. #ifndef NODIAL
  12911.       case VN_PDSFX: {
  12912.           extern char pdsfx[];
  12913.           return((char *)pdsfx);
  12914.       }
  12915.       case VN_DTYPE: {
  12916.           extern int dialtype;
  12917.           sprintf(vvbuf,"%d",dialtype); /* SAFE */
  12918.           return((char *)vvbuf);
  12919.       }
  12920. #endif /* NODIAL */
  12921.  
  12922. #ifdef UNIX
  12923.       case VN_LCKPID: {
  12924.           extern char lockpid[];
  12925.           return((char *)lockpid);
  12926.       }
  12927. #endif /* UNIX */
  12928.  
  12929. #ifndef NOXFER
  12930.       case VN_BLK:
  12931.         sprintf(vvbuf,"%d",bctr);       /* SAFE */
  12932.         return((char *)vvbuf);
  12933.  
  12934.       case VN_TFTIM:
  12935.         sprintf(vvbuf,                  /* SAFE */
  12936. #ifdef GFTIMER
  12937.                 "%ld", (long)(fptsecs + 0.5)
  12938. #else
  12939.                 "%d", tsecs
  12940. #endif /* GFTIMER */
  12941.                 );
  12942.         return((char *)vvbuf);
  12943. #endif /* NOXFER */
  12944.  
  12945.       case VN_HWPAR:
  12946.       case VN_SERIAL: {
  12947.           int sb;
  12948.           char c, * ss;
  12949.           extern int stopbits;
  12950.           vvbuf[0] = NUL;
  12951.           if (hwparity && local && !network)
  12952.             ss = parnam((char)hwparity);
  12953.           else
  12954.             ss = parnam((char)parity);
  12955.           if (cx == VN_HWPAR) {
  12956.               ckstrncpy(vvbuf,ss,VVBUFL);
  12957.               return((char *)vvbuf);
  12958.           }
  12959.           c = ss[0];
  12960.           if (islower(c)) c = toupper(c);
  12961.           sb = stopbits;
  12962.           if (sb < 1)
  12963.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  12964.           if (hwparity)
  12965.             sprintf(vvbuf," 8%c%d",c,sb); /* SAFE */
  12966.           else if (parity)
  12967.             sprintf(vvbuf," 7%c%d",c,sb); /* SAFE */
  12968.           else
  12969.             sprintf(vvbuf," 8N%d",sb);  /* SAFE */
  12970.           return((char *)vvbuf);
  12971.       }
  12972.  
  12973. #ifdef UNIX
  12974.       case VN_LCKDIR: {
  12975. #ifndef NOUUCP
  12976.           extern char * uucplockdir;
  12977.           ckstrncpy(vvbuf,uucplockdir,VVBUFL);
  12978.           x = strlen(vvbuf);
  12979.           if (x > 0) {
  12980.               if (vvbuf[x-1] != '/') {
  12981.                   vvbuf[x] = '/';
  12982.                   vvbuf[x+1] = NUL;
  12983.               }
  12984.           }
  12985. #else
  12986.           vvbuf[0] = NUL;
  12987. #endif /* NOUUCP */
  12988.           return((char *)vvbuf);
  12989.       }
  12990. #endif /* UNIX */
  12991.     } /* Break up long switch statements... */
  12992.  
  12993.     switch(y) {
  12994. #ifndef NODIAL
  12995.       case VN_DM_LP:
  12996.       case VN_DM_SP:
  12997.       case VN_DM_PD:
  12998.       case VN_DM_TD:
  12999.       case VN_DM_WA:
  13000.       case VN_DM_WD:
  13001.       case VN_DM_HF:
  13002.       case VN_DM_WB:
  13003.       case VN_DM_RC: {
  13004.           extern char * getdm();
  13005.           ckstrncpy(vvbuf,getdm(y),VVBUFL);
  13006.           return((char *)vvbuf);
  13007.       }
  13008. #endif /* NODIAL */
  13009.  
  13010.       case VN_TY_LN:
  13011.       case VN_TY_LC: {
  13012.           extern int typ_lines;
  13013.           sprintf(vvbuf,"%d",typ_lines); /* SAFE */
  13014.           return((char *)vvbuf);
  13015.       }
  13016.       case VN_TY_LM: {
  13017.           extern int typ_mtchs;
  13018.           sprintf(vvbuf,"%d",typ_mtchs); /* SAFE */
  13019.           return((char *)vvbuf);
  13020.       }
  13021.       case VN_MACLVL:
  13022.         sprintf(vvbuf,"%d",maclvl);     /* SAFE */
  13023.         return((char *)vvbuf);
  13024.     } /* Break up long switch statements... */
  13025.  
  13026.     switch(y) {
  13027. #ifndef NOXFER
  13028.       case VN_XF_BC:
  13029.         sprintf(vvbuf,"%d",crunched);   /* SAFE */
  13030.         return((char *)vvbuf);
  13031.  
  13032.       case VN_XF_TM:
  13033.         sprintf(vvbuf,"%d",timeouts);   /* SAFE */
  13034.         return((char *)vvbuf);
  13035.  
  13036.       case VN_XF_RX:
  13037.         sprintf(vvbuf,"%d",retrans);    /* SAFE */
  13038.         return((char *)vvbuf);
  13039. #endif /* NOXFER */
  13040.  
  13041.       case VN_MS_CD:                    /* Modem signals */
  13042.       case VN_MS_CTS:
  13043.       case VN_MS_DSR:
  13044.       case VN_MS_DTR:
  13045.       case VN_MS_RI:
  13046.       case VN_MS_RTS: {
  13047.           int x, z = -1;
  13048.           x = ttgmdm();                 /* Try to get them */
  13049.           if (x > -1) {
  13050.               switch (y) {
  13051.                 case VN_MS_CD:  z = (x & BM_DCD) ? 1 : 0; break;
  13052.                 case VN_MS_DSR: z = (x & BM_DSR) ? 1 : 0; break;
  13053.                 case VN_MS_CTS: z = (x & BM_CTS) ? 1 : 0; break;
  13054. #ifdef MAC
  13055.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  13056. #else
  13057. #ifndef STRATUS
  13058.                 case VN_MS_RI:  z = (x & BM_RNG) ? 1 : 0; break;
  13059. #ifndef NT
  13060.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  13061.                 case VN_MS_RTS: z = (x & BM_RTS) ? 1 : 0; break;
  13062. #endif /* NT */
  13063. #endif /* STRATUS */
  13064. #endif /* MAC */
  13065.               }
  13066.           }
  13067.           sprintf(vvbuf,"%d",z);        /* SAFE */
  13068.           return((char *)vvbuf);
  13069.       }
  13070.       case VN_MATCH:                    /* INPUT MATCH */
  13071.         return(inpmatch ? inpmatch : "");
  13072.  
  13073. #ifdef CKFLOAT
  13074.       case VN_ISCALE:            /* INPUT SCALE-FACTOR */
  13075.         return(inpscale ? inpscale : "1.0");
  13076. #endif    /* CKFLOAT */
  13077.  
  13078.       case VN_SLMSG: {                  /* SET LINE / HOST message */
  13079.           extern char * slmsg;
  13080.           vvbuf[0] = NUL;
  13081.           if (slmsg)
  13082.             ckstrncpy(vvbuf,slmsg,VVBUFL);
  13083.          return(vvbuf);
  13084.       }
  13085.  
  13086.       case VN_TXTDIR:                   /* TEXTDIR */
  13087.         return(k_info_dir ? k_info_dir : "");
  13088.  
  13089. #ifdef FNFLOAT
  13090.       case VN_MA_PI:
  13091.         return(math_pi);
  13092.  
  13093.       case VN_MA_E:
  13094.         return(math_e);
  13095.  
  13096.       case VN_MA_PR:
  13097.         sprintf(vvbuf,"%d",fp_digits);  /* SAFE */
  13098.         return(vvbuf);
  13099. #endif /* FNFLOAT */
  13100.  
  13101.       case VN_CMDBL:
  13102.         sprintf(vvbuf,"%d",CMDBL);      /* SAFE */
  13103.         return(vvbuf);
  13104.  
  13105. #ifdef CKCHANNELIO
  13106.       case VN_FERR: {
  13107.           extern int z_error;
  13108.           sprintf(vvbuf,"%d",z_error);  /* SAFE */
  13109.           return(vvbuf);
  13110.       }
  13111.       case VN_FMAX: {
  13112.           extern int z_maxchan;
  13113.           sprintf(vvbuf,"%d",z_maxchan); /* SAFE */
  13114.           return(vvbuf);
  13115.       }
  13116.       case VN_FCOU: {
  13117.           extern int z_filcount;
  13118.           sprintf(vvbuf,"%d",z_filcount); /* SAFE */
  13119.           return(vvbuf);
  13120.       }
  13121. #endif /* CKCHANNELIO */
  13122.  
  13123. #ifndef NODIAL
  13124.       case VN_DRTR: {
  13125.           extern int dialcount;
  13126.           sprintf(vvbuf,"%d",dialcount); /* SAFE */
  13127.           return(vvbuf);
  13128.       }
  13129. #endif /* NODIAL */
  13130.  
  13131. #ifndef NOLOGDIAL
  13132. #ifndef NOLOCAL
  13133.       case VN_CXTIME:
  13134.         sprintf(vvbuf,"%ld",dologshow(0)); /* SAFE */
  13135.         return(vvbuf);
  13136. #endif /* NOLOCAL */
  13137. #endif /* NOLOGDIAL */
  13138.  
  13139.       case VN_BYTE:
  13140.         sprintf(vvbuf,"%d",byteorder);  /* SAFE */
  13141.         return(vvbuf);
  13142.  
  13143.       case VN_KBCHAR:
  13144.         vvbuf[0] = NUL;
  13145.         vvbuf[1] = NUL;
  13146.         if (kbchar > 0)
  13147.           vvbuf[0] = (kbchar & 0xff);
  13148.         return(vvbuf);
  13149.  
  13150.       case VN_TTYNAM: {
  13151. #ifdef HAVECTTNAM
  13152.           extern char cttnam[];
  13153.           return((char *)cttnam);
  13154. #else
  13155.           return(CTTNAM);
  13156. #endif /* HAVECTTNAM */
  13157.       }
  13158.  
  13159.       case VN_PROMPT:
  13160.         return(cmgetp());
  13161.  
  13162.       case VN_BUILD: {
  13163.           extern char * buildid;
  13164.           return(buildid);
  13165.       }
  13166.  
  13167. #ifndef NOSEXP
  13168.       case VN_SEXP: {
  13169.           extern char * lastsexp;
  13170.           return(lastsexp ? lastsexp : "");
  13171.       }
  13172.       case VN_VSEXP: {
  13173.           extern char * sexpval;
  13174.           return(sexpval ? sexpval : "");
  13175.       }
  13176.       case VN_LSEXP: {
  13177.           extern int sexpdep;
  13178.           ckstrncpy(vvbuf,ckitoa(sexpdep),VVBUFL);
  13179.           return(vvbuf);
  13180.       }
  13181. #endif /* NOSEXP */
  13182.  
  13183. #ifdef GFTIMER
  13184.       case VN_FTIME: {
  13185.           CKFLOAT f;
  13186.           ztime(&p);
  13187.           if (p == NULL || *p == NUL)
  13188.             return(NULL);
  13189.           z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  13190.           f = (CKFLOAT)z + ((CKFLOAT)ztusec) / 1000000.0;
  13191.           sprintf(vvbuf,"%f",f);        /* SAFE */
  13192.           return(vvbuf);
  13193.       }
  13194. #endif /* GFTIMER */
  13195.  
  13196. #ifndef NOHTTP
  13197.       case VN_HTTP_C: {                 /* HTTP Code */
  13198.           extern int http_code;
  13199.           return(ckitoa(http_code));
  13200.       }
  13201.       case VN_HTTP_N:                   /* HTTP Connected */
  13202.         return( http_isconnected() ? "1" : "0");
  13203.       case VN_HTTP_H:                   /* HTTP Host */
  13204.         return( (char *)http_host() );
  13205.       case VN_HTTP_M: {                 /* HTTP Message */
  13206.           extern char http_reply_str[];
  13207.           return((char *)http_reply_str);
  13208.       }
  13209.       case VN_HTTP_S:                   /* HTTP Security */
  13210.         return((char *)http_security());
  13211. #endif /* NOHTTP */
  13212.  
  13213. #ifdef NEWFTP
  13214.       case VN_FTP_B:
  13215.         return((char *)ftp_cpl_mode());
  13216.       case VN_FTP_D:
  13217.         return((char *)ftp_dpl_mode());
  13218.       case VN_FTP_Z:
  13219.         return((char *)ftp_authtype());
  13220.       case VN_FTP_C: {
  13221.           extern int ftpcode;
  13222.           return(ckitoa(ftpcode));
  13223.       }
  13224.       case VN_FTP_M: {
  13225.           extern char ftp_reply_str[];
  13226.           if (isdigit(ftp_reply_str[0]) &&
  13227.               isdigit(ftp_reply_str[1]) &&
  13228.               isdigit(ftp_reply_str[2]) &&
  13229.               ftp_reply_str[3] == ' ')
  13230.             return(&ftp_reply_str[4]);
  13231.           else
  13232.             return(ftp_reply_str);
  13233.       }
  13234.       case VN_FTP_S: {
  13235.           extern char ftp_srvtyp[];
  13236.           return((char *)ftp_srvtyp);
  13237.       }
  13238.       case VN_FTP_H: {
  13239.           extern char * ftp_host;
  13240.           return(ftp_host ? ftp_host : "");
  13241.       }
  13242.       case VN_FTP_X: {                  /* FTP Connected */
  13243.           extern int ftpisconnected();
  13244.           return(ftpisconnected() ? "1" : "0");
  13245.       }
  13246.       case VN_FTP_L: {                  /* FTP Logged in */
  13247.           extern int ftpisloggedin();
  13248.           return(ftpisloggedin() ? "1" : "0");
  13249.       }
  13250.       case VN_FTP_G: {                  /* FTP GET-PUT-REMOTE */
  13251.           extern int ftpget;
  13252.           char * s = "";
  13253.           switch (ftpget) {
  13254.             case 0: s = "kermit"; break;
  13255.             case 1: s = "ftp"; break;
  13256.             case 2: s = "auto"; break;
  13257.           }
  13258.           return(s);
  13259.       }
  13260. #endif /* NEWFTP */
  13261.  
  13262. #ifndef NOLOCAL
  13263.       case VN_CX_STA: {                 /* CONNECT status */
  13264.           extern int cx_status;
  13265.           return(ckitoa(cx_status));
  13266.       }
  13267. #endif /* NOLOCAL */
  13268.       case VN_NOW:                      /* Timestamp */
  13269.         return(ckcvtdate(p,0));
  13270.  
  13271.       case VN_HOUR:                     /* Hour of the day */
  13272.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  13273.         if (!p) p = "";
  13274.         if (!*p) return(p);
  13275.         vvbuf[0] = p[11];
  13276.         vvbuf[1] = p[12];
  13277.         vvbuf[2] = NUL;
  13278.         return(vvbuf);                  /* and return it */
  13279.  
  13280.       case VN_LOG_CON:            /* \v(...) for log files */
  13281. #ifdef CKLOGDIAL
  13282.         return(diafil);
  13283. #else 
  13284.         return("");
  13285. #endif
  13286.       case VN_LOG_PKT:
  13287. #ifndef NOXFER
  13288.         return(pktfil);
  13289. #else
  13290.         return("");
  13291. #endif
  13292.       case VN_LOG_SES:
  13293. #ifndef NOLOCAL
  13294.         return(sesfil);
  13295. #else
  13296.         return("");
  13297. #endif
  13298.       case VN_LOG_TRA:
  13299. #ifdef TLOG
  13300.         return(trafil);
  13301. #else
  13302.         return("");
  13303. #endif
  13304.       case VN_LOG_DEB:
  13305. #ifdef DEBUG
  13306.         return(debfil);
  13307. #else
  13308.         return("");
  13309. #endif
  13310.     }
  13311.  
  13312. #ifndef NODIAL
  13313.     switch (y) {                        /* Caller ID values */
  13314.       extern char
  13315.         * callid_date, * callid_time, * callid_name,
  13316.         * callid_nmbr, * callid_mesg;
  13317.  
  13318.       case VN_CI_DA:
  13319.         return(callid_date ? callid_date : "");
  13320.  
  13321.       case VN_CI_TI:
  13322.         return(callid_time ? callid_time : "");
  13323.  
  13324.       case VN_CI_NA:
  13325.         return(callid_name ? callid_name : "");
  13326.  
  13327.       case VN_CI_NU:
  13328.         return(callid_nmbr ? callid_nmbr : "");
  13329.  
  13330.       case VN_CI_ME:
  13331.         return(callid_mesg ? callid_mesg : "");
  13332.  
  13333.     } /* End of variable-name switches */
  13334. #endif /* NODIAL */
  13335.  
  13336. #ifdef NT
  13337.     switch (y) {
  13338.       case VN_PERSONAL:
  13339.         p = (char *)GetPersonal();
  13340.         if (p) {
  13341.             GetShortPathName(p,vvbuf,VVBUFL);
  13342.             return(vvbuf);
  13343.         }
  13344.         return("");
  13345.       case VN_DESKTOP:
  13346.           p = (char *)GetDesktop();
  13347.           if (p) {
  13348.               GetShortPathName(p,vvbuf,VVBUFL);
  13349.               return(vvbuf);
  13350.           }
  13351.           return("");
  13352.       case VN_COMMON:
  13353.         p = (char *)GetAppData(1);
  13354.         if (p) {
  13355.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  13356.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  13357.             return(vvbuf);
  13358.         }
  13359.         return("");
  13360.       case VN_APPDATA:
  13361.         p = (char *)GetAppData(0);
  13362.         if (p) {
  13363.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  13364.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  13365.             return(vvbuf);
  13366.         }
  13367.         return("");
  13368.     }
  13369. #endif /* NT */
  13370.  
  13371. #ifdef TN_COMPORT
  13372.     switch (y) {
  13373.       case VN_TNC_SIG: {
  13374.         p = (char *) tnc_get_signature();
  13375.         ckstrncpy(vvbuf,p ? p : "",VVBUFL);
  13376.         return(vvbuf);
  13377.       }
  13378.     }
  13379. #endif /* TN_COMPORT */
  13380.  
  13381. #ifdef KUI
  13382.     switch (y) {
  13383.       case VN_GUI_RUN: {
  13384.       extern HWND getHwndKUI();
  13385.       if ( IsIconic(getHwndKUI()) )
  13386.             return("minimized");
  13387.       if ( IsZoomed(getHwndKUI()) )
  13388.             return("maximized");
  13389.       return("restored");
  13390.       }
  13391.       case VN_GUI_XP:
  13392.         sprintf(vvbuf,"%d",get_gui_window_pos_x());  /* SAFE */
  13393.         return(vvbuf);
  13394.       case VN_GUI_YP:
  13395.         sprintf(vvbuf,"%d",get_gui_window_pos_y());  /* SAFE */
  13396.         return(vvbuf);
  13397.       case VN_GUI_XR:
  13398.         sprintf(vvbuf,"%d",GetSystemMetrics(SM_CXSCREEN));  /* SAFE */
  13399.         return(vvbuf);
  13400.       case VN_GUI_YR:
  13401.         sprintf(vvbuf,"%d",GetSystemMetrics(SM_CYSCREEN));  /* SAFE */
  13402.         return(vvbuf);
  13403.       case VN_GUI_FNM:
  13404.           if ( ntermfont > 0 ) {
  13405.               int i;
  13406.               for (i = 0; i < ntermfont; i++) {
  13407.                   if (tt_font == term_font[i].kwval) {
  13408.                       ckstrncpy(vvbuf,term_font[i].kwd,VVBUFL);
  13409.                       return(vvbuf);
  13410.                   }
  13411.               }
  13412.           }
  13413.           return("(unknown)");
  13414.       case VN_GUI_FSZ:
  13415.           ckstrncpy(vvbuf,ckitoa(tt_font_size/2),VVBUFL);
  13416.           if ( tt_font_size % 2 )
  13417.               ckstrncat(vvbuf,".5",VVBUFL);
  13418.           return(vvbuf);
  13419.     }
  13420. #endif /* KUI */
  13421.  
  13422.     fnsuccess = 0;
  13423.     if (fnerror) {
  13424.         fnsuccess = 0;
  13425.     }
  13426.     if (fndiags) {
  13427.         if (!embuf)
  13428.           ckstrncpy(embuf,"<ERROR:NO_SUCH_VARIABLE>",EMBUFLEN);
  13429.         printf("?%s\n",embuf);
  13430.         return((char *)embuf);
  13431.     } else
  13432.       return("");
  13433. }
  13434. #endif /* NOSPL */
  13435.  
  13436.  
  13437. /*
  13438.   X X S T R I N G  --  Expand variables and backslash codes.
  13439.  
  13440.     int xxtstring(s,&s2,&n);
  13441.  
  13442.   Expands \ escapes via recursive descent.
  13443.   Argument s is a pointer to string to expand (source).
  13444.   Argument s2 is the address of where to put result (destination).
  13445.   Argument n is the length of the destination string (to prevent overruns).
  13446.   Returns -1 on failure, 0 on success,
  13447.     with destination string null-terminated and s2 pointing to the
  13448.     terminating null, so that subsequent characters can be added.
  13449. */
  13450.  
  13451. #define XXDEPLIM 100                    /* Recursion depth limit */
  13452. /*
  13453.   In Windows the stack is limited to 256K so big character arrays like
  13454.   vnambuf can't be on the stack in recursive functions like zzstring().
  13455.   But that's no reason use malloc() in Unix or VMS, which don't have
  13456.   this kind of restriction.
  13457. */
  13458. #ifdef DVNAMBUF                /* Dynamic vnambuf[] */
  13459. #undef DVNAMBUF                /* Clean slate */
  13460. #endif /* DVNAMBUF */
  13461.  
  13462. #ifndef NOSPL                /* Only if SPL included */
  13463. #ifdef OS2                /* Only for K95 */
  13464. #define DVNAMBUF
  13465. #endif /* OS2 */
  13466. #endif /* NOSPL */
  13467.  
  13468. int
  13469. zzstring(s,s2,n) char *s; char **s2; int *n; {
  13470.     int x,                              /* Current character */
  13471.         y,                              /* Worker */
  13472.         pp,                             /* Paren level */
  13473.         kp,                             /* Brace level */
  13474.         argn,                           /* Function argument counter */
  13475.         n2,                             /* Local copy of n */
  13476.         d,                              /* Array dimension */
  13477.         vbi,                            /* Variable id (integer form) */
  13478.         argl,                           /* String argument length */
  13479.         nx;                             /* Save original length */
  13480.  
  13481.     char vb,                            /* Variable id (char form) */
  13482.         *vp,                            /* Pointer to variable definition */
  13483.         *new,                           /* Local pointer to target string */
  13484. #ifdef COMMENT
  13485.         *old,                           /* Save original target pointer */
  13486. #endif /* COMMENT */
  13487.         *p,                             /* Worker */
  13488.         *q,                             /* Worker */
  13489.         *s3;                            /* Worker */
  13490.     int  x3;                            /* Worker */
  13491.     char *r  = (char *)0;               /* For holding function args */
  13492.     char *r2 = (char *)0;
  13493.     char *r3p;
  13494.  
  13495. #ifndef NOSPL
  13496. #ifdef DVNAMBUF
  13497.     char * vnambuf = NULL;              /* Buffer for variable/function name */
  13498. #else /* DVNAMBUF */
  13499.     char vnambuf[VNAML];                /* Buffer for variable/function name */
  13500. #endif /* DVNAMBUF */
  13501.     char *argp[FNARGS];                 /* Pointers to function args */
  13502. #endif /* NOSPL */
  13503.  
  13504.     static int depth = 0;               /* Call depth, avoid overflow */
  13505.  
  13506.     n2 = *n;                            /* Make local copies of args */
  13507.     nx = n2;
  13508.  
  13509.     new = *s2;                          /* for one less level of indirection */
  13510. #ifdef COMMENT
  13511.     old = new;
  13512. #endif /* COMMENT */
  13513.  
  13514. #ifndef NOSPL
  13515.     ispattern = 0;                      /* For \fpattern() */
  13516.     isjoin = 0;                /* For \fjoin() */
  13517. #endif /* NOSPL */
  13518.     depth++;                            /* Sink to a new depth */
  13519.     if (depth > XXDEPLIM) {             /* Too deep? */
  13520.         printf("?definition is circular or too deep\n");
  13521.         debug(F101,"zzstring fail","",depth);
  13522.         depth = 0;
  13523.         *new = NUL;
  13524.         return(-1);
  13525.     }
  13526.     if (!s || !new) {                   /* Watch out for null pointers */
  13527.         debug(F101,"zzstring fail 2","",depth);
  13528.         if (new)
  13529.           *new = NUL;
  13530.         depth = 0;
  13531.         return(-1);
  13532.     }
  13533.     s3 = s;
  13534.     argl = 0;
  13535.     while (*s3++) argl++;              /* Get length of source string */
  13536.     debug(F010,"zzstring entry",s,0);
  13537.     if (argl == 0) {                    /* Empty string */
  13538.         debug(F111,"zzstring empty arg",s,argl);
  13539.         depth = 0;
  13540.         *new = NUL;
  13541.         return(0);
  13542.     }
  13543.     if (argl < 0) {                     /* Watch out for garbage */
  13544.         debug(F101,"zzstring fail 3","",depth);
  13545.         *new = NUL;
  13546.         depth = 0;
  13547.         return(-1);
  13548.     }
  13549. #ifdef DVNAMBUF
  13550.     debug(F100,"vnambuf malloc...","",0);
  13551.     vnambuf = malloc(VNAML);
  13552.     if (vnambuf == NULL) {
  13553.         printf("?Out of memory");
  13554.         return(-1);
  13555.     }
  13556.     debug(F100,"vnambuf malloc ok","",0);
  13557. #endif /* DVNAMBUF */
  13558.  
  13559.     while ((x = *s)) {                  /* Loop for all characters */
  13560.         if (x != CMDQ) {                /* Is it the command-quote char? */
  13561.             *new++ = *s++;              /* No, normal char, just copy */
  13562.             if (--n2 < 0) {             /* and count it, careful of overflow */
  13563.                 debug(F101,"zzstring overflow 1","",depth);
  13564.                 depth = 0;
  13565. #ifdef DVNAMBUF
  13566.                 if (vnambuf) free(vnambuf);
  13567. #endif /* DVNAMBUF */
  13568.                 return(-1);
  13569.             }
  13570.             continue;
  13571.         }
  13572.  
  13573. /* We have the command-quote character. */
  13574.  
  13575.         x = *(s+1);                     /* Get the following character. */
  13576.         if (isupper(x)) x = tolower(x);
  13577.         switch (x) {                    /* Act according to variable type */
  13578. #ifndef NOSPL
  13579.           case 0:                       /* It's a lone backslash */
  13580.             *new++ = *s++;
  13581.             if (--n2 < 0) {
  13582.                 debug(F101,"zzstring overflow 2","",0);
  13583. #ifdef DVNAMBUF
  13584.                 if (vnambuf) free(vnambuf);
  13585. #endif /* DVNAMBUF */
  13586.                 return(-1);
  13587.             }
  13588.             break;
  13589.           case '%':                     /* Variable */
  13590.             s += 2;                     /* Get the letter or digit */
  13591.             vb = *s++;                  /* and move source pointer past it */
  13592.             vp = NULL;                  /* Assume definition is empty */
  13593.             if (vb >= '0' && vb <= '9') { /* Digit for macro arg */
  13594.                 if (maclvl < 0)         /* Digit variables are global */
  13595.                   vp = g_var[vb];       /* if no macro is active */
  13596.                 else                    /* otherwise */
  13597.                   vp = m_arg[maclvl][vb - '0']; /* they're on the stack */
  13598.             } else if (vb == '*') {     /* Macro args string */
  13599. #ifdef COMMENT
  13600.                 /* This doesn't take changes into account */
  13601.                 vp = (maclvl >= 0) ? m_line[maclvl] : topline;
  13602.                 if (!vp) vp = "";
  13603. #else
  13604.         char * ss = new;
  13605.                 if (zzstring("\\fjoin(&_[],,1)",&new,&n2) < 0) {
  13606. #ifdef DVNAMBUF
  13607.             if (vnambuf) free(vnambuf);
  13608. #endif /* DVNAMBUF */
  13609.             return(-1);
  13610.         }
  13611.         debug(F110,"zzstring \\%*",ss,0);
  13612.                 break;
  13613. #endif /* COMMENT */
  13614.             } else {
  13615.                 if (isupper(vb)) vb += ('a'-'A');
  13616.                 vp = g_var[vb];         /* Letter for global variable */
  13617.             }
  13618.             if (!vp) vp = "";
  13619. #ifdef COMMENT
  13620.             if (vp) {                   /* If definition not empty */
  13621. #endif /* COMMENT */
  13622.                 debug(F010,"zzstring %n vp",vp,0);
  13623.                 if (zzstring(vp,&new,&n2) < 0) { /* call self to evaluate it */
  13624.                     debug(F101,"zzstring fail 6","",depth);
  13625. #ifdef DVNAMBUF
  13626.                     if (vnambuf) free(vnambuf);
  13627. #endif /* DVNAMBUF */
  13628.                     return(-1);         /* Pass along failure */
  13629.                 }
  13630. #ifdef COMMENT
  13631.             } else {
  13632.                 debug(F110,"zzstring %n vp","(NULL)",0);
  13633.                 n2 = nx;
  13634.                 new = old;
  13635.                 *new = NUL;
  13636.             }
  13637. #endif /* COMMENT */
  13638.             break;
  13639.           case '&':                     /* An array reference */
  13640.             x = arraynam(s,&vbi,&d);    /* Get name and subscript */
  13641.             debug(F111,"zzstring arraynam",s,x);
  13642.             if (x < 0) {
  13643.                 debug(F101,"zzstring fail 7","",depth);
  13644. #ifdef DVNAMBUF
  13645.                 if (vnambuf) free(vnambuf);
  13646. #endif /* DVNAMBUF */
  13647.                 return(-1);
  13648.             }
  13649.             pp = 0;                     /* Bracket counter */
  13650.             while (*s) {                /* Advance source pointer... */
  13651.                 if (*s == '[') pp++;
  13652.                 if (*s == ']' && --pp == 0) break;
  13653.                 s++;
  13654.             }
  13655.             if (*s == ']') s++;         /* ...past the closing bracket. */
  13656.  
  13657.             x = chkarray(vbi,d);        /* Array is declared? */
  13658.             debug(F101,"zzstring chkarray","",x);
  13659.             if (x > 0) {
  13660. #ifdef COMMENT
  13661.                 char * s1 = NULL;
  13662. #endif /* COMMENT */
  13663.                 vbi -= ARRAYBASE;       /* Convert name to index */
  13664.  
  13665. #ifdef COMMENT
  13666.                 if (vbi == 0) {         /* Argument vector array */
  13667.                     extern char ** toparg, ** m_xarg[];
  13668.                     extern int n_xarg[];
  13669.                     if (maclvl < 0) {
  13670.                         if (topargc >= d) {
  13671.                             s1 = toparg[d];
  13672.                         }
  13673.                     } else {
  13674.                         if (n_xarg[maclvl] >= d) {
  13675.                             s1 = m_xarg[maclvl][d];
  13676.                         }
  13677.                     }
  13678.                     if (s1) {
  13679.                         if (zzstring(s1,&new,&n2) < 0) { /* evaluate */
  13680.                             debug(F101,"zzstring fail 7.5","",depth);
  13681. #ifdef DVNAMBUF
  13682.                             if (vnambuf) free(vnambuf);
  13683. #endif /* DVNAMBUF */
  13684.                             return(-1); /* Pass along failure */
  13685.                         }
  13686.                     } else {
  13687.                         /* old = new; */
  13688.                         n2 = nx;
  13689.                     }
  13690.                 } else
  13691. #endif /* COMMENT */
  13692.                   if (a_dim[vbi] >= d) { /* If subscript in range */
  13693.                     char **ap;
  13694. #ifndef COMMENT
  13695.                     debug(F110,"zzstring a_ptr[vbi]",a_ptr[vbi],0);
  13696.                     debug(F110,"zzstring a_ptr[vbi][d]",a_ptr[vbi][d],0);
  13697. #endif /* COMMENT */
  13698.                     ap = a_ptr[vbi];    /* get data pointer */
  13699.                     if (ap) {           /* and if there is one */
  13700.                         if (ap[d]) {    /* If definition not empty */
  13701.                             debug(F111,"zzstring ap[d]",ap[d],d);
  13702.                             if (zzstring(ap[d],&new,&n2) < 0) { /* evaluate */
  13703.                                 debug(F101,"zzstring fail 8","",depth);
  13704. #ifdef DVNAMBUF
  13705.                                 if (vnambuf) free(vnambuf);
  13706. #endif /* DVNAMBUF */
  13707.                                 return(-1); /* Pass along failure */
  13708.                             }
  13709.                         }
  13710.                     } else {
  13711.                         /* old = new; */
  13712.                         n2 = nx;
  13713.                     }
  13714.                 }
  13715.         }
  13716.             break;
  13717.  
  13718.           case 'f':                     /* A builtin function */
  13719.             q = vnambuf;                /* Copy the name */
  13720.             y = 0;                      /* into a separate buffer */
  13721.             s += 2;                     /* point past 'F' */
  13722.             while (y++ < VNAML) {
  13723.                 if (*s == '(') { s++; break; } /* Look for open paren */
  13724.                 if ((*q = *s) == NUL) break;   /* or end of string */
  13725.                 s++; q++;
  13726.             }
  13727.             *q = NUL;                   /* Terminate function name */
  13728.             if (y >= VNAML) {           /* Handle pathological case */
  13729.                 while (*s && (*s != '(')) /* of very long string entered */
  13730.                   s++;                    /* as function name. */
  13731.                 if (*s == ')') s++;       /* Skip past it. */
  13732.             }
  13733.             r = r2 = malloc(argl+2);    /* And make a place to copy args */
  13734.             /* debug(F101,"zzstring r2","",r2); */
  13735.             if (!r2) {                  /* Watch out for malloc failure */
  13736.                 debug(F101,"zzstring fail 9","",depth);
  13737.                 *new = NUL;
  13738.                 depth = 0;
  13739. #ifdef DVNAMBUF
  13740.                 if (vnambuf) free(vnambuf);
  13741. #endif /* DVNAMBUF */
  13742.                 return(-1);
  13743.             }
  13744.             if (r3) free(r3); /* And another to copy literal arg string */
  13745.             r3 = malloc(argl+2);
  13746.             /* debug(F101,"zzstring r3","",r3); */
  13747.             if (!r3) {
  13748.                 debug(F101,"zzstring fail 10","",depth);
  13749.                 depth = 0;
  13750.                 *new = NUL;
  13751.                 if (r2) free(r2);
  13752. #ifdef DVNAMBUF
  13753.                 if (vnambuf) free(vnambuf);
  13754. #endif /* DVNAMBUF */
  13755.                 return(-1);
  13756.             } else
  13757.               r3p = r3;
  13758.             argn = 0;                   /* Argument counter */
  13759.             argp[argn++] = r;           /* Point to first argument */
  13760.             y = 0;                      /* Completion flag */
  13761.             pp = 1;                     /* Paren level (already have one). */
  13762.             kp = 0;
  13763.             while (1) {                 /* Copy each argument, char by char. */
  13764.                 *r3p++ = *s;            /* This is a literal copy for \flit */
  13765.                 if (!*s) break;
  13766.  
  13767.                 if (*s == '{') {        /* Left brace */
  13768.                     kp++;
  13769.                 }
  13770.                 if (*s == '}') {        /* Right brace */
  13771.                     kp--;
  13772.                 }
  13773.                 if (*s == '(' && kp <= 0) { /* Open paren not in brace */
  13774.                     pp++;               /* Count it */
  13775.                 }
  13776.                 *r = *s;                /* Now copy resulting byte */
  13777.                 if (!*r)                /* If NUL, done. */
  13778.                   break;
  13779.                 if (*r == ')' && kp <= 0) { /* Closing paren, count it. */
  13780.                     if (--pp == 0) {    /* Final one? */
  13781.                         *r = NUL;       /* Make it a terminating null */
  13782.                         *(r3p - 1) = NUL;
  13783.                         s++;            /* Point past it in source string */
  13784.                         y = 1;          /* Flag we've got all the args */
  13785.                         break;          /* Done with while loop */
  13786.                     }
  13787.                 }
  13788.                 if (*r == ',' && kp <= 0) { /* Comma */
  13789.                     if (pp == 1) {          /* If not within ()'s, */
  13790.                         if (argn >= FNARGS) { /* Too many args */
  13791.                             s++; r++;   /* Keep collecting flit() string */
  13792.                             continue;
  13793.                         }
  13794.                         *r = NUL;           /* New arg, skip past comma */
  13795.                         argp[argn++] = r+1; /* In range, point to new arg */
  13796.                     }                   /* Otherwise just skip past  */
  13797.                 }
  13798.                 s++; r++;               /* Advance pointers */
  13799.             }
  13800.             if (!y)                     /* If we didn't find closing paren */
  13801.               argn = -1;
  13802. #ifdef DEBUG
  13803.             if (deblog) {
  13804.                 char buf[24];
  13805.                 debug(F111,"zzstring function name",vnambuf,y);
  13806.                 debug(F010,"zzstring function r3",r3,0);
  13807.                 for (y = 0; y < argn; y++) {
  13808.                     sprintf(buf,"arg %2d ",y);
  13809.                     debug(F010,buf,argp[y],0);
  13810.                 }
  13811.             }
  13812. #endif /* DEBUG */
  13813.             vp = fneval(vnambuf,argp,argn,r3); /* Evaluate the function. */
  13814.             if (vp) {                      /* If definition not empty */
  13815.                 while ((*new++ = *vp++)) { /* copy it to output string */
  13816.                     if (--n2 < 0) {        /* watch out for overflow */
  13817.                         debug(F101,"zzstring fail 12","",depth);
  13818.                         if (r2) { free(r2); r2 = NULL; }
  13819.                         if (r3) { free(r3); r3 = NULL; }
  13820. #ifdef DVNAMBUF
  13821.                         if (vnambuf) free(vnambuf);
  13822. #endif /* DVNAMBUF */
  13823.                         return(-1);
  13824.                     }
  13825.                 }
  13826.                 new--;                  /* Back up over terminating null */
  13827.                 n2++;                   /* to allow for further deposits. */
  13828.             }
  13829.             if (r2) { free(r2); r2 = NULL; }
  13830.             if (r3) { free(r3); r3 = NULL; }
  13831.             break;
  13832.           case '$':                     /* An environment variable */
  13833.           case 'v':                     /* Or a named builtin variable. */
  13834.           case 'm':                     /* Or a macro /long variable */
  13835.           case 's':                     /* 196 Macro substring */
  13836.           case ':':                     /* 196 \-variable substring */
  13837.             pp = 0;
  13838.             p = s+2;                    /* $/V/M must be followed by (name) */
  13839.             if (*p != '(') {            /* as in \$(HOME) or \V(count) */
  13840.                 *new++ = *s++;          /* If not, just copy it */
  13841.                 if (--n2 < 0) {
  13842.                     debug(F101,"zzstring overflow 3","",depth);
  13843. #ifdef DVNAMBUF
  13844.                     if (vnambuf) free(vnambuf);
  13845. #endif /* DVNAMBUF */
  13846.                     return(-1);
  13847.                 }
  13848.                 break;
  13849.             }
  13850.             pp++;
  13851.             p++;                        /* Point to 1st char of name */
  13852.             q = vnambuf;                /* Copy the name */
  13853.             y = 0;                      /* into a separate buffer */
  13854.             while (y++ < VNAML) {       /* Watch out for name too long */
  13855.                 if (*p == '(') {        /* Parens can be nested... */
  13856.                     pp++;
  13857.                 } else if (*p == ')') { /* Name properly terminated with ')' */
  13858.                     pp--;
  13859.                     if (pp == 0) {
  13860.                         p++;            /* Move source pointer past ')' */
  13861.                         break;
  13862.                     }
  13863.                 }
  13864.                 if ((*q = *p) == NUL)   /* String ends before ')' */
  13865.                   break;
  13866.                 p++; q++;               /* Advance pointers */
  13867.             }
  13868.             *q = NUL;                   /* Terminate the variable name */
  13869.             if (y >= VNAML) {           /* Handle pathological case */
  13870.                 while (*p && (*p != ')')) /* of very long string entered */
  13871.                   p++;                    /* as variable name. */
  13872.                 if (*p == ')') p++;       /* Skip ahead to the end of it. */
  13873.             }
  13874.             s = p;                      /* Adjust global source pointer */
  13875.             s3 = vnambuf;
  13876.             x3 = 0;
  13877.             while (*s3++) x3++;
  13878.             p = malloc(x3 + 1);         /* Make temporary space */
  13879.             if (p) {                    /* If we got the space */
  13880.                 vp = vnambuf;           /* Point to original */
  13881.                 strcpy(p,vp);           /* (safe) Make a copy of it */
  13882.                 y = VNAML;              /* Length of name buffer */
  13883.                 zzstring(p,&vp,&y);     /* Evaluate the copy */
  13884.                 free(p);                /* Free the temporary space */
  13885.                 p = NULL;
  13886.             }
  13887.             debug(F110,"zzstring vname",vnambuf,0);
  13888.             q = NULL;
  13889.             if (x == '$') {             /* Look up its value */
  13890.                 vp = getenv(vnambuf);   /* This way for environment variable */
  13891.             } else if (x == 'm' || x == 's' || x == ':') { /* Macro / substr */
  13892.                 int k, x1 = -1, x2 = -1;
  13893.                 k = strlen(vnambuf);
  13894.                 /* \s(name[n:m]) -- Compact substring notation */
  13895.                 if ((x == 's' || x == ':') && (k > 1)) { /* Substring wanted */
  13896.                     if (vnambuf[k-1] == ']') {
  13897.                         int i;
  13898.                         for (i = k-1; i > 0; i--) {
  13899.                             if (vnambuf[i] == '[') {
  13900.                                 char * p = NULL;
  13901.                                 p = (char *)malloc(k - i + 8);
  13902.                                 if (p) {
  13903.                                     /* Now this is a dirty trick... */
  13904.                                     ckmakmsg(p,
  13905.                                              k-i+8,
  13906.                                              "\\&a",
  13907.                                              &vnambuf[i],
  13908.                                              NULL,
  13909.                                              NULL
  13910.                                              );
  13911.                                     arraybounds(p,&x1,&x2);
  13912.                                     if (x1 < 1) x1 = 1;
  13913.                                     x1--; /* Adjust to 0-base */
  13914.                                     free(p);
  13915.                                     vnambuf[i] = NUL;
  13916.                                 }
  13917.                             }
  13918.                         }
  13919.                     }
  13920.                 }
  13921.                 if (x == ':') {
  13922.                     vp = vnambuf;
  13923.                 } else {
  13924.             y = isaarray(vnambuf) ?
  13925.             mxxlook(mactab,vnambuf,nmac) :
  13926.             mxlook(mactab,vnambuf,nmac);
  13927.                     if (y > -1) {    /* Got definition */
  13928.                         vp = mactab[y].mval;
  13929.                     } else {
  13930.                         vp = NULL;
  13931.                     }
  13932.                 }
  13933.                 if (vp) {
  13934.                     if ((x == 's' || x == ':') && (k > 1)) {
  13935.                         /* Compact substring notation */
  13936.                         if (x2 == 0) {  /* Length */
  13937.                             vp = NULL;
  13938.                         } else if (x1 > -1) { /* Start */
  13939.                             k = strlen(vp);
  13940.                             if (x1 > k) {  /* If it's off the end, */
  13941.                                 vp = NULL; /* result is empty */
  13942.                             } else if (k > 0) {
  13943.                                 if ((q = malloc(k+1))) {
  13944.                                     strcpy(q,vp); /* safe */
  13945.                                     if ((x2 > -1) && ((x1 + x2) <= k)) {
  13946.                                         q[x1+x2] = NUL;
  13947.                                     }
  13948.                                     vp = q+x1;
  13949.                                 }  else vp = NULL;
  13950.                             } else vp = NULL;
  13951.                         }
  13952. #ifdef DEBUG
  13953.                         if (deblog) {
  13954.                             if (!vp) {
  13955.                             } else {
  13956.                                 k = strlen(vp);
  13957.                             }
  13958.                         }
  13959. #endif /* DEBUG */
  13960.                     }
  13961.                 }
  13962.             } else {                    /* or */
  13963.                 vp = nvlook(vnambuf);   /* this way for builtin variable */
  13964.             }
  13965.             if (vp) {                   /* If definition not empty */
  13966.                 while ((*new++ = *vp++)) /* copy it to output string. */
  13967.                   if (--n2 < 0) {
  13968.                       if (q) free(q);
  13969.                       debug(F101,"zzstring overflow 4","",depth);
  13970. #ifdef DVNAMBUF
  13971.                       if (vnambuf) free(vnambuf);
  13972. #endif /* DVNAMBUF */
  13973.                       return(-1);
  13974.                   }
  13975.                 new--;                  /* Back up over terminating null */
  13976.                 n2++;                   /* to allow for further deposits. */
  13977.             }
  13978.             if (q) {
  13979.                 free(q);
  13980.                 q = NULL;
  13981.             }
  13982.             break;
  13983. #endif /* NOSPL */                      /* Handle \nnn even if NOSPL. */
  13984.  
  13985. #ifndef NOKVERBS
  13986.         case 'K':
  13987.         case 'k': {
  13988.             extern struct keytab kverbs[];
  13989.             extern int nkverbs;
  13990. #define K_BUFLEN 30
  13991.             char kbuf[K_BUFLEN + 1];    /* Key verb name buffer */
  13992.             int x, y, z, brace = 0;
  13993.             s += 2;
  13994. /*
  13995.   We assume that the verb name is {braced}, or it extends to the end of the
  13996.   string, s, or it ends with a space, control character, or backslash.
  13997. */
  13998.             p = kbuf;                   /* Copy verb name into local buffer */
  13999.             x = 0;
  14000.             if (*s == '{')  {
  14001.                 s++;
  14002.                 brace++;
  14003.             }
  14004.             while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  14005.                 if (brace && *s == '}') {
  14006.                     s++;
  14007.                     break;
  14008.                 }
  14009.                 *p++ = *s++;
  14010.             }
  14011.             brace = 0;
  14012.             *p = NUL;                   /* Terminate. */
  14013.             p = kbuf;                   /* Point back to beginning */
  14014.             debug(F110,"zzstring kverb",p,0);
  14015.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  14016.             debug(F101,"zzstring lookup",0,y);
  14017.             if (y > -1) {
  14018.                 dokverb(VCMD,y);
  14019. #ifndef NOSPL
  14020.             } else {                    /* Is it a macro? */
  14021.                 y = mxlook(mactab,p,nmac);
  14022.                 if (y > -1) {
  14023.                     debug(F111,"zzstring mxlook",p,y);
  14024.                     if ((z = dodo(y,NULL,cmdstk[cmdlvl].ccflgs)) > 0) {
  14025.                         if (cmpush() > -1) {  /* Push command parser state */
  14026.                             extern int ifc;
  14027.                             int ifcsav = ifc; /* Push IF condition on stack */
  14028.                             y = parser(1);    /* New parser to execute macro */
  14029.                             cmpop();          /* Pop command parser */
  14030.                             ifc = ifcsav;     /* Restore IF condition */
  14031.                             if (y == 0) {     /* No errors, ignore actions */
  14032.                                 p = mrval[maclvl+1]; /* If OK set return val */
  14033.                                 if (p == NULL) p = "";
  14034.                             }
  14035.                         } else {                /* Can't push any more */
  14036.                             debug(F101,"zzstring pushed too deep","",depth);
  14037.                             printf(
  14038.                                "\n?Internal error: zzstring stack overflow\n"
  14039.                                    );
  14040.                             while (cmpop() > -1);
  14041.                             p = "";
  14042.                         }
  14043.                     }
  14044.                 }
  14045. #endif /* NOSPL */
  14046.             }
  14047.             break;
  14048.         }
  14049. #endif /* NOKVERBS */
  14050.  
  14051.         default:                        /* Maybe it's a backslash code */
  14052.           y = xxesc(&s);                /* Go interpret it */
  14053.           if (y < 0) {                  /* Upon failure */
  14054.               *new++ = (char) x;        /* Just quote the next character */
  14055.               s += 2;                   /* Move past the pair */
  14056.               n2 -= 2;
  14057.               if (n2 < 0) {
  14058.                   debug(F101,"zzstring overflow 5","",depth);
  14059. #ifdef DVNAMBUF
  14060.                   if (vnambuf) free(vnambuf);
  14061. #endif /* DVNAMBUF */
  14062.                   return(-1);
  14063.               }
  14064.               continue;                 /* and go back for more */
  14065.           } else {
  14066.               *new++ = (char) y;        /* else deposit interpreted value */
  14067.               if (--n2 < 0) {
  14068.                   debug(F101,"zzstring overflow 6","",depth);
  14069. #ifdef DVNAMBUF
  14070.                   if (vnambuf) free(vnambuf);
  14071. #endif /* DVNAMBUF */
  14072.                   return(-1);
  14073.               }
  14074.           }
  14075.         }
  14076.     }
  14077.     *new = NUL;                         /* Terminate the new string */
  14078.     debug(F010,"zzstring while exit",*s2,0);
  14079.  
  14080.     depth--;                            /* Adjust stack depth gauge */
  14081.     *s2 = new;                          /* Copy results back into */
  14082.     *n = n2;                            /* the argument addresses */
  14083.     debug(F101,"zzstring ok","",depth);
  14084. #ifdef DVNAMBUF
  14085.     if (vnambuf) free(vnambuf);
  14086. #endif /* DVNAMBUF */
  14087.     return(0);                          /* and return. */
  14088. }
  14089. #endif /* NOICP */
  14090.