home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku200.tar / ckuus4.c < prev    next >
C/C++ Source or Header  |  2001-12-08  |  438KB  |  13,646 lines

  1. #include "ckcsym.h"
  2.  
  3. /*  C K U U S 4 --  "User Interface" for C-Kermit, part 4  */
  4.  
  5. /*
  6.   Author: Frank da Cruz <fdc@columbia.edu>,
  7.   Columbia University Academic Information Systems, New York City.
  8.  
  9.   Copyright (C) 1985, 2001,
  10.     Trustees of Columbia University in the City of New York.
  11.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  12.     copyright text in the ckcmai.c module for disclaimer and permissions.
  13. */
  14.  
  15. /*
  16.   File ckuus4.c -- Functions moved from other ckuus*.c modules to even
  17.   out their sizes.
  18. */
  19. #include "ckcdeb.h"
  20. #include "ckcasc.h"
  21. #include "ckcker.h"
  22. #include "ckuusr.h"
  23. #include "ckuver.h"
  24. #include "ckcnet.h"                     /* Network symbols */
  25. #include "ckcxla.h"                     /* Character sets */
  26.  
  27. #ifdef CK_AUTHENTICATION
  28. #include "ckuath.h"
  29. #endif /* CK_AUTHENTICATION */
  30. #ifdef CK_SSL
  31. #include "ck_ssl.h"
  32. #endif /* CK_SSL */
  33.  
  34. #ifdef VMS
  35. #include <errno.h>                      /* For \v(errno) */
  36. extern char * ckvmserrstr(unsigned long);
  37. #ifndef OLD_VMS
  38. #include <lib$routines.h>               /* Not for VAX C 2.4 */
  39. #else
  40. #include <libdef.h>
  41. #endif /* OLD_VMS */
  42. _PROTOTYP(int vmsttyfd, (void) );
  43. #endif /* VMS */
  44.  
  45. #ifdef OS2
  46. #ifndef NT
  47. #define INCL_NOPM
  48. #define INCL_VIO                        /* Needed for ckocon.h */
  49. #include <os2.h>
  50. #undef COMMENT
  51. #else
  52. #include <windows.h>
  53. #include <tapi.h>
  54. #include "ckntap.h"
  55. #define APIRET ULONG
  56. #endif /* NT */
  57. #include "ckocon.h"
  58. #include "ckoetc.h"
  59. int StartedFromDialer = 0;
  60. HWND hwndDialer = 0;
  61. LONG KermitDialerID = 0;
  62. #ifdef putchar
  63. #undef putchar
  64. #endif /* putchar */
  65. #define putchar(x) conoc(x)
  66. #ifdef CK_PID
  67. #include <process.h>
  68. #endif /* CK_PID */
  69. #endif /* OS2 */
  70.  
  71. extern xx_strp xxstring;
  72.  
  73. #ifdef DEC_TCPIP
  74. #include <descrip>
  75. #include <dvidef>
  76. #include <dcdef>
  77. #endif /* DEC_TCPIP */
  78.  
  79. #ifdef FNFLOAT
  80. #include <math.h>                       /* Floating-point functions */
  81. #endif /* FNFLOAT */
  82.  
  83. extern int quiet, network, xitsta, escape, nopush, xferstat,
  84.   exitonclose, tn_exit, ttnproto, autodl, flow, byteorder, what, lastxfer;
  85.  
  86. extern int filepeek, nscanfile, makestrlen;
  87. extern char * k_info_dir;
  88.  
  89. #ifndef MAC
  90. #ifndef AMIGA
  91. extern int ttyfd;
  92. #endif /* MAC */
  93. #endif /* AMIGA */
  94.  
  95. #ifdef TNCODE
  96. extern int tn_nlm, tn_b_nlm, tn_b_xfer, tn_sb_bug;
  97. extern int tn_rem_echo;
  98. extern int tn_b_meu, tn_b_ume;
  99. #endif /* TNCODE */
  100.  
  101. char * xferfile = NULL;
  102. int xferlog = 0;
  103.  
  104. extern int local, xargc, stayflg, rcflag, bgset, backgrd, cfilef,
  105.   inserver, srvcdmsg, success;
  106.  
  107. #ifdef VMS
  108. extern int batch;
  109. #endif /* VMS */
  110.  
  111. extern char cmdfil[], *versio, *ckxsys, **xargv;
  112. #ifdef DEBUG
  113. extern char debfil[];                   /* Debug log file name */
  114. extern int debtim;
  115. #endif /* DEBUG */
  116.  
  117. extern int noinit;
  118.  
  119. static char ndatbuf[10];
  120.  
  121. char *months[] = {
  122.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  123.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  124. };
  125.  
  126. char *
  127. zzndate() {                             /* Returns today's date as yyyymmdd */
  128.     char * p;
  129.     int x;
  130.  
  131. /* WARNING - This will fail if asctime() returns non-English month names */
  132.  
  133.     ztime(&p);                          /* Get "asctime" string */
  134.     if (p == NULL || *p == NUL) return("");
  135.     for (x = 20; x < 24; x++)           /* yyyy */
  136.       ndatbuf[x - 20] = p[x];
  137.     ndatbuf[6] = (char) ((p[8] == ' ') ? '0' : p[8]);
  138.     ndatbuf[7] = p[9];                  /* dd */
  139.     for (x = 0; x < 12; x++)            /* mm */
  140.       if (!strncmp(p+4,months[x],3)) break;
  141.     if (x == 12) {
  142.         ndatbuf[4] = ndatbuf[5] = '?';
  143.     } else {
  144.         x++;
  145.         ndatbuf[4] = (char) ((x < 10) ? '0' : '1');
  146.         ndatbuf[5] = (char) ((x % 10) + 48);
  147.     }
  148.     ndatbuf[8] = NUL;
  149.     return((char *)ndatbuf);
  150. }
  151.  
  152. #ifdef DCMDBUF
  153. extern struct cmdptr *cmdstk;
  154. extern char *line, *tmpbuf;
  155. #else
  156. extern struct cmdptr cmdstk[];
  157. extern char line[], tmpbuf[];
  158. #endif /* DCMDBUF */
  159.  
  160. #ifdef OS2
  161. extern char exedir[];
  162. #else
  163. extern char * exedir;
  164. #endif /* OS2 */
  165.  
  166. #ifndef NOICP                           /* Most of this file... */
  167.  
  168. #ifndef AMIGA
  169. #ifndef MAC
  170. #include <signal.h>
  171. #endif /* MAC */
  172. #endif /* AMIGA */
  173.  
  174. #ifdef STRATUS                          /* Stratus Computer, Inc.  VOS */
  175. #ifdef putchar
  176. #undef putchar
  177. #endif /* putchar */
  178. #define putchar(x) conoc(x)
  179. #ifdef getchar
  180. #undef getchar
  181. #endif /* getchar */
  182. #define getchar(x) coninc(0)
  183. #endif /* STRATUS */
  184.  
  185.  
  186. #ifdef ANYX25
  187. extern int revcall, closgr, cudata;
  188. int x25ver;
  189. extern char udata[];
  190. #ifndef IBMX25
  191. extern int npadx3;
  192. extern CHAR padparms[];
  193. extern struct keytab padx3tab[];
  194. #endif /* !IBMX25 */
  195. #ifdef IBMX25
  196. /* global variables only available for IBM X.25 - possibly interesting for
  197.  * other implementations
  198.  */
  199. extern x25addr_t local_nua;
  200. extern x25addr_t remote_nua;
  201. #endif /* IBMX25 */
  202. #endif /* ANYX25 */
  203.  
  204. #ifdef NETCONN
  205. #ifndef NODIAL
  206. extern int nnetdir;
  207. extern char *netdir[];
  208. #endif /* NODIAL */
  209. extern char ipaddr[];
  210.  
  211. #ifdef CK_NETBIOS
  212. extern unsigned short netbiosAvail;
  213. extern unsigned long NetbeuiAPI;
  214. extern unsigned char NetBiosName[];
  215. extern unsigned char NetBiosAdapter;
  216. extern unsigned char NetBiosLSN;
  217. #endif /* CK_NETBIOS */
  218.  
  219. #ifdef TCPSOCKET
  220. extern char myipaddr[];
  221. extern int tcp_rdns;
  222. #ifdef CK_DNS_SRV
  223. extern int tcp_dns_srv;
  224. #endif /* CK_DNS_SRV */
  225. extern char * tcp_address;
  226. #ifndef NOHTTP
  227. extern char * tcp_http_proxy;
  228. #endif /* NOHTTP */
  229. #ifdef NT
  230. #ifdef CK_SOCKS
  231. extern char * tcp_socks_svr;
  232. #ifdef CK_SOCKS_NS
  233. extern char * tcp_socks_ns;
  234. #endif /* CK_SOCKS_NS */
  235. #endif /* CK_SOCKS */
  236. #endif /* NT */
  237.  
  238. #ifndef NOTCPOPTS
  239. #ifdef SOL_SOCKET
  240. #ifdef SO_LINGER
  241. extern int tcp_linger;
  242. extern int tcp_linger_tmo;
  243. #endif /* SO_LINGER */
  244. #ifdef SO_DONTROUTE
  245. extern int tcp_dontroute;
  246. #endif /* SO_DONTROUTE */
  247. #ifdef TCP_NODELAY
  248. extern int tcp_nodelay;
  249. #endif /* TCP_NODELAY */
  250. #ifdef SO_SNDBUF
  251. extern int tcp_sendbuf;
  252. #endif /* SO_SNDBUF */
  253. #ifdef SO_RCVBUF
  254. extern int tcp_recvbuf;
  255. #endif /* SO_RCVBUF */
  256. #ifdef SO_KEEPALIVE
  257. extern int tcp_keepalive;
  258. #endif /* SO_KEEPALIVE */
  259. #endif /* SOL_SOCKET */
  260. #endif /* NOTCPOPTS */
  261. #endif /* TCPSOCKET */
  262. #endif /* NETCONN */
  263.  
  264. extern char * floname[];
  265.  
  266. #ifndef NOSPL
  267. extern int fndiags;                     /* Function diagnostics on/off */
  268. extern int divbyzero;
  269. int ispattern = 0;
  270. #ifdef CK_APC
  271. extern int apcactive;                   /* Nonzero = APC command was rec'd */
  272. extern int apcstatus;                   /* Are APC commands being processed? */
  273. #ifdef DCMDBUF
  274. extern char *apcbuf;                    /* APC command buffer */
  275. #else
  276. extern char apcbuf[];
  277. #endif /* DCMDBUF */
  278. #endif /* CK_APC */
  279.  
  280. extern char evalbuf[];                  /* EVALUATE result */
  281. extern char uidbuf[], pwbuf[], prmbuf[];
  282. _PROTOTYP( static char * fneval, (char *, char * [], int, char * ) );
  283. _PROTOTYP( static VOID myflsh, (void) );
  284. _PROTOTYP( static char * getip, (char *) );
  285. _PROTOTYP( int delta2sec, (char *, long *) );
  286.  
  287. #ifdef NEWFTP
  288. _PROTOTYP( char * ftp_cpl_mode, (void) );
  289. _PROTOTYP( char * ftp_dpl_mode, (void) );
  290. _PROTOTYP( char * ftp_authtype, (void) );
  291. #endif /* NEWFTP */
  292.  
  293. #ifndef NOHTTP
  294. _PROTOTYP( char * http_host, (void) );
  295. _PROTOTYP( int http_isconnected, (void) );
  296. _PROTOTYP( char * http_security, (void) );
  297. #endif /* NOHTTP */
  298.  
  299. #ifndef NOSEXP
  300. _PROTOTYP( char * dosexp, (char *) );
  301. int fsexpflag = 0;
  302. #endif /* NOSEXP */
  303.  
  304. static char hexdigits[16] = {
  305.     '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  306. };
  307. extern char * tempdir;
  308.  
  309. #ifdef CK_REXX
  310. extern char rexxbuf[];
  311. #endif /* CK_REXX */
  312.  
  313. extern int tfline[];
  314.  
  315. /* These need to be internationalized... */
  316.  
  317. static
  318. char *wkdays[] = {
  319.     "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  320. };
  321. #endif /* NOSPL */
  322.  
  323. #ifdef OS2
  324. extern char startupdir[], inidir[];
  325. #else
  326. #ifdef VMSORUNIX
  327. extern char startupdir[];
  328. #endif /* VMSORUNIX */
  329. #endif /* OS2 */
  330.  
  331. #ifdef OS2
  332. _PROTOTYP (int os2getcp, (void) );
  333. #ifdef TCPSOCKET
  334. extern char tcpname[];
  335. #endif /* TCPSOCKET */
  336. extern int tcp_avail;
  337. #ifdef DECNET
  338. extern int dnet_avail;
  339. #endif /* DECNET */
  340. #ifdef SUPERLAT
  341. extern int slat_avail;
  342. #endif /* SUPERLAT */
  343.  
  344. #ifndef NOTERM
  345. extern int tt_type, max_tt;
  346. extern struct tt_info_rec tt_info[];
  347. #endif /* NOTERM */
  348. extern int tt_rows[], tt_cols[];
  349. #else /* OS2 */
  350. extern int tt_rows, tt_cols;
  351. #endif /* OS2 */
  352.  
  353. #ifdef CK_TAPI
  354. extern int tttapi;
  355. extern int tapipass;
  356. extern struct keytab * tapilinetab;
  357. extern struct keytab * _tapilinetab;
  358. extern int ntapiline;
  359. #endif /* CK_TAPI */
  360.  
  361. extern struct keytab colxtab[];
  362. extern int ncolx;
  363.  
  364. extern char ttname[], *zinptr, *kermrc;
  365. extern char inidir[];
  366.  
  367. extern int activecmd, remonly, cmd_rows, cmd_cols, parity, seslog,
  368.   sessft, sosi, hwparity, tsecs, xargs, zincnt, tlevel, insilence, cmdmsk,
  369.   timint, timef, inbufsize, dialog, binary, carrier, cdtimo, cmask, duplex,
  370.   fmask, inecho, nettype, nmac, turnch, turn, kbchar;
  371.  
  372. #ifndef NOXFER
  373. extern CHAR eol,  mypadc, mystch, padch, seol, stchr, * epktmsg, feol;
  374. extern char *cksysid;
  375. extern struct ck_p ptab[];
  376. extern int
  377.   protocol, prefixing, xfrbel, xfrcan, xfrint, xfrchr, xfrnum, pktpaus,
  378.   lscapr, lscapu, xfermode, dest, slostart, maxrps, maxsps, maxtry, mypadn,
  379.   npad, pkttim, bigrbsiz, bigsbsiz, keep, atcapr, autopar, bctr, bctu,
  380.   crunched, ckdelay, ebq, ebqflg, pktlog, retrans, rpackets, rptflg, rptq,
  381.   rtimo, spackets, spsiz, spsizf, spsizr, timeouts, fncact, fncnv, urpsiz,
  382.   wmax, wslotn, wslotr, fdispla, spmax, fnrpath, fnspath, crc16;
  383. #endif /* NOXFER */
  384.  
  385. #ifdef OS2
  386. extern int zxpn;
  387. extern int viewonly;
  388. #endif /* OS2 */
  389.  
  390. #ifndef NOXFER
  391. #ifdef GFTIMER
  392. extern CKFLOAT fptsecs, fpxfsecs;
  393. #endif /* GFTIMER */
  394. extern long xfsecs, tfcps;
  395.  
  396. #ifdef CK_TMPDIR
  397. extern char *dldir;
  398. #endif /* CK_TMPDIR */
  399. #endif /* NOXFER */
  400.  
  401. #ifdef RECURSIVE
  402. extern int recursive;
  403. #endif /* RECURSIVE */
  404.  
  405. #ifdef VMS
  406.   extern int frecl;
  407. #endif /* VMS */
  408.  
  409. extern long
  410.   ffc, filcnt, rptn, speed, tfc, tlci, tlco, ccu, ccp, vernum, xvernum;
  411.  
  412. #ifndef NOSPL
  413. extern char fspec[], myhost[];
  414. #endif /* NOSPL */
  415.  
  416. extern char *tfnam[];                   /* Command file names */
  417.  
  418. extern char pktfil[],                   /* Packet log file name */
  419. #ifdef TLOG
  420.   trafil[],                             /* Transaction log file name */
  421. #endif /* TLOG */
  422.   sesfil[];                             /* Session log file name */
  423.  
  424. #ifndef NOXMIT                          /* TRANSMIT command variables */
  425. extern char xmitbuf[];
  426. extern int xmitf, xmitl, xmitx, xmits, xmitw, xmitt;
  427. #endif /* NOXMIT */
  428.  
  429. extern int cmdlvl;
  430.  
  431. #ifndef NOSPL
  432. /* Script programming language items */
  433. extern char **a_ptr[];                  /* Arrays */
  434. extern int a_dim[];
  435. static char * inpmatch = NULL;
  436. extern char * inpbuf, inchar[];         /* Buffers for INPUT and REINPUT */
  437. extern char *inpbp;                     /* And pointer to same */
  438. static char *r3 = (char *)0;
  439. extern int incount;                     /* INPUT character count */
  440. extern int m_found;                     /* MINPUT result */
  441. extern int maclvl;                      /* Macro invocation level */
  442. extern struct mtab *mactab;             /* Macro table */
  443. extern char *mrval[];
  444. extern int macargc[], topargc;
  445.  
  446. #ifdef COMMENT
  447. extern char *m_line[];
  448. extern char *topline;
  449. #endif /* COMMENT */
  450.  
  451. extern char *m_arg[MACLEVEL][10]; /* You have to put in the dimensions */
  452. extern char *g_var[GVARS];        /* for external 2-dimensional arrays. */
  453. #ifdef DCMDBUF
  454. extern int *count, *inpcas;
  455. #else
  456. extern int count[], inpcas[];
  457. #endif /* DCMDBUF */
  458. #endif /* NOSPL */
  459.  
  460. #ifdef UNIX
  461. extern int haslock;                     /* For UUCP locks */
  462. extern char flfnam[];
  463. #ifndef USETTYLOCK
  464. extern char lock2[];
  465. #endif /* USETTYLOCK */
  466. #endif /* UNIX */
  467.  
  468. #ifdef OS2ORUNIX
  469. extern int maxnam, maxpath;             /* Longest name, path length */
  470. #endif /* OS2ORUNIX */
  471.  
  472. extern int mdmtyp, mdmsav;
  473.  
  474. #ifndef NODIAL
  475. /* DIAL-related variables */
  476. extern char modemmsg[];
  477. extern MDMINF *modemp[];                /* Pointers to modem info structs */
  478. extern int nmdm, dialhng, dialtmo, dialksp, dialdpy, dialsrt, dialsta;
  479. extern int dialrtr, dialint, dialrstr, dialcon, dialcq, dialfld;
  480. extern int mdmspd, dialec, dialdc, dialmth, dialmauto, dialesc;
  481. extern char *dialnum,   *dialini,  *dialdir[], *dialcmd,  *dialnpr,
  482.  *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd, *diallac,
  483.  *dialhwfc, *dialswfc,  *dialnofc, *dialpulse, *dialtone, *dialname,
  484.  *dialaaon, *dialaaoff, *dialmac;
  485. extern char *diallcc,   *dialixp,  *dialixs,   *dialldp,  *diallds,
  486.  *dialpxi,  *dialpxo,   *dialsfx,  *dialtfp;
  487. extern char *diallcp,   *diallcs;
  488. extern int ntollfree, ndialpxx, nlocalac;
  489. extern char *dialtfc[], *diallcac[], *dialpxx[], *matchpxx;
  490. extern int ndialpucc, ndialtocc;
  491. extern char *dialtocc[], *dialpucc[];
  492. extern int ndialdir, dialcnf, dialcvt, dialidt, dialpace;
  493. extern long dialmax, dialcapas;
  494.  
  495. extern struct keytab mdmtab[];
  496.  
  497. #ifdef BIGBUFOK
  498. #define ARGBUFSIZ 8191
  499. #else
  500. #define ARGBUFSIZ 1023
  501. #endif /* BIGBUFOK */
  502.  
  503. #ifdef BIGBUFOK
  504. extern char * dialmsg[];
  505. #endif /* BIGBUFOK */
  506.  
  507. #endif /* NODIAL */
  508.  
  509. #ifndef NOCSETS
  510. /* Translation stuff */
  511. extern int fcharset, tcharset, tslevel, language, nlng, tcsr, tcsl;
  512. extern int dcset7, dcset8;
  513. extern struct keytab lngtab[];
  514. extern struct csinfo fcsinfo[], tcsinfo[];
  515. extern struct langinfo langs[];
  516. #ifdef CK_ANSIC
  517. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  518. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  519. #else
  520. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(); /* Character set */
  521. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(); /* translation functions. */
  522. #endif /* CK_ANSIC */
  523. #ifdef UNICODE
  524.     extern int ucsbom, ucsorder;
  525. #endif /* UNICODE */
  526. #endif /* NOCSETS */
  527.  
  528. #ifndef NOSPL
  529. /* Built-in variable names, maximum length VNAML (20 characters) */
  530.  
  531. struct keytab vartab[] = {
  532.     { "_line",     VN_TFLN,  CM_INV},    /* 192 */
  533. #ifdef OS2
  534.     { "_regname",  VN_REGN,  CM_INV},    /* 1.1.12 */
  535.     { "_regorg",   VN_REGO,  CM_INV},    /* 1.1.12 */
  536.     { "_regnum",   VN_REGS,  CM_INV},    /* 1.1.12 */
  537. #endif /* OS2 */
  538.     { "apcactive", VN_APC,   CM_INV},    /* 192 */
  539.     { "argc",      VN_ARGC,  0},
  540.     { "args",      VN_ARGS,  0},
  541.     { "authname",  VN_AUTHN, 0},    /* 196 */
  542.     { "authstate", VN_AUTHS, 0},    /* 195 */
  543.     { "authtype",  VN_AUTHT, 0},    /* 195 */
  544.     { "blockcheck",VN_BLK,   0},    /* 195 */
  545. #ifdef BROWSER
  546.     { "browser",   VN_BROWSR,0},    /* 193 */
  547.     { "browsopts", VN_BROPT, 0},    /* 193 */
  548.     { "browsurl",  VN_URL,   0},    /* 193 */
  549.     { "buildid",   VN_BUILD, 0},    /* 199 */
  550. #endif /* BROWSER */
  551.     { "byteorder", VN_BYTE,  0},    /* 195 */
  552. #ifndef NOCSETS
  553.     { "charset",   VN_CSET,  0},    /* 192 */
  554. #endif /* NOCSETS */
  555.     { "cmdbufsize",VN_CMDBL, 0},    /* 195 */
  556.     { "cmdfile",   VN_CMDF,  0},
  557.     { "cmdlevel",  VN_CMDL,  0},
  558.     { "cmdsource", VN_CMDS,  0},
  559.     { "cols",      VN_COLS,  0},    /* 190 */
  560.     { "connection",VN_CONN,  0},    /* 190 */
  561.     { "count",     VN_COUN,  0},
  562. #ifndef NOXFER
  563.     { "cps",       VN_CPS,   0},    /* 190 */
  564. #endif /* NOXFER */
  565.     { "cpu",       VN_CPU,   0},
  566. #ifndef NOXFER
  567.     { "crc16",     VN_CRC16, 0},    /* 192 */
  568.     { "ctty",      VN_TTYNAM,0},    /* 196 */
  569. #endif /* NOXFER */
  570. #ifndef NOLOGDIAL
  571. #ifndef NOLOCAL
  572.     { "cx_time",   VN_CXTIME,0},    /* 195 */
  573.     { "cx_status", VN_CX_STA,0},    /* 199 */
  574. #endif /* NOLOCAL */
  575. #endif /* NOLOGDIAL */
  576. #ifndef NODIAL
  577.     { "d$ac",      VN_D_AC,  0},    /* 192 */
  578.     { "d$cc",      VN_D_CC,  0},    /* 192 */
  579.     { "d$ip",      VN_D_IP,  0},    /* 192 */
  580.     { "d$lc",      VN_D_LCP, 0},    /* 193 */
  581.     { "d$lcp",     VN_D_LCP, CM_INV},    /* 193 */
  582.     { "d$lp",      VN_D_LP,  0},    /* 192 */
  583.     { "d$px",      VN_D_PXX, 0},    /* 195 */
  584.     { "d$pxx",     VN_D_PXX, CM_INV},    /* 195 */
  585. #endif /* NODIAL */
  586.     { "date",      VN_DATE,  0},
  587.     { "day",       VN_DAY,   0},
  588. #ifndef NODIAL
  589.     { "dialcount", VN_DRTR,  0},    /* 195 */
  590.     { "dialnumber",VN_DNUM,  0},    /* 192 */
  591.     { "dialresult",VN_MDMSG, 0},    /* 192 */
  592.     { "dialstatus",VN_DIAL,  0},    /* 190 */
  593.     { "dialsuffix",VN_PDSFX, 0},    /* 193 */
  594.     { "dialtype",  VN_DTYPE, 0},    /* 193 */
  595. #endif /* NODIAL */
  596.     { "directory", VN_DIRE,  0},
  597. #ifndef NODIAL
  598.     { "dm_hf",     VN_DM_HF, 0},    /* 199 */
  599.     { "dm_lp",     VN_DM_LP, 0},    /* 195 */
  600.     { "dm_sp",     VN_DM_SP, 0},    /* 195 */
  601.     { "dm_pd",     VN_DM_PD, 0},    /* 195 */
  602.     { "dm_td",     VN_DM_TD, 0},    /* 195 */
  603.     { "dm_wa",     VN_DM_WA, 0},    /* 195 */
  604.     { "dm_wb",     VN_DM_WB, 0},    /* 199 */
  605.     { "dm_wd",     VN_DM_WD, 0},    /* 195 */
  606.     { "dm_rc",     VN_DM_RC, 0},    /* 195 */
  607. #endif /* NODIAL */
  608. #ifndef NOXFER
  609.     { "download",  VN_DLDIR, 0},    /* 192 */
  610. #endif /* NOXFER */
  611.     { "editor",    VN_EDITOR,0},
  612.     { "editfile",  VN_EDFILE,0},
  613.     { "editopts",  VN_EDOPT, 0},
  614.     { "errno",     VN_ERRNO, 0},    /* 192 */
  615.     { "errstring", VN_ERSTR, 0},    /* 192 */
  616.     { "escape",    VN_ESC,   0},    /* 193 */
  617.     { "evaluate",  VN_EVAL,  0},    /* 190 */
  618. #ifdef OS2ORUNIX
  619.     { "exedir",    VN_EXEDIR,0},    /* 192 */
  620. #endif /* OS2ORUNIX */
  621.     { "exitstatus",VN_EXIT,  0},
  622. #ifdef CKCHANNELIO
  623.     { "f_count",   VN_FCOU,  0},    /* 195 */
  624.     { "f_error",   VN_FERR,  0},    /* 195 */
  625.     { "f_max",     VN_FMAX,  0},    /* 195 */
  626.     { "fileerror", VN_FERR,  CM_INV},    /* 195 */
  627.     { "filemax",   VN_FERR,  CM_INV},    /* 195 */
  628. #endif /* CKCHANNELIO */
  629.     { "filename",  VN_FNAM,  0},    /* 193 */
  630.     { "filenumber",VN_FNUM,  0},    /* 193 */
  631.     { "filespec",  VN_FILE,  0},
  632.     { "fsize",     VN_FFC,   0},    /* 190 */
  633. #ifdef GFTIMER
  634.     { "ftime",     VN_FTIME, 0},    /* 199 */
  635. #else
  636.     { "ftime",     VN_NTIM,  CM_INV},
  637. #endif /* GFTIMER */
  638. #ifndef NOFTP
  639. #ifndef SYSFTP
  640.     { "ftp_code",         VN_FTP_C, 0},    /* 199 */
  641.     { "ftp_cpl",          VN_FTP_B, 0}, /* 199 */
  642.     { "ftp_connected",    VN_FTP_X, 0},    /* 199 */
  643.     { "ftp_dpl",          VN_FTP_D, 0}, /* 199 */
  644.     { "ftp_getputremote", VN_FTP_G, 0},    /* 199 */
  645.     { "ftp_host",         VN_FTP_H, 0},    /* 199 */
  646.     { "ftp_loggedin",     VN_FTP_L, 0},    /* 199 */
  647.     { "ftp_message",      VN_FTP_M, 0},    /* 199 */
  648.     { "ftp_msg",          VN_FTP_M, CM_INV}, /* 199 */
  649.     { "ftp_security",     VN_FTP_Z, 0}, /* 199 */
  650.     { "ftp_server",       VN_FTP_S, 0},    /* 199 */
  651. #endif /* SYSFTP */
  652. #endif /* NOFTP */
  653.     { "ftype",     VN_MODE,  0},    /* 190 */
  654.     { "herald",    VN_HERALD,0},
  655.     { "home",      VN_HOME,  0},
  656.     { "host",      VN_HOST,  0},
  657.     { "hour",      VN_HOUR,  0},    /* 200 */
  658. #ifndef NOHTTP
  659.     { "http_code",      VN_HTTP_C, 0},  /* 199 */
  660.     { "http_connected", VN_HTTP_N, 0},  /* 199 */
  661.     { "http_host",      VN_HTTP_H, 0},  /* 199 */
  662.     { "http_message",   VN_HTTP_M, 0},  /* 199 */
  663.     { "http_security",  VN_HTTP_S, 0},  /* 199 */
  664. #endif /* NOHTTP */
  665.     { "hwparity",  VN_HWPAR, 0},    /* 195 */
  666.     { "input",     VN_IBUF,  0},
  667.     { "inchar",    VN_ICHR,  0},
  668.     { "incount",   VN_ICNT,  0},
  669.     { "inidir",    VN_INI,   0},    /* 192 */
  670.     { "inmatch",   VN_MATCH, 0},    /* 196 */
  671.     { "instatus",  VN_ISTAT, 0},    /* 192 */
  672.     { "intime",    VN_INTIME,0},    /* 193 */
  673.     { "inwait",    VN_INTMO, 0},    /* 195 */
  674.     { "ip",        VN_IPADDR, CM_ABR|CM_INV},
  675.     { "ipaddress", VN_IPADDR,0},    /* 192 */
  676.     { "iprompt",   VN_PROMPT,0},    /* 199 */
  677.     { "kbchar",    VN_KBCHAR,0},    /* 196 */
  678. #ifndef NOLOCAL
  679. #ifdef OS2
  680.     { "keyboard",  VN_KEYB,  0},
  681. #endif /* OS2 */
  682. #endif /* NOLOCAL */
  683. #ifdef CK_KERBEROS
  684.     { "krb4errmsg",    VN_K4EMSG,0},
  685.     { "krb4errno",     VN_K4ENO, 0},
  686.     { "krb4principal", VN_K4PRN, 0},
  687.     { "krb4realm",     VN_K4RLM, 0},
  688.     { "krb4service",   VN_K4SRV, 0},
  689.     { "krb5cc",        VN_K5CC,  0},
  690.     { "krb5errmsg",    VN_K5EMSG,0},
  691.     { "krb5errno",     VN_K5ENO, 0},
  692.     { "krb5principal", VN_K5PRN, 0},
  693.     { "krb5realm",     VN_K5RLM, 0},
  694.     { "krb5service",   VN_K5SRV, 0},
  695. #endif /* CK_KERBEROS */
  696.     { "line",      VN_LINE,  0},
  697.     { "local",     VN_LCL,   0},
  698. #ifdef UNIX
  699.     { "lockdir",   VN_LCKDIR,0},    /* 195 */
  700.     { "lockpid",   VN_LCKPID,0},    /* 195 */
  701. #endif /* UNIX */
  702.     { "maclevel",  VN_MACLVL,0},    /* 195 */
  703.     { "macro",     VN_MAC,   0},
  704. #ifdef FNFLOAT
  705.     { "math_e",    VN_MA_E,  0},    /* 195 */
  706.     { "math_pi",   VN_MA_PI, 0},    /* 195 */
  707.     { "math_precision", VN_MA_PR, 0},    /* 195 */
  708. #endif /* FNFLOAT */
  709.     { "minput",    VN_MINP,  0},    /* 192 */
  710.     { "model",     VN_MODL,  0},    /* 193 */
  711.     { "modem",     VN_MDM,   0},
  712. #ifndef NOLOCAL
  713. #ifdef OS2
  714.     { "mousecurx", VN_MOU_X, 0},    /* K95 1.1.14 */
  715.     { "mousecury", VN_MOU_Y, 0},    /* K95 1.1.14 */
  716. #endif /* OS2 */
  717. #endif /* NOLOCAL */
  718. #ifndef NODIAL
  719.     { "m_aa_off",  VN_M_AAX, 0},    /* all 192... */
  720.     { "m_aa_on",   VN_M_AAO, 0},
  721.     { "m_dc_off",  VN_M_DCX, 0},
  722.     { "m_dc_on",   VN_M_DCO, 0},
  723.     { "m_dial",    VN_M_DCM, 0},
  724.     { "m_ec_off",  VN_M_ECX, 0},
  725.     { "m_ec_on",   VN_M_ECO, 0},
  726.     { "m_fc_hw",   VN_M_HWF, 0},
  727.     { "m_fc_no",   VN_M_NFC, 0},
  728.     { "m_fc_sw",   VN_M_SWF, 0},
  729.     { "m_hup",     VN_M_HUP, 0},
  730.     { "m_init",    VN_M_INI, 0},
  731.     { "m_name",    VN_M_NAM, 0},    /* 195 */
  732.     { "m_pulse",   VN_M_PDM, 0},
  733.     { "m_sig_cd",  VN_MS_CD, 0},    /* 195 */
  734.     { "m_sig_cts", VN_MS_CTS,0},    /* 195 */
  735.     { "m_sig_dsr", VN_MS_DSR,0},    /* 195 */
  736.     { "m_sig_dtr", VN_MS_DTR,0},    /* 195 */
  737.     { "m_sig_ri",  VN_MS_RI, 0},    /* 195 */
  738.     { "m_sig_rts", VN_MS_RTS,0},    /* 195 */
  739.     { "m_tone",    VN_M_TDM, 0},
  740. #endif /* NODIAL */
  741.     { "name",      VN_NAME,  0},
  742.     { "ndate",     VN_NDAT,  0},
  743.     { "nday",      VN_NDAY,  0},
  744.     { "newline",   VN_NEWL,  0},
  745.     { "ntime",     VN_NTIM,  0},
  746.     { "osname",    VN_OSNAM, 0},    /* 193 */
  747.     { "osrelease", VN_OSREL, 0},    /* 193 */
  748.     { "osversion", VN_OSVER, 0},    /* 193 */
  749. #ifndef NOXFER
  750.     { "packetlen", VN_RPSIZ, 0},    /* 192 */
  751. #endif /* NOXFER */
  752.     { "parity",    VN_PRTY,  0},    /* 190 */
  753.     { "password",  VN_PWD,   CM_INV},    /* 192 */
  754. #ifdef PEXITSTAT
  755.     { "pexitstat", VN_PEXIT, 0},    /* 193 */
  756. #endif /* PEXITSTAT */
  757. #ifdef CK_PID
  758.     { "pid",       VN_PID,   0},    /* 193 */
  759. #endif /* CK_PID */
  760.     { "platform",  VN_SYSV,  0},
  761.     { "printer",   VN_PRINT, 0},    /* 193 */
  762.     { "program",   VN_PROG,  0},
  763.     { "prompt",    VN_PRM,   CM_INV},    /* 192 */
  764. #ifndef NOXFER
  765.     { "protocol",  VN_PROTO, 0},    /* 192 */
  766.     { "p_8bit",    VN_P_8BIT,0},    /* 193 */
  767.     { "p_ctl",     VN_P_CTL, 0},    /* 193 */
  768.     { "p_rpt",     VN_P_RPT, 0},    /* 193 */
  769.     { "query",     VN_QUE,   0},    /* 190 */
  770. #endif /* NOXFER */
  771.     { "return",    VN_RET,   0},
  772. #ifdef CK_REXX
  773.     { "rexx",      VN_REXX,  0},    /* 190 */
  774. #endif /* CK_REXX */
  775.     { "rows",      VN_ROWS,  0},    /* 190 */
  776. #ifndef NOSEXP
  777.     { "sdepth",    VN_LSEXP,0},        /* 199 */
  778. #endif /* NOSEXP */
  779.     { "secure",    VN_SECURE, 0},    /* 199 */
  780. #ifndef NOLOCAL
  781. #ifdef OS2
  782.     { "select",    VN_SELCT, 0},    /* 192 */
  783. #endif /* OS2 */
  784. #endif /* NOLOCAL */
  785.     { "sendlist",  VN_SNDL,  0},
  786.     { "serial",    VN_SERIAL,0},    /* 195 */
  787.     { "setlinemsg",VN_SLMSG, 0},    /* 195 */
  788. #ifndef NOSEXP
  789.     { "sexpression",VN_SEXP, 0},    /* 199 */
  790. #endif /* NOSEXP */
  791.     { "speed",     VN_SPEE,  0},
  792. #ifdef OS2
  793.     { "space",     VN_SPA,   0},
  794.     { "startup",   VN_STAR,  0},    /* 190 */
  795. #else
  796. #ifdef UNIX
  797.     { "startup",   VN_STAR,  0},    /* 193 */
  798. #else
  799. #ifdef VMS
  800.     { "startup",   VN_STAR,  0},    /* 193 */
  801. #endif /* VMS */
  802. #endif /* UNIX */
  803. #endif /* OS2 */
  804.     { "status",    VN_SUCC,  0},
  805. #ifndef NOSEXP
  806.     { "svalue",    VN_VSEXP, 0},    /* 199 */
  807. #endif /* NOSEXP */
  808. #ifndef NOXFER
  809.     { "sysid",     VN_SYSI,  0},
  810. #endif /* NOXFER */
  811.     { "system",    VN_SYST,  0},
  812.     { "terminal",  VN_TTYP,  0},
  813. #ifdef OS2
  814. #ifndef NOKVERBS
  815.     { "termkey",   VN_TRMK,  CM_INV},    /* 192 */
  816. #endif /* NOKVERBS */
  817. #endif /* OS2 */
  818.     { "test",      VN_TEST,  0},    /* 193 */
  819.     { "textdir",   VN_TXTDIR,0},    /* 195 */
  820. #ifndef NOXFER
  821.     { "tfsize",    VN_TFC,   0},
  822.     { "tftime",    VN_TFTIM, 0},    /* 195 */
  823. #endif /* NOXFER */
  824.     { "time",      VN_TIME,  0},
  825.     { "timestamp", VN_NOW,   0},    /* 200 */
  826.     { "tmpdir",    VN_TEMP,  0},    /* 192 */
  827. #ifdef CK_TRIGGER
  828.     { "trigger",   VN_TRIG,  0},    /* 193 */
  829. #endif /* CK_TRIGGER */
  830. #ifdef CK_TTYFD
  831.     { "ttyfd",     VN_TTYF,  0},
  832. #endif /* CK_TTYFD */
  833.     { "ty_ln",     VN_TY_LN, 0},    /* 195 */
  834.     { "ty_lc",     VN_TY_LC, 0},    /* 195 */
  835.     { "ty_lm",     VN_TY_LM, 0},    /* 195 */
  836. #ifdef BROWSER
  837.     { "url",       VN_URL,   CM_INV},    /* 193 */
  838. #endif /* BROWSER */
  839.     { "userid",    VN_UID,   0},    /* 192 */
  840.     { "version",   VN_VERS,  0},
  841. #ifndef NOXFER
  842.     { "window",    VN_WINDO, 0},    /* 192 */
  843. #endif /* NOXFER */
  844. #ifdef IBMX25
  845.     { "x25local_nua", VN_X25LA, 0},    /* 193 */
  846.     { "x25remote_nua", VN_X25RA, 0},    /* 193 */
  847. #endif /* IBMX25 */
  848. #ifdef CK_SSL
  849.     { "x509_issuer",  VN_X509_I, 0},
  850.     { "x509_subject", VN_X509_S, 0},
  851. #endif /* CK_SSL */
  852. #ifndef NOXFER
  853.     { "xferstatus",VN_XFSTAT,0},    /* 193 */
  854.     { "xfermsg",   VN_XFMSG, 0},    /* 193 */
  855.     { "xfer_badpackets", VN_XF_BC, 0},    /* 195 */
  856.     { "xfer_timeouts",   VN_XF_TM, 0},    /* 195 */
  857.     { "xfer_retransmits",VN_XF_RX, 0},    /* 195 */
  858. #endif /* NOXFER */
  859.     { "xprogram",  VN_XPROG, 0},    /* 193 */
  860.     { "xversion",  VN_XVNUM, 0}        /* 192 */
  861. };
  862. int nvars = (sizeof(vartab) / sizeof(struct keytab));
  863. #endif /* NOSPL */
  864.  
  865. #ifndef NOSPL
  866. struct keytab fnctab[] = {              /* Function names */
  867. #ifdef OS2
  868.     { ".oox",       FN_OOX, CM_INV},    /* ... */
  869. #endif /* OS2 */
  870.  
  871. #ifdef CKCHANNELIO
  872.     { "_eof",       FN_FEOF,   0},
  873.     { "_errmsg",    FN_FERMSG, 0},
  874.     { "_getblock",  FN_FGBLK,  0},
  875.     { "_getchar",   FN_FGCHAR, 0},
  876.     { "_getline",   FN_FGLINE, 0},
  877.     { "_handle",    FN_FILNO,  0},
  878.     { "_line",      FN_NLINE,  0},
  879.     { "_pos",       FN_FPOS,   0},
  880.     { "_putblock",  FN_FPBLK,  0},
  881.     { "_putchar",   FN_FPCHAR, 0},
  882.     { "_putline",   FN_FPLINE, 0},
  883.     { "_status",    FN_FSTAT,  0},
  884. #endif /* CKCHANNELIO */
  885.  
  886.     { "aaconvert",  FN_AADUMP, 0},    /* Associative Array conversion */
  887.     { "absolute",   FN_ABS,  0},    /* Absolute value */
  888. #ifdef TCPSOCKET
  889.     { "addr2name",  FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  890.     { "addrtoname", FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  891. #endif /* TCPSOCKET */
  892.     { "arraylook",  FN_ALOOK,0},    /* Array lookup */
  893.     { "b64decode",  FN_FMB64,0},    /* Base-64 conversion */
  894.     { "b64encode",  FN_TOB64,0},    /* ... */
  895.     { "basename",   FN_BSN,  0},    /* Basename */
  896.     { "break",      FN_BRK,  0},    /* Break (as in Snobol) */
  897.     { "ca",         FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  898.     { "cap",        FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  899.     { "capitalize", FN_CAP,  0},    /* First Letter -> uppercase */
  900.     { "caps",       FN_CAP,  CM_INV},    /* ditto */
  901.     { "character",  FN_CHR,  0},    /* Character from code */
  902.     { "checksum",   FN_CHK,  0},    /* Checksum */
  903.     { "cmdstack",   FN_CMDSTK,0},    /* Command stack */
  904.     { "cmpdates",   FN_CMPDATE,0},    /* Compare dates */
  905.     { "code",       FN_COD,  0},    /* Code from character */
  906. #ifndef NOPUSH
  907.     { "command",    FN_CMD,  0},    /* Output from a command */
  908. #endif /* NOPUSH */
  909.     { "contents",   FN_CON,  0},    /* Definition (contents) of variable */
  910.     { "crc16",      FN_CRC,  0},    /* CRC-16 */
  911. #ifdef OS2
  912.     { "crypt",      FN_CRY, CM_INV},
  913. #endif /* OS2 */
  914.     { "cvtdate",    FN_DTIM, 0},    /* Convert free date/time to std */
  915. #ifdef ZFCDAT
  916.     { "date",       FN_FD,   0},    /* File modification/creation date */
  917. #endif /* ZFCDAT */
  918.     { "day",        FN_DAY,  0},    /* Day of week */
  919.     { "dayofyear",  FN_JDATE,0},    /* Date to Day of Year */
  920.     { "definition", FN_DEF,  0},    /* Return definition of given macro */
  921.     { "delta2secs", FN_DELSEC, 0},    /* Delta time to seconds */
  922.     { "deltatosecs", FN_DELSEC, CM_INV}, /* Delta time to seconds */
  923. #ifndef NODIAL
  924.     { "dialconvert",FN_PNCVT,0},    /* Convert portable phone number */
  925. #endif /* NODIAL */
  926.     { "diffdates",  FN_DIFDATE,0},      /* Difference of two date-times */
  927.     { "dimension",  FN_DIM,  0},    /* Dimension of array */
  928.     { "directories",FN_DIR,  0},    /* List of directories */
  929.     { "dirname",    FN_DNAM, 0},    /* Directory part of filename */
  930.     { "dos2unixpath",FN_PC_DU, },    /* DOS to UNIX path */
  931.     { "dostounixpath",FN_PC_DU, CM_INV}, /* DOS to UNIX path */
  932.     { "doy",        FN_JDATE,CM_INV},    /* Date to Day of Year */
  933.     { "doy2date",   FN_DATEJ,0},    /* Day of Year to date */
  934.     { "doytodate",  FN_DATEJ,CM_INV},    /* Day of Year to date */
  935. #ifdef FN_ERRMSG
  936.     { "errstring",  FN_ERRMSG,0},    /* Error code to message */
  937. #endif /* FN_ERRMSG */
  938.     { "evaluate",   FN_EVA,  0},    /* Evaluate given arith expression */
  939.     { "execute",    FN_EXE,  0},    /* Execute given macro */
  940.     { "files",      FN_FC,   0},    /* File count */
  941. #ifdef FNFLOAT
  942.     { "fpabsolute", FN_FPABS, 0},    /* Floating-point absolute value */
  943.     { "fpadd",      FN_FPADD, 0},    /* FP add */
  944.     { "fpcosine",   FN_FPCOS, 0},    /* FP cosine */
  945.     { "fpdivide",   FN_FPDIV, 0},    /* FP divide */
  946.     { "fpexp",      FN_FPEXP, 0},    /* FP e to the x */
  947.     { "fpint",      FN_FPINT, 0},    /* FP to integer */
  948.     { "fplog10",    FN_FPLOG, 0},    /* FP base-10 logarithm */
  949.     { "fplogn",     FN_FPLN,  0},    /* FP natural logarithm */
  950.     { "fpmaximum",  FN_FPMAX, 0},    /* FP maxinum */
  951.     { "fpminimum",  FN_FPMIN, 0},    /* FP mininum */
  952.     { "fpmodulus",  FN_FPMOD, 0},    /* FP modulus */
  953.     { "fpmultiply", FN_FPMUL, 0},    /* FP multiply */
  954.     { "fpraise",    FN_FPPOW, 0},    /* FP raise to a power */
  955.     { "fpround",    FN_FPROU, 0},    /* FP round */
  956.     { "fpsine",     FN_FPSIN, 0},    /* FP sine */
  957.     { "fpsqrt",     FN_FPSQR, 0},    /* FP square root */
  958.     { "fpsubtract", FN_FPSUB, 0},    /* FP subtract */
  959.     { "fptangent",  FN_FPTAN, 0},    /* FP tangent */
  960. #endif /* FNFLOAT */
  961.     { "hex2ip",     FN_HEX2IP,0},    /* Hex to IP address */
  962.     { "hextoip",    FN_HEX2IP,CM_INV},    /* Hex to IP address */
  963.     { "hex2n",      FN_HEX2N, CM_INV},    /* Hex to decimal number */
  964.     { "hexify",     FN_HEX,   0},    /* Hexify (string) */
  965.     { "index",      FN_IND,   0},    /* Index (string search) */
  966.     { "ip2hex",     FN_IP2HEX,0},    /* IP address to hex */
  967.     { "iptohex",    FN_IP2HEX,CM_INV},    /* IP address to hex */
  968.     { "ipaddress",  FN_IPA,   0},    /* Find and return IP address */
  969.     { "jdate",      FN_JDATE, CM_INV},    /* Date to Day of Year */
  970.     { "join",       FN_JOIN,  0},    /* Join array elements */
  971.     { "keywordvalue",  FN_KWVAL, 0},    /* Keyword=Value */
  972. #ifdef CK_KERBEROS
  973.     { "krbflags",      FN_KRB_FG, 0},    /* Kerberos functions */
  974.     { "krbisvalid",    FN_KRB_IV, 0},
  975.     { "krbnextticket", FN_KRB_NX, 0},
  976.     { "krbtickets",    FN_KRB_TK, 0},
  977.     { "krbtimeleft",   FN_KRB_TT, 0},
  978. #endif /* CK_KERBEROS */
  979.     { "left",       FN_LEF,  0},    /* Leftmost n characters of string */
  980.     { "length",     FN_LEN,  0},    /* Return length of argument */
  981.     { "literal",    FN_LIT,  0},    /* Return argument literally */
  982.     { "lop",        FN_STL,  0},    /* Lop */
  983.     { "lower",      FN_LOW,  0},    /* Return lowercased argument */
  984.     { "lpad",       FN_LPA,  0},    /* Return left-padded argument */
  985.     { "ltrim",      FN_LTR,  0},    /* Left-Trim */
  986.     { "maximum",    FN_MAX,  0},    /* Return maximum of two arguments */
  987.     { "minimum",    FN_MIN,  0},    /* Return minimum of two arguments */
  988.     { "mjd",        FN_MJD,  0},    /* Date to Modified Julian Date */
  989.     { "mjd2date",   FN_MJD2, 0},    /* MJD to Date */
  990.     { "mjdtodate",  FN_MJD2, CM_INV},    /* MJD to Date */
  991.     { "modulus",    FN_MOD,  0},    /* Return modulus of two arguments */
  992. #ifdef COMMENT
  993.     { "msleep",     FN_MSLEEP,0},    /* Sleep for n milliseconds */
  994. #endif /* COMMENT */
  995.     { "n2hex",      FN_2HEX, CM_INV},    /* Number to hex */
  996.     { "n2octal",    FN_2OCT, CM_INV},    /* Number to octal */
  997.     { "n2time",     FN_N2TIM,0},    /* Number to hh:mm:ss */
  998. #ifdef TCPSOCKET
  999.     { "name2addr",  FN_HSTNAM,CM_INV},  /* Hostname to IP Address */
  1000. #endif /* TCPSOCKET */
  1001.     { "nday",       FN_NDAY, 0},    /* Numeric day of week */
  1002.     { "nextfile",   FN_FIL,  0},    /* Next file in list */
  1003.     { "ntime",      FN_NTIM, 0},    /* Time to seconds since midnight */
  1004.     { "ntohex",     FN_2HEX, CM_INV},    /* Number to hex */
  1005.     { "ntooctal",   FN_2OCT, CM_INV},    /* Number to octal */
  1006.     { "ntotime",    FN_N2TIM,CM_INV},    /* Number to hh:mm:ss */
  1007.     { "oct2n",      FN_OCT2N,CM_INV},    /* Octal to decimal number */
  1008.     { "octton",     FN_OCT2N,CM_INV},    /* Octal to decimal number */
  1009.     { "pathname",   FN_FFN,  0},    /* Full file name */
  1010.     { "pattern",    FN_PATTERN, 0},    /* Pattern (for INPUT) */
  1011. #ifdef CK_PERMS
  1012.     { "permissions",FN_PERM, 0},    /* Permissions of file */
  1013. #else
  1014.     { "permissions",FN_PERM, CM_INV},    /* Permissions of file */
  1015. #endif /* CK_PERMS */
  1016.     { "radix",      FN_RADIX,0},    /* Radix conversion */
  1017. #ifndef NORANDOM
  1018.     { "random",     FN_RAND, 0},    /* Random number */
  1019. #endif /* NORANDOM */
  1020. #ifndef NOPUSH
  1021.     { "rawcommand", FN_RAW,  0},    /* Output from a command (raw) */
  1022. #endif /* NOPUSH */
  1023. #ifdef RECURSIVE
  1024.     { "rdirectories", FN_RDIR, 0},    /* Recursive directory list */
  1025.     { "rfiles",       FN_RFIL, 0},    /* Recursive file list */
  1026. #endif /* RECURSIVE */
  1027.     { "rep",        FN_REP, CM_INV|CM_ABR},
  1028.     { "repeat",     FN_REP,  0},    /* Repeat argument given # of times */
  1029.     { "replace",    FN_RPL,  0},    /* Replace characters in string */
  1030.     { "reverse",    FN_REV,  0},    /* Reverse the argument string */
  1031.     { "right",      FN_RIG,  0},    /* Rightmost n characters of string */
  1032.     { "rindex",     FN_RIX,  0},    /* Right index */
  1033.     { "rpad",       FN_RPA,  0},    /* Right-pad the argument */
  1034.     { "rsearch",    FN_RSEARCH, 0},    /* R-L Search for pattern in string */
  1035. #ifdef OS2
  1036.     { "scrncurx",   FN_SCRN_CX,  0},    /* Screen Cursor X Pos */
  1037.     { "scrncury",   FN_SCRN_CY,  0},    /* Screen Cursor Y Pos */
  1038.     { "scrnstr",    FN_SCRN_STR, 0},    /* Screen String */
  1039. #endif /* OS2 */
  1040.     { "search",     FN_SEARCH, 0},    /* L-R Search for pattern in string */
  1041. #ifndef NOSEXP
  1042.     { "sexpression",FN_SEXP, 0},    /* S-Expression */
  1043. #endif /* NOSEXP */
  1044.     { "size",       FN_FS,   0},    /* File size */
  1045. #ifdef COMMENT
  1046.     { "sleep",      FN_SLEEP,0},    /* Sleep for n seconds */
  1047. #endif /* COMMENT */
  1048.     { "span",       FN_SPN,  0},    /* Span - like Snobol */
  1049.     { "split",      FN_SPLIT,0},    /* Split string into words */
  1050.     { "stripb",     FN_STB,  0},    /* Strip enclosing braces/brackets */
  1051.     { "stripn",     FN_STN,  0},    /* Strip n chars */
  1052.     { "stripx",     FN_STX,  0},    /* Strip suffix */
  1053.     { "su",         FN_SUB,  CM_INV|CM_ABR},
  1054.     { "sub",        FN_SUB,  CM_INV|CM_ABR},
  1055.     { "subs",       FN_SUB,  CM_INV|CM_ABR},
  1056.     { "subst",      FN_SUB,  CM_INV|CM_ABR},
  1057.     { "substitute", FN_SUBST,0},    /* Substitute chars */
  1058.     { "substring",  FN_SUB,  0},    /* Extract substring from argument */
  1059.     { "tablelook",  FN_TLOOK,0},    /* Table lookup */
  1060.     { "time",       FN_TIME, 0},    /* Free-format time to hh:mm:ss */
  1061.     { "tod2secs",   FN_NTIM, CM_INV},    /* Time-of-day-to-secs-since-midnite */
  1062.     { "todtosecs",  FN_NTIM, CM_INV},    /* Time-of-day-to-secs-since-midnite */
  1063.     { "trim",       FN_TRM,  0},    /* Trim */
  1064.     { "unhexify",   FN_UNH,  0},    /* Unhexify */
  1065.     { "unix2dospath",FN_PC_UD, 0},    /* UNIX to DOS path */
  1066.     { "unixtodospath",FN_PC_UD, CM_INV}, /* UNIX to DOS path */
  1067.     { "upper",      FN_UPP,  0},    /* Return uppercased argument */
  1068.     { "utcdate",    FN_TOGMT,0},    /* Date-time to UTC (GMT) */
  1069.     { "verify",     FN_VER,  0},    /* Verify */
  1070.     { "word",       FN_WORD, 0},    /* Extract a word */
  1071.     { "", 0, 0}
  1072. };
  1073. int nfuncs = (sizeof(fnctab) / sizeof(struct keytab)) - 1;
  1074. #endif /* NOSPL */
  1075.  
  1076. #ifndef NOSPL                           /* Buffer for expansion of */
  1077. #ifdef BIGBUFOK                         /* built-in variables. */
  1078. #define VVBUFL 1024
  1079. #else
  1080. #define VVBUFL 256
  1081. #endif /* BIGBUFOK */
  1082. char vvbuf[VVBUFL+1];
  1083. #endif /* NOSPL */
  1084.  
  1085. struct keytab disptb[] = {              /* Log file disposition */
  1086.     { "append",    1,  0},
  1087.     { "new",       0,  0}
  1088. };
  1089.  
  1090. #ifdef CKFLOAT
  1091.  
  1092. /* I N I T F L O A T  --  Deduce floating-point precision by inspection */
  1093.  
  1094. int fp_rounding = 0;                /* Nonzero if printf("%f") rounds */
  1095. int fp_digits = 0;                  /* Digits of floating point precision */
  1096.  
  1097. #ifdef COMMENT
  1098. /* For looking at internal floating-point representations */
  1099. static char fp_xbuf[128];
  1100. static char *
  1101. tohex(s, n) CHAR * s; int n; {
  1102.     int x;
  1103.     char * p = fp_xbuf;
  1104.     while (n-- > 0) {
  1105.         x = (*s >> 4) & 0x0f;
  1106.         *p++ = hexdigits[x];
  1107.         x = *s++ & 0x0f;
  1108.         *p++ = hexdigits[x];
  1109.     }
  1110.     *p = NUL;
  1111.     return((char *)fp_xbuf);
  1112. }
  1113. #endif /* COMMENT */
  1114.  
  1115. char math_pi[] = "3.1415926535897932384626433832795";
  1116. char math_e[] =  "2.7182818284590452353602874713527";
  1117.  
  1118. VOID
  1119. initfloat() {
  1120.     char * buf = NULL;
  1121.     int i, x, y;
  1122. /*
  1123.   We malloc a big temporary buffer for sprintf() to minimize likelihood of
  1124.   (and damage from) sprintf buffer overflows.  In any case, the only way this
  1125.   could happen would be if sprintf() itself had bugs, since the format
  1126.   descriptor says to cut it off at 250 decimal places.
  1127. */
  1128.     if ((buf = (char *)malloc(4096))) {
  1129.     sprintf(buf,"%0.250f",(10.0 / 3.0));
  1130.     for (i = 2; i < 250 && buf[i] == '3'; i++) ;
  1131.     x = i - 1;
  1132.     debug(F111,"initfloat 10.0/3.0",buf,x);
  1133.     sprintf(buf,"%0.250f",(4.0 / 9.0));
  1134.     for (i = 2; i < 250 && buf[i] == '4'; i++) ;
  1135.     y = i - 1;
  1136.     debug(F111,"initfloat 4.0/9.0",buf,y);
  1137.     fp_digits = (x < y) ? x : y;
  1138.     if (fp_digits < sizeof(math_pi) - 1) {
  1139.         math_pi[fp_digits+1] = NUL;
  1140.         math_e[fp_digits+1] = NUL;
  1141.     }
  1142.     sprintf(buf,"%0.6f",(7.0 / 9.0));
  1143.     if (buf[7] == '8') fp_rounding = 1;
  1144.     debug(F111,"initfloat 7.0/9.0",buf,fp_rounding);
  1145.     debug(F101,"initfloat precision","",fp_digits);
  1146.     free(buf);
  1147.     }
  1148. }
  1149. #endif /* CKFLOAT */
  1150.  
  1151. /*
  1152.   P R E S C A N -- A quick look through the command-line options for
  1153.   items that must be handled before the initialization file is executed.
  1154. */
  1155. #ifdef NT
  1156. extern int StartedFromDialer;
  1157. #endif /* NT */
  1158. #ifdef OS2
  1159. extern int k95stdio;
  1160. unsigned long startflags = 0L;
  1161. #endif /* OS2 */
  1162.  
  1163. static char *
  1164. findinpath(arg) char * arg; {
  1165. #ifdef OS2
  1166.     char * scriptenv, * keymapenv;
  1167.     int len;
  1168. #endif /* OS2 */
  1169. #ifdef DCMDBUF
  1170.     extern char * cmdbuf;
  1171. #else
  1172.     extern char cmdbuf[];
  1173. #endif /* DCMDBUF */
  1174.     char takepath[4096];
  1175.     char * s;
  1176.     int x, z;
  1177.  
  1178.     /* Set up search path... */
  1179. #ifdef OS2
  1180. #ifdef NT
  1181.     scriptenv = getenv("K95SCRIPTS");
  1182.     keymapenv = getenv("K95KEYMAPS");
  1183. #else /* NT */
  1184.     scriptenv = getenv("K2SCRIPTS");
  1185.     keymapenv = getenv("K2KEYMAPS");
  1186. #endif /* NT */
  1187.     if (!scriptenv)
  1188.       scriptenv = getenv("CK_SCRIPTS");
  1189.     if (!scriptenv)
  1190.       scriptenv = "";
  1191.     if (!keymapenv)
  1192.       keymapenv = getenv("CK_KEYMAPS");
  1193.     if (!keymapenv)
  1194.       keymapenv = "";
  1195.  
  1196. #ifndef OS2
  1197.     if (!exedir) makestr(&exedir,"");
  1198. #endif /* OS2 */
  1199.     debug(F110,"startupdir",startupdir,0);
  1200.     debug(F110,"inidir",inidir,0);
  1201.     debug(F110,"exedir",exedir,0);
  1202.     len = strlen(scriptenv) + strlen(keymapenv) + 3*strlen(startupdir)
  1203.         + 3*strlen(inidir) + 3*strlen(zhome()) + 3*strlen(exedir)
  1204.         + 4*strlen("SCRIPTS/") + 4*strlen("KEYMAPS/") + 16;
  1205.  
  1206.     if (len >= 4096) {            /* SAFE (length is checked) */
  1207.         takepath[0] = '\0';
  1208.         debug(F111,"findinpath error - path length too long","len",len);
  1209.     } else
  1210.       sprintf(takepath,
  1211.           /* semicolon-separated path list */
  1212.           "%s%s%s%s%s;%s%s;%s%s;%s;%s%s;%s%s;%s;%s%s;%s%s",
  1213.           scriptenv,
  1214.           (scriptenv[0] && scriptenv[strlen(scriptenv)-1]==';')?"":";",
  1215.           keymapenv,
  1216.           (keymapenv[0] && keymapenv[strlen(keymapenv)-1]==';')?"":";",
  1217.           startupdir,
  1218.           startupdir, "SCRIPTS/",
  1219.           startupdir, "KEYMAPS/",
  1220.           inidir,
  1221.           inidir, "SCRIPTS/",
  1222.           inidir, "KEYMAPS/",
  1223.           zhome(),
  1224.           zhome(), "SCRIPTS/",
  1225.           zhome(), "KEYMAPS/",
  1226.           exedir,
  1227.           exedir, "SCRIPTS/",
  1228.           exedir, "KEYMAPS/"
  1229.           );
  1230. #else /* not OS2 */
  1231. #ifndef NOSPL
  1232.     z = 1024;                           /* Look in home directory */
  1233.     s = takepath;
  1234.     zzstring("\\v(home)",&s,&z);
  1235. #else
  1236.     takepath[0] = '\0';
  1237. #endif /* NOSPL */
  1238. #endif /* OS2 */
  1239. /*
  1240.   All the logic for searching the take path is in the command parser.
  1241.   So even though we aren't parsing commands, we initialize and call the
  1242.   parser from here, with the purported filename stuffed into the command
  1243.   buffer, followed by some carriage returns to make the parser return.
  1244.   If the file is not found, or otherwise not accessible, the parser prints
  1245.   an appropriate message, and then we just exit.
  1246. */
  1247.     cmdini();                           /* Allocate command buffers etc */
  1248.     cmini(0);                           /* Initialize them */
  1249.     /* Stuff filename into command buf with braces in case of spaces */
  1250.     ckmakmsg(cmdbuf,CMDBL,"{",arg,"}",NULL);
  1251.     debug(F110,"prescan cmdbuf",cmdbuf,0);
  1252.     ckstrncat(cmdbuf,"\r\r",CMDBL);    /* And some carriage returns */
  1253.     if (cmifip("","",&s,&x,0,takepath,xxstring) < 0)
  1254.       return(NULL);
  1255.     cmres();
  1256.     return(s);
  1257. }
  1258.  
  1259. static int tr_int;                      /* Flag if TRANSMIT interrupted */
  1260.  
  1261. #ifndef MAC
  1262. SIGTYP
  1263. #ifdef CK_ANSIC
  1264. trtrap(int foo)                         /* TRANSMIT interrupt trap */
  1265. #else
  1266. trtrap(foo) int foo;                    /* TRANSMIT interrupt trap */
  1267. #endif /* CK_ANSIC */
  1268. /* trtrap */ {
  1269. #ifdef __EMX__
  1270.     signal(SIGINT, SIG_ACK);
  1271. #endif
  1272.     tr_int = 1;                         /* (Need arg for ANSI C) */
  1273.     SIGRETURN;
  1274. }
  1275. #endif /* MAC */
  1276. #endif /* NOICP */
  1277.  
  1278. #ifdef UNIX
  1279. VOID
  1280. getexedir() {
  1281.     extern char * xarg0;
  1282.   /*
  1283.     Unix provides no standard service for this.  We look in argv[0], and if
  1284.     we're lucky there's a full pathname.  If not we do a PATH search.
  1285.   */
  1286.     if (ckstrchr(xarg0,'/')) {        /* Global copy of argv[0] */
  1287.     int i, k;
  1288.     char * p = NULL;
  1289.     if ((k = ckstrncpy(tmpbuf,xarg0,TMPBUFSIZ-2)) > 0) {
  1290.         p = tmpbuf;
  1291.         /* Convert to fully qualified pathname */
  1292.         if (tmpbuf[0]) if (tmpbuf[0] != '/') {
  1293.         line[0] = NUL;
  1294.         zfnqfp(tmpbuf,LINBUFSIZ-2,(char *)line);
  1295.         if (line[0])
  1296.           p = line;
  1297.         }
  1298.         if (zchki(p) > -1) {    /* Is the result an existing file? */
  1299.         k = strlen(p);
  1300.         for (i = k-1; i > 0; i--) { /* Yes, strip name part */
  1301.             if (tmpbuf[i] == '/') {
  1302.             if (i < k-1)
  1303.               tmpbuf[i+1] = NUL;
  1304.             break;
  1305.             }
  1306.         }
  1307.         makestr(&exedir,p);    /* Save the result */
  1308.         }
  1309.     }
  1310.     }
  1311.     if (!exedir && xarg0) {        /* Not found? */
  1312.     char * p;
  1313.     p = getenv("PATH");        /* Search the PATH */
  1314.     if (p) {            /* If there is one... */
  1315.         char * q, * PATH = NULL;
  1316.         int k;
  1317.         makestr(&PATH,p);        /* Pokeable copy of PATH string */
  1318.         if (PATH) {            /* If malloc succeeded... */
  1319.         p = PATH;
  1320.         while (p && *p) {     /* Loop through segments */
  1321.             q = ckstrchr(p,':'); /* End of this segment */
  1322.                     if (q == p) {    /* Null PATH segment */
  1323.             p++;        /* Skip over colon */
  1324.             continue;
  1325.             }
  1326.                     if (q)        /* If not at end of PATH string */
  1327.               *q++ = NUL;    /* zero out the colon */
  1328.             if ((k = ckstrncpy(tmpbuf,p,TMPBUFSIZ)) > 0) {
  1329.             if (tmpbuf[k-1] != '/') { /* Copy this PATH segment */
  1330.                 tmpbuf[k++] = '/';    /* Append '/' if needed */
  1331.                 tmpbuf[k] = NUL;
  1332.             }
  1333.             /* Append the argv[0] value */
  1334.             if (ckstrncpy(&tmpbuf[k],xarg0,TMPBUFSIZ) > 0) {
  1335.                 if (zchki(tmpbuf) > -1) { /* File exists? */
  1336.                 tmpbuf[k] = NUL;      /* Yes, we're done */
  1337.                 zfnqfp(tmpbuf,LINBUFSIZ,(char *)line);
  1338.                 makestr(&exedir,line);
  1339.                 break;
  1340.                 }
  1341.             } else break;
  1342.             } else break;
  1343.             p = q;        /* Not found, go to next segment  */
  1344.         } /* while */
  1345.         free(PATH);        /* Free PATH copy */
  1346.         }
  1347.     }
  1348.     if (!exedir) {            /* Still nothing? */
  1349.         if (zchki(xarg0) > -1) {    /* Maybe it's in the current dir */
  1350.         zfnqfp(zgtdir(),LINBUFSIZ,(char *)line);
  1351.         makestr(&exedir,line);
  1352.         }
  1353.     }
  1354.     }
  1355.     if (!exedir) {            /* Still nothing? */
  1356.     makestr(&exedir,"/");        /* Fake it with with root. */
  1357.     }
  1358. }
  1359. #endif /* UNIX */
  1360.  
  1361. int arg_x = 0;
  1362. static int x_prescan = 0;
  1363.  
  1364. /*
  1365.   The argument y once meant something but I can't imagine what so now
  1366.   it's ignored.  (Prior to 22 Aug 98, prescan() was called twice by main(),
  1367.   and the arg differentiated the two calls.  But this caused all sorts of
  1368.   problems & confusion, so I commented out the second call.  This issue might
  1369.   need to be revisited.)
  1370. */
  1371. VOID
  1372. prescan(dummy) int dummy; {             /* Arg is ignored. */
  1373.     extern int howcalled;
  1374.     int yargc; char **yargv;
  1375.     char x;
  1376.     char *yp, *yy;
  1377. #ifdef DEBUG
  1378.     int debcount = 0;
  1379. #endif /* DEBUG */
  1380.     int z;
  1381.  
  1382.     if (x_prescan)                      /* Only run once */
  1383.       return;
  1384.     x_prescan = 1;
  1385.  
  1386.     yargc = xargc;                      /* Make copy of arg vector */
  1387.     yargv = xargv;
  1388.  
  1389. #ifndef NOICP
  1390. #ifdef DCMDBUF
  1391.     if (!kermrc)
  1392.       if (!(kermrc = (char *) malloc(KERMRCL+1)))
  1393.         fatal("prescan: no memory for kermrc");
  1394. #endif /* DCMDBUF */
  1395.     ckstrncpy(kermrc,KERMRC,KERMRCL);   /* Default init file name */
  1396. #endif /* NOICP */
  1397.  
  1398.  
  1399. #ifdef IKSD
  1400.     if (howcalled == I_AM_IKSD)         /* Internet Kermit Service daemon */
  1401.       inserver = 1;                     /* (See inserver section of ckcmai) */
  1402. #endif /* IKSD */
  1403.  
  1404. /* Command line options for Kermit */
  1405.  
  1406. #ifndef NOCMDL
  1407.     if (yargc > 1
  1408.         && *yargv[1] != '-'
  1409.         && (yargv[1][0] != '=')
  1410. #ifdef KERBANG
  1411.         && (yargv[1][0] != '+')
  1412. #endif /* KERBANG */
  1413. #ifdef IKSD
  1414.     && (howcalled != I_AM_IKSD)
  1415. #endif /* IKSD */
  1416.         ) {                /* Filename as 1st argument */
  1417. #ifndef NOICP
  1418.         char *s;
  1419. #endif /* NOICP */
  1420. #ifndef NOURL
  1421.     extern int haveurl;
  1422.         extern struct urldata g_url;
  1423.     if (urlparse(yargv[1],&g_url)) {
  1424.         if (!ckstrcmp(g_url.svc,"ftp",-1,0) ||
  1425.                 !ckstrcmp(g_url.svc,"ftps",-1,0)) {
  1426.         haveurl = 1;
  1427.         howcalled = I_AM_FTP;
  1428.         } else if (!ckstrcmp(g_url.svc,"telnet",-1,0) ||
  1429.                        !ckstrcmp(g_url.svc,"telnets",-1,0)) {
  1430.         haveurl = 1;
  1431.         howcalled = I_AM_TELNET;
  1432.         } else if (!ckstrcmp(g_url.svc,"iksd",-1,0) ||
  1433.                        !ckstrcmp(g_url.svc,"kermit",-1,0)) {
  1434.         haveurl = 1;
  1435.         howcalled = I_AM_KERMIT;
  1436.         } else if (!ckstrcmp(g_url.svc,"http",-1,0) ||
  1437.                !ckstrcmp(g_url.svc,"https",-1,0)) {
  1438.                 haveurl = 1;
  1439.                 howcalled = I_AM_HTTP;
  1440.             }
  1441.             if (haveurl) {
  1442.                 while (--yargc > 0) {    /* Go through command-line args */
  1443.                     yargv++;        /* looking for -Y and -d */
  1444.                     yp = *yargv+1;
  1445.                     if (**yargv == '-') {
  1446.                         x = *(*yargv+1);
  1447.                         while (x) {
  1448.                             switch (x) {
  1449.                   case 'Y':
  1450.                                 noinit++;
  1451.                                 break;
  1452.                   case 'd':    /* = SET DEBUG ON */
  1453. #ifdef DEBUG
  1454.                                 if (debcount++ > 0)
  1455.                   debtim = 1;
  1456.                                 if (!deblog)
  1457.                   deblog = debopn("debug.log",0);    
  1458. #endif /* DEBUG */
  1459.                                 break;
  1460. #ifdef OS2
  1461.                   case 'W':
  1462.                                 if (*(yp+1))
  1463.                   fatal("invalid argument bundling after -W");
  1464.                                 yargv++, yargc--;
  1465.                                 if (yargc < 1)
  1466.                   fatal("Window handle missing");
  1467.                                 hwndDialer = (HWND) atol(*yargv);
  1468.                                 StartedFromDialer = 1;
  1469.                                 yargv++, yargc--;
  1470.                                 KermitDialerID = atol(*yargv) ;
  1471.                                 break;
  1472.                   case '#':    /* K95 initialization options */
  1473.                                 if (*(yp+1)) {
  1474.                                     fatal("invalid argument bundling");
  1475.                                 }
  1476.                                 yargv++, yargc--;
  1477.                                 if (yargc < 1)
  1478.                   fatal("-# argument missing");
  1479.                                 startflags |= atol(*yargv);
  1480.                                 break;
  1481. #endif /* OS2 */
  1482.                             }
  1483.                             if (!yp)
  1484.                   break;
  1485.                             x = *++yp;
  1486.                         }
  1487.                     }
  1488.                 }
  1489.                 return;
  1490.             }
  1491.         }
  1492.     if (howcalled != I_AM_KERMIT)    /* I'm called "telnet" or... */
  1493.       return;
  1494. #endif /* NOURL */
  1495.  
  1496. #ifndef NOICP
  1497.         /* If it is not a URL that we recognize, try to treat it as a file */
  1498.  
  1499.     if (!isabsolute(yargv[1]))    /* If not absolute */
  1500.       s = findinpath(yargv[1]);    /* Look in PATH */
  1501.     else
  1502.       s = yargv[1];
  1503.     if (!s)
  1504.       doexit(BAD_EXIT,xitsta);
  1505.     zfnqfp(s,CKMAXPATH,cmdfil);    /* In case of CD in file */
  1506.         yargc -= 1;                     /* Skip past the filename */
  1507.         yargv += 1;                     /* Otherwise we'll get an error */
  1508. #endif /* NOICP */
  1509.     }
  1510.  
  1511. #ifndef NOCMDL
  1512. #ifdef NEWFTP
  1513.     if (howcalled == I_AM_FTP) {    /* Kermit's FTP client personality */
  1514.     while (--yargc > 0) {        /* Go through command-line args */
  1515.         yargv++;            /* looking for -Y and -d */
  1516.         yp = *yargv+1;
  1517.         if (**yargv == '-') {
  1518.         x = *(*yargv+1);
  1519.         while (x) {
  1520.             switch (x) {
  1521.               case 'Y':
  1522.             noinit++;
  1523.             break;
  1524.                       case 'd':             /* = SET DEBUG ON */
  1525. #ifdef DEBUG
  1526.                         if (debcount++ > 0)
  1527.                           debtim = 1;
  1528.                         if (!deblog)
  1529.                           deblog = debopn("debug.log",0);    
  1530. #endif /* DEBUG */
  1531.                         break;
  1532. #ifdef OS2
  1533.                       case 'W':
  1534.                         if (*(yp+1))
  1535.               fatal("invalid argument bundling after -W");
  1536.                         yargv++, yargc--;
  1537.                         if (yargc < 1)
  1538.               fatal("Window handle missing");
  1539.             hwndDialer = (HWND) atol(*yargv);
  1540.             StartedFromDialer = 1;
  1541.             yargv++, yargc--;
  1542.             KermitDialerID = atol(*yargv) ;
  1543.                         break;
  1544.                       case '#':        /* K95 initialization options */
  1545.                         if (*(yp+1)) {
  1546.                 fatal("invalid argument bundling");
  1547.                         }
  1548.                         yargv++, yargc--;
  1549.                         if (yargc < 1)
  1550.                           fatal("-# argument missing");
  1551.                         startflags |= atol(*yargv);
  1552.                         break;
  1553. #endif /* OS2 */
  1554.             }
  1555.             if (!yp)
  1556.               break;
  1557.             x = *++yp;
  1558.         }
  1559.         }
  1560.     }
  1561.     return;
  1562.     }
  1563. #endif /* NEWFTP */
  1564. #endif /* NOCMDL */
  1565.  
  1566.     while (--yargc > 0) {               /* Go through command-line args */
  1567.         yargv++;
  1568.         yp = *yargv+1;                  /* Pointer for bundled args */
  1569.         if (**yargv == '=')             /* Same rules as cmdlin()... */
  1570.           return;
  1571.         debug(F110,"prescan *yargv",*yargv,0);
  1572.  
  1573. #ifndef NOICP
  1574. #ifdef KERBANG
  1575.     yy = *yargv;
  1576.         if (!strcmp(yy,"+") || (*yy == '+' && *(yy+1) < (char)33)) {
  1577.             char * s;
  1578.             yargv++;
  1579.             noinit = 1;
  1580.             if (!*yargv)
  1581.               return;
  1582.             cfilef = 1;
  1583.             s = findinpath(*yargv);
  1584.             if (s) {
  1585.                 zfnqfp(s,CKMAXPATH,cmdfil);
  1586.                 return;
  1587.             } else
  1588.               doexit(BAD_EXIT,xitsta);
  1589.         }
  1590. #endif /* KERBANG */
  1591. #endif /* NOICP */
  1592.         if (!strcmp(*yargv,"--"))       /* getopt() conformance */
  1593.           return;
  1594. #ifdef VMS
  1595.         else if (**yargv == '/')
  1596.           continue;
  1597. #endif /* VMS */
  1598.         else if (**yargv == '-') {      /* Got an option (begins with dash) */
  1599.             x = *(*yargv+1);            /* Get option letter */
  1600.             while (x) {                 /* Allow for bundled options */
  1601.                 debug(F000,"prescan arg","",x);
  1602.                 switch (x) {
  1603. #ifndef NOICP
  1604.                   case '+':
  1605.                   case '-':
  1606.                     if (doxarg(yargv,1) < 0) {
  1607.                         fatal("Extended argument error");
  1608.                     }
  1609.                     yargv++, yargc--;
  1610.                     yp = *yargv;
  1611.                     break;
  1612. #endif /* NOICP */
  1613.  
  1614.                   case '7':             /* Undocumented... */
  1615.                     sstelnet = 1;       /* (because it doesn't work) */
  1616.                     break;
  1617. #ifdef IKSD
  1618.                   case 'A': {
  1619.                       char * p;
  1620.                       inserver = 1;     /* Flag that we are doing this */
  1621.                       srvcdmsg = 2;     /* Preset this */
  1622.                       /* See inserver section of ckcmai.c for more settings */
  1623. #ifdef OS2
  1624.                       if (*(yp+1)) {
  1625.                           fatal("invalid argument bundling after -A");
  1626.                       }
  1627. #ifdef NT
  1628.                       /* Support for Pragma Systems Telnet/Terminal Servers */
  1629.                       p = getenv("PRAGMASYS_INETD_SOCK");
  1630.                       if (p && atoi(p) != 0) {
  1631.                           ttname[0] = '$';
  1632.                           ckstrncpy(&ttname[1],p,TTNAMLEN-1);
  1633.                           break;
  1634.                       }
  1635. #endif /* NT */
  1636.                       yargv++, yargc--;
  1637.                       if (yargc < 1 || **yargv == '-') {
  1638.                           fatal("-A argument missing");
  1639.                       } else {
  1640.                           ttname[0] = '$';
  1641.                           ckstrncpy(&ttname[1],*yargv,TTNAMLEN-1);
  1642.                       }
  1643. #endif /* OS2 */
  1644.                       break;
  1645.                   }
  1646. #endif /* IKSD */
  1647.  
  1648. #ifdef OS2
  1649.                   case 'W':
  1650.                     if (*(yp+1))
  1651.                       fatal("invalid argument bundling after -W");
  1652.                     yargv++, yargc--;
  1653.                     if (yargc < 1)
  1654.                       fatal("Window handle missing");
  1655. #ifdef COMMENT
  1656.                     if (dummy) {
  1657.                         yargv++, yargc--;
  1658.                         break;
  1659.                     } else {
  1660. #endif /* COMMENT */
  1661.                         hwndDialer = (HWND) atol(*yargv);
  1662.                         StartedFromDialer = 1;
  1663.                         yargv++, yargc--;
  1664.                         KermitDialerID = atol(*yargv) ;
  1665. #ifdef COMMENT
  1666.                     }
  1667. #endif /* COMMENT */
  1668.                     break;
  1669.  
  1670.                   case '#':             /* K95 initialization options */
  1671.                     if (*(yp+1)) {
  1672.                         fatal("invalid argument bundling");
  1673.                     }
  1674.                     yargv++, yargc--;
  1675.                     if (yargc < 1)
  1676.                       fatal("-# argument missing");
  1677.                     startflags |= atol(*yargv);
  1678.                     break;
  1679. #endif /* OS2 */
  1680.  
  1681. #ifndef NOSPL
  1682.                   case 'M':                             /* My User Name */
  1683.                     if (*(yp+1)) {
  1684.                         fatal("invalid argument bundling");
  1685.                     }
  1686.                     yargv++, yargc--;
  1687.                     if ((yargc < 1) || (**yargv == '-')) {
  1688.                         fatal("missing username");
  1689.                     }
  1690.                     if ((int)strlen(*yargv) > UIDBUFLEN) {
  1691.                         fatal("username too long");
  1692.                     }
  1693. #ifdef COMMENT
  1694. /*
  1695.   This can't work.  uidbuf is overwritten in sysinit() which has yet to be
  1696.   called.  This cannot be set in prescan().
  1697. */
  1698. #ifdef IKSD
  1699.                     if (!inserver)
  1700. #endif /* IKSD */
  1701.                       ckstrncpy(uidbuf,*yargv,UIDBUFLEN);
  1702. #endif /* COMMENT */
  1703.                     break;
  1704. #endif /* NOSPL */
  1705.                   case 'R':             /* Remote-only advisory */
  1706. #ifdef CK_IFRO
  1707.                     remonly = 1;
  1708. #endif /* CK_IFRO */
  1709.                     break;
  1710.                   case 'S':             /* STAY */
  1711.                     stayflg = 1;
  1712.                     break;
  1713.                   case 'h':
  1714.                     noinit = 1;
  1715. #ifdef OS2
  1716.                     startflags |= 2;    /* No network DLLs */
  1717.                     startflags |= 4;    /* No TAPI DLLs */
  1718.                     startflags |= 8;    /* No Security DLLs */
  1719.                     startflags |= 16;   /* No Zmodem DLLs */
  1720. #endif /* OS2 */
  1721.                     break;
  1722. #ifndef NOICP
  1723.                   case 'Y':             /* No init file */
  1724.                     noinit = 1;
  1725.                     break;
  1726. #endif /* NOICP */
  1727.                   case 'd':             /* = SET DEBUG ON */
  1728. #ifdef DEBUG
  1729.             if (debcount++ > 0)
  1730.               debtim = 1;
  1731.                     if (!deblog)
  1732.               deblog = debopn("debug.log",0);    
  1733. #endif /* DEBUG */
  1734.                     break;
  1735.  
  1736.                   case 'x':             /* Server */
  1737.                     arg_x = 1;          /* Note in advance */
  1738.                     break;
  1739. #ifndef NOICP
  1740.                   case 'y':             /* Alternative init file */
  1741.             noinit = 0;
  1742.                     yargv++, yargc--;
  1743.                     if (yargc < 1) fatal("missing name in -y");
  1744.             /* Replace init file name */
  1745.                     ckstrncpy(kermrc,*yargv,KERMRCL);
  1746.                     rcflag = 1;         /* Flag that this has been done */
  1747.                     debug(F111,"prescan kermrc",kermrc,rcflag);
  1748.                     break;
  1749. #endif /* NOICP */
  1750.                   case 'z':             /* = SET BACKGROUND OFF */
  1751.                     bgset = 0;
  1752.             backgrd = 0;
  1753. #ifdef VMS
  1754.             batch = 0;
  1755. #endif /* VMS */
  1756.                     break;
  1757.  
  1758.           case 'B':        /* Force background (batch) */
  1759.             bgset = 1;
  1760.             backgrd = 1;
  1761. #ifdef VMS
  1762.             batch = 1;
  1763. #endif /* VMS */
  1764.             break;
  1765.  
  1766. #ifdef CK_NETBIOS
  1767.                   case 'N':
  1768.                     {
  1769.                         int n ;
  1770.                         yargv++, yargc--;
  1771. #ifdef COMMENT
  1772.                         if (y)
  1773.                           break;
  1774. #endif /* COMMENT */
  1775.                         if (strlen(*yargv) != 1 || (*yargv)[0] == 'X') {
  1776.                             NetBiosAdapter = -1;
  1777.                         } else {
  1778.                             n = atoi(*yargv);
  1779.                             if (n >= 0 && n <= 9)
  1780.                               NetBiosAdapter = n;
  1781.                             else
  1782.                               NetBiosAdapter = -1;
  1783.                         }
  1784.                     }
  1785.                     break;
  1786. #endif /* CK_NETBIOS */
  1787.                   default:
  1788.                     break;
  1789.                 }
  1790.                 if (!yp)
  1791.                   break;
  1792.                 x = *++yp;              /* See if options are bundled */
  1793.             }
  1794.         }
  1795.     }
  1796. #endif /* NOCMDL */
  1797. }
  1798.  
  1799. /*  G E T T C S  --  Get Transfer (Intermediate) Character Set  */
  1800.  
  1801. /*
  1802.   Given two file character sets, this routine picks out the appropriate
  1803.   "transfer" character set to use for translating between them.
  1804.   The transfer character set number is returned.
  1805.  
  1806.   Translation between two file character sets is done, for example,
  1807.   by the CONNECT, TRANSMIT, and TRANSLATE commands.
  1808.  
  1809.   Translation between Kanji character sets is not yet supported.
  1810. */
  1811. int
  1812. gettcs(cs1,cs2) int cs1, cs2; {
  1813. #ifdef NOCSETS                          /* No character-set support */
  1814.     return(0);                          /* so no translation */
  1815. #else
  1816.     int tcs = TC_TRANSP;
  1817. #ifdef KANJI
  1818. /* Kanji not supported yet */
  1819.     if (fcsinfo[cs1].alphabet == AL_JAPAN ||
  1820.         fcsinfo[cs2].alphabet == AL_JAPAN )
  1821.       tcs = TC_TRANSP;
  1822.     else
  1823. #endif /* KANJI */
  1824. #ifdef CYRILLIC
  1825. /*
  1826.   I can't remember why we don't test both sets here, but I think there
  1827.   must have been a reason...
  1828. */
  1829.       if (fcsinfo[cs2].alphabet == AL_CYRIL)
  1830.         tcs = TC_CYRILL;
  1831.       else
  1832. #endif /* CYRILLIC */
  1833. #ifdef HEBREW
  1834.           if (fcsinfo[cs1].alphabet == AL_HEBREW ||
  1835.               fcsinfo[cs2].alphabet == AL_HEBREW )
  1836.             tcs = TC_HEBREW;
  1837.           else
  1838. #endif /* HEBREW */
  1839. #ifdef GREEK
  1840.           if (fcsinfo[cs1].alphabet == AL_GREEK ||
  1841.               fcsinfo[cs2].alphabet == AL_GREEK )
  1842.             tcs = TC_GREEK;
  1843.           else
  1844. #endif /* GREEK */
  1845.  
  1846.             /* Roman sets ... */
  1847.  
  1848. #ifdef LATIN2                           /* East European */
  1849.         if (cs1 == FC_2LATIN  || cs2 == FC_2LATIN || /* Latin-2 */
  1850.             cs1 == FC_CP852   || cs2 == FC_CP852  || /* CP852 */
  1851.             cs1 == FC_CP1250  || cs2 == FC_CP1250 || /* Windows Latin-2 */
  1852.             cs1 == FC_MAZOVIA || cs2 == FC_MAZOVIA)  /* Polish Mazovia */
  1853.           tcs = TC_2LATIN;
  1854.         else
  1855. #endif /* LATIN2 */
  1856.                                         /* West European Euro-aware */
  1857.           if (cs1 == FC_CP858 || cs1 == FC_9LATIN ||
  1858.               cs2 == FC_CP858 || cs2 == FC_9LATIN)
  1859.             tcs = TC_9LATIN;
  1860.           else                          /* Traditional West European */
  1861.             tcs = TC_1LATIN;
  1862.     return(tcs);
  1863. #endif /* NOCSETS */
  1864. }
  1865.  
  1866. #ifndef NOLOCAL
  1867. /*  D O C O N E C T  --  Do the connect command  */
  1868. /*
  1869.   q = 0 means issue normal informational message about how to get back, etc.
  1870.   q != 0 means to skip the message.
  1871. */
  1872.  
  1873. int
  1874. doconect(q,async) int q, async; {
  1875.     int x;                /* Return code */
  1876. #ifdef CK_AUTODL
  1877.     extern CHAR ksbuf[];
  1878. #endif /* CK_AUTODL */
  1879. #ifndef NOKVERBS                        /* Keyboard macro material */
  1880.     extern int keymac, keymacx;
  1881. #endif /* NOKVERBS */
  1882.     extern int justone, adl_err;
  1883.     int qsave;                          /* For remembering "quiet" value */
  1884. #ifdef OS2
  1885.     extern int term_io;
  1886.     extern int display_demo;
  1887.     int term_io_save;
  1888. #endif /* OS2 */
  1889.     int is_tn = 0;
  1890.  
  1891. #ifdef IKSD
  1892.     if (inserver) {
  1893.         if (!quiet)
  1894.           printf("?Sorry, IKSD cannot CONNECT.\r\n");
  1895.         return(success = 0);
  1896.     }
  1897. #endif /* IKSD */
  1898.  
  1899.     is_tn =
  1900. #ifdef TNCODE
  1901.       (local && network && ttnproto == NP_TELNET) || (!local && sstelnet)
  1902. #else
  1903.         0
  1904. #endif /* TNCODE */
  1905.           ;
  1906. /*
  1907.   Saving, changing, and restoring the global "quiet" variable around calls
  1908.   to conect() to control whether the verbose CONNECT message is printed is
  1909.   obviously less elegant than passing a parameter to conect(), but we do it
  1910.   this way to avoid the need to change all of the ck?con.c modules.  NOTE:
  1911.   it is important to restore the value immediately upon return in case there
  1912.   is an autodownload or APC.
  1913. */
  1914.     qsave = quiet;                      /* Save it */
  1915.     if (!quiet && q > -1)
  1916.       quiet = q;                        /* Use argument temporarily */
  1917.     conres();                           /* Put console back to normal */
  1918.     debug(F101,"doconect justone 1","",justone);
  1919. #ifdef CK_AUTODL
  1920.     ksbuf[0] = NUL;                     /* Autodownload packet buffer */
  1921. #endif /* CK_AUTODL */
  1922. #ifdef OS2
  1923.     display_demo = 1;                   /* Remember to display demo */
  1924. #endif /* OS2 */
  1925.  
  1926. #ifdef IKS_OPTION
  1927.     if (is_tn && TELOPT_U(TELOPT_KERMIT) && ttchk() >= 0
  1928. #ifdef OS2
  1929.        && !viewonly
  1930. #endif /* OS2 */
  1931.         ) {
  1932.         /* If the remote side is in a state of IKS START-SERVER    */
  1933.         /* we request that the state be changed.  We will detect   */
  1934.         /* a failure to adhere to the request when we call ttinc() */
  1935.         if (!iks_wait(KERMIT_REQ_STOP,0) && !tcp_incoming) {
  1936.             if (!quiet) {
  1937.                 printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  1938.                 printf(
  1939. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  1940.                 printf(" SEND and GET for file transfer.\r\n");
  1941.                 printf(" REMOTE commands for file management.\r\n");
  1942.                 printf(" FINISH to terminate Client/Server mode.\r\n");
  1943.                 printf(" BYE to terminate and close connection.\r\n");
  1944.                 printf(" REMOTE HELP for additional information.\r\n\r\n");
  1945.             }
  1946.             quiet = qsave;
  1947.             return(0);      /* Failure */
  1948.         }
  1949.     }
  1950.  
  1951.     /* Let our peer know our state. */
  1952. #ifdef CK_AUTODL
  1953.     if (is_tn && TELOPT_ME(TELOPT_KERMIT)
  1954. #ifdef OS2
  1955.         && !viewonly
  1956. #endif /* OS2 */
  1957.          ) {
  1958.         if (autodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  1959.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  1960.         } else if (!autodl && TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  1961.             tn_siks(KERMIT_STOP);
  1962.         }
  1963.     }
  1964. #else /* CK_AUTODL */
  1965.     if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  1966.         tn_siks(KERMIT_STOP);
  1967.     }
  1968. #endif /* CK_AUTODL */
  1969. #endif /* IKS_OPTION */
  1970.  
  1971.     debug(F101,"doconect flow","",flow);
  1972. #ifdef OS2
  1973.     debug(F101,"doconect async","",async);
  1974.     x = conect(async);                  /* Connect the first time */
  1975. #else /* OS2 */
  1976.     x = conect();
  1977. #endif /* OS2 */
  1978.     debok = 1;
  1979.  
  1980. #ifdef IKS_OPTION
  1981.     if (TELOPT_U(TELOPT_KERMIT) &&
  1982.         TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  1983.         !tcp_incoming && !quiet && ttchk() >= 0
  1984.         ) {
  1985.         printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  1986.         printf(
  1987. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  1988.         printf(" SEND and GET for file transfer.\r\n");
  1989.         printf(" REMOTE commands for file management.\r\n");
  1990.         printf(" FINISH to terminate Client/Server mode.\r\n");
  1991.         printf(" BYE to terminate and close connection.\r\n");
  1992.         printf(" REMOTE HELP for additional information.\r\n\r\n");
  1993.     }
  1994. #endif /* IKS_OPTION */
  1995.  
  1996.     quiet = qsave;                      /* Restore "quiet" value */
  1997.     debug(F101,"doconect justone 2","",justone);
  1998.  
  1999. #ifdef NETCONN
  2000.     if (network && tn_exit && ttchk() < 0)
  2001.       doexit(GOOD_EXIT,xitsta);         /* Exit with good status */
  2002. #endif /* NETCONN */
  2003.  
  2004. #ifdef OS2ORUNIX
  2005.     /* Exit on disconnect if the port is not open or carrier detect */
  2006.     if (exitonclose && (ttchk() < 0))
  2007.       doexit(GOOD_EXIT,xitsta);
  2008. #endif /* OS2ORUNIX */
  2009.  
  2010. #ifdef CKCONINTB4CB
  2011.     /* The order makes a difference in HP-UX 8.00. */
  2012.     /* The other order makes it think it's in the background when it */
  2013.     /* returns from CONNECT (Apr 1999). */
  2014.     setint();
  2015.     concb((char)escape);                /* Restore console for commands */
  2016. #else
  2017.     /* This is how it has always been so better leave it */
  2018.     /* this way for all non-HP-UX-8.00 builds. */
  2019.     concb((char)escape);                /* Restore console for commands */
  2020.     setint();
  2021. #endif /* CKCONINTB4CB */
  2022.  
  2023. #ifdef OS2
  2024.     if (!async) {
  2025.     term_io_save = term_io;        /* Disable I/O by emulator */
  2026.     term_io = 0;
  2027. #endif /* OS2 */
  2028.  
  2029. #ifdef CK_APC
  2030. /*
  2031.   If an APC command was received during CONNECT mode, we define it now
  2032.   as a macro, execute the macro, and then return to CONNECT mode.
  2033.   We do this in a WHILE loop in case additional APCs come during subsequent
  2034.   CONNECT sessions.
  2035. */
  2036.     debug(F101,"doconect apcactive","",apcactive);
  2037.     debug(F101,"doconect success","",success);
  2038.  
  2039.     while (x > 0 && (apcactive == APC_LOCAL ||
  2040.              (apcactive == APC_REMOTE && apcstatus != APC_OFF))) {
  2041.         debug(F101,"doconect justone 3","",justone);
  2042.         if (mlook(mactab,"_apc_commands",nmac) == -1) {
  2043.         debug(F110,"doconect about to execute APC",apcbuf,0);
  2044.         domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  2045.         delmac("_apc_commands",1);
  2046. #ifdef DEBUG
  2047.         } else {
  2048.         debug(F100,"doconect APC in progress","",0);
  2049. #endif /* DEBUG */
  2050.         }
  2051.         debug(F101,"doconect apcactive after domac","",apcactive);
  2052.         if (!apcactive) {               /* In case CLEAR APC was in APC */
  2053.         debug(F101,"doconect quit APC loop: apcactive","",apcactive);
  2054.         break;
  2055.         }
  2056.         /* Also don't reconnect if autodownload failed - very confusing! */
  2057.         /* Let them view the local screen to see what happened. - fdc */
  2058.  
  2059.             /* This should be conditional.  If someone is relying on the */
  2060.             /* connect mode autodownload for the kermit server to use with */
  2061.             /* a remotely executed script we should be able to return to */
  2062.             /* connect mode on the failure.  What we really need to do is */
  2063.             /* report the status of the transfer and then return to CONNECT. */
  2064.             /* In unix this would simply be a printf(), but in K95 it could */
  2065.             /* use a popup dialog to report the status. - Jeff */
  2066.  
  2067. #ifndef NOXFER
  2068.         debug(F101,"doconect xferstat","",xferstat);
  2069.         if (apcactive == APC_LOCAL && !xferstat && adl_err != 0) {
  2070.         debug(F101,"doconect quit APC loop: xferstat","",xferstat);
  2071.         apcactive = APC_INACTIVE;
  2072.         break;
  2073.         }
  2074. #endif /* NOXFER */
  2075. #ifdef OS2
  2076.         msleep(250);
  2077. #endif /* OS2 */
  2078.         debug(F101,"doconect justone 4","",justone);
  2079.         qsave = quiet;        /* Do this again... */
  2080.         if (!quiet && q > -1)
  2081.           quiet = q;
  2082. #ifdef CK_AUTODL
  2083.         ksbuf[0] = NUL;
  2084. #endif /* CK_AUTODL */
  2085. #ifdef IKS_OPTION
  2086. #ifdef CK_AUTODL
  2087.         if (is_tn &&
  2088.         TELOPT_ME(TELOPT_KERMIT) &&
  2089.         !TELOPT_SB(TELOPT_KERMIT).kermit.me_start &&
  2090.         autodl
  2091. #ifdef CK_APC
  2092.         && !apcactive
  2093. #endif /* CK_APC */
  2094. #ifdef OS2
  2095.         && !viewonly
  2096. #endif /* OS2 */
  2097.         ) {
  2098.         tn_siks(KERMIT_START);    /* Send Kermit-Server Start */
  2099.         }
  2100. #endif /* CK_AUTODL */
  2101. #endif /* IKS_OPTION */
  2102. #ifndef OS2
  2103.         x = conect();        /* Re-CONNECT. */
  2104. #else /* OS2 */
  2105.         x = conect(0);
  2106.         term_io = term_io_save;
  2107. #endif /* OS2 */
  2108.         debok = 1;
  2109.         quiet = qsave;
  2110.         debug(F101,"doconect justone 5","",justone);
  2111. #ifdef NETCONN
  2112.         if (network && ttchk() < 0) {
  2113.         if (tn_exit || exitonclose)
  2114.           doexit(GOOD_EXIT,xitsta);
  2115.         else
  2116.           break;
  2117.         }
  2118. #endif /* NETCONN */
  2119.  
  2120. #ifdef OS2ORUNIX
  2121.         /* If connection dropped */
  2122.         if (ttchk() < 0) {
  2123.         concb((char)escape);    /* Restore console. */
  2124.         if (exitonclose)
  2125.           doexit(GOOD_EXIT,xitsta);
  2126.         else
  2127.           break;
  2128.         }
  2129. #endif /* OS2ORUNIX */
  2130.     } /* Loop back for more. */
  2131. #endif /* CK_APC */
  2132.  
  2133. #ifndef NOKVERBS
  2134.     if ((keymac > 0) && (keymacx > -1)) { /* Executing a keyboard macro? */
  2135.         /* Set up the macro and return */
  2136.         /* Do not clear the keymac flag */
  2137.         return(dodo(keymacx,NULL,CF_KMAC|cmdstk[cmdlvl].ccflgs));
  2138.     }
  2139. #endif /* NOKVERBS */
  2140. #ifdef OS2
  2141.     term_io = term_io_save;
  2142.     } /* if (!async) */
  2143. #endif /* OS2 */
  2144.  
  2145. #ifdef CKCONINTB4CB
  2146.     /* The order makes a difference in HP-UX 8.00. */
  2147.     /* The other order makes it think it's in the background when it */
  2148.     /* returns from CONNECT (Apr 1999). */
  2149.     setint();
  2150.     concb((char)escape);                /* Restore console for commands */
  2151. #else
  2152.     /* This is how it has always been so better leave it */
  2153.     /* this way for all non-HP-UX-8.00 builds. */
  2154.     concb((char)escape);                /* Restore console for commands */
  2155.     setint();
  2156. #endif /* CKCONINTB4CB */
  2157. #ifdef OS2
  2158.     if (!async)
  2159. #endif /* OS2 */
  2160.       what = W_COMMAND;            /* Back in command mode. */
  2161.     return(x);                          /* Done. */
  2162. }
  2163. #endif /* NOLOCAL */
  2164.  
  2165. #ifndef NOICP
  2166. #ifdef COMMENT
  2167. /*
  2168.   It seemed that this was needed for OS/2, in which \v(cmdfile) and other
  2169.   file-oriented variables or functions can return filenames containing
  2170.   backslashes, which are subsequently interpreted as quotes rather than
  2171.   directory separators (e.g. see commented section for VN_CMDF below).
  2172.   But the problem can't be cured at this level.  Example:
  2173.  
  2174.     type \v(cmdfile)
  2175.  
  2176.   Without doubling, the filename is parsed correctly, but then when passed
  2177.   to UNIX 'cat' through the shell, the backslash is removed, and then cat
  2178.   can't open the file.  With doubling, the filename is not parsed correctly
  2179.   and the TYPE command fails immediately with a "file not found" error.
  2180. */
  2181. /*
  2182.   Utility routine to double all backslashes in a string.
  2183.   s1 is pointer to source string, s2 is pointer to destination string,
  2184.   n is length of destination string, both NUL-terminated.
  2185.   Returns 0 if OK, -1 if not OK (destination string too short).
  2186. */
  2187. int
  2188. dblbs(s1,s2,n) char *s1, *s2; int n; {
  2189.     int i = 0;
  2190.     while (*s1) {
  2191.         if (*s1 == '\\') {
  2192.             if (++i > n) return(-1);
  2193.             *s2++ = '\\';
  2194.         }
  2195.         if (++i > n) return(-1);
  2196.         *s2++ = *s1++;
  2197.     }
  2198.     *s2 = NUL;
  2199.     return(0);
  2200. }
  2201. #endif /* COMMENT */
  2202.  
  2203. char *
  2204. gmdmtyp() {                             /* Get modem type */
  2205. #ifndef NODIAL
  2206.     int i, x;
  2207.  
  2208.     debug(F111,"gmdmtyp","mdmtyp",mdmtyp);
  2209.     debug(F111,"gmdmtyp","mdmsav",mdmsav);
  2210.  
  2211.     x = mdmtyp;
  2212.     if (x < 0)                          /* In case of network dialing */
  2213.       x = mdmsav;
  2214.     if (x < 1)
  2215.       return("none");
  2216.     else
  2217.       for (i = 0; i < nmdm; i++)
  2218.         if ((mdmtab[i].kwval == x) && (mdmtab[i].flgs == 0))
  2219.           return(mdmtab[i].kwd);
  2220. #endif /* NODIAL */
  2221.     return("none");
  2222. }
  2223.  
  2224. #ifndef NOXMIT
  2225. #ifndef NOLOCAL
  2226. /*  T R A N S M I T  --  Raw upload  */
  2227.  
  2228. /*  Obey current line, duplex, parity, flow, text/binary settings. */
  2229. /*  Returns 0 upon apparent success, 1 on obvious failure.  */
  2230.  
  2231. /***
  2232.  Things to add:
  2233.  . Make both text and binary mode obey set file bytesize.
  2234.  . Maybe allow user to specify terminators other than CR?
  2235.  . Maybe allow user to specify prompts other than single characters?
  2236.  . Make STATISTICS also work for TRANSMIT.
  2237.  . If TRANSMIT is done without echo, make some kind of (optional) display.
  2238.  . Make the same optimization for binary-mode transmit that was done for
  2239.    text-mode (in the no-echo / no-prompt / no-pause case).
  2240. ***/
  2241.  
  2242. /*  T R A N S M I T  --  Raw upload  */
  2243.  
  2244. /*  s is the filename, t is the turnaround (prompt) character  */
  2245.  
  2246. /*
  2247.   Maximum number of characters to buffer.
  2248.   Must be less than LINBUFSIZ
  2249. */
  2250. #ifdef OS2
  2251. #define XMBUFS 4096                     /* For compatibility with XYZmodem */
  2252. #else /* OS2 */
  2253. #define XMBUFS 1024
  2254. #endif /* OS2 */
  2255.  
  2256. #ifdef TNCODE
  2257. #ifndef IAC
  2258. #define IAC 255
  2259. #endif /* IAC */
  2260. #endif /* TNCODE */
  2261.  
  2262. #define OUTXBUFSIZ 15
  2263. static CHAR inxbuf[OUTXBUFSIZ+1];       /* Host-to-screen expansion buffer */
  2264. static int inxcount = 0;                /* and count */
  2265. static CHAR outxbuf[OUTXBUFSIZ+1];      /* Keyboard-to-host expansion buf */
  2266. static int outxcount = 0;               /* and count */
  2267.  
  2268. /*  T R A N S M I T  --  Unguarded non-protocol file transmission  */
  2269. /*
  2270.   Call with:
  2271.     char * s:   Name of file to transmit.
  2272.     char t:     Turnaround char for text-mode transmission (normally LF).
  2273.     int xlate:  nonzero = charset translation for text-mode xfer, 0 = skip.
  2274.     int binary: nonzero = transmit in binary mode, 0 = in text mode.
  2275. */
  2276. #define XBBUFSIZ 252            /* For binary blasting */
  2277. static CHAR xbbuf[XBBUFSIZ+4];
  2278.  
  2279. int
  2280. #ifdef CK_ANSIC
  2281. transmit(char * s, char t, int xlate, int binary, int xxecho)
  2282. #else
  2283. transmit(s,t,xlate,binary,xxecho) char *s; char t; int xlate, binary, xxecho;
  2284. #endif /* CK_ANSIC */
  2285. /* transmit */ {
  2286. #ifdef MAC
  2287.     extern char sstate;
  2288.     int count = 100;
  2289. #else
  2290.     int count = 0;
  2291. #ifdef OS2
  2292. #ifdef NT
  2293.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  2294. #else /* NT */
  2295.     SIGTYP (* volatile oldsig)(int);
  2296. #endif /* NT */
  2297.  
  2298. #else /* OS2 */
  2299.     SIGTYP (* oldsig)();
  2300. #endif /* OS2 */
  2301. #endif /* MAC */
  2302.     int eof = 0;                        /* End of File flag */
  2303.     int eol = 0;                        /* End of Line flag */
  2304.     int rc = 1;                         /* Return code. 0=fail, 1=succeed. */
  2305.     int myflow;                         /* Local copy of global flow... */
  2306.     int is_tn = 0;                      /* Do Telnet negotiations */
  2307.     int xbufsiz = XMBUFS;               /* Size of TRANSMIT buffer */
  2308.     int x, y, c, i;            /* Int workers... */
  2309.     int control = 0;                    /* Echo loop control */
  2310.     long nbytes = 0;                    /* File byte count */
  2311.     long zz;                            /* Long worker */
  2312.     char *p;                            /* Char * worker */
  2313.  
  2314. #ifdef PIPESEND
  2315.     extern int pipesend;
  2316. #endif /* PIPESEND */
  2317.  
  2318. #ifndef NOCSETS
  2319.     int tcs = TC_TRANSP;                /* Intermediate (xfer) char set */
  2320.     int langsv = L_USASCII;             /* Save current language */
  2321.     int unicode = 0;
  2322.     int tcssize = 0;
  2323.  
  2324. #ifdef CK_ANSIC /* ANSI C prototypes... */
  2325.     CHAR (*sxo)(CHAR);
  2326.     CHAR (*rxo)(CHAR);
  2327.     CHAR (*sxi)(CHAR);
  2328.     CHAR (*rxi)(CHAR);
  2329. #else /* Not ANSI C... */
  2330.     CHAR (*sxo)();
  2331.     CHAR (*rxo)();
  2332.     CHAR (*sxi)();
  2333.     CHAR (*rxi)();
  2334. #endif /* CK_ANSIC */
  2335. #ifdef UNICODE
  2336.     union ck_short uc;
  2337.     int bomorder = 0;
  2338. #ifdef CK_ANSIC
  2339.     extern int (*xl_ufc[MAXFCSETS+1])(USHORT);  /* Unicode to FCS */
  2340.     extern USHORT (*xl_fcu[MAXFCSETS+1])(CHAR); /* FCS to Unicode */
  2341.     extern int (*xuf)(USHORT);
  2342.     extern USHORT (*xfu)(CHAR);
  2343. #else
  2344.     extern int (*xl_ufc[MAXFCSETS+1])();
  2345.     extern USHORT (*xl_fcu[MAXFCSETS+1])();
  2346.     extern int (*xuf)();
  2347.     extern USHORT (*xfu)();
  2348. #endif /* CK_ANSIC */
  2349. #endif /* UNICODE */
  2350. #endif /* NOCSETS */
  2351.  
  2352.     debug(F101,"xmit t","",t);
  2353.     debug(F101,"xmit xlate","",xlate);
  2354.     debug(F101,"xmit binary","",binary);
  2355.  
  2356. #ifdef PIPESEND
  2357.     if (pipesend) {
  2358.         if (nopush) return(-2);
  2359.         if (zxcmd(ZIFILE,s) < 1) {
  2360.             printf("?Can't start command: %s\n",s);
  2361.             return(0);
  2362.         }
  2363.     } else
  2364. #endif /* PIPESEND */
  2365.     if (zopeni(ZIFILE,s) == 0) {        /* Open the file to be transmitted */
  2366.         printf("?Can't open file %s\n",s);
  2367.         return(0);
  2368.     }
  2369.     x = -1;                             /* Open the communication channel */
  2370.     if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) {  /* (no harm if already open) */
  2371.         printf("Can't open device %s\n",ttname);
  2372.         return(0);
  2373.     }
  2374.     zz = x ? speed : -1L;
  2375.     if (binary) {                       /* Binary file transmission */
  2376.         myflow = (flow == FLO_XONX) ? FLO_NONE : flow;
  2377.  
  2378.         if (ttvt(zz,myflow) < 0) {      /* So no Xon/Xoff! */
  2379.             printf("Can't condition line\n");
  2380.             return(0);
  2381.         }
  2382.     } else {
  2383.         if (ttpkt(zz,flow,parity) < 0) { /* Put the line in "packet mode" */
  2384.             printf("Can't condition line\n"); /* so Xon/Xoff will work, etc. */
  2385.             return(0);
  2386.         }
  2387.     }
  2388.     is_tn =
  2389. #ifdef TNCODE
  2390.       (local && network && (ttnproto == NP_TELNET)) || (!local && sstelnet)
  2391. #else
  2392.         0
  2393. #endif /* TNCODE */
  2394.           ;
  2395.  
  2396. #ifndef NOCSETS
  2397. /* Set up character set translations */
  2398.  
  2399.     tcs = 0;                            /* "Transfer" or "Other" charset */
  2400.     sxo = rxo = NULL;                   /* Initialize byte-to-byte functions */
  2401.     sxi = rxi = NULL;
  2402.     unicode = 0;                        /* Assume Unicode won't be involved */
  2403.     if (!binary && xlate) {             /* Set up charset translations */
  2404. /*
  2405.   In the SENDING direction, we are converting from the local file's
  2406.   character-set (fcharset) to the remote terminal charset (tcsr).  In the
  2407.   RECEIVING direction (echoing) we are converting from the remote end of the
  2408.   terminal charset (tcsr) to its local end (tcsl), which is not necessarily
  2409.   the same as the file character-set.  Especially when the file character
  2410.   set is UCS-2, which is not a valid terminal character set.  The various
  2411.   combinations are represented in this table:
  2412.  
  2413.   FCS = File Character Set
  2414.   RCS = Remote Terminal Character Set
  2415.   CCS = Console (Local Terminal) Character Set
  2416.  
  2417.    8   4   2   1
  2418.   FCS FCS RCS CCS
  2419.   UCS UTF UTF UTF
  2420.    0   0   0   0   =   0   =   No translation
  2421.    0   0   0   1   =   1   =   FCS -> RCS, Echo RCS -> UTF
  2422.    0   0   1   0   =   2   =   FCS -> UTF, Echo UTF -> CCS
  2423.    0   0   1   1   =   3   =   FCS -> UTF, Echo no translation
  2424.  
  2425.    0   1   0   0   =   4   =   UTF -> RCS, Echo RCS -> CCS
  2426.    0   1   0   1   =   5   =   UTF -> RCS, Echo RCS -> UTF
  2427.    0   1   1   0   =   6   =   UTF -> UTF, Echo UTF -> CCS
  2428.    0   1   1   1   =   7   =   No translation
  2429.  
  2430.    1   0   0   0   =   8   =   UCS -> RCS, Echo RCS -> CCS
  2431.    1   0   0   1   =   9   =   UCS -> RCS, Echo RCS -> UTF
  2432.    1   0   1   0   =  10   =   UCS -> UTF, Echo UTF -> CCS
  2433.    1   0   1   1   =  11   =   UCS -> UTF, Echo no translation
  2434. */
  2435. #ifdef UNICODE
  2436.         xfu = NULL;                     /* Unicode translation functions */
  2437.         xuf = NULL;
  2438.         bomorder = ucsorder;            /* UCS-2 byte order */
  2439.  
  2440.         if (fcharset == FC_UCS2)        /* File charset is UCS-2 */
  2441.           unicode |= 8;
  2442.         else if (fcharset == FC_UTF8)   /* File charset is UTF-8 */
  2443.           unicode |= 4;
  2444.         if (tcsr == FC_UTF8)            /* Remote term charset is UTF-8 */
  2445.           unicode |= 2;
  2446.         if (tcsl == FC_UTF8)            /* Local term charset is UTF-8 */
  2447.           unicode |= 1;
  2448. #endif /* UNICODE */
  2449. /*
  2450.   When Unicode not involved -- TCS is the intermediate (xfer) set, and:
  2451.   sxo = File-to-Intermediate charset function
  2452.   rxo = Intermediate-to-Remote-Terminal charset function
  2453.   sxi = Remote-Terminal-to-Intermediate
  2454.   rxi = Intermediate-to-Local-Terminal
  2455. */
  2456.         tcs = gettcs(tcsr,fcharset);    /* Get intermediate set. */
  2457.         sxo = xls[tcs][fcharset];       /* translation function */
  2458.         rxo = xlr[tcs][tcsr];           /* pointers for output functions */
  2459.         sxi = xls[tcs][tcsr];           /* and for input functions. */
  2460.         rxi = xlr[tcs][tcsl];
  2461. /*
  2462.   At this point we have unicode nonzero if Unicode is involved in the
  2463.   conversion, and to 0 if it is not.
  2464.   The following is to prevent use of zmstuff() and zdstuff() by translation
  2465.   functions (stuffing works with file i/o, not with communication i/o).
  2466. */
  2467.         langsv = language;              /* Save current SET LANGUAGE */
  2468.         language = L_USASCII;           /* No language-specific translations */
  2469.     }
  2470. #endif /* NOCSETS */
  2471.  
  2472.     i = 0;                              /* Beginning of buffer. */
  2473. #ifndef MAC
  2474. #ifndef AMIGA
  2475.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  2476. #endif /* AMIGA */
  2477. #endif /* MAC */
  2478.     tr_int = 0;                         /* Have not been interrupted (yet). */
  2479.     rc = 1;                             /* Return code presumed good. */
  2480. #ifdef VMS
  2481.     conres();
  2482. #endif /* VMS */
  2483.  
  2484. #ifndef NOCSETS
  2485.     debug(F101,"XMIT unicode","",unicode);
  2486. #ifdef UNICODE
  2487.     debug(F101,"XMIT bomorder","",bomorder);
  2488. #endif /* UNICODE */
  2489. #endif /* NOCSETS */
  2490.  
  2491.     c = 0;                              /* Initial condition */
  2492.     while (c > -1 && !eof) {            /* Loop for all characters in file */
  2493.         eol = 0;
  2494. #ifdef MAC
  2495.         /*
  2496.          * It is expensive to run the miniparser so don't do it for
  2497.          * every character.
  2498.          */
  2499.         if (--count < 0) {
  2500.             count = 100;
  2501.             miniparser(1);
  2502.             if (sstate == 'a') {
  2503.                 sstate = '\0';
  2504.                 goto xmitfail;
  2505.             }
  2506.         }
  2507. #else /* Not MAC */
  2508.         if (tr_int) {                   /* Interrupted? */
  2509.             printf("^C...\n");          /* Print message */
  2510.             goto xmitfail;
  2511.         }
  2512. #endif /* MAC */
  2513.         c = zminchar();                 /* Get a file character */
  2514. #ifdef COMMENT
  2515. /* too much */
  2516. #ifdef DEBUG
  2517.     if (deblog) {
  2518.         if (c < 0)
  2519.           debug(F101,"XMIT zminchar","",c);
  2520.         else
  2521.           debug(F000,"XMIT zminchar","",c);
  2522.     }
  2523. #endif /* DEBUG */
  2524. #endif /* COMMENT */
  2525.         if (c < -1) {                   /* Other error */
  2526.             printf("?TRANSMIT file read error: %s\n",ck_errstr());
  2527.             goto xmitfail;
  2528.         } else if (c > -1) {
  2529.             nbytes++;
  2530.             c &= fmask;                 /* Apply SET FILE BYTESIZE mask */
  2531.         } else if (c == -1) {
  2532.             eof = 1;
  2533.             debug(F101,"XMIT eof","",eof);
  2534.         }
  2535.         if (binary) {                   /* Binary... */
  2536.             if (c == -1) {        /* If EOF */
  2537.         rc = 1;            /* Success */
  2538.         eof = 1;
  2539.         goto xmitexit;        /* Done */
  2540.         }
  2541.         if (!xmitw && !xxecho) {    /* Special "blast" mode */
  2542.         if (count == XBBUFSIZ) { /* File input buffer full... */
  2543.             while (count > 0) {
  2544.             errno = 0;
  2545.             y = ttol(xbbuf,count);
  2546.             if (y < 0) {    /* try to send it. */
  2547.                 printf("?TRANSMIT output error: %s\n",
  2548.                    ck_errstr());
  2549.                 debug(F111,"XMIT binary ttol error",
  2550.                   ck_errstr(),errno);
  2551.                 rc = 0;
  2552.                 break;
  2553.             }
  2554.             if (y < 0) break;
  2555.             count -= y;
  2556.             }
  2557.             count = 0;
  2558.         }
  2559.         xbbuf[count++] = c;
  2560. #ifdef TNCODE
  2561.         if (c == IAC && is_tn)    /* Telnet IAC */
  2562.           xbbuf[count++] = IAC;    /* must be doubled */
  2563. #endif /* TNCODE */
  2564.         continue;
  2565.         }
  2566.             if (ttoc(dopar((char) c)) < 0) { /* else just send the char */
  2567.                 printf("?Can't transmit character\n");
  2568.                 goto xmitfail;
  2569.             }
  2570. #ifdef TNCODE
  2571.             if (c == IAC && is_tn)      /* Quote Telnet IAC */
  2572.               ttoc((char)IAC);
  2573. #endif /* TNCODE */
  2574.  
  2575.             if (xmitw)                  /* Pause if requested */
  2576.               msleep(xmitw);
  2577.  
  2578.             if (xxecho) {        /* SET TRANSMIT ECHO ON? */
  2579.                 if (duplex) {           /* Yes, for half duplex */
  2580. #ifndef NOLOCAL
  2581. #ifdef OS2
  2582.                     /* Echo to emulator */
  2583.                     scriptwrtbuf((USHORT)(c & cmdmsk));
  2584. #endif /* OS2 */
  2585. #endif /* NOLOCAL */
  2586.                     if (conoc((char)(c & cmdmsk)) < 0) /* echo locally. */
  2587.                       goto xmitfail;
  2588.                 } else {                /* For full duplex, */
  2589.                     int i, n;           /* display whatever is there. */
  2590.                     n = ttchk();        /* See how many chars are waiting */
  2591.                     if (n < 0) {        /* Connection dropped? */
  2592.                         printf("?Connection lost\n");
  2593.                         goto xmitfail;
  2594.                     }
  2595.                     for (i = 0; i < n; i++) { /* Read and echo that many. */
  2596.                         x = ttinc(xmitt); /* Timed read just in case. */
  2597.                         if (x > -1) {   /* If no timeout */
  2598.                             if (parity) x &= 0x7f; /* display the char, */
  2599. #ifndef NOLOCAL
  2600. #ifdef OS2
  2601.                             /* Echo to emulator */
  2602.                             scriptwrtbuf((USHORT)x);
  2603. #endif /* OS2 */
  2604. #endif /* NOLOCAL */
  2605.                             if (conoc((char)(x & cmdmsk)) < 0) {
  2606.                                 printf("?Output error\n");
  2607.                                 goto xmitfail;
  2608.                             }
  2609.                         } else if (x == -2) {
  2610.                             printf("Connection closed.\n");
  2611.                             ttclos(1);
  2612.                             goto xmitfail;
  2613.                         } else if (x == -3) {
  2614.                             printf(
  2615.                             "Session Limit exceeded - closing connection.\n"
  2616.                                    );
  2617.                             ttclos(1);
  2618.                             goto xmitfail;
  2619.                         } else {
  2620.                             printf("?Communications error\n");
  2621.                             goto xmitfail;
  2622.                         }
  2623.                     }
  2624.                 }
  2625.             } else ttflui();            /* Not echoing, just flush input. */
  2626.  
  2627.         } else {                        /* Text mode, line at a time. */
  2628. #ifdef UNICODE
  2629.             if (fcharset == FC_UCS2 && xlate) { /* Special for UCS-2 */
  2630.                 char xbuf[8];
  2631.                 x = 1 - (nbytes & 1);   /* Odd or even byte */
  2632.                 if (x == 0)             /* Note: 1 = the 1st, 0 = 2nd, etc */
  2633.                   uc.x_short = 0;
  2634.                 if (bomorder)           /* Little Endian */
  2635.                   x = 1 - x;            /* Save byte in appropriate half */
  2636.                 debug(F101,"XMIT UCS2 x","",x);
  2637.                 uc.x_char[x] = (CHAR) (c & 0xff);
  2638.                 if (nbytes & 1)         /* First byte, go back for next */
  2639.                   continue;
  2640.                 if (nbytes == 2) {      /* UCS-2 Byte Order Mark */
  2641.                     if (uc.x_short == (USHORT) 0xfeff) {
  2642.                         debug(F100,"XMIT UCS2 BOM FEFF","",bomorder);
  2643.                         continue;
  2644.                     } else if (uc.x_short == (USHORT) 0xfffe) {
  2645.                         bomorder = 1 - bomorder;
  2646.                         debug(F100,"XMIT UCS2 BOM FFFE (swap)","",bomorder);
  2647.                         continue;
  2648.                     }
  2649.                 }
  2650.                 sprintf(xbuf,"%04X",uc.x_short); /* SAFE */
  2651.                 debug(F111,"XMIT UCS2",xbuf,uc.x_short);
  2652.                 if (nbytes & 1)         /* Special eol test for UCS-2 */
  2653.                   if (uc.x_short == '\n')
  2654.                     eol = 1;
  2655. #ifdef COMMENT
  2656.                 if (uc.x_short == 0x2028 || uc.x_short == 0x2029)
  2657.                     eol = 1;
  2658. #endif /* COMMENT */
  2659.             } else
  2660. #endif /* UNICODE */
  2661.               if (c == '\n') {          /* Normal eol test otherwise */
  2662.                   eol = 1;
  2663.             }
  2664.             if (eol) {                  /* End of line? */
  2665.                 int stuff = -1;
  2666.                 debug(F101,"XMIT eol length","",i);
  2667.                 if (i == 0) {           /* Blank line? */
  2668.                     if (xmitf)          /* Yes, insert fill if asked. */
  2669.                       line[i++] = dopar((char) xmitf);
  2670.                 }
  2671.                 if (i == 0 || ((char) line[i-1]) != ((char) dopar(CR)))
  2672.                   line[i++] = dopar(CR); /* Terminate it with CR */
  2673.                 if (xmitl) {
  2674.                     stuff = LF;
  2675. #ifdef TNCODE
  2676.                 } else if (is_tn && (tn_nlm != TNL_CR)) {
  2677.                     /* TELNET NEWLINE ON/OFF/RAW */
  2678.                     stuff = (tn_nlm == TNL_CRLF) ? LF : NUL;
  2679. #endif /* TNCODE */
  2680.                 }
  2681.                 if (stuff > -1)
  2682.                   line[i++] = dopar((char)stuff);
  2683.                 line[i] = NUL;
  2684.                 debug(F111,"XMIT eol line",line,i);
  2685.  
  2686.             } else if (c != -1) {       /* Not a newline, regular character */
  2687.                 int k, x;
  2688.                 outxbuf[0] = c;         /* In case of no translation */
  2689.                 outxcount = 1;          /* Assume result is one byte */
  2690. #ifndef NOCSETS
  2691.                 switch (unicode) {
  2692.                   case 0:               /* No Unicode involved */
  2693.                   case 1:
  2694.                     if (xlate) {        /* If not /TRANSPARENT */
  2695.                         /* Local-to-intermediate */
  2696.                         if (sxo) c = (*sxo)((char)c);
  2697.                         /* Intermediate-to-remote */
  2698.                         if (rxo) c = (*rxo)((char)c);
  2699.                         outxbuf[0] = c;
  2700.                     }
  2701.                     break;
  2702. #ifdef UNICODE
  2703.                   case 2:               /* Local byte to UTF-8 */
  2704.                   case 3:
  2705.                     xfu = xl_fcu[fcharset];
  2706.                     tcssize = fcsinfo[fcharset].size;
  2707.                     outxcount =
  2708.                       b_to_u((CHAR)c,outxbuf,OUTXBUFSIZ,tcssize);
  2709.                     break;
  2710.                   case 4:               /* Local UTF-8 to remote byte */
  2711.                   case 5:
  2712.                     xuf = xl_ufc[tcsr];
  2713.                     x = u_to_b((CHAR)c); /* Convert to byte */
  2714.                     if (x == -1) {      /* If more input bytes needed */
  2715.                         continue;       /* go back and get them */
  2716.                     } else if (x == -2) { /* LS or PS (shouldn't happen) */
  2717.                         outxbuf[0] = CR;
  2718.                     } else if (x == -9) { /* UTF-8 error */
  2719.                         outxbuf[0] = '?'; /* Insert error char */
  2720.                         outxbuf[1] = u_to_b2(); /* Insert next char */
  2721.                         outxcount = 2;
  2722.                     } else {
  2723.                         outxbuf[0] =    /* Otherwise store result */
  2724.                           (unsigned)(x & 0xff);
  2725.                     }
  2726.                     break;
  2727.                   case 6:               /* UTF-8 to UTF-8 */
  2728.                   case 7:
  2729.                     break;
  2730.                   case 8:               /* UCS-2 to byte */
  2731.                   case 9:
  2732.                     xuf = xl_ufc[tcsr];
  2733.                     outxbuf[0] = (*xuf)(uc.x_short);
  2734.                     break;
  2735.                   case 10:
  2736.                   case 11: {            /* UCS-2 to UTF-8 */
  2737.                       int j;
  2738.                       CHAR * buf = NULL;
  2739.                       x = ucs2_to_utf8(uc.x_short,&buf);
  2740.                       if (x < 0) {
  2741.                           outxbuf[0] = 0xff; /* (= U+FFFD) */
  2742.                           outxbuf[1] = 0xbd;
  2743.                           x = 2;
  2744.                       }
  2745.                       for (j = 0; j < x; j++)
  2746.                         outxbuf[j] = buf[j];
  2747.                       outxcount = x;
  2748.                       break;
  2749.                   }
  2750. #endif /* UNICODE */
  2751.                 }
  2752. #endif /* NOCSETS */
  2753.                 outxbuf[outxcount] = NUL;
  2754.                 debug(F111,"XMIT outxbuf",outxbuf,outxcount);
  2755. /*
  2756.   Now the input character (1 or more bytes) is translated into the output
  2757.   expansion buffer (1 or more bytes); outxcount = number of bytes to add to
  2758.   the TRANSMIT line buffer, which we do here, taking care of parity, SI/SO
  2759.   processing, and quoting Telnet IACs.
  2760. */
  2761.                 for (k = 0; k < outxcount; k++) {
  2762.                     c = outxbuf[k];
  2763.                     if (xmits && parity && (c & 0200)) { /* If shifting */
  2764.                         line[i++] = dopar(SO); /* needs to be done, */
  2765.                         line[i++] = dopar((char)c); /* do it here, */
  2766.                         line[i++] = dopar(SI); /* crudely. */
  2767.                     } else {
  2768.                         line[i++] = dopar((char)c);
  2769. #ifdef TNCODE
  2770.                         if (c == IAC && is_tn)
  2771.                           line[i++] = IAC;
  2772. #endif /* TNCODE */
  2773.                     }
  2774.                 }
  2775.             }
  2776. /*
  2777.   Send characters if buffer full, or at end of line, or at end of file.
  2778.   (End of line only if echoing, waiting for a prompt, or pausing.)
  2779. */
  2780.             debug(F000,"XMIT c",ckitoa(i),c);
  2781.             if (i >= xbufsiz || eof || (eol && (xxecho || xmitw || t))) {
  2782.                 p = line;
  2783.                 line[i] = '\0';
  2784.                 debug(F111,"transmit buf",p,i);
  2785.                 if (ttol((CHAR *)p,i) < 0) { /* try to send it. */
  2786.                     printf("?TRANSMIT output error: %s\n",ck_errstr());
  2787.                     rc = 0;
  2788.                     break;
  2789.                 }
  2790.                 i = 0;                  /* Reset buffer pointer. */
  2791. /*
  2792.   Now we handle the echo.  If the user wants to see it, or if we have to
  2793.   wait for the turnaround character, t.  If the echo is being displayed,
  2794.   and terminal character-set translation is required, we do it here.
  2795. */
  2796.                 if (duplex && xxecho) {  /* If local echo, echo it */
  2797.                     if (parity || cmdmsk == 0x7f) { /* Strip hi bits */
  2798.                         char *ss = line;             /* if necessary */
  2799.                         while (*ss) {
  2800.                             *ss &= 0x7f;
  2801.                             ss++;
  2802.                         }
  2803.                     }
  2804. #ifndef NOLOCAL
  2805. #ifdef OS2
  2806.                     {                   /* Echo to emulator */
  2807.                         char *ss = p;
  2808.                         while (*ss) {
  2809.                             scriptwrtbuf((USHORT)*ss);
  2810.                             ss++;
  2811.                         }
  2812.                     }
  2813. #endif /* OS2 */
  2814. #endif /* NOLOCAL */
  2815.                     if (conoll(p) < 0)
  2816.                       goto xmitfail;
  2817.                 }
  2818.                 if (xmitw)              /* Sleep TRANSMIT PAUSE interval */
  2819.                   msleep(xmitw);
  2820.  
  2821.                 control = 0;            /* Readback loop control */
  2822.                 if (t != 0 && eol)      /* TRANSMIT PROMPT given and at EOL */
  2823.                   control |= 1;
  2824.                 if (xxecho && !duplex)   /* Echo desired and is remote */
  2825.                   control |= 2;
  2826.  
  2827.                 if (control) {          /* Do this if reading back the echo */
  2828.                     int n;
  2829.                     x = 0;
  2830.                     while (1) {
  2831.                         if (control & 1) { /* Termination criterion */
  2832.                             if (x == t)    /* for turnaround */
  2833.                               break;
  2834.                         } else if (control & 2) { /* And for echoing */
  2835.                             if ((n = ttchk()) < 1)
  2836.                               break;
  2837.                         }
  2838.                         if ((x = ttinc(xmitt)) < 0) { /* Read with timeout */
  2839.                             switch (x) {
  2840.                               case -2:
  2841.                                 printf("Connection closed.\n");
  2842.                                 ttclos(1);
  2843.                                 goto xmitfail;
  2844.                               case -3:
  2845.                                 printf(
  2846.                               "Session Limit exceeded - closing connection.\n"
  2847.                                        );
  2848.                                 ttclos(1); /* full thru... */
  2849.                                 goto xmitfail;
  2850.                               default:
  2851.                                 printf("?Timeout\n");
  2852.                                 goto xmitfail;
  2853.                             }
  2854.                         }
  2855.                         if (x > -1 && (control & 2)) { /* Echo any echoes */
  2856.                             if (parity)
  2857.                               x &= 0x7f;
  2858.                             c = x;
  2859. #ifndef NOLOCAL
  2860. #ifdef OS2
  2861.                             scriptwrtbuf((USHORT)x);
  2862. #endif /* OS2 */
  2863. #endif /* NOLOCAL */
  2864.                             inxbuf[0] = c;
  2865.                             inxcount = 1;
  2866. #ifndef NOCSETS
  2867.                             switch (unicode & 3) { /* Remote bits */
  2868.                               case 0:
  2869.                                 if (xlate) {
  2870.                                     if (sxi) c = (*sxi)((CHAR)c);
  2871.                                     if (rxi) c = (*rxi)((CHAR)c);
  2872.                                     inxbuf[0] = c;
  2873.                                 }
  2874.                                 break;
  2875. #ifdef UNICODE
  2876.                               case 1:   /* Remote Byte to local UTF-8 */
  2877.                                 xfu = xl_fcu[tcsr];
  2878.                                 tcssize = fcsinfo[tcsr].size;
  2879.                                 inxcount =
  2880.                                   b_to_u((CHAR)c,
  2881.                                          inxbuf,
  2882.                                          OUTXBUFSIZ,
  2883.                                          tcssize
  2884.                                          );
  2885.                                 break;
  2886.                               case 2:   /* Remote UTF-8 to local Byte */
  2887.                                 xuf = xl_ufc[tcsl];
  2888.                                 x = u_to_b((CHAR)c);
  2889.                                 if (x < 0)
  2890.                                   continue;
  2891.                                 inxbuf[0] = (unsigned)(x & 0xff);
  2892.                                 break;
  2893.                               case 3:   /* UTF-8 to UTF-8 */
  2894.                                 break;
  2895. #endif /* UNICODE */
  2896.                             }
  2897. #endif /* NOCSETS */
  2898.                             inxbuf[inxcount] = NUL;
  2899.                             if (conxo(inxcount,(char *)inxbuf) < 0)
  2900.                               goto xmitfail;
  2901.                         }
  2902.                     }
  2903.                 } else                  /* Not echoing */
  2904.                   ttflui();             /* Just flush input buffer */
  2905.             } /* End of buffer-dumping block */
  2906.         } /* End of text mode */
  2907.         if (eof) {
  2908.             rc = 1;
  2909.             goto xmitexit;
  2910.         }
  2911.     } /* End of character-reading loop */
  2912.  
  2913.   xmitfail:                             /* Failure exit point */
  2914.     rc = 0;
  2915.  
  2916.   xmitexit:                             /* General exit point */
  2917.     if (rc > 0) {
  2918.     if (binary && !xmitw && !xxecho) { /* "blasting"? */
  2919.         while (count > 0) {           /* Partial buffer still to go? */
  2920.         errno = 0;
  2921.         y = ttol(xbbuf,count);
  2922.         if (y < 0) {
  2923.             printf("?TRANSMIT output error: %s\n",
  2924.                ck_errstr());
  2925.             debug(F111,"XMIT binary eof ttol error",
  2926.               ck_errstr(),errno);
  2927.             rc = 0;
  2928.             break;
  2929.         }
  2930.         count -= y;
  2931.         }
  2932.     } else if (!binary && *xmitbuf) { /* Anything to send at EOF? */
  2933.             p = xmitbuf;                /* Yes, point to string. */
  2934.             while (*p)                  /* Send it. */
  2935.               ttoc(dopar(*p++));        /* Don't worry about echo here. */
  2936.         }
  2937.     }
  2938.  
  2939. #ifndef AMIGA
  2940. #ifndef MAC
  2941.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  2942. #endif /* MAC */
  2943. #endif /* AMIGA */
  2944. #ifdef VMS
  2945.     concb(escape);                      /* Put terminal back, */
  2946. #endif /* VMS */
  2947.     zclose(ZIFILE);                     /* Close file, */
  2948. #ifndef NOCSETS
  2949.     language = langsv;                  /* restore language, */
  2950. #endif /* NOCSETS */
  2951.     ttres();                            /* and terminal modes, */
  2952.     return(rc);                         /* and return successfully. */
  2953. }
  2954. #endif /* NOLOCAL */
  2955. #endif /* NOXMIT */
  2956.  
  2957. #ifndef NOCSETS
  2958.  
  2959. _PROTOTYP( CHAR (*sxx), (CHAR) );       /* Local translation function */
  2960. _PROTOTYP( CHAR (*rxx), (CHAR) );       /* Local translation function */
  2961. _PROTOTYP( CHAR zl1as, (CHAR) );        /* Latin-1 to ascii */
  2962. _PROTOTYP( CHAR xl1as, (CHAR) );        /* ditto */
  2963.  
  2964. /*  X L A T E  --  Translate a local file from one character set to another */
  2965.  
  2966. /*
  2967.   Translates input file (fin) from character set csin to character set csout
  2968.   and puts the result in the output file (fout).  The two character sets are
  2969.   file character sets from fcstab.
  2970. */
  2971.  
  2972. int
  2973. xlate(fin, fout, csin, csout) char *fin, *fout; int csin, csout; {
  2974.  
  2975. #ifndef MAC
  2976. #ifdef OS2
  2977.     extern int k95stdout;
  2978.     extern int wherex[], wherey[];
  2979.     extern unsigned char colorcmd;
  2980. #ifdef NT
  2981.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  2982. #else /* NT */
  2983.     SIGTYP (* volatile oldsig)(int);    /* For saving old interrupt trap. */
  2984. #endif /* NT */
  2985. #else /* OS2 */
  2986.     SIGTYP (* oldsig)();
  2987. #endif /* OS2 */
  2988. #endif /* MAC */
  2989. #ifdef CK_ANSIC
  2990.     int (*fn)(char);                    /* Output function pointer */
  2991. #else
  2992.     int (*fn)();
  2993. #endif /* CK_ANSIC */
  2994.     extern int xlatype;
  2995.     int filecode;                       /* Code for output file */
  2996.     int scrnflg = 0;
  2997.  
  2998.     int z = 1;                          /* Return code. */
  2999.     int x, c, c2;            /* Workers */
  3000. #ifndef UNICODE
  3001.     int tcs;
  3002. #endif /* UNICODE */
  3003.  
  3004.     ffc = 0L;
  3005.  
  3006.     if (zopeni(ZIFILE,fin) == 0) {      /* Open the file to be translated */
  3007. #ifdef COMMENT
  3008.     /* An error message was already printed by zopeni() */
  3009.         printf("?Can't open input file %s\n",fin);
  3010. #endif /* COMMENT */
  3011.         return(0);
  3012.     }
  3013. #ifdef MAC
  3014. /*
  3015.   If user specified no output file, it goes to the screen.  For the Mac,
  3016.   this must be done a special way (result goes to a new window); the Mac
  3017.   doesn't have a "controlling terminal" device name.
  3018. */
  3019.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZOFILE;
  3020. #else
  3021. #ifdef VMS
  3022.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZMFILE;
  3023. #else
  3024. #ifdef OS2
  3025.     filecode = (!stricmp(fout,"con") || !stricmp(fout,"con:")) ?
  3026.         ZCTERM : ZMFILE;
  3027.     if ((filecode == ZCTERM) && !k95stdout && !inserver)
  3028.     csout = FC_UCS2;
  3029. #else /* OS2 */
  3030.     filecode = ZOFILE;
  3031. #endif /* OS2 */
  3032. #endif /* VMS */
  3033. #endif /* MAC */
  3034.     if (zopeno(filecode,fout,NULL,NULL) == 0) { /* And the output file */
  3035.         printf("?Can't open output file %s\n",fout);
  3036.         return(0);
  3037.     }
  3038. #ifndef AMIGA
  3039. #ifndef MAC
  3040.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  3041. #endif /* MAC */
  3042. #endif /* AMIGA */
  3043.  
  3044.     scrnflg = (filecode == ZCTERM);     /* Set output function */
  3045.     if (scrnflg)
  3046.       fn = NULL;
  3047.     else if (filecode == ZMFILE)
  3048.       fn = putmfil;
  3049.     else
  3050.       fn = putfil;
  3051.  
  3052.     tr_int = 0;                         /* Have not been interrupted (yet). */
  3053.     z = 1;                              /* Return code presumed good. */
  3054.  
  3055.     if (!scrnflg && !quiet)
  3056.       printf(" %s (%s) => %s (%s)\n",    /* Say what we're doing. */
  3057.              fin, fcsinfo[csin].keyword,
  3058.              fout,fcsinfo[csout].keyword
  3059.              );
  3060.  
  3061. #ifndef UNICODE
  3062. /*
  3063.   Non-Unicode picks the "most appropriate" transfer character set as the
  3064.   intermediate set, which results in loss of any characters that the source
  3065.   and target sets have in common, but are lacking from the intermediate set.
  3066. */
  3067. #ifdef KANJI
  3068.     /* Special handling for Japanese... */
  3069.  
  3070.     if (fcsinfo[csin].alphabet == AL_JAPAN ||
  3071.          fcsinfo[csout].alphabet == AL_JAPAN) {
  3072.         USHORT eu;
  3073.         int c, x, y;
  3074.  
  3075.         xpnbyte(-1,0,0,NULL);           /* Reset output machine */
  3076.         xlatype = XLA_JAPAN;
  3077.  
  3078.         while ((c = xgnbyte(FC_JEUC,csin,NULL)) > -1) { /* Get an EUC byte */
  3079.             if (tr_int) {               /* Interrupted? */
  3080.                 printf("^C...\n");      /* Print message */
  3081.                 z = 0;
  3082.                 break;
  3083.             }
  3084.             /* Send EUC byte to output machine */
  3085.             if ((x = xpnbyte(c,TC_JEUC,csout,fn)) < 0) {
  3086.                 z = -1;
  3087.                 break;
  3088.             }
  3089.         }
  3090.         goto xxlate;
  3091.     }
  3092. #endif /* KANJI */
  3093.  
  3094.     /* Regular bytewise conversion... */
  3095.  
  3096.     tcs = gettcs(csin,csout);           /* Get intermediate set. */
  3097.     if (csin == csout) {                /* Input and output sets the same? */
  3098.         sxx = rxx = NULL;               /* If so, no translation. */
  3099.     } else {                            /* Otherwise, set up */
  3100.         if (tcs < 0 || tcs > MAXTCSETS ||
  3101.             csin < 0 || csin > MAXFCSETS ||
  3102.             csout < 0 || csout > MAXFCSETS) {
  3103.             debug(F100,"XLATE csets out of range","",0);
  3104.             sxx = rxx = NULL;
  3105.         } else {
  3106.             sxx = xls[tcs][csin];       /* translation function */
  3107.             rxx = xlr[tcs][csout];      /* pointers. */
  3108.             if (rxx == zl1as) rxx = xl1as;
  3109.         }
  3110.     }
  3111.     while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3112.         if (tr_int) {                   /* Interrupted? */
  3113.             printf("^C...\n");          /* Print message */
  3114.             z = 0;
  3115.             break;
  3116.         }
  3117.         if (sxx) c = (*sxx)((CHAR)c);   /* From fcs1 to tcs */
  3118.         if (rxx) c = (*rxx)((CHAR)c);   /* from tcs to fcs2 */
  3119.         if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3120.             z = -1;
  3121.             break;
  3122.         }
  3123.     }
  3124.     goto xxlate;                        /* Done. */
  3125.  
  3126. #else  /* UNICODE */
  3127. /*
  3128.    Use Unicode as the intermediate character set.  It's simple and gives
  3129.    little or no loss, but the overhead is a bit higher.
  3130. */
  3131.     initxlate(csin,csout);              /* Set up translation functions */
  3132.  
  3133.     if (xlatype == XLA_NONE) {
  3134.     while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3135.         if (tr_int) {        /* Interrupted? */
  3136.         printf("^C...\n");    /* Print message */
  3137.         z = 0;
  3138.         break;
  3139.         }
  3140.         if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3141.         z = -1;
  3142.         break;
  3143.         }
  3144.     }
  3145.     goto xxlate;            /* Done. */
  3146.     }
  3147.  
  3148.  
  3149. #ifndef NOLOCAL
  3150. #ifdef OS2
  3151.     if (csout == FC_UCS2 &&             /* we're translating to UCS-2 */
  3152.         filecode == ZCTERM &&           /* for the real screen... */
  3153.         !k95stdout && !inserver
  3154.         ) {
  3155.         union {
  3156.             USHORT ucs2;
  3157.             UCHAR  bytes[2];
  3158.         } output;
  3159.  
  3160.         while (1) {                     /* In this case we go two-by-two. */
  3161.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3162.               break;
  3163.             output.bytes[0] = c;
  3164.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3165.               break;
  3166.             output.bytes[1] = c;
  3167.  
  3168.             if (tr_int) {               /* Interrupted? */
  3169.                 printf("^C...\n");      /* Print message */
  3170.                 z = 0;
  3171.                 break;
  3172.             }
  3173.  
  3174.             VscrnWrtUCS2StrAtt(VCMD,
  3175.                                &output.ucs2,
  3176.                                1,
  3177.                                wherey[VCMD],
  3178.                                wherex[VCMD],
  3179.                                &colorcmd
  3180.                                );
  3181.         }
  3182.     } else
  3183. #endif /* OS2 */
  3184. #endif /* NOLOCAL */
  3185.  
  3186.       /* General case: Get next byte translated from fcs to UCS-2 */
  3187.  
  3188.       while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1 &&
  3189.           (c2 = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3190.       extern int fileorder;
  3191.  
  3192.           if (tr_int) {                 /* Interrupted? */
  3193.               printf("^C...\n");        /* Print message */
  3194.               z = 0;
  3195.               break;
  3196.           }
  3197.           debug(F001,"XLATE c","",c);
  3198.           debug(F001,"XLATE c2","",c2);
  3199.  
  3200.           /* And then send UCS-2 byte to translate-and-output machine */
  3201.  
  3202.           if ((x = xpnbyte(fileorder?c2:c,TC_UCS2,csout,fn)) < 0) {
  3203.               z = -1;
  3204.               break;
  3205.           }
  3206.           if ((x = xpnbyte(fileorder?c:c2,TC_UCS2,csout,fn)) < 0) {
  3207.               z = -1;
  3208.               break;
  3209.           }
  3210.       }
  3211. #endif /* UNICODE */
  3212.  
  3213.   xxlate:                               /* Common exit point */
  3214.  
  3215. #ifndef AMIGA
  3216. #ifndef MAC
  3217.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3218. #endif /* MAC */
  3219. #endif /* AMIGA */
  3220.     tr_int = 0;
  3221.     if (z < 0) {
  3222.         if (z == -1)
  3223.           printf("?File output error: %s\n",ck_errstr());
  3224.         z = 0;
  3225.     }
  3226.     zclose(ZIFILE);                     /* Close files */
  3227.     zclose(filecode);                   /* ... */
  3228.     return(success = z);                /* and return status. */
  3229. }
  3230.  
  3231. int
  3232. doxlate() {
  3233. #ifdef OS2ONLY
  3234.     extern int tt_font;
  3235. #endif /* OS2ONLY */
  3236. #ifdef UNIX
  3237.     extern char ** mtchs;        /* zxpand() file list */
  3238. #endif /* UNIX */
  3239.     extern int nfilc;
  3240.     extern struct keytab fcstab[];
  3241.     int x, y, incs, outcs, multiple = 0, wild = 0, fc = 0, len = 0;
  3242.     int ofisdir = 0;
  3243.     char * s, * tocs = "";
  3244.  
  3245.     if ((x = cmifi("File(s) to translate","",&s,&wild,xxstring)) < 0) {
  3246.     if (x == -3) {
  3247.         printf("?Name of an existing file\n");
  3248.         return(-9);
  3249.     } else
  3250.       return(x);
  3251.     }
  3252.     ckstrncpy(line,s,LINBUFSIZ);    /* Save copy of string just parsed. */
  3253.  
  3254.     if ((incs = cmkey(fcstab,nfilc,"from character-set","",xxstring)) < 0)
  3255.       return(incs);
  3256.  
  3257. #ifdef OS2
  3258.     if (isunicode())
  3259.       tocs = "ucs2";
  3260.     else
  3261. #endif /* OS2 */
  3262.       tocs = getdcset();
  3263.  
  3264.     if ((outcs = cmkey(fcstab,nfilc,"to character-set",tocs,xxstring)) < 0)
  3265.       return(outcs);
  3266.     if ((x = cmofi("output file",CTTNAM,&s,xxstring)) < 0) return(x);
  3267.     if (x > 1)
  3268.       ofisdir = 1;
  3269.  
  3270.     len = ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  3271.     if ((y = cmcfm()) < 0) return(y);    /* Confirm the command */
  3272.  
  3273.     if (len < 1)
  3274.       return(-2);
  3275.  
  3276.     if (ofisdir)
  3277.       multiple = 2;
  3278.     else if (wild) {
  3279.     if (isdir(tmpbuf))
  3280.       multiple = 2;
  3281.     else if (!strcmp(tmpbuf,CTTNAM))
  3282.       multiple = 1;
  3283. #ifdef OS2
  3284.     else if (!stricmp(tmpbuf,"con") || !stricmp(tmpbuf,"con:"))
  3285.       multiple = 1;
  3286. #else
  3287. #ifdef UNIXOROSK
  3288.     else if (!strncmp(tmpbuf,"/dev/",4))
  3289.       multiple = 1;
  3290. #endif /* UNIXOROSK */
  3291. #endif /* OS2 */
  3292.     if (!multiple) {
  3293.         printf("?A single file please\n");
  3294.         return(-9);
  3295.     }
  3296.     }
  3297.     if (!multiple) {            /* Just one file */
  3298.     return(success = xlate(line,tmpbuf,incs,outcs));
  3299.     } else {                /* Translate multiple files */
  3300.     char dirbuf[CKMAXPATH+4];
  3301.     int k;
  3302. #ifndef ZXREWIND
  3303.     int flags = ZX_FILONLY;
  3304. #endif /* ZXREWIND */
  3305.  
  3306.     if (multiple == 2) {        /* Target is a directory */
  3307.         k = ckstrncpy(dirbuf,tmpbuf,CKMAXPATH+1) - 1;
  3308.         if (k < 0)
  3309.           return(-2);
  3310. #ifdef OS2ORUNIX
  3311.         if (dirbuf[k] != '/') {
  3312.         dirbuf[k+1] = '/';
  3313.         dirbuf[k+2] = NUL;
  3314.         }
  3315. #else
  3316. #ifdef OSK
  3317.         if (dirbuf[k] != '/') {
  3318.         dirbuf[k+1] = '/';
  3319.         dirbuf[k+2] = NUL;
  3320.         }
  3321. #else
  3322. #ifdef VMS
  3323.         if (ckmatch("*.DIR;1",s,0,0))
  3324.           k = cvtdir(tmpbuf,dirbuf,TMPBUFSIZ);
  3325.         if (dirbuf[k] != ']' &&
  3326.         dirbuf[k] != '>' &&
  3327.         dirbuf[k] != ':')
  3328.           return(-2);
  3329. #else
  3330. #ifdef datageneral
  3331.         if (dirbuf[k] != ':') {
  3332.         dirbuf[k+1] = ':';
  3333.         dirbuf[k+2] = NUL;
  3334.         }
  3335. #else
  3336. #ifdef STRATUS
  3337.         if (dirbuf[k] != '>') {
  3338.         dirbuf[k+1] = '>';
  3339.         dirbuf[k+2] = NUL;
  3340.         }
  3341. #endif /* STRATUS */
  3342. #endif /* datageneral */
  3343. #endif /* VMS */
  3344. #endif /* OSK */
  3345. #endif /* OS2ORUNIX */
  3346.     }
  3347.  
  3348. #ifdef ZXREWIND
  3349.     fc = zxrewind();        /* Rewind the file list */
  3350. #else
  3351.     if (matchdot)  flags |= ZX_MATCHDOT;
  3352.     fc = nzxpand(line,flags);
  3353. #endif /* ZXREWIND */
  3354.  
  3355.     if (fc < 1) {
  3356.         printf("?Wildcard expansion error\n");
  3357.         return(-9);
  3358.     }
  3359. #ifdef UNIX
  3360.     sh_sort(mtchs,NULL,fc,0,0,filecase); /* Sort the file list */
  3361. #endif /* UNIX */
  3362.  
  3363.     while (1) {            /* Loop through the files */
  3364.         znext(line);
  3365.         if (!line[0])
  3366.           break;
  3367.         if (multiple == 2)
  3368.           ckmakmsg(tmpbuf,TMPBUFSIZ,dirbuf,line,NULL,NULL);
  3369.         if (xlate(line,tmpbuf,incs,outcs) < 1)
  3370.           return(success = 0);
  3371.     }
  3372.     }
  3373.     return(success = 1);
  3374. }
  3375. #endif /* NOCSETS */
  3376.  
  3377. static char hompthbuf[CKMAXPATH+1];
  3378.  
  3379. char *
  3380. homepath() {
  3381.     int x;
  3382.     hompthbuf[0] = NUL;
  3383. #ifdef UNIXOROSK
  3384.     x = ckstrncpy(hompthbuf,zhome(),CKMAXPATH+1);
  3385.     if (x <= 0) {
  3386.         hompthbuf[0] = '/';
  3387.         hompthbuf[1] = NUL;
  3388.     } else if (x < CKMAXPATH - 2 && hompthbuf[x-1] != '/') {
  3389.         hompthbuf[x] = '/';
  3390.         hompthbuf[x+1] = NUL;
  3391.     }
  3392.     return(hompthbuf);
  3393. #else
  3394. #ifdef STRATUS
  3395.     if (strlen(zhome()) < CKMAXPATH)    /* SAFE */
  3396.       sprintf(hompthbuf,"%s>",zhome());
  3397.     return(hompthbuf);
  3398. #else
  3399.     return(zhome());
  3400. #endif /* STRATUS */
  3401. #endif /* UNIXOROSK */
  3402. }
  3403.  
  3404. /*  D O L O G  --  Do the log command  */
  3405.  
  3406. int
  3407. dolog(x) int x; {
  3408.     int y, disp; char *s = NULL, * p = NULL, * q = NULL;
  3409.     extern int isguest;
  3410. #ifdef ZFNQFP
  3411.     struct zfnfp * fnp;
  3412. #endif /* ZFNQFP */
  3413.  
  3414.     if (isguest) {
  3415.         printf("?Anonymous log creation not allowed\n");
  3416.         return(-9);
  3417.     }
  3418.     switch (x) {                        /* Which log... */
  3419.  
  3420. #ifdef DEBUG
  3421.       case LOGD:
  3422.     q = "debug.log";
  3423.         y = cmofi("Name of debugging log file",q,&s,xxstring);
  3424.         break;
  3425. #endif /* DEBUG */
  3426.  
  3427.       case LOGP:
  3428.     q = "packet.log";
  3429.         y = cmofi("Name of packet log file",q,&s,xxstring);
  3430.         break;
  3431.  
  3432. #ifndef NOLOCAL
  3433.       case LOGS:
  3434.     q = "session.log";
  3435.         y = cmofi("Name of session log file",q,&s,xxstring);
  3436.         break;
  3437. #endif /* NOLOCAL */
  3438.  
  3439. #ifdef TLOG
  3440.       case LOGT:
  3441.     q = "transact.log";
  3442.         y = cmofi("Name of transaction log file",q,&s,xxstring);
  3443.         break;
  3444. #endif /* TLOG */
  3445.  
  3446. #ifdef CKLOGDIAL
  3447.       case LOGM: {
  3448.           int m, n;
  3449.           char mypath[CKMAXPATH+1];
  3450.       q = CXLOGFILE;
  3451.           m = ckstrncpy(mypath,homepath(),CKMAXPATH);
  3452.           n = strlen(CXLOGFILE);
  3453.           if (m + n < CKMAXPATH)
  3454.             ckstrncat(mypath,CXLOGFILE,CKMAXPATH);
  3455.           else
  3456.             ckstrncpy(mypath,CXLOGFILE,CKMAXPATH);
  3457.           y = cmofi("Name of connection log file",mypath,&s,xxstring);
  3458.           break;
  3459.       }
  3460. #endif /* CKLOGDIAL */
  3461.  
  3462.       default:
  3463.         printf("\n?Unknown log designator - %d\n",x);
  3464.         return(-2);
  3465.     }
  3466.     if (y < 0) return(y);
  3467.     if (y == 2) {            /* If they gave a directory name */
  3468.     int k;
  3469.     char * ds = "/";
  3470.     k = strlen(s);
  3471.     if (k > 0 && s[k-1] == '/') ds = "";
  3472.     ckmakmsg(tmpbuf,TMPBUFSIZ,s,ds,q,NULL);
  3473.     s = tmpbuf;
  3474.     }
  3475. #ifdef ZFNQFP
  3476. #ifdef OS2ORUNIX
  3477.     if (*s != '|')                      /* Allow for pipes */
  3478. #else
  3479. #ifdef OSK
  3480.     if (*s != '|')
  3481. #endif /* OSK */
  3482. #endif /* OS2ORUNIX */
  3483.       if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3484.           if (fnp->fpath)
  3485.             if ((int) strlen(fnp->fpath) > 0)
  3486.               s = fnp->fpath;
  3487.       } /* else if error keep original string */
  3488. #endif /* ZFNQFP */
  3489.  
  3490.     ckstrncpy(line,s,LINBUFSIZ);
  3491.     s = line;
  3492. #ifdef MAC
  3493.     y = 0;
  3494. #else
  3495.  
  3496.     p = "new";
  3497. #ifdef TLOG
  3498.     if ((x == LOGT && tlogfmt == 2) || x == LOGM)
  3499.       p = "append";
  3500. #endif /* TLOG */
  3501.  
  3502.     if ((y = cmkey(disptb,2,"Disposition",p,xxstring)) < 0)
  3503.       return(y);
  3504. #endif /* MAC */
  3505.     disp = y;
  3506.     if ((y = cmcfm()) < 0) return(y);
  3507.  
  3508.     switch (x) {
  3509.  
  3510. #ifdef DEBUG
  3511.       case LOGD:
  3512.         return(deblog = debopn(s,disp));
  3513. #endif /* DEBUG */
  3514.  
  3515. #ifndef NOXFER
  3516.       case LOGP:
  3517.         return(pktlog = pktopn(s,disp));
  3518. #endif /* NOXFER */
  3519.  
  3520. #ifndef NOLOCAL
  3521.       case LOGS:
  3522.         return(seslog = sesopn(s,disp));
  3523. #endif /* NOLOCAL */
  3524.  
  3525. #ifdef TLOG
  3526.       case LOGT:
  3527.         return(tralog = traopn(s,disp));
  3528. #endif /* TLOG */
  3529.  
  3530. #ifdef CKLOGDIAL
  3531.       case LOGM:
  3532.         return(dialog = diaopn(s,disp,0));
  3533. #endif /* CKLOGDIAL */
  3534.  
  3535.       default:
  3536.         return(-2);
  3537.     }
  3538. }
  3539.  
  3540. #ifndef NOXFER
  3541. int
  3542. pktopn(s,disp) char *s; int disp; {
  3543.     static struct filinfo xx;
  3544.  
  3545.     if (!s)
  3546.       s = "";
  3547.     if (!*s)
  3548.       return(0);
  3549.  
  3550.     debug(F111,"pktopn",s,disp);
  3551.  
  3552.     zclose(ZPFILE);
  3553.  
  3554. #ifdef OS2ORUNIX
  3555.     if (s[0] == '|') {                  /* Pipe */
  3556.         char * p = s + 1;
  3557.         debug(F110,"pktopn p",p,0);
  3558.         while (*p) {
  3559.             if (*p != ' ')
  3560.               break;
  3561.             else
  3562.               p++;
  3563.         }
  3564.         debug(F110,"pktopn pipe",p,0);
  3565.         pktlog = zxcmd(ZPFILE,p);
  3566.         debug(F101,"pktopn seslog","",seslog);
  3567.     } else {                            /* File */
  3568. #endif /* OS2ORUNIX */
  3569.         if (disp) {
  3570.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3571.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3572.             xx.lblopts = 0;
  3573.             pktlog = zopeno(ZPFILE,s,NULL,&xx);
  3574.         } else pktlog = zopeno(ZPFILE,s,NULL,NULL);
  3575.         if (!pktlog)
  3576.           printf("?%s - %s\n",s,ck_errstr());
  3577. #ifdef OS2ORUNIX
  3578.     }
  3579. #endif /* OS2ORUNIX */
  3580.     if (pktlog > 0)
  3581.       ckstrncpy(pktfil,s,CKMAXPATH+1);
  3582.     else
  3583.       *pktfil = '\0';
  3584.     return(pktlog);
  3585. }
  3586. #endif /* NOXFER */
  3587.  
  3588. int
  3589. traopn(s,disp) char *s; int disp; {
  3590. #ifdef TLOG
  3591.     static struct filinfo xx;
  3592.  
  3593.     if (!s)
  3594.       s = "";
  3595.     if (!*s)
  3596.       return(0);
  3597.  
  3598.     debug(F111,"traopn",s,disp);
  3599.     debug(F101,"traopn tlogfmt","",tlogfmt);
  3600.  
  3601.     zclose(ZTFILE);
  3602.  
  3603. #ifdef OS2ORUNIX
  3604.     if (tlogfmt == 2) {                 /* FTP format is special... */
  3605.     VOID doiklog();
  3606.         if (!disp)                      /* Append? */
  3607.           if (zchki(s) > -1)            /* No - does file exist? */
  3608.             (VOID) zdelet(s);           /* Yes - delete it. */
  3609.         xferlog = 1;
  3610.         ckstrncpy(trafil,s,CKMAXPATH);
  3611.         makestr(&xferfile,s);
  3612.     doiklog();
  3613.         return(1);
  3614.     }
  3615.     if (s[0] == '|') {                  /* Pipe */
  3616.         char * p = s + 1;
  3617.         debug(F110,"traopn p",p,0);
  3618.         while (*p) {
  3619.             if (*p != ' ')
  3620.               break;
  3621.             else
  3622.               p++;
  3623.         }
  3624.         debug(F110,"traopn pipe",p,0);
  3625.         tralog = zxcmd(ZTFILE,p);
  3626.         debug(F101,"traopn tralog","",tralog);
  3627.     }
  3628. #endif /* OS2ORUNIX */
  3629.  
  3630.     if (s[0] != '|') {                  /* File */
  3631.         if (disp) {
  3632.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3633.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3634.             xx.lblopts = 0;
  3635.             tralog = zopeno(ZTFILE,s,NULL,&xx);
  3636.         } else tralog = zopeno(ZTFILE,s,NULL,NULL);
  3637.     }
  3638.     if (!tralog)
  3639.       printf("?%s - %s\n",s,ck_errstr());
  3640.     if (tralog > 0 && tlogfmt > 0) {
  3641.         ckstrncpy(trafil,s,CKMAXPATH);
  3642.         tlog(F110,"Transaction Log:",versio,0L);
  3643. #ifndef MAC
  3644.         tlog(F100,ckxsys,"",0L);
  3645. #endif /* MAC */
  3646.         ztime(&s);
  3647.         tlog(F100,s,"",0L);
  3648.     } else
  3649.       *trafil = '\0';
  3650.     return(tralog);
  3651. #else
  3652.     return(0);
  3653. #endif /* TLOG */
  3654. }
  3655.  
  3656. #ifndef NOLOCAL
  3657. int
  3658. sesopn(s,disp) char * s; int disp; {
  3659.     static struct filinfo xx;
  3660.     extern int tsstate;
  3661.  
  3662.     tsstate = 0;            /* Session log timestamp state */
  3663.  
  3664.     if (!s)
  3665.       s = "";
  3666.     if (!*s)
  3667.       return(0);
  3668.  
  3669.     debug(F111,"sesopn",s,disp);
  3670.  
  3671.     zclose(ZSFILE);
  3672.  
  3673. #ifdef OS2ORUNIX
  3674.     if (s[0] == '|') {                  /* Pipe */
  3675.         char * p = s + 1;
  3676.         debug(F110,"sesopn p",p,0);
  3677.         while (*p) {
  3678.             if (*p != ' ')
  3679.               break;
  3680.             else
  3681.               p++;
  3682.         }
  3683.         debug(F110,"sesopn pipe",p,0);
  3684.         seslog = zxcmd(ZSFILE,p);
  3685.         debug(F101,"sesopn seslog","",seslog);
  3686.     } else {                            /* File */
  3687. #endif /* OS2ORUNIX */
  3688.         if (disp) {
  3689.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3690.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3691.             xx.lblopts = 0;
  3692.             seslog = zopeno(ZSFILE,s,NULL,&xx);
  3693.         } else
  3694.           seslog = zopeno(ZSFILE,s,NULL,NULL);
  3695.         if (!seslog)
  3696.           printf("?%s - %s\n",s,ck_errstr());
  3697. #ifdef OS2ORUNIX
  3698.     }
  3699. #endif /* OS2ORUNIX */
  3700.     if (seslog > 0)
  3701.       ckstrncpy(sesfil,s,CKMAXPATH+1);
  3702.     else
  3703.       *sesfil = '\0';
  3704.     return(seslog);
  3705. }
  3706. #endif /* NOLOCAL */
  3707. #endif /* NOICP */
  3708.  
  3709. int
  3710. debopn(s,disp) char *s; int disp; {
  3711. #ifdef DEBUG
  3712. #ifdef CK_UTSNAME
  3713.     extern char unm_mch[], unm_nam[], unm_rel[], unm_ver[], unm_mod[];
  3714. #endif /* CK_UTSNAME */
  3715. #ifdef OS2
  3716.     extern char ckxsystem[];
  3717. #endif /* OS2 */
  3718.     char *tp;
  3719.     static struct filinfo xx;
  3720.  
  3721.     if (!s)
  3722.       s = "";
  3723.     if (!*s)
  3724.       return(0);
  3725.  
  3726.     zclose(ZDFILE);
  3727.  
  3728. #ifdef OS2ORUNIX
  3729.     if (s[0] == '|') {                  /* Pipe */
  3730.         char * p = s + 1;
  3731.         debug(F110,"debopn p",p,0);
  3732.         while (*p) {
  3733.             if (*p != ' ')
  3734.               break;
  3735.             else
  3736.               p++;
  3737.         }
  3738.         debug(F110,"debopn pipe",p,0);
  3739.         deblog = zxcmd(ZDFILE,p);
  3740.         debug(F101,"debopn deblog","",deblog);
  3741.     } else {                            /* File */
  3742. #endif /* OS2ORUNIX */
  3743.         if (disp) {
  3744.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3745.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3746.             xx.lblopts = 0;
  3747.             deblog = zopeno(ZDFILE,s,NULL,&xx);
  3748.         } else
  3749.           deblog = zopeno(ZDFILE,s,NULL,NULL);
  3750.         if (!deblog)
  3751.           printf("?%s - %s\n",s,ck_errstr());
  3752. #ifdef OS2ORUNIX
  3753.     }
  3754. #endif /* OS2ORUNIX */
  3755.     if (deblog > 0) {
  3756.         ckstrncpy(debfil,s,CKMAXPATH+1);
  3757.         debug(F110,"Debug Log ",versio,0);
  3758. #ifndef MAC
  3759. #ifdef OS2
  3760.         debug(F110,ckxsys,ckxsystem,0);
  3761. #else /* OS2 */
  3762.         debug(F100,ckxsys,"",0);
  3763. #endif /* OS2 */
  3764. #endif /* MAC */
  3765. #ifdef CK_UTSNAME
  3766.         if (unm_mch[0]) {
  3767.             debug(F110,"uname machine",unm_mch,0);
  3768.             if (unm_mod[0])
  3769.               debug(F110,"uname model  ",unm_mod,0);
  3770.             debug(F110,"uname sysname",unm_nam,0);
  3771.             debug(F110,"uname release",unm_rel,0);
  3772.             debug(F110,"uname version",unm_ver,0);
  3773.         }
  3774. #ifdef KTARGET
  3775.     {
  3776.         char * s;            /* Makefile target */
  3777.         s = KTARGET;
  3778.         if (!s) s = "";
  3779.         if (!*s) s = "(unknown)";
  3780.         debug(F110,"build target",s,0);
  3781.     }
  3782. #endif /* KTARGET */
  3783.         deblog = 0;
  3784.         ztime(&tp);
  3785.         deblog = 1;
  3786.         debug(F100,tp,"",0);
  3787. #endif /* UTSNAME */
  3788.         debug(F101,"byteorder","",byteorder);
  3789. #ifndef NOICP
  3790. #ifndef NOLOCAL
  3791.     if (local) {
  3792.         debug(F110,"Active connection: ",ttname,0);
  3793.         if (!network) {
  3794.         debug(F101,"Speed","",speed);
  3795.         if (hwparity)
  3796.           debug(F110,"Parity[hardware]",parnam((char)hwparity),0);
  3797.         else
  3798.           debug(F110,"Parity",parnam((char)parity),0);
  3799.         deblog = 0;
  3800.         debug(F110,"Modem",gmdmtyp(),0);
  3801.         deblog = 1;
  3802.         }
  3803.     } else {
  3804.         debug(F110,"Active connection: ","none",0);
  3805.     }
  3806. #endif /* NOLOCAL */
  3807. #endif /* NOICP */
  3808.     } else *debfil = '\0';
  3809.     return(deblog);
  3810. #else
  3811.     return(0);
  3812. #endif /* MAC */
  3813. }
  3814.  
  3815.  
  3816. /*  C K D A T E  --  Returns current date/time in standard format  */
  3817.  
  3818. static char nowbuf[18];
  3819.  
  3820. char *
  3821. ckdate() {
  3822.     extern struct keytab cmonths[];
  3823.     int x;
  3824.     char * t;                   /* Substitute today's date */
  3825.     char dbuf[32];
  3826.     ztime(&t);
  3827.  
  3828. /*  012345678901234567890123 */
  3829. /*  Sat Jul  4 12:16:43 1998 */
  3830.  
  3831.     ckstrncpy(dbuf,t,32);
  3832.     t = dbuf;
  3833.     debug(F110,"ckdate dbuf",dbuf,0);
  3834.     nowbuf[0] = t[20];
  3835.     nowbuf[1] = t[21];
  3836.     nowbuf[2] = t[22];
  3837.     nowbuf[3] = t[23];
  3838.  
  3839.     nowbuf[4] = NUL;
  3840.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3841.  
  3842.     t[7] = NUL;
  3843.     if ((x = lookup(cmonths,t+4,12,NULL)) < 0) {
  3844.         debug(F110,"ckdate bad month",t,0);
  3845.         return("<BAD_MONTH>");
  3846.     }
  3847.     sprintf(nowbuf+4,"%02d",x);        /* SAFE */
  3848.     nowbuf[6] = (t[8] == SP) ? '0' : t[8];
  3849.     nowbuf[7] = t[9];
  3850.     nowbuf[8] = ' ';
  3851.  
  3852.     nowbuf[9] = NUL;
  3853.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3854.  
  3855.     for (x = 11; x < 19; x++) nowbuf[x-2] = t[x];
  3856.     nowbuf[17] = NUL;
  3857.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3858.  
  3859.     return((char *)nowbuf);
  3860. }
  3861.  
  3862. #ifndef NOICP
  3863. #ifdef CKLOGDIAL
  3864.  
  3865. /*
  3866.   fc = 0 for initial open, meaning open, then close immediately.
  3867.   fc > 0 for subsequent opens, meaning open for use, leave open.
  3868. */
  3869. int
  3870. diaopn(s,disp,fc) char *s; int disp, fc; {
  3871.     extern char diafil[];
  3872.     static struct filinfo xx;
  3873.  
  3874.     if (!s)
  3875.       s = "";
  3876.     if (!*s)
  3877.       return(0);
  3878.  
  3879.     debug(F110,"diaopn log",s,0);
  3880.     debug(F101,"diaopn fc",s,fc);
  3881.     debug(F101,"diaopn disp 1",s,disp);
  3882.     if (fc) disp = 1;                   /* Force append if open for use */
  3883.     debug(F101,"diaopn disp 2",s,disp);
  3884.  
  3885.     zclose(ZDIFIL);                     /* In case a log was already open */
  3886.  
  3887. #ifdef OS2ORUNIX
  3888.     if (s[0] == '|') {                  /* Pipe */
  3889.         char * p = s + 1;
  3890.         debug(F110,"diaopn p",p,0);
  3891.         while (*p) {
  3892.             if (*p != ' ')
  3893.               break;
  3894.             else
  3895.               p++;
  3896.         }
  3897.         debug(F110,"diaopn pipe",p,0);
  3898.         dialog = zxcmd(ZDIFIL,p);
  3899.         debug(F101,"diaopn dialog","",dialog);
  3900.     } else {                            /* File */
  3901. #endif /* OS2ORUNIX */
  3902.         if (disp) {
  3903.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3904.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3905.             xx.lblopts = 0;
  3906.             dialog = zopeno(ZDIFIL,s,NULL,&xx);
  3907.         } else dialog = zopeno(ZDIFIL,s,NULL,NULL);
  3908.         if (!dialog)
  3909.           printf("?%s - %s\n",s,ck_errstr());
  3910. #ifdef OS2ORUNIX
  3911.     }
  3912. #endif /* OS2ORUNIX */
  3913.     if (dialog > 0)
  3914.       ckstrncpy(diafil,s,CKMAXPATH+1);
  3915.     else
  3916.       *diafil = '\0';
  3917.     if (fc == 0)                        /* Initial open */
  3918.       zclose(ZDIFIL);                   /* close it */
  3919.     return(dialog);
  3920. }
  3921. #endif /* CKLOGDIAL */
  3922.  
  3923. #ifndef NOSHOW
  3924.  
  3925. /*  SHOW command routines */
  3926.  
  3927. char *
  3928. shoxm() {
  3929.     char * s;
  3930.     switch (binary) {
  3931.       case XYFT_T: s = "text";         break;
  3932. #ifdef VMS
  3933.       case XYFT_B: s = "binary fixed"; break;
  3934.       case XYFT_I: s = "image";        break;
  3935.       case XYFT_L: s = "labeled";      break;
  3936.       case XYFT_U: s = "binary undef"; break;
  3937. #else
  3938. #ifdef MAC
  3939.       case XYFT_B: s = "binary";       break;
  3940.       case XYFT_M: s = "macbinary";    break;
  3941. #else
  3942.       case XYFT_B: s = "binary";       break;
  3943. #ifdef CK_LABELED
  3944.       case XYFT_L: s = "labeled";      break;
  3945. #endif /* CK_LABELED */
  3946. #endif /* MAC */
  3947. #endif /* VMS */
  3948.       default: s = "unknown"; break;
  3949.     }
  3950.     return(s);
  3951. }
  3952.  
  3953. #ifndef NOXFER
  3954. VOID                                    /* SHOW TRANSFER */
  3955. shoxfer() {
  3956.     extern int docrc, usepipes, xfrxla;
  3957.     extern char * xfrmsg;
  3958.     printf("\n");
  3959.     printf(" Transfer Bell: %s\n",showoff(xfrbel));
  3960.     printf(" Transfer Interruption: %s\n",showoff(xfrint));
  3961.     printf(" Transfer Cancellation: %s\n",showoff(xfrcan));
  3962. #ifndef NOCSETS
  3963.     printf(" Transfer Translation:  %s\n",showoff(xfrxla));
  3964.     printf(" Transfer Character-set: ");
  3965.     if (tcharset == TC_TRANSP)
  3966.       printf("Transparent\n");
  3967.     else
  3968.       printf("%s\n",tcsinfo[tcharset].keyword);
  3969. #endif /* NOCSETS */
  3970.     printf(" Transfer CRC-calculation: %s\n",showoff(docrc));
  3971.     printf(" Transfer Display: ");
  3972.     switch (fdispla) {
  3973.       case XYFD_N: printf("%s\n","none"); break;
  3974.       case XYFD_R: printf("%s\n","serial"); break;
  3975.       case XYFD_C: printf("%s\n","fullscreen"); break;
  3976.       case XYFD_S: printf("%s\n","crt"); break;
  3977.       case XYFD_B: printf("%s\n","brief"); break;
  3978.     }
  3979.     printf(" Transfer Message: %s\n", xfrmsg ? xfrmsg : "(none)");
  3980.     printf(" Transfer Locking-shift: ");
  3981.     if (lscapu == 2) {
  3982.         printf("forced");
  3983.     } else {
  3984.         printf("%s", (lscapr ? "enabled" : "disabled"));
  3985.         if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  3986.     }
  3987.     printf("\n Transfer Mode: %s\n",
  3988.            xfermode == XMODE_A ?
  3989.            "automatic" :
  3990.            "manual"
  3991.            );
  3992.     printf(" Transfer Pipes: %s\n", showoff(usepipes));
  3993.     printf(" Transfer Protocol: %s\n",ptab[protocol].p_name);
  3994.     printf(" Transfer Slow-start: %s\n",showoff(slostart));
  3995.     printf("\n");
  3996. }
  3997. #endif /* NOXFER */
  3998.  
  3999. VOID
  4000. shoflow() {
  4001.     int i, x;
  4002.     extern int cxflow[], cxtype, ncxname, nfloname, autoflow;
  4003.     extern char * cxname[];
  4004.     printf("\nConnection type:        %s\n",cxname[cxtype]);
  4005.     if (autoflow) {
  4006.     printf("Current flow-control:   %s\n", floname[cxflow[cxtype]]);
  4007.     printf("Switches automatically: yes\n");
  4008.     } else {
  4009.     printf("Current flow-control:   %s\n", floname[flow]);
  4010.     printf("Switches automatically: no\n");
  4011.     }
  4012.     printf("\nDefaults by connection type:\n");
  4013.     debug(F111,"shoflow cxtype",cxname[cxtype],cxtype);
  4014.     debug(F101,"shoflow flow","",flow);
  4015.     for (i = 0; i < ncxname; i++) {
  4016. #ifdef NOLOCAL
  4017.         if (i > 0) break;
  4018. #endif /* NOLOCAL */
  4019. #ifndef NETCONN
  4020.         if (i > 2) break;
  4021. #endif /* NETCONN */
  4022. #ifndef DECNET
  4023.         if (i == CXT_DECNET) continue;
  4024. #endif /* DECNET */
  4025. #ifndef DECNET
  4026. #ifndef SUPERLAT
  4027.         if (i == CXT_LAT) continue;
  4028. #endif /* SUPERLAT */
  4029. #endif /* DECNET */
  4030. #ifndef CK_NETBIOS
  4031.         if (i == CXT_NETBIOS) continue;
  4032. #endif /* CK_NETBIOS */
  4033. #ifndef NPIPE
  4034.         if (i == CXT_NPIPE) continue;
  4035. #endif /* NPIPE */
  4036. #ifndef NETCMD
  4037.         if (i == CXT_PIPE) continue;
  4038. #endif /* NETCMD */
  4039. #ifndef ANYX25
  4040.         if (i == CXT_X25) continue;
  4041. #endif /* ANYX25 */
  4042.         x = cxflow[i];
  4043.         debug(F101,"shoflow x","",x);
  4044.         if (x < nfloname)
  4045.           printf("  %-14s: %s\n",cxname[i],floname[x]);
  4046.         else
  4047.           printf("  %-14s: (%d)\n",cxname[i],x);
  4048.     }
  4049.     printf("\n");
  4050. }
  4051.  
  4052. #ifndef NOLOCAL
  4053. #ifdef ANYX25
  4054. int
  4055. shox25(n) int n; {
  4056.     if (nettype == NET_SX25) {
  4057.         printf("SunLink X.25 V%d.%d",x25ver / 10,x25ver % 10);
  4058.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4059.         printf("\n");
  4060.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4061.         printf(" Reverse charge call %s",
  4062.                revcall ? "selected" : "not selected");
  4063.         printf (", Closed user group ");
  4064.         if (closgr > -1)
  4065.           printf ("%d",closgr);
  4066.         else
  4067.           printf ("not selected");
  4068.         printf("\n");
  4069.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4070.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4071.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4072.     } else if (nettype == NET_VX25) {
  4073.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4074.         printf("\n");
  4075.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4076.         printf(" Reverse charge call %s",
  4077.                revcall ? "selected" : "not selected");
  4078.         printf (", Closed user group [unsupported]");
  4079.         if (closgr > -1)
  4080.           printf ("%d",closgr);
  4081.         else
  4082.           printf ("not selected");
  4083.         printf (",");
  4084.         printf("\n");
  4085.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4086.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4087.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4088.     } else if (nettype == NET_IX25) {
  4089.         printf("AIX NPI X.25\n");
  4090.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4091.         printf("\n Reverse charge call %s",
  4092.                revcall ? "selected" : "not selected");
  4093.         printf (", Closed user group [unsupported]");
  4094.         if (closgr > -1)
  4095.           printf ("%d",closgr);
  4096.         else
  4097.           printf ("not selected");
  4098.         printf (",");
  4099.         printf("\n Call user data %s.\n", cudata ? udata : "not selected");
  4100.     }
  4101.     return(n);
  4102. }
  4103.  
  4104. #ifndef IBMX25
  4105. int
  4106. shopad(n) int n; {
  4107.     int i;
  4108.     printf("\nX.3 PAD Parameters:\n");
  4109.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4110.     for (i = 0; i < npadx3; i++) {
  4111.         printf(" [%d] %s %d\n",padx3tab[i].kwval,padx3tab[i].kwd,
  4112.                padparms[padx3tab[i].kwval]);
  4113.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4114.     }
  4115.     return(n);
  4116. }
  4117. #endif /* IBMX25 */
  4118. #endif /* ANYX25 */
  4119.  
  4120. VOID
  4121. shoparc() {
  4122.     extern int reliable, stopbits, clsondisc;
  4123.     int i; char *s;
  4124.     long zz;
  4125.  
  4126. #ifdef NEWFTP
  4127.     if (ftpisconnected()) {
  4128.     shoftp(1);
  4129.     printf("\n");
  4130.     }
  4131. #endif /* NEWFTP */
  4132.  
  4133.     printf("Communications Parameters:\n");
  4134.  
  4135.     if (network
  4136. #ifdef IKSD
  4137.          || inserver
  4138. #endif /* IKSD */
  4139.          ) {
  4140.         printf(" Network Host: %s%s",ttname,
  4141.                (reliable == SET_ON || (reliable == SET_AUTO && !local)
  4142. #ifdef TN_COMPORT
  4143.                && !istncomport()
  4144. #endif /* TN_COMPORT */
  4145. #ifdef IKSD
  4146.                || inserver
  4147. #endif /* IKSD */
  4148.                ) ? " (reliable)" : "");
  4149. #ifdef TN_COMPORT
  4150.         if (istncomport()) {
  4151.             int modemstate;
  4152.             char * oflow, * iflow = "", * parity, * stopsize;
  4153.             int baud = tnc_get_baud();
  4154.  
  4155.             switch (tnc_get_oflow()) {
  4156.           case TNC_CTL_OFLOW_NONE:
  4157.                 oflow = "none";
  4158.                 break;
  4159.           case TNC_CTL_OFLOW_XON_XOFF:
  4160.                 oflow = "xon/xoff";
  4161.                 break;
  4162.           case TNC_CTL_OFLOW_RTS_CTS:
  4163.                 oflow = "rts/cts";
  4164.                 break;
  4165.           case TNC_CTL_OFLOW_DCD:
  4166.                 oflow = "dcd";
  4167.                 break;
  4168.           case TNC_CTL_OFLOW_DSR:
  4169.                 oflow = "dsr";
  4170.                 break;
  4171.           default:
  4172.         oflow = "(unknown)";
  4173.             }
  4174.             switch (tnc_get_iflow()) {
  4175.           case TNC_CTL_IFLOW_NONE:
  4176.                 iflow = "none";
  4177.                 break;
  4178.           case TNC_CTL_IFLOW_XON_XOFF:
  4179.                 iflow = "xon/xoff";
  4180.                 break;
  4181.           case TNC_CTL_IFLOW_RTS_CTS:
  4182.                 iflow = "rts/cts";
  4183.                 break;
  4184.           case TNC_CTL_IFLOW_DTR:
  4185.                 break;
  4186.           default:
  4187.                 iflow = oflow;
  4188.             }
  4189.             switch (tnc_get_parity()) {
  4190.           case TNC_PAR_NONE:
  4191.                 parity = "none";
  4192.                 break;
  4193.           case TNC_PAR_ODD:
  4194.                 parity = "odd";
  4195.                 break;
  4196.           case TNC_PAR_EVEN:
  4197.                 parity = "even";
  4198.                 break;
  4199.           case TNC_PAR_MARK:
  4200.                 parity = "mark";
  4201.                 break;
  4202.           case TNC_PAR_SPACE:
  4203.                 parity = "space";
  4204.                 break;
  4205.           default:
  4206.                 parity = "(unknown)";
  4207.             }
  4208.             switch (tnc_get_stopsize()) {
  4209.           case TNC_SB_1:
  4210.                 stopsize = "1";
  4211.                 break;
  4212.           case TNC_SB_1_5:
  4213.                 stopsize = "1.5";
  4214.                 break;
  4215.           case TNC_SB_2:
  4216.                 stopsize = "2";
  4217.                 break;
  4218.           default:
  4219.                 stopsize = "(unknown)";
  4220.             }
  4221.             printf("\n  Signature            : %s\n", tnc_get_signature());
  4222.             if (baud <= 0)
  4223.           printf("  Speed                : (unknown)\n");
  4224.             else
  4225.           printf("  Speed                : %d\n", baud);
  4226.             printf("  Outbound Flow Control: %s\n", oflow);
  4227.             printf("  Inbound Flow Control : %s\n", iflow);
  4228.             printf("  Parity               : %s\n", parity);
  4229.             printf("  Data Size            : %d\n", tnc_get_datasize());
  4230.             printf("  Stop Bits            : %s\n", stopsize);
  4231.             printf("  DTR Signal           : %d\n", tnc_get_dtr_state());
  4232.             printf("  RTS Signal           : %d\n", tnc_get_rts_state());
  4233.             printf("  Modem State:\n");
  4234.             modemstate = tnc_get_ms();
  4235.             if (modemstate & TNC_MS_EDGE_RING)
  4236.           printf("    Trailing Edge Ring Detector On\n");
  4237.             else
  4238.           printf("    Trailing Edge Ring Detector Off\n");
  4239.             if (modemstate & TNC_MS_CTS_SIG)
  4240.           printf("    CTS Signal On\n");
  4241.             else
  4242.           printf("    CTS Signal Off\n");
  4243.             if (modemstate & TNC_MS_DSR_SIG)
  4244.           printf("    DSR Signal On\n");
  4245.             else
  4246.           printf("    DSR Signal Off\n");
  4247.             if (modemstate & TNC_MS_RI_SIG)
  4248.           printf("    Ring Indicator On\n");
  4249.             else
  4250.           printf("    Ring Indicator Off\n");
  4251.             if (modemstate & TNC_MS_RLSD_SIG)
  4252.           printf("    RLSD (CD) Signal On\n");
  4253.             else
  4254.           printf("    RLSD (CD) Signal Off\n");
  4255.             printf("\n");
  4256.         }
  4257. #endif /* TN_COMPORT */
  4258.     } else {
  4259.  
  4260.         printf(" %s: %s%s, speed: ",
  4261. #ifdef OS2
  4262.                "Port",
  4263. #else
  4264.                "Line",
  4265. #endif /* OS2 */
  4266.                ttname,
  4267. #ifdef CK_TTYFD
  4268.                (local &&
  4269. #ifdef VMS
  4270.                 vmsttyfd() < 0
  4271. #else
  4272.                 ttyfd == -1
  4273. #endif /* VMS */
  4274.                 ) ?
  4275.                  " (closed)" :
  4276.                    (reliable == SET_ON ? " (reliable)" : "")
  4277. #else
  4278.                ""
  4279. #endif /* CK_TTYFD */
  4280.                );
  4281.         if (
  4282. #ifdef CK_TTYFD
  4283. #ifdef VMS
  4284.             vmsttyfd() < 0
  4285. #else
  4286.             ttyfd == -1
  4287. #endif /* VMS */
  4288.             ||
  4289. #endif /* CK_TTYFD */
  4290.             (zz = ttgspd()) < 0) {
  4291.             printf("unknown");
  4292.         } else {
  4293.             if (speed == 8880) printf("75/1200");
  4294.             else if (speed == 134) printf("134.5");
  4295.             else printf("%ld",zz);
  4296.         }
  4297.     }
  4298.     if (network
  4299. #ifdef IKSD
  4300.          || inserver
  4301. #endif /* IKSD */
  4302.          )
  4303.       printf("\n Mode: ");
  4304.     else
  4305.       printf(", mode: ");
  4306.     if (local) printf("local"); else printf("remote");
  4307.     if (network == 0
  4308. #ifdef IKSD
  4309.          && !inserver
  4310. #endif/* IKSD */
  4311.          ) {
  4312. #ifdef CK_TAPI
  4313.         if (tttapi && !tapipass )
  4314.           printf(", modem: %s","TAPI");
  4315.         else
  4316. #endif /* CK_TAPI */
  4317.         printf(", modem: %s",gmdmtyp());
  4318.     } else {
  4319. #ifdef NETCONN
  4320.        if (nettype == NET_TCPA) printf(", TCP/IP");
  4321.        if (nettype == NET_TCPB) printf(", TCP/IP");
  4322.        if (nettype == NET_DEC) {
  4323.            if (ttnproto == NP_LAT) printf(", DECnet LAT");
  4324.            else if ( ttnproto == NP_CTERM ) printf(", DECnet CTERM");
  4325.            else printf(", DECnet");
  4326.        }
  4327.        if (nettype == NET_SLAT) printf(", Meridian Technologies' SuperLAT");
  4328. #ifdef NETFILE
  4329.        if (nettype == NET_FILE) printf(", local file");
  4330. #endif /* NETFILE */
  4331. #ifdef NETCMD
  4332.        if (nettype == NET_CMD) printf(", pipe");
  4333. #endif /* NETCMD */
  4334. #ifdef NETPTY
  4335.        if (nettype == NET_PTY) printf(", pseudoterminal");
  4336. #endif /* NETPTY */
  4337. #ifdef NETDLL
  4338.        if (nettype == NET_DLL) printf(", dynamic load library");
  4339. #endif /* NETDLL */
  4340.        if (nettype == NET_PIPE) printf(", Named Pipes");
  4341. #ifdef SSHBUILTIN
  4342.        if (nettype == NET_SSH)
  4343.          printf(", Secure Shell protocol (SECURE)");
  4344. #endif /* SSHBUILTIN */
  4345. #ifdef ANYX25
  4346.        if (shox25(0) < 0) return;
  4347. #endif /* ANYX25 */
  4348.        if (ttnproto == NP_TELNET) {
  4349.            printf(", telnet protocol");
  4350.            if (0
  4351. #ifdef CK_ENCRYPTION
  4352.                || ck_tn_encrypting() && ck_tn_decrypting()
  4353. #endif /* CK_ENCRYPTION */
  4354. #ifdef CK_SSL
  4355.                || tls_active_flag || ssl_active_flag
  4356. #endif /* CK_SSL */
  4357.                )
  4358.              printf(" (SECURE)");
  4359.        }
  4360. #ifdef RLOGCODE
  4361.        else if (ttnproto == NP_RLOGIN || ttnproto == NP_K4LOGIN ||
  4362.                 ttnproto == NP_K5LOGIN)
  4363.          printf(", rlogin protocol");
  4364.        else if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN)
  4365.          printf(", rlogin protocol (SECURE)");
  4366. #endif /* RLOGCODE */
  4367. #ifdef CK_KERBEROS
  4368. #ifdef KRB5
  4369.        else if (ttnproto == NP_K5U2U)
  4370.          printf(", Kerberos 5 User to User protocol (SECURE)");
  4371. #endif /* KRB5 */
  4372. #endif /* CK_KERBEROS */
  4373. #endif /* NETCONN */
  4374.     }
  4375.     printf("\n");
  4376.     if (hwparity && local && !network)
  4377.       s = parnam((char)hwparity);
  4378.     else
  4379.       s = parnam((char)parity);
  4380.     printf(" Parity: %s%s",hwparity ? "hardware " : "", s);
  4381. #ifndef NOLOCAL
  4382.     if (local && !network) {
  4383.         int sb;
  4384.         char c;
  4385.         c = s[0];
  4386.         if (islower(c)) c = toupper(c);
  4387.         sb = stopbits;
  4388.         if (sb < 1) {
  4389.             sb = (speed <= 110L) ? 2 : 1;
  4390.             printf(", stop-bits: (default)");
  4391.         } else {
  4392.             printf(", stop-bits: %d",sb);
  4393.         }
  4394.         if (hwparity)
  4395.           printf(" (8%c%d)",c,sb);
  4396.         else if (parity)
  4397.           printf(" (7%c%d)",c,sb);
  4398.         else
  4399.           printf(" (8N%d)",sb);
  4400.         printf("\n D");
  4401.     } else
  4402.       printf(", d");
  4403. #endif /* NOLOCAL */
  4404.  
  4405.     printf("uplex: %s, ", duplex ? "half" : "full");
  4406.     debug(F101,"shoparp flow","",flow);
  4407.     printf("flow: %s", floname[flow]);
  4408.     printf(", handshake: ");
  4409.     if (turn) printf("%d\n",turnch); else printf("none\n");
  4410. #ifdef COMMENT
  4411.     if (local && !network) {            /* SET CARRIER-WATCH */
  4412. #endif /* COMMENT */
  4413.         if (carrier == CAR_OFF) s = "off";
  4414.         else if (carrier == CAR_ON) s = "on";
  4415.         else if (carrier == CAR_AUT) s = "auto";
  4416.         else s = "unknown";
  4417.         printf(" Carrier-watch: %s", s);
  4418.         if (carrier == CAR_ON) {
  4419.             if (cdtimo) printf(", timeout: %d sec", cdtimo);
  4420.             else printf(", timeout: none");
  4421.         }
  4422. #ifdef COMMENT
  4423.     }
  4424. #endif /* COMMENT */
  4425.     printf(", close-on-disconnect: %s\n",showoff(clsondisc));
  4426.  
  4427. #ifdef UNIX                /* UUCP lockfile, UNIX only */
  4428.     if (local) {
  4429. #ifndef NOUUCP
  4430.     if (!network && haslock && *flfnam)
  4431.       printf(" Lockfile: %s",flfnam);
  4432. #ifndef USETTYLOCK
  4433.     if (!network && haslock && lock2[0])
  4434.       printf("\n Secondary lockfile: %s",lock2);
  4435. #endif /* USETTYLOCK */
  4436. #else
  4437. #ifdef QNX
  4438.     {
  4439.         extern int qnxportlock, qnxopencount();
  4440.         if (local)
  4441.           printf(" Qnx-port-lock: %s, Open count: %d",
  4442.              showoff(qnxportlock),
  4443.              qnxopencount()
  4444.              );
  4445.         else
  4446.           printf(" Qnx-port-lock: %s", showoff(qnxportlock));
  4447.     }
  4448. #endif /* QNX */
  4449. #endif /* NOUUCP */
  4450.     printf("\n");
  4451.     } else {
  4452.     char * s, * ttglckdir();
  4453.     s = ttglckdir();
  4454.     if (!s) s = "";
  4455.     printf(" Lockfile directory: %s\n", *s ? s : "(none)");
  4456.     }
  4457. #endif /* UNIX */
  4458.     if (!local) {
  4459.     printf(" Typical port device name: %s\n",ttgtpn());
  4460.     }
  4461.     if (local) {
  4462.         int i;
  4463.         i = parity ? 7 : 8;
  4464.         if (i == 8) i = (cmask == 0177) ? 7 : 8;
  4465.         printf(" Terminal bytesize: %d,",i);
  4466.         printf(" escape character: %d (^%c)\n",escape,ctl(escape));
  4467.     }
  4468. }
  4469.  
  4470. int
  4471. shotcp(n) int n; {
  4472. #ifdef TCPSOCKET
  4473.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  4474.         printf("SET TCP parameters:\n");
  4475.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4476.         printf(" Reverse DNS lookup: %s\n", showooa(tcp_rdns));
  4477.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4478.  
  4479. #ifdef CK_DNS_SRV
  4480.         printf(" DNS Service Records lookup: %s\n", showooa(tcp_dns_srv));
  4481.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4482. #endif /* CK_DNS_SRV */
  4483.  
  4484. #ifndef NOTCPOPTS
  4485. #ifdef SOL_SOCKET
  4486. #ifdef SO_KEEPALIVE
  4487.         printf(" Keepalive: %s\n", showoff(tcp_keepalive));
  4488.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4489. #endif /* SO_KEEPALIVE */
  4490.  
  4491. #ifdef SO_LINGER
  4492.         printf(" Linger: %s", tcp_linger ? "on, " : "off\n" );
  4493.         if (tcp_linger) {
  4494.             if (tcp_linger_tmo)
  4495.               printf("%d x 10 milliseconds\n",tcp_linger_tmo);
  4496.             else
  4497.               printf("no timeout\n");
  4498.         }
  4499.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4500. #endif /* SO_LINGER */
  4501.  
  4502. #ifdef SO_DONTROUTE
  4503.         printf(" DontRoute: %s\n", tcp_dontroute ? "on" : "off" );
  4504.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4505. #endif /* SO_DONTROUTE */
  4506.  
  4507. #ifdef TCP_NODELAY
  4508.         printf(" Nodelay: %s\n", showoff(tcp_nodelay));
  4509.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4510. #endif /* TCP_NODELAY */
  4511.  
  4512. #ifdef SO_SNDBUF
  4513.         if (tcp_sendbuf <= 0)
  4514.           printf(" Send buffer: (default size)\n");
  4515.         else
  4516.           printf(" Send buffer: %d bytes\n", tcp_sendbuf);
  4517.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4518. #endif /* SO_SNDBUF */
  4519. #ifdef SO_RCVBUF
  4520.         if (tcp_recvbuf <= 0)
  4521.           printf(" Receive buffer: (default size)\n");
  4522.         else
  4523.           printf(" Receive buffer: %d bytes\n", tcp_recvbuf);
  4524.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4525. #endif /* SO_RCVBUF */
  4526. #endif /* SOL_SOCKET */
  4527. #endif /* NOTCPOPTS */
  4528.         printf(" address: %s\n",tcp_address ? tcp_address : "(none)");
  4529.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4530. #ifndef NOHTTP
  4531.         printf(" http-proxy: %s\n",tcp_http_proxy ? tcp_http_proxy : "(none)");
  4532.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4533. #endif /* NOHTTP */
  4534. #ifdef NT
  4535. #ifdef CK_SOCKS
  4536.         printf(" socks-server: %s\n",tcp_socks_svr ? tcp_socks_svr : "(none)");
  4537.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4538. #ifdef CK_SOCKS_NS
  4539.         printf(" socks-name-server: %s\n",
  4540.            tcp_socks_ns ? tcp_socks_ns : "(none)");
  4541.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4542. #endif /* CK_SOCKS_NS */
  4543. #endif /* CK_SOCKS */
  4544. #endif /* NT */
  4545.     }
  4546. #endif /* TCPSOCKET */
  4547.     return(n);
  4548. }
  4549.  
  4550. #ifdef TNCODE
  4551.  
  4552. #ifdef CK_AUTHENTICATION
  4553. _PROTOTYP(int ck_tn_authenticated, (VOID));
  4554. extern int forward_flag, forwarded_tickets;
  4555. #endif /* CK_AUTHENTICATION */
  4556. #ifdef CK_ENCRYPTION
  4557. _PROTOTYP(int ck_tn_encrypting, (VOID));
  4558. _PROTOTYP(int ck_tn_decrypting, (VOID));
  4559. #endif /* CK_ENCRYPTION */
  4560.  
  4561. int
  4562. shotopt(n) int n; {
  4563.     int opt;
  4564.  
  4565.     printf("%-21s %12s %12s %12s %12s\n\n",
  4566.            "Telnet Option","Me (client)","U (client)",
  4567.            "Me (server)","U (server)");
  4568.     n += 2;
  4569.     if (n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4570.  
  4571.     for ( opt = TELOPT_FIRST; opt <= TELOPT_LAST; opt++) {
  4572.         switch (opt) {
  4573.           case TELOPT_AUTHENTICATION:
  4574.           case TELOPT_ENCRYPTION:
  4575.           case TELOPT_TTYPE:
  4576.           case TELOPT_NAWS:
  4577.           case TELOPT_BINARY:
  4578.           case TELOPT_NEWENVIRON:
  4579.           case TELOPT_SNDLOC:
  4580.           case TELOPT_XDISPLOC:
  4581.           case TELOPT_SGA:
  4582.           case TELOPT_ECHO:
  4583.           case TELOPT_KERMIT:
  4584.           case TELOPT_START_TLS:
  4585.           case TELOPT_FORWARD_X:
  4586.           case TELOPT_COMPORT:
  4587.             break;
  4588.           default:
  4589.             continue;
  4590.         }
  4591.         printf("%03d %-17s ",
  4592.                opt, TELOPT(opt)
  4593.                );
  4594.         printf("%12s %12s ",
  4595.                TELOPT_MODE(TELOPT_DEF_C_ME_MODE(opt)),
  4596.                TELOPT_MODE(TELOPT_DEF_C_U_MODE(opt))
  4597.                );
  4598.         printf("%12s %12s\n",
  4599.                TELOPT_MODE(TELOPT_DEF_S_ME_MODE(opt)),
  4600.                TELOPT_MODE(TELOPT_DEF_S_U_MODE(opt))
  4601.                );
  4602.  
  4603.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4604.         if (sstelnet)
  4605.           printf("%21s %12s %12s %12s %12s\n",
  4606.                  "",
  4607.                  "",
  4608.                  "",
  4609.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4610.                  (TELOPT_U(opt)?"DO":"DONT")
  4611.                  );
  4612.         else
  4613.           printf("%21s %12s %12s %12s %12s\n",
  4614.                  "",
  4615.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4616.                  (TELOPT_U(opt)?"DO":"DONT"),
  4617.                  "",
  4618.                  ""
  4619.                  );
  4620.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4621.     }
  4622.     return(n);
  4623. }
  4624.  
  4625. int
  4626. shotel(n) int n; {
  4627.     extern int tn_duplex;
  4628. #ifdef CK_ENVIRONMENT
  4629.     extern int tn_env_flg;
  4630.     extern char tn_env_acct[];
  4631.     extern char tn_env_job[];
  4632.     extern char tn_env_prnt[];
  4633.     extern char tn_env_sys[];
  4634.     extern char * tn_env_uservar[8][2];
  4635.     int x;
  4636. #endif /* CK_ENVIRONMENT */
  4637. #ifdef CK_SNDLOC
  4638.     extern char * tn_loc;
  4639. #endif /* CK_SNDLOC */
  4640.     printf("SET TELNET parameters:\n echo: %s\n NVT newline-mode: ",
  4641.            tn_duplex ? "local" : "remote");
  4642.     switch (tn_nlm) {
  4643.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4644.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4645.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4646.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4647.     }
  4648.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4649. #ifdef CK_AUTHENTICATION
  4650.     {
  4651.         int type = ck_tn_authenticated();
  4652.         printf(" authentication: ");
  4653.         switch (sstelnet ?
  4654.                 TELOPT_U_MODE(TELOPT_AUTHENTICATION) :
  4655.                  TELOPT_ME_MODE(TELOPT_AUTHENTICATION)
  4656.                 ) {
  4657.           case TN_NG_AC: printf( "accepted " ); break;
  4658.           case TN_NG_RF: printf( "refused  " ); break;
  4659.           case TN_NG_RQ: printf( "requested"); break;
  4660.           case TN_NG_MU: printf( "required "); break;
  4661.         }
  4662.  
  4663. #ifdef CK_SSL
  4664.         if ((ssl_active_flag || tls_active_flag) &&
  4665.              ck_tn_auth_valid() == AUTH_VALID &&
  4666.              (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  4667.                type == AUTHTYPE_NULL ||
  4668.                type == AUTHTYPE_AUTO))
  4669.             printf("   in use: X.509 certificate\n");
  4670.         else
  4671. #endif /* CK_SSL */
  4672.       printf("   in use: %s\n",AUTHTYPE_NAME(type));
  4673.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4674.         if (forward_flag)
  4675.           printf("  credentials forwarding requested %s\n",
  4676.                  forwarded_tickets ? "and completed" :
  4677.                  "but not completed");
  4678.         else
  4679.           printf("  credentials forwarding disabled\n");
  4680.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4681.     }
  4682. #endif /* CK_AUTHENTICATION */
  4683. #ifdef CK_ENCRYPTION
  4684.     {
  4685.         int i,x;
  4686.         int e_type = ck_tn_encrypting();
  4687.         int d_type = ck_tn_decrypting();
  4688.         char * e_str = NULL, * d_str = NULL;
  4689.         static struct keytab * tnetbl = NULL;
  4690.         static int ntnetbl = 0;
  4691.  
  4692.         x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  4693.  
  4694.         for (i = 0; i < ntnetbl; i++) {
  4695.             if (e_type == tnetbl[i].kwval)
  4696.               e_str = tnetbl[i].kwd;
  4697.             if (d_type == tnetbl[i].kwval)
  4698.               d_str = tnetbl[i].kwd;
  4699.         }
  4700.         printf(" encryption: ");
  4701.         switch (TELOPT_ME_MODE(TELOPT_ENCRYPTION)) {
  4702.           /* This should be changed to report both ME and U modes */
  4703.           case TN_NG_AC: printf( "accepted " ); break;
  4704.           case TN_NG_RF: printf( "refused  " ); break;
  4705.           case TN_NG_RQ: printf( "requested"); break;
  4706.           case TN_NG_MU: printf( "required "); break;
  4707.         }
  4708.         printf("       in use: ");
  4709.         switch ((e_type ? 1 : 0) | (d_type ? 2 : 0)) {
  4710.           case 0:
  4711.             printf("plain text in both directions");
  4712.             break;
  4713.           case 1:
  4714.             printf("%s output, plain text input",e_str);
  4715.             break;
  4716.           case 2:
  4717.             printf("plain text output, %s input",d_str);
  4718.             break;
  4719.           case 3:
  4720.             printf("%s output, %s input",e_str,d_str);
  4721.             break;
  4722.         }
  4723.         printf("\n");
  4724.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4725.     }
  4726. #endif /* CK_ENCRYPTION */
  4727. #ifdef IKS_OPTION
  4728.     printf(" kermit: ");
  4729.     switch (TELOPT_U_MODE(TELOPT_KERMIT)) {
  4730.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4731.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4732.       case TN_NG_RQ: printf( "u, requested; "); break;
  4733.       case TN_NG_MU: printf( "u, required;  "); break;
  4734.     }
  4735.     switch (TELOPT_ME_MODE(TELOPT_KERMIT)) {
  4736.       case TN_NG_AC: printf( "me, accepted;  " ); break;
  4737.       case TN_NG_RF: printf( "me, refused;   " ); break;
  4738.       case TN_NG_RQ: printf( "me, requested; "); break;
  4739.       case TN_NG_MU: printf( "me, required;  "); break;
  4740.     }
  4741.     if (TELOPT_U(TELOPT_KERMIT))
  4742.       printf(" u, %s",
  4743.              TELOPT_SB(TELOPT_KERMIT).kermit.u_start ?
  4744.              "started" :
  4745.              "stopped"
  4746.              );
  4747.     else
  4748.       printf(" u, n/a");
  4749.     if (TELOPT_ME(TELOPT_KERMIT))
  4750.       printf(" me, %s;",
  4751.              TELOPT_SB(TELOPT_KERMIT).kermit.me_start ?
  4752.              "started" :
  4753.              "stopped"
  4754.              );
  4755.     else
  4756.       printf(" me, n/a;");
  4757.     printf("\n");
  4758.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4759. #endif /* IKS_OPTION */
  4760.     printf(" BINARY newline-mode: ");
  4761.     switch (tn_b_nlm) {
  4762.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4763.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4764.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4765.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4766.     }
  4767.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4768.     printf(" binary-mode: ");
  4769.     switch (TELOPT_U_MODE(TELOPT_BINARY)) {
  4770.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4771.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4772.       case TN_NG_RQ: printf( "u, requested; "); break;
  4773.       case TN_NG_MU: printf( "u, required;  "); break;
  4774.     }
  4775.     switch (TELOPT_ME_MODE(TELOPT_BINARY)) {
  4776.       case TN_NG_AC: printf( "me, accepted; " ); break ;
  4777.       case TN_NG_RF: printf( "me, refused; " ); break;
  4778.       case TN_NG_RQ: printf( "me, requested; "); break;
  4779.       case TN_NG_MU: printf( "me, required;  "); break;
  4780.     }
  4781.     printf("u, %s; me, %s\n",
  4782.            TELOPT_U(TELOPT_BINARY) ? "BINARY" : "NVT",
  4783.            TELOPT_ME(TELOPT_BINARY) ? "BINARY" : "NVT"
  4784.            );
  4785.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4786.     printf(" binary-transfer-mode: %s\n",showoff(tn_b_xfer));
  4787.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4788.     printf(" bug binary-me-means-u-too: %s\n",showoff(tn_b_meu));
  4789.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4790.     printf(" bug binary-u-means-me-too: %s\n",showoff(tn_b_ume));
  4791.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4792.     printf(" bug sb-implies-will-do: %s\n",showoff(tn_sb_bug));
  4793.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4794.     printf(" terminal-type: ");
  4795.     if (tn_term) {
  4796.         printf("%s\n",tn_term);
  4797.     } else {
  4798.         char *p;
  4799. #ifdef OS2
  4800.         p = (tt_type >= 0 && tt_type <= max_tt) ?
  4801.           tt_info[tt_type].x_name :
  4802.             "UNKNOWN";
  4803. #else
  4804.         p = getenv("TERM");
  4805. #endif /* OS2 */
  4806.         if (p)
  4807.           printf("none (%s will be used)\n",p);
  4808.         else printf("none\n");
  4809.     }
  4810.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4811. #ifdef CK_ENVIRONMENT
  4812.     printf(" environment: %s\n", showoff(tn_env_flg));
  4813.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4814.     printf("   ACCOUNT: %s\n",tn_env_acct);
  4815.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4816.     printf("   DISPLAY: %s\n",(char *)tn_get_display() ?
  4817.             (char *)tn_get_display() : "");
  4818.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4819.     printf("   JOB    : %s\n",tn_env_job);
  4820.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4821.     printf("   PRINTER: %s\n",tn_env_prnt);
  4822.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4823. #ifndef NOSPL
  4824.     printf("   USER   : %s\n",uidbuf);
  4825.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4826. #endif /* NOSPL */
  4827.     printf("   SYSTEM : %s\n",tn_env_sys);
  4828.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4829.     for (x = 0; x < 8; x++) {
  4830.         if (tn_env_uservar[x][0] && tn_env_uservar[x][1]) {
  4831.             printf("   %-7s: %s\n",tn_env_uservar[x][0],
  4832.            tn_env_uservar[x][1]);
  4833.             if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4834.         }
  4835.     }
  4836. #endif /* CK_ENVIRONMENT */
  4837. #ifdef CK_SNDLOC
  4838.     printf("  LOCATION: %s\n", tn_loc ? tn_loc : "");
  4839.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4840. #endif /* CK_SNDLOC */
  4841. #ifdef CK_FORWARD_X
  4842.     printf(" .Xauthority-file: %s\n", (char *)XauFileName() ?
  4843.             (char *)XauFileName() : "(none)");
  4844.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4845. #endif /* CK_FORWARD_X */
  4846.     return(n);
  4847. }
  4848. #endif /* TNCODE */
  4849.  
  4850. #ifdef CK_NETBIOS
  4851. static int
  4852. shonb(n) int n; {
  4853.     printf("NETBIOS parameters:\n");
  4854.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4855.     printf(" API       : %s\n",
  4856.            NetbeuiAPI ?
  4857.            "NETAPI.DLL - IBM Extended Services or Novell Netware Requester"
  4858.            : "ACSNETB.DLL - IBM Network Transport Services/2" ) ;
  4859.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4860.     printf(" Local Name: [%s]\n", NetBiosName);
  4861.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4862.     printf(" Adapter   : %d\n", NetBiosAdapter);
  4863.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4864.     if (NetBiosLSN > 0xFF) {
  4865.         printf(" Session   : %d\n", NetBiosLSN);
  4866.     } else {
  4867.         printf(" Session   : none active\n");
  4868.     }
  4869.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4870.     return(n);
  4871. }
  4872. #endif /* CK_NETBIOS */
  4873.  
  4874. #ifndef NONET
  4875. int
  4876. shonet() {
  4877.  
  4878. #ifndef NETCONN
  4879.     printf("\nNo networks are supported in this version of C-Kermit\n");
  4880.  
  4881. #else
  4882. #ifdef NOLOCAL
  4883.     printf("\nNo networks are supported in this version of C-Kermit\n");
  4884.  
  4885. #else /* rest of this routine */
  4886.  
  4887.     int i, n = 4;
  4888.  
  4889. #ifndef NODIAL
  4890.     if (nnetdir <= 1) {
  4891.         printf("\nNetwork directory: %s\n",netdir[0] ? netdir[0] : "(none)");
  4892.         n++;
  4893.     } else {
  4894.         int i;
  4895.         printf("\nNetwork directories:\n");
  4896.         for (i = 0; i < nnetdir; i++) {
  4897.             printf("%2d. %s\n",i,netdir[i]);
  4898.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4899.         }
  4900.     }
  4901. #endif /* NODIAL */
  4902.  
  4903. #ifdef SSHCMD
  4904.     {
  4905.     extern char * sshcmd;
  4906.     printf("SSH COMMAND: %s\n",sshcmd ? sshcmd : "ssh -e none");
  4907.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4908.     }
  4909. #endif /* SSHCMD */
  4910.  
  4911. #ifdef OS2
  4912.     printf("\nNetwork availability:\n");
  4913. #else
  4914.     printf("\nSupported networks:\n");
  4915. #endif /* OS2 */
  4916.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4917.  
  4918. #ifdef VMS
  4919.  
  4920. #ifdef TCPWARE
  4921.     printf(" Process Software Corporation TCPware for OpenVMS");
  4922. #else
  4923. #ifdef MULTINET
  4924.     printf(" TGV MultiNet TCP/IP");
  4925. #else
  4926. #ifdef WINTCP
  4927.     printf(" WOLLONGONG WIN/TCP");
  4928. #else
  4929. #ifdef DEC_TCPIP
  4930.     {
  4931.         static $DESCRIPTOR(tcp_desc,"_TCP0:");
  4932.         int status;
  4933.         long devclass;
  4934.         static int itmcod = DVI$_DEVCLASS;
  4935.  
  4936. #ifdef COMMENT
  4937.         status = LIB$GETDVI(&itmcod, 0, &tcp_desc, &devclass);
  4938. #else
  4939.         /* Martin Zinser 9/96 */
  4940.         status = lib$getdvi(&itmcod, 0, &tcp_desc, &devclass);
  4941. #endif /* COMMENT */
  4942.         if ((status & 1) && (devclass == DC$_SCOM))
  4943.           printf(" Process Software Corporation TCPware for OpenVMS");
  4944.         else
  4945. #ifdef UCX50
  4946.           printf(" DEC TCP/IP Services for (Open)VMS 5.0");
  4947. #else
  4948.           printf(" DEC TCP/IP Services for (Open)VMS");
  4949. #endif /* UCX50 */
  4950.     }
  4951. #else
  4952. #ifdef CMU_TCPIP
  4953.     printf(" CMU-OpenVMS/IP");
  4954. #else
  4955.     printf(" None");
  4956. #endif /* CMU_TCPIP */
  4957. #endif /* DEC_TCPIP */
  4958. #endif /* WINTCP */
  4959. #endif /* MULTINET */
  4960. #endif /* TCPWARE */
  4961.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4962. #ifdef TNCODE
  4963.     printf(", TELNET protocol\n\n");
  4964.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4965.     n = shotel(n);
  4966.     if (n < 0) return(0);
  4967.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4968. #endif /* TNCODE */
  4969.     printf("\n");
  4970.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4971.     printf("\n");
  4972.     n = shotcp(++n);
  4973.     if (n < 0) return(0);
  4974. #else /* Not VMS */
  4975.  
  4976. #ifdef SUNX25
  4977.     printf(" SunLink X.25\n");
  4978.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4979. #endif /* SUNX25 */
  4980.  
  4981. #ifdef STRATUSX25
  4982.     printf(" Stratus VOS X.25\n");
  4983.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4984. #endif /* STRATUSX25 */
  4985.  
  4986. #ifdef IBMX25
  4987.     printf(" IBM AIX X.25\n");
  4988.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4989. #endif /* IBMX25 */
  4990.  
  4991. #ifdef HPX25
  4992.     printf(" HP-UX X.25\n");
  4993.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4994. #endif /* HPX25 */
  4995.  
  4996. #ifdef DECNET
  4997. #ifdef OS2
  4998. #ifdef NT
  4999.     if (dnet_avail)
  5000.       printf(" DECnet, LAT and CTERM protocols\n");
  5001.     else
  5002.       printf(" DECnet, LAT and CTERM protocols - not available\n");
  5003.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5004. #else /* NT */
  5005.     if (dnet_avail)
  5006.       printf(" DECnet, LAT protocol\n");
  5007.     else
  5008.       printf(" DECnet, LAT protocol - not available\n");
  5009.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5010. #endif /* NT */
  5011. #else
  5012.     printf(" DECnet\n");
  5013.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5014. #endif /* OS2 */
  5015. #endif /* DECNET */
  5016.  
  5017. #ifdef NPIPE
  5018.     printf(" Named Pipes\n");
  5019.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5020. #endif /* NPIPE */
  5021.  
  5022. #ifdef CK_NETBIOS
  5023.     if (netbiosAvail)
  5024.       printf(" NETBIOS\n");
  5025.     else
  5026.       printf(" NETBIOS - not available\n");
  5027.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5028. #endif /* CK_NETBIOS */
  5029.  
  5030. #ifdef SUPERLAT
  5031.     if (slat_avail)
  5032.       printf(" SuperLAT\n");
  5033.     else
  5034.       printf(" SuperLAT - not available\n") ;
  5035.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5036. #endif /* SUPERLAT */
  5037.  
  5038. #ifdef TCPSOCKET
  5039.     if (
  5040. #ifdef OS2
  5041.         tcp_avail
  5042. #else
  5043.         1
  5044. #endif /* OS2 */
  5045.         ) {
  5046.         char ipaddr[16];
  5047.  
  5048.         if (getlocalipaddrs(ipaddr,16,0) < 0) {
  5049. #ifdef OS2ONLY
  5050.             printf(" TCP/IP via %s\n", tcpname);
  5051. #else
  5052.             printf(" TCP/IP\n");
  5053. #endif /* OS2ONLY */
  5054.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5055.         } else {
  5056.             int i = 1;
  5057. #ifdef OS2ONLY
  5058.           printf(" TCP/IP [%16s] via %s\n", ipaddr, tcpname);
  5059. #else
  5060.           printf(" TCP/IP [%16s]\n",ipaddr);
  5061. #endif /* OS2ONLY */
  5062.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5063.  
  5064.             while (getlocalipaddrs(ipaddr,16,i++) >= 0) {
  5065.                 printf("        [%16s]\n",ipaddr);
  5066.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5067.             }
  5068.         }
  5069.         if (nettype == NET_TCPB) {
  5070.             printf("\n");
  5071.             n = shotcp(++n);
  5072.             if (n < 0) return(0);
  5073. #ifdef TNCODE
  5074.             printf("\n");
  5075.             n = shotel(++n);
  5076.             if (n < 0) return(0);
  5077. #endif /* TNCODE */
  5078.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5079.         }
  5080. #ifdef OS2
  5081.     } else {
  5082.         printf(" TCP/IP - not available%s\n",tcpname[0] ? tcpname : "" );
  5083.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5084. #endif /* OS2 */
  5085.     }
  5086. #endif /* TCPSOCKET */
  5087.  
  5088. #ifdef CK_NETBIOS
  5089.     if (netbiosAvail && nettype == NET_BIOS) {
  5090.        printf("\n") ;
  5091.        if ((n = shonb(++n)) < 0) return(0);
  5092.        if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5093.     }
  5094. #endif /* CK_NETBIOS */
  5095.  
  5096. #endif /* VMS */
  5097.  
  5098.     printf("\nActive network connection:\n");
  5099.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5100.  
  5101.     if (network) {
  5102.         printf(" Host: %s",ttname);
  5103.         if ((nettype == NET_TCPA || nettype == NET_TCPB) && *ipaddr)
  5104.           printf(" [%s]",ipaddr);
  5105.     } else
  5106.       printf(" Host: none");
  5107.     printf(", via: ");
  5108.     if (nettype == NET_TCPA || nettype == NET_TCPB)
  5109.       printf("tcp/ip\n");
  5110.     else if (nettype == NET_SX25)
  5111.       printf("SunLink X.25\n");
  5112.     else if (nettype == NET_VX25)
  5113.       printf("Stratus VOS X.25\n");
  5114.     else if (nettype == NET_IX25)
  5115.       printf("IBM AIX X.25\n");
  5116.     else if (nettype == NET_HX25)
  5117.       printf("HP-UX X.25\n");
  5118.     else if (nettype == NET_DEC) {
  5119.         if ( ttnproto == NP_LAT )
  5120.           printf("DECnet LAT\n");
  5121.         else if ( ttnproto == NP_CTERM )
  5122.           printf("DECnet CTERM\n");
  5123.         else
  5124.           printf("DECnet\n");
  5125.     } else if (nettype == NET_PIPE)
  5126.       printf("Named Pipes\n");
  5127.     else if (nettype == NET_BIOS)
  5128.       printf("NetBIOS\n");
  5129.     else if (nettype == NET_SLAT)
  5130.       printf("SuperLAT\n");
  5131.  
  5132. #ifdef NETFILE
  5133.     else if ( nettype == NET_FILE )
  5134.       printf("local file\n");
  5135. #endif /* NETFILE */
  5136. #ifdef NETCMD
  5137.     else if ( nettype == NET_CMD )
  5138.       printf("pipe\n");
  5139. #endif /* NETCMD */
  5140. #ifdef NETPTY
  5141.     else if ( nettype == NET_PTY )
  5142.         printf("pseudoterminal\n");
  5143. #endif /* NETPTY */
  5144. #ifdef NETDLL
  5145.     else if ( nettype == NET_DLL )
  5146.       printf("dynamic link library\n");
  5147. #endif /* NETDLL */
  5148.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5149.  
  5150. #ifdef ANYX25
  5151.     if ((nettype == NET_SX25) ||
  5152.         (nettype == NET_VX25) ||
  5153.         (nettype == NET_IX25))
  5154.       if ((n = shox25(n)) < 0) return(0);
  5155. #endif /* ANYX25 */
  5156.  
  5157. #ifdef SSHBUILTIN
  5158.     if (nettype == NET_SSH) {
  5159.         printf("Secure Shell protocol\n");
  5160.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5161.     }
  5162. #endif /* SSHBUILTIN */
  5163.  
  5164.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  5165. #ifdef RLOGCODE
  5166.         if (ttnproto == NP_RLOGIN) {
  5167.             printf(" LOGIN (rlogin) protocol\n");
  5168.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5169.         }
  5170. #ifdef CK_KERBEROS
  5171.         else if (ttnproto == NP_K4LOGIN) {
  5172.             printf(" Kerberos 4 LOGIN (klogin) protocol\n");
  5173.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5174.         }
  5175.         else if (ttnproto == NP_EK4LOGIN) {
  5176.             printf(" Encrypted Kerberos 4 LOGIN (eklogin) protocol\n");
  5177.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5178.         }
  5179.         else if (ttnproto == NP_K5LOGIN) {
  5180.             printf(" Kerberos 5 LOGIN (klogin) protocol\n");
  5181.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5182.         }
  5183.         else if (ttnproto == NP_EK5LOGIN) {
  5184.             printf(" Encrypted Kerberos 5 LOGIN (eklogin) protocol\n");
  5185.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5186.         }
  5187. #endif /* CK_KERBEROS */
  5188. #endif /* RLOGCODE */
  5189. #ifdef CK_KERBEROS
  5190.         if (ttnproto == NP_K5U2U) {
  5191.             printf(" Kerberos 5 User to User protocol\n");
  5192.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5193.         }
  5194. #endif /* CK_KERBEROS */
  5195.  
  5196. #ifdef TNCODE
  5197.         if (ttnproto == NP_TELNET) {
  5198.             printf(" TELNET protocol\n");
  5199.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5200.             printf(" Echoing is currently %s\n",duplex ? "local" : "remote");
  5201.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5202.         }
  5203. #endif /* TNCODE */
  5204.         if (ttnproto == NP_TCPRAW) {
  5205.             printf(" Raw TCP socket\n");
  5206.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5207.         }
  5208.     }
  5209.     printf("\n");
  5210. #endif /* NOLOCAL */
  5211. #endif /* NETCONN */
  5212.     return(0);
  5213. }
  5214. #endif /* NONET */
  5215.  
  5216. #ifndef NODIAL
  5217. VOID
  5218. shodial() {
  5219.     if (mdmtyp >= 0 || local != 0) doshodial();
  5220. }
  5221.  
  5222. VOID
  5223. shods(s) char *s; {                     /* Show a dial-related string */
  5224.     char c;
  5225.     if (s == NULL || !(*s)) {           /* Empty? */
  5226.         printf("(none)\n");
  5227.     } else {                            /* Not empty. */
  5228.         while ((c = *s++))        /* Can contain controls */
  5229.           if (c == '\\')                /* a backslash */
  5230.             printf("\\\\");
  5231.           else if (c > 31 && c < 127) {
  5232.               putchar(c);
  5233.           } else
  5234.             printf("\\{%d}",c);
  5235.         printf("\n");
  5236.     }
  5237. }
  5238.  
  5239. int
  5240. doshodial() {
  5241.  
  5242.     int i, n = 2;
  5243.  
  5244.     printf(" Dial status:  %d", dialsta);
  5245.  
  5246. #ifdef BIGBUFOK
  5247.     if (dialsta > 90)
  5248.       printf(" = Unknown error");
  5249.     else if (dialsta < 0)
  5250.       printf(" = (none)");
  5251.     else if (dialsta < 35 && dialmsg[dialsta])
  5252.       printf(" = %s", dialmsg[dialsta]);
  5253. #endif /* BIGBUFOK */
  5254.     n++;
  5255.     if (ndialdir <= 1) {
  5256.         printf("\n Dial directory: %s\n",dialdir[0] ? dialdir[0] : "(none)");
  5257.     } else {
  5258.         int i;
  5259.         printf("\n Dial directories:\n");
  5260.         for (i = 0; i < ndialdir; i++)
  5261.           printf("%2d. %s\n",i+1,dialdir[i]);
  5262.         n += ndialdir;
  5263.     }
  5264.     printf(" Dial method:  ");
  5265.     if      (dialmauto)         printf("auto   ");
  5266.     else if (dialmth == XYDM_D) printf("default");
  5267.     else if (dialmth == XYDM_P) printf("pulse  ");
  5268.     else if (dialmth == XYDM_T) printf("tone   ");
  5269.     printf("         Dial sort: %s\n",dialsrt ? "on" : "off");
  5270.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5271.     printf(" Dial hangup:  %s             Dial display: %s\n",
  5272.            dialhng ? "on " : "off", dialdpy ? "on" : "off");
  5273.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5274.     if (dialrtr > 0) {
  5275.         printf(" Dial retries: %-6d          Dial interval: %d\n",
  5276.                dialrtr, dialint);
  5277.     } else {
  5278.         printf(" Dial retries: (auto)          Dial interval: %d\n", dialint);
  5279.     }
  5280.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5281.     printf(" Dial timeout: ");
  5282. #ifdef CK_TAPI
  5283.     if (tttapi && !tapipass)
  5284.         printf("(tapi)");
  5285.     else
  5286. #endif /* CK_TAPI */
  5287.     if (dialtmo > 0)
  5288.       printf("%4d sec", dialtmo);
  5289.     else
  5290.       printf("0 (auto)");
  5291.     printf("        Redial number: %s\n",dialnum ? dialnum : "(none)");
  5292.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5293.     printf(" Dial confirmation: %s        Dial convert-directory: %s\n",
  5294.            dialcnf ? "on " : "off",
  5295.            dialcvt ? ((dialcvt == 1) ? "on" : "ask") : "off");
  5296.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5297.     printf(" Dial ignore-dialtone: %s", dialidt ? "on " : "off");
  5298.     printf("     Dial pacing: %d\n",dialpace);
  5299.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5300.     printf(
  5301. " Dial prefix:                  %s\n", dialnpr ? dialnpr : "(none)");
  5302.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5303.     printf(
  5304. " Dial suffix:                  %s\n", dialsfx ? dialsfx : "(none)");
  5305.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5306.     printf(
  5307. " Dial country-code:            %-12s", diallcc ? diallcc : "(none)");
  5308.     printf("Dial connect:  %s", dialcon ? ((dialcon == 1) ? "on" : "auto")
  5309.            : "off");
  5310.     if (dialcon != CAR_OFF)
  5311.       printf(" %s", dialcq ? "quiet" : "verbose");
  5312.     printf(
  5313. "\n Dial area-code:               %-12s", diallac ? diallac : "(none)");
  5314.     n++;
  5315.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5316.     printf("Dial restrict: ");
  5317.     if (dialrstr == 5) printf("international\n");
  5318.     else if (dialrstr == 4) printf("long-distance\n");
  5319.     else if (dialrstr == 2) printf("local\n");
  5320.     else if (dialrstr == 6) printf("none\n");
  5321.     else printf("?\n");
  5322.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5323.     printf(" Dial lc-area-codes:           ");
  5324.     if (nlocalac == 0)
  5325.       printf("(none)");
  5326.     else
  5327.       for (i = 0; i < nlocalac; i++)
  5328.         printf("%s ", diallcac[i]);
  5329.     printf(
  5330. "\n Dial lc-prefix:               %s\n", diallcp ? diallcp : "(none)");
  5331.     n++;
  5332.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5333.     printf(
  5334. " Dial lc-suffix:               %s\n", diallcs ? diallcs : "(none)");
  5335.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5336.     printf(
  5337. " Dial ld-prefix:               %s\n", dialldp ? dialldp : "(none)");
  5338.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5339.     printf(
  5340. " Dial ld-suffix:               %s\n", diallds ? diallds : "(none)");
  5341.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5342.     printf(
  5343. " Dial force-long-distance      %s\n", showoff(dialfld));
  5344.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5345.     printf(
  5346. " Dial intl-prefix:             %s\n", dialixp ? dialixp : "(none)");
  5347.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5348.     printf(
  5349. " Dial intl-suffix:             %s\n", dialixs ? dialixs : "(none)");
  5350.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5351.     printf(
  5352. " Dial toll-free-area-code:     ");
  5353.     if (ntollfree == 0)
  5354.       printf("(none)");
  5355.     else
  5356.       for (i = 0; i < ntollfree; i++)
  5357.         printf("%s ", dialtfc[i]);
  5358.     printf("\n");
  5359.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5360.  
  5361.     printf(
  5362. " Dial pulse-countries:         ");
  5363.     if (ndialpucc == 0)
  5364.       printf("(none)");
  5365.     else
  5366.       for (i = 0; i < ndialpucc; i++)
  5367.         printf("%s ", dialpucc[i]);
  5368.     printf("\n");
  5369.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5370.  
  5371.     printf(
  5372. " Dial tone-countries:          ");
  5373.     if (ndialtocc == 0)
  5374.       printf("(none)");
  5375.     else
  5376.       for (i = 0; i < ndialtocc; i++)
  5377.         printf("%s ", dialtocc[i]);
  5378.     printf("\n");
  5379.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5380.  
  5381.     printf(
  5382. " Dial toll-free-prefix:        %s\n",
  5383.            dialtfp ? dialtfp :
  5384.           (dialldp ? dialldp : "(none)")
  5385.           );
  5386.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5387.     printf(
  5388. #ifdef COMMENT
  5389. " Dial pbx-exchange:            %s\n", dialpxx ? dialpxx : "(none)");
  5390. #else
  5391. " Dial pbx-exchange:            ");
  5392.     if (ndialpxx == 0)
  5393.       printf("(none)");
  5394.     else
  5395.       for (i = 0; i < ndialpxx; i++)
  5396.         printf("%s ", dialpxx[i]);
  5397.     printf("\n");
  5398. #endif /* COMMENT */
  5399.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5400.     printf(
  5401. " Dial pbx-inside-prefix:       %s\n", dialpxi ? dialpxi : "(none)");
  5402.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5403.     printf(
  5404. " Dial pbx-outside-prefix:      %s\n", dialpxo ? dialpxo : "(none)");
  5405.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5406.     printf(
  5407. " Dial macro:                   %s\n", dialmac ? dialmac : "(none)");
  5408.     return(0);
  5409. }
  5410. #endif /* NODIAL */
  5411. #endif /* NOLOCAL */
  5412.  
  5413. /*  Show File Parameters */
  5414.  
  5415. static char *
  5416. pathval(x) int x; {
  5417.     switch (x) {
  5418.       case PATH_OFF:  return("off");
  5419.       case PATH_ABS:  return("absolute");
  5420.       case PATH_REL:  return("relative");
  5421.       case PATH_AUTO: return("auto");
  5422.       default: return("unknown");
  5423.     }
  5424. }
  5425.  
  5426. VOID
  5427. shofil() {
  5428.     char *s; int i = 0, n = 1;
  5429.     extern char * ifdnam[];
  5430. #ifdef UNIX
  5431.     extern int wildxpand;
  5432. #endif /* UNIX */
  5433.     extern char * snd_move, * snd_rename, * rcv_move, * rcv_rename;
  5434. #ifdef PATTERNS
  5435.     extern int patterns;
  5436. #endif /* PATTERNS */
  5437.     extern char * rfspec, * sfspec;
  5438. #ifdef UNIX
  5439.     extern int zobufsize, zofbuffer, zofblock;
  5440. #endif /* UNIX */
  5441. #ifdef CK_CTRLZ
  5442.     extern int eofmethod;
  5443. #endif /* CK_CTRLZ */
  5444.  
  5445.     printf("\n");
  5446.  
  5447. #ifdef VMS
  5448.     printf(" File record-Length:      %5d\n",frecl);
  5449.     n++;
  5450. #endif /* VMS */
  5451.  
  5452. #ifndef NOXFER
  5453.     printf(" Transfer mode:           %s\n",
  5454.            xfermode == XMODE_A ?
  5455.            "automatic" :
  5456.            "manual"
  5457.            );
  5458.     n++;
  5459. #ifdef PATTERNS
  5460.     printf(" File patterns:           %s", showooa(patterns));
  5461.     if (xfermode == XMODE_M && patterns)
  5462.       printf(" (but disabled by TRANSFER-MODE MANUAL)");
  5463.     else if (patterns)
  5464.       printf(" (SHOW PATTERNS for list)");
  5465.     printf("\n");
  5466.     n++;
  5467. #endif /* PATTERNS */
  5468.     if (filepeek)
  5469.       printf(" File scan:               on %d\n", nscanfile);
  5470.     else
  5471.       printf(" File scan:               off\n");
  5472.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5473.     if (xfermode == XMODE_A)
  5474.       printf(" Default file type:       %s\n",shoxm());
  5475.     else
  5476.       printf(" File type:               %s\n",shoxm());
  5477.     n++;
  5478.     if (fncnv == XYFN_L)
  5479.       s = "literal";
  5480.     else if (fncnv == XYFN_C)
  5481.       s = "converted";
  5482.     else
  5483.       s = "(unknown)";
  5484.     printf(" File names:              %s\n",s);
  5485.     n++;
  5486.     printf(" Send pathnames:          %s\n", pathval(fnspath));
  5487.     n++;
  5488.     printf(" Receive pathnames:       %s\n", pathval(fnrpath));
  5489.     n++;
  5490. #ifdef UNIXOROSK
  5491.     printf(" Match dot files:         %s\n", matchdot ? "yes" : "no");
  5492.     n++;
  5493. #ifdef UNIX
  5494.     printf(" Wildcard-expansion:      %s\n", wildxpand ? "shell" : "kermit");
  5495.     n++;
  5496. #endif /* UNIX */
  5497. #endif /* UNIXOROSK */
  5498.     printf(" File collision:          ");
  5499.     for (i = 0; i < ncolx; i++)
  5500.       if (colxtab[i].kwval == fncact) break;
  5501.     printf("%s\n", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5502.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5503.     printf(" File destination:        %s\n",
  5504.            (dest == DEST_D) ? "disk" :
  5505.            ((dest == DEST_S) ? "screen" :
  5506.             ((dest == DEST_N) ? "nowhere" :
  5507.             "printer"))
  5508.            );
  5509.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5510.     s = (keep >= 0 && keep <= 2) ? ifdnam[keep] : "keep";
  5511.     printf(" File incomplete:         %s\n",s);
  5512.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5513.     printf(" File bytesize:           %d\n",(fmask == 0177) ? 7 : 8);
  5514.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5515. #ifndef NOCSETS
  5516.     printf(" File character-set:      %s\n",fcsinfo[fcharset].keyword);
  5517.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5518.     printf(" File default 7-bit:      %s\n",fcsinfo[dcset7].keyword);
  5519.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5520.     printf(" File default 8-bit:      %s\n",fcsinfo[dcset8].keyword);
  5521.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5522. #ifdef UNICODE
  5523.     printf(" File UCS bom:            %s\n",showoff(ucsbom));
  5524.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5525.     printf(" File UCS byte-order:     %s-endian\n",
  5526.            ucsorder ? "little" : "big");
  5527.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5528.     printf(" Computer byteorder:      %s-endian\n",
  5529.            byteorder ? "little" : "big");
  5530.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5531. #endif /* UNICODE */
  5532. #endif /* NOCSETS */
  5533.  
  5534.     printf(" File end-of-line:        ");
  5535.     i = feol;
  5536.     switch (feol) {
  5537.       case XYFA_C: printf("%s\n","cr"); break;
  5538.       case XYFA_L: printf("%s\n","lf"); break;
  5539.       case XYFA_2: printf("%s\n","crlf"); break;
  5540.       default: printf("%d\n",i);
  5541.     }
  5542.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5543. #endif /* NOXFER */
  5544.  
  5545. #ifdef CK_CTRLZ
  5546.     printf(" File eof:                %s\n", eofmethod ? "ctrl-z" : "length");
  5547.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5548. #endif /* CK_CTRLZ */
  5549. #ifndef NOXFER
  5550. #ifdef CK_TMPDIR
  5551.     printf(" File download-directory: %s\n", dldir ? dldir : "(none)");
  5552.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5553. #ifdef COMMENT
  5554.     i = 256;
  5555.     s = line;
  5556.     zzstring("\\v(tmpdir)",&s,&i);
  5557.     printf(" Temporary directory:     %s\n", line);
  5558.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5559. #endif /* COMMENT */
  5560. #endif /* CK_TMPDIR */
  5561. #ifdef VMS
  5562.     {
  5563.     extern int vmssversions, vmsrversions;
  5564.     printf(" Send version-numbers:    %s\n",showoff(vmssversions));
  5565.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5566.     printf(" Receive version-numbers: %s\n",showoff(vmsrversions));
  5567.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5568.     }
  5569. #endif /* VMS */
  5570.     printf(" Send move-to:            %s\n",
  5571.            snd_move ? snd_move : "(none)");
  5572.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5573.     printf(" Send rename-to:          %s\n",
  5574.            snd_rename ? snd_rename : "(none)");
  5575.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5576.     printf(" Receive move-to:         %s\n",
  5577.            rcv_move ? rcv_move : "(none)");
  5578.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5579.     printf(" Receive rename-to:       %s\n",
  5580.            rcv_rename ? rcv_rename : "(none)");
  5581.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5582. #endif /* NOXFER */
  5583. #ifdef KERMRC
  5584.     printf(" Initialization file:     %s\n", noinit ? "(none)" :
  5585. #ifdef CK_SYSINI
  5586.            CK_SYSINI
  5587. #else
  5588.            kermrc
  5589. #endif /* CK_SYSINI */
  5590.            );
  5591. #endif /* KERMRC */
  5592.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5593.  
  5594.     if (k_info_dir) {
  5595.         printf(" Kermit doc files:        %s\n", k_info_dir);
  5596.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5597.     }
  5598.  
  5599. #ifdef CKROOT
  5600.     s = zgetroot();
  5601.     printf(" Root set:                %s\n", s ? s : "(none)");
  5602. #endif /* CKROOT */
  5603.  
  5604. #ifdef UNIX
  5605.     printf(" Disk output buffer:      %d (writes are %s, %s)\n",
  5606.            zobufsize,
  5607.            zofbuffer ? "buffered" : "unbuffered",
  5608.            zofblock ? "blocking" : "nonblocking"
  5609.            );
  5610.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5611. #ifdef DYNAMIC
  5612.     printf(" Stringspace:             %d\n", zsetfil(0,2));
  5613.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5614.     printf(" Listsize:                %d\n", zsetfil(0,4));
  5615.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;       
  5616. #endif /* DYNAMIC */
  5617. #endif /* UNIX */
  5618. #ifdef OS2ORUNIX
  5619.     printf(" Longest filename:        %d\n", maxnam);
  5620.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5621.     printf(" Longest pathname:        %d\n", maxpath);
  5622.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5623. #endif /* OS2ORUNIX */
  5624.  
  5625.     printf(" Last file sent:          %s\n", sfspec ? sfspec : "(none)");
  5626.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5627.     printf(" Last file received:      %s\n", rfspec ? rfspec : "(none)");
  5628.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5629.     printf("\n Also see:\n");
  5630.     n++;
  5631.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5632.     printf(" SHOW PROTOCOL, SHOW XFER");
  5633. #ifdef CK_LABELED
  5634.     printf(", SHOW LABELED");
  5635. #endif /* CK_LABELED */
  5636. #ifdef PATTERNS
  5637.     printf(", SHOW PATTERNS");
  5638. #endif /* PATTERNS */
  5639. #ifdef STREAMING
  5640.     printf(", SHOW STREAMING");
  5641. #endif /* STREAMING */
  5642. #ifndef NOCSETS
  5643.     printf(", SHOW CHARACTER-SETS");
  5644. #endif /* NOCSETS */
  5645.     printf("\n\n");
  5646. }
  5647.  
  5648. #ifndef NOXFER
  5649. VOID
  5650. shoparp() {                             /* Protocol */
  5651.     extern int docrc, skipbup;
  5652.     char *s;
  5653.  
  5654. #ifdef CK_TIMERS
  5655.     extern int rttflg;
  5656. #endif /* CK_TIMERS */
  5657.  
  5658.     printf("Protocol: %s\n",ptab[protocol].p_name);
  5659.  
  5660.     if (protocol == PROTO_K) {
  5661.         printf("\nProtocol Parameters:   Send    Receive");
  5662.         if (timef)
  5663.           printf("\n Timeout (used=%2d):%7d*%8d ", timint, rtimo, pkttim);
  5664.         else
  5665.           printf("\n Timeout (used=%2d):%7d%9d ",  timint, rtimo, pkttim);
  5666. #ifdef XFRCAN
  5667.         printf("       Cancellation:    %s",showoff(xfrcan));
  5668.         if (xfrcan)
  5669.           printf(" %d %d", xfrchr, xfrnum);
  5670. #endif /* XFRCAN */
  5671.         printf("\n Padding:      %11d%9d", npad,   mypadn);
  5672.         if (bctr == 4)
  5673.           printf("        Block Check: blank-free-2\n");
  5674.         else
  5675.           printf("        Block Check: %6d\n",bctr);
  5676.         printf(  " Pad Character:%11d%9d", padch,  mypadc);
  5677.         printf("        Delay:       %6d\n",ckdelay);
  5678.         printf(  " Pause:        %11d%9d", pktpaus, pktpaus);
  5679.         printf("        Attributes:      %s\n",showoff(atcapr));
  5680.         printf(  " Packet Start: %11d%9d", mystch, stchr);
  5681.         printf("        Max Retries: %6d%s\n",
  5682.            maxtry,
  5683.            (maxtry == 0) ? " (unlimited)" : ""
  5684.            );
  5685.         printf(  " Packet End:   %11d%9d", seol,   eol);
  5686.         if (ebqflg)
  5687.           printf("        8th-Bit Prefix: '%c'",ebq);
  5688.         else
  5689.           printf("        8th-Bit Prefix: ('%c' but not used)",ebq);
  5690.         printf(  "\n Packet Length:%11d ", spmax);
  5691.         printf("%8d     ",  urpsiz);
  5692.         if (rptflg)
  5693.           printf("   Repeat Prefix:  '%c'",rptq);
  5694.         else
  5695.           printf("   Repeat Prefix:  ('%c' but not used)",rptq);
  5696.         printf(  "\n Maximum Length: %9d%9d", maxsps, maxrps);
  5697.         printf("        Window Size:%7d set, %d used\n",wslotr,wmax);
  5698.         printf(    " Buffer Size:  %11d%9d", bigsbsiz, bigrbsiz);
  5699.         printf("        Locking-Shift:    ");
  5700.         if (lscapu == 2) {
  5701.             printf("forced");
  5702.         } else {
  5703.             printf("%s", (lscapr ? "enabled" : "disabled"));
  5704.             if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  5705.         }
  5706.         printf("\n\n");
  5707.  
  5708.         if (!(s = ptab[protocol].h_b_init)) s = "";
  5709.         printf(" Auto-upload command (binary): ");
  5710.         if (*s) {
  5711.             shostrdef((CHAR *)s);
  5712.             printf("\n");
  5713.         } else {
  5714.             printf("(none)\n");
  5715.         }
  5716.         if (!(s = ptab[protocol].h_t_init)) s = "";
  5717.         printf(" Auto-upload command (text):   ");
  5718.         if (*s) {
  5719.             shostrdef((CHAR *)s);
  5720.             printf("\n");
  5721.         } else {
  5722.             printf("(none)\n");
  5723.         }
  5724.         if (!(s = ptab[protocol].h_x_init)) s = "";
  5725.         printf(" Auto-server command:          ");
  5726.         if (*s) {
  5727.             shostrdef((CHAR *)s);
  5728.             printf("\n");
  5729.         } else {
  5730.             printf("(none)\n");
  5731.         }
  5732.         tmpbuf[0] = NUL;
  5733. #ifdef CK_TIMERS
  5734.         if (rttflg) {
  5735.             extern int mintime, maxtime;
  5736.             sprintf(tmpbuf," Packet timeouts: dynamic %d:%d", /* SAFE */
  5737.                     mintime,
  5738.                     maxtime);
  5739.         } else {
  5740.             sprintf(tmpbuf," Packet timeouts: fixed"); /* SAFE */
  5741.         }
  5742. #endif /* CK_TIMERS */
  5743.         if (tmpbuf[0])
  5744.           printf("%-31s",tmpbuf);
  5745.         printf("Send backup: %s\n",showoff(!skipbup));
  5746.  
  5747.         printf(" Transfer mode:   %s", xfermode == XMODE_A ?
  5748.                "automatic   " :
  5749.                "manual      "
  5750.                );
  5751.         printf(" Transfer slow-start: %s, crc: %s\n",
  5752.                showoff(slostart),
  5753.                showoff(docrc)
  5754.                );
  5755. #ifdef PIPESEND
  5756.         {
  5757.             extern int usepipes;
  5758.             printf(" Transfer pipes:  %s         ",usepipes ? "on " : "off");
  5759.         }
  5760. #endif /* PIPESEND */
  5761. #ifndef NOCSETS
  5762.         printf(" Transfer character-set: ");
  5763.         if (tcharset == TC_TRANSP)
  5764.           printf("transparent\n");
  5765.         else
  5766.           printf("%s\n", tcsinfo[tcharset].keyword );
  5767. #endif /* NOCSETS */
  5768. #ifdef PIPESEND
  5769.         {
  5770.             extern char * sndfilter, * rcvfilter;
  5771.             printf(" Send filter:     %s\n", sndfilter ? sndfilter : "(none)");
  5772.             printf(" Receive filter:  %s\n", rcvfilter ? rcvfilter : "(none)");
  5773.         }
  5774. #endif /* PIPESEND */
  5775.         printf("\nAlso see:\n");
  5776.         printf(" SHOW FILE, SHOW XFER");
  5777.  
  5778. #ifdef CK_LABELED
  5779.         printf(", SHOW LABELED");
  5780. #endif /* CK_LABELED */
  5781. #ifdef PATTERNS
  5782.         printf(", SHOW PATTERNS");
  5783. #endif /* PATTERNS */
  5784. #ifdef STREAMING
  5785.         printf(", SHOW STREAMING");
  5786. #endif /* STREAMING */
  5787. #ifndef NOCSETS
  5788.         printf(", SHOW CHARACTER-SETS");
  5789. #endif /* NOCSETS */
  5790.     }
  5791.  
  5792. #ifdef CK_XYZ
  5793. #ifdef XYZ_INTERNAL
  5794.     if (protocol != PROTO_K) {
  5795.         int i;
  5796.         int x;
  5797.         printf(" File type: %s\n", binary ? "binary" : "text");
  5798.         if (protocol == PROTO_Z) {              /* Zmodem */
  5799.             printf(" Window size:   ");
  5800.             if (ptab[protocol].winsize < 1)
  5801.               printf("none\n");
  5802.             else
  5803.               printf("%d\n",wslotr);
  5804. #ifdef COMMENT
  5805.             printf(" Packet (frame) length: ");
  5806.             if (ptab[protocol].spktlen < 0)
  5807.               printf("none\n");
  5808.             else
  5809.               printf("%d\n",spmax);
  5810. #endif /* COMMENT */
  5811.         } else {
  5812.             if (ptab[protocol].spktlen >= 1000)
  5813.               printf(" 1K packets\n");
  5814.             else
  5815.               printf(" 128-byte packets\n");
  5816.         }
  5817.         printf(" Pathname stripping when sending:   %s\n",
  5818.                showoff(ptab[protocol].fnsp)
  5819.                );
  5820.         printf(" Pathname stripping when receiving: %s\n",
  5821.                showoff(ptab[protocol].fnrp)
  5822.                );
  5823.         printf(" Filename collision action:         ");
  5824.         for (i = 0; i < ncolx; i++)
  5825.           if (colxtab[i].kwval == fncact) break;
  5826.         printf("%-12s", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5827.  
  5828.         printf("\n Escape control characters:          ");
  5829.         x = ptab[protocol].prefix;
  5830.         if (x == PX_ALL)
  5831.           printf("all\n");
  5832.         else if (x == PX_CAU || x==PX_WIL)
  5833.           printf("minimal\n");
  5834.         else
  5835.           printf("none\n");
  5836.         if (!(s = ptab[protocol].h_b_init))
  5837.           s = "";
  5838.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5839.         if (!(s = ptab[protocol].h_t_init))
  5840.           s = "";
  5841.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  5842.     }
  5843. #else
  5844.     if (protocol != PROTO_K) {
  5845.         printf("\nExecuted by external commands:\n\n");
  5846.         s = ptab[protocol].p_b_scmd;
  5847.         if (!s) s = "";
  5848.         printf(" SEND command (binary):        %s\n", *s ? s : "(none)");
  5849.         s = ptab[protocol].p_t_scmd;
  5850.         if (!s) s = "";
  5851.         printf(" SEND command (text):          %s\n", *s ? s : "(none)");
  5852.         s = ptab[protocol].p_b_rcmd;
  5853.         if (!s) s = "";
  5854.         printf(" RECEIVE command (binary):     %s\n", *s ? s : "(none)");
  5855.         s = ptab[protocol].p_t_rcmd;
  5856.         if (!s) s = "";
  5857.         printf(" RECEIVE command (text):       %s\n", *s ? s : "(none)");
  5858.         s = ptab[protocol].h_b_init;
  5859.         if (!s) s = "";
  5860.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5861.         s = ptab[protocol].h_t_init;
  5862.         if (!s) s = "";
  5863.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  5864.     }
  5865. #endif /* XYZ_INTERNAL */
  5866. #endif /* CK_XYZ */
  5867. }
  5868. #endif /* NOXFER */
  5869.  
  5870. #ifndef NOCSETS
  5871. /* Character-set items */
  5872.  
  5873. extern int s_cset, r_cset, axcset[], afcset[];
  5874. extern struct keytab xfrmtab[];
  5875.  
  5876. VOID
  5877. shoparl() {
  5878. #ifdef COMMENT
  5879.     int i;
  5880. /* Misleading... */
  5881.     printf("\nAvailable Languages:\n");
  5882.     for (i = 0; i < MAXLANG; i++) {
  5883.         printf(" %s\n",langs[i].description);
  5884.     }
  5885. #else
  5886.     printf("\nLanguage-specific translation rules: %s\n",
  5887.            language == L_USASCII ? "none" : langs[language].description);
  5888.     shocharset();
  5889.     printf("\n\n");
  5890. #endif /* COMMENT */
  5891. }
  5892.  
  5893. VOID
  5894. shocharset() {
  5895.     int x;
  5896. #ifdef COMMENT
  5897.     char * s = "Unknown";
  5898.     extern int xlatype;
  5899. #endif /* COMMENT */
  5900.  
  5901. #ifndef NOXFER
  5902.     extern int xfrxla;
  5903. #endif /* NOXFER */
  5904.  
  5905.     debug(F101,"SHOW FILE CHAR","",fcharset);
  5906.     printf("\n");
  5907. #ifndef NOXFER
  5908.     printf(" Transfer Translation: %s\n", showoff(xfrxla));
  5909.     if (!xfrxla) {
  5910.     printf(
  5911.       " Because transfer translation is off, the following are ignored:\n\n");
  5912.     }
  5913. #endif /* NOXFER */
  5914.     printf(" File Character-Set: %s (%s), ",
  5915.            fcsinfo[fcharset].keyword,
  5916.            fcsinfo[fcharset].name
  5917.            );
  5918.     if ((x = fcsinfo[fcharset].size) == 128)
  5919.       printf("7-bit");
  5920.     else if (x == 256)
  5921.       printf("8-bit");
  5922.     else
  5923.       printf("multibyte");
  5924.     printf("\n");
  5925.     printf(" File Scan: %s\n",showoff(filepeek));
  5926.     printf("   Default 7bit-Character-Set: %s\n",fcsinfo[dcset7].keyword);
  5927.     printf("   Default 8bit-Character-Set: %s\n",fcsinfo[dcset8].keyword);
  5928.     printf(" Transfer Character-Set");
  5929. #ifdef COMMENT
  5930.     if (tslevel == TS_L2)
  5931.       printf(": (international)");
  5932.     else
  5933. #endif /* COMMENT */
  5934.     if (tcharset == TC_TRANSP)
  5935.       printf(": Transparent");
  5936.     else
  5937.       printf(": %s (%s)",tcsinfo[tcharset].keyword, tcsinfo[tcharset].name);
  5938.     printf("\n");
  5939. #ifdef COMMENT
  5940.     switch (xlatype) {
  5941.       case XLA_NONE: s = "None"; break;
  5942.       case XLA_BYTE: s = "Byte"; break;
  5943.       case XLA_JAPAN: s = "Japanese"; break;
  5944.       case XLA_UNICODE: s = "Unicode"; break;
  5945.     }
  5946.     printf("\n Translation type: %s\n",s);
  5947. #endif /* COMMENT */
  5948.     printf(" SEND character-set-selection: %s\n",xfrmtab[s_cset].kwd);
  5949.     printf(" RECEIVE character-set-selection: %s\n",xfrmtab[r_cset].kwd);
  5950.     if (s_cset == XMODE_A || r_cset == XMODE_A)
  5951.       printf(
  5952.       " (Use SHOW ASSOCIATIONS to list automatic character-set selections.)\n"
  5953.              );
  5954. }
  5955.  
  5956. VOID
  5957. showassoc() {
  5958.     int i, k, n = 4;
  5959.     char * s;
  5960.     printf("\nFor incoming files:\n\n");
  5961.     printf("Transfer Character-Set   File Character-Set\n");
  5962.     for (i = 1; i <= MAXTCSETS; i++) {
  5963.         k = axcset[i];
  5964.         if (k < 0 || k > MAXFCSETS)
  5965.           s = "(none)";
  5966.         else
  5967.           s = fcsinfo[k].keyword;
  5968.         if (!s) s = "";
  5969.         if (!*s) s = "(none)";
  5970.         printf(" %-25s%s\n",tcsinfo[i].keyword,s);
  5971.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5972.     }
  5973.     printf("\nFor outbound files:\n\n");
  5974.     n += 2;
  5975.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5976.     printf("File Character-Set       Transfer Character-Set\n");
  5977.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5978.     for (i = 0; i <= MAXFCSETS; i++) {
  5979.         k = afcset[i];
  5980.         if (k < 0 || k > MAXTCSETS)
  5981.           s = "(none)";
  5982.         else
  5983.           s = tcsinfo[k].keyword;
  5984.         if (!s) s = "";
  5985.         if (!*s) s = "(none)";
  5986.         printf(" %-25s%s\n",fcsinfo[i].keyword,s);
  5987.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5988.     }
  5989. }
  5990. #endif /* NOCSETS */
  5991.  
  5992. VOID
  5993. shopar() {
  5994.     printf("Show what?  (Type \"show ?\" for a list of possiblities.)\n");
  5995. }
  5996. #endif /* NOSHOW */
  5997.  
  5998. #ifndef NOXFER
  5999. /*  D O S T A T  --  Display file transfer statistics.  */
  6000.  
  6001. int
  6002. dostat(brief) int brief; {
  6003.     extern long filrej, peakcps;
  6004.     extern int lastspmax, streamed, cleared, streamok;
  6005.     extern char whoareu[];
  6006.     int n = 0, ftp = 0;
  6007.     extern int docrc, interrupted, fatalio;
  6008.  
  6009.     ftp = lastxfer & W_FTP;
  6010.  
  6011. #ifdef CK_TTGWSIZ
  6012. #ifdef OS2
  6013.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  6014.       ttgwsiz();
  6015. #else /* OS2 */
  6016.     if (ttgwsiz() > 0) {
  6017.         if (tt_rows > 0 && tt_cols > 0) {
  6018.             cmd_rows = tt_rows;
  6019.             cmd_cols = tt_cols;
  6020.         }
  6021.     }
  6022. #endif /* OS2 */
  6023. #endif /* CK_TTGWSIZ */
  6024.  
  6025.     debug(F101,"dostat xferstat","",xferstat);
  6026.     if (xferstat < 0) {
  6027.         printf(" No file transfers yet.\n");
  6028.         return(1);
  6029.     }
  6030.     n = 0;
  6031.     if (brief) { printf("\n"); n++; };
  6032.     printf(" protocol               : %s\n",
  6033.        ftp ? "ftp" : ptab[protocol].p_name);
  6034.     n++;
  6035.     printf(" status                 : ");
  6036.     if (xferstat) printf("SUCCESS\n");
  6037.     else if (interrupted) printf("FAILURE (interrupted)\n");
  6038.     else if (fatalio) printf("FAILURE (i/o error)\n");
  6039.     else printf("FAILURE\n");
  6040. #ifndef XYZ_INTERNAL
  6041.     if (!ftp && protocol != PROTO_K) {
  6042.     printf("\n external protocol statistics not available\n");
  6043.     return(1);
  6044.     }
  6045. #endif /* XYZ_INTERNAL */
  6046.     n++;
  6047.     if (!ftp) {
  6048.     if (!xferstat > 0) {
  6049.         if (docrc)
  6050.           printf(" crc-16 of file(s)      : %ld\n", crc16);
  6051.         else
  6052.           printf(" crc-16 of file(s)      : (disabled)\n");
  6053.         n++;
  6054.     }
  6055.     if (!xferstat && *epktmsg) {
  6056.         printf(" reason                 : %s\n", epktmsg);
  6057.         n++;
  6058.     }
  6059.     }
  6060.     if (!brief) {
  6061. #ifdef NEWFTP
  6062.     if (ftp) {
  6063.         extern char ftp_srvtyp[];
  6064.             printf(" remote system type     : %s\n",ftp_srvtyp);
  6065.     } else
  6066. #endif /* NEWFTP */
  6067.       if (whoareu[0]) {
  6068.             printf(" remote system type     : %s\n",
  6069.                    getsysid((char *)whoareu));
  6070.             n++;
  6071.         }
  6072.         printf(" files transferred      : %ld\n",filcnt - filrej);
  6073.     if (!ftp)
  6074.       printf(" files not transferred  : %ld\n",filrej);
  6075.         printf(" characters last file   : %ld\n",ffc);
  6076.         printf(" total file characters  : %ld\n",tfc);
  6077.         n += ftp ? 3 : 4;
  6078.     if (!ftp) {
  6079.         printf(" communication line in  : %ld\n",tlci);
  6080.         printf(" communication line out : %ld\n",tlco);
  6081.         printf(" packets sent           : %d\n", spackets);
  6082.         printf(" packets received       : %d\n", rpackets);
  6083.         n += 4;
  6084.     }
  6085.     }
  6086.     if (ftp) goto dotimes;
  6087.  
  6088.     printf(" damaged packets rec'd  : %d\n", crunched);
  6089.     printf(" timeouts               : %d\n", timeouts);
  6090.     printf(" retransmissions        : %d\n", retrans);
  6091.     n += 3;
  6092.  
  6093.     if (!brief) {
  6094.         if (filcnt > 0) {
  6095.             printf(" parity                 : %s",parnam((char)parity));
  6096.             n++;
  6097.             if (autopar) { printf(" (detected automatically)"); n++; }
  6098.             printf(
  6099.                  "\n control characters     : %ld prefixed, %ld unprefixed\n",
  6100.                    ccp, ccu);
  6101.             n++;
  6102.             printf(" 8th bit prefixing      : ");
  6103.             n++;
  6104.             if (ebqflg) printf("yes [%c]\n",ebq); else printf("no\n");
  6105.             n++;
  6106.             printf(" locking shifts         : %s\n", lscapu ? "yes" : "no");
  6107.             n++;
  6108.         }
  6109.     }
  6110.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6111.     if (streamed > 0)
  6112.       printf(" window slots used      : (streaming)\n");
  6113.     else
  6114.       printf(" window slots used      : %d of %d\n", wmax, wslotr);
  6115.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6116.     printf(" reliable:              : %s%s\n",
  6117.            streamok ? "" : "not ", "negotiated");
  6118.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6119.     printf(" clearchannel:          : %s%s\n",
  6120.            cleared  ? "" : "not ", "negotiated");
  6121.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6122.  
  6123.     if (!brief) {
  6124.         printf(" packet length          : %d (send), %d (receive)\n",
  6125.                lastspmax, urpsiz);
  6126.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6127.         printf(" compression            : ");
  6128.         if (rptflg)
  6129.           printf("yes [%c] (%ld)\n",(char) rptq,rptn);
  6130.         else
  6131.           printf("no\n");
  6132.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6133.         if (bctu == 4)
  6134.           printf(" block check type used  : blank-free-2\n");
  6135.         else
  6136.           printf(" block check type used  : %d\n",bctu);
  6137.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6138.     }
  6139.  
  6140.   dotimes:
  6141.  
  6142. #ifdef GFTIMER
  6143. #ifdef COMMENT
  6144.     printf(" elapsed time           : %0.3f sec, %s\n", fptsecs,hhmmss(tsecs));
  6145. #endif /* COMMENT */
  6146.     printf(" elapsed time           : %s (%0.3f sec)\n",
  6147.            hhmmss((long)(fptsecs + 0.5)),fptsecs);
  6148. #else
  6149. #ifdef COMMENT
  6150.     printf(" elapsed time           : %s (%d sec)\n",hhmmss(tsecs),tsecs);
  6151. #endif /* COMMENT */
  6152.     printf(" elapsed time           : %d sec, %s\n",tsecs,hhmmss(tsecs));
  6153. #endif /* GFTIMER */
  6154.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6155.     if (!ftp && local && !network && !brief) {
  6156.         if (speed <= 0L) speed = ttgspd();
  6157.         if (speed > 0L) {
  6158.             if (speed == 8880)
  6159.               printf(" transmission rate      : 75/1200 bps\n");
  6160.             else
  6161.               printf(" transmission rate      : %ld bps\n",speed);
  6162.             if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6163.         }
  6164.     }
  6165.     if (!ftp && local && !network &&    /* Only makes sense for */
  6166.         mdmtyp == 0 &&            /* direct serial connections */
  6167.         speed > 99L &&            /* when we really know the speed */
  6168.         speed != 8880L
  6169.         ) {
  6170.         int eff;
  6171.         eff = (((tfcps * 100L) / (speed / 100L)) + 5L) / 10L;
  6172.         printf(" effective data rate    : %ld cps (%d%%)\n",tfcps,eff);
  6173.     } else
  6174.       printf(" effective data rate    : %ld cps\n", tfcps);
  6175.     if (!ftp && peakcps > 0L && peakcps > tfcps)
  6176.       printf(" peak data rate         : %ld cps\n", peakcps);
  6177.     if (brief)
  6178.       printf("\nUse STATISTICS /VERBOSE for greater detail.\n\n");
  6179.     return(1);
  6180. }
  6181. #endif /* NOXFER */
  6182.  
  6183. #ifndef NOSPL
  6184.  
  6185. /* The INPUT command */
  6186.  
  6187. /*
  6188.   NOTE: An INPUT timeout of 0 means to perform a nonblocking read of the
  6189.   material that has already arrived and is waiting to be read, and perform
  6190.   matches against it, without doing any further reads.  It should succeed
  6191.   or fail instantaneously.
  6192. */
  6193.  
  6194. /* Output buffering for "doinput" */
  6195.  
  6196. #ifdef pdp11
  6197. #define MAXBURST 16             /* Maximum size of input burst */
  6198. #else
  6199. #define MAXBURST 1024
  6200. #endif /* pdp11 */
  6201. #ifdef OSK
  6202. static CHAR *conbuf;            /* Buffer to hold output for console */
  6203. #else
  6204. static CHAR conbuf[MAXBURST];   /* Buffer to hold output for console */
  6205. #endif /* OSK */
  6206. static int concnt = 0;          /* Number of characters buffered */
  6207. #ifdef OSK
  6208. static CHAR *sesbuf;            /* Buffer to hold output for session log */
  6209. #else
  6210. static CHAR sesbuf[MAXBURST];   /* Buffer to hold output for session log */
  6211. #endif /* OSK */
  6212. static int sescnt = 0;          /* Number of characters buffered */
  6213.  
  6214. extern int debses;            /* TERMINAL DEBUG ON/OFF */
  6215.  
  6216. static VOID                             /* Flush INPUT echoing */
  6217. myflsh() {                              /* and session log output. */
  6218.     if (concnt > 0) {
  6219.     if (debses) {            /* Terminal debugging? */
  6220.         int i;
  6221.         for (i = 0; i < concnt; i++)
  6222.           conol(dbchr(conbuf[i]));
  6223.     } else
  6224.       conxo(concnt, (char *) conbuf);
  6225.         concnt = 0;
  6226.     }
  6227.     if (sescnt > 0) {
  6228.         logstr((char *) sesbuf, sescnt);
  6229.         sescnt = 0;
  6230.     }
  6231. }
  6232.  
  6233. /* Execute the INPUT and MINPUT commands */
  6234.  
  6235. int instatus = -1;
  6236. long inetime = -1L;
  6237. int inwait = 0;
  6238.  
  6239. /* For returning the input sequence that matched */
  6240.  
  6241. #ifdef BIGBUFOK
  6242. #define MATCHBUFSIZ 8191
  6243. #else
  6244. #define MATCHBUFSIZ 1023
  6245. #endif /* BIGBUFOK */
  6246. static char * matchbuf = NULL;
  6247. static int matchindex = 0;
  6248. /*
  6249.   timo = How long to wait:
  6250.          < 0 = Wait forever
  6251.            0 = Don't wait
  6252.          > 0 = Wait this many seconds
  6253.   ms   = Array of strings to wait for.
  6254.   mp   = Array of flags.
  6255.          If mp[i] == 0, ms[i] is literal, else it's a pattern.
  6256. */
  6257. int
  6258. doinput(timo,ms,mp) int timo; char *ms[]; int mp[]; {
  6259.     extern int inintr;
  6260. #ifdef CK_AUTODL
  6261.     extern int inautodl;
  6262. #endif /* CK_AUTODL */
  6263.     int x, y, i, t, rt, icn, anychar, mi[MINPMAX];
  6264. #ifdef GFTIMER
  6265.     CKFLOAT fpt = 0.0;
  6266. #endif /* GFTIMER */
  6267.     int lastchar = 0;
  6268.     int waiting = 0;
  6269.     char ch, *xp, *s;
  6270.     CHAR c;
  6271. #ifndef NOLOCAL
  6272. #ifdef OS2
  6273.     extern int term_io;
  6274.     int term_io_save;
  6275. #endif /* OS2 */
  6276. #endif /* NOLOCAL */
  6277. #ifdef TNCODE
  6278.     static int cr = 0;
  6279. #endif /* TNCODE */
  6280.     int is_tn = 0;
  6281.     int wrapped = 0;
  6282.  
  6283. #define CK_BURST
  6284. /*
  6285.   This enables the INPUT speedup code, which depends on ttchk() returning
  6286.   accurate information.  If INPUT fails with this code enabled, change the
  6287.   above "#define" to "#undef".
  6288. */
  6289. #ifdef CK_BURST
  6290.     int burst = 0;                      /* Chars remaining in input burst */
  6291. #endif /* CK_BURST */
  6292.  
  6293.     inwait = timo;                      /* For \v(inwait) */
  6294.     makestr(&inpmatch,NULL);
  6295.  
  6296.     if (!matchbuf) {
  6297.     matchbuf = malloc(MATCHBUFSIZ+1);
  6298.     matchbuf[0] = NUL;
  6299.     }
  6300.     matchindex = 0;
  6301.  
  6302.     is_tn =
  6303. #ifdef TNCODE
  6304.         (local && network && ttnproto == NP_TELNET) || (!local && sstelnet)
  6305. #else
  6306.          0
  6307. #endif /* TNCODE */
  6308.           ;
  6309.  
  6310.     instatus = INP_IE;                  /* 3 = internal error */
  6311.     kbchar = 0;
  6312.  
  6313. #ifdef OSK
  6314.     if (conbuf == NULL) {
  6315.         if ((conbuf = (CHAR *)malloc(MAXBURST*2)) == NULL) {
  6316.             return(0);
  6317.         }
  6318.         sesbuf = conbuf + MAXBURST;
  6319.     }
  6320. #endif /* OSK */
  6321.  
  6322. #ifndef NOLOCAL
  6323.     if (local) {                        /* In local mode... */
  6324.         if ((waiting = ttchk()) < 0) {  /* check that connection is open */
  6325.             printf("?Connection %s %s is not open.\n",
  6326.                    network ? "to" : "on",
  6327.                    ttname
  6328.                    );
  6329.             instatus = INP_IO;
  6330.             return(0);
  6331.         }
  6332.         debug(F101,"doinput waiting","",waiting);
  6333.         y = ttvt(speed,flow);           /* Put line in "ttvt" mode */
  6334.         if (y < 0) {
  6335.             printf("?INPUT initialization error\n");
  6336.             instatus = INP_IO;
  6337.             return(0);                  /* Watch out for failure. */
  6338.         }
  6339.     }
  6340. #endif /* NOLOCAL */
  6341.  
  6342.     debug(F111,"doinput ms[0]",ms[0],waiting);
  6343.  
  6344.     if (!ms[0]) {                       /* If we were passed a NULL pointer */
  6345.         anychar = 1;                    /*  ... */
  6346.     } else {
  6347.         y = (int)strlen(ms[0]);         /* Or if search string is empty */
  6348.         anychar = (y < 1);              /* any input character will do. */
  6349.     }
  6350.     if (!anychar && waiting == 0 && timo == 0)
  6351.       return(0);
  6352.  
  6353. #ifndef NODEBUG
  6354.     if (deblog) {
  6355.         char xbuf[24];
  6356.         debug(F101,"doinput anychar","",anychar);
  6357.         debug(F101,"doinput timo","",timo);
  6358.         debug(F101,"doinput echo","",inecho);
  6359.         debug(F101,"doinput burst","",burst);
  6360.         y = -1;
  6361.         while (ms[++y]) {
  6362.             sprintf(xbuf,"doinput string %2d",y); /* SAFE (24) */
  6363.             debug(F111,xbuf,ms[y],mp[y]);
  6364.         }
  6365.     }
  6366. #endif /* NODEBUG */
  6367.  
  6368. #ifdef IKS_OPTION
  6369.     if (is_tn) {
  6370.         /* If the remote side is in a state of IKS START-SERVER    */
  6371.         /* we request that the state be changed.  We will detect   */
  6372.         /* a failure to adhere to the request when we call ttinc() */
  6373.         if (TELOPT_U(TELOPT_KERMIT) &&
  6374.             TELOPT_SB(TELOPT_KERMIT).kermit.u_start)
  6375.           iks_wait(KERMIT_REQ_STOP,0);  /* Send Request-Stop */
  6376. #ifdef CK_AUTODL
  6377.         /* If we are processing packets during INPUT and we have not */
  6378.         /* sent a START message, do so now.                          */
  6379.         if (inautodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  6380.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  6381.         }
  6382. #endif /* CK_AUTODL */
  6383.     }
  6384. #endif /* IKS_OPTION */
  6385.     x = 0;                              /* Return code, assume failure */
  6386.     instatus = INP_TO;                  /* Status, assume timeout */
  6387.  
  6388.     for (y = 0; y < MINPMAX; y++)
  6389.       mi[y] = 0;                        /* String pattern match position */
  6390.  
  6391.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  6392.         y = -1;
  6393.  
  6394.         while ((xp = ms[++y])) {
  6395.             while (*xp) {               /* Convert to lowercase */
  6396.                 if (isupper(*xp)) *xp = (char) tolower(*xp);
  6397.                 xp++;
  6398.             }
  6399.         }
  6400.     }
  6401.     rtimer();                           /* Reset timer. */
  6402. #ifdef GFTIMER
  6403.     rftimer();                          /* Floating-point timer too. */
  6404. #endif /* GFTIMER */
  6405.     inetime = -1L;                      /* Initialize elapsed time. */
  6406.     t = 0;                              /* Time now is 0. */
  6407.     m_found = 0;                        /* Default to timed-out */
  6408.     incount = 0;                        /* Character counter */
  6409.     rt = (timo == 0) ? 0 : 1;           /* Character-read timeout interval */
  6410.  
  6411. #ifndef NOLOCAL
  6412. #ifdef OS2
  6413.     term_io_save = term_io;             /* Disable I/O by emulator */
  6414.     term_io = 0;
  6415. #endif /* OS2 */
  6416. #endif /* NOLOCAL */
  6417.  
  6418.     while (1) {                         /* Character-getting loop */
  6419. #ifdef CK_APC
  6420.         /* Check to see if there is an Autodown or other APC command */
  6421.         if (apcactive == APC_LOCAL ||
  6422.             (apcactive == APC_REMOTE && apcstatus != APC_OFF)) {
  6423.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  6424.                 debug(F110,"doinput about to execute APC",apcbuf,0);
  6425.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  6426.                 delmac("_apc_commands",1);
  6427.                 apcactive = APC_INACTIVE;
  6428. #ifdef DEBUG
  6429.             } else {
  6430.                 debug(F100,"doinput APC in progress","",0);
  6431. #endif /* DEBUG */
  6432.             }
  6433.         }
  6434. #endif /* CK_APC */
  6435.  
  6436.         if (timo == 0 && waiting < 1) { /* Special exit criterion */
  6437.             instatus = INP_TO;          /* for timeout == 0 */
  6438.             break;
  6439.         }
  6440.         if (local) {                    /* One case for local */
  6441.             y = ttinc(rt);              /* Get character from comm device */
  6442.             debug(F101,"doinput ttinc(rt) returns","",y);
  6443.             if (y < -1) {               /* Connection failed. */
  6444.                 instatus = INP_IO;      /* Status = i/o error */
  6445. #ifndef NOLOCAL
  6446. #ifdef OS2
  6447.                 term_io = term_io_save;
  6448. #endif /* OS2 */
  6449. #endif /* NOLOCAL */
  6450.                 switch (y) {
  6451.                   case -2:              /* Connection lost */
  6452.                     if (local && !network && carrier != CAR_OFF) {
  6453. #ifdef CKLOGDIAL
  6454.                         dologend();
  6455. #endif /* CKLOGDIAL */
  6456.                         printf("Connection closed.\n");
  6457.                         ttclos(1);
  6458.                     }
  6459.                     break;
  6460.                   case -3:
  6461. #ifdef CKLOGDIAL
  6462.                     dologend();
  6463. #endif /* CKLOGDIAL */
  6464.                     printf("Session Limit exceeded - closing connection.\n");
  6465.                     ttclos(1);
  6466.                   default:
  6467.                     break;
  6468.                 }
  6469.                 debug(F111,"doinput Connection failed","returning 0",y);
  6470.                 return(0);
  6471.             }
  6472.             if (inintr) {
  6473.                 debug(F111,"doinput","inintr",inintr);
  6474.                 if ((icn = conchk()) > 0) { /* Interrupted from keyboard? */
  6475.                     debug(F101,"input interrupted from keyboard","",icn);
  6476.                     kbchar = coninc(0);
  6477.                     if (kbchar >= 0) {
  6478.             while (--icn > 0) {
  6479.                 debug(F110,"doinput","absorbing",0);
  6480.                 coninc(0);      /* Yes, absorb what was typed. */
  6481.             }
  6482.             instatus = INP_UI;  /* Fail and remember why. */
  6483.             break;
  6484.             }
  6485.                 }
  6486.             }
  6487.         } else {                        /* Another for remote */
  6488.             y = coninc(rt);
  6489.             debug(F101,"doinput coninc(rt) returns","",y);
  6490.         }
  6491.         if (y > -1) {                   /* A character arrived */
  6492.             debug(F111,"doinput","a character arrived",y);
  6493.             if (timo == 0)
  6494.               waiting--;
  6495. #ifndef OS2
  6496. #define TN_NOLO
  6497. #endif /* OS2 */
  6498. #ifdef NOLOCAL
  6499. #define TN_NOLO
  6500. #endif /* NOLOCAL */
  6501.  
  6502. #ifdef TN_NOLO
  6503.             debug(F100,"doinput TN_NOLO","",0);
  6504. #ifdef TNCODE
  6505.             /* Check for telnet protocol negotiation */
  6506.             if (is_tn) {
  6507.                 switch (y & 0xff) {
  6508.                   case IAC:
  6509.                     cr = 0;
  6510.                     myflsh();   /* Break from input burst for tn_doop() */
  6511. #ifdef CK_BURST
  6512.                     burst = 0;
  6513. #endif /* CK_BURST */
  6514.                     waiting -= 2;       /* (not necessarily...) */
  6515.                     switch (tn_doop((CHAR)(y & 0xff),duplex,ttinc)) {
  6516.                       case 2: duplex = 0; continue;
  6517.                       case 1: duplex = 1; continue;
  6518. #ifdef IKS_OPTION
  6519.                       case 4:
  6520.                         if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6521.                              !tcp_incoming) {
  6522.                             instatus = INP_IKS;
  6523.                             printf(
  6524.  " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6525.                                    );
  6526.                             break;
  6527.                         }
  6528.                         continue;
  6529. #endif /* IKS_OPTION */
  6530.                       case 6:           /* TELNET DO LOGOUT received */
  6531.                       default: continue;
  6532.                     }
  6533.                   case CR:
  6534.                     cr = 1;
  6535.                     break;
  6536.                   case NUL:
  6537.                     if (!TELOPT_U(TELOPT_BINARY) && cr) {
  6538.                         cr = 0;
  6539.                         continue;
  6540.                     }
  6541.                     cr = 0;
  6542.                     break;
  6543.                   default:
  6544.                     cr = 0;
  6545.                 }
  6546.                 /* I'm echoing remote chars */
  6547.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6548.                   ttoc((char)y);
  6549.             }
  6550. #endif /* TNCODE */
  6551. #ifdef CK_AUTODL
  6552.             /* Check for file transfer packets */
  6553.             if (inautodl) autodown(y);
  6554. #endif /* CK_AUTODL */
  6555. #else  /* TN_NOLO */
  6556.             debug(F100,"doinput !TN_NOLO","",0);
  6557. #ifdef TNCODE
  6558.             /* Check for telnet protocol negotiation */
  6559.             if (is_tn) {
  6560.                 int tx;
  6561.                 switch (y & 0xff) {
  6562.                   case IAC:
  6563.                     myflsh();   /* Break from input burst for tn_doop() */
  6564. #ifdef CK_BURST
  6565.                     burst = 0;
  6566. #endif /* CK_BURST */
  6567. #ifdef IKS_OPTION
  6568.                     tx = scriptwrtbuf((USHORT)y);
  6569.                     if (tx == 4) {
  6570.                         if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6571.                             !tcp_incoming
  6572.                             ) {
  6573.                             instatus = INP_IKS;
  6574.                             printf(
  6575.   " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6576.                                    );
  6577.                             break;
  6578.                         }
  6579.                     } else if (tx == 6) {
  6580.                         /* TELNET DO LOGOUT received */
  6581.  
  6582.                     }
  6583. #else /* IKS_OPTION */
  6584.                     /* Handles Telnet negotiations */
  6585.                     tx = scriptwrtbuf((USHORT)y);
  6586.                     if (tx == 6) {
  6587.                         /* TELNET DO LOGOUT received */
  6588.                     }
  6589. #endif /* IKS_OPTION */
  6590.                     waiting -= 2;       /* (not necessarily...) */
  6591.                     cr = 0;
  6592.                     continue;           /* and autodownload check */
  6593.                   case CR:
  6594.                     cr = 1;
  6595.                     tx = scriptwrtbuf((USHORT)y);
  6596.                     if (tx == 6) {
  6597.                         /* TELNET DO LOGOUT received */
  6598.                     }
  6599.                     break;
  6600.                   case NUL:
  6601.                     cr = 0;
  6602.                     if (!TELOPT_U(TELOPT_BINARY) && cr)
  6603.                       continue;
  6604.                     tx = scriptwrtbuf((USHORT)y);
  6605.                     if (tx == 6) {
  6606.                         /* TELNET DO LOGOUT received */
  6607.                     }
  6608.                     break;
  6609.                   default:
  6610.                     cr = 0;
  6611.                     tx = scriptwrtbuf((USHORT)y);
  6612.                     if (tx == 6) {
  6613.                         /* TELNET DO LOGOUT received */
  6614.                     }
  6615.                 }
  6616.                 /* I'm echoing remote chars */
  6617.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6618.                   ttoc((CHAR)y);
  6619.             } else
  6620. #endif /* TNCODE */
  6621.               /* Handles terminal emulation responses */
  6622.               scriptwrtbuf((USHORT)y);
  6623. #endif /* TN_NOLO */
  6624.  
  6625.             /* Real input character to be checked */
  6626.  
  6627. #ifdef CK_BURST
  6628.             burst--;                    /* One less character waiting */
  6629.             debug(F101,"doinput burst","",burst);
  6630. #endif /* CK_BURST */
  6631.             c = (CHAR) (cmask & (CHAR) y); /* Mask off parity */
  6632.             inchar[0] = c;              /* Remember character for \v(inchar) */
  6633. #ifdef COMMENT
  6634. #ifdef CK_BURST
  6635.             /* Update "lastchar" time only once during input burst */
  6636.             if (burst <= 0)
  6637. #endif /* CK_BURST */
  6638. #endif /* COMMENT */
  6639.               lastchar = gtimer();      /* Remember when it came */
  6640.  
  6641.             if (c == '\0') {            /* NUL, we can't use it */
  6642.                 if (anychar) {          /* Except if any character will do? */
  6643.                     x = 1;              /* Yes, done. */
  6644.                     incount = 1;        /* This must be the first and only. */
  6645.                     break;
  6646.                 } else goto refill;     /* Otherwise continue INPUTting */
  6647.             }
  6648.             *inpbp++ = c;               /* Store char in circular buffer */
  6649.             incount++;                  /* Count it for \v(incount) */
  6650.  
  6651.             /* Don't NUL-terminate here - it's a circular buffer. */
  6652.  
  6653.             if (inpbp >= inpbuf + inbufsize) { /* Time to wrap around? */
  6654.                 wrapped++;
  6655.                 *inpbp = NUL ;          /* Make it null-terminated */
  6656.                 inpbp = inpbuf;         /* Yes. */
  6657.             }
  6658.             if (matchbuf) {
  6659.                 if (matchindex < MATCHBUFSIZ) {
  6660.                     matchbuf[matchindex++] = c;
  6661.                     matchbuf[matchindex] = NUL;
  6662.                 }
  6663.             }
  6664. #ifdef MAC
  6665.             {
  6666.                 extern char *ttermw;    /* fake pointer cast */
  6667.                 if (inecho) {
  6668.                     outchar(ttermw, c); /* echo to terminal window */
  6669.                     /* this might be too much overhead to do here ? */
  6670.                     updatecommand(ttermw);
  6671.                 }
  6672.             }
  6673. #else /* Not MAC */
  6674.             if (inecho) {        /* Buffer console output */
  6675.         conbuf[concnt++] = c;
  6676.         }
  6677. #endif /* MAC */
  6678. #ifndef OS2
  6679.             if (seslog) {
  6680. #ifdef UNIX
  6681.                 if (sessft != 0 || c != '\r')
  6682. #else
  6683. #ifdef OSK
  6684.                 if (sessft != 0 || c != '\012')
  6685. #endif /* OSK */
  6686. #endif /* UNIX */
  6687.                   sesbuf[sescnt++] = c; /* Buffer session log output */
  6688.             }
  6689. #endif /* OS2 */
  6690.             if (anychar) {              /* Any character will do? */
  6691.                 x = 1;
  6692.                 break;
  6693.             }
  6694.             if (!inpcas[cmdlvl]) {      /* Ignore alphabetic case? */
  6695.                 if (isupper(c))         /* Yes, convert input char to lower */
  6696.                   c = (CHAR) tolower(c);
  6697.             }
  6698.             debug(F000,"doinput char","",c);
  6699.  
  6700.             /* Here is the matching section */
  6701.  
  6702.             y = -1;                     /* Loop thru search strings */
  6703.             while ((s = ms[++y])) {    /* ...as many as we have. */
  6704.                 if (mp[y]) {            /* Pattern match? */
  6705. #ifdef COMMENT
  6706.                     int j;
  6707.                     /* This is gross but it works... */
  6708.                     /* We could just as easily have prepended '*' to the  */
  6709.                     /* pattern and skipped the loop, except then we would */
  6710.                     /* not have any way to identify the matching string.  */
  6711.                     for (j = 0; j < matchindex; j++) {
  6712.                         if (ckmatch(s,&matchbuf[j],1,1)) {
  6713.                             matchindex = j;
  6714.                             x = 1;
  6715.                             break;
  6716.                         }
  6717.                     }
  6718.                     if (x > 0)
  6719.                       break;
  6720. #else
  6721.             /* July 2001 - ckmatch() returns match position. */
  6722.             /* It works and it's not gross. */
  6723.             x = ckmatch(s,matchbuf,1,1+4); /* (4 = floating pattern) */
  6724.             if (x > 0) {
  6725.             matchindex = x - 1;
  6726.             x = 1;
  6727.             break;
  6728.             }
  6729. #endif /* COMMENT */
  6730.                     continue;
  6731.                 }                       /* Literal match. */
  6732.                 i = mi[y];              /* Match-position in search string. */
  6733.                 debug(F000,"compare char","",(CHAR)s[i]);
  6734.                 if (c == (CHAR) s[i]) { /* Check for match */
  6735.                     i++;                /* Got one, go to next character */
  6736.                 } else {                /* Don't have a match */
  6737.                     int j;
  6738.                     for (j = i; i > 0; ) { /* Back up in search string */
  6739.                         i--; /* (Do this here to prevent compiler foulup) */
  6740.                         /* j is the length of the substring that matched */
  6741.                         if (c == (CHAR) s[i]) {
  6742.                             if (!strncmp(s,&s[j-i],i)) {
  6743.                                 i++;          /* c actually matches -- cfk */
  6744.                                 break;
  6745.                             }
  6746.                         }
  6747.                     }
  6748.                 }
  6749.                 if ((CHAR) s[i] == (CHAR) '\0') { /* Matched to end? */
  6750.                     ckstrncpy(matchbuf,ms[y],MATCHBUFSIZ);
  6751.                     matchindex = 0;
  6752.                     x = 1;              /* Yes, */
  6753.                     break;              /* done. */
  6754.                 }
  6755.                 mi[y] = i;              /* No, remember match-position */
  6756.             }
  6757.             if (x == 1) {               /* Set \v(minput) result */
  6758.                 m_found = y + 1;
  6759.                 break;
  6760.             }
  6761.         }
  6762. #ifdef CK_BURST
  6763.         else if (y <= -1 && burst > 0) {
  6764.             debug(F111,"doinput (y<=-1&&burst>0)","burst",burst);
  6765.                                         /* a timo occurred so there can't   */
  6766.             burst = 0;                  /* be data waiting; must check timo */
  6767.         }
  6768.       refill:
  6769.         if (burst <= 0) {               /* No buffered chars remaining... */
  6770.             myflsh();                   /* Flush buffered output */
  6771.             if (local) {                /* Get size of next input burst */
  6772.                 burst = ttchk();
  6773.                 if (burst < 0) {        /* ttchk() says connection is closed */
  6774.                     instatus = INP_IO;  /* Status = i/o error */
  6775. #ifndef NOLOCAL
  6776. #ifdef OS2
  6777.                     term_io = term_io_save;
  6778. #endif /* OS2 */
  6779. #endif /* NOLOCAL */
  6780.                     printf("Fatal error - disconnected.\n");
  6781.                     ttclos(1);
  6782.                     break;
  6783.                 }
  6784.                 if (inintr) {
  6785.                     if ((icn = conchk()) > 0) { /* Interrupt from keyboard? */
  6786.                         kbchar = coninc(0);
  6787.                         debug(F101,"input interrupted from keyboard","",icn);
  6788.                         while (--icn > 0) coninc(0); /* Yes, absorb chars. */
  6789.                         break;          /* And fail. */
  6790.                     }
  6791.                 }
  6792.             } else {
  6793.                 burst = conchk();
  6794.             }
  6795.             debug(F101,"doinput burst","",burst);
  6796.             /* Prevent overflow of "conbuf" and "sesbuf" */
  6797.             if (burst > MAXBURST)
  6798.               burst = MAXBURST;
  6799.  
  6800.             /* Did not match, timer exceeded? */
  6801.             t = gtimer();
  6802.             debug(F111,"doinput gtimer","burst",t);
  6803.             debug(F101,"doinput timo","",timo);
  6804.             if ((t >= timo) && (timo > 0))
  6805.               break;
  6806.             else if (insilence > 0 && (t - lastchar) > insilence)
  6807.               break;
  6808.         } else {
  6809.             debug(F111,"doinput (burst > 0)","burst",burst);
  6810.         }
  6811. #else
  6812.         myflsh();                       /* Flush buffered output */
  6813.         /* Did not match, timer exceeded? */
  6814.         t = gtimer();
  6815.         debug(F111,"doinput gtimer","no burst",t);
  6816.         debug(F101,"doinput timo","",timo);
  6817.         if ((t >= timo) && (timo > -1))
  6818.           break;
  6819.         else if (insilence > 0 && (t - lastchar) > insilence)
  6820.           break;
  6821. #endif /* CK_BURST */
  6822.     }                                   /* Still have time left, continue. */
  6823.     myflsh();                           /* Flush buffered output. */
  6824.     if (x > 0)
  6825.       instatus = 0;
  6826. #ifndef NOLOCAL
  6827. #ifdef OS2
  6828.     term_io = term_io_save;
  6829. #endif /* OS2 */
  6830. #endif /* NOLOCAL */
  6831. #ifdef COMMENT
  6832. #ifdef IKS_OPTION
  6833. #ifdef CK_AUTODL
  6834.     if (is_tn && TELOPT_ME(TELOPT_KERMIT) && inautodl) {
  6835.         tn_siks(KERMIT_STOP);           /* Send Kermit-Server Stop */
  6836.     }
  6837. #endif /* CK_AUTODL */
  6838. #endif /* IKS_OPTION */
  6839. #endif /* COMMENT */
  6840.  
  6841. #ifdef GFTIMER
  6842.     fpt = gftimer();                    /* Get elapsed time */
  6843.  
  6844. /* If a long is 32 bits, it would take about 50 days for this to overflow. */
  6845.  
  6846.     inetime = (int)(fpt * (CKFLOAT)1000.0);
  6847. #else
  6848.     inetime = (int)(gtimer() * 1000);
  6849. #endif /* GFTIMER */
  6850.  
  6851.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  6852.     return(x);                          /* Return the return code. */
  6853. }
  6854. #endif /* NOSPL */
  6855.  
  6856. #ifndef NOSPL
  6857. /* REINPUT Command */
  6858.  
  6859. /*
  6860.   Note, the timeout parameter is required, but ignored.  Syntax is compatible
  6861.   with MS-DOS Kermit except timeout can't be omitted.  This function only
  6862.   looks at the characters already received and does not read any new
  6863.   characters from the connection.
  6864. */
  6865. int
  6866. doreinp(timo,s,pat) int timo; char *s; int pat; {
  6867.     int x, y, i;
  6868.     char *xx, *xp, *xq = (char *)0;
  6869.     CHAR c;
  6870.  
  6871.     if (!s) s = "";
  6872.     debug(F101,"doreinput pat","",pat);
  6873.  
  6874.     y = (int)strlen(s);
  6875.     debug(F111,"doreinput search",s,y);
  6876.  
  6877.     if (y > inbufsize) {                /* If search string longer than */
  6878.         debug(F101,"doreinput inbufsize","",inbufsize);
  6879.         return(0);                      /* input buffer, fail. */
  6880.     }
  6881.     makestr(&inpmatch,NULL);
  6882.     if (!matchbuf)
  6883.       matchbuf = malloc(MATCHBUFSIZ+1);
  6884.     matchindex = 0;
  6885.  
  6886.     x = 0;                              /* Return code, assume failure */
  6887.     i = 0;                              /* String pattern match position */
  6888.  
  6889.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  6890.         xp = malloc(y+2);               /* Make a separate copy of the */
  6891.         if (!xp) {                      /* search string. */
  6892.             printf("?malloc error 6\n");
  6893.             return(x);
  6894.         } else xq = xp;                 /* Keep pointer to beginning. */
  6895.         while (*s) {                    /* Yes, convert to lowercase */
  6896.             *xp = *s;
  6897.             if (isupper(*xp)) *xp = (char) tolower(*xp);
  6898.             xp++; s++;
  6899.         }
  6900.         *xp = NUL;                      /* Terminate it! */
  6901.         s = xq;                         /* Move search pointer to it. */
  6902.     }
  6903.     xx = *inpbp ? inpbp : inpbuf;       /* Current INPUT buffer pointer */
  6904.     do {
  6905.         c = *xx++;                      /* Get next character */
  6906.         if (!c) break;
  6907.         if (xx >= inpbuf + inbufsize)   /* Wrap around if necessary */
  6908.           xx = inpbuf;
  6909.         if (!inpcas[cmdlvl]) {          /* Ignore alphabetic case? */
  6910.             if (isupper(c)) c = (CHAR) tolower(c); /* Yes */
  6911.         }
  6912.         if (pat) {
  6913.             int j;
  6914.             if (matchbuf) {
  6915.                 if (matchindex < MATCHBUFSIZ) {
  6916.                     matchbuf[matchindex++] = c;
  6917.                     matchbuf[matchindex] = NUL;
  6918.                 }
  6919.                 for (j = 0; j < matchindex; j++) { /* Gross but effective */
  6920.                     if (ckmatch(s,&matchbuf[j],1,1)) {
  6921.                         debug(F101,"GOT IT","",j);
  6922.                         matchindex = j;
  6923.                         x = 1;
  6924.                         break;
  6925.                     }
  6926.                 }
  6927.             }
  6928.             if (x > 0)
  6929.               break;
  6930.             continue;
  6931.         }
  6932.         debug(F000,"doreinp char","",c);
  6933.         debug(F000,"compare char","",(CHAR) s[i]);
  6934.         if (((char) c) == ((char) s[i])) { /* Check for match */
  6935.             i++;                        /* Got one, go to next character */
  6936.         } else {                        /* Don't have a match */
  6937.             int j;
  6938.             for (j = i; i > 0; ) {      /* [jrs] search backwards for it  */
  6939.                 i--;
  6940.                 if (((char) c) == ((char) s[i])) {
  6941.                     if (!strncmp(s,&s[j-i],i)) {
  6942.                         i++;
  6943.                         break;
  6944.                     }
  6945.                 }
  6946.             }
  6947.         }                               /* [jrs] or return to zero from -1 */
  6948.         if (s[i] == '\0') {             /* Matched all the way to end? */
  6949.             ckstrncpy(matchbuf,s,MATCHBUFSIZ);
  6950.             matchindex = 0;
  6951.             x = 1;                      /* Yes, */
  6952.             break;                      /* done. */
  6953.         }
  6954.     } while (xx != inpbp && x < 1);     /* Until back where we started. */
  6955.  
  6956.     if (!inpcas[cmdlvl]) if (xq) free(xq); /* Free this if it was malloc'd. */
  6957.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  6958.     return(x);                          /* Return search result. */
  6959. }
  6960.  
  6961. /*  X X S T R I N G  --  Interpret strings containing backslash escapes  */
  6962. /*  Z Z S T R I N G  --  (new name...)  */
  6963. /*
  6964.  Copies result to new string.
  6965.   strips enclosing braces or doublequotes.
  6966.   interprets backslash escapes.
  6967.   returns 0 on success, nonzero on failure.
  6968.   tries to be compatible with MS-DOS Kermit.
  6969.  
  6970.  Syntax of input string:
  6971.   string = chars | "chars" | {chars}
  6972.   chars = (c*e*)*
  6973.   where c = any printable character, ascii 32-126
  6974.   and e = a backslash escape
  6975.   and * means 0 or more repetitions of preceding quantity
  6976.   backslash escape = \operand
  6977.   operand = {number} | number | fname(operand) | v(name) | $(name) | m(name)
  6978.   number = [r]n[n[n]]], i.e. an optional radix code followed by 1-3 digits
  6979.   radix code is oO (octal), xX (hex), dD or none (decimal) (see xxesc()).
  6980. */
  6981.  
  6982. #ifndef NOFRILLS
  6983. int
  6984. yystring(s,s2) char *s; char **s2; {    /* Reverse a string */
  6985.     int x;
  6986.     static char *new;
  6987.     new = *s2;
  6988.     if (!s || !new) return(-1);         /* Watch out for null pointers. */
  6989.     if ((x = (int)strlen(s)) == 0) {    /* Recursion done. */
  6990.         *new = '\0';
  6991.         return(0);
  6992.     }
  6993.     x--;                                /* Otherwise, call self */
  6994.     *new++ = s[x];                      /* to reverse rest of string. */
  6995.     s[x] = 0;
  6996.     return(yystring(s,&new));
  6997. }
  6998. #endif /* NOFRILLS */
  6999.  
  7000. static char ipabuf[16] = { NUL };       /* IP address buffer */
  7001.  
  7002. static char *
  7003. getip(s) char *s; {
  7004.     char c=NUL;                         /* Workers... */
  7005.     int i=0, p=0, d=0;
  7006.     int state = 0;                      /* State of 2-state FSA */
  7007.  
  7008.     while ((c = *s++)) {
  7009.         switch(state) {
  7010.           case 0:                       /* Find first digit */
  7011.             i = 0;                      /* Output buffer index */
  7012.             ipabuf[i] = NUL;            /* Initialize output buffer */
  7013.             p = 0;                      /* Period counter */
  7014.             d = 0;                      /* Digit counter */
  7015.             if (isdigit(c)) {           /* Have first digit */
  7016.                 d = 1;                  /* Count it */
  7017.                 ipabuf[i++] = c;        /* Copy it */
  7018.                 state = 1;              /* Change state */
  7019.             }
  7020.             break;
  7021.  
  7022.           case 1:                       /* In numeric field */
  7023.             if (isdigit(c)) {           /* Have digit */
  7024.                 if (++d > 3)            /* Too many */
  7025.                   state = 0;            /* Start over */
  7026.                 else                    /* Not too many */
  7027.                   ipabuf[i++] = c;      /* Keep it */
  7028.             } else if (c == '.' && p < 3) { /* Have a period */
  7029.                 p++;                    /* Count it */
  7030.                 if (d == 0)             /* Not preceded by a digit */
  7031.                   state = 0;            /* Start over */
  7032.                 else                    /* OK */
  7033.                   ipabuf[i++] = c;      /* Keep it */
  7034.                 d = 0;                  /* Reset digit counter */
  7035.             } else if (p == 3 && d > 0) { /* Not part of address */
  7036.                 ipabuf[i] = NUL;        /* If we have full IP address */
  7037.                 return((char *)ipabuf); /* Return it */
  7038.             } else {                    /* Otherwise */
  7039.                 state = 0;              /* Start over */
  7040.                 ipabuf[0] = NUL;        /* (in case no more chars left) */
  7041.             }
  7042.         }
  7043.     }                                   /* Fall thru at end of string */
  7044.     ipabuf[i] = NUL;                    /* Maybe we have one */
  7045.     return((p == 3 && d > 0) ? (char *)ipabuf : "");
  7046. }
  7047. #endif /* NOSPL */
  7048.  
  7049. /* Date Routines */
  7050.  
  7051. /* Z J D A T E  --  Convert yyyymmdd date to Day of Year */
  7052.  
  7053. static int jdays[12] = {  0,31,59,90,120,151,181,212,243,273,304,334 };
  7054. static int ldays[12] = {  0,31,60,91,121,152,182,213,244,274,305,335 };
  7055. static char zjdbuf[12] = { NUL, NUL };
  7056. /*
  7057.   Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat,
  7058.   statuimus bissextum quarto quoque anno (uti mos est) continuari debere,
  7059.   praeterquam in centesimis annis; qui, quamvis bissextiles antea semper
  7060.   fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps
  7061.   consequentur centesimi non omnes bissextiles sint, sed in quadringentis
  7062.   quibusque annis primi quique tres centesimi sine bissexto transigantur,
  7063.   quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC,
  7064.   MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus
  7065.   intercaletur, februario dies XXIX continente, idemque ordo intermittendi
  7066.   intercalandique bissextum diem in quadringentis quibusque annis perpetuo
  7067.   conservetur.  - Gregorius XIII, Anno Domini MDLXXXII.
  7068. */
  7069. char *
  7070. zjdate(date) char * date; {             /* date = yyyymmdd */
  7071.     char year[5];
  7072.     char month[3];
  7073.     char day[3];
  7074.     int d, m, x, y;
  7075.     int leapday, j;
  7076.     char * time = NULL;
  7077.  
  7078.     if (!date) date = "";               /* Validate arg */
  7079.     x = strlen(date);
  7080.     if (x < 1) return("0");
  7081.     if (x < 8) return("-1");
  7082.     for (x = 0; x < 8; x++)
  7083.       if (!isdigit(date[x]))
  7084.         return("-1");
  7085.  
  7086.     if (date[8]) if (date[9])
  7087.       time = date + 9;
  7088.  
  7089.     year[0] = date[0];                  /* Isolate year */
  7090.     year[1] = date[1];
  7091.     year[2] = date[2];
  7092.     year[3] = date[3];
  7093.     year[4] = '\0';
  7094.  
  7095.     month[0] = date[4];                 /* Month */
  7096.     month[1] = date[5];
  7097.     month[2] = '\0';;
  7098.  
  7099.     day[0] = date[6];                   /* And day */
  7100.     day[1] = date[7];
  7101.     day[2] = '\0';
  7102.  
  7103.     leapday = 0;                        /* Assume no leap day */
  7104.     y = atoi(year);
  7105.     m = atoi(month);
  7106.     d = atoi(day);
  7107.     if (m > 2) {                        /* No Leap day before March */
  7108.         if (y % 4 == 0) {               /* If year is divisible by 4 */
  7109.             leapday = 1;                /* It's a Leap year */
  7110.             if (y % 100 == 0) {         /* Except if divisible by 100 */
  7111.                 if (y % 400 != 0)       /* but not by 400 */
  7112.                   leapday = 0;
  7113.             }
  7114.         }
  7115.     }
  7116.     j = jdays[m - 1] + d + leapday;     /* Day of year */
  7117.     if (time)
  7118.       sprintf(zjdbuf,"%04d%03d %s",y,j,time); /* SAFE */
  7119.     else
  7120.       sprintf(zjdbuf,"%04d%03d",y,j);    /* SAFE */
  7121.     return((char *)zjdbuf);
  7122. }
  7123.  
  7124. static char jzdbuf[32];
  7125.  
  7126. /* J Z D A T E  --  Convert Day of Year to yyyyddmm date */
  7127.  
  7128. char *
  7129. jzdate(date) char * date; {             /* date = yyyyddd */
  7130.     char year[5];                       /* with optional time */
  7131.     char day[4];
  7132.     char * time = NULL, * p;
  7133.     int d, m, x, y;
  7134.     int leapday, j;
  7135.     int * zz;
  7136.  
  7137.     if (!date) date = "";               /* Validate arg */
  7138.     x = strlen(date);
  7139.  
  7140.     debug(F111,"jzdate len",date,x);
  7141.  
  7142.     if (x < 1) return("0");
  7143.     if (x < 7) return("-1");
  7144.     if (x > 8) time = date + 8;
  7145.  
  7146.     for (x = 0; x < 7; x++)
  7147.       if (!isdigit(date[x]))
  7148.         return("-1");
  7149.  
  7150.     year[0] = date[0];                  /* Isolate year */
  7151.     year[1] = date[1];
  7152.     year[2] = date[2];
  7153.     year[3] = date[3];
  7154.     year[4] = '\0';
  7155.  
  7156.     debug(F110,"jzdate year",year,0);
  7157.  
  7158.     day[0] = date[4];                   /* And day */
  7159.     day[1] = date[5];
  7160.     day[2] = date[6];
  7161.     day[3] = '\0';
  7162.  
  7163.     debug(F110,"jzdate day",day,0);
  7164.  
  7165.     j = atoi(day);
  7166.     if (j > 366)
  7167.       return("-1");
  7168.  
  7169.     leapday = 0;                        /* Assume no leap day */
  7170.     y = atoi(year);
  7171.     if (y % 4 == 0) {                   /* If year is divisible by 4 */
  7172.         leapday = 1;                    /* It's a Leap year */
  7173.         if (y % 100 == 0) {             /* Except if divisible by 100 */
  7174.             if (y % 400 != 0)           /* but not by 400 */
  7175.               leapday = 0;
  7176.         }
  7177.     }
  7178.     debug(F101,"jzdate leapday","",leapday);
  7179.     zz = leapday ? ldays : jdays;
  7180.  
  7181.     for (x = 0; x < 11; x++)
  7182.       if (j > zz[x] && j <= zz[x+1])
  7183.         break;
  7184.     m = x + 1;
  7185.  
  7186.     debug(F101,"jzdate m","",m);
  7187.  
  7188.     d = j - zz[x];
  7189.  
  7190.     debug(F101,"jzdate d","",d);
  7191.  
  7192.     if (time)
  7193.       sprintf(jzdbuf,"%04d%02d%02d %s",y,m,d,time); /* SAFE */
  7194.     else
  7195.       sprintf(jzdbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7196.  
  7197.     debug(F101,"jzdate jzdbuf",jzdbuf,0);
  7198.  
  7199.     p = ckcvtdate((char *)jzdbuf, 0);   /* Convert to standard form */
  7200.     ckstrncpy(jzdbuf,p,32);
  7201.     if (!time) jzdbuf[8] = NUL;         /* Remove time if not wanted */
  7202.     return((char *)jzdbuf);
  7203. }
  7204.  
  7205. /* M J D  --  Modified Julian Date */
  7206. /*
  7207.   Call with:
  7208.     Standard-format date-time string: yyyymmdd[ hh:mm:ss].
  7209.     The time, if any, is ignored.
  7210.  
  7211.   Returns:
  7212.     -1L on error, otherwise:
  7213.     The number of days since 17 Nov 1858 as a whole number:
  7214.     16 Nov 1858 = -1, 17 Nov 1858 = 0, 18 Nov 1858 = 1, 19 Nov 1858 = 2, ...
  7215.  
  7216.   The Modified Julian Date is defined by the International Astronomical
  7217.   Union as the true Julian date minus 2400000.5 days.  The true Julian
  7218.   date is the number days since since noon of 1 January 4713 BCE of the
  7219.   Julian proleptic calendar.  Conversions between calendar dates and
  7220.   Julian dates, however, assume Gregorian dating.
  7221. */
  7222. long
  7223. mjd(date) char * date; {
  7224.     char year[5];
  7225.     char month[3];
  7226.     char day[3];
  7227.     int x, a, d, m, y;
  7228.     long z;
  7229.  
  7230.     if (!date) date = "";               /* Validate arg */
  7231.     x = strlen(date);
  7232.     if (x < 1) return(0L);
  7233.     if (x < 8) return(-1L);
  7234.     for (x = 0; x < 8; x++)
  7235.       if (!isdigit(date[x]))
  7236.         return(-1L);
  7237.  
  7238.     year[0] = date[0];                  /* Isolate year */
  7239.     year[1] = date[1];
  7240.     year[2] = date[2];
  7241.     year[3] = date[3];
  7242.     year[4] = '\0';
  7243.  
  7244.     month[0] = date[4];                 /* Month */
  7245.     month[1] = date[5];
  7246.     month[2] = '\0';;
  7247.     m = atoi(month);
  7248.  
  7249.     day[0] = date[6];                   /* And day */
  7250.     day[1] = date[7];
  7251.     day[2] = '\0';
  7252.     d = atoi(day);
  7253.  
  7254.     a = (14-m)/12;            /* Calculate true Julian date */
  7255.     y = atoi(year) + 4800 - a;
  7256.     m = m + 12 * a - 3;
  7257.     z = d + (long)(306*m+5)/10 + (long)(y*365) + y/4 - y/100 + y/400 - 32045L;
  7258.  
  7259.     z -= 2400001L;            /* Convert JD to MJD */
  7260.  
  7261.     return(z);
  7262. }
  7263.  
  7264. static char mjd2dbuf[32];
  7265.  
  7266. /*  M J D 2 D A T E  --  Converts MJD to yyyymmdd  */
  7267.  
  7268. char *
  7269. #ifdef CK_ANSIC
  7270. mjd2date(long mjd)
  7271. #else
  7272. mjd2date(mjd) long mjd;
  7273. #endif /* CK_ANSIC */
  7274. /* mjd2date */ {
  7275.     long jd, l, n;
  7276.     int d, m, y;
  7277.     jd = (long)(mjd + 2400001L);
  7278.     l = jd + 68569;
  7279.     n = 4 * l / 146097L;
  7280.     l = l - (146097 * n + 3) / 4;
  7281.     y = 4000 * (l + 1) / 1461001L;
  7282.     l = l - 1461 * y / 4 + 31;
  7283.     m = 80 * l / 2447;
  7284.     d = l - 2447 * m / 80;
  7285.     l = m / 11;
  7286.     m = m + 2 - 12 * l;
  7287.     y = 100 * (n - 49) + y + l;
  7288.     sprintf(mjd2dbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7289.     return((char *)mjd2dbuf);
  7290. }
  7291.  
  7292. #ifndef NOSPL
  7293. static char ** flist = (char **) NULL;  /* File list for \fnextfile() */
  7294. static int flistn = 0;                  /* Number of items in file list */
  7295.  
  7296. /*
  7297.   The function return-value buffer must be global, since fneval() returns a
  7298.   pointer to it.  fneval() is called only by zzstring(), which always copies
  7299.   the result out of this buffer to somewhere else, so it's OK to have only
  7300.   one buffer for this in most cases.  However, since function calls can be
  7301.   nested -- e.g. functions whose arguments are functions, or recursive
  7302.   functions, at some point we should convert this to an array of buffers,
  7303.   indexed by function depth (which might or might not be the same as the
  7304.   "depth" variable).  Also, since function results are potentially quite big,
  7305.   we'd need to allocate and deallocate dynamically as we descend and ascend
  7306.   function depth.  Left for a future release...
  7307. */
  7308. char fnval[FNVALL+2];                   /* Function return value  */
  7309. static int fndepth = 0;                 /* (we don't actually use this yet) */
  7310. int fnsuccess = 1;
  7311. extern int fnerror;
  7312.  
  7313. /* f p f o r m a t  --  Floating-point number nicely formatted.  */
  7314. /*
  7315.    Returns results from a circular 1K buffer.
  7316.    Don't count on too many results remaining available at once; it could
  7317.    be anywhere from 5 to maybe 100, depending on the sizes of the results.
  7318. */
  7319. #ifdef CKFLOAT
  7320. #define FPFMTSIZ 1024
  7321. static char fpfmtbuf[FPFMTSIZ] = { NUL, NUL };
  7322. static int fpfbufpos = 0;        /* (why was this char before?) */
  7323.  
  7324. char *
  7325. fpformat(fpresult,places,round) CKFLOAT fpresult; int places, round; {
  7326.     char fbuf[16];            /* For creating printf format */
  7327.     int nines = 0, sign = 0, x, y, i, j, size = 0;
  7328.     char * buf;
  7329.     CKFLOAT ftmp;
  7330.  
  7331.     x = places ? places : (fp_digits ? fp_digits : 6);
  7332.  
  7333.     debug(F101,"fpformat fpresult","",fpresult);
  7334.     debug(F101,"fpformat places","",places);
  7335.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7336.  
  7337.     ftmp = fpresult;
  7338.     if (ftmp < 0.0) ftmp = 0.0 - fpresult;
  7339.  
  7340. #ifdef FNFLOAT
  7341.     if (!fp_rounding &&            /* If printf doesn't round, */
  7342.     (places > 0 ||            /* round result to decimal places. */
  7343.      (places == 0 && round)))
  7344.       fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  7345.     y = (ftmp == 0.0) ? 1 : (int)log10(ftmp);
  7346.     size = y + x + 3;            /* Estimated length of result */
  7347.     if (fpresult < 0.0) size++;
  7348. #else
  7349.     size = 200;                /* No way to estimate, be generous */
  7350. #endif /* FNFLOAT */
  7351.  
  7352.     debug(F101,"fpformat size","",size);
  7353.  
  7354.     if (fpfbufpos > (FPFMTSIZ - size))    /* Wrap around if necessary */
  7355.       fpfbufpos = 0;
  7356.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7357.  
  7358.     buf = &fpfmtbuf[fpfbufpos];
  7359.  
  7360.     if (places > 0) {                   /* If places specified */
  7361.     /* use specified places to write given number of digits */
  7362.     sprintf(fbuf,"%%0.%df",places);    /* SAFE */
  7363.     sprintf(buf,fbuf,fpresult);    /* SAFE */
  7364.     } else {                /* Otherwise... */
  7365.     /* Go for max precision */
  7366.     sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  7367.     sprintf(buf,fbuf,fpresult);    /* SAFE */
  7368.     }
  7369.     if (buf[0] == '-') sign = 1;
  7370.     debug(F111,"fpresult 1 errno",buf,errno); /* Check for over/underflow */
  7371.     debug(F111,"fpresult 1 fpfbufpos",buf,fpfbufpos);
  7372.     /* Give requested decimal places */
  7373.     for (i = sign; i < FPFMTSIZ && buf[i]; i++) {
  7374.     if (buf[i] == '.')        /* First find the decimal point */
  7375.       break;
  7376.     else if (i > fp_digits + sign - 1) /* replacing garbage */
  7377.       buf[i] = '0';            /* digits with 0... */
  7378.     }
  7379.     if (buf[i] == '.') {        /* Have decimal point */
  7380.     int gotend = 0;
  7381.     /* places < 0 so truncate fraction */
  7382.     if (places < 0 || (places == 0 && round)) {
  7383.         buf[i] = NUL;
  7384.     } else if (places > 0) {    /* d > 0 so this many decimal places */
  7385.         i++;                           /* First digit after decimal */
  7386.         for (j = 0; j < places; j++) { /* Truncate after d decimal */
  7387.         if (!buf[j+i])        /* places or extend to d  */
  7388.           gotend = 1;              /* decimal places. */
  7389.         if (gotend || j+i+sign > fp_digits)
  7390.           buf[j+i] = '0';
  7391.         }
  7392.         buf[j+i] = NUL;
  7393.     } else {            /* places == 0 so Do The Right Thing */
  7394.         for (j = (int)strlen(buf) - 1; j > i+1; j--) {
  7395.         if ((j - sign) > fp_digits)
  7396.           buf[j] = '0';
  7397.         if (buf[j] == '0')
  7398.           buf[j] = NUL;    /* Strip useless trailing 0's. */
  7399.         else
  7400.           break;
  7401.         }
  7402.     }
  7403.     }
  7404.     fpfmtbuf[FPFMTSIZ-1] = NUL;
  7405.     j = strlen(buf);
  7406.     sign = 0;
  7407.     for (i = j-1; i >= 0; i--) {
  7408.     if (buf[i] == '9')
  7409.       nines++;
  7410.     else
  7411.       break;
  7412.     }
  7413.     /* Do something about xx.xx99999999... */
  7414.     if (nines > 5) {
  7415.     if (isdigit(buf[i]) && i < FPFMTSIZ - 2) {
  7416.         buf[i] = buf[i] + 1;
  7417.         buf[i+1] = '0';
  7418.         buf[i+2] = '\0';
  7419.     }
  7420.     }
  7421.     if (!strncmp(buf,"-0.0",FPFMTSIZ))
  7422.       ckstrncpy(buf,"0.0",FPFMTSIZ);
  7423.     fpfbufpos += (int)strlen(buf) + 1;
  7424.     return((char *)buf);
  7425. }
  7426. #endif /* CKFLOAT */
  7427.  
  7428. static VOID
  7429. evalerr(fn) char * fn; {
  7430.     if (fndiags) {
  7431.     if (divbyzero)
  7432.       ckmakmsg(fnval,FNVALL,"<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  7433.     else
  7434.       ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  7435.     }
  7436. }
  7437.  
  7438. char *
  7439. dokwval(s,sep) char * s, sep; {
  7440.     char c = '\0', * p, * kw = NULL, * vp = NULL;
  7441.     int x;
  7442.     if (!s) return("0");
  7443.     if (!*s) return("0");
  7444.     debug(F110,"kwval arg",s,0);
  7445.     debug(F110,"kwval sep",ckctoa(sep),0);
  7446.     p = (char *)malloc((int)strlen(s)+1);
  7447.     if (!p) return("0");
  7448.     strcpy(p,s);            /* SAFE */
  7449.     s = p;
  7450.     while (*s < '!' && *s > '\0')    /* Get first nonblank */
  7451.       s++;
  7452.     if (!*s) return("0");
  7453.     if (*s == sep) return("0");
  7454.     kw = s;                /* Keyword */
  7455.     while (*s > ' ') {
  7456.     if (*s == sep) {        /* keyword=... */
  7457.         c = *s;
  7458.         break;
  7459.     }
  7460.     s++;
  7461.     }
  7462.     *s++ = NUL;                /* Terminate keyword */
  7463.     while (*s < '!' && *s > '\0')    /* Skip blanks */
  7464.       s++;
  7465.     if (!c && *s == sep) {
  7466.     c = *s++;            /* Have separator */
  7467.     while (*s < '!' && *s > '\0')    /* Skip blanks */
  7468.       s++;
  7469.     }
  7470.     if (c) {
  7471.     vp = s;
  7472.     while (*s > ' ')        /* Skip to end */
  7473.       s++;
  7474.     *s = NUL;            /* Terminate value */
  7475.     }
  7476.     debug(F110,"kwval c",ckctoa(c),0);
  7477.     debug(F110,"kwval keyword",kw,0);
  7478.     debug(F110,"kwval value",vp,0);
  7479.     x = c ? addmac(kw,vp) : -1;
  7480.     free(p);
  7481.     return((x < 0) ? "0" : "1");
  7482. }
  7483.  
  7484.  
  7485. static char *                           /* Evaluate builtin functions */
  7486. fneval(fn,argp,argn,xp) char *fn, *argp[]; int argn; char * xp; {
  7487.     int i=0, j=0, k=0, len1=0, len2=0, len3=0, n=0, t=0, x=0, y=0;
  7488.     int cx, failed = 0;            /* Return code, 0 = ok */
  7489.     long z = 0L;
  7490.     char *bp[FNARGS + 1];               /* Pointers to malloc'd strings */
  7491.     char c = NUL;
  7492.     char *p = NULL, *s = NULL;
  7493.     char *val1 = NULL, *val2 = NULL;    /* Pointers to numeric string values */
  7494.  
  7495. #ifdef RECURSIVE
  7496.     int rsave = recursive;
  7497. #endif /* RECURSIVE */
  7498. #ifdef OS2
  7499.     int zsave = zxpn;
  7500. #endif /* OS2 */
  7501.  
  7502.     if (!fn) fn = "";                   /* Protect against null pointers */
  7503.     if (!*fn) return("");
  7504.  
  7505.     for (i = 0; i < FNARGS; i++)        /* Initialize argument pointers */
  7506.       bp[i] = NULL;
  7507. /*
  7508.   IMPORTANT: Note that argn is not an accurate count of the number of
  7509.   arguments.  We can't really tell if an argument is null until after we
  7510.   execute the code below.  So argn is really the maximum number of arguments
  7511.   we might have.  Argn should always be at least 1, even if the function is
  7512.   called with empty parentheses (but don't count on it).
  7513. */
  7514.     debug(F111,"fneval",fn,argn);
  7515.     debug(F110,"fneval",argp[0],0);
  7516.     if (argn > FNARGS)                  /* Discard excess arguments */
  7517.       argn = FNARGS;
  7518.  
  7519.     fndepth++;
  7520.     debug(F101,"fneval fndepth","",fndepth);
  7521.     p = fnval;
  7522.     fnval[0] = NUL;
  7523.     y = lookup(fnctab,fn,nfuncs,&x);    /* Look up the function name */
  7524.     cx = y;                /* Because y is too generic... */
  7525.     if (cx < 0) {                        /* Not found */
  7526.         failed = 1;
  7527.         if (fndiags) {                  /* FUNCTION DIAGNOSTIC ON */
  7528.             int x;
  7529.             x = strlen(fn);
  7530.         /* The following sprintf's are safe */
  7531.             switch (cx) {
  7532.               case -1:
  7533.                 if (x + 32 < FNVALL)
  7534.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION:\\f%s()>",fn);
  7535.                 else
  7536.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION>");
  7537.                 break;
  7538.               case -2:
  7539.                 if (x + 26 < FNVALL)
  7540.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS:\\f%s()>",fn);
  7541.                 else
  7542.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS>");
  7543.                 break;
  7544.               case -3:
  7545.                 sprintf(fnval,"<ERROR:FUNCTION_NAME_MISSING:\\f()>");
  7546.                 break;
  7547.               default:
  7548.                 if (x + 26 < FNVALL)
  7549.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE:\\f%s()>",fn);
  7550.                 else
  7551.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE>");
  7552.                 break;
  7553.             }
  7554.         }
  7555.         goto fnend;                     /* Always leave via common exit */
  7556.     }
  7557.     fn = fnctab[x].kwd;            /* Full name of function */
  7558.  
  7559.     if (argn < 0) {
  7560.     failed = 1;
  7561.     p = fnval;
  7562.     if (fndiags)
  7563.       sprintf(fnval,"<ERROR:MISSING_ARG:\\f%s()>",fn);
  7564.     goto fnend;
  7565.     }
  7566.     if (cx == FN_LIT) {            /* literal(arg1) */
  7567.         debug(F010,"flit",xp,0);
  7568.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7569.         goto fnend;
  7570.     }
  7571.  
  7572. #ifdef DEBUG
  7573.     if (deblog) {
  7574.         int j;
  7575.         for (j = 0; j < argn; j++)
  7576.           debug(F111,"fneval arg",argp[j],j);
  7577.     }
  7578. #endif /* DEBUG */
  7579.     for (j = argn-1; j >= 0; j--) {     /* Uncount empty trailing args */
  7580.         if (!argp[j])
  7581.           argn--;
  7582.         else if (!*(argp[j]))
  7583.           argn--;
  7584.         else break;
  7585.     }
  7586.     debug(F111,"fneval argn",fn,argn);
  7587. /*
  7588.   \fliteral() and \fcontents() are special functions that do not evaluate
  7589.   their arguments, and are treated specially here.  After these come the
  7590.   functions whose arguments are evaluated in the normal way.
  7591. */
  7592. #ifdef COMMENT
  7593.     /* (moved up) */
  7594.     if (cx == FN_LIT) {            /* literal(arg1) */
  7595.         debug(F110,"flit",xp,0);
  7596.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7597.         goto fnend;
  7598.     }
  7599. #endif /* COMMENT */
  7600.     if (cx == FN_CON) {            /* Contents of variable, unexpanded. */
  7601.         char c;
  7602.         if (!(p = argp[0]) || !*p) {
  7603.             failed = 1;
  7604.             p = fnval;
  7605.             if (fndiags)
  7606.               sprintf(fnval,"<ERROR:MISSING_ARG:\\fcontents()>");
  7607.             goto fnend;
  7608.         }
  7609.         p = brstrip(p);
  7610.         if (*p == CMDQ) p++;
  7611.         if ((c = *p) == '%') {          /* Scalar variable. */
  7612.             c = *++p;                   /* Get ID character. */
  7613.             p = "";                     /* Assume definition is empty */
  7614.             if (!c) {                   /* Double paranoia */
  7615.                 failed = 1;
  7616.                 p = fnval;
  7617.                 if (fndiags)
  7618.                   sprintf(fnval,"<ERROR:ARG_BAD_VARIABLE:\\fcontents()>");
  7619.                 goto fnend;
  7620.             }
  7621.             if (c >= '0' && c <= '9') { /* Digit for macro arg */
  7622.                 if (maclvl < 0)         /* Digit variables are global */
  7623.                   p = g_var[c];         /* if no macro is active */
  7624.                 else                    /* otherwise */
  7625.                   p = m_arg[maclvl][c - '0']; /* they're on the stack */
  7626.             } else if (c == '*') {
  7627. #ifdef COMMENT
  7628.                 p = (maclvl > -1) ? m_line[maclvl] : topline;
  7629.                 if (!p) p = "";
  7630. #else
  7631.         int nx = FNVALL;
  7632.         char * sx = fnval;
  7633.         p = fnval;
  7634. #ifdef COMMENT
  7635.         if (cmdsrc() == 0 && topline)
  7636.           p = topline;
  7637.         else
  7638. #endif /* COMMENT */
  7639.           if (zzstring("\\fjoin(&_[],{ },1)",&sx,&nx) < 0) {
  7640.             failed = 1;
  7641.             p = fnval;
  7642.             if (fndiags)
  7643.               sprintf(fnval,"<ERROR:OVERFLOW:\\fcontents()>");
  7644.         }
  7645. #endif /* COMMENT */
  7646.             } else {
  7647.                 if (isupper(c)) c -= ('a'-'A');
  7648.                 p = g_var[c];           /* Letter for global variable */
  7649.             }
  7650.             if (!p) p = "";
  7651.             goto fnend;
  7652.         } else if (c == '&') {        /* Array reference. */
  7653.             int vbi, d;
  7654.             if (arraynam(p,&vbi,&d) < 0) { /* Get name and subscript */
  7655.                 failed = 1;
  7656.                 p = fnval;
  7657.                 if (fndiags)
  7658.                   sprintf(fnval,"<ERROR:ARG_BAD_ARRAY:\\fcontents()>");
  7659.                 goto fnend;
  7660.             }
  7661.             if (chkarray(vbi,d) > 0) {  /* Array is declared? */
  7662.                 vbi -= ARRAYBASE;       /* Convert name to index */
  7663.                 if (a_dim[vbi] >= d) {  /* If subscript in range */
  7664.                     char **ap;
  7665.                     ap = a_ptr[vbi];    /* get data pointer */
  7666.                     if (ap) {           /* and if there is one */
  7667.                         p = ap[d];
  7668.                         goto fnend;
  7669.                     }
  7670.                 }
  7671.             } else {
  7672.                 failed = 1;
  7673.                 p = fnval;
  7674.                 if (fndiags)
  7675.                   sprintf(fnval,"<ERROR:ARG_NOT_ARRAY:\\fcontents()>");
  7676.                 goto fnend;
  7677.             }
  7678.         } else {
  7679.             failed = 1;
  7680.             p = fnval;
  7681.             if (fndiags)
  7682.               sprintf(fnval,"<ERROR:ARG_NOT_VARIABLE:\\fcontents()>");
  7683.             goto fnend;
  7684.         }
  7685.     }
  7686.     p = fnval;                          /* Default result pointer */
  7687.     fnval[0] = NUL;                     /* Default result = empty string */
  7688.  
  7689.  
  7690.     for (i = 0; i < argn; i++) {        /* Loop to expand each argument */
  7691.     n = MAXARGLEN;            /* Allow plenty of space */
  7692.         bp[i] = s = malloc(n+1);        /* Allocate space for this argument */
  7693.         if (bp[i] == NULL) {            /* Handle failure to get space */
  7694.             failed = 1;
  7695.             if (fndiags)
  7696.               ckmakmsg(fnval,FNVALL,"<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  7697.             goto fnend;
  7698.         }
  7699.         p = argp[i] ? argp[i] : "";     /* Point to this argument */
  7700.  
  7701. /*
  7702.   Trim leading and trailing spaces from the original argument, before
  7703.   evaluation.  This code new to edit 184.  Fixed in edit 199 to trim
  7704.   blanks BEFORE stripping braces.
  7705.  
  7706. */
  7707.         {
  7708.             int x, j;
  7709.             x = strlen(p);
  7710.         j = x - 1;            /* Trim trailing whitespace */
  7711.         while (j > 0 && (*(p + j) == SP || *(p + j) == HT))
  7712.           *(p + j--) = NUL;
  7713.         while (*p == SP || *p == HT) /* Strip leading whitespace */
  7714.           p++;
  7715.             x = strlen(p);
  7716.             if (*p == '{' && *(p+x-1) == '}') {    /* NOW strip braces */
  7717.                 p[x-1] = NUL;
  7718.                 p++;
  7719.                 x -= 2;
  7720.             }
  7721.         }
  7722.  
  7723. /* Now evaluate the argument */
  7724.  
  7725.         debug(F111,"fneval calling zzstring",p,n);
  7726.         t = zzstring(p,&s,&n);          /* Expand arg into new space */
  7727.         debug(F101,"fneval zzstring","",t);
  7728.         debug(F101,"fneval zzstring","",n);
  7729.         if (t < 0) {
  7730.             debug(F101,"fneval zzstring fails, arg","",i);
  7731.             failed = 1;
  7732.             if (fndiags) {
  7733.                 if (n == 0)
  7734.                   ckmakmsg(fnval,FNVALL,
  7735.                "<ERROR:ARG_TOO_LONG:\\f",fn,"()>",NULL);
  7736.                 else
  7737.                   ckmakmsg(fnval,FNVALL,
  7738.                "<ERROR:ARG_EVAL_FAILURE:\\f",fn,"()>",NULL);
  7739.             }
  7740.             goto fnend;
  7741.         }
  7742.         debug(F111,"fneval arg",bp[i],i);
  7743.     }
  7744.  
  7745. #ifdef DEBUG
  7746.     if (deblog) {
  7747.         int j;
  7748.         for (j = 0; j < argn; j++) {
  7749.             debug(F111,"fneval arg post eval",argp[j],j);
  7750.             debug(F111,"fneval evaluated arg",bp[j],j);
  7751.         }
  7752.     }
  7753. #endif /* DEBUG */
  7754. /*
  7755.   From this point on, bp[0..argn-1] are not NULL and all must be freed
  7756.   before returning.
  7757. */
  7758.     if (argn < 1) {                     /* Catch required args missing */
  7759.         switch (cx) {
  7760.           case FN_DEF:
  7761.           case FN_EVA:
  7762.           case FN_EXE:
  7763.           case FN_CHR:
  7764.           case FN_COD:
  7765.           case FN_MAX:
  7766.           case FN_MIN:
  7767.           case FN_MOD:
  7768.           case FN_FD:
  7769.           case FN_FS:
  7770.           case FN_TOD:
  7771.           case FN_FFN:
  7772.           case FN_BSN:
  7773.           case FN_RAW:
  7774.           case FN_CMD:
  7775.           case FN_2HEX:
  7776.           case FN_2OCT:
  7777.           case FN_DNAM:
  7778. #ifdef FN_ERRMSG
  7779.           case FN_ERRMSG:
  7780. #endif /* FN_ERRMSG */
  7781. #ifdef CK_KERBEROS
  7782.           case FN_KRB_TK:
  7783.           case FN_KRB_NX:
  7784.           case FN_KRB_IV:
  7785.           case FN_KRB_TT:
  7786.           case FN_KRB_FG:
  7787. #endif /* CK_KERBEROS */
  7788.           case FN_MJD2:
  7789.           case FN_N2TIM:
  7790.           case FN_DIM:
  7791.           case FN_DATEJ:
  7792.           case FN_PNCVT:
  7793.           case FN_PERM:
  7794.           case FN_ALOOK:
  7795.           case FN_TLOOK:
  7796.           case FN_ABS:
  7797.           case FN_AADUMP:
  7798.       case FN_JOIN:
  7799. #ifdef CKFLOAT
  7800.           case FN_FPABS:
  7801.           case FN_FPEXP:
  7802.           case FN_FPLOG:
  7803.           case FN_FPLN:
  7804.           case FN_FPMOD:
  7805.           case FN_FPSQR:
  7806.           case FN_FPADD:
  7807.           case FN_FPDIV:
  7808.           case FN_FPMUL:
  7809.           case FN_FPPOW:
  7810.           case FN_FPSUB:
  7811.           case FN_FPINT:
  7812.           case FN_FPROU:
  7813.           case FN_FPSIN:
  7814.           case FN_FPCOS:
  7815.           case FN_FPTAN:
  7816. #endif /* CKFLOAT */
  7817. #ifdef TCPSOCKET
  7818.           case FN_HSTADD:
  7819.           case FN_HSTNAM:
  7820. #endif /* TCPSOCKET */
  7821.       case FN_DELSEC:
  7822.       case FN_KWVAL:
  7823.       case FN_SLEEP:
  7824.       case FN_MSLEEP:
  7825.             failed = 1;
  7826.             p = fnval;
  7827.             if (fndiags)
  7828.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  7829.             goto fnend;
  7830.         }
  7831.     }
  7832.     p = fnval;                          /* Reset these again. */
  7833.     fnval[0] = NUL;
  7834.  
  7835.     switch (cx) {            /* Do function on expanded args. */
  7836. #ifdef TCPSOCKET
  7837.       case FN_HSTADD:
  7838.         p = ckaddr2name(bp[0]);
  7839.         goto fnend;
  7840.       case FN_HSTNAM:
  7841.         p = ckname2addr(bp[0]);
  7842.         goto fnend;
  7843. #endif /* TCPSOCKET */
  7844.  
  7845.       case FN_DEF:                      /* \fdefinition(arg1) */
  7846.         k = mxlook(mactab,bp[0],nmac);
  7847.         p = (k > -1) ? mactab[k].mval : "";
  7848.         goto fnend;
  7849.  
  7850.       case FN_EVA:                      /* \fevaluate(arg1) */
  7851.         p = *(bp[0]) ? evalx(bp[0]) : "";
  7852.         if (!*p && fndiags) {
  7853.             failed = 1;
  7854.             p = fnval;
  7855.         evalerr(fn);
  7856.         }
  7857.         goto fnend;
  7858.  
  7859.       case FN_EXE:                      /* \fexecute(arg1) */
  7860.         j = (int)strlen(s = bp[0]);     /* Length of macro invocation */
  7861.         p = "";                         /* Initialize return value to null */
  7862.         if (j) {                        /* If there is a macro to execute */
  7863.             while (*s == SP) s++,j--;   /* strip leading spaces */
  7864.             p = s;                      /* remember beginning of macro name */
  7865.             for (i = 0; i < j; i++) {   /* find end of macro name */
  7866.                 if (*s == SP)
  7867.                   break;
  7868.                 s++;
  7869.             }
  7870.             if (*s == SP)       {       /* if there was a space after */
  7871.                 *s++ = NUL;             /* terminate the macro name */
  7872.                 while (*s == SP) s++;   /* skip past any extra spaces */
  7873.             } else
  7874.           s = "";            /* maybe there are no arguments */
  7875.             if (p && *p) {
  7876.         k = mlook(mactab,p,nmac); /* Look up the macro name */
  7877.         debug(F111,"fexec mlook",p,k);
  7878.             } else
  7879.               k = -1;
  7880.             if (k < 0) {
  7881.         char * p2 = p;
  7882.                 failed = 1;
  7883.                 p = fnval;
  7884.                 if (fndiags)
  7885.                   ckmakxmsg(fnval,FNVALL,
  7886.                 "<ERROR:NO_SUCH_MACRO:\\f",fn,"(",p2,")>",
  7887.                 NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  7888.                 goto fnend;
  7889.             }
  7890. /*
  7891.   This is just a WEE bit dangerous because we are copying up to 9 arguments
  7892.   into the space reserved for one.  It won't overrun the buffer, but if there
  7893.   are lots of long arguments we might lose some.  The other problem is that if
  7894.   the macro has more than 3 arguments, the 4th through last are all
  7895.   concatenated onto the third.  (The workaround is to use spaces rather than
  7896.   commas to separate them.)  Leaving it like this to avoid having to allocate
  7897.   tons more buffers.
  7898. */
  7899.             if (argn > 1) {             /* Commas used instead of spaces */
  7900.                 int i;
  7901.                 char *p = bp[0];        /* Reuse this space */
  7902.                 *p = NUL;               /* Make into dodo() arg list */
  7903.                 for (i = 1; i < argn; i++) {
  7904.                     strncat(p,bp[i],MAXARGLEN);
  7905.                     strncat(p," ",MAXARGLEN);
  7906.                 }
  7907.                 s = bp[0];              /* Point to new list */
  7908.             }
  7909.             p = "";                     /* Initialize return value */
  7910.             if (k >= 0) {               /* If macro found in table */
  7911.                 /* Go set it up (like DO cmd) */
  7912.                 if ((j = dodo(k,s,cmdstk[cmdlvl].ccflgs)) > 0) {
  7913.                     if (cmpush() > -1) { /* Push command parser state */
  7914.                         extern int ifc;
  7915.                         int ifcsav = ifc; /* Push IF condition on stack */
  7916.                         k = parser(1);  /* Call parser to execute the macro */
  7917.                         cmpop();        /* Pop command parser */
  7918.                         ifc = ifcsav;   /* Restore IF condition */
  7919.                         if (k == 0) {   /* No errors, ignore action cmds. */
  7920.                             p = mrval[maclvl+1]; /* If OK, set return value. */
  7921.                             if (p == NULL) p = "";
  7922.                         }
  7923.                     } else {            /* Can't push any more */
  7924.                         debug(F100,"zzstring fneval fexec failure","",0);
  7925.                         printf("\n?\\fexec() too deeply nested\n");
  7926.                         while (cmpop() > -1) ;
  7927.                         p = "";
  7928.                     }
  7929.                 }
  7930.             }
  7931.         }
  7932.     debug(F110,"zzstring fneval fexecute final p",p,0);
  7933.         goto fnend;
  7934.  
  7935. #ifdef RECURSIVE
  7936.       case FN_RDIR:                     /* \frdir..() - Recursive dir count */
  7937.       case FN_RFIL:                     /* \frfiles() - Recursive file count */
  7938.         /* recursive = 2; */            /* fall thru... */
  7939. #endif /* RECURSIVE */
  7940.       case FN_FC:                       /* \ffiles() - File count. */
  7941.       case FN_DIR: {                    /* \ffdir.() - Directory count. */
  7942.           char abuf[16], *s;
  7943.           char ** ap = NULL;
  7944.           int x, xflags = 0;
  7945.           if (matchdot)
  7946.             xflags |= ZX_MATCHDOT;
  7947.           if (cx == FN_RDIR || cx == FN_RFIL) {
  7948.           xflags |= ZX_RECURSE;
  7949. #ifdef CKSYMLINK
  7950.           /* Recursive - don't follow symlinks */
  7951.           xflags |= ZX_NOLINKS;
  7952. #endif /* CKSYMLINK */
  7953.       }
  7954.           failed = 0;
  7955.           if (argn < 1) {
  7956.               p = "0";
  7957.               goto fnend;
  7958.           }
  7959.           if (cx == FN_DIR || cx == FN_RDIR) { /* Only list directories */
  7960.               xflags |= ZX_DIRONLY;
  7961. #ifdef OS2
  7962.               zxpn = 1;                 /* Use the alternate list */
  7963. #endif /* OS2 */
  7964.           } else {                      /* List only files */
  7965.               xflags |= ZX_FILONLY;
  7966. #ifdef OS2
  7967.               zxpn = 1;                 /* Use the alternate list */
  7968. #endif /* OS2 */
  7969.           }
  7970.           if (*(bp[0])) {
  7971.               k = nzxpand(bp[0],xflags);
  7972.               if (k < 0) k = 0;
  7973.               sprintf(fnval,"%d",k);    /* SAFE */
  7974.               p = fnval;
  7975.           } else
  7976.             p = "0";
  7977.  
  7978.           if (argn > 1) {               /* Assign list to array */
  7979.               fnval[0] = NUL;           /* Initial return value */
  7980.               ckstrncpy(abuf,bp[1],16); /* Get array reference */
  7981.               s = abuf;
  7982.               if (*s == CMDQ) s++;
  7983.               failed = 1;               /* Assume it's bad */
  7984.               p = fnval;                /* Point to result */
  7985.               if (fndiags)              /* Default is this error message */
  7986.                 ckmakmsg(fnval,FNVALL,
  7987.              "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  7988.               if (s[0] != '&')          /* "Address" of array */
  7989.                 goto fnend;
  7990.               if (s[2])
  7991.                 if (s[2] != '[' || s[3] != ']')
  7992.                   goto fnend;
  7993.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  7994.                 s[1] += 32;
  7995.               if ((x = dclarray(s[1],k)) < 0) /* File list plus count */
  7996.                 goto fnend;
  7997.               failed = 0;               /* Unset failure flag */
  7998.               ap = a_ptr[x];            /* Point to array we just declared */
  7999.               sprintf(fnval,"%d",k);    /* SAFE */
  8000.           }
  8001. #ifdef OS2
  8002.           if (ap) {                     /* We are making an array */
  8003.               int i;
  8004.               char tmp[16];
  8005.               ap[0] = NULL;             /* Containing number of files    */
  8006.               makestr(&(ap[0]),ckitoa(k));
  8007.  
  8008.               ckstrncpy(tmp,fnval,16);  /* Save return value */
  8009.  
  8010.               for (i = 1; i <= k; i++) { /* Fill it */
  8011.                   ap[i] = NULL;
  8012.                   znext(fnval);         /* Next filename */
  8013.                   if (!*fnval)          /* No more, done */
  8014.                     break;              /* In case a premature end */
  8015.                   makestr(&(ap[i]),fnval);
  8016.               }
  8017. #ifdef ZXREWIND
  8018.               k = zxrewind();           /* Reset the file expansion */
  8019. #else
  8020.               k = nzxpand(bp[0],xflags);
  8021. #endif /* ZXREWIND */
  8022.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8023.           }
  8024. #else /* OS2 */
  8025.           {                             /* Make copies of the list */
  8026.               int i; char tmp[16];
  8027.               if (flist) {              /* Free old file list, if any */
  8028.                   for (i = 0; flist[i]; i++) { /* and each string */
  8029.                       free(flist[i]);
  8030.                       flist[i] = NULL;
  8031.                   }
  8032.                   free((char *)flist);
  8033.               }
  8034.               ckstrncpy(tmp,fnval,16);  /* Save our return value */
  8035.               flist = (char **) malloc((k+1) * sizeof(char *)); /* New array */
  8036.               if (flist) {
  8037.                   for (i = 0; i <= k; i++) { /* Fill it */
  8038.                       flist[i] = NULL;
  8039.                       znext(fnval);     /* Next filename */
  8040.                       if (!*fnval)      /* No more, done */
  8041.                         break;
  8042.                       makestr(&(flist[i]),fnval);
  8043.                   }
  8044.                   if (ap) {             /* If array pointer given */
  8045.                       ap[0] = NULL;
  8046.                       makestr(&(ap[0]),ckitoa(k));
  8047.                       for (i = 0; i < k; i++) { /* Copy file list to array */
  8048.                           ap[i+1] = NULL;
  8049.                           makestr(&(ap[i+1]),flist[i]);
  8050.                       }
  8051.                   }
  8052.               }
  8053.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8054.               flistn = 0;               /* Reset global list pointer */
  8055.           }
  8056. #endif /* OS2 */
  8057. #ifdef RECURSIVE
  8058.           recursive = rsave;
  8059. #endif /* RECURSIVE */
  8060. #ifdef OS2
  8061.           zxpn = zsave;
  8062. #endif /* OS2 */
  8063.       }
  8064.       goto fnend;
  8065.  
  8066.       case FN_FIL:                      /* \fnextfile() - Next file in list. */
  8067.         p = fnval;                      /* (no args) */
  8068.         *p = NUL;
  8069. #ifdef OS2
  8070.         zxpn = 1;                       /* OS/2 - use the alternate list */
  8071.         znext(p);                       /* Call system-dependent function */
  8072.         zxpn = zsave;                   /* Restore original list */
  8073. #else
  8074.         if (flist)                      /* Others, use our own list. */
  8075.           if (flist[flistn])
  8076.             p = flist[flistn++];
  8077. #endif /* OS2 */
  8078.         goto fnend;
  8079.  
  8080.     } /* Break up big switch... */
  8081.  
  8082.     switch (cx) {
  8083.       case FN_IND:                      /* \findex(s1,s2,start) */
  8084.       case FN_RIX:                      /* \frindex(s1,s2,start) */
  8085.       case FN_SEARCH:                   /* \fsearch(pat,string,start) */
  8086.       case FN_RSEARCH: {                /* \frsearch(pat,string,start) */
  8087.         int i = 0, right = 0, search = 0;
  8088.         right = (cx == FN_RIX || cx == FN_RSEARCH);
  8089.         search = (cx == FN_SEARCH || cx == FN_RSEARCH);
  8090.         p = "0";
  8091.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8092.             int start = 0;
  8093.             char * pat = NULL;
  8094.             len1 = (int)strlen(pat = bp[0]); /* length of string to look for */
  8095.             len2 = (int)strlen(s = bp[1]); /* length of string to look in */
  8096.             if (len1 < 1 || len2 < 1)   /* Watch out for empty strings */
  8097.               goto fnend;
  8098.             start = right ? -1 : 0;     /* Default starting position */
  8099.             if (argn > 2) {
  8100.                 val1 = *(bp[2]) ? evalx(bp[2]) : "1";
  8101.                 if (chknum(val1)) {
  8102.                     int t;
  8103.                     t = atoi(val1);
  8104.                     if (!search) {      /* Index or Rindex */
  8105.                         j = len2 - len1; /* Length difference */
  8106.                         t--;             /* Convert position to 0-based */
  8107.                         if (t < 0) t = 0;
  8108.                         start = t;
  8109.                         if (!right && start < 0) start = 0;
  8110.                     } else {            /* Search or Rsearch */
  8111.                         int x;
  8112.                         if (t < 0) t = 0;
  8113.                         if (right) {    /* Right to left */
  8114.                             if (t > len2) t = len2;
  8115.                             start = len2 - t - 1;
  8116.                             if (start < 0)
  8117.                   goto fnend;
  8118.                             x = len2 - t;
  8119.                             s[x] = NUL;
  8120.                         } else {        /* Left to right */
  8121.                             start = t - 1;
  8122.                             if (start < 0) start = 0;
  8123.                             if (start >= len2)
  8124.                   goto fnend;
  8125.                         }
  8126.                     }
  8127.                 } else {
  8128.                     failed = 1;
  8129.             evalerr(fn);
  8130.             p = fnval;
  8131.                     goto fnend;
  8132.                 }
  8133.             }
  8134.             if (search) {               /* \fsearch() or \frsearch() */
  8135.         if (right && pat[0] == '^') {
  8136.             right = 0;
  8137.             start = 0;
  8138.         }
  8139.                 if (right) {
  8140.                     if (start < 0) start = len2 - 1;
  8141.                     for (i = start;
  8142.                          i >= 0 && !ckmatch(pat,s+i,inpcas[cmdlvl],1+4);
  8143.                          i--) ;
  8144.                     if (i < 0) i = 0; else i++;
  8145.                 } else {
  8146.             i = ckmatch(pat,&s[start],inpcas[cmdlvl],1+4);
  8147.             if (start > 0) i += start;
  8148.                 }
  8149.             } else {
  8150.                 i = ckindex(pat,bp[1],start,right,inpcas[cmdlvl]);
  8151.             }
  8152.             sprintf(fnval,"%d",i);    /* SAFE */
  8153.             p = fnval;
  8154.         }
  8155.         goto fnend;
  8156.       }
  8157.  
  8158.       case FN_RPL:                      /* \freplace(s1,s2,s3) */
  8159.       /*
  8160.         s = bp[0] = source string
  8161.             bp[1] = match string
  8162.             bp[2] = replacement string
  8163.             bp[3] = which occurrence (default = all);
  8164.         p = fnval = destination (result) string
  8165.       */
  8166.         if (argn < 1)                   /* Nothing */
  8167.           goto fnend;
  8168.         if (argn < 2) {                 /* Only works if we have 2 or 3 args */
  8169.             ckstrncpy(p,bp[0],FNVALL);
  8170.         } else {
  8171.         int occur = 0, xx = 0, j2;
  8172.             len1 = (int)strlen(bp[0]);  /* length of string to look in */
  8173.             len2 = (int)strlen(bp[1]);  /* length of string to look for */
  8174.             len3 = (argn < 3) ? 0 : (int)strlen(bp[2]); /* Len of replacemnt */
  8175.             j = len1 - len2 + 1;
  8176.         j2 = j;
  8177.         if (argn > 3) {
  8178.         if (chknum(bp[3])) {
  8179.             occur = atoi(bp[3]);
  8180.         } else {
  8181.             failed = 1;
  8182.             if (fndiags)
  8183.               ckmakmsg(fnval,FNVALL,
  8184.                    "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8185.             goto fnend;
  8186.         }
  8187.         }
  8188.         /* If args out of whack... */
  8189.             if (j < 1 || len1 == 0 || len2 == 0) {
  8190.                 ckstrncpy(p,bp[0],FNVALL); /* just return original string */
  8191.                 p[FNVALL] = NUL;
  8192.             } else {
  8193.           ragain:
  8194.                 s = bp[0];              /* Point to beginning of string */
  8195.                 while (j-- > 0) {    /* For each character */
  8196.                     if (!ckstrcmp(bp[1],s,len2,inpcas[cmdlvl]) &&
  8197.             (occur == 0 || occur == ++xx)) {
  8198.                         if (len3) {
  8199.                             ckstrncpy(p,bp[2],FNVALL);
  8200.                             p += len3;
  8201.                         }
  8202.                         s += len2;    /* and skip past it. */
  8203.                     } else {            /* No, */
  8204.                         *p++ = *s++;    /* just copy this character */
  8205.                     }
  8206.                 }
  8207.                 *p = NUL;
  8208.                 while ((*p++ = *s++));
  8209.         if (occur < 0) {    /* cheap... */
  8210.             occur = xx + occur + 1;
  8211.             xx = 0;
  8212.             p = fnval;
  8213.             j = j2;
  8214.             if (occur > 0)
  8215.               goto ragain;
  8216.         }
  8217.             }
  8218.         }
  8219.         p = fnval;
  8220.         goto fnend;
  8221.  
  8222.       case FN_CHR:                      /* \fcharacter(arg1) */
  8223.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8224.         if (chknum(val1)) {             /* Must be numeric */
  8225.             i = atoi(val1);
  8226.             if (i >= 0 && i < 256) {    /* Must be an 8-bit value */
  8227.                 p = fnval;
  8228.                 *p++ = (char) i;
  8229.                 *p = NUL;
  8230.                 p = fnval;
  8231.             } else {
  8232.                 failed = 1;
  8233.                 if (fndiags)
  8234.                   ckmakmsg(fnval,FNVALL,
  8235.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  8236.             }
  8237.         } else {
  8238.             failed = 1;
  8239.         evalerr(fn);
  8240.         }
  8241.         goto fnend;
  8242.  
  8243.       case FN_COD:                      /* \fcode(char) */
  8244.         if ((int)strlen(bp[0]) > 0) {
  8245.             p = fnval;
  8246.             i = *bp[0];
  8247.             sprintf(p,"%d",(i & 0xff));    /* SAFE */
  8248.         } else p = "";                  /* Can't happen */
  8249.         goto fnend;
  8250.  
  8251.       case FN_LEN:                      /* \flength(arg1) */
  8252.         if (argn > 0) {
  8253.             p = fnval;
  8254.             sprintf(p,"%d",(int)strlen(bp[0]));    /* SAFE */
  8255.         } else p = "0";
  8256.         goto fnend;
  8257.  
  8258.       case FN_LOW:                      /* \flower(arg1) */
  8259.         s = bp[0] ? bp[0] : "";
  8260.         p = fnval;
  8261.         while (*s) {
  8262.             if (isupper(*s))
  8263.               *p = (char) tolower(*s);
  8264.             else
  8265.               *p = *s;
  8266.             p++; s++;
  8267.         }
  8268.         *p = NUL;
  8269.         p = fnval;
  8270.         goto fnend;
  8271.  
  8272.       case FN_MAX:                      /* \fmax(arg1,arg2) */
  8273.       case FN_MIN:                      /* \fmin(arg1,arg2) */
  8274.       case FN_MOD:                      /* \fmod(arg1,arg2) */
  8275.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8276. #ifdef COMMENT
  8277.     /* No longer necessary because evalx() no longer overwrites its */
  8278.     /* result every time it's called (2000/09/23). */
  8279.         free(bp[0]);
  8280.         bp[0] = NULL;
  8281. #endif /* COMMENT */
  8282.         if (argn > 1) {
  8283. #ifdef COMMENT
  8284.         /* Ditto... */
  8285.             bp[0] = malloc((int)strlen(val1)+1);
  8286.         if (bp[0])
  8287.           strcpy(bp[0],val1);    /* safe */
  8288.             val1 = bp[0];
  8289. #endif /* COMMENT */
  8290.             val2 = *(bp[1]) ? evalx(bp[1]) : "";
  8291.             if (chknum(val1) && chknum(val2)) {
  8292.                 i = atoi(val1);
  8293.                 j = atoi(val2);
  8294.                 switch (y) {
  8295.                   case FN_MAX:
  8296.                     if (j < i) j = i;
  8297.                     break;
  8298.                   case FN_MIN:
  8299.                     if (j > i) j = i;
  8300.                     break;
  8301.                   case FN_MOD:
  8302.                     if (j == 0) {
  8303.                         failed = 1;
  8304.                         if (fndiags)
  8305.                           ckmakmsg(fnval,FNVALL,
  8306.                    "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  8307.                         else
  8308.                           fnval[0] = NUL;
  8309.                         goto fnend;
  8310.                     } else
  8311.                       j = i % j;
  8312.                 }
  8313.                 p = fnval;
  8314.                 sprintf(p,"%d",j);    /* SAFE */
  8315.             } else {
  8316.                 failed = 1;
  8317.         evalerr(fn);
  8318.             }
  8319.         } else p = val1;
  8320.         goto fnend;
  8321.     } /* Break up big switch... */
  8322.  
  8323.     switch (y) {
  8324.       case FN_SUB:                      /* \fsubstr(arg1,arg2,arg3) */
  8325.       case FN_RIG:                      /* \fright(arg1,arg2) */
  8326.       case FN_LEF:                      /* \fleft(arg1,arg2) */
  8327.         if (argn < 1)
  8328.           goto fnend;
  8329.         val1 = "";
  8330.         if (argn > 1)
  8331.           if (*(bp[1]))
  8332.             val1 =  evalx(bp[1]);
  8333. #ifdef COMMENT
  8334.         if (bp[1]) free(bp[1]);         /* Have to copy this */
  8335.         bp[1] = malloc((int)strlen(val1)+1);
  8336.         if (!bp[1]) {
  8337.             failed = 1;
  8338.             if (fndiags) {
  8339.         p = fnval;
  8340.         ckmakmsg(fnval,FNVALL,
  8341.              "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  8342.         }
  8343.             goto fnend;
  8344.         }
  8345.         strcpy(bp[1],val1);        /* safe */
  8346.         val1 = bp[1];
  8347. #endif /* COMMENT */
  8348.         val2 = "";
  8349.         if (argn > 2)
  8350.           if (*(bp[2]))
  8351.             val2 = evalx(bp[2]);
  8352.         if (
  8353.             ((argn > 1) && (int)strlen(val1) && !rdigits(val1)) ||
  8354.             ((cx == FN_SUB) &&
  8355.               ((argn > 2) && (int)strlen(val2) && !rdigits(val2)))
  8356.             ) {
  8357.             failed = 1;
  8358.         evalerr(fn);
  8359.         } else {
  8360.             int lx;
  8361.             p = fnval;                  /* pointer to result */
  8362.             lx = strlen(bp[0]);         /* length of arg1 */
  8363.             if (cx == FN_SUB) {        /* substring */
  8364.                 k = (argn > 2) ? atoi(val2) : MAXARGLEN; /* length */
  8365.                 j = (argn > 1) ? atoi(val1) : 1; /* start pos for substr */
  8366.             } else if (cx == FN_LEF) {    /* left */
  8367.                 k = (argn > 1) ? atoi(val1) : lx;
  8368.                 j = 1;
  8369.             } else {                             /* right */
  8370.                 k = (argn > 1) ? atoi(val1) : lx; /* length */
  8371.                 j = lx - k + 1;                  /* start pos for right */
  8372.                 if (j < 1) j = 1;
  8373.             }
  8374.             if (k > 0 && j <= lx) {              /* if start pos in range */
  8375.                 s = bp[0]+j-1;                   /* point to source string */
  8376.                 for (i = 0; (i < k) && (*p++ = *s++); i++) ;  /* copy */
  8377.             }
  8378.             *p = NUL;                   /* terminate the result */
  8379.             p = fnval;                  /* and point to it. */
  8380.         }
  8381.         goto fnend;
  8382.  
  8383.       case FN_UPP:                      /* \fupper(arg1) */
  8384.         s = bp[0] ? bp[0] : "";
  8385.         p = fnval;
  8386.         while (*s) {
  8387.             if (islower(*s))
  8388.               *p = (char) toupper(*s);
  8389.             else
  8390.               *p = *s;
  8391.             p++; s++;
  8392.         }
  8393.         *p = NUL;
  8394.         p = fnval;
  8395.         goto fnend;
  8396.  
  8397.       case FN_REP:                      /* \frepeat(text,number) */
  8398.         if (argn < 1)
  8399.           goto fnend;
  8400.         val1 = "1";
  8401.         if (argn > 1)
  8402.           if (*(bp[1]))
  8403.             val1 = evalx(bp[1]);
  8404.         if (chknum(val1)) {             /* Repeat count */
  8405.             n = atoi(val1);
  8406.             debug(F111,"SUNDAY frepeat n",val1,n);
  8407.             if (n > 0) {                /* Make n copies */
  8408.                 p = fnval;
  8409.                 *p = '\0';
  8410.                 k = (int)strlen(bp[0]); /* Make sure string has some length */
  8411.                 debug(F111,"SUNDAY frepeat k","",k);
  8412.                 debug(F111,"SUNDAY frepeat FNVALL","",FNVALL);
  8413.                 if (k * n >= FNVALL) {  /* But not too much... */
  8414.                     failed = 1;
  8415.                     if (fndiags)
  8416.                       ckmakmsg(fnval,FNVALL,
  8417.                    "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  8418.                     else
  8419.                       fnval[0] = NUL;
  8420.                     p = fnval;
  8421.                     goto fnend;
  8422.                 }
  8423.                 if (k > 0) {            /* If there is something to copy */
  8424.                     for (i = 0; i < n; i++) { /* Copy loop */
  8425.                         s = bp[0];
  8426.                         for (j = 0; j < k; j++) {
  8427.                             if ((p - fnval) >= FNVALL)
  8428.                               break;    /* shouldn't happen... */
  8429.                             else
  8430.                               *p++ = *s++;
  8431.                         }
  8432.                     }
  8433.                     *p = NUL;
  8434.                 }
  8435.             }
  8436.         } else {
  8437.             failed = 1;
  8438.         evalerr(fn);
  8439.         }
  8440.         p = fnval;
  8441.         goto fnend;
  8442.  
  8443. #ifndef NOFRILLS
  8444.       case FN_REV:                      /* \freverse() */
  8445.         if (argn < 1)
  8446.           goto fnend;
  8447.         yystring(bp[0],&p);
  8448.         goto fnend;
  8449. #endif /* NOFRILLS */
  8450.  
  8451.       case FN_RPA:                      /* \frpad() and \flpad() */
  8452.       case FN_LPA:
  8453.         if (argn < 1)
  8454.           goto fnend;
  8455.         val1 = "";
  8456.         if (argn > 1)
  8457.           if (*(bp[1]))
  8458.             val1 = evalx(bp[1]);
  8459.         if (argn == 1) {        /* If a number wasn't given */
  8460.             p = fnval;                  /* just return the original string */
  8461.             ckstrncpy(p,bp[0],FNVALL);
  8462.     } else if (argn > 1 &&  !*val1) {
  8463.             failed = 1;
  8464.         evalerr(fn);
  8465.         } else /* if (chknum(val1)) */ { /* Repeat count */
  8466.             char pc;
  8467.             n = atoi(val1);
  8468.             if (n >= 0) {
  8469.                 p = fnval;
  8470.                 k = (int)strlen(bp[0]); /* Length of string to be padded */
  8471.                 if (k >= n) {           /* It's already long enough */
  8472.                     ckstrncpy(p,bp[0],FNVALL);
  8473.                 } else {
  8474.                     if (n + k <= FNVALL) {
  8475.                         pc = (char) ((argn < 3) ? SP : *bp[2]);
  8476.                         if (!pc) pc = SP;
  8477.                         if (cx == FN_RPA) { /* RPAD */
  8478.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8479.                             p[k] = NUL;
  8480.                             p += k;
  8481.                             for (i = k; i < n; i++)
  8482.                               *p++ = pc;
  8483.                         } else {        /* LPAD */
  8484.                             n -= k;
  8485.                             for (i = 0; i < n; i++)
  8486.                               *p++ = pc;
  8487.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8488.                             p[k] = NUL;
  8489.                             p += k;
  8490.                         }
  8491.                     }
  8492.                     *p = NUL;
  8493.                 }
  8494.             }
  8495.         }
  8496.         p = fnval;
  8497.         goto fnend;
  8498.  
  8499. #ifdef ZFCDAT
  8500.       case FN_FD:                       /* \fdate(filename) */
  8501.         p = fnval;
  8502.         s = zfcdat(bp[0]);
  8503.         if (!s) s = "";
  8504.         if (!*s) {
  8505.             failed = 1;
  8506.             if (fndiags)
  8507.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8508.             goto fnend;
  8509.         }
  8510.         ckstrncpy(fnval,s,FNVALL);
  8511. #endif /* ZFCDAT */
  8512.         goto fnend;
  8513.  
  8514.     } /* Break up big switch... */
  8515.  
  8516.     switch (y) {
  8517.       case FN_FS:                       /* \fsize(filename) */
  8518.         p = fnval;
  8519.         z = zchki(bp[0]);
  8520.         if (z < 0) {
  8521.             failed = 1;
  8522.             if (fndiags) {
  8523.                 if (z == -1)
  8524.                   ckmakmsg(fnval,FNVALL,
  8525.                "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8526.                 else if (z == -2)
  8527.                   ckmakmsg(fnval,FNVALL,
  8528.                "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  8529.                 else if (z == -3)
  8530.                   ckmakmsg(fnval,FNVALL,
  8531.                "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  8532.                 else
  8533.                   ckmakmsg(fnval,FNVALL,
  8534.                "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  8535.             }
  8536.             goto fnend;
  8537.         }
  8538.         sprintf(fnval,"%ld",z);        /* SAFE */
  8539.         goto fnend;
  8540.  
  8541.       case FN_VER:                      /* \fverify() */
  8542.         p = "0";
  8543.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8544.             int start;
  8545.             char *s2, ch1, ch2;
  8546.             start = 0;
  8547.             if (argn > 2) {             /* Starting position specified */
  8548.                 val1 = *(bp[2]) ? evalx(bp[2]) : "0";
  8549.                 if (chknum(val1)) {
  8550.                     start = atoi(val1) /* - 1 */;
  8551.                     if (start < 0) start = 0;
  8552.                     if (start > (int)strlen(bp[1]))
  8553.                       goto verfin;
  8554.                 } else {
  8555.                     failed = 1;
  8556.             evalerr(fn);
  8557.                     goto fnend;
  8558.                 }
  8559.             }
  8560.             i = start;
  8561.             p = "0";
  8562.             for (s = bp[1] + start; *s; s++,i++) {
  8563.                 ch1 = *s;
  8564.                 if (!inpcas[cmdlvl]) if (islower(ch1)) ch1 = toupper(ch1);
  8565.                 j = 0;
  8566.                 for (s2 = bp[0]; *s2; s2++) {
  8567.                     ch2 = *s2;
  8568.                     if (!inpcas[cmdlvl]) if (islower(ch2)) ch2 = toupper(ch2);
  8569.                     if (ch1 == ch2) {
  8570.                         j = 1;
  8571.                         break;
  8572.                     }
  8573.                 }
  8574.                 if (j == 0) {
  8575.                     sprintf(fnval,"%d",i+1); /* SAFE */
  8576.                     p = fnval;
  8577.                     break;
  8578.                 }
  8579.             }
  8580.         }
  8581.       verfin:
  8582.         goto fnend;
  8583.  
  8584.       case FN_IPA:                      /* Find and return IP address */
  8585.         if (argn > 0) {                 /* in argument string. */
  8586.             int start = 0;
  8587.             if (argn > 1) {             /* Starting position specified */
  8588.                 if (chknum(bp[1])) {
  8589.                     start = atoi(bp[1]) - 1;
  8590.                     if (start < 0) start = 0;
  8591.                 } else {
  8592.                     failed = 1;
  8593.                     if (fndiags)
  8594.                       ckmakmsg(fnval,FNVALL,
  8595.                    "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8596.                     goto fnend;
  8597.                 }
  8598.             }
  8599.             p = getip(bp[0]+start);
  8600.         } else p = "";
  8601.         goto fnend;
  8602.  
  8603. #ifdef OS2
  8604.       case FN_CRY:
  8605.         p = "";
  8606.         if (argn > 0) {
  8607.             p = fnval;
  8608.             ckstrncpy(p,bp[0],FNVALL);
  8609.             ck_encrypt(p);
  8610.         }
  8611.         goto fnend;
  8612.  
  8613.       case FN_OOX:
  8614.         p = "";
  8615.         if (argn > 0)
  8616.           p = (char *) ck_oox(bp[0], (argn > 1) ? bp[1] : "");
  8617.         goto fnend;
  8618. #endif /* OS2 */
  8619.  
  8620.       case FN_HEX:                      /* \fhexify(arg1) */
  8621.         if (argn < 1)
  8622.           goto fnend;
  8623.         if ((int)strlen(bp[0]) < (FNVALL / 2)) {
  8624.             s = bp[0];
  8625.             p = fnval;
  8626.             while (*s) {
  8627.                 x = (*s >> 4) & 0x0f;
  8628.                 *p++ = hexdigits[x];
  8629.                 x = *s++ & 0x0f;
  8630.                 *p++ = hexdigits[x];
  8631.             }
  8632.             *p = NUL;
  8633.             p = fnval;
  8634.         }
  8635.         goto fnend;
  8636.  
  8637.       case FN_UNH: {                    /* \funhex(arg1) */
  8638.           int c[2], i;
  8639.           if (argn < 1)
  8640.             goto fnend;
  8641.           if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  8642.               s = bp[0];
  8643.               p = fnval;
  8644.               while (*s) {
  8645.                   for (i = 0; i < 2; i++) {
  8646.                       c[i] = *s++;
  8647.                       if (!c[i]) { p = ""; goto unhexfin; }
  8648.                       if (islower(c[i])) c[i] = toupper(c[i]);
  8649.                       if (c[i] >= '0' && c[i] <= '9') {
  8650.                           c[i] -= 0x30;
  8651.                       } else if (c[i] >= 'A' && c[i] <= 'F') {
  8652.                           c[i] -= 0x37;
  8653.                       } else {
  8654.                           failed = 1;
  8655.                           if (fndiags)
  8656.                             ckmakmsg(fnval,
  8657.                      FNVALL,
  8658.                      "<ERROR:ARG_OUT_OF_RANGE:\\f",
  8659.                      fn,
  8660.                      "()>",
  8661.                      NULL
  8662.                      );
  8663.                           goto fnend;
  8664.                       }
  8665.                   }
  8666.                   *p++ = ((c[0] << 4) & 0xf0) | (c[1] & 0x0f);
  8667.               }
  8668.               *p = NUL;
  8669.               p = fnval;
  8670.           }
  8671.         unhexfin:
  8672.           goto fnend;
  8673.       }
  8674.  
  8675.       case FN_BRK: {                    /* \fbreak() */
  8676.           char * c;                     /* Characters to break on */
  8677.           char c2, s2;
  8678.           int start = 0;
  8679.           int done = 0;
  8680.           if (argn < 1)
  8681.             goto fnend;
  8682.           if (argn > 2) {
  8683.               s = bp[2] ? bp[2] : "0";
  8684.               if (chknum(s)) {
  8685.                   start = atoi(s);
  8686.                   if (start < 0) start = 0;
  8687.                   if (start > (int)strlen(bp[0]))
  8688.                     goto brkfin;
  8689.               } else {
  8690.                   failed = 1;
  8691.                   if (fndiags)
  8692.                     ckmakmsg(fnval,FNVALL,
  8693.                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8694.                   goto fnend;
  8695.               }
  8696.           }
  8697.           s = bp[0] + start;            /* Source pointer */
  8698.  
  8699.           while (*s && !done) {
  8700.               s2 = *s;
  8701.               if (!inpcas[cmdlvl] && islower(s2)) s2 = toupper(s2);
  8702.               c = bp[1] ? bp[1] : "";   /* Character to break on */
  8703.               while (*c) {
  8704.                   c2 = *c;
  8705.                   if (!inpcas[cmdlvl] && islower(c2)) c2 = toupper(c2);
  8706.                   if (c2 == s2) {
  8707.                       done = 1;
  8708.                       break;
  8709.                   }
  8710.                   c++;
  8711.               }
  8712.               if (done) break;
  8713.               *p++ = *s++;
  8714.           }
  8715.           *p = NUL;                     /* terminate the result */
  8716.           p = fnval;                    /* and point to it. */
  8717.         brkfin:
  8718.           goto fnend;
  8719.       }
  8720.  
  8721.       case FN_SPN: {                    /* \fspan() */
  8722.           char *q;
  8723.           char c1, c2;
  8724.           int start = 0;
  8725.           if (argn < 1)
  8726.             goto fnend;
  8727.           if (argn > 2) {               /* Starting position */
  8728.               s = bp[2] ? bp[2] : "0";
  8729.               if (chknum(s)) {
  8730.                   start = atoi(s);
  8731.                   if (start < 0) start = 0;
  8732.               } else {
  8733.                   failed = 1;
  8734.                   if (fndiags)
  8735.                     ckmakmsg(fnval,FNVALL,
  8736.                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8737.                   goto fnend;
  8738.               }
  8739.           }
  8740.           s = bp[0] + start;            /* Source pointer */
  8741.           if (argn > 1 &&
  8742.               (int)strlen(bp[1]) > 0 &&
  8743.               start <= (int)strlen(bp[0])) {
  8744.               while (*s) {              /* Loop thru source string */
  8745.                   q = bp[1];            /* Span string */
  8746.                   c1 = *s;
  8747.                   if (!inpcas[cmdlvl])
  8748.                     if (islower(c1)) c1 = toupper(c1);
  8749.                   x = 0;
  8750.                   while ((c2 = *q++)) {
  8751.                       if (!inpcas[cmdlvl])
  8752.                         if (islower(c2)) c2 = toupper(c2);
  8753.                       if (c1 == c2) { x = 1; break; }
  8754.                   }
  8755.                   if (!x) break;
  8756.                   *p++ = *s++;
  8757.               }
  8758.               *p = NUL;                 /* Terminate and return the result */
  8759.               p = fnval;
  8760.           }
  8761.           goto fnend;
  8762.       }
  8763.     } /* Break up big switch... */
  8764.  
  8765.     switch (y) {
  8766.       case FN_TRM:                      /* \ftrim(s1[,s2]) */
  8767.       case FN_LTR:                      /* \fltrim(s1[,s2]) */
  8768.         if (argn < 1)
  8769.           goto fnend;
  8770.         if ((len1 = (int)strlen(bp[0])) > 0) {
  8771.             if (len1 > FNVALL)
  8772.               len1 = FNVALL;
  8773.             s = " \t\r\n";
  8774.             if (argn > 1)               /* Trim list given */
  8775.               s = bp[1];
  8776.             len2 = (int)strlen(s);
  8777.             if (len2 < 1) {             /* or not... */
  8778.                 s = " \t\r\n";          /* Default is to trim whitespace */
  8779.                 len2 = 2;
  8780.             }
  8781.             if (cx == FN_TRM) {        /* Trim from right */
  8782.                 char * q, p2, q2;
  8783.                 ckstrncpy(fnval,bp[0],FNVALL); /* Copy string to output */
  8784.                 p = fnval + len1 - 1;   /* Point to last character */
  8785.  
  8786.                 while (p >= (char *)fnval) { /* Go backwards */
  8787.                     q = s;              /* Point to trim list */
  8788.                     p2 = *p;
  8789.                     if (!inpcas[cmdlvl])
  8790.                       if (islower(p2)) p2 = toupper(p2);
  8791.                     while (*q) {        /* Is this char in trim list? */
  8792.                         q2 = *q;
  8793.                         if (!inpcas[cmdlvl])
  8794.                           if (islower(q2)) q2 = toupper(q2);
  8795.                         if (p2 == q2) { /* Yes, null it out */
  8796.                             *p = NUL;
  8797.                             break;
  8798.                         }
  8799.                         q++;
  8800.                     }
  8801.                     if (!*q)            /* Trim list exhausted */
  8802.                       break;            /* So we're done. */
  8803.                     p--;                /* Else keep trimming */
  8804.                 }
  8805.             } else {                    /* Trim from left */
  8806.                 char * q, p2, q2;
  8807.                 p = bp[0];              /* Source */
  8808.                 while (*p) {
  8809.                     p2 = *p;
  8810.                     if (!inpcas[cmdlvl])
  8811.                       if (islower(p2)) p2 = toupper(p2);
  8812.                     q = s;
  8813.                     while (*q) {        /* Is this char in trim list? */
  8814.                         q2 = *q;
  8815.                         if (!inpcas[cmdlvl])
  8816.                           if (islower(q2)) q2 = toupper(q2);
  8817.                         if (p2 == q2) { /* Yes, point past it */
  8818.                             p++;        /* and try next source character */
  8819.                             break;
  8820.                         }
  8821.                         q++;            /* No, try next trim character */
  8822.                     }
  8823.                     if (!*q)            /* Trim list exhausted */
  8824.                       break;            /* So we're done. */
  8825.                 }
  8826.                 ckstrncpy(fnval,p,FNVALL);
  8827.             }
  8828.             p = fnval;
  8829.         } else p = "";
  8830.         goto fnend;
  8831.  
  8832.       case FN_CAP:                      /* \fcapitalize(arg1) */
  8833.         if (argn < 1)
  8834.           goto fnend;
  8835.         s = bp[0];
  8836.         p = fnval;
  8837.         x = 0;
  8838.         while ((c = *s++)) {
  8839.             if (isalpha(c)) {
  8840.                 if (x == 0) {
  8841.                     x = 1;
  8842.                     if (islower(c))
  8843.                       c = toupper(c);
  8844.                 } else if (isupper(c))
  8845.                   c = tolower(c);
  8846.             }
  8847.             *p++ = c;
  8848.         }
  8849.         *p = NUL;
  8850.         p = fnval;
  8851.         goto fnend;
  8852.  
  8853. #ifdef COMMENT
  8854.       case FN_TOD:                      /* Time of day to secs since midnite */
  8855.         sprintf(fnval,"%ld",tod2sec(bp[0])); /* SAFE */
  8856.         goto fnend;
  8857. #endif /* COMMENT */
  8858.  
  8859.       case FN_FFN:                      /* Full pathname of file */
  8860.         zfnqfp(bp[0],FNVALL,p);
  8861.         if (!p) p = "";
  8862.         goto fnend;
  8863.  
  8864.       case FN_CHK: {                    /* \fchecksum() */
  8865.           long chk = 0;
  8866.           p = (argn > 0) ? bp[0] : "";
  8867.           while (*p) chk += *p++;
  8868.           sprintf(fnval,"%lu",chk);    /* SAFE */
  8869.           p = fnval;
  8870.           goto fnend;
  8871.       }
  8872.  
  8873. #ifndef NOXFER
  8874.       case FN_CRC:                      /* \fcrc16() */
  8875.         if (argn > 0)
  8876.       sprintf(fnval,"%u",        /* SAFE */
  8877.           chk3((CHAR *)bp[0],(int)strlen(bp[0])));
  8878.         else
  8879.           p = "0";
  8880.         goto fnend;
  8881. #endif /* NOXFER */
  8882.  
  8883.       case FN_BSN:                      /* \fbasename() */
  8884.         zstrip(bp[0],&p);
  8885.         goto fnend;
  8886.  
  8887. #ifndef NOLOCAL
  8888. #ifdef OS2
  8889.       case FN_SCRN_CX:                  /* \fscrncurx() */
  8890.         p = fnval;
  8891.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->x); /* SAFE */
  8892.         goto fnend;
  8893.  
  8894.       case FN_SCRN_CY:                  /* \fscrncury() */
  8895.         p = fnval;
  8896.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->y); /* SAFE */
  8897.         goto fnend;
  8898.  
  8899.       case FN_SCRN_STR: {               /* \fscrnstr() */
  8900.           videoline * line = NULL;
  8901.           viocell * cells = NULL;
  8902.           int row = 0, col = 0, len = 0;
  8903.           /* NOTE: On Unicode systems, the screen contents are stored in */
  8904.           /* in Unicode.  Therefore, we should really be performing a    */
  8905.           /* conversion to the local character set.                      */
  8906.  
  8907.           /* 6/18/2000 - added the translation to lcs */
  8908.  
  8909.           if (bp[0] == NULL || bp[0][0] == '\0') {
  8910.               row = 0;
  8911.           } else {
  8912.               if (chknum(bp[0])) {
  8913.                   row = atoi(bp[0]);
  8914.                   if (row < 0)
  8915.                     row = 0;
  8916.               } else {
  8917.                   failed = 1;
  8918.                   if (fndiags)
  8919.                     ckmakmsg(fnval,FNVALL,
  8920.                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8921.                   goto fnend;
  8922.               }
  8923.           }
  8924.           line = VscrnGetLineFromTop( VTERM, (USHORT) row );
  8925.           if (line != NULL) {
  8926.               if (bp[1] == NULL || bp[1][0] == '\0')
  8927.                 col = 0;
  8928.               else {
  8929.                   if (chknum(bp[0])) {
  8930.                       col = atoi(bp[1]);
  8931.                       if (col < 0 || col >= line->width)
  8932.                         col = 0;
  8933.                   } else {
  8934.                       failed = 1;
  8935.                       if (fndiags)
  8936.                         ckmakmsg(fnval,FNVALL,
  8937.                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8938.                       goto fnend;
  8939.                   }
  8940.               }
  8941.               if (bp[2] == NULL || bp[2][0] == '\0') {
  8942.                   len = line->width - (col+1);
  8943.               } else {
  8944.                   if (!chknum(bp[2])) {
  8945.                       failed = 1;
  8946.                       if (fndiags)
  8947.                         ckmakmsg(fnval,FNVALL,
  8948.                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8949.                       goto fnend;
  8950.                   }
  8951.                   len = atoi(bp[2]);
  8952.                   if (len < 0 || len > line->width)
  8953.                     len = line->width;
  8954.               }
  8955.               cells = line->cells;
  8956.               for (i = 0; i < len; i++) {
  8957.                   int pos = i + col;
  8958.                   if (pos < line->width) {
  8959.                       if (isunicode())
  8960.             fnval[i] = (CHAR) utolxlat(cells[pos].c);
  8961.                       else
  8962.             fnval[i] = (CHAR) (cells[pos].c & 0xFF);
  8963.                       if (fnval[i] == 0)
  8964.                         fnval[i] = SP;
  8965.                   } else
  8966.                     fnval[i] = SP;
  8967.               }
  8968.               fnval[i] = '\0';
  8969.           } else {
  8970.               fnval[0] = '\0';
  8971.           }
  8972.           p = fnval;
  8973.           goto fnend;
  8974.       }
  8975. #endif /* OS2 */
  8976. #endif /* NOLOCAL */
  8977.  
  8978. #ifndef NOPUSH
  8979.       case FN_RAW:                      /* \frawcommand() */
  8980.       case FN_CMD: {                    /* \fcommand() */
  8981.           int x, c, n = FNVALL;
  8982.           x = 0;                        /* Completion flag */
  8983. /*
  8984.   ZIFILE can be safely used because we can't possibly be transferring a file
  8985.   while executing this function.
  8986. */
  8987.           if (!nopush && zxcmd(ZIFILE,bp[0]) > 0) { /* Open the command */
  8988.               while (n-- > -1) {        /* Read from it */
  8989.                   if ((c = zminchar()) < 0) {
  8990.                       x = 1;             /* EOF - set completion flag */
  8991.                       if (cx == FN_CMD) { /* If not "rawcommand" */
  8992.                           p--;           /* remove trailing newlines */
  8993.                           while (*p == CR || *p == LF)
  8994.                             p--;
  8995.                           p++;
  8996.                       }
  8997.                       *p = NUL;         /* Terminate the string */
  8998.                       break;
  8999.                   } else                /* Command still running */
  9000.                     *p++ = c;           /* Copy the bytes */
  9001.               }
  9002.               zclose(ZIFILE);           /* Close the command */
  9003.           }
  9004.           /* Return null string if command's output was too long. */
  9005.           p = fnval;
  9006.           if (!x) {
  9007.               failed = 1;
  9008.               if (fndiags)
  9009.                 ckmakmsg(fnval,FNVALL,
  9010.              "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  9011.           }
  9012.           goto fnend;
  9013.       }
  9014. #endif /* NOPUSH */
  9015.     } /* Break up big switch... */
  9016.  
  9017.     switch (y) {
  9018.       case FN_STX:                      /* \fstripx(string,c) */
  9019.         if (!(s = bp[0]))               /* Make sure there is a string */
  9020.           goto fnend;
  9021.         c = '.';                        /* Character to strip from */
  9022.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9023.         n = ckstrncpy(fnval,bp[0],FNVALL);
  9024.         while (--n >= 0) {
  9025.             if (fnval[n] == c) {
  9026.                 fnval[n] = NUL;
  9027.                 break;
  9028.             }
  9029.         }
  9030.         p = fnval;
  9031.         goto fnend;
  9032.  
  9033.       case FN_STL:                      /* \flop(string,c) */
  9034.         if (!(s = bp[0]))               /* Make sure there is a string */
  9035.           goto fnend;
  9036.         c = '.';                        /* Character to strip to */
  9037.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9038.         x = 0;
  9039.         while (*s++) {
  9040.             if (*(s-1) == c) {
  9041.                 x = 1;
  9042.                 break;
  9043.             }
  9044.         }
  9045.         if (!x) s = bp[0];
  9046.         ckstrncpy(fnval,s,FNVALL);
  9047.         p = fnval;
  9048.         goto fnend;
  9049.  
  9050.       case FN_STN:                      /* \fstripn(string,n) */
  9051.         if (argn < 1)                   /* Remove n chars from right */
  9052.           goto fnend;
  9053.         val1 = "0";
  9054.         if (argn > 1)
  9055.           if (*(bp[1]))
  9056.             val1 = evalx(bp[1]);
  9057.         if (!chknum(val1)) {
  9058.             failed = 1;
  9059.         evalerr(fn);
  9060.             goto fnend;
  9061.         }
  9062.         n = atoi(val1);
  9063.         if (n < 0) n = 0;
  9064.         k = (int)strlen(s = bp[0]) - n;
  9065.         if (k < 0) k = 0;
  9066.         p = fnval;
  9067.         while (k-- > 0)
  9068.           *p++ = *s++;
  9069.         *p = NUL;
  9070.         p = fnval;
  9071.         goto fnend;
  9072.  
  9073.       case FN_STB: {                    /* \fstripb(string,c) */
  9074.           char c2 = NUL;
  9075.       int i, k = 0;
  9076.       char * gr_opn = "\"{'([<";    /* Group open brackets */
  9077.       char * gr_cls = "\"}')]>";    /* Group close brackets */
  9078.  
  9079.           p = fnval;
  9080.           *p = NUL;
  9081.           if (!(s = bp[0]))             /* Make sure there is a string */
  9082.             goto fnend;
  9083.           if ((x = strlen(s)) < 1)
  9084.             goto fnend;
  9085.           c = NUL;                      /* Brace/bracket kind */
  9086.           if (argn > 1) {
  9087.           if (*bp[1]) {
  9088.           if (chknum(bp[1])) {
  9089.               k = atoi(bp[1]);
  9090.               if (k < 0) k = 63;
  9091.               for (i = 0; i < 6; i++) {
  9092.               if (k & (1<<i)) {
  9093.                   if (s[0] == gr_opn[i] && s[x-1] == gr_cls[i]) {
  9094.                   ckstrncpy(fnval,s+1,FNVALL);
  9095.                   fnval[x-2] = NUL;
  9096.                   goto fnend;
  9097.                   }
  9098.               }
  9099.               }
  9100.               ckstrncpy(fnval,s,FNVALL); /* No match */
  9101.               goto fnend;
  9102.           }
  9103.           }
  9104.       }
  9105.       c = *bp[1];
  9106.           if (!c) c = s[0];
  9107.           if (argn > 2) if (*bp[2]) c2 = *bp[2];
  9108.           if (*s == c) {
  9109.               if (!c2) {
  9110.                   switch (c) {
  9111.                     case '(': c2 = ')'; break;
  9112.                     case '[': c2 = ']'; break;
  9113.                     case '{': c2 = '}'; break;
  9114.                     case '<': c2 = '>'; break;
  9115.                     case '"': c2 = '"'; break;
  9116.                     case 39:  c2 = 39;  break;
  9117.                     case 96:  c2 = 39;  break;
  9118.                     default:
  9119.                       if (argn == 2) {
  9120.                           c2 = c;
  9121.                       } else {
  9122.                           strncpy(fnval,s,x); /* Leave it like this */
  9123.                           fnval[x] = NUL;
  9124.                           goto fnend;
  9125.                       }
  9126.                   }
  9127.               }
  9128.               if (s[x-1] == c2) {
  9129.                   strncpy(fnval,s+1,x-2); /* Leave it like this */
  9130.                   fnval[x-2] = NUL;
  9131.                   goto fnend;
  9132.               }
  9133.           }
  9134.           strncpy(fnval,s,x);
  9135.           fnval[x] = NUL;
  9136.           goto fnend;
  9137.       }
  9138.  
  9139.       case FN_2HEX:                     /* Number to hex */
  9140.       case FN_2OCT:                     /* Number to octal */
  9141.     val1 = evalx(bp[0]);
  9142.     if (!*val1) {
  9143.             failed = 1;
  9144.         evalerr(fn);
  9145.             goto fnend;
  9146.         }
  9147.         sprintf(fnval, cx == FN_2HEX ? "%lx" : "%lo", atol(val1)); /* SAFE */
  9148.         if (cx == FN_2HEX && (int)(strlen(fnval)&1))
  9149.           sprintf(fnval,"0%lx",atol(val1)); /* SAFE */
  9150.         p = fnval;
  9151.         goto fnend;
  9152.  
  9153.       case FN_DNAM: {                   /* Directory part of file name */
  9154.           char *s;
  9155.           zfnqfp(bp[0],FNVALL,p);       /* Get full name */
  9156.           if (!isdir(p)) {              /* Is it already a directory? */
  9157.               zstrip(p,&s);             /* No get basename */
  9158.               if (*s) {
  9159.                   x = ckindex(s,p,0,0,0); /* Pos of latter in former */
  9160.                   if (x > 0) p[x-1] = NUL;
  9161.               }
  9162.           }
  9163.           if (!p) p = "";
  9164.           goto fnend;
  9165.       }
  9166.  
  9167. #ifndef NORANDOM
  9168.       case FN_RAND:                     /* Random number */
  9169.         k = rand();
  9170.         x = 0;
  9171.         if (argn > 0) {
  9172.             if (!chknum(bp[0])) {
  9173.                 failed = 1;
  9174.                 if (fndiags)
  9175.                   ckmakmsg(fnval,FNVALL,
  9176.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9177.                 goto fnend;
  9178.             }
  9179.             x = atoi(bp[0]);
  9180.         }
  9181. #ifdef COMMENT
  9182.     sprintf(fnval,"%d", x > 0 ? k % x : (x == 0 ? 0 : (0 - (k % (-x)))));
  9183. #else
  9184.     debug(F111,"rand",ckitoa(x),k);
  9185. #ifdef SUNOS4
  9186. /* This is really strange but on SunOS, if we are requesting random numbers */
  9187. /* between 0 and 4 or less, they always come out in sequence: 0 1 2 3 0 1 2 */
  9188. /* Shifting the result of rand() in this case gives a more random result.   */
  9189.     if (x < 5)
  9190.       k = k >> 5;
  9191. #endif /* SUNOS4 */
  9192.     if (x > 0)
  9193.       x = k % x;
  9194.     else if (x == 0)
  9195.       x = 0;
  9196.     else
  9197.       x = 0 - (k % (-x));
  9198.     debug(F101,"rand x","",x);
  9199.         sprintf(fnval,"%d", x);        /* SAFE */
  9200. #endif /* COMMENT */
  9201.         p = fnval;
  9202.         goto fnend;
  9203. #endif /* NORANDOM */
  9204.     } /* Break up big switch... */
  9205.  
  9206.     switch (y) {
  9207.       case FN_SPLIT:                    /* \fsplit(s1,a,s2,s3,mask) */
  9208.       case FN_WORD: {                   /* \fword(s1,n,s2,s3,mask) */
  9209.           int wordnum = 0;
  9210.           int splitting = 0;
  9211.           int x;
  9212.           int array = 0;
  9213.       int grouping = 0;
  9214.       int nocollapse = 0;
  9215.           char * sep = "";
  9216.           char * notsep = "";
  9217.           char * bp0 = NULL;
  9218.           char * bp1 = NULL;
  9219.           char   abuf[16];
  9220.       struct stringarray * q = NULL;
  9221.  
  9222.           splitting = (cx == FN_SPLIT);    /* Our job */
  9223.  
  9224.       fnval[0] = splitting ? '0' : NUL; /* Initial return value */
  9225.           fnval[1] = NUL;
  9226.       p = fnval;
  9227.           bp0 = bp[0];            /* Source string */
  9228.           if (!bp0) bp0 = "";
  9229.           debug(F111,"fsplit bp[0]",bp0,argn);
  9230.           if (argn < 1 || !*bp0)    /* If none, return default value */
  9231.         goto fnend;
  9232.  
  9233.           bp1 = bp[1];            /* Function-dependent arg */
  9234.           if (!bp1) bp1 = "";        /* (array or number) */
  9235.           debug(F110,"fsplit bp[1]",bp1,0);
  9236.       if (bp[5]) {
  9237.           if (!chknum(bp[5])) {
  9238.                   failed = 1;
  9239.           ckmakmsg(fnval,FNVALL,
  9240.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9241.                   goto fnend;
  9242.           }
  9243.           x = atoi(bp[5]);
  9244.           nocollapse = x;
  9245.       }
  9246.           if (!splitting) {             /* \fword(): n = desired word number */
  9247.               val1 = "1";               /* Default is first word */
  9248.               if (argn > 1)             /* Word number supplied */
  9249.                 if (*bp1)
  9250.                   val1 = evalx(bp1);
  9251.               if (!chknum(val1)) {
  9252.                   failed = 1;
  9253.           ckmakmsg(fnval,FNVALL,
  9254.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9255.                   goto fnend;
  9256.               }
  9257.               n = atoi(val1);
  9258.           } else if (argn > 1 && *bp1) { /* \fsplit(): n = word count */
  9259.               ckstrncpy(abuf,bp1,16);   /* Get array reference */
  9260.               debug(F110,"fsplit abuf 1",abuf,0);
  9261.               failed = 1;               /* Assume it's bad */
  9262.               if (fndiags)              /* Default is this error message */
  9263.                 ckmakmsg(fnval,FNVALL,
  9264.              "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9265.               if (abuf[0] != '&')    /* "Address" of array */
  9266.         goto fnend;        /* It's bad */
  9267.               if (abuf[2]) {        /* Check for brackets */
  9268.                   if (abuf[2] != '[' || abuf[3] != ']') {
  9269.                       goto fnend;    /* Bad */
  9270.                   }
  9271.               }
  9272.               debug(F110,"fsplit abuf 2",abuf,0);
  9273.               if (abuf[1] > 64 && abuf[1] < 91) /* Convert upper to lower */
  9274.                 abuf[1] += 32;
  9275.               if (abuf[1] < 97 || abuf[1] > 122) { /* Check for a-z */
  9276.                   goto fnend;
  9277.               }
  9278.               debug(F110,"fsplit abuf 3",abuf,0);
  9279.               array = 1;
  9280.               fnval[0] = NUL;           /* No error, erase message */
  9281.               failed = 0;               /* Unset failure flag */
  9282.               n = 0;                    /* Initialize word counter */
  9283.           }
  9284.           if (argn > 2)                 /* Have break set? */
  9285.             sep = bp[2];
  9286.       debug(F111,"fsplit sep",sep,argn);
  9287.           if (argn > 3)                 /* Have include set? */
  9288.             notsep = bp[3];
  9289.       debug(F111,"fsplit notsep",notsep,argn);
  9290.       if (argn > 4) {        /* Have grouping set? */
  9291.           char * bp4 = bp[4];
  9292.           debug(F111,"fsplit bp4",bp4,argn);
  9293.           if (!bp4) bp4 = "0";
  9294.           if (!*bp4) bp4 = "0";
  9295.           if (chknum(bp4)) {
  9296.           grouping = atoi(bp4);
  9297.           if (grouping == -1)
  9298.             grouping = 127;
  9299.           } else {
  9300.           failed = 1;
  9301.           if (fndiags)
  9302.             ckmakmsg(fnval,FNVALL,
  9303.                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9304.           goto fnend;
  9305.           }
  9306.       }
  9307.       /* Args parsed, now do the work */
  9308.  
  9309.       debug(F111,"fsplit bp0",bp0,n);
  9310.       q = cksplit(splitting,n,bp0,sep,notsep,grouping,0,nocollapse);
  9311.  
  9312.       wordnum = q ? q->a_size : -1;    /* Check result */
  9313.       if (wordnum < 0) {
  9314.           failed = 1;        /* Failure */
  9315.           if (fndiags)
  9316.         ckmakmsg(fnval,FNVALL,
  9317.              (wordnum == -1) ?
  9318.              "<ERROR:MALLOC_FAILURE:\\f" :
  9319.              "<ERROR:TOO_MANY_WORDS:\\f",
  9320.              fn,
  9321.              "()>",
  9322.              NULL
  9323.              );
  9324.           goto fnend;
  9325.       }
  9326.           if (splitting) {        /* \fsplit() result */
  9327.           ckstrncpy(fnval,ckitoa(wordnum),FNVALL);
  9328.               if (array) {        /* Array was not declared. */
  9329.                   int i;
  9330.                   if ((x = dclarray(abuf[1],wordnum)) < 0) { /* Declare it. */
  9331.                       failed = 1;
  9332.               if (fndiags)
  9333.             ckmakmsg(fnval,FNVALL,
  9334.                  "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  9335.                       goto fnend;
  9336.                   }
  9337.                   for (i = 1; i <= wordnum; i++) { /* Copy results */
  9338.               makestr(&(a_ptr[x][i]),q->a_head[i]);
  9339.           }
  9340.                   a_ptr[x][0] = NULL;    /* Array is 1-based */
  9341.                   makestr(&(a_ptr[x][0]),fnval); /* Element = size */
  9342.               }
  9343.           } else {            /* \fword() result */
  9344.           char * s;
  9345.           s = q->a_head[1];
  9346.           if (!s) s = "";
  9347.           ckstrncpy(fnval,s,FNVALL);
  9348.       }
  9349.           goto fnend;            /* Done */
  9350.       }
  9351.  
  9352.     } /* Break up big switch... */
  9353.  
  9354.     switch (y) {
  9355.  
  9356. #ifdef CK_KERBEROS
  9357.       case FN_KRB_TK:                   /* Kerberos tickets */
  9358.       case FN_KRB_NX:                   /* Kerberos next ticket */
  9359.       case FN_KRB_IV:                   /* Kerberos ticket is valid */
  9360.       case FN_KRB_FG:                   /* Kerberos Ticket flags */
  9361.       case FN_KRB_TT: {                 /* Kerberos ticket time */
  9362.           int kv = 0;                   /* Kerberos version */
  9363.           int n = 0;
  9364.           char * s = NULL;
  9365.           if (rdigits(bp[0])) {
  9366.               kv = atoi(bp[0]);
  9367.           } else {
  9368.               failed = 1;
  9369.               if (fndiags)
  9370.                 ckmakmsg(fnval,FNVALL,
  9371.              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9372.               goto fnend;
  9373.           }
  9374.           if (kv != 4 && kv != 5) {
  9375.               failed = 1;
  9376.               if (fndiags)
  9377.                 ckmakmsg(fnval,FNVALL,
  9378.              "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9379.               goto fnend;
  9380.           }
  9381.           if ((cx == FN_KRB_IV || cx == FN_KRB_TT || cx == FN_KRB_FG) &&
  9382.                argn < 2) {
  9383.               failed = 1;
  9384.               if (fndiags)
  9385.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9386.               goto fnend;
  9387.           }
  9388.           switch (y) {
  9389.             case FN_KRB_TK:             /* Number of Kerberos tickets */
  9390. #ifdef CK_AUTHENTICATION
  9391.               switch (kv) {
  9392.                 case 4:
  9393.                   n = ck_krb4_get_tkts();
  9394.                   sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9395.                   goto fnend;
  9396.                 case 5: {
  9397.                     extern char * krb5_d_cc;
  9398.                     n = ck_krb5_get_tkts(krb5_d_cc);
  9399.                     sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9400.                     goto fnend;
  9401.                 }
  9402.               }
  9403. #else
  9404.               sprintf(fnval,"%d",0);    /* SAFE */
  9405. #endif /* CK_AUTHENTICATION */
  9406.               goto fnend;
  9407.  
  9408.             case FN_KRB_NX:             /* Kerberos next ticket */
  9409. #ifdef CK_AUTHENTICATION
  9410.               switch (kv) {
  9411.                 case 4:
  9412.                   s = ck_krb4_get_next_tkt();
  9413.           ckstrncpy(fnval, s ? s : "",FNVALL);
  9414.                   goto fnend;
  9415.                 case 5:
  9416.                   s = ck_krb5_get_next_tkt();
  9417.           ckstrncpy(fnval, s ? s : "",FNVALL);
  9418.                   goto fnend;
  9419.               }
  9420. #else
  9421.               sprintf(fnval,"k%d next-ticket-string",kv); /* SAFE */
  9422. #endif /* CK_AUTHENTICATION */
  9423.               goto fnend;
  9424.  
  9425.             case FN_KRB_IV:             /* Kerberos ticket is valid */
  9426. #ifdef CK_AUTHENTICATION
  9427.               /* Return 1 if valid, 0 if not */
  9428.               switch (kv) {
  9429.                 case 4:
  9430.                   n = ck_krb4_tkt_isvalid(bp[1]);
  9431.                   sprintf(fnval, "%d", n > 0 ? 1 : 0); /* SAVE */
  9432.                   goto fnend;
  9433.                 case 5: {
  9434.                     extern char * krb5_d_cc;
  9435.                     n = ck_krb5_tkt_isvalid(krb5_d_cc,bp[1]);
  9436.                     sprintf(fnval,"%d", n > 0 ? 1 : 0);    /* SAFE */
  9437.                     goto fnend;
  9438.                 }
  9439.               }
  9440. #else
  9441.               sprintf(fnval,"%d",0);    /* SAFE */
  9442. #endif /* CK_AUTHENTICATION */
  9443.               goto fnend;
  9444.  
  9445.             case FN_KRB_TT:             /* Kerberos ticket time */
  9446. #ifdef CK_AUTHENTICATION
  9447.               switch (kv) {
  9448.                 case 4:
  9449.                   n = ck_krb4_tkt_time(bp[1]);
  9450.                   sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9451.                   goto fnend;
  9452.                 case 5: {
  9453.                     extern char * krb5_d_cc;
  9454.                     n = ck_krb5_tkt_time(krb5_d_cc,bp[1]);
  9455.                     sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9456.                     goto fnend;
  9457.                 }
  9458.               }
  9459. #else
  9460.               ckstrncpy(fnval,"600",FNVALL); /* Some time */
  9461. #endif /* CK_AUTHENTICATION */
  9462.               goto fnend;
  9463.  
  9464.             case FN_KRB_FG:             /* Kerberos ticket flags */
  9465. #ifdef CK_AUTHENTICATION
  9466.               switch (kv) {
  9467.                 case 4:
  9468.                   fnval[0] = '\0';
  9469.                   goto fnend;
  9470.                 case 5: {
  9471.                     extern char * krb5_d_cc;
  9472.                     ckstrncpy(fnval,ck_krb5_tkt_flags(krb5_d_cc,bp[1]),FNVALL);
  9473.                     goto fnend;
  9474.                 }
  9475.               }
  9476. #else
  9477.               fnval[0] = '\0';
  9478. #endif /* CK_AUTHENTICATION */
  9479.               goto fnend;
  9480.           }
  9481.           p = fnval;
  9482.           goto fnend;
  9483.       }
  9484. #endif /* CK_KERBEROS */
  9485.  
  9486. #ifdef FN_ERRMSG
  9487.       case FN_ERRMSG:
  9488.         if (rdigits(bp[0])) {
  9489.             k = atoi(bp[0]);
  9490.         } else {
  9491.             failed = 1;
  9492.             if (fndiags)
  9493.              ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9494.             goto fnend;
  9495.         }
  9496. #ifdef VMS
  9497.         ckstrncpy(fnval,ckvmserrstr(k),FNVALL);
  9498. #else
  9499.         x = errno;
  9500.         errno = k;
  9501.         ckstrncpy(fnval,ck_errstr(),FNVALL);
  9502.         errno = x;
  9503. #endif /* VMS */
  9504.         p = fnval;
  9505.         goto fnend;
  9506. #endif /* FN_ERRMSG */
  9507.  
  9508.       case FN_DIM: {
  9509.           int max;
  9510.           char abuf[16], *s;
  9511.           fnval[0] = NUL;               /* Initial return value */
  9512.           ckstrncpy(abuf,bp[0],16);     /* Get array reference */
  9513.           s = abuf;
  9514.           if (*s == CMDQ) s++;
  9515.           failed = 1;                   /* Assume it's bad */
  9516.           p = fnval;                    /* Point to result */
  9517.           if (fndiags)                  /* Default is this error message */
  9518.         ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9519.           if (s[0] != '&') {            /* "Address" of array */
  9520.               goto fnend;
  9521.           }
  9522.           if (s[2]) {
  9523.               if (s[2] != '[' || s[3] != ']') {
  9524.                   goto fnend;
  9525.               }
  9526.           }
  9527.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  9528.             s[1] += 32;
  9529.           if (s[1] < 95 || s[1] > 122) { /* Check for a-z */
  9530.               goto fnend;                       /* Bad */
  9531.           }
  9532.           if ((max = chkarray(s[1],1)) < 1)
  9533.             max = 0;
  9534.           failed = 0;                   /* Unset failure flag */
  9535.           sprintf(fnval,"%d",max);    /* SAFE */
  9536.           goto fnend;
  9537.       }
  9538.  
  9539.     } /* Break up big switch... */
  9540.  
  9541.     switch (y) {
  9542.       case FN_JDATE:
  9543.         if (argn < 1)                   /* Check number of args */
  9544.           p = ckdate();                 /* None, get today's date-time */
  9545.         else                            /* Some */
  9546.           p = bp[0];                    /* Use first */
  9547.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9548.         ckstrncpy(fnval,zjdate(p),FNVALL); /* Convert to Julian */
  9549.         p = fnval;                      /* Point to result */
  9550.         failed = 0;
  9551.         if (*p == '-') {
  9552.             failed = 1;
  9553.             if (fndiags)                /* Default is this error message */
  9554.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9555.         }
  9556.         goto fnend;
  9557.  
  9558.       case FN_DATEJ:
  9559.         ckstrncpy(fnval,jzdate(bp[0]),FNVALL); /* Convert to yyyy<dayofyear> */
  9560.         p = fnval;                      /* Point to result */
  9561.         failed = 0;
  9562.         if (*p == '-') {
  9563.             failed = 1;
  9564.             if (fndiags)                /* Default is this error message */
  9565.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9566.         }
  9567.         goto fnend;
  9568.  
  9569.       case FN_DTIM:                     /* \fcvtdate() */
  9570.       case FN_TIME:                     /* Free-format time to hh:mm:ss */
  9571.       case FN_NTIM:                     /* Time to sec since midnight */
  9572.     s = (argn > 0) ? bp[0] : "";
  9573.     if (!s) s = "";
  9574.     if (!*s)
  9575.           p = ckdate();                 /* None, get today's date */
  9576.         else                            /* Some */
  9577.           p = bp[0];                    /* Use first */
  9578.         p = ckcvtdate(p,2);             /* Convert to standard form */
  9579.         if (*p == '<') {
  9580.             failed = 1;
  9581.             if (fndiags)                /* Default is this error message */
  9582.               ckmakmsg(fnval,FNVALL,
  9583.                "<ERROR:ARG_BAD_DATE_OR_TIME:\\f",fn,"()>",NULL);
  9584.             p = fnval;
  9585.             goto fnend;
  9586.         }
  9587.     if (argn > 1) {
  9588.         s = bp[1];
  9589.         if (!s) s = "";
  9590.         if (!*s) s = "0";
  9591.         if (!chknum(s)) {
  9592.         failed = 1;
  9593.         if (fndiags)
  9594.           ckmakmsg(fnval,FNVALL,
  9595.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9596.         p = fnval;
  9597.         goto fnend;
  9598.         }
  9599.         x = atoi(s);
  9600.         if (x) p = shuffledate(p,x);
  9601.     }
  9602.     if (cx == FN_TIME) {
  9603.             p += 9;
  9604.         } else if (cx == FN_NTIM) {
  9605.             long sec = 0L;
  9606.             p[11] = NUL;
  9607.             p[14] = NUL;
  9608.             sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  9609.             sprintf(fnval,"%ld",sec);    /* SAFE */
  9610.             p = fnval;
  9611.     }
  9612.         goto fnend;
  9613.  
  9614.       case FN_MJD:                      /* Modified Julian Date */
  9615.         if (argn < 1)                   /* Check number of args */
  9616.           p = zzndate();                /* None, get today's date-time */
  9617.         else                            /* Some */
  9618.           p = bp[0];                    /* Use first */
  9619.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9620.         if (*p == '-') {
  9621.             failed = 1;
  9622.             if (fndiags)                /* Default is this error message */
  9623.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9624.             goto fnend;
  9625.         }
  9626.     /* Convert to modified Julian date */
  9627.         sprintf(fnval,"%ld",mjd(p));    /* SAFE */
  9628.         p = fnval;                      /* Point to result */
  9629.         goto fnend;
  9630.  
  9631.       case FN_MJD2: {
  9632.           long k = 0L;
  9633.           int n = 0;
  9634.           p = evalx(bp[0]);
  9635.           if (*p == '-') {
  9636.               p++;
  9637.               n = 1;
  9638.           }
  9639.           if (!rdigits(p)) {
  9640.               failed = 1;
  9641.           evalerr(fn);
  9642.               p = fnval;
  9643.               goto fnend;
  9644.           } else {
  9645.               k = atol(p);
  9646.               if (n) k = -k;
  9647.           }
  9648.           ckstrncpy(fnval,mjd2date(k),FNVALL); /* Convert to Date */
  9649.           p = fnval;                    /* Point to result */
  9650.           failed = 0;
  9651.           goto fnend;
  9652.       }
  9653.  
  9654. #ifndef NODIAL
  9655.       case FN_PNCVT: {                  /* Convert phone number */
  9656.           extern char * pncvt();
  9657.           failed = 0;
  9658.           p = pncvt(bp[0]);
  9659.           if (!p) p = "";
  9660.           if (!*p) {
  9661.             failed = 1;
  9662.             if (fndiags)                /* Default is this error message */
  9663.               ckmakmsg(fnval,FNVALL,
  9664.                "<ERROR:ARG_BAD_PHONENUM:\\f",fn,"()>",NULL);
  9665.         }
  9666.         goto fnend;
  9667.       }
  9668. #endif /* NODIAL */
  9669.  
  9670.       case FN_DAY:
  9671.       case FN_NDAY:
  9672.         if (argn < 1)                   /* Check number of args */
  9673.           p = zzndate();                /* None, get today's date-time */
  9674.         else                            /* Some */
  9675.           p = bp[0];                    /* Use first */
  9676.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9677.         if (*p == '-') {
  9678.             failed = 1;
  9679.             if (fndiags)                /* Default is this error message */
  9680.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9681.             goto fnend;
  9682.         }
  9683.         failed = 0;
  9684.         z = mjd(p);                     /* Convert to modified Julian date */
  9685.     z = z % 7L;
  9686.     if (z < 0) z = 0 - z;
  9687.         k = ((int)z + 3) % 7;        /* Day of week */
  9688.         p = fnval;                      /* Point to result */
  9689.         if (cx == FN_NDAY)
  9690.           sprintf(fnval,"%d",k);    /* SAFE */
  9691.         else
  9692.           ckstrncpy(fnval,wkdays[k],FNVALL);
  9693.         goto fnend;
  9694.  
  9695.       case FN_N2TIM: {                  /* Sec since midnight to hh:mm:ss */
  9696.           long k = 0L;
  9697.           int n = 0, hh, mm, ss;
  9698.           char * s = bp[0];
  9699.           if (argn < 1)                 /* If no arg substitute 0 */
  9700.             s = "0";
  9701.           p = evalx(s);                 /* Evaluate expression silently */
  9702.           if (*p == '-') {              /* Check result for minus sign */
  9703.               p++;
  9704.               n = 1;
  9705.           }
  9706.           if (!rdigits(p)) { /* Check for numeric */
  9707.               failed = 1;
  9708.           ckmakmsg(fnval,FNVALL,
  9709.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9710.               p = fnval;
  9711.               goto fnend;
  9712.           } else {
  9713.               k = atol(p);
  9714.               if (n) k = -k;
  9715.           }
  9716.           if (k < 0) {                  /* Check for negative */
  9717.               failed = 1;
  9718.               if (fndiags)
  9719.                 ckmakmsg(fnval,FNVALL,
  9720.              "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9721.               p = fnval;
  9722.               goto fnend;
  9723.           }
  9724.           hh = k / 3600L;               /* Have positive number */
  9725.           mm = (k % 3600L) / 60L;       /* break it down... */
  9726.           ss = ((k % 3600L) % 60L);
  9727.  
  9728.           sprintf(fnval,"%02d:%02d:%02d",hh,mm,ss); /* SAFE */
  9729.           p = fnval;
  9730.           failed = 0;
  9731.           goto fnend;
  9732.       }
  9733.  
  9734.       case FN_PERM: {                   /* File permissions */
  9735.           p = fnval;
  9736.           z = zchki(bp[0]);
  9737.           if (z < 0) {
  9738.               failed = 1;
  9739.               if (fndiags) {
  9740.                   if (z == -1)
  9741.                     ckmakmsg(fnval,FNVALL,
  9742.                  "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  9743.                   else if (z == -2)
  9744.                     ckmakmsg(fnval,FNVALL,
  9745.                  "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  9746.                   else if (z == -3)
  9747.                     ckmakmsg(fnval,FNVALL,
  9748.                  "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  9749.                   else
  9750.                     ckmakmsg(fnval,FNVALL,
  9751.                  "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  9752.               }
  9753.               goto fnend;
  9754.           }
  9755. #ifdef CK_PERMS
  9756.           ckstrncpy(fnval,ziperm(bp[0]),FNVALL);
  9757. #else
  9758.           ckstrncpy(fnval,"(unknown)",FNVALL);
  9759. #endif /* CK_PERMS */
  9760.           goto fnend;
  9761.       }
  9762.       case FN_TLOOK:            /* tablelook() */
  9763.       case FN_ALOOK: {            /* arraylook() */
  9764.           int i, x, hi, lo, max, cmdlen;
  9765.           char abuf[16], *s, *pat;
  9766.           char kwbuf[256];
  9767.           char delim = ':';
  9768.           failed = 1;                   /* Assume failure */
  9769.           ckstrncpy(fnval,"-1",FNVALL);
  9770.           pat = bp[0];            /* Point to search pattern */
  9771.           if (!pat) pat = "";        /* Watch out for NULL pointer */
  9772.           cmdlen = strlen(pat);        /* Get pattern length */
  9773.           if (argn < 2 /* || cmdlen < 1 */ ) { /* Need two args */
  9774.               if (fndiags)
  9775.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9776.               goto fnend;
  9777.           }
  9778.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  9779.           if (argn > 2)
  9780.             delim = *(bp[2]);
  9781.           s = abuf;
  9782.           if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Get index and bounds */
  9783.               if (fndiags)
  9784.                ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9785.               goto fnend;
  9786.           }
  9787.           p = fnval;                    /* Point to result */
  9788.           max = a_dim[x];               /* Size of array */
  9789.           if (lo < 0) lo = 0;           /* Use given range if any */
  9790.           if (lo > max) lo = max;
  9791.           if (hi < 0) hi = max;
  9792.           if (hi > max) hi = max;
  9793.           failed = 0;                   /* Unset failure flag */
  9794.           if (max < 1)
  9795.             goto fnend;
  9796.           kwbuf[255] = NUL;
  9797.           for (i = lo; i <= hi; i++) {
  9798.               if (!a_ptr[x][i])
  9799.                 continue;
  9800.               if (cx == FN_ALOOK) {
  9801.                   if (ckmatch(pat,a_ptr[x][i],inpcas[cmdlvl],1+4)) {
  9802.                       sprintf(fnval,"%d",i); /* SAFE */
  9803.                       goto fnend;
  9804.                   }
  9805.               } else if (cx == FN_TLOOK) {
  9806.                   char * aa;
  9807.                   int j = 0, v = 0, len;
  9808.                   if (i == hi)
  9809.                     break;
  9810.                   aa = a_ptr[x][i];     /* Point to this array element */
  9811.                   if (!aa) aa = "";
  9812.                   while (j < 254 && *aa) { /* Isolate keyword */
  9813.                       if (*aa == delim)
  9814.                         break;
  9815.                       kwbuf[j++] = *aa++;
  9816.                   }
  9817.                   kwbuf[j] = NUL;
  9818.                   len = j;
  9819.                   v = 0;
  9820.                   if ((len == cmdlen && !ckstrcmp(kwbuf,pat,len,0)) ||
  9821.                       ((v = !ckstrcmp(kwbuf,pat,cmdlen,0)) &&
  9822.                        ckstrcmp(a_ptr[x][i+1],pat,cmdlen,0))) {
  9823.                       sprintf(fnval,"%d",i); /* SAFE */
  9824.                       goto fnend;
  9825.                   }
  9826.                   if (v) {              /* Ambiguous */
  9827.                       ckstrncpy(fnval,"-2",FNVALL);
  9828.                       goto fnend;
  9829.                   }
  9830.               }
  9831.           }
  9832.           if (cx == FN_TLOOK) {        /* tablelook() last element */
  9833.               ckstrncpy(fnval,"-1",FNVALL);
  9834.               if (!ckstrcmp(a_ptr[x][hi],pat,cmdlen,0))
  9835.                 sprintf(fnval,"%d",hi);    /* SAFE */
  9836.           }
  9837.           goto fnend;
  9838.       }
  9839.       case FN_TOB64:                    /* Base-64 conversion */
  9840.       case FN_FMB64:
  9841.         p = fnval;
  9842.         *p = NUL;
  9843.         if (argn < 1)
  9844.           goto fnend;
  9845.         if (cx == FN_TOB64) {
  9846.             x = b8tob64(bp[0],-1,fnval,FNVALL);
  9847.         } else {
  9848.             x = strlen(bp[0]);
  9849.             if (x % 4) {                /* length must be multiple of 4 */
  9850.                 failed = 1;
  9851.                 ckmakmsg(fnval,FNVALL,
  9852.              "<ERROR:ARG_INCOMPLETE:\\f",fn,"()>",NULL);
  9853.                 goto fnend;
  9854.             }
  9855.             b64tob8(NULL,0,NULL,0);     /* Reset */
  9856.             x = b64tob8(bp[0],-1,fnval,FNVALL);
  9857.             b64tob8(NULL,0,NULL,0);     /* Reset again */
  9858.         }
  9859.         if (x < 0) {
  9860.             failed = 1;
  9861.             if (fndiags) {
  9862.                 char * m = "INTERNAL_ERROR";
  9863.                 switch (x) {
  9864.                   case -1: m = "ARG_TOO_LONG"; break;
  9865.                   case -2: m = "ARG_OUT_OF_RANGE"; break;
  9866.                 }
  9867.         if (ckmakmsg(fnval,FNVALL,"<ERROR:",m,"\\f",fn) > 0)
  9868.           ckstrncat(fnval,"()>",FNVALL);
  9869.             }
  9870.         }
  9871.         goto fnend;
  9872.  
  9873.       case FN_ABS: {
  9874.           char * s;
  9875.           s = bp[0];
  9876.           if (*s == '-' || *s == '+')
  9877.             s++;
  9878.           if (!rdigits(s)) {
  9879.               if (fndiags)
  9880.                 ckmakmsg(fnval,FNVALL,
  9881.              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9882.               goto fnend;
  9883.           }
  9884.           ckstrncpy(fnval,s,FNVALL);
  9885.           goto fnend;
  9886.       }
  9887.  
  9888.       case FN_AADUMP: {
  9889.           char abuf[16], *s = NULL, **ap = NULL, **vp = NULL;
  9890.           char pattern[VNAML];
  9891.           int slen, i, j, k, first = -1;
  9892.           extern int xdelmac();
  9893.           p = fnval;
  9894.           if (argn < 2) {
  9895.               if (fndiags)
  9896.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG2:\\f",fn,"()>",NULL);
  9897.               goto fnend;
  9898.           }
  9899.           debug(F101,"aaconvert argn","",argn);
  9900.           s = bp[0];
  9901.           slen = strlen(s);
  9902.  
  9903.           /* Count elements so we can create the array */
  9904.  
  9905.       ckmakmsg(pattern,VNAML,s,"<*>",NULL,NULL);
  9906.           for (k = 0, i = 0; i < nmac; i++) {
  9907.               if (ckmatch(pattern,mactab[i].kwd,0,1)) {
  9908.                   if (first < 0)        /* Remember location of first match */
  9909.                     first = i;
  9910.                   k++;
  9911.               }
  9912.           }
  9913.           debug(F101,"aaconvert matches","",k);
  9914.           debug(F101,"aaconvert first","",first);
  9915.           fnval[0] = NUL;               /* Initial return value */
  9916.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  9917.           s = abuf;
  9918.           if (*s == CMDQ) s++;
  9919.           p = fnval;                    /* Point to result */
  9920.           if (fndiags)                  /* Default is this error message */
  9921.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9922.           if (s[0] != '&')              /* Address of array */
  9923.             goto fnend;
  9924.           if (s[2])
  9925.             if (s[2] != '[' || s[3] != ']')
  9926.               goto fnend;
  9927.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  9928.             s[1] += 32;
  9929.           if ((x = dclarray(s[1],k)) < 0) /* Declare array to size */
  9930.             goto fnend;
  9931.           ap = a_ptr[x];                /* Point to array we just declared */
  9932.           debug(F111,"aaconvert array 1",abuf,ap);
  9933.           abuf[0] = NUL;
  9934.           if (argn > 2) {
  9935.               ckstrncpy(abuf,bp[2],16); /* Get value array reference */
  9936.               s = abuf;
  9937.               if (*s == CMDQ) s++;
  9938.               if (s[0] != '&')          /* Address of array */
  9939.                 goto fnend;
  9940.               if (s[2])
  9941.                 if (s[2] != '[' || s[3] != ']')
  9942.                   goto fnend;
  9943.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  9944.                 s[1] += 32;
  9945.               if ((x = dclarray(s[1],k)) < 0)
  9946.                 goto fnend;
  9947.               vp = a_ptr[x];            /* Point to array we just declared */
  9948.           }
  9949.           debug(F111,"aaconvert array 2",abuf,vp);
  9950.           makestr(&ap[0],ckitoa(k));
  9951.           if (vp) makestr(&vp[0],ckitoa(k));
  9952.           if (fndiags)
  9953.            ckmakmsg(fnval,FNVALL,"<ERROR:ASSOCIATIVE_ARRAY:\\f",fn,"()>",NULL);
  9954.  
  9955.           /* Copy macro index & value to the arrays and then remove the */
  9956.           /* macro, so the 'first' pointer keeps indicating the next one. */
  9957.           /* We could combine the initial counting loop with this one but */
  9958.           /* then it would be harder to create the array and anyway this */
  9959.           /* function is plenty fast as it is. */
  9960.  
  9961.           for (i = 1; i <= k; ) {
  9962.               if (!ckmatch(pattern,mactab[first].kwd,0,1)) {
  9963.                   debug(F111,"aaconvert oddball",mactab[first].kwd,first);
  9964.                   first++;
  9965.                   continue;
  9966.               }
  9967.               ckstrncpy(tmpbuf,mactab[first].kwd,TMPBUFSIZ); /* Macro name */
  9968.               s = tmpbuf;                       /* Make writeable copy */
  9969.               s += slen;                        /* Isolate "index" */
  9970.               j = strlen(s) - 1;
  9971.               if (*s != '<' || *(s+j) != '>') { /* Check syntax */
  9972.                   /* This shouldn't happen */
  9973.                   debug(F111,"aaconvert ERROR",mactab[first].kwd,first);
  9974.                   goto fnend;
  9975.               }
  9976.               *(s+j) = NUL;             /* Remove final '>' */
  9977.               debug(F111,"aaconvert",s+1,i);
  9978.               makestr(&(ap[i]),s+1);    /* Set first array to index */
  9979.               if (vp)
  9980.                 makestr(&(vp[i]),mactab[first].mval); /* 2nd to value */
  9981.               if (xdelmac(first) < 0)
  9982.                 goto fnend;
  9983.               i++;
  9984.           }
  9985.           sprintf(fnval,"%d",k);    /* SAFE */
  9986.           p = fnval;            /* Return size of array */
  9987.           debug(F110,"aaconvert return",p,0);
  9988.           failed = 0;                   /* Unset failure flag */
  9989.           goto fnend;
  9990.       }
  9991.  
  9992.     } /* End of switch() */
  9993.  
  9994. #ifdef FNFLOAT
  9995. /*
  9996.   Floating-point functions.  To be included only if FNFLOAT is defined, which
  9997.   should happen only if CKFLOAT is also defined, and if the math library is
  9998.   linked in.  Even then, we might have float-vs-double confusion as well as
  9999.   confusion about what the final "%f" format effector is supposed to reference
  10000.   (32 bits, 64 bits, etc).  Expect trouble if CKFLOAT does not match the data
  10001.   type of math library functions or args.
  10002. */
  10003.     if (cx == FN_FPABS ||        /* Floating-point functions */
  10004.         cx == FN_FPADD ||
  10005.         cx == FN_FPDIV ||
  10006.         cx == FN_FPEXP ||
  10007.         cx == FN_FPLOG ||
  10008.         cx == FN_FPLN  ||
  10009.         cx == FN_FPMOD ||
  10010.         cx == FN_FPMAX ||
  10011.         cx == FN_FPMIN ||
  10012.         cx == FN_FPMUL ||
  10013.         cx == FN_FPPOW ||
  10014.         cx == FN_FPSQR ||
  10015.         cx == FN_FPINT ||
  10016.         cx == FN_FPSUB ||
  10017.         cx == FN_FPROU ||
  10018.         cx == FN_FPSIN ||
  10019.         cx == FN_FPCOS ||
  10020.         cx == FN_FPTAN) {
  10021.         CKFLOAT farg[2], fpresult = 0.0;
  10022.         char fpbuf[64], * bp0;
  10023.         double dummy;
  10024.         /* int sign = 0; */
  10025.         int i, j, places = 0;
  10026.         int argcount = 1;
  10027.  
  10028.         failed = 1;
  10029.         p = fnval;
  10030.         bp0 = bp[0];
  10031.         if (!bp0)
  10032.           bp0 = "0";
  10033.         else if (!*bp0)
  10034.           bp0 = "0";
  10035.         if (!isfloat(bp0,0)) {
  10036.         k = mxlook(mactab,bp0,nmac);
  10037.         bp0 = (k > -1) ? mactab[k].mval : NULL;
  10038.         if (bp0) {
  10039.         if (!isfloat(bp0,0)) {
  10040.             if (fndiags)
  10041.               ckmakmsg(fnval,FNVALL,
  10042.                    "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10043.             goto fnend;
  10044.         }
  10045.         }
  10046.         }
  10047.         if (cx == FN_FPINT) {        /* Float to int */
  10048.             failed = 0;
  10049.             ckstrncpy(fnval,bp0,FNVALL);
  10050.             for (i = 0; fnval[i]; i++) {
  10051.                 if (fnval[i] == '.') {
  10052.                     fnval[i] = NUL;
  10053.                     break;
  10054.                 }
  10055.             }
  10056.             goto fnend;
  10057.         }
  10058.         switch (y) {                    /* These need 2 args */
  10059.           case FN_FPADD:
  10060.           case FN_FPDIV:
  10061.           case FN_FPMOD:
  10062.           case FN_FPMAX:
  10063.           case FN_FPMIN:
  10064.           case FN_FPMUL:
  10065.           case FN_FPPOW:
  10066.           case FN_FPSUB:
  10067.             argcount = 2;
  10068.         }
  10069.         /* Missing arguments are supplied as 0.0 */
  10070.  
  10071.         debug(F111,fn,"argcount",argcount);
  10072.         for (i = 0; i < argcount; i++) { /* Get floating-point args */
  10073. #ifdef DEBUG
  10074.             if (deblog) {
  10075.         ckmakmsg(fpbuf,
  10076.              64,
  10077.              "bp[",
  10078.              ckitoa(i),
  10079.              bp[i] ? bp[i] : "(null)",
  10080.              "]"
  10081.              );
  10082.                 debug(F100,fpbuf,"",0);
  10083.             }
  10084. #endif /* DEBUG */
  10085.             if (!bp[i]) {
  10086.                 farg[i] = 0.0;
  10087.             } else if (!*(bp[i])) {
  10088.                 farg[i] = 0.0;
  10089.             } else if (!isfloat(bp[i],0)) {
  10090.         char * tmp;
  10091.         k = mxlook(mactab,bp[i],nmac);
  10092.         tmp = (k > -1) ? mactab[k].mval : NULL;
  10093.         if (tmp) {
  10094.             if (!isfloat(tmp,0)) {
  10095.             if (fndiags)
  10096.               ckmakmsg(fnval,FNVALL,
  10097.                    "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10098.             goto fnend;
  10099.             }
  10100.         }
  10101.             }
  10102.         farg[i] = floatval;
  10103.  
  10104. #ifdef DEBUG
  10105.             if (deblog) {
  10106.                 sprintf(fpbuf,"farg[%d]=%f",i,farg[i]);    /* SAFE */
  10107.                 debug(F100,fpbuf,"",0);
  10108.             }
  10109. #endif /* DEBUG */
  10110.         }
  10111.         if (bp[argcount]) {             /* Get decimal places */
  10112.             char * s;
  10113.             s = bp[argcount];
  10114.             if (!s) s = "";
  10115.             if (!*s) s = "0";
  10116.             s = evalx(s);
  10117.         if (!s) s = "";
  10118.         if (!*s) {
  10119.         evalerr(fn);
  10120.                 goto fnend;
  10121.             }
  10122.             places = atoi(s);
  10123.         }
  10124.         errno = 0;
  10125.         failed = 0;
  10126.         switch (y) {                    /* Now do the requested function */
  10127.           case FN_FPABS:                /* Floating-point absolute value */
  10128. #ifndef COMMENT
  10129.             fpresult = fabs(farg[0]);
  10130. #else
  10131.             if (farg[0] < 0.0)
  10132.               fpresult = 0.0 - farg[0];
  10133. #endif /* COMMENT */
  10134.             break;
  10135.           case FN_FPADD:                /* FP add */
  10136.             fpresult = farg[0] + farg[1];
  10137.             break;
  10138.           case FN_FPDIV:                /* FP divide */
  10139.           case FN_FPMOD:                /* FP modulus */
  10140.             if (!farg[1]) {
  10141.                 failed = 1;
  10142.                 if (fndiags)
  10143.                   ckmakmsg(fnval,FNVALL,
  10144.                "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  10145.             } else
  10146.               fpresult = (cx == FN_FPDIV) ?
  10147.                 (farg[0] / farg[1]) :
  10148.                   fmod(farg[0],farg[1]);
  10149.             break;
  10150.           case FN_FPEXP:                /* FP e to the x */
  10151.             fpresult = (CKFLOAT) exp(farg[0]);
  10152.             break;
  10153.           case FN_FPLOG:                /* FP base-10 logarithm */
  10154.           case FN_FPLN:                 /* FP natural logarithm */
  10155.             if (farg[0] < 0.0) {
  10156.                 failed = 1;
  10157.                 if (fndiags)
  10158.                   ckmakmsg(fnval,FNVALL,
  10159.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10160.             } else
  10161.               fpresult = (cx == FN_FPLOG) ? log10(farg[0]) : log(farg[0]);
  10162.             break;
  10163.           case FN_FPMUL:                /* FP multiply */
  10164.             fpresult = farg[0] * farg[1];
  10165.             break;
  10166.           case FN_FPPOW:                /* FP raise to a power */
  10167.             fpresult = modf(farg[1],&dummy);
  10168.             if ((!farg[0] && farg[1] <= 0.0) ||
  10169.                 (farg[0] < 0.0 && fpresult)) {
  10170.                 failed = 1;
  10171.                 if (fndiags)
  10172.                   ckmakmsg(fnval,FNVALL,
  10173.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10174.             } else
  10175.               fpresult = pow(farg[0],farg[1]);
  10176.             break;
  10177.           case FN_FPSQR:                /* FP square root */
  10178.             if (farg[0] < 0.0) {
  10179.                 failed = 1;
  10180.                 if (fndiags)
  10181.                   ckmakmsg(fnval,FNVALL,
  10182.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10183.             } else
  10184.               fpresult = sqrt(farg[0]);
  10185.             break;
  10186.           case FN_FPSUB:                /* FP subtract */
  10187.             fpresult = farg[0] - farg[1];
  10188.             break;
  10189.           case FN_FPROU:                /* FP round */
  10190.             fpresult = farg[0];
  10191.             break;
  10192.           case FN_FPSIN:                /* FP sine */
  10193.             fpresult = (CKFLOAT) sin(farg[0]);
  10194.             break;
  10195.           case FN_FPCOS:                /* FP cosine */
  10196.             fpresult = (CKFLOAT) cos(farg[0]);
  10197.             break;
  10198.           case FN_FPTAN:                /* FP tangent */
  10199.             fpresult = (CKFLOAT) tan(farg[0]);
  10200.             break;
  10201.           case FN_FPMAX:
  10202.             fpresult = (farg[0] > farg[1]) ? farg[0] : farg[1];
  10203.             break;
  10204.           case FN_FPMIN:
  10205.             fpresult = (farg[0] < farg[1]) ? farg[0] : farg[1];
  10206.             break;
  10207.         }
  10208.  
  10209.         /* Get here with fpresult = function result */
  10210.  
  10211.         if (errno) {                    /* If range or domain error */
  10212.             failed = 1;
  10213.             if (fndiags)
  10214.               ckmakmsg(fnval,FNVALL,
  10215.                "<ERROR:FLOATING-POINT-OP:\\f",fn,"()>",NULL);
  10216.         }
  10217.         if (failed)            /* and/or any other kind of error, */
  10218.       goto fnend;            /* fail. */
  10219. #ifndef COMMENT
  10220.     /* Call routine containing code that was formerly inline */
  10221.     ckstrncpy(fnval,fpformat(fpresult,places,cx == FN_FPROU),FNVALL);
  10222. #else
  10223.         {
  10224.             char fbuf[16];              /* For creating printf format */
  10225.             if (!fp_rounding &&         /* If printf doesn't round, */
  10226.                 (places > 0 ||          /* round result to decimal places. */
  10227.                  (places == 0 && cx == FN_FPROU)))
  10228.               fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  10229.             if (places > 0) {                   /* If places specified */
  10230.         /* use specified places to write given number of digits */
  10231.                 sprintf(fbuf,"%%0.%df",places);    /* SAFE */
  10232.                 sprintf(fnval,fbuf,fpresult);   /* SAFE */
  10233.             } else {                            /* Otherwise... */
  10234. #ifdef COMMENT
  10235. /*
  10236.   Here we want to print exactly fp_digits significant digits, no matter which
  10237.   side of the decimal point they are on.  That is, we want want the default
  10238.   format to show the maximum number of non-garbage digits, AND we want the last
  10239.   such digit to be rounded.  Of course there is no way to do that, since the
  10240.   digit after the last non-garbage digit is, well, garbage.  So the following
  10241.   clever ruse does no good.
  10242. */
  10243.                 int sign = 0, m = 0;
  10244.                 sprintf(fnval,"%f",fpresult);
  10245.                 if (fnval[0] == '-') sign = 1;
  10246.                 for (i = sign; i < FNVALL; i++) {
  10247.                     if (isdigit(fnval[i]))
  10248.                       m++;
  10249.                     else
  10250.                       break;
  10251.                 }
  10252.                 if (m > 1) {
  10253.                     int d = fp_digits - m;
  10254.                     if (d < 1) d = 1;
  10255.                     sprintf(fbuf,"%%%d.%df",fp_digits+sign+1,d);
  10256.                 } else {
  10257.                     sprintf(fbuf,"%%0.%df",fp_digits);
  10258.                 }
  10259.                 sprintf(fnval,fbuf,fpresult);
  10260. #else
  10261.         /* Go for max precision */
  10262.                 sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  10263.                 sprintf(fnval,fbuf,fpresult); /* SAFE */
  10264.  
  10265. #endif /* COMMENT */
  10266.             }
  10267.             if (fnval[0] == '-') sign = 1;
  10268.         }
  10269.         debug(F111,"fpresult 1",fnval,errno); /* Check for over/underflow */
  10270.         for (i = sign; fnval[i]; i++) { /* Give requested decimal places */
  10271.             if (fnval[i] == '.')        /* First find the decimal point */
  10272.               break;
  10273.             else if (i > fp_digits + sign - 1) /* replacing garbage */
  10274.               fnval[i] = '0';           /* digits with 0... */
  10275.         }
  10276.         if (fnval[i] == '.') {          /* Have decimal point */
  10277.             int gotend = 0;
  10278.             /* d < 0 so truncate fraction */
  10279.             if (places < 0 || (places == 0 && cx == FN_FPROU)) {
  10280.                 fnval[i] = NUL;
  10281.             } else if (places > 0) {    /* d > 0 so this many decimal places */
  10282.                 i++;                           /* First digit after decimal */
  10283.                 for (j = 0; j < places; j++) { /* Truncate after d decimal */
  10284.                     if (!fnval[j+i])           /* places or extend to d  */
  10285.                       gotend = 1;              /* decimal places. */
  10286.                     if (gotend || j+i+sign > fp_digits)
  10287.                       fnval[j+i] = '0';
  10288.                 }
  10289.                 fnval[j+i] = NUL;
  10290.             } else {                    /* d == 0 so Do The Right Thing */
  10291.                 for (j = (int)strlen(fnval) - 1; j > i+1; j--) {
  10292.                     if ((j - sign) > fp_digits)
  10293.                       fnval[j] = '0';
  10294.                     if (fnval[j] == '0')
  10295.                       fnval[j] = NUL;   /* Strip useless trailing 0's. */
  10296.                     else
  10297.                       break;
  10298.                 }
  10299.             }
  10300.         }
  10301. #endif /* COMMENT */
  10302.         debug(F111,"fpresult 2",fnval,errno);
  10303.         goto fnend;
  10304.  
  10305.     }
  10306. #endif /* FNFLOAT */
  10307.  
  10308. #ifdef CKCHANNELIO
  10309.     if (cx == FN_FSTAT  ||        /* File functions */
  10310.         cx == FN_FPOS   ||
  10311.         cx == FN_FEOF   ||
  10312.         cx == FN_FGCHAR ||
  10313.         cx == FN_FGLINE ||
  10314.         cx == FN_FGBLK  ||
  10315.         cx == FN_FPCHAR ||
  10316.         cx == FN_FPLINE ||
  10317.         cx == FN_FPBLK  ||
  10318.         cx == FN_NLINE  ||
  10319.         cx == FN_FERMSG ||
  10320.         cx == FN_FILNO) {
  10321.         int x = 0, t = 0, channel;
  10322.         long z;
  10323.         extern int z_maxchan;
  10324.  
  10325.         failed = 1;                     /* Assume failure */
  10326.         p = fnval;                      /* until we validate args */
  10327.         if (cx == FN_FERMSG) {
  10328.             extern int z_error;
  10329.             if (argn < 1) {
  10330.                 x = z_error;
  10331.             } else if (chknum(bp[0])) {
  10332.                 x = atoi(bp[0]);
  10333.             } else if (fndiags)
  10334.               ckmakmsg(fnval,FNVALL,
  10335.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10336.             failed = 0;
  10337.             ckstrncpy(fnval,ckferror(x),FNVALL);
  10338.             goto fnend;
  10339.         }
  10340.         if (argn < 1) {                 /* All file functions need channel */
  10341.             if (fndiags)
  10342.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10343.             goto fnend;
  10344.         }
  10345.         if (rdigits(bp[0])) {           /* Channel must be numeric */
  10346.             channel = atoi(bp[0]);
  10347.         } else {                        /* Fail if it isn't */
  10348.             if (fndiags)
  10349.               ckmakmsg(fnval,FNVALL,
  10350.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10351.             goto fnend;
  10352.         }
  10353.         if (channel < 0 || channel > z_maxchan) { /* Check channel range */
  10354.             if (fndiags)
  10355.               ckmakmsg(fnval,FNVALL,
  10356.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10357.             goto fnend;
  10358.         }
  10359.         x = z_getmode(channel);         /* Find out about the channel */
  10360.  
  10361.         failed = 0;                     /* Assume success from here down */
  10362.         if (cx == FN_FSTAT) {        /* Status / modes of channel */
  10363.             if (x > -1)
  10364.               x &= FM_RWB;              /* Mask out irrelevant bits */
  10365.             else                        /* In this case not open is OK */
  10366.               x = 0;            /* 0 if not open, 1-7 if open */
  10367.             sprintf(fnval,"%d",x);    /* SAFE */
  10368.             goto fnend;
  10369.         } else if (x < 1) {             /* Not \f_status() so must be open */
  10370.             failed = 1;
  10371.             if (fndiags)
  10372.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_OPEN:\\f",fn,"()>",NULL);
  10373.             goto fnend;
  10374.         }
  10375.         switch (y) {                    /* Do the requested function */
  10376.           case FN_FPOS:                 /* Get position */
  10377.             z = z_getpos(channel);
  10378.             sprintf(fnval,"%ld",z);    /* SAFE */
  10379.             goto fnend;
  10380.  
  10381.           case FN_NLINE:                /* Get line number */
  10382.             z = z_getline(channel);
  10383.             sprintf(fnval,"%ld",z);    /* SAFE */
  10384.             goto fnend;
  10385.  
  10386.           case FN_FEOF:                 /* Check EOF */
  10387.             t = 0;
  10388.             if (x & FM_EOF) t = 1;
  10389.             sprintf(fnval,"%d",t);    /* SAFE */
  10390.             goto fnend;
  10391.  
  10392.           case FN_FILNO:                /* Get file handle */
  10393.             x = z_getfnum(channel);
  10394.             sprintf(fnval,"%d",x);    /* SAFE */
  10395.             goto fnend;
  10396.  
  10397.           case FN_FPBLK:                /* Read or write block */
  10398.           case FN_FGBLK:
  10399.             if (argn < 2) {
  10400.                 if (fndiags)
  10401.                   ckmakmsg(fnval,FNVALL,
  10402.                "<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10403.                 goto fnend;
  10404.             }
  10405.             if (rdigits(bp[1])) {
  10406.                 t = atoi(bp[1]);
  10407.             } else {
  10408.                 if (fndiags)
  10409.                   ckmakmsg(fnval,FNVALL,
  10410.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10411.                 goto fnend;
  10412.             }
  10413.           case FN_FGCHAR:               /* Read or write character or line */
  10414.           case FN_FPCHAR:
  10415.           case FN_FGLINE:
  10416.           case FN_FPLINE:
  10417.             fnval[0] = NUL;
  10418.             switch (y) {
  10419.               case FN_FGCHAR: t = z_in(channel,fnval,FNVALL,1,1); break;
  10420.               case FN_FGLINE: t = z_in(channel,fnval,FNVALL,FNVALL-1,0); break;
  10421.               case FN_FGBLK:
  10422.                 if (t >= FNVALL) t = FNVALL - 1;
  10423.                 t = z_in(channel,fnval,FNVALL,t,1);
  10424.                 break;
  10425.               case FN_FPCHAR: t = z_out(channel,bp[1],1,1);  break;
  10426.               case FN_FPLINE: t = z_out(channel,bp[1],-1,0); break;
  10427.               case FN_FPBLK:  t = z_out(channel,bp[1],-1,1); break;
  10428.             }
  10429.             if (t < 0) {                /* Handle read/write error */
  10430.                 failed = 1;
  10431.                 if (fndiags && t != FX_EOF)
  10432.                   ckmakmsg(fnval,FNVALL,
  10433.                "<ERROR:FILE_ERROR_%d:\\f",fn,"()>",NULL);
  10434.                 goto fnend;
  10435.             }
  10436.             if (cx == FN_FGCHAR)    /* Null terminate char */
  10437.               fnval[1] = NUL;
  10438.             /* Write (put) functions return numeric status code */
  10439.             if (cx == FN_FPCHAR || cx == FN_FPLINE || cx == FN_FPBLK)
  10440.               sprintf(fnval,"%d",t);    /* SAFE */
  10441.             goto fnend;
  10442.         }
  10443.     }
  10444. #endif /* CKCHANNELIO */
  10445.  
  10446.     if (cx == FN_PATTERN) {        /* \fpattern() */
  10447.         ispattern = 1;
  10448.         if (argn > 0) {
  10449.             p = fnval;
  10450.             ckstrncpy(fnval,bp[0],FNVALL);
  10451.         } else p = "";
  10452.         goto fnend;
  10453.     }
  10454.  
  10455.     if (cx == FN_HEX2N || cx == FN_OCT2N) { /* \fhex2n(), \foct2n() */
  10456.         p = "0";
  10457.         if (argn < 1)
  10458.           goto fnend;
  10459.         p = ckradix(bp[0], ((cx == FN_HEX2N) ? 16 : 8), 10);
  10460.         if (!p) {
  10461.             if (fndiags)
  10462.               ckmakmsg(fnval,FNVALL,
  10463.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10464.             goto fnend;
  10465.         }
  10466.         failed = 0;
  10467.         ckstrncpy(fnval,p,FNVALL);
  10468.         p = fnval;
  10469.         goto fnend;
  10470.     }
  10471.  
  10472.     if (cx == FN_HEX2IP) {
  10473.         int c[2], ip[4], i, k;
  10474.         p = "0";
  10475.         if (argn < 1)
  10476.           goto fnend;
  10477.         s = bp[0];
  10478.         if ((int)strlen(s) != 8) {
  10479.             failed = 1;
  10480.             if (fndiags)
  10481.               ckmakmsg(fnval,FNVALL,
  10482.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10483.             goto fnend;
  10484.         }
  10485.         p = fnval;
  10486.         for (k = 0; k < 8; k += 2) {
  10487.             for (i = 0; i < 2; i++) {
  10488.                 c[i] = *s++;
  10489.                 if (islower(c[i])) c[i] = toupper(c[i]);
  10490.                 if (c[i] >= '0' && c[i] <= '9') {
  10491.                     c[i] -= 0x30;
  10492.                 } else if (c[i] >= 'A' && c[i] <= 'F') {
  10493.                     c[i] -= 0x37;
  10494.                 } else {
  10495.                     failed = 1;
  10496.                     if (fndiags)
  10497.                       ckmakmsg(fnval,FNVALL,
  10498.                    "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10499.                     goto fnend;
  10500.                 }
  10501.                 ip[k/2] = c[0] << 4 | c[1];
  10502.             }
  10503.             sprintf(p,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10504.         }
  10505.         goto fnend;
  10506.     }
  10507.     if (cx == FN_IP2HEX) {
  10508.         int ip[4], i;
  10509.         char * q;
  10510.         p = "00000000";
  10511.         if (argn < 1)
  10512.           goto fnend;
  10513.         s = bp[0];
  10514.         p = fnval;
  10515.         for (i = 0; i < 3; i++) {
  10516.             q = ckstrchr(s,'.');
  10517.             if (q) {
  10518.                 *q++ = NUL;
  10519.                 ip[i] = atoi(s);
  10520.                 s = q;
  10521.             } else {
  10522.                 failed = 1;
  10523.                 if (fndiags)
  10524.                   ckmakmsg(fnval,FNVALL,
  10525.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10526.                 goto fnend;
  10527.             }
  10528.         }
  10529.         ip[3] = atoi(s);
  10530.         sprintf(p,"%02x%02x%02x%02x",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10531.         goto fnend;
  10532.     }
  10533.     if (cx == FN_RADIX) {
  10534.         failed = 1;
  10535.         p = fnval;
  10536.         if (argn < 3) {
  10537.             if (fndiags)
  10538.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10539.             goto fnend;
  10540.         }
  10541.         if (!rdigits(bp[1]) || !rdigits(bp[2])) {
  10542.             if (fndiags)
  10543.               ckmakmsg(fnval,FNVALL,
  10544.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10545.             goto fnend;
  10546.         }
  10547.         p = ckradix(bp[0],atoi(bp[1]),atoi(bp[2]));
  10548.         if (!p) {
  10549.             if (fndiags)
  10550.               ckmakmsg(fnval,FNVALL,
  10551.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10552.             goto fnend;
  10553.         }
  10554.         failed = 0;
  10555.         ckstrncpy(fnval,p,FNVALL);
  10556.         p = fnval;
  10557.         goto fnend;
  10558.     }
  10559.     if (cx == FN_JOIN) {
  10560.     int i, x, y, z, flag, hi, lo, max, seplen, grouping = 0;
  10561.     char abuf[16], c, *s, *q, *sep = NULL;
  10562.     char * gr_opn = "\"{'([<";    /* Group open brackets */
  10563.     char * gr_cls = "\"}')]>";    /* Group close brackets */
  10564.     char lb[2], rb[2];        /* Selected left and right brackets */
  10565.  
  10566.     failed = 1;            /* Assume failure */
  10567.     fnval[0] = NUL;
  10568.     debug(F101,"FNJOIN ARGN","",argn);
  10569.  
  10570.     ckstrncpy(abuf,bp[0],16);    /* Get array reference */
  10571.     s = abuf;
  10572.     if ((x = arraybounds(s,&lo,&hi)) < 0) {  /* Get index and bounds */
  10573.         if (fndiags)
  10574.           ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10575.         goto fnend;
  10576.     }
  10577.     p = fnval;            /* Point to result */
  10578.     max = a_dim[x];            /* Size of array */
  10579.     if (lo < 0) lo = 1;        /* Use given range if any */
  10580.     if (lo > max) lo = max;
  10581.     if (hi < 0) hi = max;
  10582.     if (hi > max) hi = max;
  10583.     failed = 0;            /* Unset failure flag */
  10584.     if (max < 1)
  10585.       goto fnend;
  10586.     sep = " ";            /* Separator */
  10587.     if (argn > 1)
  10588.       if (bp[1])
  10589.         if (*bp[1])
  10590.           sep = bp[1];
  10591.     lb[0] = NUL;
  10592.     rb[0] = NUL;
  10593.     lb[1] = NUL;
  10594.     rb[1] = NUL;
  10595.     if (argn > 2) {            /* Grouping? */
  10596.         char * bp2 = bp[2];
  10597.         if (!bp2) bp2 = "0";
  10598.         if (!*bp2) bp2 = "0";
  10599.         if (chknum(bp2)) {
  10600.         grouping = atoi(bp2);
  10601.         if (grouping < 0 || grouping > 63)
  10602.           grouping = 1;
  10603.         } else {
  10604.         failed = 1;
  10605.         if (fndiags)
  10606.           ckmakmsg(fnval,FNVALL,
  10607.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10608.         goto fnend;
  10609.         }
  10610.         if (grouping) {        /* Take lowest-order one */
  10611.         int j, k;        /* and set the others to 0 */
  10612.         for (k = 0; k < 6; k++) {
  10613.             j = 1 << k;
  10614.             if (grouping & j) {
  10615.             lb[0] = gr_opn[k];
  10616.             rb[0] = gr_cls[k];
  10617.             break;
  10618.             }
  10619.         }
  10620.         }
  10621.     }
  10622.     if (argn > 3)            /* Nonzero 4th arg for no separator */
  10623.       if (chknum(bp[3]))
  10624.         if (atoi(bp[3]) > 0)
  10625.           sep = NULL;
  10626.     if (!sep) {
  10627.         sep = "";
  10628.         seplen = 0;
  10629.     } else
  10630.       seplen = strlen(sep);
  10631.     for (i = lo; i <= hi; i++) {    /* Loop thru selected array elements */
  10632.         s = a_ptr[x][i];        /* Get next element */
  10633.         if (!s)
  10634.           s = "";
  10635.         flag = 0;            /* Buffer overrun flag */
  10636.         if (grouping) {        /* Does this element need quoting? */
  10637.         q = s;            /* Look for spaces */
  10638.         while ((c = *q++)) { if (c == SP) { flag++; break; } }
  10639.         }
  10640.         y = strlen(s);        /* Get length of this element */
  10641.         if (cx == 0 && grouping)    /* If empty it might need quoting */
  10642.           flag = 1;
  10643.         if (flag) {            /* Add grouping if needed */
  10644.         char * s2 = NULL;
  10645.         y += 2;
  10646.         if ((q = (char *)malloc(y+1))) {
  10647.             ckmakmsg(q,y+1,(char *)lb,s,(char *)rb,NULL);
  10648.             makestr(&s2,q);
  10649.             free(q);
  10650.             s = s2;
  10651.         }
  10652.         }
  10653.         z = 0;            /* Number of chars copied */
  10654.         flag = 0;            /* flag is now buffer-overrun flag */
  10655.         if (y > 0)            /* If this string is not empty */
  10656.           z = ckstrncat(fnval,s,FNVALL); /* copy it. */
  10657.         if (z < y)            /* Check for buffer overrun. */
  10658.           flag++;
  10659.         if (!flag && *sep && i < hi) { /* If buffer still has room */
  10660.         z = ckstrncat(fnval,sep,FNVALL); /* copy delimiter */
  10661.         if (z < seplen)
  10662.           flag++;
  10663.         }
  10664.         if (flag) {
  10665.         failed = 1;
  10666.         if (fndiags)
  10667.           ckmakmsg(fnval,FNVALL,
  10668.                "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10669.         goto fnend;
  10670.         }
  10671.     }
  10672.     goto fnend;
  10673.     }
  10674.     if (cx == FN_SUBST) {        /* \fsubstitute() */
  10675.     CHAR c, * s, * r, * tp[2], buf1[256], buf2[256], buf3[256];
  10676.     int len, i, j, state = 0, lo = 0, hi = 0;
  10677.  
  10678.     failed = 0;
  10679.     p = fnval;            /* Result pointer */
  10680.     *p = NUL;
  10681.     if (!bp[0])            /* No target, no result*/
  10682.       goto fnend;
  10683.  
  10684.     len = strlen(bp[0]);        /* Length of source */
  10685.     if (len == 0)
  10686.       goto fnend;
  10687.     if (len > FNVALL) {
  10688.         failed = 1;
  10689.         if (fndiags)
  10690.           ckmakmsg(fnval,FNVALL,
  10691.                "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10692.         goto fnend;
  10693.     }
  10694.     if (!bp[1]) {
  10695.         ckstrncpy(bp[0],fnval,FNVALL);
  10696.         goto fnend;
  10697.     }
  10698.     tp[0] = buf1;            /* For s2-s3 interpretation loop */
  10699.     tp[1] = buf2;
  10700.  
  10701.     for (i = 0; i < 256; i++) {    /* Initialize working buffers */
  10702.         buf1[i] = 0;        /* s2 expansion buffer */
  10703.         buf2[i] = 0;        /* s3 expansion buffer */
  10704.         buf3[i] = i;        /* Translation table */
  10705.     }
  10706.     for (i = 0; i < 2; i++) {    /* Interpret s2 and s3 */
  10707.         s = (CHAR *)bp[i+1];    /* Arg pointer */
  10708.         if (!s) s = (CHAR *)"";
  10709.         r = tp[i];            /* To construct interpreted arg */
  10710.         j = 0;            /* Output buf pointer */
  10711.         state = 0;            /* Initial state */
  10712.         while (c = *s++) {        /* Loop thru arg chars */
  10713.         if (j > 255)        /* Output buf full */
  10714.           break;
  10715.         switch (state) {
  10716.           case 0:        /* Normal state */
  10717.             switch (c) {
  10718.               case '\\':    /* Have quote */
  10719.             state = 1;
  10720.             break;
  10721.               case '[':        /* Have range starter */
  10722.             state = 2;
  10723.             break;
  10724.               default:        /* Anything else */
  10725.             r[j++] = c;
  10726.             break;
  10727.             }
  10728.             continue;
  10729.           case 1:        /* Quoted char */
  10730.             r[j++] = c;
  10731.             state = 0;
  10732.             continue;
  10733.           case 2:        /* Range bottom */
  10734.             lo = c;
  10735.             state++;
  10736.             continue;
  10737.           case 3:        /* Range separater */
  10738.             if (c != '-') {
  10739.             failed = 1;
  10740.             if (fndiags)
  10741.               ckmakmsg(fnval,FNVALL,
  10742.                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  10743.             goto fnend;
  10744.             }
  10745.             state++;
  10746.             continue;
  10747.           case 4:        /* Range top */
  10748.             hi = c;
  10749.             state++;
  10750.             continue;
  10751.           case 5:        /* Range end */
  10752.             if (c != ']') {
  10753.             failed = 1;
  10754.             if (fndiags)
  10755.               ckmakmsg(fnval,FNVALL,
  10756.                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  10757.             goto fnend;
  10758.             }
  10759.             for (k = lo; k <= hi && j < 255; k++) /* Fill in */
  10760.               r[j++] = k;
  10761.             lo = 0; hi = 0;    /* Reset */
  10762.             state = 0;
  10763.             continue;
  10764.         }
  10765.         }
  10766.     }
  10767.     for (i = 0; i < 256 && buf1[i]; i++) {    /* Create translation table */
  10768.         k = (unsigned)buf1[i];
  10769.         buf3[k] = buf2[i];
  10770.     }
  10771.     s = (CHAR *)bp[0];        /* Point to source string */
  10772.     for (i = 0; i < len; i++) {    /* Translation loop */
  10773.         k = (unsigned)s[i];        /* Get next char */
  10774.         if (!buf3[k])        /* Remove this char */
  10775.           continue;
  10776.         *p++ = buf3[k];        /* Substitute this char */
  10777.     }
  10778.     *p = NUL;
  10779.     p = fnval;
  10780.     goto fnend;
  10781.     }
  10782.  
  10783. #ifndef NOSEXP
  10784.     if (cx == FN_SEXP) {        /* \fsexpression(arg1) */
  10785.         char * p2;
  10786.     fsexpflag++;
  10787.     p = (argn > 0) ? dosexp(bp[0]) : "";
  10788.     fsexpflag--;
  10789.     p2 = fnval;
  10790.     while ((*p2++ = *p++)) ;
  10791.     p = fnval;
  10792.         goto fnend;
  10793.     }
  10794. #endif /* NOSEXP */
  10795.  
  10796.     if (cx == FN_CMDSTK) {        /* \fcmdstack(n1,n2) */
  10797.     int i, j, k;
  10798.     char * s;
  10799.  
  10800.     if (bp[0])
  10801.       val1 = *(bp[0]) ? evalx(bp[0]) : ckitoa(cmdlvl);
  10802.         else
  10803.           val1 = ckitoa(cmdlvl);
  10804. #ifdef COMMENT
  10805.         free(bp[0]);            /* (evalx() always uses same buffer) */
  10806.         bp[0] = NULL;            /* (not any more!) */
  10807. #endif /* COMMENT */
  10808.     failed = 1;
  10809.         if (argn > 1) {
  10810. #ifdef COMMENT
  10811.         makestr(&(bp[0]),val1);
  10812.             val1 = bp[0];
  10813. #endif /* COMMENT */
  10814.             val2 = *(bp[1]) ? evalx(bp[1]) : "0";
  10815.             if (!(chknum(val1) && chknum(val2))) {
  10816.         if (fndiags)
  10817.           ckmakmsg(fnval,FNVALL,
  10818.                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10819.         goto fnend;
  10820.             }
  10821.     } else {
  10822.         val1 = ckitoa(cmdlvl);
  10823.         val2 = "0";
  10824.     }
  10825.     i = atoi(val1);            /* Level */
  10826.     j = atoi(val2);            /* Flags */
  10827.     if (i < 0 || i > cmdlvl) {
  10828.         if (fndiags)
  10829.           ckmakmsg(fnval,FNVALL,
  10830.                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10831.         goto fnend;
  10832.     }
  10833.     failed = 0;
  10834.     p = fnval;
  10835.     k = cmdstk[i].src;        /* What (prompt, file, macro) */
  10836.     if (j) {
  10837.         ckstrncpy(fnval,ckitoa(k),FNVALL);
  10838.         goto fnend;
  10839.     }
  10840.     switch (k) {
  10841.       case CMD_KB:
  10842.         ckstrncpy(fnval,"(prompt)",FNVALL);
  10843.         break;
  10844.       case CMD_TF:
  10845.         s = tfnam[cmdstk[i].lvl];
  10846.         if (!zfnqfp(s,FNVALL,fnval))
  10847.           ckstrncpy(fnval,s,FNVALL);
  10848.         break;
  10849.       case CMD_MD:
  10850.         ckstrncpy(fnval,m_arg[cmdstk[i].lvl][0],FNVALL);
  10851.         break;
  10852.     }
  10853.     goto fnend;
  10854.     }
  10855. #ifdef CKFLOAT
  10856.     if (cx == FN_DIFDATE) {        /* \fdiffdates(d1,d2) */
  10857.     char * d1, * d2;
  10858.     d1 = bp[0] ? bp[0] : ckdate();
  10859.     d2 = bp[1] ? bp[1] : ckdate();
  10860.     p = (char *)cmdiffdate(d1,d2);
  10861.     if (!p) {
  10862.         failed = 1;
  10863.         if (fndiags) {
  10864.         ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  10865.         p = fnval;
  10866.         }
  10867.     }
  10868.     goto fnend;
  10869.     }
  10870. #endif /* CKFLOAT */
  10871.     if (cx == FN_CMPDATE) {        /* \fcmddates(d1,d2) */
  10872.     int x = 0;
  10873.     char d1[18], d2[18], * dp;
  10874.     failed = 0;
  10875.     d1[0] = NUL;
  10876.     d2[0] = NUL;
  10877.     p = fnval;
  10878.     dp = cmcvtdate(bp[0],1);
  10879.     if (dp) {
  10880.         ckstrncpy(d1,dp,18);
  10881.         if ((dp = cmcvtdate(bp[1],1))) {
  10882.         ckstrncpy(d2,dp,18);
  10883.         x = 1;
  10884.         }
  10885.     }
  10886.     if (x == 0) {
  10887.         failed = 1;
  10888.         if (fndiags)
  10889.           ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  10890.     } else {
  10891.         x = strcmp(d1,d2);
  10892.         if (x > 0)
  10893.           x = 1;
  10894.         else if (x < 0)
  10895.           x = -1;
  10896.         sprintf(fnval,"%d",x);
  10897.     }
  10898.     goto fnend;
  10899.     }
  10900.     if (cx == FN_TOGMT) {        /* \futcdate(d1) */
  10901.     char * d1, * dp;
  10902.     char datebuf[32];
  10903.     char d2[32];
  10904.     p = fnval;
  10905.     failed = 1;
  10906.     if ((dp = cmcvtdate(bp[0],1))) { /* The given date */
  10907.         ckstrncpy(datebuf,dp,18);
  10908.         ckstrncpy(d2,dp,18);    /* local time */
  10909.         ckstrncat(datebuf,"Z",19);    /* Same time GMT */
  10910.         if ((dp = cmcvtdate(datebuf,1))) /* converted to local time */
  10911.           ckstrncpy(datebuf,dp,18);
  10912.         if ((p = (char *)cmdiffdate(d2,datebuf))) { /* Get offset */
  10913.         ckstrncat(d2,p,32);    /* Append offset to local time */
  10914.         if ((dp = cmcvtdate(d2,1))) {
  10915.             failed = 0;
  10916.             ckstrncpy(fnval,dp,FNVALL);
  10917.             p = fnval;
  10918.         }
  10919.         }
  10920.     }
  10921.     if (failed && fndiags)
  10922.       ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  10923.     goto fnend;
  10924.     }
  10925.     if (cx == FN_DELSEC) {        /* \fdelta2secs(delta-time) */
  10926.     long secs;
  10927.     p = fnval;
  10928.     if ((x = delta2sec(bp[0],&secs)) < 0) {
  10929.         failed = 1;
  10930.         if (fndiags)
  10931.           ckmakmsg(fnval,FNVALL,
  10932.                (x == -1) ?
  10933.                  "<ERROR:BAD_DELTA_TIME:\\f" :
  10934.                  "<ERROR:OVERFLOW:\\f",
  10935.                fn,
  10936.                "()>",
  10937.                NULL
  10938.                );
  10939.         goto fnend;
  10940.     }
  10941.     sprintf(p,"%ld",secs);
  10942.     goto fnend;
  10943.     }
  10944.     if (cx == FN_PC_DU) {
  10945.     char c, * s = bp[0];
  10946.     if (!s) s = "";
  10947.     p = fnval;
  10948.     while ((c = *s++)) {
  10949.         if (c == ':') {
  10950.         if (*s != '\\')
  10951.           *p++ = '/';
  10952.         } else if (c == '\\') {
  10953.         *p++ = '/';
  10954.         } else {
  10955.         *p++ = c;
  10956.         }
  10957.     }
  10958.     *p = NUL;
  10959.     p = fnval;
  10960.     goto fnend;
  10961.     }
  10962.     if (cx == FN_PC_UD) {        /* Unix to DOS path */
  10963.     char c, * s = bp[0];
  10964.     if (!s) s = "";
  10965.     if (*s == '~') {        /* Skip leading tilde */
  10966.         s++;
  10967.         if (*s == '/')
  10968.           s++;
  10969.     }
  10970.     p = fnval;
  10971.     while ((c = *s++))
  10972.       *p ++ = (c == '/') ? '\\' : c;
  10973.     *p = NUL;
  10974.     p = fnval;
  10975.     goto fnend;
  10976.     }
  10977.     if (cx == FN_KWVAL) {        /* Keyword=Value */
  10978.     p = dokwval(bp[0],bp[1]?*(bp[1]):'=');
  10979.     goto fnend;
  10980.     }
  10981. #ifdef COMMENT
  10982. /* Cute idea but doesn't work */
  10983.     if (cx == FN_SLEEP || cx == FN_MSLEEP) {
  10984.     p = "";
  10985.     if (chknum(bp[0])) {
  10986.         x = atoi(bp[0]);
  10987.     } else {
  10988.         failed = 1;
  10989.         if (fndiags) {
  10990.         ckmakmsg(fnval,FNVALL,
  10991.              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10992.         p = fnval;
  10993.             }        
  10994.         goto fnend;
  10995.     }
  10996.     if (cx == FN_SLEEP)
  10997.       x *= 1000;
  10998.     msleep(x);
  10999.     goto fnend;
  11000.     }
  11001. #endif /* COMMENT */
  11002.  
  11003. /* Note: when adding new functions remember to update dohfunc in ckuus2.c. */
  11004.  
  11005.     failed = 1;
  11006.     if (fndiags)
  11007.       ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN_FUNCTION:\\f",fn,"()>",NULL);
  11008.  
  11009.   fnend:
  11010.     /* Free temporary storage for aguments */
  11011.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  11012.     fndepth--;
  11013.     if (failed) {                       /* Handle failure */
  11014.         debug(F111,"fnend",fnval,errno);
  11015.         if (!p) p = "";
  11016.         if (p[0]) {
  11017.             /* In case this wasn't caught above... */
  11018.             k = strlen(p);
  11019.             if (p[0] != '<' && p[k-1] != '>') {
  11020.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_ARG:\\f",fn,"()>",NULL);
  11021.                 p = fnval;
  11022.             }
  11023.         } else {
  11024.             ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN:\\f",fn,"()>",NULL);
  11025.             p = fnval;
  11026.         }
  11027.         if (fnerror)                    /* SET FUNCTION ERROR ON */
  11028.           fnsuccess = 0;                /* Make command fail (see ckuus5.c) */
  11029.         debug(F111,"fneval failed",p,fnsuccess);
  11030.         if (fndiags)                    /* SET FUNCTION DIAGNOSTICS ON */
  11031.           printf("?%s\n",p);            /* Print error message now. */
  11032.         else
  11033.           return("");                   /* Return nothing. */
  11034.     }
  11035.     return(p);
  11036. }
  11037. #endif /* NOSPL */
  11038.  
  11039. static char ckpidbuf[32] = "????";
  11040.  
  11041. #ifdef VMS
  11042. _PROTOTYP(long zgpid,(void));
  11043. #endif /* VMS */
  11044.  
  11045. char *
  11046. ckgetpid() {                            /* Return pid as string */
  11047. #ifdef CK_PID
  11048. #ifdef OS2
  11049. #define getpid _getpid
  11050.     unsigned long zz;
  11051. #else
  11052.     long zz;
  11053. #endif /* OS2 */
  11054. #ifdef VMS
  11055.     zz = zgpid();
  11056. #else
  11057.     zz = getpid();
  11058. #endif /* VMS */
  11059.     sprintf(ckpidbuf,"%ld",zz);        /* SAFE */
  11060. #endif /* CK_PID */
  11061.     return((char *)ckpidbuf);
  11062. }
  11063.  
  11064. #ifndef NOSPL
  11065. #define EMBUFLEN 128                    /* Error message buffer length */
  11066.  
  11067. static char embuf[EMBUFLEN+1];
  11068.  
  11069. char *                                  /* Evaluate builtin variable */
  11070. nvlook(s) char *s; {
  11071.     int x, y, cx;
  11072.     long z;
  11073.     char *p;
  11074. #ifndef NODIAL
  11075.     MDMINF * m;
  11076. #endif /* NODIAL */
  11077. #ifndef NOKVERBS                        /* Keyboard macro material */
  11078.     extern int keymac, keymacx;
  11079. #endif /* NOKVERBS */
  11080. #ifdef CK_LOGIN
  11081.     extern int isguest;
  11082. #endif /* CK_LOGIN */
  11083.     if (!s) s = "";
  11084.     x = strlen(s);
  11085.     if (fndiags) {                      /* FUNCTION DIAGNOSTIC ON */
  11086.         if (x + 32 < EMBUFLEN)
  11087.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE:\\v(%s)>",s); /* SAFE */
  11088.         else
  11089.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE>"); /* SAFE */
  11090.     } else                              /* FUNCTION DIAGNOSTIC OFF */
  11091.       embuf[0] = NUL;
  11092.     x = VVBUFL;
  11093.     p = vvbuf;
  11094.     if (zzstring(s,&p,&x) < 0) {        /* e.g. for \v(\%a) */
  11095.         y = -1;
  11096.     } else {
  11097.         s = vvbuf;
  11098.         y = lookup(vartab,s,nvars,&x);
  11099.     }
  11100.     cx = y;                /* y is too generic */
  11101. #ifndef NODIAL
  11102.     m = (mdmtyp > 0) ? modemp[mdmtyp] : NULL; /* For \v(m_xxx) variables */
  11103. #endif /* NODIAL */
  11104.  
  11105.     debug(F101,"nvlook y","",y);
  11106.  
  11107.     switch (y) {
  11108.       case VN_ARGC:                     /* ARGC */
  11109.         sprintf(vvbuf,"%d",maclvl < 0 ? topargc : macargc[maclvl]); /* SAFE */
  11110.         return(vvbuf);
  11111.  
  11112.       case VN_ARGS:                     /* ARGS */
  11113.         sprintf(vvbuf,"%d",xargs);    /* SAFE */
  11114.         return(vvbuf);
  11115.  
  11116.       case VN_COUN:                     /* COUNT */
  11117.         sprintf(vvbuf,"%d",count[cmdlvl]); /* SAFE */
  11118.         return(vvbuf);
  11119.  
  11120.       case VN_DATE:                     /* DATE */
  11121.         ztime(&p);                      /* Get "asctime" string */
  11122.         if (p == NULL || *p == NUL) return(NULL);
  11123.         vvbuf[0] = p[8];                /* dd */
  11124.         vvbuf[1] = p[9];
  11125.         vvbuf[2] = SP;
  11126.         vvbuf[3] = p[4];                /* mmm */
  11127.         vvbuf[4] = p[5];
  11128.         vvbuf[5] = p[6];
  11129.         vvbuf[6] = SP;
  11130.         for (x = 20; x < 24; x++)       /* yyyy */
  11131.           vvbuf[x - 13] = p[x];
  11132.         vvbuf[11] = NUL;
  11133.         return(vvbuf);
  11134.  
  11135.       case VN_NDAT:                     /* Numeric date */
  11136.         ckstrncpy(vvbuf,zzndate(),VVBUFL);
  11137.         return(vvbuf);
  11138.  
  11139.       case VN_DIRE:                     /* DIRECTORY */
  11140.         s = zgtdir();                   /* Get current directory */
  11141.         if (!s)
  11142. #ifdef UNIXOROSK
  11143.           s = "./";
  11144. #else
  11145. #ifdef VMS
  11146.           s = "[]";
  11147. #else
  11148.           s = "";
  11149. #endif /* VMS */
  11150. #endif /* UNIXOROSK */
  11151.         ckstrncpy(vvbuf,s,VVBUFL);
  11152.         s = vvbuf;
  11153. #ifdef UNIXOROSK
  11154.         x = strlen(s);
  11155.         if (x < VVBUFL - 1) {
  11156.             if (s[x-1] != '/') {
  11157.                 s[x] = '/';
  11158.                 s[x+1] = NUL;
  11159.             }
  11160.         }
  11161. #endif /* UNIXOROSK */
  11162.         return(s);
  11163.  
  11164.       case VN_FILE:                     /* filespec */
  11165.         return(fspec);
  11166.  
  11167.       case VN_HOST:                     /* host name */
  11168.         if (*myhost) {                  /* If known */
  11169.             return(myhost);             /* return it. */
  11170.         } else {                        /* Otherwise */
  11171.             ckstrncpy(vvbuf,"unknown",VVBUFL); /* just say "unknown" */
  11172.             return(vvbuf);
  11173.         }
  11174.  
  11175.       case VN_SYST:                     /* System type */
  11176. #ifdef UNIX
  11177.         ckstrncpy(vvbuf,"UNIX",VVBUFL);
  11178. #else
  11179. #ifdef VMS
  11180.         ckstrncpy(vvbuf,"VMS",VVBUFL);
  11181. #else
  11182. #ifdef OSK
  11183.         ckstrncpy(vvbuf,"OS9/68K",VVBUFL);
  11184. #else
  11185. #ifdef AMIGA
  11186.         ckstrncpy(vvbuf,"Amiga",VVBUFL);
  11187. #else
  11188. #ifdef MAC
  11189.         ckstrncpy(vvbuf,"Macintosh",VVBUFL);
  11190. #else
  11191. #ifdef OS2
  11192. #ifdef NT
  11193.         ckstrncpy(vvbuf,"WIN32",VVBUFL) ;
  11194. #else /* NT */
  11195.         ckstrncpy(vvbuf,"OS/2",VVBUFL);
  11196. #endif /* NT */
  11197. #else
  11198. #ifdef datageneral
  11199.         ckstrncpy(vvbuf,"AOS/VS",VVBUFL);
  11200. #else
  11201. #ifdef GEMDOS
  11202.         ckstrncpy(vvbuf,"Atari_ST",VVBUFL);
  11203. #else
  11204. #ifdef STRATUS
  11205.         ckstrncpy(vvbuf,"Stratus_VOS",VVBUFL);
  11206. #else
  11207.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11208. #endif /* STRATUS */
  11209. #endif /* GEMDOS */
  11210. #endif /* datageneral */
  11211. #endif /* OS2 */
  11212. #endif /* MAC */
  11213. #endif /* AMIGA */
  11214. #endif /* OSK */
  11215. #endif /* VMS */
  11216. #endif /* UNIX */
  11217.         return(vvbuf);
  11218.  
  11219.       case VN_SYSV:                     /* System herald */
  11220. #ifdef IKSD
  11221. #ifdef CK_LOGIN
  11222.         if (inserver && isguest)
  11223.           return("");
  11224. #endif /* CK_LOGIN */
  11225. #endif /* IKSD */
  11226.         for (x = y = 0; x < VVBUFL; x++) {
  11227.             if (ckxsys[x] == SP && y == 0) continue;
  11228.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  11229.         }
  11230.         vvbuf[y] = NUL;
  11231.         return(vvbuf);
  11232.     } /* Break up long switch statements... */
  11233.  
  11234.     switch(y) {
  11235.       case VN_TIME:                     /* TIME. Assumes that ztime returns */
  11236.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11237.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11238.           return("");
  11239.         for (x = 11; x < 19; x++)       /* copy hh:mm:ss */
  11240.           vvbuf[x - 11] = p[x];         /* to vvbuf */
  11241.         vvbuf[8] = NUL;                 /* terminate */
  11242.         return(vvbuf);                  /* and return it */
  11243.  
  11244.       case VN_NTIM:                     /* Numeric time */
  11245.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11246.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11247.           return(NULL);
  11248.         z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  11249.         sprintf(vvbuf,"%ld",z);        /* SAFE */
  11250.         return(vvbuf);
  11251.  
  11252. #ifdef CK_TTYFD
  11253.       case VN_TTYF:                     /* TTY file descriptor */
  11254.         sprintf(vvbuf,"%d",        /* SAFE */
  11255. #ifdef VMS
  11256.                 vmsttyfd()
  11257. #else
  11258.                 ttyfd
  11259. #endif /* VMS */
  11260.                 );
  11261.         return(vvbuf);
  11262. #endif /* CK_TTYFD */
  11263.  
  11264.       case VN_VERS:                     /* Numeric Kermit version number */
  11265.         sprintf(vvbuf,"%ld",vernum);    /* SAFE */
  11266.         return(vvbuf);
  11267.  
  11268.       case VN_XVNUM:                    /* Product-specific version number */
  11269.         sprintf(vvbuf,"%ld",xvernum);    /* SAFE */
  11270.         return(vvbuf);
  11271.  
  11272.       case VN_HOME:                     /* Home directory */
  11273.         return(homepath());
  11274.  
  11275.       case VN_IBUF:                     /* INPUT buffer */
  11276.         return((char *)inpbuf);
  11277.  
  11278.       case VN_ICHR:                     /* INPUT character */
  11279.         inchar[1] = NUL;
  11280.         return((char *)inchar);
  11281.  
  11282.       case VN_ICNT:                     /* INPUT character count */
  11283.         sprintf(vvbuf,"%d",incount);    /* SAFE */
  11284.         return(vvbuf);
  11285.  
  11286.       case VN_SPEE: {                   /* Transmission SPEED */
  11287.           long t;
  11288.           t = ttgspd();
  11289.           if (t < 0L)
  11290.             sprintf(vvbuf,"unknown");    /* SAFE */
  11291.           else
  11292.             sprintf(vvbuf,"%ld",t);    /* SAFE */
  11293.           return(vvbuf);
  11294.       }
  11295.  
  11296.       case VN_SUCC:                     /* SUCCESS flag */
  11297.     /* Note inverted sense */
  11298.         sprintf(vvbuf,"%d",(success == 0) ? 1 : 0); /* SAFE */
  11299.         return(vvbuf);
  11300.  
  11301.       case VN_LINE: {                   /* LINE */
  11302. #ifdef DEBUG
  11303.           if (deblog) {
  11304.               debug(F111,"\\v(line) local",ttname,local);
  11305.               debug(F111,"\\v(line) inserver","",inserver);
  11306. #ifdef TNCODE
  11307.               debug(F111,"\\v(line) tcp_incoming","",tcp_incoming);
  11308. #endif /* TNCODE */
  11309. #ifdef CK_TAPI
  11310.               debug(F111,"\\v(line) tttapi","",tttapi);
  11311. #endif /* CK_TAPI */
  11312.           }
  11313. #endif /* DEBUG */
  11314.  
  11315. #ifdef CK_TAPI
  11316.           if (tttapi) {                 /* If I have made a TAPI connection */
  11317.               int i;                    /* return the TAPI device name */
  11318.               for (i = 0; i < ntapiline; i++) {
  11319.                   if (!strcmp(ttname,tapilinetab[i].kwd)) {
  11320.                       p = _tapilinetab[i].kwd;
  11321.                       return(p);
  11322.                   }
  11323.               }
  11324.           }
  11325. #endif /* CK_TAPI */
  11326. #ifndef NOXFER
  11327.           if (inserver                  /* If I am a TCP server */
  11328. #ifdef TNCODE
  11329.               || tcp_incoming
  11330. #endif /* TNCODE */
  11331.               )
  11332. #ifdef TCPSOCKET
  11333.             p = ckgetpeer();            /* return peer name */
  11334.           else
  11335. #endif /* TCPSOCKET */
  11336. #endif /* NOXFER */
  11337.           if (local)                    /* Otherwise if in local mode */
  11338.             p = (char *) ttname;        /* return SET LINE / SET HOST name */
  11339.           else                          /* Otherwise */
  11340.             p = "";                     /* return empty string */
  11341.           if (!p)                       /* In case ckgetpeer() returns */
  11342.             p = "";                     /* null pointer... */
  11343.           debug(F110,"\\v(line) p",p,0);
  11344.           if (!*p)
  11345.             p = (char *) ttname;
  11346.           return(p);
  11347.       }
  11348.       case VN_PROG:                     /* Program name */
  11349.         return("C-Kermit");
  11350.  
  11351.     } /* Break up long switch statements... */
  11352.  
  11353.     switch(y) {
  11354.       case VN_RET:                      /* Value of most recent RETURN */
  11355.         debug(F111,"\\v(return)",mrval[maclvl+1],maclvl+1);
  11356.         p = mrval[maclvl+1];
  11357.         if (p == NULL) p = "";
  11358.         return(p);
  11359.  
  11360.       case VN_FFC:                      /* Size of most recent file */
  11361.         sprintf(vvbuf, "%ld", ffc);    /* SAFE */
  11362.         return(vvbuf);
  11363.  
  11364.       case VN_TFC:                      /* Size of most recent file group */
  11365.         sprintf(vvbuf, "%ld", tfc);    /* SAFE */
  11366.         return(vvbuf);
  11367.  
  11368.       case VN_CPU:                      /* CPU type */
  11369. #ifdef IKSD
  11370. #ifdef CK_LOGIN
  11371.         if (inserver && isguest)
  11372.           return("");
  11373. #endif /* CK_LOGIN */
  11374. #endif /* IKSD */
  11375. #ifdef OS2
  11376.          {
  11377.             char * getcpu(void) ;
  11378.             return getcpu();
  11379.          }
  11380. #else /* OS2 */
  11381. #ifdef CKCPU
  11382.         return(CKCPU);                  /* Traditionally, compile-time value */
  11383. #else
  11384. #ifdef CK_UTSNAME
  11385.         {                               /* But if none, try runtime value */
  11386.             extern char unm_mch[];
  11387.             return((char *)unm_mch);
  11388.         }
  11389. #else
  11390.         return("unknown");
  11391. #endif /* CK_UTSNAME */
  11392. #endif /* CKCPU */
  11393. #endif /* OS2 */
  11394.  
  11395.       case VN_CMDL:                     /* Command level */
  11396.         sprintf(vvbuf, "%d", cmdlvl);    /* SAFE */
  11397.         return(vvbuf);
  11398.  
  11399.       case VN_DAY:                      /* Day of week */
  11400.         ztime(&p);
  11401.         if (p != NULL && *p != NUL)     /* ztime() succeeded. */
  11402.           ckstrncpy(vvbuf,p,4);
  11403.         else
  11404.           vvbuf[0] = NUL;               /* ztime() failed. */
  11405.         return(vvbuf);                  /* Return what we got. */
  11406.  
  11407.       case VN_NDAY: {                   /* Numeric day of week */
  11408.           long k;
  11409.           z = mjd(zzndate());           /* Get modified Julian date */
  11410.           k = (((int)(z % 7L)) + 3) % 7; /* Get day number */
  11411.           sprintf(vvbuf,"%ld",k);    /* SAFE */
  11412.           return(vvbuf);
  11413.       }
  11414.  
  11415.       case VN_LCL:                      /* Local (vs remote) mode */
  11416.         ckstrncpy(vvbuf, local ? "1" : "0",VVBUFL);
  11417.         return(vvbuf);
  11418.  
  11419.       case VN_CMDS:                     /* Command source */
  11420.         if (cmdstk[cmdlvl].src == CMD_KB)
  11421.           ckstrncpy(vvbuf,"prompt",VVBUFL);
  11422.         else if (cmdstk[cmdlvl].src == CMD_MD)
  11423.           ckstrncpy(vvbuf,"macro",VVBUFL);
  11424.         else if (cmdstk[cmdlvl].src == CMD_TF)
  11425.           ckstrncpy(vvbuf,"file",VVBUFL);
  11426.         else
  11427.       ckstrncpy(vvbuf,"unknown",VVBUFL);
  11428.         return(vvbuf);
  11429.  
  11430.       case VN_CMDF:                     /* Current command file name */
  11431. #ifdef COMMENT                          /* (see comments above) */
  11432.         if (tfnam[tlevel]) {            /* (near dblbs declaration) */
  11433.             dblbs(tfnam[tlevel],vvbuf,VVBUFL);
  11434.             return(vvbuf);
  11435.         } else return("");
  11436. #else
  11437.         if (tlevel < 0)
  11438.           return("");
  11439.         else
  11440.           return(tfnam[tlevel] ? tfnam[tlevel] : "");
  11441. #endif /* COMMENT */
  11442.  
  11443.       case VN_MAC:                      /* Current macro name */
  11444.         return((maclvl > -1) ? m_arg[maclvl][0] : "");
  11445.  
  11446.       case VN_EXIT:
  11447.         sprintf(vvbuf,"%d",xitsta);    /* SAFE */
  11448.         return(vvbuf);
  11449.  
  11450.     } /* Break up long switch statements... */
  11451.  
  11452.     switch(y) {
  11453.       case VN_PRTY: {                   /* Parity */
  11454.           char *ss;
  11455.           switch (parity) {
  11456.             case 0:   ss = "none";  break;
  11457.             case 'e': ss = "even";  break;
  11458.             case 'm': ss = "mark";  break;
  11459.             case 'o': ss = "odd";   break;
  11460.             case 's': ss = "space"; break;
  11461.             default:  ss = "unknown"; break;
  11462.           }
  11463.           ckstrncpy(vvbuf,ss,VVBUFL);
  11464.           return(vvbuf);
  11465.       }
  11466.  
  11467.       case VN_DIAL:
  11468.         sprintf(vvbuf,"%d",        /* SAFE */
  11469. #ifndef NODIAL
  11470.                 dialsta
  11471. #else
  11472.                 -1
  11473. #endif /* NODIAL */
  11474.                 );
  11475.         return(vvbuf);
  11476.  
  11477. #ifdef OS2
  11478.       case VN_KEYB:
  11479.         ckstrncpy(vvbuf,conkbg(),VVBUFL);
  11480.         return(vvbuf);
  11481.       case VN_SELCT: {
  11482. #ifndef NOLOCAL
  11483.           const char * selection = GetSelection();
  11484.           return( (char *) (selection ? selection : "" )) ;
  11485. #else
  11486.           return("");
  11487. #endif /* NOLOCAL */
  11488.       }
  11489. #endif /* OS2 */
  11490.  
  11491. #ifndef NOXFER
  11492.       case VN_CPS:
  11493.         sprintf(vvbuf,"%ld",tfcps);    /* SAFE */
  11494.         return(vvbuf);
  11495. #endif /* NOXFER */
  11496.  
  11497.       case VN_MODE:                     /* File transfer mode */
  11498.         switch (binary) {
  11499.           case XYFT_T: ckstrncpy(vvbuf,"text",VVBUFL); break;
  11500.           case XYFT_B:
  11501.           case XYFT_U: ckstrncpy(vvbuf,"binary",VVBUFL); break;
  11502.           case XYFT_I: ckstrncpy(vvbuf,"image",VVBUFL); break;
  11503.           case XYFT_L: ckstrncpy(vvbuf,"labeled",VVBUFL); break;
  11504.           case XYFT_M: ckstrncpy(vvbuf,"macbinary",VVBUFL); break;
  11505.           default:     ckstrncpy(vvbuf,"unknown",VVBUFL);
  11506.         }
  11507.         return(vvbuf);
  11508.  
  11509. #ifdef CK_REXX
  11510.       case VN_REXX:
  11511.         return(rexxbuf);
  11512. #endif /* CK_REXX */
  11513.  
  11514.       case VN_NEWL:                     /* System newline char or sequence */
  11515. #ifdef UNIX
  11516.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11517. #else
  11518. #ifdef datageneral
  11519.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11520. #else
  11521. #ifdef OSK
  11522.         ckstrncpy(vvbuf,"\15",VVBUFL);    /* Remember, these are octal... */
  11523. #else
  11524. #ifdef MAC
  11525.         ckstrncpy(vvbuf,"\15",VVBUFL);
  11526. #else
  11527. #ifdef OS2
  11528.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11529. #else
  11530. #ifdef STRATUS
  11531.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11532. #else
  11533. #ifdef VMS
  11534.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11535. #else
  11536. #ifdef AMIGA
  11537.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11538. #else
  11539. #ifdef GEMDOS
  11540.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11541. #else
  11542.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11543. #endif /* GEMDOS */
  11544. #endif /* AMIGA */
  11545. #endif /* VMS */
  11546. #endif /* STRATUS */
  11547. #endif /* OS2 */
  11548. #endif /* MAC */
  11549. #endif /* OSK */
  11550. #endif /* datageneral */
  11551. #endif /* UNIX */
  11552.         return(vvbuf);
  11553.  
  11554.       case VN_ROWS:                     /* ROWS */
  11555.       case VN_COLS:                     /* COLS */
  11556.         ckstrncpy(vvbuf,(cx == VN_ROWS) ? "24" : "80",VVBUFL); /* Default */
  11557. #ifdef CK_TTGWSIZ
  11558. #ifdef OS2
  11559.         if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  11560.           ttgwsiz();
  11561.         sprintf(vvbuf,"%d",        /* SAFE */
  11562.         (cx == VN_ROWS) ? tt_rows[VTERM] : tt_cols[VTERM]);
  11563. #else /* OS2 */
  11564.         if (ttgwsiz() > 0)              /* Get window size */
  11565.           if (tt_cols > 0 && tt_rows > 0) /* sets tt_rows, tt_cols */
  11566.             sprintf(vvbuf,"%d",        /* SAFE */
  11567.             (cx == VN_ROWS) ? tt_rows : tt_cols);
  11568. #endif /* OS2 */
  11569. #endif /* CK_TTGWSIZ */
  11570.         return(vvbuf);
  11571.  
  11572.       case VN_TTYP:
  11573. #ifdef NOTERM
  11574.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11575. #else
  11576. #ifdef OS2
  11577.         sprintf(vvbuf, "%s",        /* SAFE */
  11578.                 (tt_type >= 0 && tt_type <= max_tt) ?
  11579.                 tt_info[tt_type].x_name :
  11580.                 "unknown"
  11581.                 );
  11582. #else
  11583. #ifdef MAC
  11584.         ckstrncpy(vvbuf,"vt320",VVBUFL);
  11585. #else
  11586.         p = getenv("TERM");
  11587.         ckstrncpy(vvbuf,p ? p : "unknown",VVBUFL+1);
  11588. #endif /* MAC */
  11589. #endif /* OS2 */
  11590. #endif /* NOTERM */
  11591.         return(vvbuf);
  11592.  
  11593.       case VN_MINP:                     /* MINPUT */
  11594.         sprintf(vvbuf, "%d", m_found);    /* SAFE */
  11595.         return(vvbuf);
  11596.     } /* Break up long switch statements... */
  11597.  
  11598.     switch(y) {
  11599.       case VN_CONN:                     /* CONNECTION */
  11600.         if (!local) {
  11601.           ckstrncpy(vvbuf,"remote",VVBUFL);
  11602.         } else {
  11603.             if (!network)
  11604.               ckstrncpy(vvbuf,"serial",VVBUFL);
  11605. #ifdef TCPSOCKET
  11606.             else if (nettype == NET_TCPB || nettype == NET_TCPA) {
  11607.                 if (ttnproto == NP_TELNET)
  11608.                   ckstrncpy(vvbuf,"tcp/ip_telnet",VVBUFL);
  11609. #ifdef CK_SSL
  11610.                 else if (ttnproto == NP_SSL)
  11611.                   ckstrncpy(vvbuf,"tcp/ip_ssl",VVBUFL);
  11612.                 else if (ttnproto == NP_TLS)
  11613.                   ckstrncpy(vvbuf,"tcp/ip_tls",VVBUFL);
  11614. #endif /* CK_SSL */
  11615.                 else
  11616.                   ckstrncpy(vvbuf,"tcp/ip",VVBUFL);
  11617.             }
  11618. #endif /* TCPSOCKET */
  11619. #ifdef SSHBUILTIN
  11620.             else if (nettype == NET_SSH)
  11621.                   ckstrncpy(vvbuf,"tcp/ip_ssh",VVBUFL);
  11622. #endif /* SSHBUILTIN */
  11623. #ifdef ANYX25
  11624.             else if (nettype == NET_SX25 ||
  11625.                      nettype == NET_VX25 ||
  11626.                      nettype == NET_IX25
  11627.                      )
  11628.               ckstrncpy(vvbuf,"x.25",VVBUFL);
  11629. #endif /* ANYX25 */
  11630. #ifdef DECNET
  11631.             else if (nettype == NET_DEC) {
  11632.                 if (ttnproto == NP_LAT)
  11633.           ckstrncpy(vvbuf,"decnet_lat",VVBUFL);
  11634.                 else if ( ttnproto == NP_CTERM )
  11635.           ckstrncpy(vvbuf,"decnet_cterm",VVBUFL);
  11636.                 else
  11637.           ckstrncpy(vvbuf,"decnet",VVBUFL);
  11638.             }
  11639. #endif /* DECNET */
  11640. #ifdef SUPERLAT
  11641.         else if (nettype == NET_SLAT)
  11642.           ckstrncpy(vvbuf,"superlat",VVBUFL);
  11643. #endif /* SUPERLAT */
  11644. #ifdef NETFILE
  11645.         else if (nettype == NET_FILE)
  11646.           ckstrncpy(vvbuf,"local_file",VVBUFL);
  11647. #endif /* NETFILE */
  11648. #ifdef NETCMD
  11649.         else if (nettype == NET_CMD)
  11650.           ckstrncpy(vvbuf,"pipe",VVBUFL);
  11651. #endif /* NETCMD */
  11652. #ifdef NETPTY
  11653.         else if (nettype == NET_PTY)
  11654.           ckstrncpy(vvbuf,"pseudoterminal",VVBUFL);
  11655. #endif /* NETPTY */
  11656. #ifdef NETDLL
  11657.         else if (nettype == NET_DLL)
  11658.           ckstrncpy(vvbuf,"dynamic_link_library",VVBUFL);
  11659. #endif /* NETDLL */
  11660.  
  11661. #ifdef NPIPE
  11662.             else if (nettype == NET_PIPE)
  11663.               ckstrncpy(vvbuf,"named_pipe",VVBUFL);
  11664. #endif /* NPIPE */
  11665. #ifdef CK_NETBIOS
  11666.             else if (nettype == NET_BIOS)
  11667.               ckstrncpy(vvbuf,"netbios",VVBUFL);
  11668. #endif /* CK_NETBIOS */
  11669.             else
  11670.               ckstrncpy(vvbuf,"unknown",VVBUFL);
  11671.         }
  11672.         return(vvbuf);
  11673.  
  11674. #ifndef NOXFER
  11675.       case VN_SYSI:                     /* System ID, Kermit code */
  11676.         return((char *)cksysid);
  11677. #endif /* NOXFER */
  11678.  
  11679. #ifdef OS2
  11680.       case VN_SPA: {
  11681.       unsigned long space = zdskspace(0);
  11682.       if (space > 0 && space < 1024)
  11683.         sprintf(vvbuf,"-1");
  11684.       else
  11685.         sprintf(vvbuf,"%lu",space); /* SAFE */
  11686.       return(vvbuf);
  11687.       }
  11688. #endif /* OS2 */
  11689.  
  11690. #ifndef NOXFER
  11691.       case VN_QUE: {
  11692.           extern char querybuf[];
  11693.           return(querybuf);
  11694.       }
  11695. #endif /* NOXFER */
  11696.  
  11697. #ifndef NOCSETS
  11698.       case VN_CSET:
  11699. #ifdef OS2
  11700.         sprintf(vvbuf,"cp%d",os2getcp()); /* SAFE */
  11701. #else
  11702.         ckstrncpy(vvbuf,fcsinfo[fcharset].keyword,VVBUFL+1);
  11703. #endif /* OS2 */
  11704.         return(vvbuf);
  11705. #endif /* NOCSETS */
  11706.  
  11707. #ifdef OS2
  11708.       case VN_EXEDIR:
  11709.         return(exedir);
  11710.       case VN_STAR:
  11711.         return(startupdir);
  11712. #else
  11713.       case VN_EXEDIR:
  11714.         return(exedir ? exedir : "");
  11715. #ifdef VMSORUNIX
  11716.       case VN_STAR:
  11717.         return(startupdir);
  11718. #endif /* VMSORUNIX */
  11719. #endif /* OS2 */
  11720.  
  11721.       case VN_INI:
  11722.         return(inidir);
  11723.  
  11724.       case VN_MDM:
  11725.         return(gmdmtyp());
  11726.  
  11727.       case VN_EVAL:
  11728.         return(evalbuf);
  11729.  
  11730. #ifndef NODIAL
  11731.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  11732.         return(diallcc ? diallcc : "");
  11733.  
  11734.       case VN_D_AC:                     /* DIAL AREA-CODE */
  11735.         return(diallac ? diallac : "");
  11736.  
  11737.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  11738.         return(dialixp ? dialixp : "");
  11739.  
  11740.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  11741.         return(dialldp ? dialldp : "");
  11742.  
  11743.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  11744.         return(diallcp ? diallcp : "");
  11745.  
  11746.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE that matched */
  11747.         return(matchpxx ? matchpxx : "");
  11748. #else
  11749.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  11750.       case VN_D_AC:                     /* DIAL AREA-CODE */
  11751.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  11752.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  11753.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  11754.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE */
  11755.         return("");
  11756. #endif /* NODIAL */
  11757.       case VN_UID:
  11758. #ifdef UNIX
  11759.         {
  11760.             extern char * whoami();     /* From ckufio.c... */
  11761. #ifdef IKSD
  11762.             if (inserver)
  11763.               return((char *)uidbuf);
  11764.             else
  11765. #endif /* IKSD */
  11766.           if (uidbuf[0])
  11767.                 return((char *)uidbuf);
  11768.           else
  11769.                 return(whoami());
  11770.         }
  11771. #else
  11772.         return((char *)uidbuf);
  11773. #endif /* UNIX */
  11774.     } /* Break up long switch statements... */
  11775.  
  11776.     switch(y) {
  11777.       case VN_PWD:
  11778. #ifdef OS2
  11779.         if (activecmd == XXOUT || activecmd == XXLNOUT) {
  11780.             ckstrncpy(vvbuf,pwbuf,VVBUFL);
  11781.             ck_encrypt((char *)vvbuf);
  11782.             return((char *)vvbuf);
  11783.         } else
  11784. #endif /* OS2 */
  11785.           return((char *)pwbuf);
  11786.  
  11787.       case VN_PRM:
  11788.         return((char *)prmbuf);
  11789.  
  11790.       case VN_PROTO:
  11791. #ifdef NOXFER
  11792.         return("none");
  11793. #else
  11794. #ifdef CK_XYZ
  11795.         return(ptab[protocol].p_name);
  11796. #else
  11797.         return("kermit");
  11798. #endif /* CK_XYZ */
  11799. #endif /* NOXFER */
  11800.  
  11801. #ifndef NOXFER
  11802. #ifdef CK_TMPDIR
  11803.       case VN_DLDIR:
  11804.         return(dldir ? dldir : "");
  11805. #endif /* CK_TMPDIR */
  11806. #endif /* NOXFER */
  11807.  
  11808. #ifndef NODIAL
  11809.       case VN_M_INI:                    /* Modem init string */
  11810.         return(dialini ? dialini : (m ? m->wake_str : ""));
  11811.  
  11812.       case VN_M_DCM:                    /* Modem dial command */
  11813.         return(dialcmd ? dialcmd : (m ? m->dial_str : ""));
  11814.  
  11815.       case VN_M_DCO:                    /* Modem data compression on */
  11816.         return(dialdcon ? dialdcon : (m ? m->dc_on_str : ""));
  11817.  
  11818.       case VN_M_DCX:                    /* Modem data compression off */
  11819.         return(dialdcoff ? dialdcoff : (m ? m->dc_off_str : ""));
  11820.  
  11821.       case VN_M_ECO:                    /* Modem error correction on */
  11822.         return(dialecon ? dialecon : (m ? m->ec_on_str : ""));
  11823.  
  11824.       case VN_M_ECX:                    /* Modem error correction off */
  11825.         return(dialecoff ? dialecoff : (m ? m->ec_off_str : ""));
  11826.  
  11827.       case VN_M_AAO:                    /* Modem autoanswer on */
  11828.         return(dialaaon ? dialaaon : (m ? m->aa_on_str : ""));
  11829.  
  11830.       case VN_M_AAX:                    /* Modem autoanswer off */
  11831.         return(dialaaoff ? dialaaoff : (m ? m->aa_off_str : ""));
  11832.  
  11833.       case VN_M_HUP:                    /* Modem hangup command */
  11834.         return(dialhcmd ? dialhcmd : (m ? m->hup_str : ""));
  11835.  
  11836.       case VN_M_HWF:                    /* Modem hardware flow command */
  11837.         return(dialhwfc ? dialhwfc : (m ? m->hwfc_str : ""));
  11838.  
  11839.       case VN_M_SWF:                    /* Modem software flow command */
  11840.         return(dialswfc ? dialswfc : (m ? m->swfc_str : ""));
  11841.  
  11842.       case VN_M_NFC:                    /* Modem no flow-control command */
  11843.         return(dialnofc ? dialnofc : (m ? m->nofc_str : ""));
  11844.  
  11845.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  11846.         return(dialpulse ? dialpulse : (m ? m->pulse : ""));
  11847.  
  11848.       case VN_M_TDM:                    /* Modem tone dialing mode */
  11849.         return(dialtone ? dialtone : (m ? m->tone : ""));
  11850.  
  11851.       case VN_M_NAM:                    /* Modem full name */
  11852.         return(dialname ? dialname : (m ? m->name : ""));
  11853. #else
  11854.       case VN_M_INI:                    /* Modem init string */
  11855.       case VN_M_DCM:                    /* Modem dial command */
  11856.       case VN_M_DCO:                    /* Modem data compression on */
  11857.       case VN_M_DCX:                    /* Modem data compression off */
  11858.       case VN_M_ECO:                    /* Modem error correction on */
  11859.       case VN_M_ECX:                    /* Modem error correction off */
  11860.       case VN_M_AAO:                    /* Modem autoanswer on */
  11861.       case VN_M_AAX:                    /* Modem autoanswer off */
  11862.       case VN_M_HUP:                    /* Modem hangup command */
  11863.       case VN_M_HWF:                    /* Modem hardware flow command */
  11864.       case VN_M_SWF:                    /* Modem software flow command */
  11865.       case VN_M_NFC:                    /* Modem no flow-control command */
  11866.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  11867.       case VN_M_TDM:                    /* Modem tone dialing mode */
  11868.       case VN_M_NAM:
  11869.         return("");
  11870. #endif /* NODIAL */
  11871.  
  11872.       case VN_ISTAT:                    /* INPUT status */
  11873.         sprintf(vvbuf, "%d", instatus);    /* SAFE */
  11874.         return(vvbuf);
  11875.  
  11876.       case VN_TEMP:                     /* Temporary directory */
  11877.         if (tempdir) {
  11878.             p = tempdir;
  11879.         } else {
  11880. #ifdef OS2
  11881. #ifdef NT
  11882.             p = getenv("K95TMP");
  11883. #else
  11884.             p = getenv("K2TMP");
  11885. #endif /* NT */
  11886.             if ( !p )
  11887. #endif /* OS2 */
  11888.               p = getenv("CK_TMP");
  11889.             if (!p) p = getenv("TMPDIR");
  11890.             if (!p) p = getenv("TEMP");
  11891.             if (!p) p = getenv("TMP");
  11892.  
  11893. #ifdef OS2ORUNIX
  11894.         if (p) {
  11895.         int len = strlen(p);
  11896.         if (p[len-1] != '/'
  11897. #ifdef OS2
  11898.                     && p[len-1] != '\\'
  11899. #endif /* OS2 */
  11900.                      ) {
  11901.             static char foo[CKMAXPATH];
  11902.             ckstrncpy(foo,p,CKMAXPATH);
  11903.             ckstrncat(foo,"/",CKMAXPATH);
  11904.             p = foo;
  11905.         }
  11906.         } else
  11907. #else /* OS2ORUNIX */
  11908.             if (!p)
  11909. #endif /* OS2ORUNIX */
  11910. #ifdef UNIX                             /* Systems that have a standard */
  11911.               p = "/tmp/";              /* temporary directory... */
  11912. #else
  11913. #ifdef datageneral
  11914.               p = ":TMP:";
  11915. #else
  11916.               p = "";
  11917. #endif /* datageneral */
  11918. #endif /* UNIX */
  11919.         }
  11920.         ckstrncpy(vvbuf,p,VVBUFL);
  11921.         p = vvbuf;
  11922.  
  11923. /* This needs generalizing for VOS, AOS/VS, etc... */
  11924.  
  11925.         while (*p) {
  11926. #ifdef OS2
  11927.             if (*p == '\\') *p = '/';
  11928. #endif /* OS2 */
  11929.             p++;
  11930.         }
  11931. #ifndef VMS
  11932.         if (p > vvbuf) {
  11933.             char c =                    /* Directory termination character */
  11934. #ifdef MAC
  11935.               ':'
  11936. #else
  11937. #ifdef datageneral
  11938.               ':'
  11939. #else
  11940. #ifdef STRATUS
  11941.               '>'
  11942. #else
  11943.               '/'
  11944. #endif /* STRATUS */
  11945. #endif /* datageneral */
  11946. #endif /* MAC */
  11947.                 ;
  11948.  
  11949.             if (*(p-1) != c) {
  11950.                 *p++ = c;
  11951.                 *p = NUL;
  11952.             }
  11953.         }
  11954. #endif /* VMS */
  11955.         return(vvbuf);
  11956.     } /* Break up long switch statements... */
  11957.  
  11958.     switch(y) {
  11959.       case VN_ERRNO:                    /* Error number */
  11960. #ifdef VMS
  11961.         {
  11962.             extern int vms_lasterr;
  11963.             sprintf(vvbuf, "%d", vms_lasterr); /* SAFE */
  11964.         }
  11965. #else
  11966.         sprintf(vvbuf, "%d", errno);    /* SAFE */
  11967. #endif /* VMS */
  11968.         return(vvbuf);
  11969.  
  11970.       case VN_ERSTR:                    /* Error string */
  11971.         ckstrncpy(vvbuf,ck_errstr(),VVBUFL);
  11972.         return(vvbuf);
  11973.  
  11974. #ifndef NOXFER
  11975.       case VN_RPSIZ:                    /* RECEIVE packet-length */
  11976.         sprintf(vvbuf,"%d",urpsiz);    /* SAFE */
  11977.         return(vvbuf);
  11978.  
  11979.       case VN_WINDO:                    /* WINDOW slots */
  11980.         sprintf(vvbuf,"%d",wslotr);    /* SAFE */
  11981.         return(vvbuf);
  11982. #endif /* NOXFER */
  11983.  
  11984.       case VN_TFLN:                     /* TAKE-file line number */
  11985.         if (tlevel > -1) {
  11986.             sprintf(vvbuf, "%d", tfline[tlevel]); /* SAFE */
  11987.             return(vvbuf);
  11988.         } else
  11989.           return("0");
  11990.  
  11991.       case VN_MDMSG:                    /* DIALRESULT */
  11992. #ifndef NODIAL
  11993.         return((char *)modemmsg);
  11994. #else
  11995.         return("");
  11996. #endif /* NODIAL */
  11997.  
  11998.       case VN_DNUM:                     /* DIALNUMBER */
  11999. #ifndef NODIAL
  12000.         return(dialnum ? (char *) dialnum : "");
  12001. #else
  12002.         return("");
  12003. #endif /* NODIAL */
  12004.  
  12005.       case VN_APC:
  12006.         sprintf(vvbuf, "%d",        /* SAFE */
  12007. #ifdef CK_APC
  12008.                 apcactive
  12009. #else
  12010.                 0
  12011. #endif /* CK_APC */
  12012.                 );
  12013.         return((char *)vvbuf);
  12014.  
  12015. #ifdef OS2
  12016. #ifndef NOKVERBS
  12017.       case VN_TRMK:
  12018.           sprintf(vvbuf, "%d", keymac);    /* SAFE */
  12019.         return((char *)vvbuf);
  12020. #endif /* NOKVERBS */
  12021. #endif /* OS2 */
  12022.  
  12023.       case VN_IPADDR:
  12024. #ifdef TCPSOCKET
  12025. #ifndef OSK
  12026.       /* This dumps core on OS-9 for some reason, but only if executed */
  12027.       /* before we have made a TCP connection.  This is obviously not */
  12028.       /* the ideal fix. */
  12029.         if (!myipaddr[0])
  12030.           getlocalipaddr();
  12031. #endif /* OSK */
  12032. #endif /* TCPSOCKET */
  12033.     ckstrncpy(vvbuf,
  12034. #ifdef TCPSOCKET
  12035.                 (char *)myipaddr,
  12036. #else
  12037.                 "",
  12038. #endif /* TCPSOCKET */
  12039.         VVBUFL);
  12040.         return((char *)vvbuf);
  12041.  
  12042. #ifndef NOXFER
  12043.       case VN_CRC16:                    /* CRC-16 of most recent transfer */
  12044.         sprintf(vvbuf,"%d",crc16);    /* SAFE */
  12045.         return(vvbuf);
  12046. #endif /* NOXFER */
  12047.  
  12048. #ifdef CK_PID
  12049.       case VN_PID:
  12050. #ifdef IKSD
  12051. #ifdef CK_LOGIN
  12052.         if (inserver && isguest)
  12053.           return("");
  12054. #endif /* CK_LOGIN */
  12055. #endif /* IKSD */
  12056.         return(ckgetpid());
  12057. #endif /* CK_PID */
  12058.  
  12059. #ifndef NOXFER
  12060.       case VN_FNAM: {                   /* \v(filename) */
  12061.           extern char filnam[], ofn1[], *sfspec, *rrfspec;
  12062.           char * tmp;
  12063.           switch (what) {               /* File transfer is in progress */
  12064. #ifdef NEWFTP
  12065.         case (W_FTP|W_RECV):
  12066.         case (W_FTP|W_SEND):
  12067.           return((char *)filnam);
  12068. #endif /* NEWFTP */
  12069.             case W_RECV:
  12070.             case W_REMO:
  12071.               return((char *)ofn1);
  12072.             default:                    /* Most recent file transferred */
  12073.               if (filnam[0]) {          /* (if any) */
  12074.                   return((char *)filnam);
  12075.               } else if (lastxfer & W_SEND && sfspec) {
  12076.                   if (fnspath == PATH_OFF)
  12077.                     zstrip(sfspec,&tmp);
  12078.                   else
  12079.                     tmp = sfspec;
  12080.                   return(tmp);
  12081.               } else if (lastxfer & W_RECV && rrfspec) {
  12082.                   if (fnrpath == PATH_OFF)
  12083.                     zstrip(rrfspec,&tmp);
  12084.                   else
  12085.                     tmp = rrfspec;
  12086.                   return(tmp);
  12087.               } else
  12088.                 return("");
  12089.           }
  12090.       }
  12091.       case VN_FNUM:                     /* \v(filenum) */
  12092.         sprintf(vvbuf,"%ld",filcnt);    /* SAFE */
  12093.         return((char *)vvbuf);
  12094. #endif /* NOXFER */
  12095.  
  12096. #ifdef PEXITSTAT
  12097.       case VN_PEXIT: {
  12098.           extern int pexitstat;
  12099.           sprintf(vvbuf,"%d",pexitstat); /* SAFE */
  12100.           return((char *)vvbuf);
  12101.       }
  12102. #endif /* PEXITSTAT */
  12103.  
  12104. #ifndef NOXFER
  12105.       case VN_P_8BIT:
  12106.         vvbuf[0] = parity ? ebq : NUL;
  12107.         vvbuf[1] = NUL;
  12108.         return((char *)vvbuf);
  12109.  
  12110.       case VN_P_CTL: {
  12111.           extern CHAR myctlq;
  12112.           vvbuf[0] = myctlq;
  12113.           vvbuf[1] = NUL;
  12114.           return((char *)vvbuf);
  12115.       }
  12116.       case VN_P_RPT: {
  12117.           extern int rptena;
  12118.           vvbuf[0] = rptena ? rptq : NUL;
  12119.           vvbuf[1] = NUL;
  12120.           return((char *)vvbuf);
  12121.       }
  12122. #endif /* NOXFER */
  12123.  
  12124. #ifdef OS2
  12125.       case VN_REGN:
  12126.         return(get_reg_name());
  12127.       case VN_REGO:
  12128.         return(get_reg_corp());
  12129.       case VN_REGS:
  12130.         return(get_reg_sn());
  12131. #endif /* OS2 */
  12132.     } /* Break up long switch statements... */
  12133.  
  12134.     switch(y) {
  12135.       case VN_XPROG:
  12136. #ifdef OS2
  12137. #ifdef NT
  12138. #ifdef KUI
  12139.         return("K-95G");
  12140. #else
  12141.         return("K-95");
  12142. #endif /* KUI */
  12143. #else
  12144.         return("K/2");
  12145. #endif /* NT */
  12146. #else
  12147.         return("C-Kermit");
  12148. #endif /* OS2 */
  12149.  
  12150.       case VN_EDITOR:
  12151. #ifdef NOFRILLS
  12152.         return("");
  12153. #else
  12154. #ifdef NOPUSH
  12155.         return("");
  12156. #else
  12157.         {
  12158.             extern char editor[];
  12159.             char *ss;
  12160.             if (!editor[0]) {
  12161.                 ss = getenv("EDITOR");
  12162.                 if (ss) {
  12163.                     ckstrncpy(editor,ss,CKMAXPATH);
  12164.                 }
  12165.             }
  12166.             debug(F110,"\\v(editor)",editor,0);
  12167.             return(editor[0] ? (char *)editor : "");
  12168.         }
  12169. #endif /* NOPUSH */
  12170. #endif /* NOFRILLS */
  12171.  
  12172.       case VN_EDOPT:
  12173. #ifdef NOFRILLS
  12174.         return("");
  12175. #else
  12176. #ifdef NOPUSH
  12177.         return("");
  12178. #else
  12179.         {
  12180.             extern char editopts[];
  12181.             return(editopts[0] ? (char *)editopts : "");
  12182.         }
  12183. #endif /* NOPUSH */
  12184. #endif /* NOFRILLS */
  12185.  
  12186.       case VN_EDFILE:
  12187. #ifdef NOFRILLS
  12188.         return("");
  12189. #else
  12190. #ifdef NOPUSH
  12191.         return("");
  12192. #else
  12193.         {
  12194.             extern char editfile[];
  12195.             return(editfile[0] ? (char *)editfile : "");
  12196.         }
  12197. #endif /* NOPUSH */
  12198. #endif /* NOFRILLS */
  12199.  
  12200. #ifdef BROWSER
  12201.       case VN_BROWSR: {
  12202.           extern char browser[];
  12203.           if (!browser[0]) {
  12204.               s = getenv("BROWSER");
  12205.               if (s) ckstrncpy(browser,s,CKMAXPATH);
  12206.           }
  12207.           return(browser[0] ? (char *)browser : "");
  12208.       }
  12209.       case VN_BROPT: {
  12210.           extern char browsopts[];
  12211.           return(browsopts[0] ? (char *)browsopts : "");
  12212.       }
  12213.       case VN_URL: {
  12214.           extern char browsurl[];
  12215.           return(browsurl[0] ? (char *)browsurl : "");
  12216.       }
  12217. #endif /* BROWSER */
  12218.       case VN_HERALD:
  12219.         return((char *)versio);
  12220.  
  12221.       case VN_TEST: {                   /* test */
  12222.           extern char * ck_s_test, * ck_s_tver;
  12223.           if (!ck_s_test) ck_s_test = "";
  12224.           if (!ck_s_tver) ck_s_tver = "";
  12225.           if (*ck_s_test) {
  12226.               ckstrncpy(vvbuf,ck_s_test,VVBUFL);
  12227.               if (*ck_s_tver) {
  12228.                   ckstrncat(vvbuf,".",VVBUFL);
  12229.                   ckstrncat(vvbuf,ck_s_tver,VVBUFL);
  12230.               }
  12231.           } else
  12232.             ckstrncpy(vvbuf,"0",VVBUFL);
  12233.           return((char *)vvbuf);
  12234.       }
  12235.  
  12236. #ifndef NOXFER
  12237.       case VN_XFSTAT:                   /* xferstatus */
  12238.         x = xferstat;                   /* Like success */
  12239.         if (x > -1) x = (x == 0) ? 1 : 0; /* External value is reversed */
  12240.         sprintf(vvbuf,"%d",x);        /* SAFE */
  12241.         return((char *)vvbuf);
  12242.  
  12243.       case VN_XFMSG:                    /* xfermsg */
  12244.         return((char *)epktmsg);
  12245.  
  12246. #ifndef NOMSEND
  12247.       case VN_SNDL: {                   /* sendlist */
  12248.           extern int filesinlist;
  12249.           sprintf(vvbuf,"%d",filesinlist); /* SAFE */
  12250.           return((char *)vvbuf);
  12251.       }
  12252. #endif /* NOMSEND */
  12253. #endif /* NOXFER */
  12254.  
  12255. #ifdef CK_TRIGGER
  12256.       case VN_TRIG: {
  12257.           extern char * triggerval;
  12258.           return(triggerval ? triggerval : "");
  12259.       }
  12260. #endif /* CK_TRIGGER */
  12261. #ifdef OS2MOUSE
  12262. #ifdef OS2
  12263.       case VN_MOU_X: {
  12264.           extern int MouseCurX;
  12265.           sprintf(vvbuf,"%d",MouseCurX); /* SAFE */
  12266.           return((char *)vvbuf);
  12267.       }
  12268.       case VN_MOU_Y: {
  12269.           extern int MouseCurY;
  12270.           sprintf(vvbuf,"%d",MouseCurY); /* SAFE */
  12271.           return((char *)vvbuf);
  12272.       }
  12273. #endif /* OS2 */
  12274. #endif /* OS2MOUSE */
  12275.       case VN_PRINT: {
  12276.           extern int printpipe;
  12277.           extern char * printername;
  12278. #ifdef PRINTSWI
  12279.           extern int noprinter;
  12280.           if (noprinter) return("");
  12281. #endif /* PRINTSWI */
  12282.       ckmakmsg(vvbuf,VVBUFL,
  12283.            printpipe ? "|" : "",
  12284.            printername ? printername :
  12285. #ifdef OS2
  12286.            "PRN",
  12287. #else
  12288.            "(default)",
  12289. #endif /* OS2 */
  12290.            NULL,
  12291.            NULL
  12292.            );
  12293.           return((char *)vvbuf);
  12294.       }
  12295.     } /* Break up long switch statements... */
  12296.  
  12297.     switch(y) {
  12298.       case VN_ESC:                      /* Escape character */
  12299.         sprintf(vvbuf,"%d",escape);    /* SAFE */
  12300.         return((char *)vvbuf);
  12301.  
  12302.       case VN_INTIME:
  12303.         sprintf(vvbuf,"%ld",inetime);    /* SAFE */
  12304.         return((char *)vvbuf);
  12305.  
  12306.       case VN_INTMO:
  12307.         sprintf(vvbuf,"%d",inwait);    /* SAFE */
  12308.         return((char *)vvbuf);
  12309.  
  12310.       case VN_SECURE:
  12311.     if (0
  12312. #ifdef CK_ENCRYPTION
  12313.         || ck_tn_encrypting() && ck_tn_decrypting()
  12314. #endif /* CK_ENCRYPTION */
  12315. #ifdef CK_SSL
  12316.         || tls_active_flag || ssl_active_flag
  12317. #endif /* CK_SSL */
  12318.         )
  12319.       return("1");
  12320.     else
  12321.       return("0");
  12322.  
  12323.       case VN_AUTHN:
  12324. #ifdef CK_AUTHENTICATION
  12325.         {
  12326.             extern char szUserNameAuthenticated[];
  12327.             return((char *)szUserNameAuthenticated);
  12328.         }
  12329. #else /* CK_AUTHENTICATION */
  12330.         return((char *)"");
  12331. #endif /* CK_AUTHENTICATION */
  12332.  
  12333.       case VN_AUTHS:
  12334. #ifdef CK_AUTHENTICATION
  12335.         switch (ck_tn_auth_valid()) {
  12336.           case AUTH_UNKNOWN:
  12337.             return((char *)"unknown");
  12338.           case AUTH_OTHER:
  12339.             return((char *)"other");
  12340.           case AUTH_USER:
  12341.             return((char *)"user");
  12342.           case AUTH_VALID:
  12343.             return((char *)"valid");
  12344.           case AUTH_REJECT:
  12345.           default:
  12346.             return((char *)"rejected");
  12347.         }
  12348. #else /* CK_AUTHENTICATION */
  12349.         return((char *)"rejected");
  12350. #endif /* CK_AUTHENTICATION */
  12351.  
  12352.       case VN_AUTHT:
  12353. #ifdef CK_AUTHENTICATION
  12354. #ifdef CK_SSL
  12355.         if ((ssl_active_flag || tls_active_flag) &&
  12356.         ck_tn_auth_valid() == AUTH_VALID &&
  12357.         (sstelnet ? (!TELOPT_U(TELOPT_AUTHENTICATION)) :
  12358.                         (!TELOPT_ME(TELOPT_AUTHENTICATION))) ||
  12359.          ck_tn_authenticated() == AUTHTYPE_NULL ||
  12360.          ck_tn_authenticated() == AUTHTYPE_AUTO)
  12361.       return("X_509_CERTIFICATE");
  12362.         else
  12363. #endif /* CK_SSL */
  12364.       return(AUTHTYPE_NAME(ck_tn_authenticated()));
  12365. #else /* CK_AUTHENTICATION */
  12366.         return((char *)"NULL");
  12367. #endif /* CK_AUTHENTICATION */
  12368.  
  12369. #ifdef CK_KERBEROS
  12370.       case VN_K4PRN: {
  12371.           extern char * krb4_d_principal;
  12372.           if (krb4_d_principal)
  12373.             ckstrncpy(vvbuf,krb4_d_principal,VVBUFL+1);
  12374.           else
  12375.             *vvbuf = NUL;
  12376.           return((char *)vvbuf);
  12377.       }
  12378.       case VN_K5PRN: {
  12379.           extern char * krb5_d_principal;
  12380.           if (krb5_d_principal)
  12381.             ckstrncpy(vvbuf,krb5_d_principal,VVBUFL+1);
  12382.           else
  12383.             *vvbuf = NUL;
  12384.           return((char *)vvbuf);
  12385.       }
  12386.       case VN_K4RLM: {
  12387.           extern char * krb4_d_realm;
  12388.           if (krb4_d_realm) {
  12389.               ckstrncpy(vvbuf,krb4_d_realm,VVBUFL+1);
  12390.           } else {
  12391.               char * s = ck_krb4_getrealm();
  12392.               ckstrncpy(vvbuf,s ? s : "",VVBUFL+1);
  12393.           }
  12394.           return((char *)vvbuf);
  12395.       }
  12396.       case VN_K4SRV: {
  12397.           extern char * krb4_d_srv;
  12398.           if (krb4_d_srv)
  12399.             ckstrncpy(vvbuf,krb4_d_srv,VVBUFL+1);
  12400.           else
  12401.             ckstrncpy(vvbuf,"rcmd",VVBUFL);
  12402.           return((char *)vvbuf);
  12403.       }
  12404.       case VN_K5RLM: {
  12405.           extern char * krb5_d_realm;
  12406.           extern char * krb5_d_cc;
  12407.           if (krb5_d_realm) {
  12408.               ckstrncpy(vvbuf,krb5_d_realm,VVBUFL+1);
  12409.           } else {
  12410.               char * s = ck_krb5_getrealm(krb5_d_cc);
  12411.               ckstrncpy(vvbuf,s,VVBUFL+1);
  12412.           }
  12413.           return((char *)vvbuf);
  12414.       }
  12415.       case VN_K5CC: {
  12416.           extern char * krb5_d_cc;
  12417.           if (krb5_d_cc)
  12418.             ckstrncpy(vvbuf,krb5_d_cc,VVBUFL+1);
  12419.           else
  12420.             ckstrncpy(vvbuf,ck_krb5_get_cc_name(),VVBUFL+1);
  12421.           return((char *)vvbuf);
  12422.       }
  12423.       case VN_K5SRV: {
  12424.           extern char * krb5_d_srv;
  12425.           if (krb5_d_srv)
  12426.             ckstrncpy(vvbuf,krb5_d_srv,VVBUFL+1);
  12427.           else
  12428.             ckstrncpy(vvbuf,"host",VVBUFL);
  12429.           return((char *)vvbuf);
  12430.       }
  12431.       case VN_K4ENO: {
  12432.         extern char * krb4_errno;
  12433.         sprintf(vvbuf,"%d",krb4_errno);    /* SAFE */
  12434.         return((char *)vvbuf);
  12435.       }
  12436.       case VN_K5ENO: {
  12437.         extern char * krb5_errno;
  12438.         sprintf(vvbuf,"%d",krb5_errno);    /* SAFE */
  12439.         return((char *)vvbuf);
  12440.       }
  12441.       case VN_K4EMSG: {
  12442.         extern char * krb4_errmsg;
  12443.         ckstrncpy(vvbuf,krb4_errmsg?krb4_errmsg:"",VVBUFL+1);
  12444.         return((char *)vvbuf);
  12445.       }
  12446.       case VN_K5EMSG: {
  12447.         extern char * krb5_errmsg;
  12448.         ckstrncpy(vvbuf,krb5_errmsg,VVBUFL+1);
  12449.         return((char *)vvbuf);
  12450.       }
  12451. #endif /* CK_KERBEROS */
  12452. #ifdef CK_SSL
  12453.       case VN_X509_S:
  12454.     if (ssl_active_flag)
  12455.       ckstrncpy(vvbuf,ssl_get_subject_name(ssl_con),VVBUFL+1);
  12456.     else if (tls_active_flag)
  12457.       ckstrncpy(vvbuf,ssl_get_subject_name(tls_con),VVBUFL+1);
  12458.     else
  12459.       ckstrncpy(vvbuf,"",VVBUFL+1);
  12460.     return((char *)vvbuf);
  12461.       case VN_X509_I:
  12462.     if (ssl_active_flag)
  12463.       ckstrncpy(vvbuf,ssl_get_issuer_name(ssl_con),VVBUFL+1);
  12464.     else if (tls_active_flag)
  12465.       ckstrncpy(vvbuf,ssl_get_issuer_name(tls_con),VVBUFL+1);
  12466.     else
  12467.       ckstrncpy(vvbuf,"",VVBUFL+1);
  12468.     return((char *)vvbuf);
  12469. #endif /* CK_SSL */
  12470.  
  12471.       case VN_OSNAM:
  12472. #ifdef IKSD
  12473. #ifdef CK_LOGIN
  12474.         if (inserver && isguest)
  12475.           return("");
  12476. #endif /* CK_LOGIN */
  12477. #endif /* IKSD */
  12478. #ifdef CK_UTSNAME
  12479.         {
  12480.             extern char unm_nam[];
  12481.             return((char *)unm_nam);
  12482.         }
  12483. #else
  12484.         for (x = y = 0; x < VVBUFL; x++) {
  12485.             if (ckxsys[x] == SP && cx == 0) continue;
  12486.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  12487.         }
  12488.         vvbuf[y] = NUL;
  12489.         return(vvbuf);
  12490. #endif /* CK_UTSNAME */
  12491.  
  12492.       case VN_OSVER: {
  12493. #ifdef CK_UTSNAME
  12494.           extern char unm_ver[];
  12495. #ifdef IKSD
  12496. #ifdef CK_LOGIN
  12497.           if (inserver && isguest)
  12498.             return("");
  12499. #endif /* CK_LOGIN */
  12500. #endif /* IKSD */
  12501.           return((char *)unm_ver);
  12502. #else
  12503.           return("");
  12504. #endif /* CK_UTSNAME */
  12505.       }
  12506.  
  12507.       case VN_OSREL: {
  12508. #ifdef CK_UTSNAME
  12509.           extern char unm_rel[];
  12510. #ifdef IKSD
  12511. #ifdef CK_LOGIN
  12512.           if (inserver && isguest)
  12513.             return("");
  12514. #endif /* CK_LOGIN */
  12515. #endif /* IKSD */
  12516.           return((char *)unm_rel);
  12517. #else
  12518.           return("");
  12519. #endif /* CK_UTSNAME */
  12520.       }
  12521.     } /* Break up long switch statements... */
  12522.  
  12523.     switch(y) {
  12524.       case VN_NAME: {
  12525.           extern char * myname;
  12526.           return(myname);
  12527.       }
  12528.  
  12529.       case VN_MODL: {
  12530. #ifdef CK_UTSNAME
  12531.           extern char unm_mod[], unm_mch[];
  12532.           int y = VVBUFL - 1;
  12533.           char * s = unm_mod;
  12534. #endif /* CK_UTSNAME */
  12535. #ifdef IKSD
  12536. #ifdef CK_LOGIN
  12537.           if (inserver && isguest)
  12538.             return("");
  12539. #endif /* CK_LOGIN */
  12540. #endif /* IKSD */
  12541.  
  12542. #ifdef COMMENT                          /* was HPUX */
  12543.           if (!unm_mod[0] && !nopush)
  12544.             zzstring("\\fcommand(model)",&s,&y);
  12545. /*
  12546.    Another possibility would be:
  12547.      "\\fcommand(ksh -c 'whence model 1>&- && model || uname -m')"
  12548.    But that would depend on having ksh.
  12549. */
  12550. #else
  12551. #ifdef OSF32                            /* Digital UNIX 3.2 and higher... */
  12552. /* Note: Ultrix has /etc/sizer, but it is not publicly executable. */
  12553. /* sizer -c outputs 'cpu:<tab><tab>"DECxxxx"' */
  12554.           if (!unm_mod[0]) {
  12555.               char * p;
  12556.               int flag = 0;
  12557.               zzstring("\\fcommand(/usr/sbin/sizer -c)",&s,&y);
  12558.               debug(F110,"DU model",unm_mod,0);
  12559.               s = unm_mod;
  12560.               p = unm_mod;
  12561.               while (*p) {              /* Extract the part in quotes */
  12562.                   if (*p == '"') {
  12563.                       if (flag)
  12564.                         break;
  12565.                       flag = 1;
  12566.                       p++;
  12567.                       continue;
  12568.                   }
  12569.                   if (flag)
  12570.                     *s++ = *p;
  12571.                   p++;
  12572.               }
  12573.               *s = NUL;
  12574.           }
  12575. #endif /* OSF32 */
  12576. #endif /* COMMENT */
  12577.  
  12578. #ifdef CK_UTSNAME
  12579.           if (unm_mod[0])
  12580.             return((char *)unm_mod);
  12581.           else
  12582.             return((char *)unm_mch);
  12583. #else
  12584.           return("");
  12585. #endif /* CK_UTSNAME */
  12586.       }
  12587.  
  12588. #ifdef IBMX25
  12589.       /* X.25 variables (local and remote address) */
  12590.       case VN_X25LA:
  12591.         if (!local_nua[0] && !x25local_nua(local_nua))
  12592.           *vvbuf = NULL;
  12593.         else
  12594.           ckstrncpy(vvbuf,local_nua,VVBUFL+1);
  12595.         return((char *)vvbuf);
  12596.  
  12597.       case VN_X25RA:
  12598.         if (!remote_nua[0])
  12599.           *vvbuf = NULL;
  12600.         else
  12601.           ckstrncpy(vvbuf,remote_nua,VVBUFL+1);
  12602.         return((char *)vvbuf);
  12603. #endif /* IBMX25 */
  12604.  
  12605. #ifndef NODIAL
  12606.       case VN_PDSFX: {
  12607.           extern char pdsfx[];
  12608.           return((char *)pdsfx);
  12609.       }
  12610.       case VN_DTYPE: {
  12611.           extern int dialtype;
  12612.           sprintf(vvbuf,"%d",dialtype);    /* SAFE */
  12613.           return((char *)vvbuf);
  12614.       }
  12615. #endif /* NODIAL */
  12616.  
  12617. #ifdef UNIX
  12618.       case VN_LCKPID: {
  12619.           extern char lockpid[];
  12620.           return((char *)lockpid);
  12621.       }
  12622. #endif /* UNIX */
  12623.  
  12624. #ifndef NOXFER
  12625.       case VN_BLK:
  12626.         sprintf(vvbuf,"%d",bctr);    /* SAFE */
  12627.         return((char *)vvbuf);
  12628.  
  12629.       case VN_TFTIM:
  12630.         sprintf(vvbuf,            /* SAFE */
  12631. #ifdef GFTIMER
  12632.                 "%ld", (long)(fptsecs + 0.5)
  12633. #else
  12634.                 "%d", tsecs
  12635. #endif /* GFTIMER */
  12636.                 );
  12637.         return((char *)vvbuf);
  12638. #endif /* NOXFER */
  12639.  
  12640.       case VN_HWPAR:
  12641.       case VN_SERIAL: {
  12642.           int sb;
  12643.           char c, * ss;
  12644.           extern int stopbits;
  12645.           vvbuf[0] = NUL;
  12646.           if (hwparity && local && !network)
  12647.             ss = parnam((char)hwparity);
  12648.           else
  12649.             ss = parnam((char)parity);
  12650.           if (cx == VN_HWPAR) {
  12651.               ckstrncpy(vvbuf,ss,VVBUFL);
  12652.               return((char *)vvbuf);
  12653.           }
  12654.           c = ss[0];
  12655.           if (islower(c)) c = toupper(c);
  12656.           sb = stopbits;
  12657.           if (sb < 1)
  12658.             sb = (speed <= 110L) ? 2 : 1;
  12659.           if (hwparity)
  12660.             sprintf(vvbuf," 8%c%d",c,sb); /* SAFE */
  12661.           else if (parity)
  12662.             sprintf(vvbuf," 7%c%d",c,sb); /* SAFE */
  12663.           else
  12664.             sprintf(vvbuf," 8N%d",sb);    /* SAFE */
  12665.           return((char *)vvbuf);
  12666.       }
  12667.  
  12668. #ifdef UNIX
  12669.       case VN_LCKDIR: {
  12670. #ifndef NOUUCP
  12671.           extern char * uucplockdir;
  12672.           ckstrncpy(vvbuf,uucplockdir,VVBUFL);
  12673.           x = strlen(vvbuf);
  12674.           if (x > 0) {
  12675.               if (vvbuf[x-1] != '/') {
  12676.                   vvbuf[x] = '/';
  12677.                   vvbuf[x+1] = NUL;
  12678.               }
  12679.           }
  12680. #else
  12681.           vvbuf[0] = NUL;
  12682. #endif /* NOUUCP */
  12683.           return((char *)vvbuf);
  12684.       }
  12685. #endif /* UNIX */
  12686.     } /* Break up long switch statements... */
  12687.  
  12688.     switch(y) {
  12689. #ifndef NODIAL
  12690.       case VN_DM_LP:
  12691.       case VN_DM_SP:
  12692.       case VN_DM_PD:
  12693.       case VN_DM_TD:
  12694.       case VN_DM_WA:
  12695.       case VN_DM_WD:
  12696.       case VN_DM_HF:
  12697.       case VN_DM_WB:
  12698.       case VN_DM_RC: {
  12699.           extern char * getdm();
  12700.           ckstrncpy(vvbuf,getdm(y),VVBUFL);
  12701.           return((char *)vvbuf);
  12702.       }
  12703. #endif /* NODIAL */
  12704.  
  12705.       case VN_TY_LN:
  12706.       case VN_TY_LC: {
  12707.           extern int typ_lines;
  12708.           sprintf(vvbuf,"%d",typ_lines); /* SAFE */
  12709.           return((char *)vvbuf);
  12710.       }
  12711.       case VN_TY_LM: {
  12712.           extern int typ_mtchs;
  12713.           sprintf(vvbuf,"%d",typ_mtchs); /* SAFE */
  12714.           return((char *)vvbuf);
  12715.       }
  12716.       case VN_MACLVL:
  12717.         sprintf(vvbuf,"%d",maclvl);    /* SAFE */
  12718.         return((char *)vvbuf);
  12719.     } /* Break up long switch statements... */
  12720.  
  12721.     switch(y) {
  12722. #ifndef NOXFER
  12723.       case VN_XF_BC:
  12724.         sprintf(vvbuf,"%d",crunched);    /* SAFE */
  12725.         return((char *)vvbuf);
  12726.  
  12727.       case VN_XF_TM:
  12728.         sprintf(vvbuf,"%d",timeouts);    /* SAFE */
  12729.         return((char *)vvbuf);
  12730.  
  12731.       case VN_XF_RX:
  12732.         sprintf(vvbuf,"%d",retrans);    /* SAFE */
  12733.         return((char *)vvbuf);
  12734. #endif /* NOXFER */
  12735.  
  12736.       case VN_MS_CD:                    /* Modem signals */
  12737.       case VN_MS_CTS:
  12738.       case VN_MS_DSR:
  12739.       case VN_MS_DTR:
  12740.       case VN_MS_RI:
  12741.       case VN_MS_RTS: {
  12742.           int x, z = -1;
  12743.           x = ttgmdm();                 /* Try to get them */
  12744.           if (x > -1) {
  12745.               switch (y) {
  12746.                 case VN_MS_CD:  z = (x & BM_DCD) ? 1 : 0; break;
  12747.                 case VN_MS_DSR: z = (x & BM_DSR) ? 1 : 0; break;
  12748.                 case VN_MS_CTS: z = (x & BM_CTS) ? 1 : 0; break;
  12749. #ifdef MAC
  12750.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  12751. #else
  12752. #ifndef STRATUS
  12753.                 case VN_MS_RI:  z = (x & BM_RNG) ? 1 : 0; break;
  12754. #ifndef NT
  12755.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  12756.                 case VN_MS_RTS: z = (x & BM_RTS) ? 1 : 0; break;
  12757. #endif /* NT */
  12758. #endif /* STRATUS */
  12759. #endif /* MAC */
  12760.               }
  12761.           }
  12762.           sprintf(vvbuf,"%d",z);    /* SAFE */
  12763.           return((char *)vvbuf);
  12764.       }
  12765.       case VN_MATCH:                    /* INPUT MATCH */
  12766.         return(inpmatch ? inpmatch : "");
  12767.  
  12768.       case VN_SLMSG: {                  /* SET LINE / HOST message */
  12769.           extern char * slmsg;
  12770.           vvbuf[0] = NUL;
  12771.           if (slmsg)
  12772.             ckstrncpy(vvbuf,slmsg,VVBUFL);
  12773.          return(vvbuf);
  12774.       }
  12775.  
  12776.       case VN_TXTDIR:                   /* TEXTDIR */
  12777.         return(k_info_dir ? k_info_dir : "");
  12778.  
  12779. #ifdef FNFLOAT
  12780.       case VN_MA_PI:
  12781.         return(math_pi);
  12782.  
  12783.       case VN_MA_E:
  12784.         return(math_e);
  12785.  
  12786.       case VN_MA_PR:
  12787.         sprintf(vvbuf,"%d",fp_digits);    /* SAFE */
  12788.         return(vvbuf);
  12789. #endif /* FNFLOAT */
  12790.  
  12791.       case VN_CMDBL:
  12792.         sprintf(vvbuf,"%d",CMDBL);    /* SAFE */
  12793.         return(vvbuf);
  12794.  
  12795. #ifdef CKCHANNELIO
  12796.       case VN_FERR: {
  12797.           extern int z_error;
  12798.           sprintf(vvbuf,"%d",z_error);    /* SAFE */
  12799.           return(vvbuf);
  12800.       }
  12801.       case VN_FMAX: {
  12802.           extern int z_maxchan;
  12803.           sprintf(vvbuf,"%d",z_maxchan); /* SAFE */
  12804.           return(vvbuf);
  12805.       }
  12806.       case VN_FCOU: {
  12807.           extern int z_filcount;
  12808.           sprintf(vvbuf,"%d",z_filcount); /* SAFE */
  12809.           return(vvbuf);
  12810.       }
  12811. #endif /* CKCHANNELIO */
  12812.  
  12813. #ifndef NODIAL
  12814.       case VN_DRTR: {
  12815.           extern int dialcount;
  12816.           sprintf(vvbuf,"%d",dialcount); /* SAFE */
  12817.           return(vvbuf);
  12818.       }
  12819. #endif /* NODIAL */
  12820.  
  12821. #ifndef NOLOGDIAL
  12822. #ifndef NOLOCAL
  12823.       case VN_CXTIME:
  12824.         sprintf(vvbuf,"%ld",dologshow(0)); /* SAFE */
  12825.         return(vvbuf);
  12826. #endif /* NOLOCAL */
  12827. #endif /* NOLOGDIAL */
  12828.  
  12829.       case VN_BYTE:
  12830.         sprintf(vvbuf,"%d",byteorder);    /* SAFE */
  12831.         return(vvbuf);
  12832.  
  12833.       case VN_KBCHAR:
  12834.         vvbuf[0] = NUL;
  12835.         vvbuf[1] = NUL;
  12836.         if (kbchar > 0)
  12837.           vvbuf[0] = (kbchar & 0xff);
  12838.         return(vvbuf);
  12839.  
  12840.       case VN_TTYNAM: {
  12841. #ifdef HAVECTTNAM
  12842.           extern char cttnam[];
  12843.           return((char *)cttnam);
  12844. #else
  12845.           return(CTTNAM);
  12846. #endif /* HAVECTTNAM */
  12847.       }
  12848.  
  12849.       case VN_PROMPT:
  12850.     return(cmgetp());
  12851.  
  12852.       case VN_BUILD: {
  12853.       extern char * buildid;
  12854.       return(buildid);
  12855.       }
  12856.  
  12857. #ifndef NOSEXP
  12858.       case VN_SEXP: {
  12859.       extern char * lastsexp;
  12860.       return(lastsexp);
  12861.       }
  12862.       case VN_VSEXP: {
  12863.       extern char * sexpval;
  12864.       return(sexpval);
  12865.       }
  12866.       case VN_LSEXP: {
  12867.       extern int sexpdep;
  12868.       ckstrncpy(vvbuf,ckitoa(sexpdep),VVBUFL);
  12869.       return(vvbuf);
  12870.       }
  12871. #endif /* NOSEXP */
  12872.  
  12873. #ifdef GFTIMER
  12874.       case VN_FTIME: {
  12875.       CKFLOAT f;
  12876.       ztime(&p);
  12877.       if (p == NULL || *p == NUL)
  12878.         return(NULL);
  12879.       z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  12880.       f = (CKFLOAT)z + ((CKFLOAT)ztusec) / 1000000.0;
  12881.       sprintf(vvbuf,"%f",f);    /* SAFE */
  12882.       return(vvbuf);
  12883.       }
  12884. #endif /* GFTIMER */
  12885.  
  12886. #ifndef NOHTTP
  12887.       case VN_HTTP_C: {            /* HTTP Code */
  12888.       extern int http_code;
  12889.       return(ckitoa(http_code));
  12890.       }
  12891.       case VN_HTTP_N:            /* HTTP Connected */
  12892.     return( http_isconnected() ? "1" : "0");
  12893.       case VN_HTTP_H:            /* HTTP Host */
  12894.     return( (char *)http_host() );
  12895.       case VN_HTTP_M: {            /* HTTP Message */
  12896.       extern char http_reply_str[];
  12897.       return((char *)http_reply_str);
  12898.       }
  12899.       case VN_HTTP_S:            /* HTTP Security */
  12900.         return((char *)http_security());
  12901. #endif /* NOHTTP */
  12902.  
  12903. #ifdef NEWFTP
  12904.       case VN_FTP_B:
  12905.     return((char *)ftp_cpl_mode());
  12906.       case VN_FTP_D:
  12907.     return((char *)ftp_dpl_mode());
  12908.       case VN_FTP_Z:
  12909.     return((char *)ftp_authtype());
  12910.       case VN_FTP_C: {
  12911.       extern int ftpcode;
  12912.       return(ckitoa(ftpcode));
  12913.       }
  12914.       case VN_FTP_M: {
  12915.       extern char ftp_reply_str[];
  12916.       if (isdigit(ftp_reply_str[0]) &&
  12917.           isdigit(ftp_reply_str[1]) &&
  12918.           isdigit(ftp_reply_str[2]) &&
  12919.           ftp_reply_str[3] == ' ')
  12920.         return(&ftp_reply_str[4]);
  12921.       else
  12922.         return(ftp_reply_str);
  12923.       }
  12924.       case VN_FTP_S: {
  12925.       extern char ftp_srvtyp[];
  12926.       return((char *)ftp_srvtyp);
  12927.       }
  12928.       case VN_FTP_H: {
  12929.       extern char * ftp_host;
  12930.       return(ftp_host ? ftp_host : "");
  12931.       }
  12932.       case VN_FTP_X: {            /* FTP Connected */
  12933.       extern int ftpisconnected();
  12934.       return(ftpisconnected() ? "1" : "0");
  12935.       }
  12936.       case VN_FTP_L: {            /* FTP Logged in */
  12937.       extern int ftpisloggedin();
  12938.       return(ftpisloggedin() ? "1" : "0");
  12939.       }
  12940.       case VN_FTP_G: {            /* FTP GET-PUT-REMOTE */
  12941.       extern int ftpget;
  12942.       char * s = "";
  12943.       switch (ftpget) {
  12944.         case 0: s = "kermit"; break;
  12945.         case 1: s = "ftp"; break;
  12946.         case 2: s = "auto"; break;
  12947.       }
  12948.       return(s);
  12949.       }
  12950. #endif /* NEWFTP */
  12951.  
  12952. #ifndef NOLOCAL
  12953.       case VN_CX_STA: {            /* CONNECT status */
  12954.       extern int cx_status;
  12955.       return(ckitoa(cx_status));
  12956.       }
  12957. #endif /* NOLOCAL */
  12958.       case VN_NOW:            /* Timestamp */
  12959.         return(ckcvtdate(p,0));
  12960.  
  12961.       case VN_HOUR:            /* Hour of the day */
  12962.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  12963.     if (!p) p = "";
  12964.     if (!*p) return(p);
  12965.     vvbuf[0] = p[11];
  12966.     vvbuf[1] = p[12];
  12967.     vvbuf[2] = NUL;
  12968.         return(vvbuf);                  /* and return it */
  12969.     
  12970.     } /* End of variable-name switches */
  12971.  
  12972.     fnsuccess = 0;
  12973.     if (fnerror) {
  12974.         fnsuccess = 0;
  12975.     }
  12976.     if (fndiags) {
  12977.         if (!embuf)
  12978.       ckstrncpy(embuf,"<ERROR:NO_SUCH_VARIABLE>",EMBUFLEN);
  12979.         printf("?%s\n",embuf);
  12980.         return((char *)embuf);
  12981.     } else
  12982.       return("");
  12983. }
  12984. #endif /* NOSPL */
  12985.  
  12986.  
  12987. /*
  12988.   X X S T R I N G  --  Expand variables and backslash codes.
  12989.  
  12990.     int xxtstring(s,&s2,&n);
  12991.  
  12992.   Expands \ escapes via recursive descent.
  12993.   Argument s is a pointer to string to expand (source).
  12994.   Argument s2 is the address of where to put result (destination).
  12995.   Argument n is the length of the destination string (to prevent overruns).
  12996.   Returns -1 on failure, 0 on success,
  12997.     with destination string null-terminated and s2 pointing to the
  12998.     terminating null, so that subsequent characters can be added.
  12999. */
  13000.  
  13001. #define XXDEPLIM 100                    /* Recursion depth limit */
  13002.  
  13003. int
  13004. zzstring(s,s2,n) char *s; char **s2; int *n; {
  13005.     int x,                              /* Current character */
  13006.         y,                              /* Worker */
  13007.         pp,                             /* Paren level */
  13008.         kp,                             /* Brace level */
  13009.         argn,                           /* Function argument counter */
  13010.         n2,                             /* Local copy of n */
  13011.         d,                              /* Array dimension */
  13012.         vbi,                            /* Variable id (integer form) */
  13013.         argl,                           /* String argument length */
  13014.         nx;                             /* Save original length */
  13015.  
  13016.     char vb,                            /* Variable id (char form) */
  13017.         *vp,                            /* Pointer to variable definition */
  13018.         *new,                           /* Local pointer to target string */
  13019. #ifdef COMMENT
  13020.         *old,                           /* Save original target pointer */
  13021. #endif /* COMMENT */
  13022.         *p,                             /* Worker */
  13023.         *q,                             /* Worker */
  13024.         *s3;                /* Worker */
  13025.     int  x3;                /* Worker */
  13026.     char *r  = (char *)0;               /* For holding function args */
  13027.     char *r2 = (char *)0;
  13028.     char *r3p;
  13029.  
  13030. #ifndef NOSPL
  13031. #ifdef DYNAMIC
  13032.     char * vnambuf = NULL;        /* Buffer for variable/function name */
  13033. #else /* DYNAMIC */
  13034.     char vnambuf[VNAML];                /* Buffer for variable/function name */
  13035. #endif /* DYNAMIC */
  13036.     char *argp[FNARGS];                 /* Pointers to function args */
  13037. #endif /* NOSPL */
  13038.  
  13039.     static int depth = 0;               /* Call depth, avoid overflow */
  13040.  
  13041.     n2 = *n;                            /* Make local copies of args */
  13042.     nx = n2;
  13043.  
  13044.     new = *s2;                          /* for one less level of indirection */
  13045. #ifdef COMMENT
  13046.     old = new;
  13047. #endif /* COMMENT */
  13048.  
  13049. #ifndef NOSPL
  13050.     ispattern = 0;                      /* For \fpattern() */
  13051. #endif /* NOSPL */
  13052.     depth++;                            /* Sink to a new depth */
  13053.     if (depth > XXDEPLIM) {             /* Too deep? */
  13054.         printf("?definition is circular or too deep\n");
  13055.         debug(F101,"zzstring fail","",depth);
  13056.         depth = 0;
  13057.         *new = NUL;
  13058.         return(-1);
  13059.     }
  13060.     if (!s || !new) {                   /* Watch out for null pointers */
  13061.         debug(F101,"zzstring fail 2","",depth);
  13062.     if (new)
  13063.       *new = NUL;
  13064.         depth = 0;
  13065.         return(-1);
  13066.     }
  13067.     s3 = s;
  13068.     argl = 0;
  13069.     while (*s3++) argl++;              /* Get length of source string */
  13070.     debug(F010,"zzstring entry",s,0);
  13071.     if (argl == 0) {                    /* Empty string */
  13072.         debug(F111,"zzstring empty arg",s,argl);
  13073.         depth = 0;
  13074.         *new = NUL;
  13075.         return(0);
  13076.     }
  13077.     if (argl < 0) {                     /* Watch out for garbage */
  13078.         debug(F101,"zzstring fail 3","",depth);
  13079.         *new = NUL;
  13080.         depth = 0;
  13081.         return(-1);
  13082.     }
  13083. #ifndef NOSPL
  13084. #ifdef DYNAMIC
  13085.     debug(F100,"vnambuf malloc...","",0);
  13086.     vnambuf = malloc(VNAML);
  13087.     if (vnambuf == NULL) {
  13088.         printf("?Out of memory");
  13089.         return(-1);
  13090.     }
  13091.     debug(F100,"vnambuf malloc ok","",0);
  13092. #endif /* DYNAMIC */
  13093. #endif /* NOSPL */
  13094.  
  13095.     while ((x = *s)) {            /* Loop for all characters */
  13096.         if (x != CMDQ) {                /* Is it the command-quote char? */
  13097.             *new++ = *s++;              /* No, normal char, just copy */
  13098.             if (--n2 < 0) {             /* and count it, careful of overflow */
  13099.                 debug(F101,"zzstring overflow 1","",depth);
  13100.                 depth = 0;
  13101. #ifndef NOSPL
  13102. #ifdef DYNAMIC
  13103.                 if (vnambuf) free(vnambuf);
  13104. #endif /* DYNAMIC */
  13105. #endif /* NOSPL */
  13106.         return(-1);
  13107.             }
  13108.             continue;
  13109.         }
  13110.  
  13111. /* We have the command-quote character. */
  13112.  
  13113.         x = *(s+1);                     /* Get the following character. */
  13114.         if (isupper(x)) x = tolower(x);
  13115.         switch (x) {                    /* Act according to variable type */
  13116. #ifndef NOSPL
  13117.           case 0:                       /* It's a lone backslash */
  13118.             *new++ = *s++;
  13119.             if (--n2 < 0) {
  13120.                 debug(F101,"zzstring overflow 2","",0);
  13121. #ifdef DYNAMIC
  13122. #ifndef NOSPL
  13123.                 if (vnambuf) free(vnambuf);
  13124. #endif /* NOSPL */
  13125. #endif /* DYNAMIC */
  13126.                 return(-1);
  13127.             }
  13128.             break;
  13129.           case '%':                     /* Variable */
  13130.             s += 2;                     /* Get the letter or digit */
  13131.             vb = *s++;                  /* and move source pointer past it */
  13132.             vp = NULL;                  /* Assume definition is empty */
  13133.             if (vb >= '0' && vb <= '9') { /* Digit for macro arg */
  13134.                 if (maclvl < 0)         /* Digit variables are global */
  13135.                   vp = g_var[vb];       /* if no macro is active */
  13136.                 else                    /* otherwise */
  13137.                   vp = m_arg[maclvl][vb - '0']; /* they're on the stack */
  13138.             } else if (vb == '*') {    /* Macro args string */
  13139. #ifdef COMMENT
  13140.         /* This doesn't take changes into account */
  13141.         vp = (maclvl >= 0) ? m_line[maclvl] : topline;
  13142.                 if (!vp) vp = "";
  13143. #else
  13144.         if (zzstring("\\fjoin(&_[],,1)",&new,&n2) < 0)
  13145.           return(-1);
  13146.         break;
  13147. #endif /* COMMENT */
  13148.             } else {
  13149.                 if (isupper(vb)) vb += ('a'-'A');
  13150.                 vp = g_var[vb];         /* Letter for global variable */
  13151.             }
  13152.             if (!vp) vp = "";
  13153. #ifdef COMMENT
  13154.             if (vp) {                   /* If definition not empty */
  13155. #endif /* COMMENT */
  13156.                 debug(F010,"zzstring %n vp",vp,0);
  13157.                 if (zzstring(vp,&new,&n2) < 0) { /* call self to evaluate it */
  13158.                     debug(F101,"zzstring fail 6","",depth);
  13159. #ifdef DYNAMIC
  13160. #ifndef NOSPL
  13161.             if (vnambuf) free(vnambuf);
  13162. #endif /* NOSPL */
  13163. #endif /* DYNAMIC */
  13164.                     return(-1);         /* Pass along failure */
  13165.                 }
  13166. #ifdef COMMENT
  13167.             } else {
  13168.                 debug(F110,"zzstring %n vp","(NULL)",0);
  13169.                 n2 = nx;
  13170.                 new = old;
  13171.                 *new = NUL;
  13172.             }
  13173. #endif /* COMMENT */
  13174.             break;
  13175.           case '&':                     /* An array reference */
  13176.             x = arraynam(s,&vbi,&d);    /* Get name and subscript */
  13177.             debug(F111,"zzstring arraynam",s,x);
  13178.             if (x < 0) {
  13179.                 debug(F101,"zzstring fail 7","",depth);
  13180. #ifdef DYNAMIC
  13181. #ifndef NOSPL
  13182.                 if (vnambuf) free(vnambuf);
  13183. #endif /* NOSPL */
  13184. #endif /* DYNAMIC */
  13185.                 return(-1);
  13186.             }
  13187.             pp = 0;                     /* Bracket counter */
  13188.             while (*s) {                /* Advance source pointer... */
  13189.                 if (*s == '[') pp++;
  13190.                 if (*s == ']' && --pp == 0) break;
  13191.                 s++;
  13192.             }
  13193.             if (*s == ']') s++;         /* ...past the closing bracket. */
  13194.  
  13195.             x = chkarray(vbi,d);        /* Array is declared? */
  13196.             debug(F101,"zzstring chkarray","",x);
  13197.             if (x > 0) {
  13198. #ifdef COMMENT
  13199.                 char * s1 = NULL;
  13200. #endif /* COMMENT */
  13201.                 vbi -= ARRAYBASE;       /* Convert name to index */
  13202.  
  13203. #ifdef COMMENT
  13204.                 if (vbi == 0) {         /* Argument vector array */
  13205.                     extern char ** toparg, ** m_xarg[];
  13206.                     extern int n_xarg[];
  13207.                     if (maclvl < 0) {
  13208.                         if (topargc >= d) {
  13209.                             s1 = toparg[d];
  13210.                         }
  13211.                     } else {
  13212.                         if (n_xarg[maclvl] >= d) {
  13213.                             s1 = m_xarg[maclvl][d];
  13214.                         }
  13215.                     }
  13216.                     if (s1) {
  13217.                         if (zzstring(s1,&new,&n2) < 0) { /* evaluate */
  13218.                             debug(F101,"zzstring fail 7.5","",depth);
  13219. #ifdef DYNAMIC
  13220. #ifndef NOSPL
  13221.                 if (vnambuf) free(vnambuf);
  13222. #endif /* NOSPL */
  13223. #endif /* DYNAMIC */
  13224.                             return(-1); /* Pass along failure */
  13225.                         }
  13226.                     } else {
  13227.                         /* old = new; */
  13228.                         n2 = nx;
  13229.                     }
  13230.                 } else
  13231. #endif /* COMMENT */
  13232.                   if (a_dim[vbi] >= d) {        /* If subscript in range */
  13233.                     char **ap;
  13234. #ifndef COMMENT
  13235.                     debug(F110,"zzstring a_ptr[vbi]",a_ptr[vbi],0);
  13236.                     debug(F110,"zzstring a_ptr[vbi][d]",a_ptr[vbi][d],0);
  13237. #endif /* COMMENT */
  13238.                     ap = a_ptr[vbi];    /* get data pointer */
  13239.                     if (ap) {           /* and if there is one */
  13240.                         if (ap[d]) {    /* If definition not empty */
  13241.                             debug(F111,"zzstring ap[d]",ap[d],d);
  13242.                             if (zzstring(ap[d],&new,&n2) < 0) { /* evaluate */
  13243.                                 debug(F101,"zzstring fail 8","",depth);
  13244. #ifdef DYNAMIC
  13245. #ifndef NOSPL
  13246.                 if (vnambuf) free(vnambuf);
  13247. #endif /* NOSPL */
  13248. #endif /* DYNAMIC */
  13249.                                 return(-1); /* Pass along failure */
  13250.                             }
  13251.                         }
  13252.                     } else {
  13253.                         /* old = new; */
  13254.                         n2 = nx;
  13255.                     }
  13256.                 }
  13257.             }
  13258.             break;
  13259.  
  13260.           case 'f':                     /* A builtin function */
  13261.             q = vnambuf;                /* Copy the name */
  13262.             y = 0;                      /* into a separate buffer */
  13263.             s += 2;                     /* point past 'F' */
  13264.             while (y++ < VNAML) {
  13265.                 if (*s == '(') { s++; break; } /* Look for open paren */
  13266.                 if ((*q = *s) == NUL) break;   /* or end of string */
  13267.                 s++; q++;
  13268.             }
  13269.             *q = NUL;                   /* Terminate function name */
  13270.             if (y >= VNAML) {           /* Handle pathological case */
  13271.                 while (*s && (*s != '(')) /* of very long string entered */
  13272.                   s++;                    /* as function name. */
  13273.                 if (*s == ')') s++;       /* Skip past it. */
  13274.             }
  13275.             r = r2 = malloc(argl+2);    /* And make a place to copy args */
  13276.             /* debug(F101,"zzstring r2","",r2); */
  13277.             if (!r2) {                  /* Watch out for malloc failure */
  13278.                 debug(F101,"zzstring fail 9","",depth);
  13279.                 *new = NUL;
  13280.                 depth = 0;
  13281. #ifdef DYNAMIC
  13282. #ifndef NOSPL
  13283.                 if (vnambuf) free(vnambuf);
  13284. #endif /* NOSPL */
  13285. #endif /* DYNAMIC */
  13286.                 return(-1);
  13287.             }
  13288.             if (r3) free(r3); /* And another to copy literal arg string */
  13289.             r3 = malloc(argl+2);
  13290.             /* debug(F101,"zzstring r3","",r3); */
  13291.             if (!r3) {
  13292.                 debug(F101,"zzstring fail 10","",depth);
  13293.                 depth = 0;
  13294.                 *new = NUL;
  13295.                 if (r2) free(r2);
  13296. #ifdef DYNAMIC
  13297. #ifndef NOSPL
  13298.                 if (vnambuf) free(vnambuf);
  13299. #endif /* NOSPL */
  13300. #endif /* DYNAMIC */
  13301.                 return(-1);
  13302.             } else
  13303.               r3p = r3;
  13304.             argn = 0;                   /* Argument counter */
  13305.             argp[argn++] = r;           /* Point to first argument */
  13306.             y = 0;                      /* Completion flag */
  13307.             pp = 1;                     /* Paren level (already have one). */
  13308.             kp = 0;
  13309.             while (1) {                 /* Copy each argument, char by char. */
  13310.                 *r3p++ = *s;            /* This is a literal copy for \flit */
  13311.                 if (!*s) break;
  13312.  
  13313.                 if (*s == '{') {        /* Left brace */
  13314.                     kp++;
  13315.                 }
  13316.                 if (*s == '}') {        /* Right brace */
  13317.                     kp--;
  13318.                 }
  13319.                 if (*s == '(' && kp <= 0) { /* Open paren not in brace */
  13320.                     pp++;               /* Count it */
  13321.                 }
  13322.                 *r = *s;                /* Now copy resulting byte */
  13323.                 if (!*r)                /* If NUL, done. */
  13324.                   break;
  13325.                 if (*r == ')' && kp <= 0) { /* Closing paren, count it. */
  13326.                     if (--pp == 0) {    /* Final one? */
  13327.                         *r = NUL;       /* Make it a terminating null */
  13328.                         *(r3p - 1) = NUL;
  13329.                         s++;            /* Point past it in source string */
  13330.                         y = 1;          /* Flag we've got all the args */
  13331.                         break;          /* Done with while loop */
  13332.                     }
  13333.                 }
  13334.                 if (*r == ',' && kp <= 0) { /* Comma */
  13335.                     if (pp == 1) {          /* If not within ()'s, */
  13336.                         if (argn >= FNARGS) { /* Too many args */
  13337.                             s++; r++;   /* Keep collecting flit() string */
  13338.                             continue;
  13339.                         }
  13340.                         *r = NUL;           /* New arg, skip past comma */
  13341.                         argp[argn++] = r+1; /* In range, point to new arg */
  13342.                     }                   /* Otherwise just skip past  */
  13343.                 }
  13344.                 s++; r++;               /* Advance pointers */
  13345.             }
  13346.             if (!y)            /* If we didn't find closing paren */
  13347.           argn = -1;
  13348. #ifdef DEBUG
  13349.             if (deblog) {
  13350.         char buf[24];
  13351.         debug(F111,"zzstring function name",vnambuf,y);
  13352.         debug(F010,"zzstring function r3",r3,0);
  13353.         for (y = 0; y < argn; y++) {
  13354.             sprintf(buf,"arg %2d ",y);
  13355.             debug(F010,buf,argp[y],0);
  13356.         }
  13357.         }
  13358. #endif /* DEBUG */
  13359.             vp = fneval(vnambuf,argp,argn,r3); /* Evaluate the function. */
  13360.             if (vp) {                      /* If definition not empty */
  13361.                 while ((*new++ = *vp++)) { /* copy it to output string */
  13362.             if (--n2 < 0) {        /* watch out for overflow */
  13363.             debug(F101,"zzstring fail 12","",depth);
  13364.             if (r2) { free(r2); r2 = NULL; }
  13365.             if (r3) { free(r3); r3 = NULL; }
  13366. #ifdef DYNAMIC
  13367. #ifndef NOSPL
  13368.             if (vnambuf) free(vnambuf);
  13369. #endif /* NOSPL */
  13370. #endif /* DYNAMIC */
  13371.             return(-1);
  13372.             }
  13373.         }
  13374.                 new--;                  /* Back up over terminating null */
  13375.                 n2++;                   /* to allow for further deposits. */
  13376.             }
  13377.             if (r2) { free(r2); r2 = NULL; }
  13378.             if (r3) { free(r3); r3 = NULL; }
  13379.             break;
  13380.           case '$':                     /* An environment variable */
  13381.           case 'v':                     /* Or a named builtin variable. */
  13382.           case 'm':                     /* Or a macro /long variable */
  13383.           case 's':                     /* 196 Macro substring */
  13384.           case ':':                     /* 196 \-variable substring */
  13385.             pp = 0;
  13386.             p = s+2;                    /* $/V/M must be followed by (name) */
  13387.             if (*p != '(') {            /* as in \$(HOME) or \V(count) */
  13388.                 *new++ = *s++;          /* If not, just copy it */
  13389.                 if (--n2 < 0) {
  13390.                     debug(F101,"zzstring overflow 3","",depth);
  13391. #ifdef DYNAMIC
  13392. #ifndef NOSPL
  13393.             if (vnambuf) free(vnambuf);
  13394. #endif /* NOSPL */
  13395. #endif /* DYNAMIC */
  13396.                     return(-1);
  13397.                 }
  13398.                 break;
  13399.             }
  13400.             pp++;
  13401.             p++;                        /* Point to 1st char of name */
  13402.             q = vnambuf;                /* Copy the name */
  13403.             y = 0;                      /* into a separate buffer */
  13404.             while (y++ < VNAML) {       /* Watch out for name too long */
  13405.                 if (*p == '(') {        /* Parens can be nested... */
  13406.                     pp++;
  13407.                 } else if (*p == ')') { /* Name properly terminated with ')' */
  13408.                     pp--;
  13409.                     if (pp == 0) {
  13410.                         p++;            /* Move source pointer past ')' */
  13411.                         break;
  13412.                     }
  13413.                 }
  13414.                 if ((*q = *p) == NUL)   /* String ends before ')' */
  13415.                   break;
  13416.                 p++; q++;               /* Advance pointers */
  13417.             }
  13418.             *q = NUL;                   /* Terminate the variable name */
  13419.             if (y >= VNAML) {           /* Handle pathological case */
  13420.                 while (*p && (*p != ')')) /* of very long string entered */
  13421.                   p++;                    /* as variable name. */
  13422.                 if (*p == ')') p++;       /* Skip ahead to the end of it. */
  13423.             }
  13424.             s = p;                      /* Adjust global source pointer */
  13425.         s3 = vnambuf;
  13426.         x3 = 0;
  13427.         while (*s3++) x3++;
  13428.             p = malloc(x3 + 1);        /* Make temporary space */
  13429.             if (p) {                    /* If we got the space */
  13430.                 vp = vnambuf;           /* Point to original */
  13431.                 strcpy(p,vp);           /* (safe) Make a copy of it */
  13432.                 y = VNAML;              /* Length of name buffer */
  13433.                 zzstring(p,&vp,&y);     /* Evaluate the copy */
  13434.                 free(p);                /* Free the temporary space */
  13435.                 p = NULL;
  13436.             }
  13437.             debug(F110,"zzstring vname",vnambuf,0);
  13438.             q = NULL;
  13439.             if (x == '$') {             /* Look up its value */
  13440.                 vp = getenv(vnambuf);   /* This way for environment variable */
  13441.             } else if (x == 'm' || x == 's' || x == ':') { /* Macro / substr */
  13442.                 int k, x1 = -1, x2 = -1;
  13443.                 k = strlen(vnambuf);
  13444.                 /* \s(name[n:m]) -- Compact substring notation */
  13445.                 if ((x == 's' || x == ':') && (k > 1)) { /* Substring wanted */
  13446.                     if (vnambuf[k-1] == ']') {
  13447.                         int i;
  13448.                         for (i = k-1; i > 0; i--) {
  13449.                             if (vnambuf[i] == '[') {
  13450.                                 char * p = NULL;
  13451.                                 p = (char *)malloc(k - i + 8);
  13452.                                 if (p) {
  13453.                                     /* Now this is a dirty trick... */
  13454.                     ckmakmsg(p,
  13455.                          k-i+8,
  13456.                          "\\&a",
  13457.                          &vnambuf[i],
  13458.                          NULL,
  13459.                          NULL
  13460.                          );
  13461.                                     arraybounds(p,&x1,&x2);
  13462.                                     if (x1 < 1) x1 = 1;
  13463.                                     x1--; /* Adjust to 0-base */
  13464.                                     free(p);
  13465.                                     vnambuf[i] = NUL;
  13466.                                 }
  13467.                             }
  13468.                         }
  13469.                     }
  13470.                 }
  13471.                 if (x == ':') {
  13472.                     vp = vnambuf;
  13473.                 } else {
  13474.                     y = mxlook(mactab,vnambuf,nmac); /* get definition */
  13475.                     if (y > -1) {               /* Got definition */
  13476.                         vp = mactab[y].mval;
  13477.                     } else {
  13478.                         vp = NULL;
  13479.                     }
  13480.                 }
  13481.                 if (vp) {
  13482.                     if ((x == 's' || x == ':') && (k > 1)) {
  13483.                         /* Compact substring notation */
  13484.                         if (x2 == 0) {  /* Length */
  13485.                             vp = NULL;
  13486.                         } else if (x1 > -1) { /* Start */
  13487.                             k = strlen(vp);
  13488.                             if (x1 > k) {  /* If it's off the end, */
  13489.                                 vp = NULL; /* result is empty */
  13490.                             } else if (k > 0) {
  13491.                                 if ((q = malloc(k+1))) {
  13492.                                     strcpy(q,vp); /* safe */
  13493.                                     if ((x2 > -1) && ((x1 + x2) <= k)) {
  13494.                                         q[x1+x2] = NUL;
  13495.                                     }
  13496.                                     vp = q+x1;
  13497.                                 }  else vp = NULL;
  13498.                             } else vp = NULL;
  13499.                         }
  13500. #ifdef DEBUG
  13501.                         if (deblog) {
  13502.                             if (!vp) {
  13503.                             } else {
  13504.                                 k = strlen(vp);
  13505.                             }
  13506.                         }
  13507. #endif /* DEBUG */
  13508.                     }
  13509.                 }
  13510.             } else {                    /* or */
  13511.                 vp = nvlook(vnambuf);   /* this way for builtin variable */
  13512.             }
  13513.             if (vp) {                   /* If definition not empty */
  13514.                 while ((*new++ = *vp++)) /* copy it to output string. */
  13515.                   if (--n2 < 0) {
  13516.                       if (q) free(q);
  13517.                       debug(F101,"zzstring overflow 4","",depth);
  13518. #ifdef DYNAMIC
  13519. #ifndef NOSPL
  13520.               if (vnambuf) free(vnambuf);
  13521. #endif /* NOSPL */
  13522. #endif /* DYNAMIC */
  13523.                       return(-1);
  13524.                   }
  13525.                 new--;                  /* Back up over terminating null */
  13526.                 n2++;                   /* to allow for further deposits. */
  13527.             }
  13528.             if (q) {
  13529.                 free(q);
  13530.                 q = NULL;
  13531.             }
  13532.             break;
  13533. #endif /* NOSPL */                      /* Handle \nnn even if NOSPL. */
  13534.  
  13535. #ifndef NOKVERBS
  13536.         case 'K':
  13537.         case 'k': {
  13538.             extern struct keytab kverbs[];
  13539.             extern int nkverbs;
  13540. #define K_BUFLEN 30
  13541.             char kbuf[K_BUFLEN + 1];    /* Key verb name buffer */
  13542.             int x, y, z, brace = 0;
  13543.             s += 2;
  13544. /*
  13545.   We assume that the verb name is {braced}, or it extends to the end of the
  13546.   string, s, or it ends with a space, control character, or backslash.
  13547. */
  13548.             p = kbuf;                   /* Copy verb name into local buffer */
  13549.             x = 0;
  13550.             if (*s == '{')  {
  13551.                 s++;
  13552.                 brace++;
  13553.             }
  13554.             while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  13555.                 if (brace && *s == '}') {
  13556.                     s++;
  13557.                     break;
  13558.                 }
  13559.                 *p++ = *s++;
  13560.             }
  13561.             brace = 0;
  13562.             *p = NUL;                   /* Terminate. */
  13563.             p = kbuf;                   /* Point back to beginning */
  13564.             debug(F110,"zzstring kverb",p,0);
  13565.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  13566.             debug(F101,"zzstring lookup",0,y);
  13567.             if (y > -1) {
  13568.                 dokverb(VCMD,y);
  13569. #ifndef NOSPL
  13570.             } else {                    /* Is it a macro? */
  13571.                 y = mxlook(mactab,p,nmac);
  13572.                 if (y > -1) {
  13573.                     debug(F111,"zzstring mxlook",p,y);
  13574.                     if ((z = dodo(y,NULL,cmdstk[cmdlvl].ccflgs)) > 0) {
  13575.                         if (cmpush() > -1) {  /* Push command parser state */
  13576.                             extern int ifc;
  13577.                             int ifcsav = ifc; /* Push IF condition on stack */
  13578.                             y = parser(1);    /* New parser to execute macro */
  13579.                             cmpop();          /* Pop command parser */
  13580.                             ifc = ifcsav;     /* Restore IF condition */
  13581.                             if (y == 0) {     /* No errors, ignore actions */
  13582.                                 p = mrval[maclvl+1]; /* If OK set return val */
  13583.                                 if (p == NULL) p = "";
  13584.                             }
  13585.                         } else {                /* Can't push any more */
  13586.                             debug(F101,"zzstring pushed too deep","",depth);
  13587.                             printf(
  13588.                                "\n?Internal error: zzstring stack overflow\n"
  13589.                                    );
  13590.                             while (cmpop() > -1);
  13591.                             p = "";
  13592.                         }
  13593.                     }
  13594.                 }
  13595. #endif /* NOSPL */
  13596.             }
  13597.             break;
  13598.         }
  13599. #endif /* NOKVERBS */
  13600.  
  13601.         default:                        /* Maybe it's a backslash code */
  13602.           y = xxesc(&s);                /* Go interpret it */
  13603.           if (y < 0) {                  /* Upon failure */
  13604.               *new++ = (char) x;        /* Just quote the next character */
  13605.               s += 2;                   /* Move past the pair */
  13606.               n2 -= 2;
  13607.               if (n2 < 0) {
  13608.                   debug(F101,"zzstring overflow 5","",depth);
  13609. #ifdef DYNAMIC
  13610. #ifndef NOSPL
  13611.           if (vnambuf) free(vnambuf);
  13612. #endif /* NOSPL */
  13613. #endif /* DYNAMIC */
  13614.                   return(-1);
  13615.               }
  13616.               continue;                 /* and go back for more */
  13617.           } else {
  13618.               *new++ = (char) y;        /* else deposit interpreted value */
  13619.               if (--n2 < 0) {
  13620.                   debug(F101,"zzstring overflow 6","",depth);
  13621. #ifdef DYNAMIC
  13622. #ifndef NOSPL
  13623.           if (vnambuf) free(vnambuf);
  13624. #endif /* NOSPL */
  13625. #endif /* DYNAMIC */
  13626.                   return(-1);
  13627.               }
  13628.           }
  13629.         }
  13630.     }
  13631.     *new = NUL;                         /* Terminate the new string */
  13632.     debug(F010,"zzstring while exit",*s2,0);
  13633.  
  13634.     depth--;                            /* Adjust stack depth gauge */
  13635.     *s2 = new;                          /* Copy results back into */
  13636.     *n = n2;                            /* the argument addresses */
  13637.     debug(F101,"zzstring ok","",depth);
  13638. #ifdef DYNAMIC
  13639. #ifndef NOSPL
  13640.     if (vnambuf) free(vnambuf);
  13641. #endif /* NOSPL */
  13642. #endif /* DYNAMIC */
  13643.     return(0);                          /* and return. */
  13644. }
  13645. #endif /* NOICP */
  13646.