home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku206.zip / ckuus4.c < prev    next >
C/C++ Source or Header  |  2002-10-18  |  482KB  |  13,963 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, 2002,
  10.     Trustees of Columbia University in the City of New York.
  11.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  12.     copyright text in the ckcmai.c module for disclaimer and permissions.
  13. */
  14.  
  15. /*
  16.   File ckuus4.c -- Functions moved from other ckuus*.c modules to even
  17.   out their sizes.
  18. */
  19. #include "ckcdeb.h"
  20. #include "ckcasc.h"
  21. #include "ckcker.h"
  22. #include "ckuusr.h"
  23. #include "ckuver.h"
  24. #include "ckcnet.h"                     /* Network symbols */
  25. #include "ckcxla.h"                     /* Character sets */
  26.  
  27. #ifdef CK_AUTHENTICATION
  28. #include "ckuath.h"
  29. #endif /* CK_AUTHENTICATION */
  30. #ifdef CK_SSL
  31. #include "ck_ssl.h"
  32. #endif /* CK_SSL */
  33.  
  34. #ifdef VMS
  35. #include <errno.h>                      /* For \v(errno) */
  36. extern char * ckvmserrstr(unsigned long);
  37. #ifndef OLD_VMS
  38. #include <lib$routines.h>               /* Not for VAX C 2.4 */
  39. #else
  40. #include <libdef.h>
  41. #endif /* OLD_VMS */
  42. _PROTOTYP(int vmsttyfd, (void) );
  43. #endif /* VMS */
  44.  
  45. #ifdef OS2
  46. #ifndef NT
  47. #define INCL_NOPM
  48. #define INCL_VIO                        /* Needed for ckocon.h */
  49. #include <os2.h>
  50. #undef COMMENT
  51. #else
  52. #include <windows.h>
  53. #include <tapi.h>
  54. #include "ckntap.h"
  55. #define APIRET ULONG
  56. #endif /* NT */
  57. #include "ckocon.h"
  58. #include "ckoetc.h"
  59. int StartedFromDialer = 0;
  60. HWND hwndDialer = 0;
  61. LONG KermitDialerID = 0;
  62. #ifdef putchar
  63. #undef putchar
  64. #endif /* putchar */
  65. #define putchar(x) conoc(x)
  66. #ifdef CK_PID
  67. #include <process.h>
  68. #endif /* CK_PID */
  69. #endif /* OS2 */
  70.  
  71. #ifdef KUI
  72. extern struct keytab * term_font;
  73. extern int ntermfont, tt_font, tt_font_size;
  74. #endif /* KUI */
  75.  
  76. extern xx_strp xxstring;
  77.  
  78. #ifdef DEC_TCPIP
  79. #include <descrip>
  80. #include <dvidef>
  81. #include <dcdef>
  82. #endif /* DEC_TCPIP */
  83.  
  84. #ifdef FNFLOAT
  85. #include <math.h>                       /* Floating-point functions */
  86. #endif /* FNFLOAT */
  87.  
  88. extern int quiet, network, xitsta, escape, nopush, xferstat,
  89.   exitonclose, tn_exit, ttnproto, autodl, flow, byteorder, what, lastxfer;
  90.  
  91. extern int filepeek, nscanfile, makestrlen;
  92. extern char * k_info_dir;
  93.  
  94. #ifndef MAC
  95. #ifndef AMIGA
  96. extern int ttyfd;
  97. #endif /* MAC */
  98. #endif /* AMIGA */
  99.  
  100. #ifdef TNCODE
  101. extern int tn_nlm, tn_b_nlm, tn_b_xfer, tn_sb_bug;
  102. extern int tn_rem_echo;
  103. extern int tn_b_meu, tn_b_ume;
  104. #endif /* TNCODE */
  105.  
  106. char * xferfile = NULL;
  107. int xferlog = 0;
  108.  
  109. extern int local, xargc, stayflg, rcflag, bgset, backgrd, cfilef,
  110.   inserver, srvcdmsg, success;
  111.  
  112. #ifdef VMS
  113. extern int batch;
  114. #endif /* VMS */
  115.  
  116. extern char cmdfil[], *versio, *ckxsys, **xargv;
  117. #ifdef DEBUG
  118. extern char debfil[];                   /* Debug log file name */
  119. extern int debtim;
  120. #endif /* DEBUG */
  121.  
  122. extern int noinit;
  123.  
  124. static char ndatbuf[10];
  125.  
  126. char *months[] = {
  127.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  128.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  129. };
  130.  
  131. char *
  132. zzndate() {                             /* Returns today's date as yyyymmdd */
  133.     char * p = NULL;
  134.     int x;
  135.  
  136. /* WARNING - This will fail if asctime() returns non-English month names */
  137.  
  138.     ztime(&p);                          /* Get "asctime" string */
  139.     if (p == NULL || *p == NUL) return("");
  140.     for (x = 20; x < 24; x++)           /* yyyy */
  141.       ndatbuf[x - 20] = p[x];
  142.     ndatbuf[6] = (char) ((p[8] == ' ') ? '0' : p[8]);
  143.     ndatbuf[7] = p[9];                  /* dd */
  144.     for (x = 0; x < 12; x++)            /* mm */
  145.       if (!strncmp(p+4,months[x],3)) break;
  146.     if (x == 12) {
  147.         ndatbuf[4] = ndatbuf[5] = '?';
  148.     } else {
  149.         x++;
  150.         ndatbuf[4] = (char) ((x < 10) ? '0' : '1');
  151.         ndatbuf[5] = (char) ((x % 10) + 48);
  152.     }
  153.     ndatbuf[8] = NUL;
  154.     debug(F110,"zzndate return",ndatbuf,0);
  155.     return((char *)ndatbuf);
  156. }
  157.  
  158. #ifdef DCMDBUF
  159. extern struct cmdptr *cmdstk;
  160. extern char *line, *tmpbuf;
  161. #else
  162. extern struct cmdptr cmdstk[];
  163. extern char line[], tmpbuf[];
  164. #endif /* DCMDBUF */
  165.  
  166. #ifdef OS2
  167. extern char exedir[];
  168. #else
  169. extern char * exedir;
  170. #endif /* OS2 */
  171.  
  172. extern int nettype;
  173.  
  174. #ifndef NOICP                           /* Most of this file... */
  175. #ifdef CKLOGDIAL
  176. extern char diafil[];
  177. #endif /* CKLOGDIAL */
  178.  
  179. #ifndef AMIGA
  180. #ifndef MAC
  181. #include <signal.h>
  182. #endif /* MAC */
  183. #endif /* AMIGA */
  184.  
  185. #ifdef STRATUS                          /* Stratus Computer, Inc.  VOS */
  186. #ifdef putchar
  187. #undef putchar
  188. #endif /* putchar */
  189. #define putchar(x) conoc(x)
  190. #ifdef getchar
  191. #undef getchar
  192. #endif /* getchar */
  193. #define getchar(x) coninc(0)
  194. #endif /* STRATUS */
  195.  
  196.  
  197. #ifdef ANYX25
  198. extern int revcall, closgr, cudata;
  199. int x25ver;
  200. extern char udata[];
  201. #ifndef IBMX25
  202. extern int npadx3;
  203. extern CHAR padparms[];
  204. extern struct keytab padx3tab[];
  205. #endif /* !IBMX25 */
  206. #ifdef IBMX25
  207. /* global variables only available for IBM X.25 - possibly interesting for
  208.  * other implementations
  209.  */
  210. extern x25addr_t local_nua;
  211. extern x25addr_t remote_nua;
  212. #endif /* IBMX25 */
  213. #endif /* ANYX25 */
  214.  
  215. #ifdef NETCONN
  216. #ifndef NODIAL
  217. extern int nnetdir;
  218. extern char *netdir[];
  219. #endif /* NODIAL */
  220. extern char ipaddr[];
  221.  
  222. #ifdef CK_NETBIOS
  223. extern unsigned short netbiosAvail;
  224. extern unsigned long NetbeuiAPI;
  225. extern unsigned char NetBiosName[];
  226. extern unsigned char NetBiosAdapter;
  227. extern unsigned char NetBiosLSN;
  228. #endif /* CK_NETBIOS */
  229.  
  230. #ifdef TCPSOCKET
  231. extern char myipaddr[];
  232. extern int tcp_rdns;
  233. #ifdef CK_DNS_SRV
  234. extern int tcp_dns_srv;
  235. #endif /* CK_DNS_SRV */
  236. extern char * tcp_address;
  237. #ifndef NOHTTP
  238. extern char * tcp_http_proxy;
  239. #endif /* NOHTTP */
  240. #ifdef NT
  241. #ifdef CK_SOCKS
  242. extern char * tcp_socks_svr;
  243. #ifdef CK_SOCKS_NS
  244. extern char * tcp_socks_ns;
  245. #endif /* CK_SOCKS_NS */
  246. #endif /* CK_SOCKS */
  247. #endif /* NT */
  248.  
  249. #ifndef NOTCPOPTS
  250. #ifdef SOL_SOCKET
  251. #ifdef SO_LINGER
  252. extern int tcp_linger;
  253. extern int tcp_linger_tmo;
  254. #endif /* SO_LINGER */
  255. #ifdef SO_DONTROUTE
  256. extern int tcp_dontroute;
  257. #endif /* SO_DONTROUTE */
  258. #ifdef TCP_NODELAY
  259. extern int tcp_nodelay;
  260. #endif /* TCP_NODELAY */
  261. #ifdef SO_SNDBUF
  262. extern int tcp_sendbuf;
  263. #endif /* SO_SNDBUF */
  264. #ifdef SO_RCVBUF
  265. extern int tcp_recvbuf;
  266. #endif /* SO_RCVBUF */
  267. #ifdef SO_KEEPALIVE
  268. extern int tcp_keepalive;
  269. #endif /* SO_KEEPALIVE */
  270. #endif /* SOL_SOCKET */
  271. #endif /* NOTCPOPTS */
  272. #endif /* TCPSOCKET */
  273. #endif /* NETCONN */
  274.  
  275. extern char * floname[];
  276.  
  277. #ifndef NOSPL
  278. extern int fndiags;                     /* Function diagnostics on/off */
  279. extern int divbyzero;
  280. int ispattern = 0;
  281. #ifdef CK_APC
  282. extern int apcactive;                   /* Nonzero = APC command was rec'd */
  283. extern int apcstatus;                   /* Are APC commands being processed? */
  284. #ifdef DCMDBUF
  285. extern char *apcbuf;                    /* APC command buffer */
  286. #else
  287. extern char apcbuf[];
  288. #endif /* DCMDBUF */
  289. #endif /* CK_APC */
  290.  
  291. extern char evalbuf[];                  /* EVALUATE result */
  292. extern char uidbuf[], pwbuf[], prmbuf[];
  293. _PROTOTYP( static char * fneval, (char *, char * [], int, char * ) );
  294. _PROTOTYP( static VOID myflsh, (void) );
  295. _PROTOTYP( static char * getip, (char *) );
  296. _PROTOTYP( int delta2sec, (char *, long *) );
  297.  
  298. #ifdef NEWFTP
  299. _PROTOTYP( char * ftp_cpl_mode, (void) );
  300. _PROTOTYP( char * ftp_dpl_mode, (void) );
  301. _PROTOTYP( char * ftp_authtype, (void) );
  302. #endif /* NEWFTP */
  303.  
  304. #ifndef NOHTTP
  305. _PROTOTYP( char * http_host, (void) );
  306. _PROTOTYP( int http_isconnected, (void) );
  307. _PROTOTYP( char * http_security, (void) );
  308. #endif /* NOHTTP */
  309.  
  310. #ifndef NOSEXP
  311. _PROTOTYP( char * dosexp, (char *) );
  312. int fsexpflag = 0;
  313. #endif /* NOSEXP */
  314.  
  315. static char hexdigits[16] = {
  316.     '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  317. };
  318. extern char * tempdir;
  319.  
  320. #ifdef CK_REXX
  321. extern char rexxbuf[];
  322. #endif /* CK_REXX */
  323.  
  324. extern int tfline[];
  325.  
  326. /* These need to be internationalized... */
  327.  
  328. static
  329. char *wkdays[] = {
  330.     "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  331. };
  332. #endif /* NOSPL */
  333.  
  334. #ifdef OS2
  335. extern char startupdir[], inidir[];
  336. #else
  337. #ifdef VMSORUNIX
  338. extern char startupdir[];
  339. #endif /* VMSORUNIX */
  340. #endif /* OS2 */
  341.  
  342. #ifdef OS2
  343. _PROTOTYP (int os2getcp, (void) );
  344. #ifdef TCPSOCKET
  345. extern char tcpname[];
  346. #endif /* TCPSOCKET */
  347. extern int tcp_avail;
  348. #ifdef DECNET
  349. extern int dnet_avail;
  350. #endif /* DECNET */
  351. #ifdef SUPERLAT
  352. extern int slat_avail;
  353. #endif /* SUPERLAT */
  354.  
  355. #ifndef NOTERM
  356. extern int tt_type, max_tt;
  357. extern struct tt_info_rec tt_info[];
  358. #endif /* NOTERM */
  359. extern int tt_rows[], tt_cols[];
  360. #else /* OS2 */
  361. extern int tt_rows, tt_cols;
  362. #endif /* OS2 */
  363.  
  364. #ifdef CK_TAPI
  365. extern int tttapi;
  366. extern int tapipass;
  367. extern struct keytab * tapilinetab;
  368. extern struct keytab * _tapilinetab;
  369. extern int ntapiline;
  370. #endif /* CK_TAPI */
  371.  
  372. extern struct keytab colxtab[];
  373. extern int ncolx;
  374.  
  375. extern char ttname[], *zinptr, *kermrc;
  376. extern char inidir[];
  377.  
  378. extern int activecmd, remonly, cmd_rows, cmd_cols, parity, seslog,
  379.   sessft, sosi, hwparity, tsecs, xargs, zincnt, tlevel, insilence, cmdmsk,
  380.   timint, timef, inbufsize, dialog, binary, carrier, cdtimo, cmask, duplex,
  381.   fmask, inecho, nmac, turnch, turn, kbchar;
  382.  
  383. #ifndef NOXFER
  384. extern CHAR eol,  mypadc, mystch, padch, seol, stchr, * epktmsg, feol;
  385. extern char *cksysid;
  386. extern struct ck_p ptab[];
  387. extern int
  388.   protocol, prefixing, xfrbel, xfrcan, xfrint, xfrchr, xfrnum, pktpaus,
  389.   lscapr, lscapu, xfermode, dest, slostart, maxrps, maxsps, maxtry, mypadn,
  390.   npad, pkttim, bigrbsiz, bigsbsiz, keep, atcapr, autopar, bctr, bctu,
  391.   crunched, ckdelay, ebq, ebqflg, pktlog, retrans, rpackets, rptflg, rptq,
  392.   rtimo, spackets, spsiz, spsizf, spsizr, timeouts, fncact, fncnv, urpsiz,
  393.   wmax, wslotn, wslotr, fdispla, spmax, fnrpath, fnspath, crc16;
  394. #endif /* NOXFER */
  395.  
  396. #ifdef OS2
  397. extern int zxpn;
  398. extern int viewonly;
  399. #endif /* OS2 */
  400.  
  401. #ifndef NOXFER
  402. #ifdef GFTIMER
  403. extern CKFLOAT fptsecs, fpxfsecs;
  404. #endif /* GFTIMER */
  405. extern long xfsecs, tfcps;
  406.  
  407. #ifdef CK_TMPDIR
  408. extern char *dldir;
  409. #endif /* CK_TMPDIR */
  410. #endif /* NOXFER */
  411.  
  412. #ifdef RECURSIVE
  413. extern int recursive;
  414. #endif /* RECURSIVE */
  415.  
  416. #ifdef VMS
  417.   extern int frecl;
  418. #endif /* VMS */
  419.  
  420. extern long
  421.   ffc, filcnt, rptn, speed, tfc, tlci, tlco, ccu, ccp, vernum, xvernum;
  422.  
  423. #ifndef NOSPL
  424. extern char fspec[], myhost[];
  425. #endif /* NOSPL */
  426.  
  427. extern char *tfnam[];                   /* Command file names */
  428.  
  429. extern char pktfil[],                   /* Packet log file name */
  430. #ifdef TLOG
  431.   trafil[],                             /* Transaction log file name */
  432. #endif /* TLOG */
  433.   sesfil[];                             /* Session log file name */
  434.  
  435. #ifndef NOXMIT                          /* TRANSMIT command variables */
  436. extern char xmitbuf[];
  437. extern int xmitf, xmitl, xmitx, xmits, xmitw, xmitt;
  438. #endif /* NOXMIT */
  439.  
  440. extern int cmdlvl;
  441.  
  442. #ifndef NOSPL
  443. /* Script programming language items */
  444. extern char **a_ptr[];                  /* Arrays */
  445. extern int a_dim[];
  446. static char * inpmatch = NULL;
  447. extern char * inpbuf, inchar[];         /* Buffers for INPUT and REINPUT */
  448. extern char *inpbp;                     /* And pointer to same */
  449. static char *r3 = (char *)0;
  450. extern int incount;                     /* INPUT character count */
  451. extern int m_found;                     /* MINPUT result */
  452. extern int maclvl;                      /* Macro invocation level */
  453. extern struct mtab *mactab;             /* Macro table */
  454. extern char *mrval[];
  455. extern int macargc[], topargc;
  456.  
  457. #ifdef COMMENT
  458. extern char *m_line[];
  459. extern char *topline;
  460. #endif /* COMMENT */
  461.  
  462. extern char *m_arg[MACLEVEL][10]; /* You have to put in the dimensions */
  463. extern char *g_var[GVARS];        /* for external 2-dimensional arrays. */
  464. #ifdef DCMDBUF
  465. extern int *count, *inpcas;
  466. #else
  467. extern int count[], inpcas[];
  468. #endif /* DCMDBUF */
  469. #endif /* NOSPL */
  470.  
  471. #ifdef UNIX
  472. extern int haslock;                     /* For UUCP locks */
  473. extern char flfnam[];
  474. #ifndef USETTYLOCK
  475. extern char lock2[];
  476. #endif /* USETTYLOCK */
  477. #endif /* UNIX */
  478.  
  479. #ifdef OS2ORUNIX
  480. extern int maxnam, maxpath;             /* Longest name, path length */
  481. #endif /* OS2ORUNIX */
  482.  
  483. extern int mdmtyp, mdmsav;
  484.  
  485. #ifndef NODIAL
  486. /* DIAL-related variables */
  487. extern char modemmsg[];
  488. extern MDMINF *modemp[];                /* Pointers to modem info structs */
  489. extern int nmdm, dialhng, dialtmo, dialksp, dialdpy, dialsrt, dialsta;
  490. extern int dialrtr, dialint, dialrstr, dialcon, dialcq, dialfld;
  491. extern int mdmspd, dialec, dialdc, dialmth, dialmauto, dialesc;
  492. extern char *dialnum,   *dialini,  *dialdir[], *dialcmd,  *dialnpr,
  493.  *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd, *diallac,
  494.  *dialhwfc, *dialswfc,  *dialnofc, *dialpulse, *dialtone, *dialname,
  495.  *dialaaon, *dialaaoff, *dialmac;
  496. extern char *diallcc,   *dialixp,  *dialixs,   *dialldp,  *diallds,
  497.  *dialpxi,  *dialpxo,   *dialsfx,  *dialtfp;
  498. extern char *diallcp,   *diallcs;
  499. extern int ntollfree, ndialpxx, nlocalac;
  500. extern char *dialtfc[], *diallcac[], *dialpxx[], *matchpxx;
  501. extern int ndialpucc, ndialtocc;
  502. extern char *dialtocc[], *dialpucc[];
  503. extern int ndialdir, dialcnf, dialcvt, dialidt, dialpace;
  504. extern long dialmax, dialcapas;
  505.  
  506. extern struct keytab mdmtab[];
  507.  
  508. #ifdef BIGBUFOK
  509. #define ARGBUFSIZ 8191
  510. #else
  511. #define ARGBUFSIZ 1023
  512. #endif /* BIGBUFOK */
  513.  
  514. #ifdef BIGBUFOK
  515. extern char * dialmsg[];
  516. #endif /* BIGBUFOK */
  517.  
  518. #endif /* NODIAL */
  519.  
  520. #ifndef NOCSETS
  521. /* Translation stuff */
  522. extern int fcharset, tcharset, tslevel, language, nlng, tcsr, tcsl;
  523. extern int dcset7, dcset8;
  524. extern struct keytab lngtab[];
  525. extern struct csinfo fcsinfo[], tcsinfo[];
  526. extern struct langinfo langs[];
  527. #ifdef CK_ANSIC
  528. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  529. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  530. #else
  531. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(); /* Character set */
  532. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(); /* translation functions. */
  533. #endif /* CK_ANSIC */
  534. #ifdef UNICODE
  535.     extern int ucsbom, ucsorder;
  536. #endif /* UNICODE */
  537. #endif /* NOCSETS */
  538.  
  539. #ifndef NOSPL
  540. /* Built-in variable names, maximum length VNAML (20 characters) */
  541.  
  542. struct keytab vartab[] = {
  543.     { "_line",     VN_TFLN,  CM_INV},   /* 192 */
  544. #ifdef OS2
  545.     { "_regname",  VN_REGN,  CM_INV},   /* 1.1.12 */
  546.     { "_regorg",   VN_REGO,  CM_INV},   /* 1.1.12 */
  547.     { "_regnum",   VN_REGS,  CM_INV},   /* 1.1.12 */
  548. #endif /* OS2 */
  549.     { "apcactive", VN_APC,   CM_INV},   /* 192 */
  550. #ifdef NT
  551.     { "appdata",   VN_APPDATA, 0},      /* 201 */
  552. #endif /* NT */
  553.     { "argc",      VN_ARGC,  0},
  554.     { "args",      VN_ARGS,  0},
  555.     { "authname",  VN_AUTHN, 0},        /* 196 */
  556.     { "authstate", VN_AUTHS, 0},        /* 195 */
  557.     { "authtype",  VN_AUTHT, 0},        /* 195 */
  558.     { "blockcheck",VN_BLK,   0},        /* 195 */
  559. #ifdef BROWSER
  560.     { "browser",   VN_BROWSR,0},        /* 193 */
  561.     { "browsopts", VN_BROPT, 0},        /* 193 */
  562.     { "browsurl",  VN_URL,   0},        /* 193 */
  563.     { "buildid",   VN_BUILD, 0},        /* 199 */
  564. #endif /* BROWSER */
  565.     { "byteorder", VN_BYTE,  0},        /* 195 */
  566. #ifndef NOCSETS
  567.     { "charset",   VN_CSET,  0},        /* 192 */
  568. #endif /* NOCSETS */
  569.     { "cmdbufsize",VN_CMDBL, 0},        /* 195 */
  570.     { "cmdfile",   VN_CMDF,  0},
  571.     { "cmdlevel",  VN_CMDL,  0},
  572.     { "cmdsource", VN_CMDS,  0},
  573.     { "cols",      VN_COLS,  0},        /* 190 */
  574. #ifdef NT
  575.     { "common",    VN_COMMON, 0},       /* 201 */
  576. #endif /* NT */
  577.     { "connection",VN_CONN,  0},        /* 190 */
  578.     { "count",     VN_COUN,  0},
  579. #ifndef NOXFER
  580.     { "cps",       VN_CPS,   0},        /* 190 */
  581. #endif /* NOXFER */
  582.     { "cpu",       VN_CPU,   0},
  583. #ifndef NOXFER
  584.     { "crc16",     VN_CRC16, 0},        /* 192 */
  585.     { "ctty",      VN_TTYNAM,0},        /* 196 */
  586. #endif /* NOXFER */
  587. #ifndef NOLOGDIAL
  588. #ifndef NOLOCAL
  589.     { "cx_time",   VN_CXTIME,0},        /* 195 */
  590.     { "cx_status", VN_CX_STA,0},        /* 199 */
  591. #endif /* NOLOCAL */
  592. #endif /* NOLOGDIAL */
  593. #ifndef NODIAL
  594.     { "d$ac",      VN_D_AC,  0},        /* 192 */
  595.     { "d$cc",      VN_D_CC,  0},        /* 192 */
  596.     { "d$ip",      VN_D_IP,  0},        /* 192 */
  597.     { "d$lc",      VN_D_LCP, 0},        /* 193 */
  598.     { "d$lcp",     VN_D_LCP, CM_INV},   /* 193 */
  599.     { "d$lp",      VN_D_LP,  0},        /* 192 */
  600.     { "d$px",      VN_D_PXX, 0},        /* 195 */
  601.     { "d$pxx",     VN_D_PXX, CM_INV},   /* 195 */
  602. #endif /* NODIAL */
  603.     { "date",      VN_DATE,  0},
  604.     { "day",       VN_DAY,   0},
  605. #ifdef NT
  606.     { "desktop",   VN_DESKTOP, 0},     /* 201 */
  607. #endif /* NT */
  608. #ifndef NODIAL
  609.     { "dialcount", VN_DRTR,  0},        /* 195 */
  610.     { "dialnumber",VN_DNUM,  0},        /* 192 */
  611.     { "dialresult",VN_MDMSG, 0},        /* 192 */
  612.     { "dialstatus",VN_DIAL,  0},        /* 190 */
  613.     { "dialsuffix",VN_PDSFX, 0},        /* 193 */
  614.     { "dialtype",  VN_DTYPE, 0},        /* 193 */
  615. #endif /* NODIAL */
  616.     { "directory", VN_DIRE,  0},
  617. #ifndef NODIAL
  618.     { "dm_hf",     VN_DM_HF, 0},        /* 199 */
  619.     { "dm_lp",     VN_DM_LP, 0},        /* 195 */
  620.     { "dm_sp",     VN_DM_SP, 0},        /* 195 */
  621.     { "dm_pd",     VN_DM_PD, 0},        /* 195 */
  622.     { "dm_td",     VN_DM_TD, 0},        /* 195 */
  623.     { "dm_wa",     VN_DM_WA, 0},        /* 195 */
  624.     { "dm_wb",     VN_DM_WB, 0},        /* 199 */
  625.     { "dm_wd",     VN_DM_WD, 0},        /* 195 */
  626.     { "dm_rc",     VN_DM_RC, 0},        /* 195 */
  627. #endif /* NODIAL */
  628. #ifndef NOXFER
  629.     { "download",  VN_DLDIR, 0},        /* 192 */
  630. #endif /* NOXFER */
  631.     { "editor",    VN_EDITOR,0},
  632.     { "editfile",  VN_EDFILE,0},
  633.     { "editopts",  VN_EDOPT, 0},
  634.     { "errno",     VN_ERRNO, 0},        /* 192 */
  635.     { "errstring", VN_ERSTR, 0},        /* 192 */
  636.     { "escape",    VN_ESC,   0},        /* 193 */
  637.     { "evaluate",  VN_EVAL,  0},        /* 190 */
  638. #ifdef OS2ORUNIX
  639.     { "exedir",    VN_EXEDIR,0},        /* 192 */
  640. #endif /* OS2ORUNIX */
  641.     { "exitstatus",VN_EXIT,  0},
  642. #ifdef CKCHANNELIO
  643.     { "f_count",   VN_FCOU,  0},        /* 195 */
  644.     { "f_error",   VN_FERR,  0},        /* 195 */
  645.     { "f_max",     VN_FMAX,  0},        /* 195 */
  646.     { "fileerror", VN_FERR,  CM_INV},   /* 195 */
  647.     { "filemax",   VN_FERR,  CM_INV},   /* 195 */
  648. #endif /* CKCHANNELIO */
  649.     { "filename",  VN_FNAM,  0},        /* 193 */
  650.     { "filenumber",VN_FNUM,  0},        /* 193 */
  651.     { "filespec",  VN_FILE,  0},
  652.     { "fsize",     VN_FFC,   0},        /* 190 */
  653. #ifdef GFTIMER
  654.     { "ftime",     VN_FTIME, 0},        /* 199 */
  655. #else
  656.     { "ftime",     VN_NTIM,  CM_INV},
  657. #endif /* GFTIMER */
  658. #ifndef NOFTP
  659. #ifndef SYSFTP
  660.     { "ftp_code",         VN_FTP_C, 0}, /* 199 */
  661.     { "ftp_cpl",          VN_FTP_B, 0}, /* 199 */
  662.     { "ftp_connected",    VN_FTP_X, 0}, /* 199 */
  663.     { "ftp_dpl",          VN_FTP_D, 0}, /* 199 */
  664.     { "ftp_getputremote", VN_FTP_G, 0}, /* 199 */
  665.     { "ftp_host",         VN_FTP_H, 0}, /* 199 */
  666.     { "ftp_loggedin",     VN_FTP_L, 0}, /* 199 */
  667.     { "ftp_message",      VN_FTP_M, 0}, /* 199 */
  668.     { "ftp_msg",          VN_FTP_M, CM_INV}, /* 199 */
  669.     { "ftp_security",     VN_FTP_Z, 0}, /* 199 */
  670.     { "ftp_server",       VN_FTP_S, 0}, /* 199 */
  671. #endif /* SYSFTP */
  672. #endif /* NOFTP */
  673.     { "ftype",     VN_MODE,  0},        /* 190 */
  674. #ifdef KUI
  675.     { "gui_fontname", VN_GUI_FNM, 0},    /* 205 */
  676.     { "gui_fontsize", VN_GUI_FSZ, 0},    /* 205 */
  677.     { "gui_runmode", VN_GUI_RUN, 0},    /* 205 */
  678.     { "gui_xpos",    VN_GUI_XP,  0},    /* 205 */
  679.     { "gui_xres",    VN_GUI_XR,  0},    /* 205 */
  680.     { "gui_ypos",    VN_GUI_YP,  0},    /* 205 */
  681.     { "gui_yres",    VN_GUI_YR,  0},    /* 205 */
  682. #endif /* KUI */
  683.     { "herald",    VN_HERALD, 0},
  684.     { "home",      VN_HOME,   0},
  685.     { "host",      VN_HOST,   0},
  686.     { "hour",      VN_HOUR,   0},       /* 200 */
  687. #ifndef NOHTTP
  688.     { "http_code",      VN_HTTP_C, 0},  /* 199 */
  689.     { "http_connected", VN_HTTP_N, 0},  /* 199 */
  690.     { "http_host",      VN_HTTP_H, 0},  /* 199 */
  691.     { "http_message",   VN_HTTP_M, 0},  /* 199 */
  692.     { "http_security",  VN_HTTP_S, 0},  /* 199 */
  693. #endif /* NOHTTP */
  694.     { "hwparity",  VN_HWPAR, 0},        /* 195 */
  695.     { "input",     VN_IBUF,  0},
  696.     { "inchar",    VN_ICHR,  0},
  697.     { "incount",   VN_ICNT,  0},
  698.     { "inidir",    VN_INI,   0},        /* 192 */
  699.     { "inmatch",   VN_MATCH, 0},        /* 196 */
  700.     { "instatus",  VN_ISTAT, 0},        /* 192 */
  701.     { "intime",    VN_INTIME,0},        /* 193 */
  702.     { "inwait",    VN_INTMO, 0},        /* 195 */
  703.     { "ip",        VN_IPADDR, CM_ABR|CM_INV},
  704.     { "ipaddress", VN_IPADDR,0},        /* 192 */
  705.     { "iprompt",   VN_PROMPT,0},        /* 199 */
  706.     { "kbchar",    VN_KBCHAR,0},        /* 196 */
  707. #ifndef NOLOCAL
  708. #ifdef OS2
  709.     { "keyboard",  VN_KEYB,  0},
  710. #endif /* OS2 */
  711. #endif /* NOLOCAL */
  712. #ifdef CK_KERBEROS
  713.     { "krb4errmsg",    VN_K4EMSG,0},
  714.     { "krb4errno",     VN_K4ENO, 0},
  715.     { "krb4principal", VN_K4PRN, 0},
  716.     { "krb4realm",     VN_K4RLM, 0},
  717.     { "krb4service",   VN_K4SRV, 0},
  718.     { "krb5cc",        VN_K5CC,  0},
  719.     { "krb5errmsg",    VN_K5EMSG,0},
  720.     { "krb5errno",     VN_K5ENO, 0},
  721.     { "krb5principal", VN_K5PRN, 0},
  722.     { "krb5realm",     VN_K5RLM, 0},
  723.     { "krb5service",   VN_K5SRV, 0},
  724. #endif /* CK_KERBEROS */
  725.     { "line",      VN_LINE,  0},
  726.     { "local",     VN_LCL,   0},
  727. #ifdef UNIX
  728.     { "lockdir",   VN_LCKDIR,0},        /* 195 */
  729.     { "lockpid",   VN_LCKPID,0},        /* 195 */
  730. #endif /* UNIX */
  731.     { "log_connection", VN_LOG_CON, 0}, /* 206 */
  732.     { "log_debug", VN_LOG_DEB, 0},      /* 206 */
  733.     { "log_packet", VN_LOG_PKT, 0},     /* 206 */
  734.     { "log_session", VN_LOG_SES, 0},    /* 206 */
  735.     { "log_transaction", VN_LOG_TRA, 0},/* 206 */
  736.     { "maclevel",  VN_MACLVL,0},        /* 195 */
  737.     { "macro",     VN_MAC,   0},
  738. #ifdef FNFLOAT
  739.     { "math_e",    VN_MA_E,  0},        /* 195 */
  740.     { "math_pi",   VN_MA_PI, 0},        /* 195 */
  741.     { "math_precision", VN_MA_PR, 0},   /* 195 */
  742. #endif /* FNFLOAT */
  743.     { "minput",    VN_MINP,  0},        /* 192 */
  744.     { "model",     VN_MODL,  0},        /* 193 */
  745.     { "modem",     VN_MDM,   0},
  746. #ifndef NOLOCAL
  747. #ifdef OS2
  748.     { "mousecurx", VN_MOU_X, 0},        /* K95 1.1.14 */
  749.     { "mousecury", VN_MOU_Y, 0},        /* K95 1.1.14 */
  750. #endif /* OS2 */
  751. #endif /* NOLOCAL */
  752. #ifndef NODIAL
  753.     { "m_aa_off",  VN_M_AAX, 0},        /* all 192... */
  754.     { "m_aa_on",   VN_M_AAO, 0},
  755.     { "m_dc_off",  VN_M_DCX, 0},
  756.     { "m_dc_on",   VN_M_DCO, 0},
  757.     { "m_dial",    VN_M_DCM, 0},
  758.     { "m_ec_off",  VN_M_ECX, 0},
  759.     { "m_ec_on",   VN_M_ECO, 0},
  760.     { "m_fc_hw",   VN_M_HWF, 0},
  761.     { "m_fc_no",   VN_M_NFC, 0},
  762.     { "m_fc_sw",   VN_M_SWF, 0},
  763.     { "m_hup",     VN_M_HUP, 0},
  764.     { "m_init",    VN_M_INI, 0},
  765.     { "m_name",    VN_M_NAM, 0},        /* 195 */
  766.     { "m_pulse",   VN_M_PDM, 0},
  767.     { "m_sig_cd",  VN_MS_CD, 0},        /* 195 */
  768.     { "m_sig_cts", VN_MS_CTS,0},        /* 195 */
  769.     { "m_sig_dsr", VN_MS_DSR,0},        /* 195 */
  770.     { "m_sig_dtr", VN_MS_DTR,0},        /* 195 */
  771.     { "m_sig_ri",  VN_MS_RI, 0},        /* 195 */
  772.     { "m_sig_rts", VN_MS_RTS,0},        /* 195 */
  773.     { "m_tone",    VN_M_TDM, 0},
  774. #endif /* NODIAL */
  775.     { "name",      VN_NAME,  0},
  776.     { "ndate",     VN_NDAT,  0},
  777.     { "nday",      VN_NDAY,  0},
  778.     { "newline",   VN_NEWL,  0},
  779.     { "ntime",     VN_NTIM,  0},
  780.     { "osname",    VN_OSNAM, 0},        /* 193 */
  781.     { "osrelease", VN_OSREL, 0},        /* 193 */
  782.     { "osversion", VN_OSVER, 0},        /* 193 */
  783. #ifndef NOXFER
  784.     { "packetlen", VN_RPSIZ, 0},        /* 192 */
  785. #endif /* NOXFER */
  786.     { "parity",    VN_PRTY,  0},        /* 190 */
  787.     { "password",  VN_PWD,   CM_INV},   /* 192 */
  788. #ifdef NT
  789.     { "personal",  VN_PERSONAL, 0},     /* 201 */
  790. #endif /* NT */
  791. #ifdef PEXITSTAT
  792.     { "pexitstat", VN_PEXIT, 0},        /* 193 */
  793. #endif /* PEXITSTAT */
  794. #ifdef CK_PID
  795.     { "pid",       VN_PID,   0},        /* 193 */
  796. #endif /* CK_PID */
  797.     { "platform",  VN_SYSV,  0},
  798.     { "printer",   VN_PRINT, 0},        /* 193 */
  799.     { "program",   VN_PROG,  0},
  800.     { "prompt",    VN_PRM,   CM_INV},   /* 192 */
  801. #ifndef NOXFER
  802.     { "protocol",  VN_PROTO, 0},        /* 192 */
  803.     { "p_8bit",    VN_P_8BIT,0},        /* 193 */
  804.     { "p_ctl",     VN_P_CTL, 0},        /* 193 */
  805.     { "p_rpt",     VN_P_RPT, 0},        /* 193 */
  806.     { "query",     VN_QUE,   0},        /* 190 */
  807. #endif /* NOXFER */
  808.     { "return",    VN_RET,   0},
  809. #ifdef CK_REXX
  810.     { "rexx",      VN_REXX,  0},        /* 190 */
  811. #endif /* CK_REXX */
  812. #ifdef TN_COMPORT
  813.     { "rfc2217_signature", VN_TNC_SIG, 0}, /* 201 */
  814.     { "rfc2717_signature", VN_TNC_SIG, CM_INV}, /* 202 */
  815. #endif /* TN_COMPORT */
  816.     { "rows",      VN_ROWS,  0},        /* 190 */
  817. #ifndef NOSEXP
  818.     { "sdepth",    VN_LSEXP,0},         /* 199 */
  819. #endif /* NOSEXP */
  820.     { "secure",    VN_SECURE, 0},       /* 199 */
  821. #ifndef NOLOCAL
  822. #ifdef OS2
  823.     { "select",    VN_SELCT, 0},        /* 192 */
  824. #endif /* OS2 */
  825. #endif /* NOLOCAL */
  826.     { "sendlist",  VN_SNDL,  0},
  827.     { "serial",    VN_SERIAL,0},        /* 195 */
  828.     { "setlinemsg",VN_SLMSG, 0},        /* 195 */
  829. #ifndef NOSEXP
  830.     { "sexpression",VN_SEXP, 0},        /* 199 */
  831. #endif /* NOSEXP */
  832.     { "speed",     VN_SPEE,  0},
  833. #ifdef OS2
  834.     { "space",     VN_SPA,   0},
  835.     { "startup",   VN_STAR,  0},        /* 190 */
  836. #else
  837. #ifdef UNIX
  838.     { "startup",   VN_STAR,  0},        /* 193 */
  839. #else
  840. #ifdef VMS
  841.     { "startup",   VN_STAR,  0},        /* 193 */
  842. #endif /* VMS */
  843. #endif /* UNIX */
  844. #endif /* OS2 */
  845.     { "status",    VN_SUCC,  0},
  846. #ifndef NOSEXP
  847.     { "svalue",    VN_VSEXP, 0},        /* 199 */
  848. #endif /* NOSEXP */
  849. #ifndef NOXFER
  850.     { "sysid",     VN_SYSI,  0},
  851. #endif /* NOXFER */
  852.     { "system",    VN_SYST,  0},
  853.     { "terminal",  VN_TTYP,  0},
  854. #ifdef OS2
  855. #ifndef NOKVERBS
  856.     { "termkey",   VN_TRMK,  CM_INV},   /* 192 */
  857. #endif /* NOKVERBS */
  858. #endif /* OS2 */
  859.     { "test",      VN_TEST,  0},        /* 193 */
  860.     { "textdir",   VN_TXTDIR,0},        /* 195 */
  861. #ifndef NOXFER
  862.     { "tfsize",    VN_TFC,   0},
  863.     { "tftime",    VN_TFTIM, 0},        /* 195 */
  864. #endif /* NOXFER */
  865.     { "time",      VN_TIME,  0},
  866.     { "timestamp", VN_NOW,   0},        /* 200 */
  867.     { "tmpdir",    VN_TEMP,  0},        /* 192 */
  868. #ifdef CK_TRIGGER
  869.     { "trigger",   VN_TRIG,  0},        /* 193 */
  870. #endif /* CK_TRIGGER */
  871. #ifdef CK_TTYFD
  872.     { "ttyfd",     VN_TTYF,  0},
  873. #endif /* CK_TTYFD */
  874.     { "ty_ln",     VN_TY_LN, 0},        /* 195 */
  875.     { "ty_lc",     VN_TY_LC, 0},        /* 195 */
  876.     { "ty_lm",     VN_TY_LM, 0},        /* 195 */
  877. #ifdef BROWSER
  878.     { "url",       VN_URL,   CM_INV},   /* 193 */
  879. #endif /* BROWSER */
  880.     { "userid",    VN_UID,   0},        /* 192 */
  881.     { "version",   VN_VERS,  0},
  882. #ifndef NOXFER
  883.     { "window",    VN_WINDO, 0},        /* 192 */
  884. #endif /* NOXFER */
  885. #ifdef IBMX25
  886.     { "x25local_nua", VN_X25LA, 0},     /* 193 */
  887.     { "x25remote_nua", VN_X25RA, 0},    /* 193 */
  888. #endif /* IBMX25 */
  889. #ifdef CK_SSL
  890.     { "x509_issuer",  VN_X509_I, 0},
  891.     { "x509_subject", VN_X509_S, 0},
  892. #endif /* CK_SSL */
  893. #ifndef NOXFER
  894.     { "xferstatus",VN_XFSTAT,0},        /* 193 */
  895.     { "xfermsg",   VN_XFMSG, 0},        /* 193 */
  896.     { "xfer_badpackets", VN_XF_BC, 0},  /* 195 */
  897.     { "xfer_timeouts",   VN_XF_TM, 0},  /* 195 */
  898.     { "xfer_retransmits",VN_XF_RX, 0},  /* 195 */
  899. #endif /* NOXFER */
  900.     { "xprogram",  VN_XPROG, 0},        /* 193 */
  901.     { "xversion",  VN_XVNUM, 0}         /* 192 */
  902. };
  903. int nvars = (sizeof(vartab) / sizeof(struct keytab));
  904. #endif /* NOSPL */
  905.  
  906. #ifndef NOSPL
  907. struct keytab fnctab[] = {              /* Function names */
  908. #ifdef OS2
  909.     { ".oox",       FN_OOX, CM_INV},    /* ... */
  910. #endif /* OS2 */
  911.  
  912. #ifdef CKCHANNELIO
  913.     { "_eof",       FN_FEOF,   0},
  914.     { "_errmsg",    FN_FERMSG, 0},
  915.     { "_getblock",  FN_FGBLK,  0},
  916.     { "_getchar",   FN_FGCHAR, 0},
  917.     { "_getline",   FN_FGLINE, 0},
  918.     { "_handle",    FN_FILNO,  0},
  919.     { "_line",      FN_NLINE,  0},
  920.     { "_pos",       FN_FPOS,   0},
  921.     { "_putblock",  FN_FPBLK,  0},
  922.     { "_putchar",   FN_FPCHAR, 0},
  923.     { "_putline",   FN_FPLINE, 0},
  924.     { "_status",    FN_FSTAT,  0},
  925. #endif /* CKCHANNELIO */
  926.  
  927.     { "aaconvert",  FN_AADUMP, 0},      /* Associative Array conversion */
  928.     { "absolute",   FN_ABS,  0},        /* Absolute value */
  929. #ifdef TCPSOCKET
  930.     { "addr2name",  FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  931.     { "addrtoname", FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  932. #endif /* TCPSOCKET */
  933.     { "arraylook",  FN_ALOOK,0},        /* Array lookup */
  934.     { "b64decode",  FN_FMB64,0},        /* Base-64 conversion */
  935.     { "b64encode",  FN_TOB64,0},        /* ... */
  936.     { "basename",   FN_BSN,  0},        /* Basename */
  937.     { "break",      FN_BRK,  0},        /* Break (as in Snobol) */
  938.     { "ca",         FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  939.     { "cap",        FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  940.     { "capitalize", FN_CAP,  0},        /* First Letter -> uppercase */
  941.     { "caps",       FN_CAP,  CM_INV},   /* ditto */
  942.     { "character",  FN_CHR,  0},        /* Character from code */
  943.     { "checksum",   FN_CHK,  0},        /* Checksum */
  944.     { "cmdstack",   FN_CMDSTK,0},       /* Command stack */
  945.     { "cmpdates",   FN_CMPDATE,0},      /* Compare dates */
  946.     { "code",       FN_COD,  0},        /* Code from character */
  947. #ifndef NOPUSH
  948.     { "command",    FN_CMD,  0},        /* Output from a command */
  949. #endif /* NOPUSH */
  950.     { "contents",   FN_CON,  0},        /* Definition (contents) of variable */
  951.     { "crc16",      FN_CRC,  0},        /* CRC-16 */
  952. #ifdef OS2
  953.     { "crypt",      FN_CRY, CM_INV},
  954. #endif /* OS2 */
  955.     { "cvtdate",    FN_DTIM, 0},        /* Convert free date/time to std */
  956. #ifdef ZFCDAT
  957.     { "date",       FN_FD,   0},        /* File modification/creation date */
  958. #endif /* ZFCDAT */
  959.     { "day",        FN_DAY,  0},        /* Day of week */
  960.     { "dayofyear",  FN_JDATE,0},        /* Date to Day of Year */
  961.     { "definition", FN_DEF,  0},        /* Return definition of given macro */
  962.     { "delta2secs", FN_DELSEC, 0},      /* Delta time to seconds */
  963.     { "deltatosecs", FN_DELSEC, CM_INV}, /* Delta time to seconds */
  964. #ifndef NODIAL
  965.     { "dialconvert",FN_PNCVT,0},        /* Convert portable phone number */
  966. #endif /* NODIAL */
  967.     { "diffdates",  FN_DIFDATE,0},      /* Difference of two date-times */
  968.     { "dimension",  FN_DIM,  0},        /* Dimension of array */
  969.     { "directories",FN_DIR,  0},        /* List of directories */
  970.     { "dirname",    FN_DNAM, 0},        /* Directory part of filename */
  971.     { "dos2unixpath",FN_PC_DU, },       /* DOS to UNIX path */
  972.     { "dostounixpath",FN_PC_DU, CM_INV}, /* DOS to UNIX path */
  973.     { "doy",        FN_JDATE,CM_INV},   /* Date to Day of Year */
  974.     { "doy2date",   FN_DATEJ,0},        /* Day of Year to date */
  975.     { "doytodate",  FN_DATEJ,CM_INV},   /* Day of Year to date */
  976. #ifdef FN_ERRMSG
  977.     { "errstring",  FN_ERRMSG,0},       /* Error code to message */
  978. #endif /* FN_ERRMSG */
  979.     { "evaluate",   FN_EVA,  0},        /* Evaluate given arith expression */
  980.     { "execute",    FN_EXE,  0},        /* Execute given macro */
  981.     { "files",      FN_FC,   0},        /* File count */
  982. #ifdef FNFLOAT
  983.     { "fpabsolute", FN_FPABS, 0},       /* Floating-point absolute value */
  984.     { "fpadd",      FN_FPADD, 0},       /* FP add */
  985.     { "fpcosine",   FN_FPCOS, 0},       /* FP cosine */
  986.     { "fpdivide",   FN_FPDIV, 0},       /* FP divide */
  987.     { "fpexp",      FN_FPEXP, 0},       /* FP e to the x */
  988.     { "fpint",      FN_FPINT, 0},       /* FP to integer */
  989.     { "fplog10",    FN_FPLOG, 0},       /* FP base-10 logarithm */
  990.     { "fplogn",     FN_FPLN,  0},       /* FP natural logarithm */
  991.     { "fpmaximum",  FN_FPMAX, 0},       /* FP maxinum */
  992.     { "fpminimum",  FN_FPMIN, 0},       /* FP mininum */
  993.     { "fpmodulus",  FN_FPMOD, 0},       /* FP modulus */
  994.     { "fpmultiply", FN_FPMUL, 0},       /* FP multiply */
  995.     { "fpraise",    FN_FPPOW, 0},       /* FP raise to a power */
  996.     { "fpround",    FN_FPROU, 0},       /* FP round */
  997.     { "fpsine",     FN_FPSIN, 0},       /* FP sine */
  998.     { "fpsqrt",     FN_FPSQR, 0},       /* FP square root */
  999.     { "fpsubtract", FN_FPSUB, 0},       /* FP subtract */
  1000.     { "fptangent",  FN_FPTAN, 0},       /* FP tangent */
  1001. #endif /* FNFLOAT */
  1002.     { "hex2ip",     FN_HEX2IP,0},       /* Hex to IP address */
  1003.     { "hextoip",    FN_HEX2IP,CM_INV},  /* Hex to IP address */
  1004.     { "hex2n",      FN_HEX2N, CM_INV},  /* Hex to decimal number */
  1005.     { "hexify",     FN_HEX,   0},       /* Hexify (string) */
  1006.     { "index",      FN_IND,   0},       /* Index (string search) */
  1007.     { "ip2hex",     FN_IP2HEX,0},       /* IP address to hex */
  1008.     { "iptohex",    FN_IP2HEX,CM_INV},  /* IP address to hex */
  1009.     { "ipaddress",  FN_IPA,   0},       /* Find and return IP address */
  1010.     { "jdate",      FN_JDATE, CM_INV},  /* Date to Day of Year */
  1011.     { "join",       FN_JOIN,  0},       /* Join array elements */
  1012.     { "keywordvalue",  FN_KWVAL, 0},    /* Keyword=Value */
  1013. #ifdef CK_KERBEROS
  1014.     { "krbflags",      FN_KRB_FG, 0},   /* Kerberos functions */
  1015.     { "krbisvalid",    FN_KRB_IV, 0},
  1016.     { "krbnextticket", FN_KRB_NX, 0},
  1017.     { "krbtickets",    FN_KRB_TK, 0},
  1018.     { "krbtimeleft",   FN_KRB_TT, 0},
  1019. #endif /* CK_KERBEROS */
  1020.     { "left",       FN_LEF,  0},        /* Leftmost n characters of string */
  1021.     { "length",     FN_LEN,  0},        /* Return length of argument */
  1022.     { "literal",    FN_LIT,  0},        /* Return argument literally */
  1023. #ifdef NT
  1024.     { "longpathname",FN_LNAME,0},    /* GetLongPathName() */
  1025. #else
  1026.     { "longpathname",FN_FFN,CM_INV},
  1027. #endif /* NT */
  1028.     { "lop",        FN_STL,  0},        /* Lop */
  1029.     { "lower",      FN_LOW,  0},        /* Return lowercased argument */
  1030.     { "lpad",       FN_LPA,  0},        /* Return left-padded argument */
  1031.     { "ltrim",      FN_LTR,  0},        /* Left-Trim */
  1032.     { "maximum",    FN_MAX,  0},        /* Return maximum of two arguments */
  1033.     { "minimum",    FN_MIN,  0},        /* Return minimum of two arguments */
  1034.     { "mjd",        FN_MJD,  0},        /* Date to Modified Julian Date */
  1035.     { "mjd2date",   FN_MJD2, 0},        /* MJD to Date */
  1036.     { "mjdtodate",  FN_MJD2, CM_INV},   /* MJD to Date */
  1037.     { "modulus",    FN_MOD,  0},        /* Return modulus of two arguments */
  1038. #ifdef COMMENT
  1039.     { "msleep",     FN_MSLEEP,0},       /* Sleep for n milliseconds */
  1040. #endif /* COMMENT */
  1041.     { "n2hex",      FN_2HEX, CM_INV},   /* Number to hex */
  1042.     { "n2octal",    FN_2OCT, CM_INV},   /* Number to octal */
  1043.     { "n2time",     FN_N2TIM,0},        /* Number to hh:mm:ss */
  1044. #ifdef TCPSOCKET
  1045.     { "name2addr",  FN_HSTNAM,CM_INV},  /* Hostname to IP Address */
  1046. #endif /* TCPSOCKET */
  1047.     { "nday",       FN_NDAY, 0},        /* Numeric day of week */
  1048.     { "nextfile",   FN_FIL,  0},        /* Next file in list */
  1049.     { "ntime",      FN_NTIM, 0},        /* Time to seconds since midnight */
  1050.     { "ntohex",     FN_2HEX, CM_INV},   /* Number to hex */
  1051.     { "ntooctal",   FN_2OCT, CM_INV},   /* Number to octal */
  1052.     { "ntotime",    FN_N2TIM,CM_INV},   /* Number to hh:mm:ss */
  1053.     { "oct2n",      FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1054.     { "octton",     FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1055.     { "pathname",   FN_FFN,  0},        /* Full file name */
  1056.     { "pattern",    FN_PATTERN, 0},     /* Pattern (for INPUT) */
  1057. #ifdef CK_PERMS
  1058.     { "permissions",FN_PERM, 0},        /* Permissions of file */
  1059. #else
  1060.     { "permissions",FN_PERM, CM_INV},   /* Permissions of file */
  1061. #endif /* CK_PERMS */
  1062.     { "radix",      FN_RADIX,0},        /* Radix conversion */
  1063. #ifndef NORANDOM
  1064.     { "random",     FN_RAND, 0},        /* Random number */
  1065. #endif /* NORANDOM */
  1066. #ifndef NOPUSH
  1067.     { "rawcommand", FN_RAW,  0},        /* Output from a command (raw) */
  1068. #endif /* NOPUSH */
  1069. #ifdef RECURSIVE
  1070.     { "rdirectories", FN_RDIR, 0},      /* Recursive directory list */
  1071.     { "rfiles",       FN_RFIL, 0},      /* Recursive file list */
  1072. #endif /* RECURSIVE */
  1073.     { "rep",        FN_REP, CM_INV|CM_ABR},
  1074.     { "repeat",     FN_REP,  0},        /* Repeat argument given # of times */
  1075.     { "replace",    FN_RPL,  0},        /* Replace characters in string */
  1076.     { "reverse",    FN_REV,  0},        /* Reverse the argument string */
  1077.     { "right",      FN_RIG,  0},        /* Rightmost n characters of string */
  1078.     { "rindex",     FN_RIX,  0},        /* Right index */
  1079.     { "rpad",       FN_RPA,  0},        /* Right-pad the argument */
  1080.     { "rsearch",    FN_RSEARCH, 0},     /* R-L Search for pattern in string */
  1081. #ifdef OS2
  1082.     { "scrncurx",   FN_SCRN_CX,  0},    /* Screen Cursor X Pos */
  1083.     { "scrncury",   FN_SCRN_CY,  0},    /* Screen Cursor Y Pos */
  1084.     { "scrnstr",    FN_SCRN_STR, 0},    /* Screen String */
  1085. #endif /* OS2 */
  1086.     { "search",     FN_SEARCH, 0},      /* L-R Search for pattern in string */
  1087. #ifndef NOSEXP
  1088.     { "sexpression",FN_SEXP, 0},        /* S-Expression */
  1089. #endif /* NOSEXP */
  1090. #ifdef NT
  1091.     { "shortpathname",FN_SNAME,0},    /* GetShortPathName() */
  1092. #else
  1093.     { "shortpathname",FN_FFN,CM_INV},
  1094. #endif /* NT */
  1095.     { "size",       FN_FS,   0},        /* File size */
  1096. #ifdef COMMENT
  1097.     { "sleep",      FN_SLEEP,0},        /* Sleep for n seconds */
  1098. #endif /* COMMENT */
  1099.     { "span",       FN_SPN,  0},        /* Span - like Snobol */
  1100.     { "split",      FN_SPLIT,0},        /* Split string into words */
  1101.     { "stripb",     FN_STB,  0},        /* Strip enclosing braces/brackets */
  1102.     { "stripn",     FN_STN,  0},        /* Strip n chars */
  1103.     { "stripx",     FN_STX,  0},        /* Strip suffix */
  1104.     { "su",         FN_SUB,  CM_INV|CM_ABR},
  1105.     { "sub",        FN_SUB,  CM_INV|CM_ABR},
  1106.     { "subs",       FN_SUB,  CM_INV|CM_ABR},
  1107.     { "subst",      FN_SUB,  CM_INV|CM_ABR},
  1108.     { "substitute", FN_SUBST,0},        /* Substitute chars */
  1109.     { "substring",  FN_SUB,  0},        /* Extract substring from argument */
  1110.     { "tablelook",  FN_TLOOK,0},        /* Table lookup */
  1111.     { "time",       FN_TIME, 0},        /* Free-format time to hh:mm:ss */
  1112.     { "tod2secs",   FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1113.     { "todtosecs",  FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1114.     { "trim",       FN_TRM,  0},        /* Trim */
  1115.     { "unhexify",   FN_UNH,  0},        /* Unhexify */
  1116.     { "unix2dospath",FN_PC_UD, 0},      /* UNIX to DOS path */
  1117.     { "unixtodospath",FN_PC_UD, CM_INV}, /* UNIX to DOS path */
  1118.     { "upper",      FN_UPP,  0},        /* Return uppercased argument */
  1119.     { "utcdate",    FN_TOGMT,0},        /* Date-time to UTC (GMT) */
  1120.     { "verify",     FN_VER,  0},        /* Verify */
  1121.     { "word",       FN_WORD, 0},        /* Extract a word */
  1122.     { "", 0, 0}
  1123. };
  1124. int nfuncs = (sizeof(fnctab) / sizeof(struct keytab)) - 1;
  1125. #endif /* NOSPL */
  1126.  
  1127. #ifndef NOSPL                           /* Buffer for expansion of */
  1128. #ifdef BIGBUFOK                         /* built-in variables. */
  1129. #define VVBUFL 1024
  1130. #else
  1131. #define VVBUFL 256
  1132. #endif /* BIGBUFOK */
  1133. char vvbuf[VVBUFL+1];
  1134. #endif /* NOSPL */
  1135.  
  1136. struct keytab disptb[] = {              /* Log file disposition */
  1137.     { "append",    1,  0},
  1138.     { "new",       0,  0}
  1139. };
  1140.  
  1141. #ifdef CKFLOAT
  1142.  
  1143. /* I N I T F L O A T  --  Deduce floating-point precision by inspection */
  1144.  
  1145. int fp_rounding = 0;                /* Nonzero if printf("%f") rounds */
  1146. int fp_digits = 0;                  /* Digits of floating point precision */
  1147.  
  1148. #ifdef COMMENT
  1149. /* For looking at internal floating-point representations */
  1150. static char fp_xbuf[128];
  1151. static char *
  1152. tohex(s, n) CHAR * s; int n; {
  1153.     int x;
  1154.     char * p = fp_xbuf;
  1155.     while (n-- > 0) {
  1156.         x = (*s >> 4) & 0x0f;
  1157.         *p++ = hexdigits[x];
  1158.         x = *s++ & 0x0f;
  1159.         *p++ = hexdigits[x];
  1160.     }
  1161.     *p = NUL;
  1162.     return((char *)fp_xbuf);
  1163. }
  1164. #endif /* COMMENT */
  1165.  
  1166. char math_pi[] = "3.1415926535897932384626433832795";
  1167. char math_e[] =  "2.7182818284590452353602874713527";
  1168.  
  1169. VOID
  1170. initfloat() {
  1171.     char * buf = NULL;
  1172.     int i, x, y;
  1173. /*
  1174.   We malloc a big temporary buffer for sprintf() to minimize likelihood of
  1175.   (and damage from) sprintf buffer overflows.  In any case, the only way this
  1176.   could happen would be if sprintf() itself had bugs, since the format
  1177.   descriptor says to cut it off at 250 decimal places.
  1178. */
  1179.     if ((buf = (char *)malloc(4096))) {
  1180.         sprintf(buf,"%0.250f",(10.0 / 3.0));
  1181.         for (i = 2; i < 250 && buf[i] == '3'; i++) ;
  1182.         x = i - 1;
  1183.         debug(F111,"initfloat 10.0/3.0",buf,x);
  1184.         sprintf(buf,"%0.250f",(4.0 / 9.0));
  1185.         for (i = 2; i < 250 && buf[i] == '4'; i++) ;
  1186.         y = i - 1;
  1187.         debug(F111,"initfloat 4.0/9.0",buf,y);
  1188.         fp_digits = (x < y) ? x : y;
  1189.         if (fp_digits < sizeof(math_pi) - 1) {
  1190.             math_pi[fp_digits+1] = NUL;
  1191.             math_e[fp_digits+1] = NUL;
  1192.         }
  1193.         sprintf(buf,"%0.6f",(7.0 / 9.0));
  1194.         if (buf[7] == '8') fp_rounding = 1;
  1195.         debug(F111,"initfloat 7.0/9.0",buf,fp_rounding);
  1196.         debug(F101,"initfloat precision","",fp_digits);
  1197.         free(buf);
  1198.     }
  1199. }
  1200. #endif /* CKFLOAT */
  1201.  
  1202. /*
  1203.   P R E S C A N -- A quick look through the command-line options for
  1204.   items that must be handled before the initialization file is executed.
  1205. */
  1206. #ifdef NT
  1207. extern int StartedFromDialer;
  1208. #endif /* NT */
  1209. #ifdef OS2
  1210. extern int k95stdio;
  1211. unsigned long startflags = 0L;
  1212. #endif /* OS2 */
  1213.  
  1214. static char *
  1215. findinpath(arg) char * arg; {
  1216. #ifdef OS2
  1217.     char * scriptenv, * keymapenv;
  1218.     int len;
  1219. #endif /* OS2 */
  1220. #ifdef DCMDBUF
  1221.     extern char * cmdbuf;
  1222. #else
  1223.     extern char cmdbuf[];
  1224. #endif /* DCMDBUF */
  1225.     char takepath[4096];
  1226.     char * s;
  1227.     int x, z;
  1228.  
  1229.     /* Set up search path... */
  1230. #ifdef OS2
  1231.     char * appdata0 = NULL, *appdata1 = NULL;
  1232. #ifdef NT
  1233.     scriptenv = getenv("K95SCRIPTS");
  1234.     keymapenv = getenv("K95KEYMAPS");
  1235.     makestr(&appdata0,(char *)GetAppData(0));
  1236.     makestr(&appdata1,(char *)GetAppData(1));
  1237. #else /* NT */
  1238.     scriptenv = getenv("K2SCRIPTS");
  1239.     keymapenv = getenv("K2KEYMAPS");
  1240. #endif /* NT */
  1241.     if (!scriptenv)
  1242.       scriptenv = getenv("CK_SCRIPTS");
  1243.     if (!scriptenv)
  1244.       scriptenv = "";
  1245.     if (!keymapenv)
  1246.       keymapenv = getenv("CK_KEYMAPS");
  1247.     if (!keymapenv)
  1248.       keymapenv = "";
  1249.  
  1250.     debug(F110,"startupdir",startupdir,0);
  1251.     debug(F110,"common appdata directory",appdata1,0);
  1252.     debug(F110,"appdata directory",appdata0,0);
  1253.     debug(F110,"inidir",inidir,0);
  1254.     debug(F110,"home",zhome(),0);
  1255.     debug(F110,"exedir",exedir,0);
  1256.  
  1257.     len = strlen(scriptenv) + strlen(keymapenv) + 3*strlen(startupdir)
  1258.         + 3*strlen(inidir) + 3*strlen(zhome()) + 3*strlen(exedir)
  1259.         + (appdata0 ? 3*strlen(appdata0) : 0) 
  1260.         + (appdata1 ? 3*strlen(appdata1) : 0)
  1261.         + 6*strlen("SCRIPTS/") + 6*strlen("KEYMAPS/") + 16;
  1262.  
  1263.     if (len >= 4096) {                  /* SAFE (length is checked) */
  1264.         takepath[0] = '\0';
  1265.         debug(F111,"findinpath error - path length too long","len",len);
  1266.     } else
  1267.       sprintf(takepath,
  1268.               /* semicolon-separated path list */
  1269.     "%s%s%s%s%s;%s%s;%s%s;%s%s%s%s%s%s%s%s%s%s%s%s%s;%s%s;%s%s;%s;%s%s;%s%s",
  1270.               scriptenv,
  1271.               (scriptenv[0] && scriptenv[strlen(scriptenv)-1]==';')?"":";",
  1272.               keymapenv,
  1273.               (keymapenv[0] && keymapenv[strlen(keymapenv)-1]==';')?"":";",
  1274.               startupdir,
  1275.               startupdir, "SCRIPTS/",
  1276.               startupdir, "KEYMAPS/",
  1277.               appdata1 ? appdata1 : "", 
  1278.               appdata1 ? "Kermit 95;" : "",
  1279.               appdata1 ? appdata1 : "",
  1280.               appdata1 ? "Kermit 95/SCRIPTS/;" : "",
  1281.               appdata1 ? appdata1 : "",
  1282.               appdata1 ? "Kermit 95/KEYMAPS/;" : "",
  1283.               appdata0 ? appdata0 : "",
  1284.               appdata0 ? "Kermit 95;" : "",
  1285.               appdata0 ? appdata0 : "",
  1286.               appdata0 ? "Kermit 95/SCRIPTS/;" : "",
  1287.               appdata0 ? appdata0 : "",
  1288.               appdata0 ? "Kermit 95/KEYMAPS/;" : "",
  1289.               inidir,
  1290.               inidir, "SCRIPTS/",
  1291.               inidir, "KEYMAPS/",
  1292.               zhome(),
  1293.               zhome(), "SCRIPTS/",
  1294.               zhome(), "KEYMAPS/",
  1295.               exedir,
  1296.               exedir, "SCRIPTS/",
  1297.               exedir, "KEYMAPS/"
  1298.               );
  1299.     debug(F110,"findinpath takepath",takepath,0);
  1300. #ifdef NT
  1301.     makestr(&appdata0,NULL);
  1302.     makestr(&appdata1,NULL);
  1303. #endif /* NT */
  1304. #else /* not OS2 */
  1305. #ifndef NOSPL
  1306.     z = 1024;                           /* Look in home directory */
  1307.     s = takepath;
  1308.     zzstring("\\v(home)",&s,&z);
  1309. #else
  1310.     takepath[0] = '\0';
  1311. #endif /* NOSPL */
  1312. #endif /* OS2 */
  1313. /*
  1314.   All the logic for searching the take path is in the command parser.
  1315.   So even though we aren't parsing commands, we initialize and call the
  1316.   parser from here, with the purported filename stuffed into the command
  1317.   buffer, followed by some carriage returns to make the parser return.
  1318.   If the file is not found, or otherwise not accessible, the parser prints
  1319.   an appropriate message, and then we just exit.
  1320. */
  1321.     cmdini();                           /* Allocate command buffers etc */
  1322.     cmini(0);                           /* Initialize them */
  1323.     /* Stuff filename into command buf with braces in case of spaces */
  1324.     ckmakmsg(cmdbuf,CMDBL,"{",arg,"}",NULL);
  1325.     debug(F110,"findinpath cmdbuf",cmdbuf,0);
  1326.     ckstrncat(cmdbuf,"\r\r",CMDBL);     /* And some carriage returns */
  1327.     if (cmifip("","",&s,&x,0,takepath,xxstring) < 0)
  1328.       return(NULL);
  1329.     cmres();
  1330.     return(s);
  1331. }
  1332.  
  1333. static int tr_int;                      /* Flag if TRANSMIT interrupted */
  1334.  
  1335. #ifndef MAC
  1336. SIGTYP
  1337. #ifdef CK_ANSIC
  1338. trtrap(int foo)                         /* TRANSMIT interrupt trap */
  1339. #else
  1340. trtrap(foo) int foo;                    /* TRANSMIT interrupt trap */
  1341. #endif /* CK_ANSIC */
  1342. /* trtrap */ {
  1343. #ifdef __EMX__
  1344.     signal(SIGINT, SIG_ACK);
  1345. #endif
  1346.     tr_int = 1;                         /* (Need arg for ANSI C) */
  1347.     SIGRETURN;
  1348. }
  1349. #endif /* MAC */
  1350. #endif /* NOICP */
  1351.  
  1352. #ifdef UNIX
  1353. VOID
  1354. getexedir() {
  1355.     extern char * xarg0;
  1356.   /*
  1357.     Unix provides no standard service for this.  We look in argv[0], and if
  1358.     we're lucky there's a full pathname.  If not we do a PATH search.
  1359.   */
  1360.     if (ckstrchr(xarg0,'/')) {          /* Global copy of argv[0] */
  1361.         int i, k;
  1362.         char * p = NULL;
  1363.         if ((k = ckstrncpy(tmpbuf,xarg0,TMPBUFSIZ-2)) > 0) {
  1364.             p = tmpbuf;
  1365.             /* Convert to fully qualified pathname */
  1366.             if (tmpbuf[0]) if (tmpbuf[0] != '/') {
  1367.                 line[0] = NUL;
  1368.                 zfnqfp(tmpbuf,LINBUFSIZ-2,(char *)line);
  1369.                 if (line[0])
  1370.                   p = line;
  1371.             }
  1372.             if (zchki(p) > -1) {        /* Is the result an existing file? */
  1373.                 k = strlen(p);
  1374.                 for (i = k-1; i > 0; i--) { /* Yes, strip name part */
  1375.                     if (tmpbuf[i] == '/') {
  1376.                         if (i < k-1)
  1377.                           tmpbuf[i+1] = NUL;
  1378.                         break;
  1379.                     }
  1380.                 }
  1381.                 makestr(&exedir,p);     /* Save the result */
  1382.             }
  1383.         }
  1384.     }
  1385.     if (!exedir && xarg0) {             /* Not found? */
  1386.         char * p;
  1387.         p = getenv("PATH");             /* Search the PATH */
  1388.         if (p) {                        /* If there is one... */
  1389.             char * q, * PATH = NULL;
  1390.             int k;
  1391.             makestr(&PATH,p);           /* Pokeable copy of PATH string */
  1392.             if (PATH) {                 /* If malloc succeeded... */
  1393.                 p = PATH;
  1394.                 while (p && *p) {        /* Loop through segments */
  1395.                     q = ckstrchr(p,':'); /* End of this segment */
  1396.                     if (q == p) {       /* Null PATH segment */
  1397.                         p++;            /* Skip over colon */
  1398.                         continue;
  1399.                     }
  1400.                     if (q)              /* If not at end of PATH string */
  1401.                       *q++ = NUL;       /* zero out the colon */
  1402.                     if ((k = ckstrncpy(tmpbuf,p,TMPBUFSIZ)) > 0) {
  1403.                         if (tmpbuf[k-1] != '/') { /* Copy this PATH segment */
  1404.                             tmpbuf[k++] = '/';    /* Append '/' if needed */
  1405.                             tmpbuf[k] = NUL;
  1406.                         }
  1407.                         /* Append the argv[0] value */
  1408.                         if (ckstrncpy(&tmpbuf[k],xarg0,TMPBUFSIZ) > 0) {
  1409.                             if (zchki(tmpbuf) > -1) { /* File exists? */
  1410.                                 tmpbuf[k] = NUL;      /* Yes, we're done */
  1411.                                 zfnqfp(tmpbuf,LINBUFSIZ,(char *)line);
  1412.                                 makestr(&exedir,line);
  1413.                                 break;
  1414.                             }
  1415.                         } else break;
  1416.                     } else break;
  1417.                     p = q;              /* Not found, go to next segment  */
  1418.                 } /* while */
  1419.                 free(PATH);             /* Free PATH copy */
  1420.             }
  1421.         }
  1422.         if (!exedir) {                  /* Still nothing? */
  1423.             if (zchki(xarg0) > -1) {    /* Maybe it's in the current dir */
  1424.                 zfnqfp(zgtdir(),LINBUFSIZ,(char *)line);
  1425.                 makestr(&exedir,line);
  1426.             }
  1427.         }
  1428.     }
  1429.     if (!exedir) {                      /* Still nothing? */
  1430.         makestr(&exedir,"/");           /* Fake it with with root. */
  1431.     }
  1432. }
  1433. #endif /* UNIX */
  1434.  
  1435. int arg_x = 0;
  1436. static int x_prescan = 0;
  1437.  
  1438. /*
  1439.   The argument y once meant something but I can't imagine what so now
  1440.   it's ignored.  (Prior to 22 Aug 98, prescan() was called twice by main(),
  1441.   and the arg differentiated the two calls.  But this caused all sorts of
  1442.   problems & confusion, so I commented out the second call.  This issue might
  1443.   need to be revisited.)
  1444. */
  1445. VOID
  1446. prescan(dummy) int dummy; {             /* Arg is ignored. */
  1447.     extern int howcalled;
  1448.     int yargc; char **yargv;
  1449.     char x;
  1450.     char *yp, *yy;
  1451. #ifdef DEBUG
  1452.     int debcount = 0;
  1453. #endif /* DEBUG */
  1454.     int z;
  1455.  
  1456.     if (x_prescan)                      /* Only run once */
  1457.       return;
  1458.     x_prescan = 1;
  1459.  
  1460.     yargc = xargc;                      /* Make copy of arg vector */
  1461.     yargv = xargv;
  1462.  
  1463. #ifndef NOICP
  1464. #ifdef DCMDBUF
  1465.     if (!kermrc)
  1466.       if (!(kermrc = (char *) malloc(KERMRCL+1)))
  1467.         fatal("prescan: no memory for kermrc");
  1468. #endif /* DCMDBUF */
  1469.     ckstrncpy(kermrc,KERMRC,KERMRCL);   /* Default init file name */
  1470. #endif /* NOICP */
  1471.  
  1472.  
  1473. #ifdef IKSD
  1474.     if (howcalled == I_AM_IKSD)         /* Internet Kermit Service daemon */
  1475.       inserver = 1;                     /* (See inserver section of ckcmai) */
  1476. #endif /* IKSD */
  1477.  
  1478. /* Command line options for Kermit */
  1479.  
  1480. #ifndef NOCMDL
  1481.     if (yargc > 1
  1482.         && *yargv[1] != '-'
  1483.         && (yargv[1][0] != '=')
  1484. #ifdef KERBANG
  1485.         && (yargv[1][0] != '+')
  1486. #endif /* KERBANG */
  1487. #ifdef IKSD
  1488.         && (howcalled != I_AM_IKSD)
  1489. #endif /* IKSD */
  1490.         ) {                             /* Filename as 1st argument */
  1491. #ifndef NOICP
  1492.         char *s;
  1493. #endif /* NOICP */
  1494. #ifndef NOURL
  1495.         extern int haveurl;
  1496.         extern struct urldata g_url;
  1497.         if (urlparse(yargv[1],&g_url)) {
  1498.             if (!ckstrcmp(g_url.svc,"ftp",-1,0) ||
  1499.                 !ckstrcmp(g_url.svc,"ftps",-1,0)) {
  1500.                 haveurl = 1;
  1501.                 howcalled = I_AM_FTP;
  1502.             } else if (!ckstrcmp(g_url.svc,"telnet",-1,0) ||
  1503.                        !ckstrcmp(g_url.svc,"telnets",-1,0)) {
  1504.                 haveurl = 1;
  1505.                 howcalled = I_AM_TELNET;
  1506.             } else if (!ckstrcmp(g_url.svc,"ssh",-1,0)) {
  1507.                 haveurl = 1;
  1508.                 howcalled = I_AM_SSH;
  1509.             } else if (!ckstrcmp(g_url.svc,"iksd",-1,0) ||
  1510.                        !ckstrcmp(g_url.svc,"kermit",-1,0)) {
  1511.                 haveurl = 1;
  1512.                 howcalled = I_AM_KERMIT;
  1513.             } else if (!ckstrcmp(g_url.svc,"http",-1,0) ||
  1514.                        !ckstrcmp(g_url.svc,"https",-1,0)) {
  1515.                 haveurl = 1;
  1516.                 howcalled = I_AM_HTTP;
  1517.             }
  1518.             if (haveurl) {
  1519.                 while (--yargc > 0) {   /* Go through command-line args */
  1520.                     yargv++;            /* looking for -Y and -d */
  1521.                     yp = *yargv+1;
  1522.                     if (**yargv == '-') {
  1523.                         x = *(*yargv+1);
  1524.                         while (x) {
  1525.                             switch (x) {
  1526.                               case 'Y':
  1527.                                 noinit++;
  1528.                                 break;
  1529.                               case 'h':
  1530.                                   noinit = 1;
  1531. #ifdef OS2
  1532.                                   startflags |= 2;    /* No network DLLs */
  1533.                                   startflags |= 4;    /* No TAPI DLLs */
  1534.                                   startflags |= 8;    /* No Security DLLs */
  1535.                                   startflags |= 16;   /* No Zmodem DLLs */
  1536.                                   startflags |= 32;   /* Stdin */
  1537.                                   startflags |= 64;   /* Stdout */
  1538. #endif /* OS2 */
  1539.                                   break;
  1540.                               case 'd': /* = SET DEBUG ON */
  1541. #ifdef DEBUG
  1542.                                 if (debcount++ > 0)
  1543.                                   debtim = 1;
  1544.                                 if (!deblog)
  1545.                                   deblog = debopn("debug.log",0);
  1546. #endif /* DEBUG */
  1547.                                 break;
  1548. #ifdef OS2
  1549.                               case 'W':
  1550.                                 if (*(yp+1))
  1551.                                   fatal("invalid argument bundling after -W");
  1552.                                 yargv++, yargc--;
  1553.                                 if (yargc < 1)
  1554.                                   fatal("Window handle missing");
  1555.                                 hwndDialer = (HWND) atol(*yargv);
  1556.                                 StartedFromDialer = 1;
  1557.                                 yargv++, yargc--;
  1558.                                 KermitDialerID = atol(*yargv) ;
  1559.                                 break;
  1560.                               case '#': /* K95 initialization options */
  1561.                                 if (*(yp+1)) {
  1562.                                     fatal("invalid argument bundling");
  1563.                                 }
  1564.                                 yargv++, yargc--;
  1565.                                 if (yargc < 1)
  1566.                                   fatal("-# argument missing");
  1567.                                 startflags |= atol(*yargv);
  1568.                                 break;
  1569. #endif /* OS2 */
  1570.                             }
  1571.                             if (!yp)
  1572.                               break;
  1573.                             x = *++yp;
  1574.                         }
  1575.                     }
  1576.                 }
  1577.                 return;
  1578.             }
  1579.         }
  1580.         /* after this point non-Kermit personalities must return */
  1581.         switch (howcalled) {
  1582.       case I_AM_KERMIT:
  1583.       case I_AM_IKSD:
  1584.       case I_AM_SSHSUB:
  1585.             break;
  1586.       default:
  1587.             return;
  1588.         }
  1589. #endif /* NOURL */
  1590.  
  1591. #ifndef NOICP
  1592.         /* If it is not a URL that we recognize, try to treat it as a file */
  1593.  
  1594.         if (!isabsolute(yargv[1]))      /* If not absolute */
  1595.           s = findinpath(yargv[1]);     /* Look in PATH */
  1596.         else
  1597.           s = yargv[1];
  1598.         if (!s)
  1599.           doexit(BAD_EXIT,xitsta);
  1600.         zfnqfp(s,CKMAXPATH,cmdfil);     /* In case of CD in file */
  1601.         yargc -= 1;                     /* Skip past the filename */
  1602.         yargv += 1;                     /* Otherwise we'll get an error */
  1603. #endif /* NOICP */
  1604.     }
  1605.  
  1606. #ifndef NOCMDL
  1607. #ifdef NEWFTP
  1608.     if (howcalled == I_AM_FTP) {        /* Kermit's FTP client personality */
  1609.         while (--yargc > 0) {           /* Go through command-line args */
  1610.             yargv++;                    /* looking for -Y and -d */
  1611.             yp = *yargv+1;
  1612.             if (**yargv == '-') {
  1613.                 x = *(*yargv+1);
  1614.                 while (x) {
  1615.                     switch (x) {
  1616.                       case 'Y':
  1617.                         noinit++;
  1618.                         break;
  1619.                       case 'h':
  1620.                         noinit = 1;
  1621. #ifdef OS2
  1622.                         startflags |= 2;    /* No network DLLs */
  1623.                         startflags |= 4;    /* No TAPI DLLs */
  1624.                         startflags |= 8;    /* No Security DLLs */
  1625.                         startflags |= 16;   /* No Zmodem DLLs */
  1626.                         startflags |= 32;   /* Stdin */
  1627.                         startflags |= 64;   /* Stdout */
  1628. #endif /* OS2 */
  1629.                         break;
  1630.                       case 'd':             /* = SET DEBUG ON */
  1631. #ifdef DEBUG
  1632.                         if (debcount++ > 0)
  1633.                           debtim = 1;
  1634.                         if (!deblog)
  1635.                           deblog = debopn("debug.log",0);
  1636. #endif /* DEBUG */
  1637.                         break;
  1638. #ifdef OS2
  1639.                       case 'W':
  1640.                         if (*(yp+1))
  1641.                           fatal("invalid argument bundling after -W");
  1642.                         yargv++, yargc--;
  1643.                         if (yargc < 1)
  1644.                           fatal("Window handle missing");
  1645.                         hwndDialer = (HWND) atol(*yargv);
  1646.                         StartedFromDialer = 1;
  1647.                         yargv++, yargc--;
  1648.                         KermitDialerID = atol(*yargv) ;
  1649.                         break;
  1650.                       case '#':         /* K95 initialization options */
  1651.                         if (*(yp+1)) {
  1652.                             fatal("invalid argument bundling");
  1653.                         }
  1654.                         yargv++, yargc--;
  1655.                         if (yargc < 1)
  1656.                           fatal("-# argument missing");
  1657.                         startflags |= atol(*yargv);
  1658.                         break;
  1659. #endif /* OS2 */
  1660.                     }
  1661.                     if (!yp)
  1662.                       break;
  1663.                     x = *++yp;
  1664.                 }
  1665.             }
  1666.         }
  1667.         return;
  1668.     }
  1669. #endif /* NEWFTP */
  1670. #endif /* NOCMDL */
  1671.  
  1672.     while (--yargc > 0) {               /* Go through command-line args */
  1673.         yargv++;
  1674.         yp = *yargv+1;                  /* Pointer for bundled args */
  1675.         if (**yargv == '=')             /* Same rules as cmdlin()... */
  1676.           return;
  1677.         debug(F110,"prescan *yargv",*yargv,0);
  1678.  
  1679. #ifndef NOICP
  1680. #ifdef KERBANG
  1681.         yy = *yargv;
  1682.         if (!strcmp(yy,"+") || (*yy == '+' && *(yy+1) < (char)33)) {
  1683.             char * s;
  1684.             yargv++;
  1685.             noinit = 1;
  1686.             if (!*yargv)
  1687.               return;
  1688.             cfilef = 1;
  1689.             s = findinpath(*yargv);
  1690.             if (s) {
  1691.                 zfnqfp(s,CKMAXPATH,cmdfil);
  1692.                 return;
  1693.             } else
  1694.               doexit(BAD_EXIT,xitsta);
  1695.         }
  1696. #endif /* KERBANG */
  1697. #endif /* NOICP */
  1698.         if (!strcmp(*yargv,"--"))       /* getopt() conformance */
  1699.           return;
  1700. #ifdef VMS
  1701.         else if (**yargv == '/')
  1702.           continue;
  1703. #endif /* VMS */
  1704.         else if (**yargv == '-') {      /* Got an option (begins with dash) */
  1705.             x = *(*yargv+1);            /* Get option letter */
  1706.             while (x) {                 /* Allow for bundled options */
  1707.                 debug(F000,"prescan arg","",x);
  1708.                 switch (x) {
  1709. #ifndef NOICP
  1710.                   case '+':
  1711.                   case '-':
  1712.                     if (doxarg(yargv,1) < 0) {
  1713.                         fatal("Extended argument error");
  1714.                     }
  1715.                     yargv++, yargc--;
  1716.                     yp = *yargv;
  1717.                     break;
  1718. #endif /* NOICP */
  1719.  
  1720.                   case '7':             /* Undocumented... */
  1721.                     sstelnet = 1;       /* (because it doesn't work) */
  1722.                     break;
  1723. #ifdef IKSD
  1724.                   case 'A': {
  1725.                       char * p;
  1726.                       inserver = 1;     /* Flag that we are doing this */
  1727.                       srvcdmsg = 2;     /* Preset this */
  1728.                       /* See inserver section of ckcmai.c for more settings */
  1729. #ifdef OS2
  1730.                       if (*(yp+1)) {
  1731.                           fatal("invalid argument bundling after -A");
  1732.                       }
  1733. #ifdef NT
  1734.                       /* Support for Pragma Systems Telnet/Terminal Servers */
  1735.                       p = getenv("PRAGMASYS_INETD_SOCK");
  1736.                       if (p && atoi(p) != 0) {
  1737.                           ttname[0] = '$';
  1738.                           ckstrncpy(&ttname[1],p,TTNAMLEN-1);
  1739.                           break;
  1740.                       }
  1741. #endif /* NT */
  1742.                       yargv++, yargc--;
  1743.                       if (yargc < 1 || **yargv == '-') {
  1744.                           fatal("-A argument missing");
  1745.                       } else {
  1746.                           ttname[0] = '$';
  1747.                           ckstrncpy(&ttname[1],*yargv,TTNAMLEN-1);
  1748.                       }
  1749. #endif /* OS2 */
  1750.                       break;
  1751.                   }
  1752. #endif /* IKSD */
  1753.  
  1754. #ifdef OS2
  1755.                   case 'W':
  1756.                     if (*(yp+1))
  1757.                       fatal("invalid argument bundling after -W");
  1758.                     yargv++, yargc--;
  1759.                     if (yargc < 1)
  1760.                       fatal("Window handle missing");
  1761. #ifdef COMMENT
  1762.                     if (dummy) {
  1763.                         yargv++, yargc--;
  1764.                         break;
  1765.                     } else {
  1766. #endif /* COMMENT */
  1767.                         hwndDialer = (HWND) atol(*yargv);
  1768.                         StartedFromDialer = 1;
  1769.                         yargv++, yargc--;
  1770.                         KermitDialerID = atol(*yargv) ;
  1771. #ifdef COMMENT
  1772.                     }
  1773. #endif /* COMMENT */
  1774.                     break;
  1775.  
  1776.                   case '#':             /* K95 initialization options */
  1777.                     if (*(yp+1)) {
  1778.                         fatal("invalid argument bundling");
  1779.                     }
  1780.                     yargv++, yargc--;
  1781.                     if (yargc < 1)
  1782.                       fatal("-# argument missing");
  1783.                     startflags |= atol(*yargv);
  1784.                     break;
  1785. #endif /* OS2 */
  1786.  
  1787. #ifndef NOSPL
  1788.                   case 'M':                             /* My User Name */
  1789.                     if (*(yp+1)) {
  1790.                         fatal("invalid argument bundling");
  1791.                     }
  1792.                     yargv++, yargc--;
  1793.                     if ((yargc < 1) || (**yargv == '-')) {
  1794.                         fatal("missing username");
  1795.                     }
  1796.                     if ((int)strlen(*yargv) > UIDBUFLEN) {
  1797.                         fatal("username too long");
  1798.                     }
  1799. #ifdef COMMENT
  1800. /*
  1801.   This can't work.  uidbuf is overwritten in sysinit() which has yet to be
  1802.   called.  This cannot be set in prescan().
  1803. */
  1804. #ifdef IKSD
  1805.                     if (!inserver)
  1806. #endif /* IKSD */
  1807.                       ckstrncpy(uidbuf,*yargv,UIDBUFLEN);
  1808. #endif /* COMMENT */
  1809.                     break;
  1810. #endif /* NOSPL */
  1811.                   case 'R':             /* Remote-only advisory */
  1812. #ifdef CK_IFRO
  1813.                     remonly = 1;
  1814. #endif /* CK_IFRO */
  1815.                     break;
  1816.                   case 'S':             /* STAY */
  1817.                     stayflg = 1;
  1818.                     break;
  1819.                   case 'h':
  1820.                     noinit = 1;
  1821. #ifdef OS2
  1822.                     startflags |= 2;    /* No network DLLs */
  1823.                     startflags |= 4;    /* No TAPI DLLs */
  1824.                     startflags |= 8;    /* No Security DLLs */
  1825.                     startflags |= 16;   /* No Zmodem DLLs */
  1826.                     startflags |= 32;   /* Stdin */
  1827.                     startflags |= 64;   /* Stdout */
  1828. #endif /* OS2 */
  1829.                     break;
  1830. #ifndef NOICP
  1831.                   case 'Y':             /* No init file */
  1832.                     noinit = 1;
  1833.                     break;
  1834. #endif /* NOICP */
  1835.                   case 'd':             /* = SET DEBUG ON */
  1836. #ifdef DEBUG
  1837.                     if (debcount++ > 0)
  1838.                       debtim = 1;
  1839.                     if (!deblog)
  1840.                       deblog = debopn("debug.log",0);
  1841. #endif /* DEBUG */
  1842.                     break;
  1843.  
  1844.                   case 'x':             /* Server */
  1845.                     arg_x = 1;          /* Note in advance */
  1846.                     break;
  1847. #ifndef NOICP
  1848.                   case 'y':             /* Alternative init file */
  1849.                     noinit = 0;
  1850.                     yargv++, yargc--;
  1851.                     if (yargc < 1) fatal("missing name in -y");
  1852.                     /* Replace init file name */
  1853.                     ckstrncpy(kermrc,*yargv,KERMRCL);
  1854.                     rcflag = 1;         /* Flag that this has been done */
  1855.                     debug(F111,"prescan kermrc",kermrc,rcflag);
  1856.                     break;
  1857. #endif /* NOICP */
  1858.                   case 'z':             /* = SET BACKGROUND OFF */
  1859.                     bgset = 0;
  1860.                     backgrd = 0;
  1861. #ifdef VMS
  1862.                     batch = 0;
  1863. #endif /* VMS */
  1864.                     break;
  1865.  
  1866.                   case 'B':             /* Force background (batch) */
  1867.                     bgset = 1;
  1868.                     backgrd = 1;
  1869. #ifdef VMS
  1870.                     batch = 1;
  1871. #endif /* VMS */
  1872.                     break;
  1873.  
  1874. #ifdef CK_NETBIOS
  1875.                   case 'N':
  1876.                     {
  1877.                         int n ;
  1878.                         yargv++, yargc--;
  1879. #ifdef COMMENT
  1880.                         if (y)
  1881.                           break;
  1882. #endif /* COMMENT */
  1883.                         if (strlen(*yargv) != 1 || (*yargv)[0] == 'X') {
  1884.                             NetBiosAdapter = -1;
  1885.                         } else {
  1886.                             n = atoi(*yargv);
  1887.                             if (n >= 0 && n <= 9)
  1888.                               NetBiosAdapter = n;
  1889.                             else
  1890.                               NetBiosAdapter = -1;
  1891.                         }
  1892.                     }
  1893.                     break;
  1894. #endif /* CK_NETBIOS */
  1895.                   default:
  1896.                     break;
  1897.                 }
  1898.                 if (!yp)
  1899.                   break;
  1900.                 x = *++yp;              /* See if options are bundled */
  1901.             }
  1902.         }
  1903.     }
  1904. #endif /* NOCMDL */
  1905. }
  1906.  
  1907. /*  G E T T C S  --  Get Transfer (Intermediate) Character Set  */
  1908.  
  1909. /*
  1910.   Given two file character sets, this routine picks out the appropriate
  1911.   "transfer" character set to use for translating between them.
  1912.   The transfer character set number is returned.
  1913.  
  1914.   Translation between two file character sets is done, for example,
  1915.   by the CONNECT, TRANSMIT, and TRANSLATE commands.
  1916.  
  1917.   Translation between Kanji character sets is not yet supported.
  1918. */
  1919. int
  1920. gettcs(cs1,cs2) int cs1, cs2; {
  1921. #ifdef NOCSETS                          /* No character-set support */
  1922.     return(0);                          /* so no translation */
  1923. #else
  1924.     int tcs = TC_TRANSP;
  1925. #ifdef KANJI
  1926. /* Kanji not supported yet */
  1927.     if (fcsinfo[cs1].alphabet == AL_JAPAN ||
  1928.         fcsinfo[cs2].alphabet == AL_JAPAN )
  1929.       tcs = TC_TRANSP;
  1930.     else
  1931. #endif /* KANJI */
  1932. #ifdef CYRILLIC
  1933. /*
  1934.   I can't remember why we don't test both sets here, but I think there
  1935.   must have been a reason...
  1936. */
  1937.       if (fcsinfo[cs2].alphabet == AL_CYRIL)
  1938.         tcs = TC_CYRILL;
  1939.       else
  1940. #endif /* CYRILLIC */
  1941. #ifdef HEBREW
  1942.           if (fcsinfo[cs1].alphabet == AL_HEBREW ||
  1943.               fcsinfo[cs2].alphabet == AL_HEBREW )
  1944.             tcs = TC_HEBREW;
  1945.           else
  1946. #endif /* HEBREW */
  1947. #ifdef GREEK
  1948.           if (fcsinfo[cs1].alphabet == AL_GREEK ||
  1949.               fcsinfo[cs2].alphabet == AL_GREEK )
  1950.             tcs = TC_GREEK;
  1951.           else
  1952. #endif /* GREEK */
  1953.  
  1954.             /* Roman sets ... */
  1955.  
  1956. #ifdef LATIN2                           /* East European */
  1957.         if (cs1 == FC_2LATIN  || cs2 == FC_2LATIN || /* Latin-2 */
  1958.             cs1 == FC_CP852   || cs2 == FC_CP852  || /* CP852 */
  1959.             cs1 == FC_CP1250  || cs2 == FC_CP1250 || /* Windows Latin-2 */
  1960.             cs1 == FC_MAZOVIA || cs2 == FC_MAZOVIA)  /* Polish Mazovia */
  1961.           tcs = TC_2LATIN;
  1962.         else
  1963. #endif /* LATIN2 */
  1964.                                         /* West European Euro-aware */
  1965.           if (cs1 == FC_CP858 || cs1 == FC_9LATIN ||
  1966.               cs2 == FC_CP858 || cs2 == FC_9LATIN)
  1967.             tcs = TC_9LATIN;
  1968.           else                          /* Traditional West European */
  1969.             tcs = TC_1LATIN;
  1970.     return(tcs);
  1971. #endif /* NOCSETS */
  1972. }
  1973.  
  1974. #ifndef NOLOCAL
  1975. /*  D O C O N E C T  --  Do the connect command  */
  1976. /*
  1977.   q = 0 means issue normal informational message about how to get back, etc.
  1978.   q != 0 means to skip the message.
  1979. */
  1980.  
  1981. int
  1982. doconect(q,async) int q, async; {
  1983.     int x;                              /* Return code */
  1984. #ifdef CK_AUTODL
  1985.     extern CHAR ksbuf[];
  1986. #endif /* CK_AUTODL */
  1987. #ifndef NOKVERBS                        /* Keyboard macro material */
  1988.     extern int keymac, keymacx;
  1989. #endif /* NOKVERBS */
  1990.     extern int justone, adl_err;
  1991.     int qsave;                          /* For remembering "quiet" value */
  1992. #ifdef OS2
  1993.     extern int term_io;
  1994.     extern int display_demo;
  1995.     int term_io_save;
  1996. #ifdef KUI
  1997.     extern int kui_async;
  1998. #endif /* KUI */
  1999. #endif /* OS2 */
  2000.     int is_tn = 0;
  2001.  
  2002. #ifdef IKSD
  2003.     if (inserver) {
  2004.         if (!quiet)
  2005.           printf("?Sorry, IKSD cannot CONNECT.\r\n");
  2006.         return(success = 0);
  2007.     }
  2008. #endif /* IKSD */
  2009.  
  2010.     is_tn =
  2011. #ifdef TNCODE
  2012.       (local && network && IS_TELNET()) || (!local && sstelnet)
  2013. #else
  2014.         0
  2015. #endif /* TNCODE */
  2016.           ;
  2017. /*
  2018.   Saving, changing, and restoring the global "quiet" variable around calls
  2019.   to conect() to control whether the verbose CONNECT message is printed is
  2020.   obviously less elegant than passing a parameter to conect(), but we do it
  2021.   this way to avoid the need to change all of the ck?con.c modules.  NOTE:
  2022.   it is important to restore the value immediately upon return in case there
  2023.   is an autodownload or APC.
  2024. */
  2025.     qsave = quiet;                      /* Save it */
  2026.     if (!quiet && q > -1)
  2027.       quiet = q;                        /* Use argument temporarily */
  2028.     conres();                           /* Put console back to normal */
  2029.     debug(F101,"doconect justone 1","",justone);
  2030. #ifdef CK_AUTODL
  2031.     ksbuf[0] = NUL;                     /* Autodownload packet buffer */
  2032. #endif /* CK_AUTODL */
  2033. #ifdef OS2
  2034.     display_demo = 1;                   /* Remember to display demo */
  2035. #endif /* OS2 */
  2036.  
  2037. #ifdef IKS_OPTION
  2038.     if (is_tn && TELOPT_U(TELOPT_KERMIT) && ttchk() >= 0
  2039. #ifdef OS2
  2040.        && !viewonly
  2041. #endif /* OS2 */
  2042.         ) {
  2043.         /* If the remote side is in a state of IKS START-SERVER    */
  2044.         /* we request that the state be changed.  We will detect   */
  2045.         /* a failure to adhere to the request when we call ttinc() */
  2046.         if (!iks_wait(KERMIT_REQ_STOP,0) && !tcp_incoming) {
  2047.             if (!quiet) {
  2048.                 printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2049.                 printf(
  2050. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2051.                 printf(" SEND and GET for file transfer.\r\n");
  2052.                 printf(" REMOTE commands for file management.\r\n");
  2053.                 printf(" FINISH to terminate Client/Server mode.\r\n");
  2054.                 printf(" BYE to terminate and close connection.\r\n");
  2055.                 printf(" REMOTE HELP for additional information.\r\n\r\n");
  2056.             }
  2057.             quiet = qsave;
  2058.             return(0);      /* Failure */
  2059.         }
  2060.     }
  2061.  
  2062.     /* Let our peer know our state. */
  2063. #ifdef CK_AUTODL
  2064.     if (is_tn && TELOPT_ME(TELOPT_KERMIT)
  2065. #ifdef OS2
  2066.         && !viewonly
  2067. #endif /* OS2 */
  2068.          ) {
  2069.         if (autodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2070.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  2071.         } else if (!autodl && TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2072.             tn_siks(KERMIT_STOP);
  2073.         }
  2074.     }
  2075. #else /* CK_AUTODL */
  2076.     if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2077.         tn_siks(KERMIT_STOP);
  2078.     }
  2079. #endif /* CK_AUTODL */
  2080. #endif /* IKS_OPTION */
  2081.  
  2082.     debug(F101,"doconect flow","",flow);
  2083. #ifdef OS2
  2084.     debug(F101,"doconect async","",async);
  2085. #ifdef KUI
  2086.     if (kui_async)
  2087.       async = 1;;
  2088. #endif /* KUI */
  2089.     x = conect(async);                  /* Connect the first time */
  2090. #else /* OS2 */
  2091.     x = conect();
  2092. #endif /* OS2 */
  2093.     debok = 1;
  2094.  
  2095. #ifdef IKS_OPTION
  2096.     if (TELOPT_U(TELOPT_KERMIT) &&
  2097.         TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  2098.         !tcp_incoming && !quiet && ttchk() >= 0
  2099.         ) {
  2100.         printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2101.         printf(
  2102. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2103.         printf(" SEND and GET for file transfer.\r\n");
  2104.         printf(" REMOTE commands for file management.\r\n");
  2105.         printf(" FINISH to terminate Client/Server mode.\r\n");
  2106.         printf(" BYE to terminate and close connection.\r\n");
  2107.         printf(" REMOTE HELP for additional information.\r\n\r\n");
  2108.     }
  2109. #endif /* IKS_OPTION */
  2110.  
  2111.     quiet = qsave;                      /* Restore "quiet" value */
  2112.     debug(F101,"doconect justone 2","",justone);
  2113.  
  2114. #ifdef NETCONN
  2115.     if (network && tn_exit && ttchk() < 0)
  2116.       doexit(GOOD_EXIT,xitsta);         /* Exit with good status */
  2117. #endif /* NETCONN */
  2118.  
  2119. #ifdef OS2ORUNIX
  2120.     /* Exit on disconnect if the port is not open or carrier detect */
  2121.     if (exitonclose && (ttchk() < 0))
  2122.       doexit(GOOD_EXIT,xitsta);
  2123. #endif /* OS2ORUNIX */
  2124.  
  2125. #ifdef CKCONINTB4CB
  2126.     /* The order makes a difference in HP-UX 8.00. */
  2127.     /* The other order makes it think it's in the background when it */
  2128.     /* returns from CONNECT (Apr 1999). */
  2129.     setint();
  2130.     concb((char)escape);                /* Restore console for commands */
  2131. #else
  2132.     /* This is how it has always been so better leave it */
  2133.     /* this way for all non-HP-UX-8.00 builds. */
  2134.     concb((char)escape);                /* Restore console for commands */
  2135.     setint();
  2136. #endif /* CKCONINTB4CB */
  2137.  
  2138. #ifdef OS2
  2139.     if (!async) {
  2140.         term_io_save = term_io;         /* Disable I/O by emulator */
  2141.         term_io = 0;
  2142. #endif /* OS2 */
  2143.  
  2144. #ifdef CK_APC
  2145. /*
  2146.   If an APC command was received during CONNECT mode, we define it now
  2147.   as a macro, execute the macro, and then return to CONNECT mode.
  2148.   We do this in a WHILE loop in case additional APCs come during subsequent
  2149.   CONNECT sessions.
  2150. */
  2151.         debug(F101,"doconect apcactive","",apcactive);
  2152.         debug(F101,"doconect success","",success);
  2153.  
  2154.         while (x > 0 && (apcactive == APC_LOCAL ||
  2155.                          (apcactive == APC_REMOTE && apcstatus != APC_OFF))) {
  2156.             debug(F101,"doconect justone 3","",justone);
  2157.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  2158.                 debug(F110,"doconect about to execute APC",apcbuf,0);
  2159.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  2160.                 delmac("_apc_commands",1);
  2161. #ifdef DEBUG
  2162.             } else {
  2163.                 debug(F100,"doconect APC in progress","",0);
  2164. #endif /* DEBUG */
  2165.             }
  2166.             debug(F101,"doconect apcactive after domac","",apcactive);
  2167.             if (!apcactive) {               /* In case CLEAR APC was in APC */
  2168.                 debug(F101,"doconect quit APC loop: apcactive","",apcactive);
  2169.                 break;
  2170.             }
  2171.             /* Also don't reconnect if autodownload failed - very confusing! */
  2172.             /* Let them view the local screen to see what happened. - fdc */
  2173.  
  2174.             /* This should be conditional.  If someone is relying on the */
  2175.             /* connect mode autodownload for the kermit server to use with */
  2176.             /* a remotely executed script we should be able to return to */
  2177.             /* connect mode on the failure.  What we really need to do is */
  2178.             /* report the status of the transfer and then return to CONNECT. */
  2179.             /* In unix this would simply be a printf(), but in K95 it could */
  2180.             /* use a popup dialog to report the status. - Jeff */
  2181.  
  2182. #ifndef NOXFER
  2183.             debug(F101,"doconect xferstat","",xferstat);
  2184.             if (apcactive == APC_LOCAL && !xferstat && adl_err != 0) {
  2185.                 debug(F101,"doconect quit APC loop: xferstat","",xferstat);
  2186.                 apcactive = APC_INACTIVE;
  2187.                 break;
  2188.             }
  2189. #endif /* NOXFER */
  2190. #ifdef OS2
  2191.             msleep(250);
  2192. #endif /* OS2 */
  2193.             debug(F101,"doconect justone 4","",justone);
  2194.             qsave = quiet;              /* Do this again... */
  2195.             if (!quiet && q > -1)
  2196.               quiet = q;
  2197. #ifdef CK_AUTODL
  2198.             ksbuf[0] = NUL;
  2199. #endif /* CK_AUTODL */
  2200. #ifdef IKS_OPTION
  2201. #ifdef CK_AUTODL
  2202.             if (is_tn &&
  2203.                 TELOPT_ME(TELOPT_KERMIT) &&
  2204.                 !TELOPT_SB(TELOPT_KERMIT).kermit.me_start &&
  2205.                 autodl
  2206. #ifdef CK_APC
  2207.                 && !apcactive
  2208. #endif /* CK_APC */
  2209. #ifdef OS2
  2210.                 && !viewonly
  2211. #endif /* OS2 */
  2212.                 ) {
  2213.                 tn_siks(KERMIT_START);  /* Send Kermit-Server Start */
  2214.             }
  2215. #endif /* CK_AUTODL */
  2216. #endif /* IKS_OPTION */
  2217. #ifndef OS2
  2218.             x = conect();               /* Re-CONNECT. */
  2219. #else /* OS2 */
  2220.             x = conect(0);
  2221.             term_io = term_io_save;
  2222. #endif /* OS2 */
  2223.             debok = 1;
  2224.             quiet = qsave;
  2225.             debug(F101,"doconect justone 5","",justone);
  2226. #ifdef NETCONN
  2227.             if (network && ttchk() < 0) {
  2228.                 if (tn_exit || exitonclose)
  2229.                   doexit(GOOD_EXIT,xitsta);
  2230.                 else
  2231.                   break;
  2232.             }
  2233. #endif /* NETCONN */
  2234.  
  2235. #ifdef OS2ORUNIX
  2236.             /* If connection dropped */
  2237.             if (ttchk() < 0) {
  2238.                 concb((char)escape);    /* Restore console. */
  2239.                 if (exitonclose)
  2240.                   doexit(GOOD_EXIT,xitsta);
  2241.                 else
  2242.                   break;
  2243.             }
  2244. #endif /* OS2ORUNIX */
  2245.         } /* Loop back for more. */
  2246. #endif /* CK_APC */
  2247.  
  2248. #ifndef NOKVERBS
  2249.         if ((keymac > 0) && (keymacx > -1)) { /* Executing a keyboard macro? */
  2250.             /* Set up the macro and return */
  2251.             /* Do not clear the keymac flag */
  2252.             return(dodo(keymacx,NULL,CF_KMAC|cmdstk[cmdlvl].ccflgs));
  2253.         }
  2254. #endif /* NOKVERBS */
  2255. #ifdef OS2
  2256.         term_io = term_io_save;
  2257.     } /* if (!async) */
  2258. #endif /* OS2 */
  2259.  
  2260. #ifdef CKCONINTB4CB
  2261.     /* The order makes a difference in HP-UX 8.00. */
  2262.     /* The other order makes it think it's in the background when it */
  2263.     /* returns from CONNECT (Apr 1999). */
  2264.     setint();
  2265.     concb((char)escape);                /* Restore console for commands */
  2266. #else
  2267.     /* This is how it has always been so better leave it */
  2268.     /* this way for all non-HP-UX-8.00 builds. */
  2269.     concb((char)escape);                /* Restore console for commands */
  2270.     setint();
  2271. #endif /* CKCONINTB4CB */
  2272. #ifdef OS2
  2273.     if (!async)
  2274. #endif /* OS2 */
  2275.       what = W_COMMAND;                 /* Back in command mode. */
  2276.     return(x);                          /* Done. */
  2277. }
  2278. #endif /* NOLOCAL */
  2279.  
  2280. #ifndef NOICP
  2281. #ifdef COMMENT
  2282. /*
  2283.   It seemed that this was needed for OS/2, in which \v(cmdfile) and other
  2284.   file-oriented variables or functions can return filenames containing
  2285.   backslashes, which are subsequently interpreted as quotes rather than
  2286.   directory separators (e.g. see commented section for VN_CMDF below).
  2287.   But the problem can't be cured at this level.  Example:
  2288.  
  2289.     type \v(cmdfile)
  2290.  
  2291.   Without doubling, the filename is parsed correctly, but then when passed
  2292.   to UNIX 'cat' through the shell, the backslash is removed, and then cat
  2293.   can't open the file.  With doubling, the filename is not parsed correctly
  2294.   and the TYPE command fails immediately with a "file not found" error.
  2295. */
  2296. /*
  2297.   Utility routine to double all backslashes in a string.
  2298.   s1 is pointer to source string, s2 is pointer to destination string,
  2299.   n is length of destination string, both NUL-terminated.
  2300.   Returns 0 if OK, -1 if not OK (destination string too short).
  2301. */
  2302. int
  2303. dblbs(s1,s2,n) char *s1, *s2; int n; {
  2304.     int i = 0;
  2305.     while (*s1) {
  2306.         if (*s1 == '\\') {
  2307.             if (++i > n) return(-1);
  2308.             *s2++ = '\\';
  2309.         }
  2310.         if (++i > n) return(-1);
  2311.         *s2++ = *s1++;
  2312.     }
  2313.     *s2 = NUL;
  2314.     return(0);
  2315. }
  2316. #endif /* COMMENT */
  2317.  
  2318. char *
  2319. gmdmtyp() {                             /* Get modem type */
  2320. #ifndef NODIAL
  2321.     int i, x;
  2322.  
  2323.     debug(F111,"gmdmtyp","mdmtyp",mdmtyp);
  2324.     debug(F111,"gmdmtyp","mdmsav",mdmsav);
  2325.  
  2326.     x = mdmtyp;
  2327.     if (x < 0)                          /* In case of network dialing */
  2328.       x = mdmsav;
  2329.     if (x < 1)
  2330.       return("none");
  2331.     else
  2332.       for (i = 0; i < nmdm; i++)
  2333.         if ((mdmtab[i].kwval == x) && (mdmtab[i].flgs == 0))
  2334.           return(mdmtab[i].kwd);
  2335. #endif /* NODIAL */
  2336.     return("none");
  2337. }
  2338.  
  2339. #ifndef NOXMIT
  2340. #ifndef NOLOCAL
  2341. /*  T R A N S M I T  --  Raw upload  */
  2342.  
  2343. /*  Obey current line, duplex, parity, flow, text/binary settings. */
  2344. /*  Returns 0 upon apparent success, 1 on obvious failure.  */
  2345.  
  2346. /***
  2347.  Things to add:
  2348.  . Make both text and binary mode obey set file bytesize.
  2349.  . Maybe allow user to specify terminators other than CR?
  2350.  . Maybe allow user to specify prompts other than single characters?
  2351.  . Make STATISTICS also work for TRANSMIT.
  2352.  . If TRANSMIT is done without echo, make some kind of (optional) display.
  2353.  . Make the same optimization for binary-mode transmit that was done for
  2354.    text-mode (in the no-echo / no-prompt / no-pause case).
  2355. ***/
  2356.  
  2357. /*  T R A N S M I T  --  Raw upload  */
  2358.  
  2359. /*  s is the filename, t is the turnaround (prompt) character  */
  2360.  
  2361. /*
  2362.   Maximum number of characters to buffer.
  2363.   Must be less than LINBUFSIZ
  2364. */
  2365. #ifdef OS2
  2366. #define XMBUFS 4096                     /* For compatibility with XYZmodem */
  2367. #else /* OS2 */
  2368. #define XMBUFS 1024
  2369. #endif /* OS2 */
  2370.  
  2371. #ifdef TNCODE
  2372. #ifndef IAC
  2373. #define IAC 255
  2374. #endif /* IAC */
  2375. #endif /* TNCODE */
  2376.  
  2377. #define OUTXBUFSIZ 15
  2378. static CHAR inxbuf[OUTXBUFSIZ+1];       /* Host-to-screen expansion buffer */
  2379. static int inxcount = 0;                /* and count */
  2380. static CHAR outxbuf[OUTXBUFSIZ+1];      /* Keyboard-to-host expansion buf */
  2381. static int outxcount = 0;               /* and count */
  2382.  
  2383. /*  T R A N S M I T  --  Unguarded non-protocol file transmission  */
  2384. /*
  2385.   Call with:
  2386.     char * s:   Name of file to transmit.
  2387.     char t:     Turnaround char for text-mode transmission (normally LF).
  2388.     int xlate:  nonzero = charset translation for text-mode xfer, 0 = skip.
  2389.     int binary: nonzero = transmit in binary mode, 0 = in text mode.
  2390. */
  2391. #define XBBUFSIZ 252                    /* For binary blasting */
  2392. static CHAR xbbuf[XBBUFSIZ+4];
  2393.  
  2394. int
  2395. #ifdef CK_ANSIC
  2396. transmit(char * s, char t, int xlate, int binary, int xxecho)
  2397. #else
  2398. transmit(s,t,xlate,binary,xxecho) char *s; char t; int xlate, binary, xxecho;
  2399. #endif /* CK_ANSIC */
  2400. /* transmit */ {
  2401. #ifdef MAC
  2402.     extern char sstate;
  2403.     int count = 100;
  2404. #else
  2405.     int count = 0;
  2406. #ifdef OS2
  2407. #ifdef NT
  2408.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  2409. #else /* NT */
  2410.     SIGTYP (* volatile oldsig)(int);
  2411. #endif /* NT */
  2412.  
  2413. #else /* OS2 */
  2414.     SIGTYP (* oldsig)();
  2415. #endif /* OS2 */
  2416. #endif /* MAC */
  2417.     int eof = 0;                        /* End of File flag */
  2418.     int eol = 0;                        /* End of Line flag */
  2419.     int rc = 1;                         /* Return code. 0=fail, 1=succeed. */
  2420.     int myflow;                         /* Local copy of global flow... */
  2421.     int is_tn = 0;                      /* Do Telnet negotiations */
  2422.     int xbufsiz = XMBUFS;               /* Size of TRANSMIT buffer */
  2423.     int x, y, c, i;                     /* Int workers... */
  2424.     int control = 0;                    /* Echo loop control */
  2425.     long nbytes = 0;                    /* File byte count */
  2426.     long zz;                            /* Long worker */
  2427.     char *p;                            /* Char * worker */
  2428.  
  2429. #ifdef PIPESEND
  2430.     extern int pipesend;
  2431. #endif /* PIPESEND */
  2432.  
  2433. #ifndef NOCSETS
  2434.     int tcs = TC_TRANSP;                /* Intermediate (xfer) char set */
  2435.     int langsv = L_USASCII;             /* Save current language */
  2436.     int unicode = 0;
  2437.     int tcssize = 0;
  2438.  
  2439. #ifdef CK_ANSIC /* ANSI C prototypes... */
  2440.     CHAR (*sxo)(CHAR);
  2441.     CHAR (*rxo)(CHAR);
  2442.     CHAR (*sxi)(CHAR);
  2443.     CHAR (*rxi)(CHAR);
  2444. #else /* Not ANSI C... */
  2445.     CHAR (*sxo)();
  2446.     CHAR (*rxo)();
  2447.     CHAR (*sxi)();
  2448.     CHAR (*rxi)();
  2449. #endif /* CK_ANSIC */
  2450. #ifdef UNICODE
  2451.     union ck_short uc;
  2452.     int bomorder = 0;
  2453. #ifdef CK_ANSIC
  2454.     extern int (*xl_ufc[MAXFCSETS+1])(USHORT);  /* Unicode to FCS */
  2455.     extern USHORT (*xl_fcu[MAXFCSETS+1])(CHAR); /* FCS to Unicode */
  2456.     extern int (*xuf)(USHORT);
  2457.     extern USHORT (*xfu)(CHAR);
  2458. #else
  2459.     extern int (*xl_ufc[MAXFCSETS+1])();
  2460.     extern USHORT (*xl_fcu[MAXFCSETS+1])();
  2461.     extern int (*xuf)();
  2462.     extern USHORT (*xfu)();
  2463. #endif /* CK_ANSIC */
  2464. #endif /* UNICODE */
  2465. #endif /* NOCSETS */
  2466.  
  2467.     debug(F101,"xmit t","",t);
  2468.     debug(F101,"xmit xlate","",xlate);
  2469.     debug(F101,"xmit binary","",binary);
  2470.  
  2471. #ifdef PIPESEND
  2472.     if (pipesend) {
  2473.         if (nopush) return(-2);
  2474.         if (zxcmd(ZIFILE,s) < 1) {
  2475.             printf("?Can't start command: %s\n",s);
  2476.             return(0);
  2477.         }
  2478.     } else
  2479. #endif /* PIPESEND */
  2480.     if (zopeni(ZIFILE,s) == 0) {        /* Open the file to be transmitted */
  2481.         printf("?Can't open file %s\n",s);
  2482.         return(0);
  2483.     }
  2484.     x = -1;                             /* Open the communication channel */
  2485.     if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) {  /* (no harm if already open) */
  2486.         printf("Can't open device %s\n",ttname);
  2487.         return(0);
  2488.     }
  2489.     zz = x ? speed : -1L;
  2490.     if (binary) {                       /* Binary file transmission */
  2491.         myflow = (flow == FLO_XONX) ? FLO_NONE : flow;
  2492.  
  2493.         if (ttvt(zz,myflow) < 0) {      /* So no Xon/Xoff! */
  2494.             printf("Can't condition line\n");
  2495.             return(0);
  2496.         }
  2497.     } else {
  2498.         if (ttpkt(zz,flow,parity) < 0) { /* Put the line in "packet mode" */
  2499.             printf("Can't condition line\n"); /* so Xon/Xoff will work, etc. */
  2500.             return(0);
  2501.         }
  2502.     }
  2503.     is_tn =
  2504. #ifdef TNCODE
  2505.       (local && network && IS_TELNET()) || (!local && sstelnet)
  2506. #else
  2507.         0
  2508. #endif /* TNCODE */
  2509.           ;
  2510.  
  2511. #ifndef NOCSETS
  2512. /* Set up character set translations */
  2513.  
  2514.     tcs = 0;                            /* "Transfer" or "Other" charset */
  2515.     sxo = rxo = NULL;                   /* Initialize byte-to-byte functions */
  2516.     sxi = rxi = NULL;
  2517.     unicode = 0;                        /* Assume Unicode won't be involved */
  2518.     if (!binary && xlate) {             /* Set up charset translations */
  2519. /*
  2520.   In the SENDING direction, we are converting from the local file's
  2521.   character-set (fcharset) to the remote terminal charset (tcsr).  In the
  2522.   RECEIVING direction (echoing) we are converting from the remote end of the
  2523.   terminal charset (tcsr) to its local end (tcsl), which is not necessarily
  2524.   the same as the file character-set.  Especially when the file character
  2525.   set is UCS-2, which is not a valid terminal character set.  The various
  2526.   combinations are represented in this table:
  2527.  
  2528.   FCS = File Character Set
  2529.   RCS = Remote Terminal Character Set
  2530.   CCS = Console (Local Terminal) Character Set
  2531.  
  2532.    8   4   2   1
  2533.   FCS FCS RCS CCS
  2534.   UCS UTF UTF UTF
  2535.    0   0   0   0   =   0   =   No translation
  2536.    0   0   0   1   =   1   =   FCS -> RCS, Echo RCS -> UTF
  2537.    0   0   1   0   =   2   =   FCS -> UTF, Echo UTF -> CCS
  2538.    0   0   1   1   =   3   =   FCS -> UTF, Echo no translation
  2539.  
  2540.    0   1   0   0   =   4   =   UTF -> RCS, Echo RCS -> CCS
  2541.    0   1   0   1   =   5   =   UTF -> RCS, Echo RCS -> UTF
  2542.    0   1   1   0   =   6   =   UTF -> UTF, Echo UTF -> CCS
  2543.    0   1   1   1   =   7   =   No translation
  2544.  
  2545.    1   0   0   0   =   8   =   UCS -> RCS, Echo RCS -> CCS
  2546.    1   0   0   1   =   9   =   UCS -> RCS, Echo RCS -> UTF
  2547.    1   0   1   0   =  10   =   UCS -> UTF, Echo UTF -> CCS
  2548.    1   0   1   1   =  11   =   UCS -> UTF, Echo no translation
  2549. */
  2550. #ifdef UNICODE
  2551.         xfu = NULL;                     /* Unicode translation functions */
  2552.         xuf = NULL;
  2553.         bomorder = ucsorder;            /* UCS-2 byte order */
  2554.  
  2555.         if (fcharset == FC_UCS2)        /* File charset is UCS-2 */
  2556.           unicode |= 8;
  2557.         else if (fcharset == FC_UTF8)   /* File charset is UTF-8 */
  2558.           unicode |= 4;
  2559.         if (tcsr == FC_UTF8)            /* Remote term charset is UTF-8 */
  2560.           unicode |= 2;
  2561.         if (tcsl == FC_UTF8)            /* Local term charset is UTF-8 */
  2562.           unicode |= 1;
  2563. #endif /* UNICODE */
  2564. /*
  2565.   When Unicode not involved -- TCS is the intermediate (xfer) set, and:
  2566.   sxo = File-to-Intermediate charset function
  2567.   rxo = Intermediate-to-Remote-Terminal charset function
  2568.   sxi = Remote-Terminal-to-Intermediate
  2569.   rxi = Intermediate-to-Local-Terminal
  2570. */
  2571.         tcs = gettcs(tcsr,fcharset);    /* Get intermediate set. */
  2572.         sxo = xls[tcs][fcharset];       /* translation function */
  2573.         rxo = xlr[tcs][tcsr];           /* pointers for output functions */
  2574.         sxi = xls[tcs][tcsr];           /* and for input functions. */
  2575.         rxi = xlr[tcs][tcsl];
  2576. /*
  2577.   At this point we have unicode nonzero if Unicode is involved in the
  2578.   conversion, and to 0 if it is not.
  2579.   The following is to prevent use of zmstuff() and zdstuff() by translation
  2580.   functions (stuffing works with file i/o, not with communication i/o).
  2581. */
  2582.         langsv = language;              /* Save current SET LANGUAGE */
  2583.         language = L_USASCII;           /* No language-specific translations */
  2584.     }
  2585. #endif /* NOCSETS */
  2586.  
  2587.     i = 0;                              /* Beginning of buffer. */
  2588. #ifndef MAC
  2589. #ifndef AMIGA
  2590.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  2591. #endif /* AMIGA */
  2592. #endif /* MAC */
  2593.     tr_int = 0;                         /* Have not been interrupted (yet). */
  2594.     rc = 1;                             /* Return code presumed good. */
  2595. #ifdef VMS
  2596.     conres();
  2597. #endif /* VMS */
  2598.  
  2599. #ifndef NOCSETS
  2600.     debug(F101,"XMIT unicode","",unicode);
  2601. #ifdef UNICODE
  2602.     debug(F101,"XMIT bomorder","",bomorder);
  2603. #endif /* UNICODE */
  2604. #endif /* NOCSETS */
  2605.  
  2606.     c = 0;                              /* Initial condition */
  2607.     while (c > -1 && !eof) {            /* Loop for all characters in file */
  2608.         eol = 0;
  2609. #ifdef MAC
  2610.         /*
  2611.          * It is expensive to run the miniparser so don't do it for
  2612.          * every character.
  2613.          */
  2614.         if (--count < 0) {
  2615.             count = 100;
  2616.             miniparser(1);
  2617.             if (sstate == 'a') {
  2618.                 sstate = '\0';
  2619.                 goto xmitfail;
  2620.             }
  2621.         }
  2622. #else /* Not MAC */
  2623.         if (tr_int) {                   /* Interrupted? */
  2624.             printf("^C...\n");          /* Print message */
  2625.             goto xmitfail;
  2626.         }
  2627. #endif /* MAC */
  2628.         c = zminchar();                 /* Get a file character */
  2629. #ifdef COMMENT
  2630. /* too much */
  2631. #ifdef DEBUG
  2632.         if (deblog) {
  2633.             if (c < 0)
  2634.               debug(F101,"XMIT zminchar","",c);
  2635.             else
  2636.               debug(F000,"XMIT zminchar","",c);
  2637.         }
  2638. #endif /* DEBUG */
  2639. #endif /* COMMENT */
  2640.         if (c < -1) {                   /* Other error */
  2641.             printf("?TRANSMIT file read error: %s\n",ck_errstr());
  2642.             goto xmitfail;
  2643.         } else if (c > -1) {
  2644.             nbytes++;
  2645.             c &= fmask;                 /* Apply SET FILE BYTESIZE mask */
  2646.         } else if (c == -1) {
  2647.             eof = 1;
  2648.             debug(F101,"XMIT eof","",eof);
  2649.         }
  2650.         if (binary) {                   /* Binary... */
  2651.             if (c == -1) {              /* If EOF */
  2652.                 rc = 1;                 /* Success */
  2653.                 eof = 1;
  2654.                 goto xmitexit;          /* Done */
  2655.             }
  2656.             if (!xmitw && !xxecho) {    /* Special "blast" mode */
  2657.                 if (count == XBBUFSIZ) { /* File input buffer full... */
  2658.                     while (count > 0) {
  2659.                         errno = 0;
  2660.                         y = ttol(xbbuf,count);
  2661.                         if (y < 0) {    /* try to send it. */
  2662.                             printf("?TRANSMIT output error: %s\n",
  2663.                                    ck_errstr());
  2664.                             debug(F111,"XMIT binary ttol error",
  2665.                                   ck_errstr(),errno);
  2666.                             rc = 0;
  2667.                             break;
  2668.                         }
  2669.                         if (y < 0) break;
  2670.                         count -= y;
  2671.                     }
  2672.                     count = 0;
  2673.                 }
  2674.                 xbbuf[count++] = c;
  2675. #ifdef TNCODE
  2676.                 if (c == IAC && is_tn)  /* Telnet IAC */
  2677.                   xbbuf[count++] = IAC; /* must be doubled */
  2678. #endif /* TNCODE */
  2679.                 continue;
  2680.             }
  2681.             if (ttoc(dopar((char) c)) < 0) { /* else just send the char */
  2682.                 printf("?Can't transmit character\n");
  2683.                 goto xmitfail;
  2684.             }
  2685. #ifdef TNCODE
  2686.             if (c == IAC && is_tn)      /* Quote Telnet IAC */
  2687.               ttoc((char)IAC);
  2688. #endif /* TNCODE */
  2689.  
  2690.             if (xmitw)                  /* Pause if requested */
  2691.               msleep(xmitw);
  2692.  
  2693.             if (xxecho) {               /* SET TRANSMIT ECHO ON? */
  2694.                 if (duplex) {           /* Yes, for half duplex */
  2695. #ifndef NOLOCAL
  2696. #ifdef OS2
  2697.                     /* Echo to emulator */
  2698.                     scriptwrtbuf((USHORT)(c & cmdmsk));
  2699. #endif /* OS2 */
  2700. #endif /* NOLOCAL */
  2701.                     if (conoc((char)(c & cmdmsk)) < 0) /* echo locally. */
  2702.                       goto xmitfail;
  2703.                 } else {                /* For full duplex, */
  2704.                     int i, n;           /* display whatever is there. */
  2705.                     n = ttchk();        /* See how many chars are waiting */
  2706.                     if (n < 0) {        /* Connection dropped? */
  2707.                         printf("?Connection lost\n");
  2708.                         goto xmitfail;
  2709.                     }
  2710.                     for (i = 0; i < n; i++) { /* Read and echo that many. */
  2711.                         x = ttinc(xmitt); /* Timed read just in case. */
  2712.                         if (x > -1) {   /* If no timeout */
  2713.                             if (parity) x &= 0x7f; /* display the char, */
  2714. #ifndef NOLOCAL
  2715. #ifdef OS2
  2716.                             /* Echo to emulator */
  2717.                             scriptwrtbuf((USHORT)x);
  2718. #endif /* OS2 */
  2719. #endif /* NOLOCAL */
  2720.                             if (conoc((char)(x & cmdmsk)) < 0) {
  2721.                                 printf("?Output error\n");
  2722.                                 goto xmitfail;
  2723.                             }
  2724.                         } else if (x == -2) {
  2725.                             printf("Connection closed.\n");
  2726.                             ttclos(1);
  2727.                             goto xmitfail;
  2728.                         } else if (x == -3) {
  2729.                             printf(
  2730.                             "Session Limit exceeded - closing connection.\n"
  2731.                                    );
  2732.                             ttclos(1);
  2733.                             goto xmitfail;
  2734.                         } else {
  2735.                             printf("?Communications error\n");
  2736.                             goto xmitfail;
  2737.                         }
  2738.                     }
  2739.                 }
  2740.             } else ttflui();            /* Not echoing, just flush input. */
  2741.  
  2742.         } else {                        /* Text mode, line at a time. */
  2743. #ifdef UNICODE
  2744.             if (fcharset == FC_UCS2 && xlate) { /* Special for UCS-2 */
  2745.                 char xbuf[8];
  2746.                 x = 1 - (nbytes & 1);   /* Odd or even byte */
  2747.                 if (x == 0)             /* Note: 1 = the 1st, 0 = 2nd, etc */
  2748.                   uc.x_short = 0;
  2749.                 if (bomorder)           /* Little Endian */
  2750.                   x = 1 - x;            /* Save byte in appropriate half */
  2751.                 debug(F101,"XMIT UCS2 x","",x);
  2752.                 uc.x_char[x] = (CHAR) (c & 0xff);
  2753.                 if (nbytes & 1)         /* First byte, go back for next */
  2754.                   continue;
  2755.                 if (nbytes == 2) {      /* UCS-2 Byte Order Mark */
  2756.                     if (uc.x_short == (USHORT) 0xfeff) {
  2757.                         debug(F100,"XMIT UCS2 BOM FEFF","",bomorder);
  2758.                         continue;
  2759.                     } else if (uc.x_short == (USHORT) 0xfffe) {
  2760.                         bomorder = 1 - bomorder;
  2761.                         debug(F100,"XMIT UCS2 BOM FFFE (swap)","",bomorder);
  2762.                         continue;
  2763.                     }
  2764.                 }
  2765.                 sprintf(xbuf,"%04X",uc.x_short); /* SAFE */
  2766.                 debug(F111,"XMIT UCS2",xbuf,uc.x_short);
  2767.                 if (nbytes & 1)         /* Special eol test for UCS-2 */
  2768.                   if (uc.x_short == '\n')
  2769.                     eol = 1;
  2770. #ifdef COMMENT
  2771.                 if (uc.x_short == 0x2028 || uc.x_short == 0x2029)
  2772.                     eol = 1;
  2773. #endif /* COMMENT */
  2774.             } else
  2775. #endif /* UNICODE */
  2776.               if (c == '\n') {          /* Normal eol test otherwise */
  2777.                   eol = 1;
  2778.             }
  2779.             if (eol) {                  /* End of line? */
  2780.                 int stuff = -1;
  2781.                 debug(F101,"XMIT eol length","",i);
  2782.                 if (i == 0) {           /* Blank line? */
  2783.                     if (xmitf)          /* Yes, insert fill if asked. */
  2784.                       line[i++] = dopar((char) xmitf);
  2785.                 }
  2786.                 if (i == 0 || ((char) line[i-1]) != ((char) dopar(CR)))
  2787.                   line[i++] = dopar(CR); /* Terminate it with CR */
  2788.                 if (xmitl) {
  2789.                     stuff = LF;
  2790. #ifdef TNCODE
  2791.                 } else if (is_tn && (tn_nlm != TNL_CR)) {
  2792.                     /* TELNET NEWLINE ON/OFF/RAW */
  2793.                     stuff = (tn_nlm == TNL_CRLF) ? LF : NUL;
  2794. #endif /* TNCODE */
  2795.                 }
  2796.                 if (stuff > -1)
  2797.                   line[i++] = dopar((char)stuff);
  2798.                 line[i] = NUL;
  2799.                 debug(F111,"XMIT eol line",line,i);
  2800.  
  2801.             } else if (c != -1) {       /* Not a newline, regular character */
  2802.                 int k, x;
  2803.                 outxbuf[0] = c;         /* In case of no translation */
  2804.                 outxcount = 1;          /* Assume result is one byte */
  2805. #ifndef NOCSETS
  2806.                 switch (unicode) {
  2807.                   case 0:               /* No Unicode involved */
  2808.                   case 1:
  2809.                     if (xlate) {        /* If not /TRANSPARENT */
  2810.                         /* Local-to-intermediate */
  2811.                         if (sxo) c = (*sxo)((char)c);
  2812.                         /* Intermediate-to-remote */
  2813.                         if (rxo) c = (*rxo)((char)c);
  2814.                         outxbuf[0] = c;
  2815.                     }
  2816.                     break;
  2817. #ifdef UNICODE
  2818.                   case 2:               /* Local byte to UTF-8 */
  2819.                   case 3:
  2820.                     xfu = xl_fcu[fcharset];
  2821.                     tcssize = fcsinfo[fcharset].size;
  2822.                     outxcount =
  2823.                       b_to_u((CHAR)c,outxbuf,OUTXBUFSIZ,tcssize);
  2824.                     break;
  2825.                   case 4:               /* Local UTF-8 to remote byte */
  2826.                   case 5:
  2827.                     xuf = xl_ufc[tcsr];
  2828.                     x = u_to_b((CHAR)c); /* Convert to byte */
  2829.                     if (x == -1) {      /* If more input bytes needed */
  2830.                         continue;       /* go back and get them */
  2831.                     } else if (x == -2) { /* LS or PS (shouldn't happen) */
  2832.                         outxbuf[0] = CR;
  2833.                     } else if (x == -9) { /* UTF-8 error */
  2834.                         outxbuf[0] = '?'; /* Insert error char */
  2835.                         outxbuf[1] = u_to_b2(); /* Insert next char */
  2836.                         outxcount = 2;
  2837.                     } else {
  2838.                         outxbuf[0] =    /* Otherwise store result */
  2839.                           (unsigned)(x & 0xff);
  2840.                     }
  2841.                     break;
  2842.                   case 6:               /* UTF-8 to UTF-8 */
  2843.                   case 7:
  2844.                     break;
  2845.                   case 8:               /* UCS-2 to byte */
  2846.                   case 9:
  2847.                     xuf = xl_ufc[tcsr];
  2848.                     outxbuf[0] = (*xuf)(uc.x_short);
  2849.                     break;
  2850.                   case 10:
  2851.                   case 11: {            /* UCS-2 to UTF-8 */
  2852.                       int j;
  2853.                       CHAR * buf = NULL;
  2854.                       x = ucs2_to_utf8(uc.x_short,&buf);
  2855.                       if (x < 0) {
  2856.                           outxbuf[0] = 0xff; /* (= U+FFFD) */
  2857.                           outxbuf[1] = 0xbd;
  2858.                           x = 2;
  2859.                       }
  2860.                       for (j = 0; j < x; j++)
  2861.                         outxbuf[j] = buf[j];
  2862.                       outxcount = x;
  2863.                       break;
  2864.                   }
  2865. #endif /* UNICODE */
  2866.                 }
  2867. #endif /* NOCSETS */
  2868.                 outxbuf[outxcount] = NUL;
  2869.                 debug(F111,"XMIT outxbuf",outxbuf,outxcount);
  2870. /*
  2871.   Now the input character (1 or more bytes) is translated into the output
  2872.   expansion buffer (1 or more bytes); outxcount = number of bytes to add to
  2873.   the TRANSMIT line buffer, which we do here, taking care of parity, SI/SO
  2874.   processing, and quoting Telnet IACs.
  2875. */
  2876.                 for (k = 0; k < outxcount; k++) {
  2877.                     c = outxbuf[k];
  2878.                     if (xmits && parity && (c & 0200)) { /* If shifting */
  2879.                         line[i++] = dopar(SO); /* needs to be done, */
  2880.                         line[i++] = dopar((char)c); /* do it here, */
  2881.                         line[i++] = dopar(SI); /* crudely. */
  2882.                     } else {
  2883.                         line[i++] = dopar((char)c);
  2884. #ifdef TNCODE
  2885.                         if (c == IAC && is_tn)
  2886.                           line[i++] = IAC;
  2887. #endif /* TNCODE */
  2888.                     }
  2889.                 }
  2890.             }
  2891. /*
  2892.   Send characters if buffer full, or at end of line, or at end of file.
  2893.   (End of line only if echoing, waiting for a prompt, or pausing.)
  2894. */
  2895.             debug(F000,"XMIT c",ckitoa(i),c);
  2896.             if (i >= xbufsiz || eof || (eol && (xxecho || xmitw || t))) {
  2897.                 p = line;
  2898.                 line[i] = '\0';
  2899.                 debug(F111,"transmit buf",p,i);
  2900.                 if (ttol((CHAR *)p,i) < 0) { /* try to send it. */
  2901.                     printf("?TRANSMIT output error: %s\n",ck_errstr());
  2902.                     rc = 0;
  2903.                     break;
  2904.                 }
  2905.                 i = 0;                  /* Reset buffer pointer. */
  2906. /*
  2907.   Now we handle the echo.  If the user wants to see it, or if we have to
  2908.   wait for the turnaround character, t.  If the echo is being displayed,
  2909.   and terminal character-set translation is required, we do it here.
  2910. */
  2911.                 if (duplex && xxecho) {  /* If local echo, echo it */
  2912.                     if (parity || cmdmsk == 0x7f) { /* Strip hi bits */
  2913.                         char *ss = line;             /* if necessary */
  2914.                         while (*ss) {
  2915.                             *ss &= 0x7f;
  2916.                             ss++;
  2917.                         }
  2918.                     }
  2919. #ifndef NOLOCAL
  2920. #ifdef OS2
  2921.                     {                   /* Echo to emulator */
  2922.                         char *ss = p;
  2923.                         while (*ss) {
  2924.                             scriptwrtbuf((USHORT)*ss);
  2925.                             ss++;
  2926.                         }
  2927.                     }
  2928. #endif /* OS2 */
  2929. #endif /* NOLOCAL */
  2930.                     if (conoll(p) < 0)
  2931.                       goto xmitfail;
  2932.                 }
  2933.                 if (xmitw)              /* Sleep TRANSMIT PAUSE interval */
  2934.                   msleep(xmitw);
  2935.  
  2936.                 control = 0;            /* Readback loop control */
  2937.                 if (t != 0 && eol)      /* TRANSMIT PROMPT given and at EOL */
  2938.                   control |= 1;
  2939.                 if (xxecho && !duplex)   /* Echo desired and is remote */
  2940.                   control |= 2;
  2941.  
  2942.                 if (control) {          /* Do this if reading back the echo */
  2943.                     int n;
  2944.                     x = 0;
  2945.                     while (1) {
  2946.                         if (control & 1) { /* Termination criterion */
  2947.                             if (x == t)    /* for turnaround */
  2948.                               break;
  2949.                         } else if (control & 2) { /* And for echoing */
  2950.                             if ((n = ttchk()) < 1)
  2951.                               break;
  2952.                         }
  2953.                         if ((x = ttinc(xmitt)) < 0) { /* Read with timeout */
  2954.                             switch (x) {
  2955.                               case -2:
  2956.                                 printf("Connection closed.\n");
  2957.                                 ttclos(1);
  2958.                                 goto xmitfail;
  2959.                               case -3:
  2960.                                 printf(
  2961.                               "Session Limit exceeded - closing connection.\n"
  2962.                                        );
  2963.                                 ttclos(1); /* full thru... */
  2964.                                 goto xmitfail;
  2965.                               default:
  2966.                                 printf("?Timeout\n");
  2967.                                 goto xmitfail;
  2968.                             }
  2969.                         }
  2970.                         if (x > -1 && (control & 2)) { /* Echo any echoes */
  2971.                             if (parity)
  2972.                               x &= 0x7f;
  2973.                             c = x;
  2974. #ifndef NOLOCAL
  2975. #ifdef OS2
  2976.                             scriptwrtbuf((USHORT)x);
  2977. #endif /* OS2 */
  2978. #endif /* NOLOCAL */
  2979.                             inxbuf[0] = c;
  2980.                             inxcount = 1;
  2981. #ifndef NOCSETS
  2982.                             switch (unicode & 3) { /* Remote bits */
  2983.                               case 0:
  2984.                                 if (xlate) {
  2985.                                     if (sxi) c = (*sxi)((CHAR)c);
  2986.                                     if (rxi) c = (*rxi)((CHAR)c);
  2987.                                     inxbuf[0] = c;
  2988.                                 }
  2989.                                 break;
  2990. #ifdef UNICODE
  2991.                               case 1:   /* Remote Byte to local UTF-8 */
  2992.                                 xfu = xl_fcu[tcsr];
  2993.                                 tcssize = fcsinfo[tcsr].size;
  2994.                                 inxcount =
  2995.                                   b_to_u((CHAR)c,
  2996.                                          inxbuf,
  2997.                                          OUTXBUFSIZ,
  2998.                                          tcssize
  2999.                                          );
  3000.                                 break;
  3001.                               case 2:   /* Remote UTF-8 to local Byte */
  3002.                                 xuf = xl_ufc[tcsl];
  3003.                                 x = u_to_b((CHAR)c);
  3004.                                 if (x < 0)
  3005.                                   continue;
  3006.                                 inxbuf[0] = (unsigned)(x & 0xff);
  3007.                                 break;
  3008.                               case 3:   /* UTF-8 to UTF-8 */
  3009.                                 break;
  3010. #endif /* UNICODE */
  3011.                             }
  3012. #endif /* NOCSETS */
  3013.                             inxbuf[inxcount] = NUL;
  3014.                             if (conxo(inxcount,(char *)inxbuf) < 0)
  3015.                               goto xmitfail;
  3016.                         }
  3017.                     }
  3018.                 } else                  /* Not echoing */
  3019.                   ttflui();             /* Just flush input buffer */
  3020.             } /* End of buffer-dumping block */
  3021.         } /* End of text mode */
  3022.         if (eof) {
  3023.             rc = 1;
  3024.             goto xmitexit;
  3025.         }
  3026.     } /* End of character-reading loop */
  3027.  
  3028.   xmitfail:                             /* Failure exit point */
  3029.     rc = 0;
  3030.  
  3031.   xmitexit:                             /* General exit point */
  3032.     if (rc > 0) {
  3033.         if (binary && !xmitw && !xxecho) { /* "blasting"? */
  3034.             while (count > 0) {            /* Partial buffer still to go? */
  3035.                 errno = 0;
  3036.                 y = ttol(xbbuf,count);
  3037.                 if (y < 0) {
  3038.                     printf("?TRANSMIT output error: %s\n",
  3039.                            ck_errstr());
  3040.                     debug(F111,"XMIT binary eof ttol error",
  3041.                           ck_errstr(),errno);
  3042.                     rc = 0;
  3043.                     break;
  3044.                 }
  3045.                 count -= y;
  3046.             }
  3047.         } else if (!binary && *xmitbuf) { /* Anything to send at EOF? */
  3048.             p = xmitbuf;                /* Yes, point to string. */
  3049.             while (*p)                  /* Send it. */
  3050.               ttoc(dopar(*p++));        /* Don't worry about echo here. */
  3051.         }
  3052.     }
  3053.  
  3054. #ifndef AMIGA
  3055. #ifndef MAC
  3056.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3057. #endif /* MAC */
  3058. #endif /* AMIGA */
  3059. #ifdef VMS
  3060.     concb(escape);                      /* Put terminal back, */
  3061. #endif /* VMS */
  3062.     zclose(ZIFILE);                     /* Close file, */
  3063. #ifndef NOCSETS
  3064.     language = langsv;                  /* restore language, */
  3065. #endif /* NOCSETS */
  3066.     ttres();                            /* and terminal modes, */
  3067.     return(rc);                         /* and return successfully. */
  3068. }
  3069. #endif /* NOLOCAL */
  3070. #endif /* NOXMIT */
  3071.  
  3072. #ifndef NOCSETS
  3073.  
  3074. _PROTOTYP( CHAR (*sxx), (CHAR) );       /* Local translation function */
  3075. _PROTOTYP( CHAR (*rxx), (CHAR) );       /* Local translation function */
  3076. _PROTOTYP( CHAR zl1as, (CHAR) );        /* Latin-1 to ascii */
  3077. _PROTOTYP( CHAR xl1as, (CHAR) );        /* ditto */
  3078.  
  3079. /*  X L A T E  --  Translate a local file from one character set to another */
  3080.  
  3081. /*
  3082.   Translates input file (fin) from character set csin to character set csout
  3083.   and puts the result in the output file (fout).  The two character sets are
  3084.   file character sets from fcstab.
  3085. */
  3086.  
  3087. int
  3088. xlate(fin, fout, csin, csout) char *fin, *fout; int csin, csout; {
  3089.  
  3090. #ifndef MAC
  3091. #ifdef OS2
  3092.     extern int k95stdout;
  3093.     extern int wherex[], wherey[];
  3094.     extern unsigned char colorcmd;
  3095. #ifdef NT
  3096.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  3097. #else /* NT */
  3098.     SIGTYP (* volatile oldsig)(int);    /* For saving old interrupt trap. */
  3099. #endif /* NT */
  3100. #else /* OS2 */
  3101.     SIGTYP (* oldsig)();
  3102. #endif /* OS2 */
  3103. #endif /* MAC */
  3104. #ifdef CK_ANSIC
  3105.     int (*fn)(char);                    /* Output function pointer */
  3106. #else
  3107.     int (*fn)();
  3108. #endif /* CK_ANSIC */
  3109.     extern int xlatype;
  3110.     int filecode;                       /* Code for output file */
  3111.     int scrnflg = 0;
  3112.  
  3113.     int z = 1;                          /* Return code. */
  3114.     int x, c, c2;                       /* Workers */
  3115. #ifndef UNICODE
  3116.     int tcs;
  3117. #endif /* UNICODE */
  3118.  
  3119.     ffc = 0L;
  3120.  
  3121.     if (zopeni(ZIFILE,fin) == 0) {      /* Open the file to be translated */
  3122. #ifdef COMMENT
  3123.         /* An error message was already printed by zopeni() */
  3124.         printf("?Can't open input file %s\n",fin);
  3125. #endif /* COMMENT */
  3126.         return(0);
  3127.     }
  3128. #ifdef MAC
  3129. /*
  3130.   If user specified no output file, it goes to the screen.  For the Mac,
  3131.   this must be done a special way (result goes to a new window); the Mac
  3132.   doesn't have a "controlling terminal" device name.
  3133. */
  3134.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZOFILE;
  3135. #else
  3136. #ifdef VMS
  3137.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZMFILE;
  3138. #else
  3139. #ifdef OS2
  3140.     filecode = (!stricmp(fout,"con") || !stricmp(fout,"con:")) ?
  3141.         ZCTERM : ZMFILE;
  3142.     if ((filecode == ZCTERM) && !k95stdout && !inserver)
  3143.         csout = FC_UCS2;
  3144. #else /* OS2 */
  3145.     filecode = ZOFILE;
  3146. #endif /* OS2 */
  3147. #endif /* VMS */
  3148. #endif /* MAC */
  3149.     if (zopeno(filecode,fout,NULL,NULL) == 0) { /* And the output file */
  3150.         printf("?Can't open output file %s\n",fout);
  3151.         return(0);
  3152.     }
  3153. #ifndef AMIGA
  3154. #ifndef MAC
  3155.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  3156. #endif /* MAC */
  3157. #endif /* AMIGA */
  3158.  
  3159.     scrnflg = (filecode == ZCTERM);     /* Set output function */
  3160.     if (scrnflg)
  3161.       fn = NULL;
  3162.     else if (filecode == ZMFILE)
  3163.       fn = putmfil;
  3164.     else
  3165.       fn = putfil;
  3166.  
  3167.     tr_int = 0;                         /* Have not been interrupted (yet). */
  3168.     z = 1;                              /* Return code presumed good. */
  3169.  
  3170.     if (!scrnflg && !quiet)
  3171.       printf(" %s (%s) => %s (%s)\n",   /* Say what we're doing. */
  3172.              fin, fcsinfo[csin].keyword,
  3173.              fout,fcsinfo[csout].keyword
  3174.              );
  3175.  
  3176. #ifndef UNICODE
  3177. /*
  3178.   Non-Unicode picks the "most appropriate" transfer character set as the
  3179.   intermediate set, which results in loss of any characters that the source
  3180.   and target sets have in common, but are lacking from the intermediate set.
  3181. */
  3182. #ifdef KANJI
  3183.     /* Special handling for Japanese... */
  3184.  
  3185.     if (fcsinfo[csin].alphabet == AL_JAPAN ||
  3186.          fcsinfo[csout].alphabet == AL_JAPAN) {
  3187.         USHORT eu;
  3188.         int c, x, y;
  3189.  
  3190.         xpnbyte(-1,0,0,NULL);           /* Reset output machine */
  3191.         xlatype = XLA_JAPAN;
  3192.  
  3193.         while ((c = xgnbyte(FC_JEUC,csin,NULL)) > -1) { /* Get an EUC byte */
  3194.             if (tr_int) {               /* Interrupted? */
  3195.                 printf("^C...\n");      /* Print message */
  3196.                 z = 0;
  3197.                 break;
  3198.             }
  3199.             /* Send EUC byte to output machine */
  3200.             if ((x = xpnbyte(c,TC_JEUC,csout,fn)) < 0) {
  3201.                 z = -1;
  3202.                 break;
  3203.             }
  3204.         }
  3205.         goto xxlate;
  3206.     }
  3207. #endif /* KANJI */
  3208.  
  3209.     /* Regular bytewise conversion... */
  3210.  
  3211.     tcs = gettcs(csin,csout);           /* Get intermediate set. */
  3212.     if (csin == csout) {                /* Input and output sets the same? */
  3213.         sxx = rxx = NULL;               /* If so, no translation. */
  3214.     } else {                            /* Otherwise, set up */
  3215.         if (tcs < 0 || tcs > MAXTCSETS ||
  3216.             csin < 0 || csin > MAXFCSETS ||
  3217.             csout < 0 || csout > MAXFCSETS) {
  3218.             debug(F100,"XLATE csets out of range","",0);
  3219.             sxx = rxx = NULL;
  3220.         } else {
  3221.             sxx = xls[tcs][csin];       /* translation function */
  3222.             rxx = xlr[tcs][csout];      /* pointers. */
  3223.             if (rxx == zl1as) rxx = xl1as;
  3224.         }
  3225.     }
  3226.     while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3227.         if (tr_int) {                   /* Interrupted? */
  3228.             printf("^C...\n");          /* Print message */
  3229.             z = 0;
  3230.             break;
  3231.         }
  3232.         if (sxx) c = (*sxx)((CHAR)c);   /* From fcs1 to tcs */
  3233.         if (rxx) c = (*rxx)((CHAR)c);   /* from tcs to fcs2 */
  3234.         if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3235.             z = -1;
  3236.             break;
  3237.         }
  3238.     }
  3239.     goto xxlate;                        /* Done. */
  3240.  
  3241. #else  /* UNICODE */
  3242. /*
  3243.    Use Unicode as the intermediate character set.  It's simple and gives
  3244.    little or no loss, but the overhead is a bit higher.
  3245. */
  3246.     initxlate(csin,csout);              /* Set up translation functions */
  3247.  
  3248.     if (xlatype == XLA_NONE) {
  3249.         while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3250.             if (tr_int) {               /* Interrupted? */
  3251.                 printf("^C...\n");      /* Print message */
  3252.                 z = 0;
  3253.                 break;
  3254.             }
  3255.             if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3256.                 z = -1;
  3257.                 break;
  3258.             }
  3259.         }
  3260.         goto xxlate;                    /* Done. */
  3261.     }
  3262.  
  3263.  
  3264. #ifndef NOLOCAL
  3265. #ifdef OS2
  3266.     if (csout == FC_UCS2 &&             /* we're translating to UCS-2 */
  3267.         filecode == ZCTERM &&           /* for the real screen... */
  3268.         !k95stdout && !inserver
  3269.         ) {
  3270.         union {
  3271.             USHORT ucs2;
  3272.             UCHAR  bytes[2];
  3273.         } output;
  3274.  
  3275.         while (1) {                     /* In this case we go two-by-two. */
  3276.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3277.               break;
  3278.             output.bytes[0] = c;
  3279.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3280.               break;
  3281.             output.bytes[1] = c;
  3282.  
  3283.             if (tr_int) {               /* Interrupted? */
  3284.                 printf("^C...\n");      /* Print message */
  3285.                 z = 0;
  3286.                 break;
  3287.             }
  3288.  
  3289.             VscrnWrtUCS2StrAtt(VCMD,
  3290.                                &output.ucs2,
  3291.                                1,
  3292.                                wherey[VCMD],
  3293.                                wherex[VCMD],
  3294.                                &colorcmd
  3295.                                );
  3296.         }
  3297.     } else
  3298. #endif /* OS2 */
  3299. #endif /* NOLOCAL */
  3300.  
  3301.       /* General case: Get next byte translated from fcs to UCS-2 */
  3302.  
  3303. #ifdef COMMENT
  3304.       while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1 &&
  3305.               (c2 = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3306.           extern int fileorder;
  3307.  
  3308.           if (tr_int) {                 /* Interrupted? */
  3309.               printf("^C...\n");        /* Print message */
  3310.               z = 0;
  3311.               break;
  3312.           }
  3313.           debug(F001,"XLATE c","",c);
  3314.           debug(F001,"XLATE c2","",c2);
  3315.  
  3316.           /* And then send UCS-2 byte to translate-and-output machine */
  3317.  
  3318.           if ((x = xpnbyte(fileorder?c2:c,TC_UCS2,csout,fn)) < 0) {
  3319.               z = -1;
  3320.               break;
  3321.           }
  3322.           if ((x = xpnbyte(fileorder?c:c2,TC_UCS2,csout,fn)) < 0) {
  3323.               z = -1;
  3324.               break;
  3325.           }
  3326.       }
  3327. #else
  3328.     while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3329.           if (tr_int) {                 /* Interrupted? */
  3330.               printf("^C...\n");        /* Print message */
  3331.               z = 0;
  3332.               break;
  3333.           }
  3334.           if ((x = xpnbyte(c,TC_UCS2,csout,fn)) < 0) {
  3335.               z = -1;
  3336.               break;
  3337.           }
  3338.       }
  3339. #endif /* COMMENT */
  3340.  
  3341. #endif /* UNICODE */
  3342.  
  3343.   xxlate:                               /* Common exit point */
  3344.  
  3345. #ifndef AMIGA
  3346. #ifndef MAC
  3347.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3348. #endif /* MAC */
  3349. #endif /* AMIGA */
  3350.     tr_int = 0;
  3351.     if (z < 0) {
  3352.         if (z == -1)
  3353.           printf("?File output error: %s\n",ck_errstr());
  3354.         z = 0;
  3355.     }
  3356.     zclose(ZIFILE);                     /* Close files */
  3357.     zclose(filecode);                   /* ... */
  3358.     return(success = z);                /* and return status. */
  3359. }
  3360.  
  3361. int
  3362. doxlate() {
  3363. #ifdef OS2ONLY
  3364.     extern int tt_font;
  3365. #endif /* OS2ONLY */
  3366. #ifdef UNIX
  3367.     extern char ** mtchs;               /* zxpand() file list */
  3368. #endif /* UNIX */
  3369.     extern int nfilc;
  3370.     extern struct keytab fcstab[];
  3371.     int x, y, incs, outcs, multiple = 0, wild = 0, fc = 0, len = 0;
  3372.     int ofisdir = 0;
  3373.     char * s, * tocs = "";
  3374.  
  3375.     if ((x = cmifi("File(s) to translate","",&s,&wild,xxstring)) < 0) {
  3376.         if (x == -3) {
  3377.             printf("?Name of an existing file\n");
  3378.             return(-9);
  3379.         } else
  3380.           return(x);
  3381.     }
  3382.     ckstrncpy(line,s,LINBUFSIZ);        /* Save copy of string just parsed. */
  3383.  
  3384.     if ((incs = cmkey(fcstab,nfilc,"from character-set","",xxstring)) < 0)
  3385.       return(incs);
  3386.  
  3387. #ifdef OS2
  3388.     if (isunicode())
  3389.       tocs = "ucs2";
  3390.     else
  3391. #endif /* OS2 */
  3392.       tocs = getdcset();
  3393.  
  3394.     if ((outcs = cmkey(fcstab,nfilc,"to character-set",tocs,xxstring)) < 0)
  3395.       return(outcs);
  3396.     if ((x = cmofi("output file",CTTNAM,&s,xxstring)) < 0) return(x);
  3397.     if (x > 1)
  3398.       ofisdir = 1;
  3399.  
  3400.     len = ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  3401.     if ((y = cmcfm()) < 0) return(y);   /* Confirm the command */
  3402.  
  3403.     if (len < 1)
  3404.       return(-2);
  3405.  
  3406.     if (ofisdir)
  3407.       multiple = 2;
  3408.     else if (wild) {
  3409.         if (isdir(tmpbuf))
  3410.           multiple = 2;
  3411.         else if (!strcmp(tmpbuf,CTTNAM))
  3412.           multiple = 1;
  3413. #ifdef OS2
  3414.         else if (!stricmp(tmpbuf,"con") || !stricmp(tmpbuf,"con:"))
  3415.           multiple = 1;
  3416. #else
  3417. #ifdef UNIXOROSK
  3418.         else if (!strncmp(tmpbuf,"/dev/",4))
  3419.           multiple = 1;
  3420. #endif /* UNIXOROSK */
  3421. #endif /* OS2 */
  3422.         if (!multiple) {
  3423.             printf("?A single file please\n");
  3424.             return(-9);
  3425.         }
  3426.     }
  3427.     if (!multiple) {                    /* Just one file */
  3428.         return(success = xlate(line,tmpbuf,incs,outcs));
  3429.     } else {                            /* Translate multiple files */
  3430.         char dirbuf[CKMAXPATH+4];
  3431.         int k;
  3432. #ifndef ZXREWIND
  3433.         int flags = ZX_FILONLY;
  3434. #endif /* ZXREWIND */
  3435.  
  3436.         if (multiple == 2) {            /* Target is a directory */
  3437.             k = ckstrncpy(dirbuf,tmpbuf,CKMAXPATH+1) - 1;
  3438.             if (k < 0)
  3439.               return(-2);
  3440. #ifdef OS2ORUNIX
  3441.             if (dirbuf[k] != '/') {
  3442.                 dirbuf[k+1] = '/';
  3443.                 dirbuf[k+2] = NUL;
  3444.             }
  3445. #else
  3446. #ifdef OSK
  3447.             if (dirbuf[k] != '/') {
  3448.                 dirbuf[k+1] = '/';
  3449.                 dirbuf[k+2] = NUL;
  3450.             }
  3451. #else
  3452. #ifdef VMS
  3453.             if (ckmatch("*.DIR;1",s,0,0))
  3454.               k = cvtdir(tmpbuf,dirbuf,TMPBUFSIZ);
  3455.             if (dirbuf[k] != ']' &&
  3456.                 dirbuf[k] != '>' &&
  3457.                 dirbuf[k] != ':')
  3458.               return(-2);
  3459. #else
  3460. #ifdef datageneral
  3461.             if (dirbuf[k] != ':') {
  3462.                 dirbuf[k+1] = ':';
  3463.                 dirbuf[k+2] = NUL;
  3464.             }
  3465. #else
  3466. #ifdef STRATUS
  3467.             if (dirbuf[k] != '>') {
  3468.                 dirbuf[k+1] = '>';
  3469.                 dirbuf[k+2] = NUL;
  3470.             }
  3471. #endif /* STRATUS */
  3472. #endif /* datageneral */
  3473. #endif /* VMS */
  3474. #endif /* OSK */
  3475. #endif /* OS2ORUNIX */
  3476.         }
  3477.  
  3478. #ifdef ZXREWIND
  3479.         fc = zxrewind();                /* Rewind the file list */
  3480. #else
  3481.         if (matchdot)  flags |= ZX_MATCHDOT;
  3482.         fc = nzxpand(line,flags);
  3483. #endif /* ZXREWIND */
  3484.  
  3485.         if (fc < 1) {
  3486.             printf("?Wildcard expansion error\n");
  3487.             return(-9);
  3488.         }
  3489. #ifdef UNIX
  3490.         sh_sort(mtchs,NULL,fc,0,0,filecase); /* Sort the file list */
  3491. #endif /* UNIX */
  3492.  
  3493.         while (1) {                     /* Loop through the files */
  3494.             znext(line);
  3495.             if (!line[0])
  3496.               break;
  3497.             if (multiple == 2)
  3498.               ckmakmsg(tmpbuf,TMPBUFSIZ,dirbuf,line,NULL,NULL);
  3499.             if (xlate(line,tmpbuf,incs,outcs) < 1)
  3500.               return(success = 0);
  3501.         }
  3502.     }
  3503.     return(success = 1);
  3504. }
  3505. #endif /* NOCSETS */
  3506.  
  3507. static char hompthbuf[CKMAXPATH+1];
  3508.  
  3509. char *
  3510. homepath() {
  3511.     int x;
  3512.     extern char * myhome;
  3513.     char * h;
  3514.  
  3515.     h = myhome ? myhome : zhome();
  3516.     hompthbuf[0] = NUL;
  3517. #ifdef UNIXOROSK
  3518.     x = ckstrncpy(hompthbuf,h,CKMAXPATH+1);
  3519.     if (x <= 0) {
  3520.         hompthbuf[0] = '/';
  3521.         hompthbuf[1] = NUL;
  3522.     } else if (x < CKMAXPATH - 2 && hompthbuf[x-1] != '/') {
  3523.         hompthbuf[x] = '/';
  3524.         hompthbuf[x+1] = NUL;
  3525.     }
  3526.     return(hompthbuf);
  3527. #else
  3528. #ifdef STRATUS
  3529.     if (strlen(h) < CKMAXPATH)
  3530.       sprintf(hompthbuf,"%s>",h);    /* SAFE */
  3531.     return(hompthbuf);
  3532. #else
  3533.     return(h);
  3534. #endif /* STRATUS */
  3535. #endif /* UNIXOROSK */
  3536. }
  3537.  
  3538. /*  D O L O G  --  Do the log command  */
  3539.  
  3540. int
  3541. dolog(x) int x; {
  3542.     int y, disp; char *s = NULL, * p = NULL, * q = NULL;
  3543.     extern int isguest;
  3544. #ifdef ZFNQFP
  3545.     struct zfnfp * fnp;
  3546. #endif /* ZFNQFP */
  3547.  
  3548.     if (isguest) {
  3549.         printf("?Anonymous log creation not allowed\n");
  3550.         return(-9);
  3551.     }
  3552.     switch (x) {                        /* Which log... */
  3553.  
  3554. #ifdef DEBUG
  3555.       case LOGD:
  3556.         q = "debug.log";
  3557.         y = cmofi("Name of debugging log file",q,&s,xxstring);
  3558.         break;
  3559. #endif /* DEBUG */
  3560.  
  3561.       case LOGP:
  3562.         q = "packet.log";
  3563.         y = cmofi("Name of packet log file",q,&s,xxstring);
  3564.         break;
  3565.  
  3566. #ifndef NOLOCAL
  3567.       case LOGS:
  3568.         q = "session.log";
  3569.         y = cmofi("Name of session log file",q,&s,xxstring);
  3570.         break;
  3571. #endif /* NOLOCAL */
  3572.  
  3573. #ifdef TLOG
  3574.       case LOGT:
  3575.         q = "transact.log";
  3576.         y = cmofi("Name of transaction log file",q,&s,xxstring);
  3577.         break;
  3578. #endif /* TLOG */
  3579.  
  3580. #ifdef CKLOGDIAL
  3581.       case LOGM: {
  3582.           int m, n;
  3583.           char mypath[CKMAXPATH+1];
  3584.           q = CXLOGFILE;
  3585.           m = ckstrncpy(mypath,homepath(),CKMAXPATH);
  3586.           n = strlen(CXLOGFILE);
  3587.           if (m + n < CKMAXPATH)
  3588.             ckstrncat(mypath,CXLOGFILE,CKMAXPATH);
  3589.           else
  3590.             ckstrncpy(mypath,CXLOGFILE,CKMAXPATH);
  3591.           y = cmofi("Name of connection log file",mypath,&s,xxstring);
  3592.           break;
  3593.       }
  3594. #endif /* CKLOGDIAL */
  3595.  
  3596.       default:
  3597.         printf("\n?Unknown log designator - %d\n",x);
  3598.         return(-2);
  3599.     }
  3600.     if (y < 0) return(y);
  3601.     if (y == 2) {                       /* If they gave a directory name */
  3602.         int k;
  3603.         char * ds = "/";
  3604.         k = strlen(s);
  3605.         if (k > 0 && s[k-1] == '/') ds = "";
  3606.         ckmakmsg(tmpbuf,TMPBUFSIZ,s,ds,q,NULL);
  3607.         s = tmpbuf;
  3608.     }
  3609. #ifdef ZFNQFP
  3610. #ifdef OS2ORUNIX
  3611.     if (*s != '|')                      /* Allow for pipes */
  3612. #else
  3613. #ifdef OSK
  3614.     if (*s != '|')
  3615. #endif /* OSK */
  3616. #endif /* OS2ORUNIX */
  3617.       if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3618.           if (fnp->fpath)
  3619.             if ((int) strlen(fnp->fpath) > 0)
  3620.               s = fnp->fpath;
  3621.       } /* else if error keep original string */
  3622. #endif /* ZFNQFP */
  3623.  
  3624.     ckstrncpy(line,s,LINBUFSIZ);
  3625.     s = line;
  3626. #ifdef MAC
  3627.     y = 0;
  3628. #else
  3629.  
  3630.     p = "new";
  3631. #ifdef TLOG
  3632.     if ((x == LOGT && tlogfmt == 2) || x == LOGM)
  3633.       p = "append";
  3634. #endif /* TLOG */
  3635.  
  3636.     if ((y = cmkey(disptb,2,"Disposition",p,xxstring)) < 0)
  3637.       return(y);
  3638. #endif /* MAC */
  3639.     disp = y;
  3640.     if ((y = cmcfm()) < 0) return(y);
  3641.  
  3642.     switch (x) {
  3643.  
  3644. #ifdef DEBUG
  3645.       case LOGD:
  3646.         return(deblog = debopn(s,disp));
  3647. #endif /* DEBUG */
  3648.  
  3649. #ifndef NOXFER
  3650.       case LOGP:
  3651.         return(pktlog = pktopn(s,disp));
  3652. #endif /* NOXFER */
  3653.  
  3654. #ifndef NOLOCAL
  3655.       case LOGS:
  3656.         setseslog(sesopn(s,disp));
  3657.         return(seslog);
  3658. #endif /* NOLOCAL */
  3659.  
  3660. #ifdef TLOG
  3661.       case LOGT:
  3662.         return(tralog = traopn(s,disp));
  3663. #endif /* TLOG */
  3664.  
  3665. #ifdef CKLOGDIAL
  3666.       case LOGM:
  3667.         return(dialog = diaopn(s,disp,0));
  3668. #endif /* CKLOGDIAL */
  3669.  
  3670.       default:
  3671.         return(-2);
  3672.     }
  3673. }
  3674.  
  3675. #ifndef NOXFER
  3676. int
  3677. pktopn(s,disp) char *s; int disp; {
  3678.     static struct filinfo xx;
  3679.  
  3680.     if (!s)
  3681.       s = "";
  3682.     if (!*s)
  3683.       return(0);
  3684.  
  3685.     debug(F111,"pktopn",s,disp);
  3686.  
  3687.     zclose(ZPFILE);
  3688.  
  3689. #ifdef OS2ORUNIX
  3690.     if (s[0] == '|') {                  /* Pipe */
  3691.         char * p = s + 1;
  3692.         debug(F110,"pktopn p",p,0);
  3693.         while (*p) {
  3694.             if (*p != ' ')
  3695.               break;
  3696.             else
  3697.               p++;
  3698.         }
  3699.         debug(F110,"pktopn pipe",p,0);
  3700.         pktlog = zxcmd(ZPFILE,p);
  3701.         debug(F101,"pktopn seslog","",seslog);
  3702.     } else {                            /* File */
  3703. #endif /* OS2ORUNIX */
  3704.         if (disp) {
  3705.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3706.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3707.             xx.lblopts = 0;
  3708.             pktlog = zopeno(ZPFILE,s,NULL,&xx);
  3709.         } else pktlog = zopeno(ZPFILE,s,NULL,NULL);
  3710.         if (!pktlog)
  3711.           printf("?%s - %s\n",s,ck_errstr());
  3712. #ifdef OS2ORUNIX
  3713.     }
  3714. #endif /* OS2ORUNIX */
  3715.     if (pktlog > 0)
  3716.       ckstrncpy(pktfil,s,CKMAXPATH+1);
  3717.     else
  3718.       *pktfil = '\0';
  3719.     return(pktlog);
  3720. }
  3721. #endif /* NOXFER */
  3722.  
  3723. int
  3724. traopn(s,disp) char *s; int disp; {
  3725. #ifdef TLOG
  3726.     static struct filinfo xx;
  3727.  
  3728.     if (!s)
  3729.       s = "";
  3730.     if (!*s)
  3731.       return(0);
  3732.  
  3733.     debug(F111,"traopn",s,disp);
  3734.     debug(F101,"traopn tlogfmt","",tlogfmt);
  3735.  
  3736.     zclose(ZTFILE);
  3737.  
  3738. #ifdef OS2ORUNIX
  3739.     if (tlogfmt == 2) {                 /* FTP format is special... */
  3740.         VOID doiklog();
  3741.         if (!disp)                      /* Append? */
  3742.           if (zchki(s) > -1)            /* No - does file exist? */
  3743.             (VOID) zdelet(s);           /* Yes - delete it. */
  3744.         xferlog = 1;
  3745.         ckstrncpy(trafil,s,CKMAXPATH);
  3746.         makestr(&xferfile,s);
  3747.         doiklog();
  3748.         return(1);
  3749.     }
  3750.     if (s[0] == '|') {                  /* Pipe */
  3751.         char * p = s + 1;
  3752.         debug(F110,"traopn p",p,0);
  3753.         while (*p) {
  3754.             if (*p != ' ')
  3755.               break;
  3756.             else
  3757.               p++;
  3758.         }
  3759.         debug(F110,"traopn pipe",p,0);
  3760.         tralog = zxcmd(ZTFILE,p);
  3761.         debug(F101,"traopn tralog","",tralog);
  3762.     }
  3763. #endif /* OS2ORUNIX */
  3764.  
  3765.     if (s[0] != '|') {                  /* File */
  3766.         if (disp) {
  3767.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3768.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3769.             xx.lblopts = 0;
  3770.             tralog = zopeno(ZTFILE,s,NULL,&xx);
  3771.         } else tralog = zopeno(ZTFILE,s,NULL,NULL);
  3772.     }
  3773.     if (!tralog)
  3774.       printf("?%s - %s\n",s,ck_errstr());
  3775.     if (tralog > 0 && tlogfmt > 0) {
  3776.         ckstrncpy(trafil,s,CKMAXPATH);
  3777.         tlog(F110,"Transaction Log:",versio,0L);
  3778. #ifndef MAC
  3779.         tlog(F100,ckxsys,"",0L);
  3780. #endif /* MAC */
  3781.         ztime(&s);
  3782.         tlog(F100,s,"",0L);
  3783.     } else
  3784.       *trafil = '\0';
  3785.     return(tralog);
  3786. #else
  3787.     return(0);
  3788. #endif /* TLOG */
  3789. }
  3790.  
  3791. #ifndef NOLOCAL
  3792. int
  3793. sesopn(s,disp) char * s; int disp; {
  3794.     static struct filinfo xx;
  3795.     extern int tsstate;
  3796.  
  3797.     tsstate = 0;                        /* Session log timestamp state */
  3798.  
  3799.     if (!s)
  3800.       s = "";
  3801.     if (!*s)
  3802.       return(0);
  3803.  
  3804.     debug(F111,"sesopn",s,disp);
  3805.  
  3806.     zclose(ZSFILE);
  3807.  
  3808. #ifdef OS2ORUNIX
  3809.     if (s[0] == '|') {                  /* Pipe */
  3810.         char * p = s + 1;
  3811.         debug(F110,"sesopn p",p,0);
  3812.         while (*p) {
  3813.             if (*p != ' ')
  3814.               break;
  3815.             else
  3816.               p++;
  3817.         }
  3818.         debug(F110,"sesopn pipe",p,0);
  3819.         setseslog(zxcmd(ZSFILE,p));
  3820.         debug(F101,"sesopn seslog","",seslog);
  3821.     } else {                            /* File */
  3822. #endif /* OS2ORUNIX */
  3823.         if (disp) {
  3824.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3825.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3826.             xx.lblopts = 0;
  3827.             setseslog(zopeno(ZSFILE,s,NULL,&xx));
  3828.         } else
  3829.           setseslog(zopeno(ZSFILE,s,NULL,NULL));
  3830.         if (!seslog)
  3831.           printf("?%s - %s\n",s,ck_errstr());
  3832. #ifdef OS2ORUNIX
  3833.     }
  3834. #endif /* OS2ORUNIX */
  3835.     if (seslog > 0)
  3836.       ckstrncpy(sesfil,s,CKMAXPATH+1);
  3837.     else
  3838.       *sesfil = '\0';
  3839.     return(seslog);
  3840. }
  3841. #endif /* NOLOCAL */
  3842. #endif /* NOICP */
  3843.  
  3844. int
  3845. debopn(s,disp) char *s; int disp; {
  3846. #ifdef DEBUG
  3847. #ifdef CK_UTSNAME
  3848.     extern char unm_mch[], unm_nam[], unm_rel[], unm_ver[], unm_mod[];
  3849. #endif /* CK_UTSNAME */
  3850. #ifdef OS2
  3851.     extern char ckxsystem[];
  3852. #endif /* OS2 */
  3853.     char *tp;
  3854.     static struct filinfo xx;
  3855.  
  3856.     if (!s)
  3857.       s = "";
  3858.     if (!*s)
  3859.       return(0);
  3860.  
  3861.     zclose(ZDFILE);
  3862.  
  3863. #ifdef OS2ORUNIX
  3864.     if (s[0] == '|') {                  /* Pipe */
  3865.         char * p = s + 1;
  3866.         debug(F110,"debopn p",p,0);
  3867.         while (*p) {
  3868.             if (*p != ' ')
  3869.               break;
  3870.             else
  3871.               p++;
  3872.         }
  3873.         debug(F110,"debopn pipe",p,0);
  3874.         deblog = zxcmd(ZDFILE,p);
  3875.         debug(F101,"debopn deblog","",deblog);
  3876.     } else {                            /* File */
  3877. #endif /* OS2ORUNIX */
  3878.         if (disp) {
  3879.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3880.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3881.             xx.lblopts = 0;
  3882.             deblog = zopeno(ZDFILE,s,NULL,&xx);
  3883.         } else
  3884.           deblog = zopeno(ZDFILE,s,NULL,NULL);
  3885.         if (!deblog)
  3886.           printf("?%s - %s\n",s,ck_errstr());
  3887. #ifdef OS2ORUNIX
  3888.     }
  3889. #endif /* OS2ORUNIX */
  3890.     if (deblog > 0) {
  3891.         ckstrncpy(debfil,s,CKMAXPATH+1);
  3892.         debug(F110,"Debug Log ",versio,0);
  3893. #ifndef MAC
  3894. #ifdef OS2
  3895.         debug(F110,ckxsys,ckxsystem,0);
  3896. #else /* OS2 */
  3897.         debug(F100,ckxsys,"",0);
  3898. #endif /* OS2 */
  3899. #endif /* MAC */
  3900. #ifdef CK_UTSNAME
  3901.         if (unm_mch[0]) {
  3902.             debug(F110,"uname machine",unm_mch,0);
  3903.             if (unm_mod[0])
  3904.               debug(F110,"uname model  ",unm_mod,0);
  3905.             debug(F110,"uname sysname",unm_nam,0);
  3906.             debug(F110,"uname release",unm_rel,0);
  3907.             debug(F110,"uname version",unm_ver,0);
  3908.         }
  3909. #ifdef KTARGET
  3910.         {
  3911.             char * s;                   /* Makefile target */
  3912.             s = KTARGET;
  3913.             if (!s) s = "";
  3914.             if (!*s) s = "(unknown)";
  3915.             debug(F110,"build target",s,0);
  3916.         }
  3917. #endif /* KTARGET */
  3918.         deblog = 0;
  3919.         ztime(&tp);
  3920.         deblog = 1;
  3921.         debug(F100,tp,"",0);
  3922. #endif /* UTSNAME */
  3923.         debug(F101,"byteorder","",byteorder);
  3924. #ifndef NOICP
  3925. #ifndef NOLOCAL
  3926.         if (local) {
  3927.             debug(F110,"Active connection: ",ttname,0);
  3928.             if (!network) {
  3929.                 debug(F101,"Speed","",speed);
  3930.                 if (hwparity)
  3931.                   debug(F110,"Parity[hardware]",parnam((char)hwparity),0);
  3932.                 else
  3933.                   debug(F110,"Parity",parnam((char)parity),0);
  3934.                 deblog = 0;
  3935.                 debug(F110,"Modem",gmdmtyp(),0);
  3936.                 deblog = 1;
  3937.             }
  3938.         } else {
  3939.             debug(F110,"Active connection: ","none",0);
  3940.         }
  3941. #endif /* NOLOCAL */
  3942. #endif /* NOICP */
  3943.     } else *debfil = '\0';
  3944.     return(deblog);
  3945. #else
  3946.     return(0);
  3947. #endif /* MAC */
  3948. }
  3949.  
  3950.  
  3951. /*  C K D A T E  --  Returns current date/time in standard format  */
  3952.  
  3953. static char nowbuf[18];
  3954.  
  3955. char *
  3956. ckdate() {
  3957.     extern struct keytab cmonths[];
  3958.     int x;
  3959.     char * t;                   /* Substitute today's date */
  3960.     char dbuf[32];
  3961.     ztime(&t);
  3962.  
  3963. /*  012345678901234567890123 */
  3964. /*  Sat Jul  4 12:16:43 1998 */
  3965.  
  3966.     ckstrncpy(dbuf,t,32);
  3967.     t = dbuf;
  3968.     debug(F110,"ckdate dbuf",dbuf,0);
  3969.     nowbuf[0] = t[20];
  3970.     nowbuf[1] = t[21];
  3971.     nowbuf[2] = t[22];
  3972.     nowbuf[3] = t[23];
  3973.  
  3974.     nowbuf[4] = NUL;
  3975.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3976.  
  3977.     t[7] = NUL;
  3978.     if ((x = lookup(cmonths,t+4,12,NULL)) < 0) {
  3979.         debug(F110,"ckdate bad month",t,0);
  3980.         return("<BAD_MONTH>");
  3981.     }
  3982.     sprintf(nowbuf+4,"%02d",x);         /* SAFE */
  3983.     nowbuf[6] = (t[8] == SP) ? '0' : t[8];
  3984.     nowbuf[7] = t[9];
  3985.     nowbuf[8] = ' ';
  3986.  
  3987.     nowbuf[9] = NUL;
  3988.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3989.  
  3990.     for (x = 11; x < 19; x++) nowbuf[x-2] = t[x];
  3991.     nowbuf[17] = NUL;
  3992.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3993.  
  3994.     return((char *)nowbuf);
  3995. }
  3996.  
  3997. #ifndef NOICP
  3998. #ifdef CKLOGDIAL
  3999.  
  4000. /*
  4001.   fc = 0 for initial open, meaning open, then close immediately.
  4002.   fc > 0 for subsequent opens, meaning open for use, leave open.
  4003. */
  4004. int
  4005. diaopn(s,disp,fc) char *s; int disp, fc; {
  4006.     static struct filinfo xx;
  4007.  
  4008.     if (!s)
  4009.       s = "";
  4010.     if (!*s)
  4011.       return(0);
  4012.  
  4013.     debug(F110,"diaopn log",s,0);
  4014.     debug(F101,"diaopn fc",s,fc);
  4015.     debug(F101,"diaopn disp 1",s,disp);
  4016.     if (fc) disp = 1;                   /* Force append if open for use */
  4017.     debug(F101,"diaopn disp 2",s,disp);
  4018.  
  4019.     zclose(ZDIFIL);                     /* In case a log was already open */
  4020.  
  4021. #ifdef OS2ORUNIX
  4022.     if (s[0] == '|') {                  /* Pipe */
  4023.         char * p = s + 1;
  4024.         debug(F110,"diaopn p",p,0);
  4025.         while (*p) {
  4026.             if (*p != ' ')
  4027.               break;
  4028.             else
  4029.               p++;
  4030.         }
  4031.         debug(F110,"diaopn pipe",p,0);
  4032.         dialog = zxcmd(ZDIFIL,p);
  4033.         debug(F101,"diaopn dialog","",dialog);
  4034.     } else {                            /* File */
  4035. #endif /* OS2ORUNIX */
  4036.         if (disp) {
  4037.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  4038.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  4039.             xx.lblopts = 0;
  4040.             dialog = zopeno(ZDIFIL,s,NULL,&xx);
  4041.         } else dialog = zopeno(ZDIFIL,s,NULL,NULL);
  4042.         if (!dialog)
  4043.           printf("?%s - %s\n",s,ck_errstr());
  4044. #ifdef OS2ORUNIX
  4045.     }
  4046. #endif /* OS2ORUNIX */
  4047.     if (dialog > 0)
  4048.       ckstrncpy(diafil,s,CKMAXPATH+1);
  4049.     else
  4050.       *diafil = '\0';
  4051.     if (fc == 0)                        /* Initial open */
  4052.       zclose(ZDIFIL);                   /* close it */
  4053.     return(dialog);
  4054. }
  4055. #endif /* CKLOGDIAL */
  4056.  
  4057. #ifndef NOSHOW
  4058.  
  4059. /*  SHOW command routines */
  4060.  
  4061. char *
  4062. shoxm() {
  4063.     char * s;
  4064.     switch (binary) {
  4065.       case XYFT_T: s = "text";         break;
  4066. #ifdef VMS
  4067.       case XYFT_B: s = "binary fixed"; break;
  4068.       case XYFT_I: s = "image";        break;
  4069.       case XYFT_L: s = "labeled";      break;
  4070.       case XYFT_U: s = "binary undef"; break;
  4071. #else
  4072. #ifdef MAC
  4073.       case XYFT_B: s = "binary";       break;
  4074.       case XYFT_M: s = "macbinary";    break;
  4075. #else
  4076.       case XYFT_B: s = "binary";       break;
  4077. #ifdef CK_LABELED
  4078.       case XYFT_L: s = "labeled";      break;
  4079. #endif /* CK_LABELED */
  4080. #endif /* MAC */
  4081. #endif /* VMS */
  4082.       default: s = "unknown"; break;
  4083.     }
  4084.     return(s);
  4085. }
  4086.  
  4087. #ifndef NOXFER
  4088. VOID                                    /* SHOW TRANSFER */
  4089. shoxfer() {
  4090.     extern int docrc, usepipes, xfrxla, whereflg;
  4091.     extern char * xfrmsg;
  4092.     printf("\n");
  4093.     printf(" Transfer Bell: %s\n",showoff(xfrbel));
  4094.     printf(" Transfer Interruption: %s\n",showoff(xfrint));
  4095.     printf(" Transfer Cancellation: %s\n",showoff(xfrcan));
  4096. #ifndef NOCSETS
  4097.     printf(" Transfer Translation:  %s\n",showoff(xfrxla));
  4098.     printf(" Transfer Character-set: ");
  4099.     if (tcharset == TC_TRANSP)
  4100.       printf("Transparent\n");
  4101.     else
  4102.       printf("%s\n",tcsinfo[tcharset].keyword);
  4103. #endif /* NOCSETS */
  4104.     printf(" Transfer CRC-calculation: %s\n",showoff(docrc));
  4105.     printf(" Transfer Display: ");
  4106.     switch (fdispla) {
  4107.       case XYFD_N: printf("%s\n","none"); break;
  4108.       case XYFD_R: printf("%s\n","serial"); break;
  4109.       case XYFD_C: printf("%s\n","fullscreen"); break;
  4110.       case XYFD_S: printf("%s\n","crt"); break;
  4111.       case XYFD_B: printf("%s\n","brief"); break;
  4112.       case XYFD_G: printf("%s\n","gui"); break;
  4113.     }
  4114.     printf(" Transfer Message: %s\n", xfrmsg ? xfrmsg : "(none)");
  4115.     printf(" Transfer Locking-shift: ");
  4116.     if (lscapu == 2) {
  4117.         printf("forced");
  4118.     } else {
  4119.         printf("%s", (lscapr ? "enabled" : "disabled"));
  4120.         if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  4121.     }
  4122.     printf("\n Transfer Mode: %s\n",
  4123.            xfermode == XMODE_A ?
  4124.            "automatic" :
  4125.            "manual"
  4126.            );
  4127.     printf(" Transfer Pipes: %s\n", showoff(usepipes));
  4128.     printf(" Transfer Protocol: %s\n",ptab[protocol].p_name);
  4129.     printf(" Transfer Report: %s\n",showoff(whereflg));
  4130.     printf(" Transfer Slow-start: %s\n",showoff(slostart));
  4131.     printf("\n");
  4132. }
  4133. #endif /* NOXFER */
  4134.  
  4135. VOID
  4136. shoflow() {
  4137.     int i, x;
  4138.     extern int cxflow[], cxtype, ncxname, nfloname, autoflow;
  4139.     extern char * cxname[];
  4140.     printf("\nConnection type:        %s\n",cxname[cxtype]);
  4141.     if (autoflow) {
  4142.         printf("Current flow-control:   %s\n", floname[cxflow[cxtype]]);
  4143.         printf("Switches automatically: yes\n");
  4144.     } else {
  4145.         printf("Current flow-control:   %s\n", floname[flow]);
  4146.         printf("Switches automatically: no\n");
  4147.     }
  4148.     printf("\nDefaults by connection type:\n");
  4149.     debug(F111,"shoflow cxtype",cxname[cxtype],cxtype);
  4150.     debug(F101,"shoflow flow","",flow);
  4151.     for (i = 0; i < ncxname; i++) {
  4152. #ifdef NOLOCAL
  4153.         if (i > 0) break;
  4154. #endif /* NOLOCAL */
  4155. #ifndef NETCONN
  4156.         if (i > 2) break;
  4157. #endif /* NETCONN */
  4158. #ifndef DECNET
  4159.         if (i == CXT_DECNET) continue;
  4160. #endif /* DECNET */
  4161. #ifndef DECNET
  4162. #ifndef SUPERLAT
  4163.         if (i == CXT_LAT) continue;
  4164. #endif /* SUPERLAT */
  4165. #endif /* DECNET */
  4166. #ifndef CK_NETBIOS
  4167.         if (i == CXT_NETBIOS) continue;
  4168. #endif /* CK_NETBIOS */
  4169. #ifndef NPIPE
  4170.         if (i == CXT_NPIPE) continue;
  4171. #endif /* NPIPE */
  4172. #ifndef NETCMD
  4173.         if (i == CXT_PIPE) continue;
  4174. #endif /* NETCMD */
  4175. #ifndef ANYX25
  4176.         if (i == CXT_X25) continue;
  4177. #endif /* ANYX25 */
  4178.         x = cxflow[i];
  4179.         debug(F101,"shoflow x","",x);
  4180.         if (x < nfloname)
  4181.           printf("  %-14s: %s\n",cxname[i],floname[x]);
  4182.         else
  4183.           printf("  %-14s: (%d)\n",cxname[i],x);
  4184.     }
  4185.     printf("\n");
  4186. }
  4187.  
  4188. #ifndef NOLOCAL
  4189. #ifdef ANYX25
  4190. int
  4191. shox25(n) int n; {
  4192.     if (nettype == NET_SX25) {
  4193.         printf("SunLink X.25 V%d.%d",x25ver / 10,x25ver % 10);
  4194.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4195.         printf("\n");
  4196.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4197.         printf(" Reverse charge call %s",
  4198.                revcall ? "selected" : "not selected");
  4199.         printf (", Closed user group ");
  4200.         if (closgr > -1)
  4201.           printf ("%d",closgr);
  4202.         else
  4203.           printf ("not selected");
  4204.         printf("\n");
  4205.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4206.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4207.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4208.     } else if (nettype == NET_VX25) {
  4209.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4210.         printf("\n");
  4211.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4212.         printf(" Reverse charge call %s",
  4213.                revcall ? "selected" : "not selected");
  4214.         printf (", Closed user group [unsupported]");
  4215.         if (closgr > -1)
  4216.           printf ("%d",closgr);
  4217.         else
  4218.           printf ("not selected");
  4219.         printf (",");
  4220.         printf("\n");
  4221.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4222.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4223.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4224.     } else if (nettype == NET_IX25) {
  4225.         printf("AIX NPI X.25\n");
  4226.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4227.         printf("\n Reverse charge call %s",
  4228.                revcall ? "selected" : "not selected");
  4229.         printf (", Closed user group [unsupported]");
  4230.         if (closgr > -1)
  4231.           printf ("%d",closgr);
  4232.         else
  4233.           printf ("not selected");
  4234.         printf (",");
  4235.         printf("\n Call user data %s.\n", cudata ? udata : "not selected");
  4236.     }
  4237.     return(n);
  4238. }
  4239.  
  4240. #ifndef IBMX25
  4241. int
  4242. shopad(n) int n; {
  4243.     int i;
  4244.     printf("\nX.3 PAD Parameters:\n");
  4245.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4246.     for (i = 0; i < npadx3; i++) {
  4247.         printf(" [%d] %s %d\n",padx3tab[i].kwval,padx3tab[i].kwd,
  4248.                padparms[padx3tab[i].kwval]);
  4249.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4250.     }
  4251.     return(n);
  4252. }
  4253. #endif /* IBMX25 */
  4254. #endif /* ANYX25 */
  4255.  
  4256. VOID
  4257. shoparc() {
  4258.     extern int reliable, stopbits, clsondisc;
  4259.     int i; char *s;
  4260.     long zz;
  4261.  
  4262. #ifdef NEWFTP
  4263.     if (ftpisconnected()) {
  4264.         shoftp(1);
  4265.         printf("\n");
  4266.     }
  4267. #endif /* NEWFTP */
  4268.  
  4269.     printf("Communications Parameters:\n");
  4270.  
  4271.     if (network
  4272. #ifdef IKSD
  4273.          || inserver
  4274. #endif /* IKSD */
  4275.          ) {
  4276.         printf(" Network Host: %s%s",ttname,
  4277.                (reliable == SET_ON || (reliable == SET_AUTO && !local)
  4278. #ifdef TN_COMPORT
  4279.                && !istncomport()
  4280. #endif /* TN_COMPORT */
  4281. #ifdef IKSD
  4282.                || inserver
  4283. #endif /* IKSD */
  4284.                ) ? " (reliable)" : "");
  4285. #ifdef TN_COMPORT
  4286.         if (istncomport()) {
  4287.             int modemstate;
  4288.             char * oflow, * iflow = "", * parity, * stopsize;
  4289.             int baud = tnc_get_baud();
  4290.  
  4291.             switch (tnc_get_oflow()) {
  4292.               case TNC_CTL_OFLOW_NONE:
  4293.                 oflow = "none";
  4294.                 break;
  4295.               case TNC_CTL_OFLOW_XON_XOFF:
  4296.                 oflow = "xon/xoff";
  4297.                 break;
  4298.               case TNC_CTL_OFLOW_RTS_CTS:
  4299.                 oflow = "rts/cts";
  4300.                 break;
  4301.               case TNC_CTL_OFLOW_DCD:
  4302.                 oflow = "dcd";
  4303.                 break;
  4304.               case TNC_CTL_OFLOW_DSR:
  4305.                 oflow = "dsr";
  4306.                 break;
  4307.               default:
  4308.                 oflow = "(unknown)";
  4309.             }
  4310.             switch (tnc_get_iflow()) {
  4311.               case TNC_CTL_IFLOW_NONE:
  4312.                 iflow = "none";
  4313.                 break;
  4314.               case TNC_CTL_IFLOW_XON_XOFF:
  4315.                 iflow = "xon/xoff";
  4316.                 break;
  4317.               case TNC_CTL_IFLOW_RTS_CTS:
  4318.                 iflow = "rts/cts";
  4319.                 break;
  4320.               case TNC_CTL_IFLOW_DTR:
  4321.                 break;
  4322.               default:
  4323.                 iflow = oflow;
  4324.             }
  4325.             switch (tnc_get_parity()) {
  4326.               case TNC_PAR_NONE:
  4327.                 parity = "none";
  4328.                 break;
  4329.               case TNC_PAR_ODD:
  4330.                 parity = "odd";
  4331.                 break;
  4332.               case TNC_PAR_EVEN:
  4333.                 parity = "even";
  4334.                 break;
  4335.               case TNC_PAR_MARK:
  4336.                 parity = "mark";
  4337.                 break;
  4338.               case TNC_PAR_SPACE:
  4339.                 parity = "space";
  4340.                 break;
  4341.               default:
  4342.                 parity = "(unknown)";
  4343.             }
  4344.             switch (tnc_get_stopsize()) {
  4345.               case TNC_SB_1:
  4346.                 stopsize = "1";
  4347.                 break;
  4348.               case TNC_SB_1_5:
  4349.                 stopsize = "1.5";
  4350.                 break;
  4351.               case TNC_SB_2:
  4352.                 stopsize = "2";
  4353.                 break;
  4354.               default:
  4355.                 stopsize = "(unknown)";
  4356.             }
  4357.             printf("\n  Signature            : %s\n", tnc_get_signature());
  4358.             if (baud <= 0)
  4359.               printf("  Speed                : (unknown)\n");
  4360.             else
  4361.               printf("  Speed                : %d\n", baud);
  4362.             printf("  Outbound Flow Control: %s\n", oflow);
  4363.             printf("  Inbound Flow Control : %s\n", iflow);
  4364.             printf("  Parity               : %s\n", parity);
  4365.             printf("  Data Size            : %d\n", tnc_get_datasize());
  4366.             printf("  Stop Bits            : %s\n", stopsize);
  4367.             printf("  DTR Signal           : %d\n", tnc_get_dtr_state());
  4368.             printf("  RTS Signal           : %d\n", tnc_get_rts_state());
  4369.             printf("  Modem State:\n");
  4370.             modemstate = tnc_get_ms();
  4371.             if (modemstate & TNC_MS_EDGE_RING)
  4372.               printf("    Trailing Edge Ring Detector On\n");
  4373.             else
  4374.               printf("    Trailing Edge Ring Detector Off\n");
  4375.             if (modemstate & TNC_MS_CTS_SIG)
  4376.               printf("    CTS Signal On\n");
  4377.             else
  4378.               printf("    CTS Signal Off\n");
  4379.             if (modemstate & TNC_MS_DSR_SIG)
  4380.               printf("    DSR Signal On\n");
  4381.             else
  4382.               printf("    DSR Signal Off\n");
  4383.             if (modemstate & TNC_MS_RI_SIG)
  4384.               printf("    Ring Indicator On\n");
  4385.             else
  4386.               printf("    Ring Indicator Off\n");
  4387.             if (modemstate & TNC_MS_RLSD_SIG)
  4388.               printf("    RLSD (CD) Signal On\n");
  4389.             else
  4390.               printf("    RLSD (CD) Signal Off\n");
  4391.             printf("\n");
  4392.         }
  4393. #endif /* TN_COMPORT */
  4394.     } else {
  4395.  
  4396.         printf(" %s: %s%s, speed: ",
  4397. #ifdef OS2
  4398.                "Port",
  4399. #else
  4400.                "Line",
  4401. #endif /* OS2 */
  4402.                ttname,
  4403. #ifdef CK_TTYFD
  4404.                (local &&
  4405. #ifdef VMS
  4406.                 vmsttyfd() < 0
  4407. #else
  4408.                 ttyfd == -1
  4409. #endif /* VMS */
  4410.                 ) ?
  4411.                  " (closed)" :
  4412.                    (reliable == SET_ON ? " (reliable)" : "")
  4413. #else
  4414.                ""
  4415. #endif /* CK_TTYFD */
  4416.                );
  4417.         if (
  4418. #ifdef CK_TTYFD
  4419. #ifdef VMS
  4420.             vmsttyfd() < 0
  4421. #else
  4422.             ttyfd == -1
  4423. #endif /* VMS */
  4424.             ||
  4425. #endif /* CK_TTYFD */
  4426.             (zz = ttgspd()) < 0) {
  4427.             printf("unknown");
  4428.         } else {
  4429.             if (speed == 8880) printf("75/1200");
  4430.             else if (speed == 134) printf("134.5");
  4431.             else printf("%ld",zz);
  4432.         }
  4433.     }
  4434.     if (network
  4435. #ifdef IKSD
  4436.          || inserver
  4437. #endif /* IKSD */
  4438.          )
  4439.       printf("\n Mode: ");
  4440.     else
  4441.       printf(", mode: ");
  4442.     if (local) printf("local"); else printf("remote");
  4443.     if (network == 0
  4444. #ifdef IKSD
  4445.          && !inserver
  4446. #endif/* IKSD */
  4447.          ) {
  4448. #ifdef CK_TAPI
  4449.         if (tttapi && !tapipass )
  4450.           printf(", modem: %s","TAPI");
  4451.         else
  4452. #endif /* CK_TAPI */
  4453.         printf(", modem: %s",gmdmtyp());
  4454.     } else {
  4455. #ifdef NETCONN
  4456.        if (nettype == NET_TCPA) printf(", TCP/IP");
  4457.        if (nettype == NET_TCPB) printf(", TCP/IP");
  4458.        if (nettype == NET_DEC) {
  4459.            if (ttnproto == NP_LAT) printf(", DECnet LAT");
  4460.            else if ( ttnproto == NP_CTERM ) printf(", DECnet CTERM");
  4461.            else printf(", DECnet");
  4462.        }
  4463.        if (nettype == NET_SLAT) printf(", Meridian Technologies' SuperLAT");
  4464. #ifdef NETFILE
  4465.        if (nettype == NET_FILE) printf(", local file");
  4466. #endif /* NETFILE */
  4467. #ifdef NETCMD
  4468.        if (nettype == NET_CMD) printf(", pipe");
  4469. #endif /* NETCMD */
  4470. #ifdef NETPTY
  4471.        if (nettype == NET_PTY) printf(", pseudoterminal");
  4472. #endif /* NETPTY */
  4473. #ifdef NETDLL
  4474.        if (nettype == NET_DLL) printf(", dynamic load library");
  4475. #endif /* NETDLL */
  4476.        if (nettype == NET_PIPE) printf(", Named Pipes");
  4477. #ifdef SSHBUILTIN
  4478.        if (nettype == NET_SSH)
  4479.          printf(", Secure Shell protocol (SECURE)");
  4480. #endif /* SSHBUILTIN */
  4481. #ifdef ANYX25
  4482.        if (shox25(0) < 0) return;
  4483. #endif /* ANYX25 */
  4484.        if (IS_TELNET()) {
  4485.            printf(", telnet protocol");
  4486.            if (0
  4487. #ifdef CK_ENCRYPTION
  4488.                || ck_tn_encrypting() && ck_tn_decrypting()
  4489. #endif /* CK_ENCRYPTION */
  4490. #ifdef CK_SSL
  4491.                || tls_active_flag || ssl_active_flag
  4492. #endif /* CK_SSL */
  4493.                )
  4494.              printf(" (SECURE)");
  4495.        }
  4496. #ifdef RLOGCODE
  4497.        else if (ttnproto == NP_RLOGIN || ttnproto == NP_K4LOGIN ||
  4498.                 ttnproto == NP_K5LOGIN)
  4499.          printf(", rlogin protocol");
  4500.        else if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN)
  4501.          printf(", rlogin protocol (SECURE)");
  4502. #endif /* RLOGCODE */
  4503. #ifdef CK_KERBEROS
  4504. #ifdef KRB5
  4505.        else if (ttnproto == NP_K5U2U)
  4506.          printf(", Kerberos 5 User to User protocol (SECURE)");
  4507. #endif /* KRB5 */
  4508. #endif /* CK_KERBEROS */
  4509. #endif /* NETCONN */
  4510.     }
  4511.     printf("\n");
  4512.     if (hwparity && local && !network)
  4513.       s = parnam((char)hwparity);
  4514.     else
  4515.       s = parnam((char)parity);
  4516.     printf(" Parity: %s%s",hwparity ? "hardware " : "", s);
  4517. #ifndef NOLOCAL
  4518.     if (local && !network) {
  4519.         int sb;
  4520.         char c;
  4521.         c = s[0];
  4522.         if (islower(c)) c = toupper(c);
  4523.         sb = stopbits;
  4524.         if (sb < 1) {
  4525.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  4526.             printf(", stop-bits: (default)");
  4527.         } else {
  4528.             printf(", stop-bits: %d",sb);
  4529.         }
  4530.         if (hwparity)
  4531.           printf(" (8%c%d)",c,sb);
  4532.         else if (parity)
  4533.           printf(" (7%c%d)",c,sb);
  4534.         else
  4535.           printf(" (8N%d)",sb);
  4536.         printf("\n D");
  4537.     } else
  4538.       printf(", d");
  4539. #endif /* NOLOCAL */
  4540.  
  4541.     printf("uplex: %s, ", duplex ? "half" : "full");
  4542.     debug(F101,"shoparp flow","",flow);
  4543.     printf("flow: %s", floname[flow]);
  4544.     printf(", handshake: ");
  4545.     if (turn) printf("%d\n",turnch); else printf("none\n");
  4546. #ifdef COMMENT
  4547.     if (local && !network) {            /* SET CARRIER-WATCH */
  4548. #endif /* COMMENT */
  4549.         if (carrier == CAR_OFF) s = "off";
  4550.         else if (carrier == CAR_ON) s = "on";
  4551.         else if (carrier == CAR_AUT) s = "auto";
  4552.         else s = "unknown";
  4553.         printf(" Carrier-watch: %s", s);
  4554.         if (carrier == CAR_ON) {
  4555.             if (cdtimo) printf(", timeout: %d sec", cdtimo);
  4556.             else printf(", timeout: none");
  4557.         }
  4558. #ifdef COMMENT
  4559.     }
  4560. #endif /* COMMENT */
  4561.     printf(", close-on-disconnect: %s\n",showoff(clsondisc));
  4562.  
  4563. #ifdef UNIX                             /* UUCP lockfile, UNIX only */
  4564.     if (local) {
  4565. #ifndef NOUUCP
  4566.         if (!network && haslock && *flfnam)
  4567.           printf(" Lockfile: %s",flfnam);
  4568. #ifndef USETTYLOCK
  4569.         if (!network && haslock && lock2[0])
  4570.           printf("\n Secondary lockfile: %s",lock2);
  4571. #endif /* USETTYLOCK */
  4572. #else
  4573. #ifdef QNX
  4574.         {
  4575.             extern int qnxportlock, qnxopencount();
  4576.             if (local)
  4577.               printf(" Qnx-port-lock: %s, Open count: %d",
  4578.                      showoff(qnxportlock),
  4579.                      qnxopencount()
  4580.                      );
  4581.             else
  4582.               printf(" Qnx-port-lock: %s", showoff(qnxportlock));
  4583.         }
  4584. #endif /* QNX */
  4585. #endif /* NOUUCP */
  4586.         printf("\n");
  4587.     } else {
  4588.         char * s, * ttglckdir();
  4589.         s = ttglckdir();
  4590.         if (!s) s = "";
  4591.         printf(" Lockfile directory: %s\n", *s ? s : "(none)");
  4592.     }
  4593. #endif /* UNIX */
  4594.     if (!local) {
  4595.         printf(" Typical port device name: %s\n",ttgtpn());
  4596.     }
  4597.     if (local) {
  4598.         int i;
  4599.         i = parity ? 7 : 8;
  4600.         if (i == 8) i = (cmask == 0177) ? 7 : 8;
  4601.         printf(" Terminal bytesize: %d,",i);
  4602.         printf(" escape character: %d (^%c)\n",escape,ctl(escape));
  4603.     }
  4604. }
  4605.  
  4606. int
  4607. shotcp(n) int n; {
  4608. #ifdef TCPSOCKET
  4609.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  4610.         printf("SET TCP parameters:\n");
  4611.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4612.         printf(" Reverse DNS lookup: %s\n", showooa(tcp_rdns));
  4613.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4614.  
  4615. #ifdef CK_DNS_SRV
  4616.         printf(" DNS Service Records lookup: %s\n", showooa(tcp_dns_srv));
  4617.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4618. #endif /* CK_DNS_SRV */
  4619.  
  4620. #ifndef NOTCPOPTS
  4621. #ifdef SOL_SOCKET
  4622. #ifdef SO_KEEPALIVE
  4623.         printf(" Keepalive: %s\n", showoff(tcp_keepalive));
  4624.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4625. #endif /* SO_KEEPALIVE */
  4626.  
  4627. #ifdef SO_LINGER
  4628.         printf(" Linger: %s", tcp_linger ? "on, " : "off\n" );
  4629.         if (tcp_linger) {
  4630.             if (tcp_linger_tmo)
  4631.               printf("%d x 10 milliseconds\n",tcp_linger_tmo);
  4632.             else
  4633.               printf("no timeout\n");
  4634.         }
  4635.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4636. #endif /* SO_LINGER */
  4637.  
  4638. #ifdef SO_DONTROUTE
  4639.         printf(" DontRoute: %s\n", tcp_dontroute ? "on" : "off" );
  4640.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4641. #endif /* SO_DONTROUTE */
  4642.  
  4643. #ifdef TCP_NODELAY
  4644.         printf(" Nodelay: %s\n", showoff(tcp_nodelay));
  4645.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4646. #endif /* TCP_NODELAY */
  4647.  
  4648. #ifdef SO_SNDBUF
  4649.         if (tcp_sendbuf <= 0)
  4650.           printf(" Send buffer: (default size)\n");
  4651.         else
  4652.           printf(" Send buffer: %d bytes\n", tcp_sendbuf);
  4653.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4654. #endif /* SO_SNDBUF */
  4655. #ifdef SO_RCVBUF
  4656.         if (tcp_recvbuf <= 0)
  4657.           printf(" Receive buffer: (default size)\n");
  4658.         else
  4659.           printf(" Receive buffer: %d bytes\n", tcp_recvbuf);
  4660.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4661. #endif /* SO_RCVBUF */
  4662. #endif /* SOL_SOCKET */
  4663. #endif /* NOTCPOPTS */
  4664.         printf(" address: %s\n",tcp_address ? tcp_address : "(none)");
  4665.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4666. #ifndef NOHTTP
  4667.         printf(" http-proxy: %s\n",tcp_http_proxy ? tcp_http_proxy : "(none)");
  4668.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4669. #endif /* NOHTTP */
  4670. #ifdef NT
  4671. #ifdef CK_SOCKS
  4672.         printf(" socks-server: %s\n",tcp_socks_svr ? tcp_socks_svr : "(none)");
  4673.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4674. #ifdef CK_SOCKS_NS
  4675.         printf(" socks-name-server: %s\n",
  4676.                tcp_socks_ns ? tcp_socks_ns : "(none)");
  4677.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4678. #endif /* CK_SOCKS_NS */
  4679. #endif /* CK_SOCKS */
  4680. #endif /* NT */
  4681.     }
  4682. #endif /* TCPSOCKET */
  4683.     return(n);
  4684. }
  4685.  
  4686. #ifdef TNCODE
  4687. int
  4688. shotopt(n) int n; {
  4689.     int opt;
  4690.  
  4691.     printf("%-21s %12s %12s %12s %12s\n\n",
  4692.            "Telnet Option","Me (client)","U (client)",
  4693.            "Me (server)","U (server)");
  4694.     n += 2;
  4695.     if (n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4696.  
  4697.     for ( opt = TELOPT_FIRST; opt <= TELOPT_LAST; opt++) {
  4698.         switch (opt) {
  4699.           case TELOPT_AUTHENTICATION:
  4700.           case TELOPT_ENCRYPTION:
  4701.           case TELOPT_TTYPE:
  4702.           case TELOPT_NAWS:
  4703.           case TELOPT_BINARY:
  4704.           case TELOPT_NEWENVIRON:
  4705.           case TELOPT_SNDLOC:
  4706.           case TELOPT_XDISPLOC:
  4707.           case TELOPT_SGA:
  4708.           case TELOPT_ECHO:
  4709.           case TELOPT_KERMIT:
  4710.           case TELOPT_START_TLS:
  4711.           case TELOPT_FORWARD_X:
  4712.           case TELOPT_COMPORT:
  4713.             break;
  4714.           default:
  4715.             continue;
  4716.         }
  4717.         printf("%03d %-17s ",
  4718.                opt, TELOPT(opt)
  4719.                );
  4720.         printf("%12s %12s ",
  4721.                TELOPT_MODE(TELOPT_DEF_C_ME_MODE(opt)),
  4722.                TELOPT_MODE(TELOPT_DEF_C_U_MODE(opt))
  4723.                );
  4724.         printf("%12s %12s\n",
  4725.                TELOPT_MODE(TELOPT_DEF_S_ME_MODE(opt)),
  4726.                TELOPT_MODE(TELOPT_DEF_S_U_MODE(opt))
  4727.                );
  4728.  
  4729.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4730.         if (sstelnet)
  4731.           printf("%21s %12s %12s %12s %12s\n",
  4732.                  "",
  4733.                  "",
  4734.                  "",
  4735.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4736.                  (TELOPT_U(opt)?"DO":"DONT")
  4737.                  );
  4738.         else
  4739.           printf("%21s %12s %12s %12s %12s\n",
  4740.                  "",
  4741.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4742.                  (TELOPT_U(opt)?"DO":"DONT"),
  4743.                  "",
  4744.                  ""
  4745.                  );
  4746.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4747.     }
  4748.     return(n);
  4749. }
  4750.  
  4751. int
  4752. shotel(n) int n; {
  4753.     extern int tn_duplex;
  4754. #ifdef CK_ENVIRONMENT
  4755.     extern int tn_env_flg;
  4756.     extern char tn_env_acct[];
  4757.     extern char tn_env_job[];
  4758.     extern char tn_env_prnt[];
  4759.     extern char tn_env_sys[];
  4760.     extern char * tn_env_uservar[8][2];
  4761.     int x;
  4762. #endif /* CK_ENVIRONMENT */
  4763. #ifdef CK_SNDLOC
  4764.     extern char * tn_loc;
  4765. #endif /* CK_SNDLOC */
  4766.     printf("SET TELNET parameters:\n echo: %s\n NVT newline-mode: ",
  4767.            tn_duplex ? "local" : "remote");
  4768.     switch (tn_nlm) {
  4769.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4770.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4771.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4772.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4773.     }
  4774.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4775. #ifdef CK_AUTHENTICATION
  4776.     {
  4777.         int type = ck_tn_authenticated();
  4778.         printf(" authentication: ");
  4779.         switch (sstelnet ?
  4780.                 TELOPT_U_MODE(TELOPT_AUTHENTICATION) :
  4781.                  TELOPT_ME_MODE(TELOPT_AUTHENTICATION)
  4782.                 ) {
  4783.           case TN_NG_AC: printf( "accepted " ); break;
  4784.           case TN_NG_RF: printf( "refused  " ); break;
  4785.           case TN_NG_RQ: printf( "requested"); break;
  4786.           case TN_NG_MU: printf( "required "); break;
  4787.         }
  4788.  
  4789. #ifdef CK_SSL
  4790.         if ((ssl_active_flag || tls_active_flag) &&
  4791.              ck_tn_auth_valid() == AUTH_VALID &&
  4792.              (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  4793.                type == AUTHTYPE_NULL ||
  4794.                type == AUTHTYPE_AUTO))
  4795.             printf("   in use: X.509 certificate\n");
  4796.         else
  4797. #endif /* CK_SSL */
  4798.           printf("   in use: %s\n",AUTHTYPE_NAME(type));
  4799.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4800.         if (forward_flag)
  4801.           printf("  credentials forwarding requested %s\n",
  4802.                  forwarded_tickets ? "and completed" :
  4803.                  "but not completed");
  4804.         else
  4805.           printf("  credentials forwarding disabled\n");
  4806.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4807.     }
  4808. #endif /* CK_AUTHENTICATION */
  4809. #ifdef CK_ENCRYPTION
  4810.     {
  4811.         int i,x;
  4812.         int e_type = ck_tn_encrypting();
  4813.         int d_type = ck_tn_decrypting();
  4814.         char * e_str = NULL, * d_str = NULL;
  4815.         static struct keytab * tnetbl = NULL;
  4816.         static int ntnetbl = 0;
  4817.  
  4818.         x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  4819.  
  4820.         for (i = 0; i < ntnetbl; i++) {
  4821.             if (e_type == tnetbl[i].kwval)
  4822.               e_str = tnetbl[i].kwd;
  4823.             if (d_type == tnetbl[i].kwval)
  4824.               d_str = tnetbl[i].kwd;
  4825.         }
  4826.         printf(" encryption: ");
  4827.         switch (TELOPT_ME_MODE(TELOPT_ENCRYPTION)) {
  4828.           /* This should be changed to report both ME and U modes */
  4829.           case TN_NG_AC: printf( "accepted " ); break;
  4830.           case TN_NG_RF: printf( "refused  " ); break;
  4831.           case TN_NG_RQ: printf( "requested"); break;
  4832.           case TN_NG_MU: printf( "required "); break;
  4833.         }
  4834.         printf("       in use: ");
  4835.         switch ((e_type ? 1 : 0) | (d_type ? 2 : 0)) {
  4836.           case 0:
  4837.             printf("plain text in both directions");
  4838.             break;
  4839.           case 1:
  4840.             printf("%s output, plain text input",e_str);
  4841.             break;
  4842.           case 2:
  4843.             printf("plain text output, %s input",d_str);
  4844.             break;
  4845.           case 3:
  4846.             printf("%s output, %s input",e_str,d_str);
  4847.             break;
  4848.         }
  4849.         printf("\n");
  4850.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4851.     }
  4852. #endif /* CK_ENCRYPTION */
  4853. #ifdef IKS_OPTION
  4854.     printf(" kermit: ");
  4855.     switch (TELOPT_U_MODE(TELOPT_KERMIT)) {
  4856.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4857.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4858.       case TN_NG_RQ: printf( "u, requested; "); break;
  4859.       case TN_NG_MU: printf( "u, required;  "); break;
  4860.     }
  4861.     switch (TELOPT_ME_MODE(TELOPT_KERMIT)) {
  4862.       case TN_NG_AC: printf( "me, accepted;  " ); break;
  4863.       case TN_NG_RF: printf( "me, refused;   " ); break;
  4864.       case TN_NG_RQ: printf( "me, requested; "); break;
  4865.       case TN_NG_MU: printf( "me, required;  "); break;
  4866.     }
  4867.     if (TELOPT_U(TELOPT_KERMIT))
  4868.       printf(" u, %s",
  4869.              TELOPT_SB(TELOPT_KERMIT).kermit.u_start ?
  4870.              "started" :
  4871.              "stopped"
  4872.              );
  4873.     else
  4874.       printf(" u, n/a");
  4875.     if (TELOPT_ME(TELOPT_KERMIT))
  4876.       printf(" me, %s;",
  4877.              TELOPT_SB(TELOPT_KERMIT).kermit.me_start ?
  4878.              "started" :
  4879.              "stopped"
  4880.              );
  4881.     else
  4882.       printf(" me, n/a;");
  4883.     printf("\n");
  4884.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4885. #endif /* IKS_OPTION */
  4886.     printf(" BINARY newline-mode: ");
  4887.     switch (tn_b_nlm) {
  4888.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4889.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4890.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4891.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4892.     }
  4893.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4894.     printf(" binary-mode: ");
  4895.     switch (TELOPT_U_MODE(TELOPT_BINARY)) {
  4896.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4897.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4898.       case TN_NG_RQ: printf( "u, requested; "); break;
  4899.       case TN_NG_MU: printf( "u, required;  "); break;
  4900.     }
  4901.     switch (TELOPT_ME_MODE(TELOPT_BINARY)) {
  4902.       case TN_NG_AC: printf( "me, accepted; " ); break ;
  4903.       case TN_NG_RF: printf( "me, refused; " ); break;
  4904.       case TN_NG_RQ: printf( "me, requested; "); break;
  4905.       case TN_NG_MU: printf( "me, required;  "); break;
  4906.     }
  4907.     printf("u, %s; me, %s\n",
  4908.            TELOPT_U(TELOPT_BINARY) ? "BINARY" : "NVT",
  4909.            TELOPT_ME(TELOPT_BINARY) ? "BINARY" : "NVT"
  4910.            );
  4911.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4912.     printf(" binary-transfer-mode: %s\n",showoff(tn_b_xfer));
  4913.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4914.     printf(" bug binary-me-means-u-too: %s\n",showoff(tn_b_meu));
  4915.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4916.     printf(" bug binary-u-means-me-too: %s\n",showoff(tn_b_ume));
  4917.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4918.     printf(" bug sb-implies-will-do: %s\n",showoff(tn_sb_bug));
  4919.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4920.     printf(" terminal-type: ");
  4921.     if (tn_term) {
  4922.         printf("%s\n",tn_term);
  4923.     } else {
  4924.         char *p;
  4925. #ifdef OS2
  4926.         p = (tt_type >= 0 && tt_type <= max_tt) ?
  4927.           tt_info[tt_type].x_name :
  4928.             "UNKNOWN";
  4929. #else
  4930.         p = getenv("TERM");
  4931. #endif /* OS2 */
  4932.         if (p)
  4933.           printf("none (%s will be used)\n",p);
  4934.         else printf("none\n");
  4935.     }
  4936.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4937. #ifdef CK_ENVIRONMENT
  4938.     printf(" environment: %s\n", showoff(tn_env_flg));
  4939.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4940.     printf("   ACCOUNT: %s\n",tn_env_acct);
  4941.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4942.     printf("   DISPLAY: %s\n",(char *)tn_get_display() ?
  4943.             (char *)tn_get_display() : "");
  4944.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4945.     printf("   JOB    : %s\n",tn_env_job);
  4946.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4947.     printf("   PRINTER: %s\n",tn_env_prnt);
  4948.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4949. #ifndef NOSPL
  4950.     printf("   USER   : %s\n",uidbuf);
  4951.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4952. #endif /* NOSPL */
  4953.     printf("   SYSTEM : %s\n",tn_env_sys);
  4954.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4955.     for (x = 0; x < 8; x++) {
  4956.         if (tn_env_uservar[x][0] && tn_env_uservar[x][1]) {
  4957.             printf("   %-7s: %s\n",tn_env_uservar[x][0],
  4958.                    tn_env_uservar[x][1]);
  4959.             if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4960.         }
  4961.     }
  4962. #endif /* CK_ENVIRONMENT */
  4963. #ifdef CK_SNDLOC
  4964.     printf("  LOCATION: %s\n", tn_loc ? tn_loc : "");
  4965.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4966. #endif /* CK_SNDLOC */
  4967. #ifdef CK_FORWARD_X
  4968.     printf(" .Xauthority-file: %s\n", (char *)XauFileName() ?
  4969.             (char *)XauFileName() : "(none)");
  4970.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4971. #endif /* CK_FORWARD_X */
  4972.     return(n);
  4973. }
  4974. #endif /* TNCODE */
  4975.  
  4976. #ifdef CK_NETBIOS
  4977. static int
  4978. shonb(n) int n; {
  4979.     printf("NETBIOS parameters:\n");
  4980.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4981.     printf(" API       : %s\n",
  4982.            NetbeuiAPI ?
  4983.            "NETAPI.DLL - IBM Extended Services or Novell Netware Requester"
  4984.            : "ACSNETB.DLL - IBM Network Transport Services/2" ) ;
  4985.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4986.     printf(" Local Name: [%s]\n", NetBiosName);
  4987.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4988.     printf(" Adapter   : %d\n", NetBiosAdapter);
  4989.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4990.     if (NetBiosLSN > 0xFF) {
  4991.         printf(" Session   : %d\n", NetBiosLSN);
  4992.     } else {
  4993.         printf(" Session   : none active\n");
  4994.     }
  4995.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4996.     return(n);
  4997. }
  4998. #endif /* CK_NETBIOS */
  4999.  
  5000. #ifndef NONET
  5001. int
  5002. shonet() {
  5003.  
  5004. #ifndef NETCONN
  5005.     printf("\nNo networks are supported in this version of C-Kermit\n");
  5006.  
  5007. #else
  5008. #ifdef NOLOCAL
  5009.     printf("\nNo networks are supported in this version of C-Kermit\n");
  5010.  
  5011. #else /* rest of this routine */
  5012.  
  5013.     int i, n = 4;
  5014.  
  5015. #ifndef NODIAL
  5016.     if (nnetdir <= 1) {
  5017.         printf("\nNetwork directory: %s\n",netdir[0] ? netdir[0] : "(none)");
  5018.         n++;
  5019.     } else {
  5020.         int i;
  5021.         printf("\nNetwork directories:\n");
  5022.         for (i = 0; i < nnetdir; i++) {
  5023.             printf("%2d. %s\n",i,netdir[i]);
  5024.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5025.         }
  5026.     }
  5027. #endif /* NODIAL */
  5028.  
  5029. #ifdef SSHCMD
  5030.     {
  5031.         extern char * sshcmd;
  5032.         printf("SSH COMMAND: %s\n",sshcmd ? sshcmd : "ssh -e none");
  5033.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5034.     }
  5035. #endif /* SSHCMD */
  5036.  
  5037. #ifdef OS2
  5038.     printf("\nNetwork availability:\n");
  5039. #else
  5040.     printf("\nSupported networks:\n");
  5041. #endif /* OS2 */
  5042.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5043.  
  5044. #ifdef VMS
  5045.  
  5046. #ifdef TCPWARE
  5047.     printf(" Process Software Corporation TCPware for OpenVMS");
  5048. #else
  5049. #ifdef MULTINET
  5050.     printf(" TGV MultiNet TCP/IP");
  5051. #else
  5052. #ifdef WINTCP
  5053.     printf(" WOLLONGONG WIN/TCP");
  5054. #else
  5055. #ifdef DEC_TCPIP
  5056.     {
  5057.         static $DESCRIPTOR(tcp_desc,"_TCP0:");
  5058.         int status;
  5059.         long devclass;
  5060.         static int itmcod = DVI$_DEVCLASS;
  5061.  
  5062. #ifdef COMMENT
  5063.         status = LIB$GETDVI(&itmcod, 0, &tcp_desc, &devclass);
  5064. #else
  5065.         /* Martin Zinser 9/96 */
  5066.         status = lib$getdvi(&itmcod, 0, &tcp_desc, &devclass);
  5067. #endif /* COMMENT */
  5068.         if ((status & 1) && (devclass == DC$_SCOM))
  5069.           printf(" Process Software Corporation TCPware for OpenVMS");
  5070.         else
  5071. #ifdef UCX50
  5072.           printf(" DEC TCP/IP Services for (Open)VMS 5.0");
  5073. #else
  5074.           printf(" DEC TCP/IP Services for (Open)VMS");
  5075. #endif /* UCX50 */
  5076.     }
  5077. #else
  5078. #ifdef CMU_TCPIP
  5079.     printf(" CMU-OpenVMS/IP");
  5080. #else
  5081.     printf(" None");
  5082. #endif /* CMU_TCPIP */
  5083. #endif /* DEC_TCPIP */
  5084. #endif /* WINTCP */
  5085. #endif /* MULTINET */
  5086. #endif /* TCPWARE */
  5087.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5088. #ifdef TNCODE
  5089.     printf(", TELNET protocol\n\n");
  5090.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5091.     n = shotel(n);
  5092.     if (n < 0) return(0);
  5093.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5094. #endif /* TNCODE */
  5095.     printf("\n");
  5096.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5097.     printf("\n");
  5098.     n = shotcp(++n);
  5099.     if (n < 0) return(0);
  5100. #else /* Not VMS */
  5101.  
  5102. #ifdef SUNX25
  5103.     printf(" SunLink X.25\n");
  5104.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5105. #endif /* SUNX25 */
  5106.  
  5107. #ifdef STRATUSX25
  5108.     printf(" Stratus VOS X.25\n");
  5109.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5110. #endif /* STRATUSX25 */
  5111.  
  5112. #ifdef IBMX25
  5113.     printf(" IBM AIX X.25\n");
  5114.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5115. #endif /* IBMX25 */
  5116.  
  5117. #ifdef HPX25
  5118.     printf(" HP-UX X.25\n");
  5119.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5120. #endif /* HPX25 */
  5121.  
  5122. #ifdef SSHBUILTIN
  5123.     if (ck_ssleay_is_installed())
  5124.         printf(" SSH V1 and V2 protocols\n");
  5125.     else
  5126.         printf(" SSH V1 and V2 protocols - not available\n");
  5127. #endif /* SSHBUILTIN */
  5128.  
  5129. #ifdef DECNET
  5130. #ifdef OS2
  5131. #ifdef NT
  5132.     if (dnet_avail)
  5133.       printf(" DECnet, LAT and CTERM protocols\n");
  5134.     else
  5135.       printf(" DECnet, LAT and CTERM protocols - not available\n");
  5136.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5137. #else /* NT */
  5138.     if (dnet_avail)
  5139.       printf(" DECnet, LAT protocol\n");
  5140.     else
  5141.       printf(" DECnet, LAT protocol - not available\n");
  5142.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5143. #endif /* NT */
  5144. #else
  5145.     printf(" DECnet\n");
  5146.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5147. #endif /* OS2 */
  5148. #endif /* DECNET */
  5149.  
  5150. #ifdef NPIPE
  5151.     printf(" Named Pipes\n");
  5152.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5153. #endif /* NPIPE */
  5154.  
  5155. #ifdef CK_NETBIOS
  5156.     if (netbiosAvail)
  5157.       printf(" NETBIOS\n");
  5158.     else
  5159.       printf(" NETBIOS - not available\n");
  5160.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5161. #endif /* CK_NETBIOS */
  5162.  
  5163. #ifdef SUPERLAT
  5164.     if (slat_avail)
  5165.       printf(" SuperLAT\n");
  5166.     else
  5167.       printf(" SuperLAT - not available\n") ;
  5168.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5169. #endif /* SUPERLAT */
  5170.  
  5171. #ifdef TCPSOCKET
  5172.     if (
  5173. #ifdef OS2
  5174.         tcp_avail
  5175. #else
  5176.         1
  5177. #endif /* OS2 */
  5178.         ) {
  5179.         char ipaddr[16];
  5180.  
  5181.         if (getlocalipaddrs(ipaddr,16,0) < 0) {
  5182. #ifdef OS2ONLY
  5183.             printf(" TCP/IP via %s\n", tcpname);
  5184. #else
  5185.             printf(" TCP/IP\n");
  5186. #endif /* OS2ONLY */
  5187.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5188.         } else {
  5189.             int i = 1;
  5190. #ifdef OS2ONLY
  5191.           printf(" TCP/IP [%16s] via %s\n", ipaddr, tcpname);
  5192. #else
  5193.           printf(" TCP/IP [%16s]\n",ipaddr);
  5194. #endif /* OS2ONLY */
  5195.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5196.  
  5197.             while (getlocalipaddrs(ipaddr,16,i++) >= 0) {
  5198.                 printf("        [%16s]\n",ipaddr);
  5199.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5200.             }
  5201.         }
  5202.         if (nettype == NET_TCPB) {
  5203.             printf("\n");
  5204.             n = shotcp(++n);
  5205.             if (n < 0) return(0);
  5206. #ifdef TNCODE
  5207.             printf("\n");
  5208.             n = shotel(++n);
  5209.             if (n < 0) return(0);
  5210. #endif /* TNCODE */
  5211.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5212.         }
  5213. #ifdef OS2
  5214.     } else {
  5215.         printf(" TCP/IP - not available%s\n",tcpname[0] ? tcpname : "" );
  5216.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5217. #endif /* OS2 */
  5218.     }
  5219. #endif /* TCPSOCKET */
  5220.  
  5221. #ifdef CK_NETBIOS
  5222.     if (netbiosAvail && nettype == NET_BIOS) {
  5223.        printf("\n") ;
  5224.        if ((n = shonb(++n)) < 0) return(0);
  5225.        if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5226.     }
  5227. #endif /* CK_NETBIOS */
  5228.  
  5229. #endif /* VMS */
  5230.  
  5231.     printf("\nActive network connection:\n");
  5232.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5233.  
  5234.     if (network) {
  5235.         printf(" Host: %s",ttname);
  5236.         if ((nettype == NET_TCPA || nettype == NET_TCPB) && *ipaddr)
  5237.           printf(" [%s]",ipaddr);
  5238.     } else
  5239.       printf(" Host: none");
  5240.     printf(", via: ");
  5241.     if (nettype == NET_TCPA || nettype == NET_TCPB)
  5242.       printf("tcp/ip\n");
  5243.     else if (nettype == NET_SX25)
  5244.       printf("SunLink X.25\n");
  5245.     else if (nettype == NET_VX25)
  5246.       printf("Stratus VOS X.25\n");
  5247.     else if (nettype == NET_IX25)
  5248.       printf("IBM AIX X.25\n");
  5249.     else if (nettype == NET_HX25)
  5250.       printf("HP-UX X.25\n");
  5251.     else if (nettype == NET_DEC) {
  5252.         if ( ttnproto == NP_LAT )
  5253.           printf("DECnet LAT\n");
  5254.         else if ( ttnproto == NP_CTERM )
  5255.           printf("DECnet CTERM\n");
  5256.         else
  5257.           printf("DECnet\n");
  5258.     } else if (nettype == NET_PIPE)
  5259.       printf("Named Pipes\n");
  5260.     else if (nettype == NET_BIOS)
  5261.       printf("NetBIOS\n");
  5262.     else if (nettype == NET_SLAT)
  5263.       printf("SuperLAT\n");
  5264.  
  5265. #ifdef NETFILE
  5266.     else if ( nettype == NET_FILE )
  5267.       printf("local file\n");
  5268. #endif /* NETFILE */
  5269. #ifdef NETCMD
  5270.     else if ( nettype == NET_CMD )
  5271.       printf("pipe\n");
  5272. #endif /* NETCMD */
  5273. #ifdef NETPTY
  5274.     else if ( nettype == NET_PTY )
  5275.         printf("pseudoterminal\n");
  5276. #endif /* NETPTY */
  5277. #ifdef NETDLL
  5278.     else if ( nettype == NET_DLL )
  5279.       printf("dynamic link library\n");
  5280. #endif /* NETDLL */
  5281.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5282.  
  5283. #ifdef ANYX25
  5284.     if ((nettype == NET_SX25) ||
  5285.         (nettype == NET_VX25) ||
  5286.         (nettype == NET_IX25))
  5287.       if ((n = shox25(n)) < 0) return(0);
  5288. #endif /* ANYX25 */
  5289.  
  5290. #ifdef SSHBUILTIN
  5291.     if (nettype == NET_SSH) {
  5292.         printf("Secure Shell protocol\n");
  5293.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5294.     }
  5295. #endif /* SSHBUILTIN */
  5296.  
  5297.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  5298. #ifdef RLOGCODE
  5299.         if (ttnproto == NP_RLOGIN) {
  5300.             printf(" LOGIN (rlogin) protocol\n");
  5301.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5302.         }
  5303. #ifdef CK_KERBEROS
  5304.         else if (ttnproto == NP_K4LOGIN) {
  5305.             printf(" Kerberos 4 LOGIN (klogin) protocol\n");
  5306.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5307.         }
  5308.         else if (ttnproto == NP_EK4LOGIN) {
  5309.             printf(" Encrypted Kerberos 4 LOGIN (eklogin) protocol\n");
  5310.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5311.         }
  5312.         else if (ttnproto == NP_K5LOGIN) {
  5313.             printf(" Kerberos 5 LOGIN (klogin) protocol\n");
  5314.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5315.         }
  5316.         else if (ttnproto == NP_EK5LOGIN) {
  5317.             printf(" Encrypted Kerberos 5 LOGIN (eklogin) protocol\n");
  5318.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5319.         }
  5320. #endif /* CK_KERBEROS */
  5321. #endif /* RLOGCODE */
  5322. #ifdef CK_KERBEROS
  5323.         if (ttnproto == NP_K5U2U) {
  5324.             printf(" Kerberos 5 User to User protocol\n");
  5325.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5326.         }
  5327. #endif /* CK_KERBEROS */
  5328.  
  5329. #ifdef TNCODE
  5330.         if (IS_TELNET()) {
  5331.             printf(" TELNET protocol\n");
  5332.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5333.             printf(" Echoing is currently %s\n",duplex ? "local" : "remote");
  5334.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5335.         }
  5336. #endif /* TNCODE */
  5337.         if (ttnproto == NP_TCPRAW) {
  5338.             printf(" Raw TCP socket\n");
  5339.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5340.         }
  5341.     }
  5342.     printf("\n");
  5343. #endif /* NOLOCAL */
  5344. #endif /* NETCONN */
  5345.     return(0);
  5346. }
  5347. #endif /* NONET */
  5348.  
  5349. #ifndef NODIAL
  5350. VOID
  5351. shodial() {
  5352.     if (mdmtyp >= 0 || local != 0) doshodial();
  5353. }
  5354.  
  5355. VOID
  5356. shods(s) char *s; {                     /* Show a dial-related string */
  5357.     char c;
  5358.     if (s == NULL || !(*s)) {           /* Empty? */
  5359.         printf("(none)\n");
  5360.     } else {                            /* Not empty. */
  5361.         while ((c = *s++))              /* Can contain controls */
  5362.           if (c == '\\')                /* a backslash */
  5363.             printf("\\\\");
  5364.           else if (c > 31 && c < 127) {
  5365.               putchar(c);
  5366.           } else
  5367.             printf("\\{%d}",c);
  5368.         printf("\n");
  5369.     }
  5370. }
  5371.  
  5372. int
  5373. doshodial() {
  5374.  
  5375.     int i, n = 2;
  5376.  
  5377.     printf(" Dial status:  %d", dialsta);
  5378.  
  5379. #ifdef BIGBUFOK
  5380.     if (dialsta > 90)
  5381.       printf(" = Unknown error");
  5382.     else if (dialsta < 0)
  5383.       printf(" = (none)");
  5384.     else if (dialsta < 35 && dialmsg[dialsta])
  5385.       printf(" = %s", dialmsg[dialsta]);
  5386. #endif /* BIGBUFOK */
  5387.     n++;
  5388.     if (ndialdir <= 1) {
  5389.         printf("\n Dial directory: %s\n",dialdir[0] ? dialdir[0] : "(none)");
  5390.     } else {
  5391.         int i;
  5392.         printf("\n Dial directories:\n");
  5393.         for (i = 0; i < ndialdir; i++)
  5394.           printf("%2d. %s\n",i+1,dialdir[i]);
  5395.         n += ndialdir;
  5396.     }
  5397.     printf(" Dial method:  ");
  5398.     if      (dialmauto)         printf("auto   ");
  5399.     else if (dialmth == XYDM_D) printf("default");
  5400.     else if (dialmth == XYDM_P) printf("pulse  ");
  5401.     else if (dialmth == XYDM_T) printf("tone   ");
  5402.     printf("         Dial sort: %s\n",dialsrt ? "on" : "off");
  5403.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5404.     printf(" Dial hangup:  %s             Dial display: %s\n",
  5405.            dialhng ? "on " : "off", dialdpy ? "on" : "off");
  5406.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5407.     if (dialrtr > 0) {
  5408.         printf(" Dial retries: %-6d          Dial interval: %d\n",
  5409.                dialrtr, dialint);
  5410.     } else {
  5411.         printf(" Dial retries: (auto)          Dial interval: %d\n", dialint);
  5412.     }
  5413.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5414.     printf(" Dial timeout: ");
  5415. #ifdef CK_TAPI
  5416.     if (tttapi && !tapipass)
  5417.         printf("(tapi)");
  5418.     else
  5419. #endif /* CK_TAPI */
  5420.     if (dialtmo > 0)
  5421.       printf("%4d sec", dialtmo);
  5422.     else
  5423.       printf("0 (auto)");
  5424.     printf("        Redial number: %s\n",dialnum ? dialnum : "(none)");
  5425.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5426.     printf(" Dial confirmation: %s        Dial convert-directory: %s\n",
  5427.            dialcnf ? "on " : "off",
  5428.            dialcvt ? ((dialcvt == 1) ? "on" : "ask") : "off");
  5429.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5430.     printf(" Dial ignore-dialtone: %s", dialidt ? "on " : "off");
  5431.     printf("     Dial pacing: %d\n",dialpace);
  5432.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5433.     printf(
  5434. " Dial prefix:                  %s\n", dialnpr ? dialnpr : "(none)");
  5435.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5436.     printf(
  5437. " Dial suffix:                  %s\n", dialsfx ? dialsfx : "(none)");
  5438.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5439.     printf(
  5440. " Dial country-code:            %-12s", diallcc ? diallcc : "(none)");
  5441.     printf("Dial connect:  %s", dialcon ? ((dialcon == 1) ? "on" : "auto")
  5442.            : "off");
  5443.     if (dialcon != CAR_OFF)
  5444.       printf(" %s", dialcq ? "quiet" : "verbose");
  5445.     printf(
  5446. "\n Dial area-code:               %-12s", diallac ? diallac : "(none)");
  5447.     n++;
  5448.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5449.     printf("Dial restrict: ");
  5450.     if (dialrstr == 5) printf("international\n");
  5451.     else if (dialrstr == 4) printf("long-distance\n");
  5452.     else if (dialrstr == 2) printf("local\n");
  5453.     else if (dialrstr == 6) printf("none\n");
  5454.     else printf("?\n");
  5455.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5456.     printf(" Dial lc-area-codes:           ");
  5457.     if (nlocalac == 0)
  5458.       printf("(none)");
  5459.     else
  5460.       for (i = 0; i < nlocalac; i++)
  5461.         printf("%s ", diallcac[i]);
  5462.     printf(
  5463. "\n Dial lc-prefix:               %s\n", diallcp ? diallcp : "(none)");
  5464.     n++;
  5465.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5466.     printf(
  5467. " Dial lc-suffix:               %s\n", diallcs ? diallcs : "(none)");
  5468.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5469.     printf(
  5470. " Dial ld-prefix:               %s\n", dialldp ? dialldp : "(none)");
  5471.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5472.     printf(
  5473. " Dial ld-suffix:               %s\n", diallds ? diallds : "(none)");
  5474.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5475.     printf(
  5476. " Dial force-long-distance      %s\n", showoff(dialfld));
  5477.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5478.     printf(
  5479. " Dial intl-prefix:             %s\n", dialixp ? dialixp : "(none)");
  5480.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5481.     printf(
  5482. " Dial intl-suffix:             %s\n", dialixs ? dialixs : "(none)");
  5483.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5484.     printf(
  5485. " Dial toll-free-area-code:     ");
  5486.     if (ntollfree == 0)
  5487.       printf("(none)");
  5488.     else
  5489.       for (i = 0; i < ntollfree; i++)
  5490.         printf("%s ", dialtfc[i]);
  5491.     printf("\n");
  5492.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5493.  
  5494.     printf(
  5495. " Dial pulse-countries:         ");
  5496.     if (ndialpucc == 0)
  5497.       printf("(none)");
  5498.     else
  5499.       for (i = 0; i < ndialpucc; i++)
  5500.         printf("%s ", dialpucc[i]);
  5501.     printf("\n");
  5502.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5503.  
  5504.     printf(
  5505. " Dial tone-countries:          ");
  5506.     if (ndialtocc == 0)
  5507.       printf("(none)");
  5508.     else
  5509.       for (i = 0; i < ndialtocc; i++)
  5510.         printf("%s ", dialtocc[i]);
  5511.     printf("\n");
  5512.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5513.  
  5514.     printf(
  5515.     " Dial toll-free-prefix:        %s\n",
  5516.     dialtfp ? dialtfp :
  5517.     (dialldp ? dialldp : "(none)")
  5518.     );
  5519.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5520.     printf(" Dial pbx-exchange:            ");
  5521.     if (ndialpxx == 0)
  5522.       printf("(none)");
  5523.     else
  5524.       for (i = 0; i < ndialpxx; i++)
  5525.         printf("%s ", dialpxx[i]);
  5526.     printf("\n");
  5527.  
  5528.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5529.     printf(
  5530. " Dial pbx-inside-prefix:       %s\n", dialpxi ? dialpxi : "(none)");
  5531.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5532.     printf(
  5533. " Dial pbx-outside-prefix:      %s\n", dialpxo ? dialpxo : "(none)");
  5534.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5535.     printf(
  5536. " Dial macro:                   %s\n", dialmac ? dialmac : "(none)");
  5537.     return(0);
  5538. }
  5539. #endif /* NODIAL */
  5540. #endif /* NOLOCAL */
  5541.  
  5542. /*  Show File Parameters */
  5543.  
  5544. static char *
  5545. pathval(x) int x; {
  5546.     switch (x) {
  5547.       case PATH_OFF:  return("off");
  5548.       case PATH_ABS:  return("absolute");
  5549.       case PATH_REL:  return("relative");
  5550.       case PATH_AUTO: return("auto");
  5551.       default: return("unknown");
  5552.     }
  5553. }
  5554.  
  5555. VOID
  5556. shofil() {
  5557.     char *s; int i = 0, n = 1;
  5558.     extern char * ifdnam[];
  5559. #ifdef UNIX
  5560.     extern int wildxpand;
  5561. #endif /* UNIX */
  5562.     extern char * snd_move, * snd_rename, * rcv_move, * rcv_rename;
  5563. #ifdef PATTERNS
  5564.     extern int patterns;
  5565. #endif /* PATTERNS */
  5566.     extern char * rfspec, * sfspec;
  5567. #ifdef UNIX
  5568.     extern int zobufsize, zofbuffer, zofblock;
  5569. #endif /* UNIX */
  5570. #ifdef CK_CTRLZ
  5571.     extern int eofmethod;
  5572. #endif /* CK_CTRLZ */
  5573.  
  5574.     printf("\n");
  5575.  
  5576. #ifdef VMS
  5577.     printf(" File record-Length:      %5d\n",frecl);
  5578.     n++;
  5579. #endif /* VMS */
  5580.  
  5581. #ifndef NOXFER
  5582.     printf(" Transfer mode:           %s\n",
  5583.            xfermode == XMODE_A ?
  5584.            "automatic" :
  5585.            "manual"
  5586.            );
  5587.     n++;
  5588. #ifdef PATTERNS
  5589.     printf(" File patterns:           %s", showooa(patterns));
  5590.     if (xfermode == XMODE_M && patterns)
  5591.       printf(" (but disabled by TRANSFER-MODE MANUAL)");
  5592.     else if (patterns)
  5593.       printf(" (SHOW PATTERNS for list)");
  5594.     printf("\n");
  5595.     n++;
  5596. #endif /* PATTERNS */
  5597.     if (filepeek)
  5598.       printf(" File scan:               on %d\n", nscanfile);
  5599.     else
  5600.       printf(" File scan:               off\n");
  5601.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5602.     if (xfermode == XMODE_A)
  5603.       printf(" Default file type:       %s\n",shoxm());
  5604.     else
  5605.       printf(" File type:               %s\n",shoxm());
  5606.     n++;
  5607.     if (fncnv == XYFN_L)
  5608.       s = "literal";
  5609.     else if (fncnv == XYFN_C)
  5610.       s = "converted";
  5611.     else
  5612.       s = "(unknown)";
  5613.     printf(" File names:              %s\n",s);
  5614.     n++;
  5615.     printf(" Send pathnames:          %s\n", pathval(fnspath));
  5616.     n++;
  5617.     printf(" Receive pathnames:       %s\n", pathval(fnrpath));
  5618.     n++;
  5619. #ifdef UNIXOROSK
  5620.     printf(" Match dot files:         %s\n", matchdot ? "yes" : "no");
  5621.     n++;
  5622. #ifdef UNIX
  5623.     printf(" Wildcard-expansion:      %s\n", wildxpand ? "shell" : "kermit");
  5624.     n++;
  5625. #endif /* UNIX */
  5626. #endif /* UNIXOROSK */
  5627.     printf(" File collision:          ");
  5628.     for (i = 0; i < ncolx; i++)
  5629.       if (colxtab[i].kwval == fncact) break;
  5630.     printf("%s\n", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5631.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5632.     printf(" File destination:        %s\n",
  5633.            (dest == DEST_D) ? "disk" :
  5634.            ((dest == DEST_S) ? "screen" :
  5635.             ((dest == DEST_N) ? "nowhere" :
  5636.             "printer"))
  5637.            );
  5638.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5639.     s = (keep >= 0 && keep <= 2) ? ifdnam[keep] : "keep";
  5640.     printf(" File incomplete:         %s\n",s);
  5641.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5642.     printf(" File bytesize:           %d\n",(fmask == 0177) ? 7 : 8);
  5643.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5644. #ifndef NOCSETS
  5645.     printf(" File character-set:      %s\n",fcsinfo[fcharset].keyword);
  5646.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5647.     printf(" File default 7-bit:      %s\n",fcsinfo[dcset7].keyword);
  5648.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5649.     printf(" File default 8-bit:      %s\n",fcsinfo[dcset8].keyword);
  5650.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5651. #ifdef UNICODE
  5652.     printf(" File UCS bom:            %s\n",showoff(ucsbom));
  5653.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5654.     printf(" File UCS byte-order:     %s-endian\n",
  5655.            ucsorder ? "little" : "big");
  5656.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5657.     printf(" Computer byteorder:      %s-endian\n",
  5658.            byteorder ? "little" : "big");
  5659.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5660. #endif /* UNICODE */
  5661. #endif /* NOCSETS */
  5662.  
  5663.     printf(" File end-of-line:        ");
  5664.     i = feol;
  5665.     switch (feol) {
  5666.       case XYFA_C: printf("%s\n","cr"); break;
  5667.       case XYFA_L: printf("%s\n","lf"); break;
  5668.       case XYFA_2: printf("%s\n","crlf"); break;
  5669.       default: printf("%d\n",i);
  5670.     }
  5671.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5672. #endif /* NOXFER */
  5673.  
  5674. #ifdef CK_CTRLZ
  5675.     printf(" File eof:                %s\n", eofmethod ? "ctrl-z" : "length");
  5676.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5677. #endif /* CK_CTRLZ */
  5678. #ifndef NOXFER
  5679. #ifdef CK_TMPDIR
  5680.     printf(" File download-directory: %s\n", dldir ? dldir : "(none)");
  5681.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5682. #ifdef COMMENT
  5683.     i = 256;
  5684.     s = line;
  5685.     zzstring("\\v(tmpdir)",&s,&i);
  5686.     printf(" Temporary directory:     %s\n", line);
  5687.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5688. #endif /* COMMENT */
  5689. #endif /* CK_TMPDIR */
  5690. #ifdef VMS
  5691.     {
  5692.         extern int vmssversions, vmsrversions;
  5693.         printf(" Send version-numbers:    %s\n",showoff(vmssversions));
  5694.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5695.         printf(" Receive version-numbers: %s\n",showoff(vmsrversions));
  5696.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5697.     }
  5698. #endif /* VMS */
  5699.     printf(" Send move-to:            %s\n",
  5700.            snd_move ? snd_move : "(none)");
  5701.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5702.     printf(" Send rename-to:          %s\n",
  5703.            snd_rename ? snd_rename : "(none)");
  5704.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5705.     printf(" Receive move-to:         %s\n",
  5706.            rcv_move ? rcv_move : "(none)");
  5707.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5708.     printf(" Receive rename-to:       %s\n",
  5709.            rcv_rename ? rcv_rename : "(none)");
  5710.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5711. #endif /* NOXFER */
  5712. #ifdef KERMRC
  5713.     printf(" Initialization file:     %s\n", noinit ? "(none)" :
  5714. #ifdef CK_SYSINI
  5715.            CK_SYSINI
  5716. #else
  5717.            kermrc
  5718. #endif /* CK_SYSINI */
  5719.            );
  5720. #endif /* KERMRC */
  5721.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5722.  
  5723.     if (k_info_dir) {
  5724.         printf(" Kermit doc files:        %s\n", k_info_dir);
  5725.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5726.     }
  5727.  
  5728. #ifdef CKROOT
  5729.     s = zgetroot();
  5730.     printf(" Root set:                %s\n", s ? s : "(none)");
  5731. #endif /* CKROOT */
  5732.  
  5733. #ifdef UNIX
  5734.     printf(" Disk output buffer:      %d (writes are %s, %s)\n",
  5735.            zobufsize,
  5736.            zofbuffer ? "buffered" : "unbuffered",
  5737.            zofblock ? "blocking" : "nonblocking"
  5738.            );
  5739.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5740. #ifdef DYNAMIC
  5741.     printf(" Stringspace:             %d\n", zsetfil(0,2));
  5742.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5743.     printf(" Listsize:                %d\n", zsetfil(0,4));
  5744.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5745. #endif /* DYNAMIC */
  5746. #endif /* UNIX */
  5747. #ifdef OS2ORUNIX
  5748.     printf(" Longest filename:        %d\n", maxnam);
  5749.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5750.     printf(" Longest pathname:        %d\n", maxpath);
  5751.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5752. #endif /* OS2ORUNIX */
  5753.  
  5754.     printf(" Last file sent:          %s\n", sfspec ? sfspec : "(none)");
  5755.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5756.     printf(" Last file received:      %s\n", rfspec ? rfspec : "(none)");
  5757.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5758.     printf("\n Also see:\n");
  5759.     n++;
  5760.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5761.     printf(" SHOW PROTOCOL, SHOW XFER");
  5762. #ifdef CK_LABELED
  5763.     printf(", SHOW LABELED");
  5764. #endif /* CK_LABELED */
  5765. #ifdef PATTERNS
  5766.     printf(", SHOW PATTERNS");
  5767. #endif /* PATTERNS */
  5768. #ifdef STREAMING
  5769.     printf(", SHOW STREAMING");
  5770. #endif /* STREAMING */
  5771. #ifndef NOCSETS
  5772.     printf(", SHOW CHARACTER-SETS");
  5773. #endif /* NOCSETS */
  5774.     printf("\n\n");
  5775. }
  5776.  
  5777. #ifndef NOXFER
  5778. VOID
  5779. shoparp() {                             /* Protocol */
  5780.     extern int docrc, skipbup;
  5781.     char *s;
  5782.  
  5783. #ifdef CK_TIMERS
  5784.     extern int rttflg;
  5785. #endif /* CK_TIMERS */
  5786.  
  5787.     printf("Protocol: %s\n",ptab[protocol].p_name);
  5788.  
  5789.     if (protocol == PROTO_K) {
  5790.         printf("\nProtocol Parameters:   Send    Receive");
  5791.         if (timef)
  5792.           printf("\n Timeout (used=%2d):%7d*%8d ", timint, rtimo, pkttim);
  5793.         else
  5794.           printf("\n Timeout (used=%2d):%7d%9d ",  timint, rtimo, pkttim);
  5795. #ifdef XFRCAN
  5796.         printf("       Cancellation:    %s",showoff(xfrcan));
  5797.         if (xfrcan)
  5798.           printf(" %d %d", xfrchr, xfrnum);
  5799. #endif /* XFRCAN */
  5800.         printf("\n Padding:      %11d%9d", npad,   mypadn);
  5801.         if (bctr == 4)
  5802.           printf("        Block Check: blank-free-2\n");
  5803.         else
  5804.           printf("        Block Check: %6d\n",bctr);
  5805.         printf(  " Pad Character:%11d%9d", padch,  mypadc);
  5806.         printf("        Delay:       %6d\n",ckdelay);
  5807.         printf(  " Pause:        %11d%9d", pktpaus, pktpaus);
  5808.         printf("        Attributes:      %s\n",showoff(atcapr));
  5809.         printf(  " Packet Start: %11d%9d", mystch, stchr);
  5810.         printf("        Max Retries: %6d%s\n",
  5811.                maxtry,
  5812.                (maxtry == 0) ? " (unlimited)" : ""
  5813.                );
  5814.         printf(  " Packet End:   %11d%9d", seol,   eol);
  5815.         if (ebqflg)
  5816.           printf("        8th-Bit Prefix: '%c'",ebq);
  5817.         else
  5818.           printf("        8th-Bit Prefix: ('%c' but not used)",ebq);
  5819.         printf(  "\n Packet Length:%11d ", spmax);
  5820.         printf("%8d     ",  urpsiz);
  5821.         if (rptflg)
  5822.           printf("   Repeat Prefix:  '%c'",rptq);
  5823.         else
  5824.           printf("   Repeat Prefix:  ('%c' but not used)",rptq);
  5825.         printf(  "\n Maximum Length: %9d%9d", maxsps, maxrps);
  5826.         printf("        Window Size:%7d set, %d used\n",wslotr,wmax);
  5827.         printf(    " Buffer Size:  %11d%9d", bigsbsiz, bigrbsiz);
  5828.         printf("        Locking-Shift:    ");
  5829.         if (lscapu == 2) {
  5830.             printf("forced");
  5831.         } else {
  5832.             printf("%s", (lscapr ? "enabled" : "disabled"));
  5833.             if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  5834.         }
  5835.         printf("\n\n");
  5836.  
  5837.         if (!(s = ptab[protocol].h_b_init)) s = "";
  5838.         printf(" Auto-upload command (binary): ");
  5839.         if (*s) {
  5840.             shostrdef((CHAR *)s);
  5841.             printf("\n");
  5842.         } else {
  5843.             printf("(none)\n");
  5844.         }
  5845.         if (!(s = ptab[protocol].h_t_init)) s = "";
  5846.         printf(" Auto-upload command (text):   ");
  5847.         if (*s) {
  5848.             shostrdef((CHAR *)s);
  5849.             printf("\n");
  5850.         } else {
  5851.             printf("(none)\n");
  5852.         }
  5853.         if (!(s = ptab[protocol].h_x_init)) s = "";
  5854.         printf(" Auto-server command:          ");
  5855.         if (*s) {
  5856.             shostrdef((CHAR *)s);
  5857.             printf("\n");
  5858.         } else {
  5859.             printf("(none)\n");
  5860.         }
  5861.         tmpbuf[0] = NUL;
  5862. #ifdef CK_TIMERS
  5863.         if (rttflg) {
  5864.             extern int mintime, maxtime;
  5865.             sprintf(tmpbuf," Packet timeouts: dynamic %d:%d", /* SAFE */
  5866.                     mintime,
  5867.                     maxtime);
  5868.         } else {
  5869.             sprintf(tmpbuf," Packet timeouts: fixed"); /* SAFE */
  5870.         }
  5871. #endif /* CK_TIMERS */
  5872.         if (tmpbuf[0])
  5873.           printf("%-31s",tmpbuf);
  5874.         printf("Send backup: %s\n",showoff(!skipbup));
  5875.  
  5876.         printf(" Transfer mode:   %s", xfermode == XMODE_A ?
  5877.                "automatic   " :
  5878.                "manual      "
  5879.                );
  5880.         printf(" Transfer slow-start: %s, crc: %s\n",
  5881.                showoff(slostart),
  5882.                showoff(docrc)
  5883.                );
  5884. #ifdef PIPESEND
  5885.         {
  5886.             extern int usepipes;
  5887.             printf(" Transfer pipes:  %s         ",usepipes ? "on " : "off");
  5888.         }
  5889. #endif /* PIPESEND */
  5890. #ifndef NOCSETS
  5891.         printf(" Transfer character-set: ");
  5892.         if (tcharset == TC_TRANSP)
  5893.           printf("transparent\n");
  5894.         else
  5895.           printf("%s\n", tcsinfo[tcharset].keyword );
  5896. #endif /* NOCSETS */
  5897. #ifdef PIPESEND
  5898.         {
  5899.             extern char * sndfilter, * rcvfilter;
  5900.             printf(" Send filter:     %s\n", sndfilter ? sndfilter : "(none)");
  5901.             printf(" Receive filter:  %s\n", rcvfilter ? rcvfilter : "(none)");
  5902.         }
  5903. #endif /* PIPESEND */
  5904.         printf("\nAlso see:\n");
  5905.         printf(" SHOW FILE, SHOW XFER");
  5906.  
  5907. #ifdef CK_LABELED
  5908.         printf(", SHOW LABELED");
  5909. #endif /* CK_LABELED */
  5910. #ifdef PATTERNS
  5911.         printf(", SHOW PATTERNS");
  5912. #endif /* PATTERNS */
  5913. #ifdef STREAMING
  5914.         printf(", SHOW STREAMING");
  5915. #endif /* STREAMING */
  5916. #ifndef NOCSETS
  5917.         printf(", SHOW CHARACTER-SETS");
  5918. #endif /* NOCSETS */
  5919.     }
  5920.  
  5921. #ifdef CK_XYZ
  5922. #ifdef XYZ_INTERNAL
  5923.     if (protocol != PROTO_K) {
  5924.         int i;
  5925.         int x;
  5926.         printf(" File type: %s\n", binary ? "binary" : "text");
  5927.         if (protocol == PROTO_Z) {              /* Zmodem */
  5928.             printf(" Window size:   ");
  5929.             if (ptab[protocol].winsize < 1)
  5930.               printf("none\n");
  5931.             else
  5932.               printf("%d\n",wslotr);
  5933. #ifdef COMMENT
  5934.             printf(" Packet (frame) length: ");
  5935.             if (ptab[protocol].spktlen < 0)
  5936.               printf("none\n");
  5937.             else
  5938.               printf("%d\n",spmax);
  5939. #endif /* COMMENT */
  5940.         } else {
  5941.             if (ptab[protocol].spktlen >= 1000)
  5942.               printf(" 1K packets\n");
  5943.             else
  5944.               printf(" 128-byte packets\n");
  5945.         }
  5946.         printf(" Pathname stripping when sending:   %s\n",
  5947.                showoff(ptab[protocol].fnsp)
  5948.                );
  5949.         printf(" Pathname stripping when receiving: %s\n",
  5950.                showoff(ptab[protocol].fnrp)
  5951.                );
  5952.         printf(" Filename collision action:         ");
  5953.         for (i = 0; i < ncolx; i++)
  5954.           if (colxtab[i].kwval == fncact) break;
  5955.         printf("%-12s", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5956.  
  5957.         printf("\n Escape control characters:          ");
  5958.         x = ptab[protocol].prefix;
  5959.         if (x == PX_ALL)
  5960.           printf("all\n");
  5961.         else if (x == PX_CAU || x==PX_WIL)
  5962.           printf("minimal\n");
  5963.         else
  5964.           printf("none\n");
  5965.         if (!(s = ptab[protocol].h_b_init))
  5966.           s = "";
  5967.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5968.         if (!(s = ptab[protocol].h_t_init))
  5969.           s = "";
  5970.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  5971.     }
  5972. #else
  5973.     if (protocol != PROTO_K) {
  5974.         printf("\nExecuted by external commands:\n\n");
  5975.         s = ptab[protocol].p_b_scmd;
  5976.         if (!s) s = "";
  5977.         printf(" SEND command (binary):        %s\n", *s ? s : "(none)");
  5978.         s = ptab[protocol].p_t_scmd;
  5979.         if (!s) s = "";
  5980.         printf(" SEND command (text):          %s\n", *s ? s : "(none)");
  5981.         s = ptab[protocol].p_b_rcmd;
  5982.         if (!s) s = "";
  5983.         printf(" RECEIVE command (binary):     %s\n", *s ? s : "(none)");
  5984.         s = ptab[protocol].p_t_rcmd;
  5985.         if (!s) s = "";
  5986.         printf(" RECEIVE command (text):       %s\n", *s ? s : "(none)");
  5987.         s = ptab[protocol].h_b_init;
  5988.         if (!s) s = "";
  5989.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5990.         s = ptab[protocol].h_t_init;
  5991.         if (!s) s = "";
  5992.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  5993.     }
  5994. #endif /* XYZ_INTERNAL */
  5995. #endif /* CK_XYZ */
  5996. }
  5997. #endif /* NOXFER */
  5998.  
  5999. #ifndef NOCSETS
  6000. /* Character-set items */
  6001.  
  6002. extern int s_cset, r_cset, axcset[], afcset[];
  6003. extern struct keytab xfrmtab[];
  6004.  
  6005. VOID
  6006. shoparl() {
  6007. #ifdef COMMENT
  6008.     int i;
  6009. /* Misleading... */
  6010.     printf("\nAvailable Languages:\n");
  6011.     for (i = 0; i < MAXLANG; i++) {
  6012.         printf(" %s\n",langs[i].description);
  6013.     }
  6014. #else
  6015.     printf("\nLanguage-specific translation rules: %s\n",
  6016.            language == L_USASCII ? "none" : langs[language].description);
  6017.     shocharset();
  6018.     printf("\n\n");
  6019. #endif /* COMMENT */
  6020. }
  6021.  
  6022. VOID
  6023. shocharset() {
  6024.     int x;
  6025. #ifdef COMMENT
  6026.     char * s = "Unknown";
  6027.     extern int xlatype;
  6028. #endif /* COMMENT */
  6029.  
  6030. #ifndef NOXFER
  6031.     extern int xfrxla;
  6032. #endif /* NOXFER */
  6033.  
  6034.     debug(F101,"SHOW FILE CHAR","",fcharset);
  6035.     printf("\n");
  6036. #ifndef NOXFER
  6037.     printf(" Transfer Translation: %s\n", showoff(xfrxla));
  6038.     if (!xfrxla) {
  6039.         printf(
  6040.       " Because transfer translation is off, the following are ignored:\n\n");
  6041.     }
  6042. #endif /* NOXFER */
  6043.     printf(" File Character-Set: %s (%s), ",
  6044.            fcsinfo[fcharset].keyword,
  6045.            fcsinfo[fcharset].name
  6046.            );
  6047.     if ((x = fcsinfo[fcharset].size) == 128)
  6048.       printf("7-bit");
  6049.     else if (x == 256)
  6050.       printf("8-bit");
  6051.     else
  6052.       printf("multibyte");
  6053.     printf("\n");
  6054.     printf(" File Scan: %s\n",showoff(filepeek));
  6055.     printf("   Default 7bit-Character-Set: %s\n",fcsinfo[dcset7].keyword);
  6056.     printf("   Default 8bit-Character-Set: %s\n",fcsinfo[dcset8].keyword);
  6057.     printf(" Transfer Character-Set");
  6058. #ifdef COMMENT
  6059.     if (tslevel == TS_L2)
  6060.       printf(": (international)");
  6061.     else
  6062. #endif /* COMMENT */
  6063.     if (tcharset == TC_TRANSP)
  6064.       printf(": Transparent");
  6065.     else
  6066.       printf(": %s (%s)",tcsinfo[tcharset].keyword, tcsinfo[tcharset].name);
  6067.     printf("\n");
  6068. #ifdef COMMENT
  6069.     switch (xlatype) {
  6070.       case XLA_NONE: s = "None"; break;
  6071.       case XLA_BYTE: s = "Byte"; break;
  6072.       case XLA_JAPAN: s = "Japanese"; break;
  6073.       case XLA_UNICODE: s = "Unicode"; break;
  6074.     }
  6075.     printf("\n Translation type: %s\n",s);
  6076. #endif /* COMMENT */
  6077.     printf(" SEND character-set-selection: %s\n",xfrmtab[s_cset].kwd);
  6078.     printf(" RECEIVE character-set-selection: %s\n",xfrmtab[r_cset].kwd);
  6079.     if (s_cset == XMODE_A || r_cset == XMODE_A)
  6080.       printf(
  6081.       " (Use SHOW ASSOCIATIONS to list automatic character-set selections.)\n"
  6082.              );
  6083. }
  6084.  
  6085. VOID
  6086. showassoc() {
  6087.     int i, k, n = 4;
  6088.     char * s;
  6089.     printf("\nFor incoming files:\n\n");
  6090.     printf("Transfer Character-Set   File Character-Set\n");
  6091.     for (i = 1; i <= MAXTCSETS; i++) {
  6092.         k = axcset[i];
  6093.         if (k < 0 || k > MAXFCSETS)
  6094.           s = "(none)";
  6095.         else
  6096.           s = fcsinfo[k].keyword;
  6097.         if (!s) s = "";
  6098.         if (!*s) s = "(none)";
  6099.         printf(" %-25s%s\n",tcsinfo[i].keyword,s);
  6100.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6101.     }
  6102.     printf("\nFor outbound files:\n\n");
  6103.     n += 2;
  6104.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6105.     printf("File Character-Set       Transfer Character-Set\n");
  6106.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6107.     for (i = 0; i <= MAXFCSETS; i++) {
  6108.         k = afcset[i];
  6109.         if (k < 0 || k > MAXTCSETS)
  6110.           s = "(none)";
  6111.         else
  6112.           s = tcsinfo[k].keyword;
  6113.         if (!s) s = "";
  6114.         if (!*s) s = "(none)";
  6115.         printf(" %-25s%s\n",fcsinfo[i].keyword,s);
  6116.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6117.     }
  6118. }
  6119. #endif /* NOCSETS */
  6120.  
  6121. VOID
  6122. shopar() {
  6123.     printf("Show what?  (Type \"show ?\" for a list of possiblities.)\n");
  6124. }
  6125. #endif /* NOSHOW */
  6126.  
  6127. #ifndef NOXFER
  6128. /*  D O S T A T  --  Display file transfer statistics.  */
  6129.  
  6130. int
  6131. dostat(brief) int brief; {
  6132.     extern long filrej, peakcps;
  6133.     extern int lastspmax, streamed, cleared, streamok;
  6134.     extern char whoareu[];
  6135.     int n = 0, ftp = 0;
  6136.     extern int docrc, interrupted, fatalio;
  6137.  
  6138.     ftp = lastxfer & W_FTP;
  6139.  
  6140. #ifdef CK_TTGWSIZ
  6141. #ifdef OS2
  6142.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  6143.       ttgwsiz();
  6144. #else /* OS2 */
  6145.     if (ttgwsiz() > 0) {
  6146.         if (tt_rows > 0 && tt_cols > 0) {
  6147.             cmd_rows = tt_rows;
  6148.             cmd_cols = tt_cols;
  6149.         }
  6150.     }
  6151. #endif /* OS2 */
  6152. #endif /* CK_TTGWSIZ */
  6153.  
  6154.     debug(F101,"dostat xferstat","",xferstat);
  6155.     if (xferstat < 0) {
  6156.         printf(" No file transfers yet.\n");
  6157.         return(1);
  6158.     }
  6159.     n = 0;
  6160.     if (brief) { printf("\n"); n++; };
  6161.     printf(" protocol               : %s\n",
  6162.            ftp ? "ftp" : ptab[protocol].p_name);
  6163.     n++;
  6164.     printf(" status                 : ");
  6165.     if (xferstat) printf("SUCCESS\n");
  6166.     else if (interrupted) printf("FAILURE (interrupted)\n");
  6167.     else if (fatalio) printf("FAILURE (i/o error)\n");
  6168.     else printf("FAILURE\n");
  6169. #ifndef XYZ_INTERNAL
  6170.     if (!ftp && protocol != PROTO_K) {
  6171.         printf("\n external protocol statistics not available\n");
  6172.         return(1);
  6173.     }
  6174. #endif /* XYZ_INTERNAL */
  6175.     n++;
  6176.     if (!ftp) {
  6177.         if (!xferstat > 0) {
  6178.             if (docrc)
  6179.               printf(" crc-16 of file(s)      : %ld\n", crc16);
  6180.             else
  6181.               printf(" crc-16 of file(s)      : (disabled)\n");
  6182.             n++;
  6183.         }
  6184.         if (!xferstat && *epktmsg) {
  6185.             printf(" reason                 : %s\n", epktmsg);
  6186.             n++;
  6187.         }
  6188.     }
  6189.     if (!brief) {
  6190. #ifdef NEWFTP
  6191.         if (ftp) {
  6192.             extern char ftp_srvtyp[];
  6193.             printf(" remote system type     : %s\n",ftp_srvtyp);
  6194.         } else
  6195. #endif /* NEWFTP */
  6196.           if (whoareu[0]) {
  6197.             printf(" remote system type     : %s\n",
  6198.                    getsysid((char *)whoareu));
  6199.             n++;
  6200.         }
  6201.         printf(" files transferred      : %ld\n",filcnt - filrej);
  6202.         if (!ftp)
  6203.           printf(" files not transferred  : %ld\n",filrej);
  6204.         printf(" characters last file   : %ld\n",ffc);
  6205.         printf(" total file characters  : %ld\n",tfc);
  6206.         n += ftp ? 3 : 4;
  6207.         if (!ftp) {
  6208.             printf(" communication line in  : %ld\n",tlci);
  6209.             printf(" communication line out : %ld\n",tlco);
  6210.             printf(" packets sent           : %d\n", spackets);
  6211.             printf(" packets received       : %d\n", rpackets);
  6212.             n += 4;
  6213.         }
  6214.     }
  6215.     if (ftp) goto dotimes;
  6216.  
  6217.     printf(" damaged packets rec'd  : %d\n", crunched);
  6218.     printf(" timeouts               : %d\n", timeouts);
  6219.     printf(" retransmissions        : %d\n", retrans);
  6220.     n += 3;
  6221.  
  6222.     if (!brief) {
  6223.         if (filcnt > 0) {
  6224.             printf(" parity                 : %s",parnam((char)parity));
  6225.             n++;
  6226.             if (autopar) { printf(" (detected automatically)"); n++; }
  6227.             printf(
  6228.                  "\n control characters     : %ld prefixed, %ld unprefixed\n",
  6229.                    ccp, ccu);
  6230.             n++;
  6231.             printf(" 8th bit prefixing      : ");
  6232.             n++;
  6233.             if (ebqflg) printf("yes [%c]\n",ebq); else printf("no\n");
  6234.             n++;
  6235.             printf(" locking shifts         : %s\n", lscapu ? "yes" : "no");
  6236.             n++;
  6237.         }
  6238.     }
  6239.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6240.     if (streamed > 0)
  6241.       printf(" window slots used      : (streaming)\n");
  6242.     else
  6243.       printf(" window slots used      : %d of %d\n", wmax, wslotr);
  6244.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6245.     printf(" reliable:              : %s%s\n",
  6246.            streamok ? "" : "not ", "negotiated");
  6247.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6248.     printf(" clearchannel:          : %s%s\n",
  6249.            cleared  ? "" : "not ", "negotiated");
  6250.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6251.  
  6252.     if (!brief) {
  6253.         printf(" packet length          : %d (send), %d (receive)\n",
  6254.                lastspmax, urpsiz);
  6255.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6256.         printf(" compression            : ");
  6257.         if (rptflg)
  6258.           printf("yes [%c] (%ld)\n",(char) rptq,rptn);
  6259.         else
  6260.           printf("no\n");
  6261.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6262.         if (bctu == 4)
  6263.           printf(" block check type used  : blank-free-2\n");
  6264.         else
  6265.           printf(" block check type used  : %d\n",bctu);
  6266.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6267.     }
  6268.  
  6269.   dotimes:
  6270.  
  6271. #ifdef GFTIMER
  6272. #ifdef COMMENT
  6273.     printf(" elapsed time           : %0.3f sec, %s\n", fptsecs,hhmmss(tsecs));
  6274. #endif /* COMMENT */
  6275.     printf(" elapsed time           : %s (%0.3f sec)\n",
  6276.            hhmmss((long)(fptsecs + 0.5)),fptsecs);
  6277. #else
  6278. #ifdef COMMENT
  6279.     printf(" elapsed time           : %s (%d sec)\n",hhmmss(tsecs),tsecs);
  6280. #endif /* COMMENT */
  6281.     printf(" elapsed time           : %d sec, %s\n",tsecs,hhmmss(tsecs));
  6282. #endif /* GFTIMER */
  6283.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6284.     if (!ftp && local && !network && !brief) {
  6285.         if (speed <= 0L) speed = ttgspd();
  6286.         if (speed > 0L) {
  6287.             if (speed == 8880)
  6288.               printf(" transmission rate      : 75/1200 bps\n");
  6289.             else
  6290.               printf(" transmission rate      : %ld bps\n",speed);
  6291.             if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6292.         }
  6293.     }
  6294.     if (!ftp && local && !network &&    /* Only makes sense for */
  6295.         mdmtyp == 0 &&                  /* direct serial connections */
  6296.         speed > 99L &&                  /* when we really know the speed */
  6297.         speed != 8880L
  6298.         ) {
  6299.         int eff;
  6300.         eff = (((tfcps * 100L) / (speed / 100L)) + 5L) / 10L;
  6301.         printf(" effective data rate    : %ld cps (%d%%)\n",tfcps,eff);
  6302.     } else
  6303.       printf(" effective data rate    : %ld cps\n", tfcps);
  6304.     if (!ftp && peakcps > 0L && peakcps > tfcps)
  6305.       printf(" peak data rate         : %ld cps\n", peakcps);
  6306.     if (brief)
  6307.       printf("\nUse STATISTICS /VERBOSE for greater detail.\n\n");
  6308.     return(1);
  6309. }
  6310. #endif /* NOXFER */
  6311.  
  6312. #ifndef NOSPL
  6313.  
  6314. /* The INPUT command */
  6315.  
  6316. /*
  6317.   NOTE: An INPUT timeout of 0 means to perform a nonblocking read of the
  6318.   material that has already arrived and is waiting to be read, and perform
  6319.   matches against it, without doing any further reads.  It should succeed
  6320.   or fail instantaneously.
  6321. */
  6322.  
  6323. /* Output buffering for "doinput" */
  6324.  
  6325. #ifdef pdp11
  6326. #define MAXBURST 16             /* Maximum size of input burst */
  6327. #else
  6328. #define MAXBURST 1024
  6329. #endif /* pdp11 */
  6330. #ifdef OSK
  6331. static CHAR *conbuf;            /* Buffer to hold output for console */
  6332. #else
  6333. static CHAR conbuf[MAXBURST];   /* Buffer to hold output for console */
  6334. #endif /* OSK */
  6335. static int concnt = 0;          /* Number of characters buffered */
  6336. #ifdef OSK
  6337. static CHAR *sesbuf;            /* Buffer to hold output for session log */
  6338. #else
  6339. static CHAR sesbuf[MAXBURST];   /* Buffer to hold output for session log */
  6340. #endif /* OSK */
  6341. static int sescnt = 0;          /* Number of characters buffered */
  6342.  
  6343. extern int debses;                      /* TERMINAL DEBUG ON/OFF */
  6344.  
  6345. static VOID                             /* Flush INPUT echoing */
  6346. myflsh() {                              /* and session log output. */
  6347.     if (concnt > 0) {
  6348.         if (debses) {                   /* Terminal debugging? */
  6349.             int i;
  6350.             for (i = 0; i < concnt; i++)
  6351.               conol(dbchr(conbuf[i]));
  6352.         } else
  6353.           conxo(concnt, (char *) conbuf);
  6354.         concnt = 0;
  6355.     }
  6356.     if (sescnt > 0) {
  6357.         logstr((char *) sesbuf, sescnt);
  6358.         sescnt = 0;
  6359.     }
  6360. }
  6361.  
  6362. /* Execute the INPUT and MINPUT commands */
  6363.  
  6364. int instatus = -1;
  6365. long inetime = -1L;
  6366. int inwait = 0;
  6367.  
  6368. /* For returning the input sequence that matched */
  6369.  
  6370. #ifdef BIGBUFOK
  6371. #define MATCHBUFSIZ 8191
  6372. #else
  6373. #define MATCHBUFSIZ 1023
  6374. #endif /* BIGBUFOK */
  6375. static char * matchbuf = NULL;
  6376. static int matchindex = 0;
  6377. /*
  6378.   timo = How long to wait:
  6379.          < 0 = Wait forever
  6380.            0 = Don't wait
  6381.          > 0 = Wait this many seconds
  6382.   ms   = Array of strings to wait for.
  6383.   mp   = Array of flags.
  6384.          If mp[i] == 0, ms[i] is literal, else it's a pattern.
  6385. */
  6386. int
  6387. doinput(timo,ms,mp) int timo; char *ms[]; int mp[]; {
  6388.     extern int inintr;
  6389. #ifdef CK_AUTODL
  6390.     extern int inautodl;
  6391. #endif /* CK_AUTODL */
  6392.     int x, y, i, t, rt, icn, anychar, mi[MINPMAX];
  6393. #ifdef GFTIMER
  6394.     CKFLOAT fpt = 0.0;
  6395. #endif /* GFTIMER */
  6396.     int lastchar = 0;
  6397.     int waiting = 0;
  6398.     int imask = 0;
  6399.     char ch, *xp, *s;
  6400.     CHAR c;
  6401. #ifndef NOLOCAL
  6402. #ifdef OS2
  6403.     extern int term_io;
  6404.     int term_io_save;
  6405. #endif /* OS2 */
  6406. #endif /* NOLOCAL */
  6407. #ifdef TNCODE
  6408.     static int cr = 0;
  6409. #endif /* TNCODE */
  6410.     int is_tn = 0;
  6411.     int wrapped = 0;
  6412.  
  6413. #define CK_BURST
  6414. /*
  6415.   This enables the INPUT speedup code, which depends on ttchk() returning
  6416.   accurate information.  If INPUT fails with this code enabled, change the
  6417.   above "#define" to "#undef".
  6418. */
  6419. #ifdef CK_BURST
  6420.     int burst = 0;                      /* Chars remaining in input burst */
  6421. #endif /* CK_BURST */
  6422.  
  6423.     imask = cmask;
  6424.     if (parity) imask = 0x7f;
  6425.     inwait = timo;                      /* For \v(inwait) */
  6426.     makestr(&inpmatch,NULL);
  6427.  
  6428.     if (!matchbuf) {
  6429.         matchbuf = malloc(MATCHBUFSIZ+1);
  6430.         matchbuf[0] = NUL;
  6431.     }
  6432.     matchindex = 0;
  6433.  
  6434.     is_tn =
  6435. #ifdef TNCODE
  6436.         (local && network && IS_TELNET()) || (!local && sstelnet)
  6437. #else
  6438.          0
  6439. #endif /* TNCODE */
  6440.           ;
  6441.  
  6442.     instatus = INP_IE;                  /* 3 = internal error */
  6443.     kbchar = 0;
  6444.  
  6445. #ifdef OSK
  6446.     if (conbuf == NULL) {
  6447.         if ((conbuf = (CHAR *)malloc(MAXBURST*2)) == NULL) {
  6448.             return(0);
  6449.         }
  6450.         sesbuf = conbuf + MAXBURST;
  6451.     }
  6452. #endif /* OSK */
  6453.  
  6454. #ifndef NOLOCAL
  6455.     if (local) {                        /* In local mode... */
  6456.         if ((waiting = ttchk()) < 0) {  /* check that connection is open */
  6457.             printf("?Connection %s %s is not open.\n",
  6458.                    network ? "to" : "on",
  6459.                    ttname
  6460.                    );
  6461.             instatus = INP_IO;
  6462.             return(0);
  6463.         }
  6464.         debug(F101,"doinput waiting","",waiting);
  6465.         y = ttvt(speed,flow);           /* Put line in "ttvt" mode */
  6466.         if (y < 0) {
  6467.             printf("?INPUT initialization error\n");
  6468.             instatus = INP_IO;
  6469.             return(0);                  /* Watch out for failure. */
  6470.         }
  6471.     }
  6472. #endif /* NOLOCAL */
  6473.  
  6474.     debug(F111,"doinput ms[0]",ms[0],waiting);
  6475.  
  6476.     if (!ms[0]) {                       /* If we were passed a NULL pointer */
  6477.         anychar = 1;                    /*  ... */
  6478.     } else {
  6479.         y = (int)strlen(ms[0]);         /* Or if search string is empty */
  6480.         anychar = (y < 1);              /* any input character will do. */
  6481.     }
  6482.     if (!anychar && waiting == 0 && timo == 0)
  6483.       return(0);
  6484.  
  6485. #ifndef NODEBUG
  6486.     if (deblog) {
  6487.         char xbuf[24];
  6488.         debug(F101,"doinput anychar","",anychar);
  6489.         debug(F101,"doinput timo","",timo);
  6490.         debug(F101,"doinput echo","",inecho);
  6491.         debug(F101,"doinput burst","",burst);
  6492.         y = -1;
  6493.         while (ms[++y]) {
  6494.             sprintf(xbuf,"doinput string %2d",y); /* SAFE (24) */
  6495.             debug(F111,xbuf,ms[y],mp[y]);
  6496.         }
  6497.     }
  6498. #endif /* NODEBUG */
  6499.  
  6500. #ifdef IKS_OPTION
  6501.     if (is_tn) {
  6502.         /* If the remote side is in a state of IKS START-SERVER    */
  6503.         /* we request that the state be changed.  We will detect   */
  6504.         /* a failure to adhere to the request when we call ttinc() */
  6505.         if (TELOPT_U(TELOPT_KERMIT) &&
  6506.             TELOPT_SB(TELOPT_KERMIT).kermit.u_start)
  6507.           iks_wait(KERMIT_REQ_STOP,0);  /* Send Request-Stop */
  6508. #ifdef CK_AUTODL
  6509.         /* If we are processing packets during INPUT and we have not */
  6510.         /* sent a START message, do so now.                          */
  6511.         if (inautodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  6512.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  6513.         }
  6514. #endif /* CK_AUTODL */
  6515.     }
  6516. #endif /* IKS_OPTION */
  6517.     x = 0;                              /* Return code, assume failure */
  6518.     instatus = INP_TO;                  /* Status, assume timeout */
  6519.  
  6520.     for (y = 0; y < MINPMAX; y++)
  6521.       mi[y] = 0;                        /* String pattern match position */
  6522.  
  6523.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  6524.         y = -1;
  6525.  
  6526.         while ((xp = ms[++y])) {
  6527.             while (*xp) {               /* Convert to lowercase */
  6528.                 if (isupper(*xp)) *xp = (char) tolower(*xp);
  6529.                 xp++;
  6530.             }
  6531.         }
  6532.     }
  6533.     rtimer();                           /* Reset timer. */
  6534. #ifdef GFTIMER
  6535.     rftimer();                          /* Floating-point timer too. */
  6536. #endif /* GFTIMER */
  6537.     inetime = -1L;                      /* Initialize elapsed time. */
  6538.     t = 0;                              /* Time now is 0. */
  6539.     m_found = 0;                        /* Default to timed-out */
  6540.     incount = 0;                        /* Character counter */
  6541.     rt = (timo == 0) ? 0 : 1;           /* Character-read timeout interval */
  6542.  
  6543. #ifndef NOLOCAL
  6544. #ifdef OS2
  6545.     term_io_save = term_io;             /* Disable I/O by emulator */
  6546.     term_io = 0;
  6547. #endif /* OS2 */
  6548. #endif /* NOLOCAL */
  6549.  
  6550.     while (1) {                         /* Character-getting loop */
  6551. #ifdef CK_APC
  6552.         /* Check to see if there is an Autodown or other APC command */
  6553.         if (apcactive == APC_LOCAL ||
  6554.             (apcactive == APC_REMOTE && apcstatus != APC_OFF)) {
  6555.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  6556.                 debug(F110,"doinput about to execute APC",apcbuf,0);
  6557.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  6558.                 delmac("_apc_commands",1);
  6559.                 apcactive = APC_INACTIVE;
  6560. #ifdef DEBUG
  6561.             } else {
  6562.                 debug(F100,"doinput APC in progress","",0);
  6563. #endif /* DEBUG */
  6564.             }
  6565.         }
  6566. #endif /* CK_APC */
  6567.  
  6568.         if (timo == 0 && waiting < 1) { /* Special exit criterion */
  6569.             instatus = INP_TO;          /* for timeout == 0 */
  6570.             break;
  6571.         }
  6572.         if (local) {                    /* One case for local */
  6573.             y = ttinc(rt);              /* Get character from comm device */
  6574.             debug(F101,"doinput ttinc(rt) returns","",y);
  6575.             if (y < -1) {               /* Connection failed. */
  6576.                 instatus = INP_IO;      /* Status = i/o error */
  6577. #ifndef NOLOCAL
  6578. #ifdef OS2
  6579.                 term_io = term_io_save;
  6580. #endif /* OS2 */
  6581. #endif /* NOLOCAL */
  6582.                 switch (y) {
  6583.                   case -2:              /* Connection lost */
  6584.                     if (local && !network && carrier != CAR_OFF) {
  6585.                         dologend();
  6586.                         printf("Connection closed.\n");
  6587.                         ttclos(1);
  6588.                     }
  6589.                     break;
  6590.                   case -3:
  6591.                     dologend();
  6592.                     printf("Session Limit exceeded - closing connection.\n");
  6593.                     ttclos(1);
  6594.                   default:
  6595.                     break;
  6596.                 }
  6597.                 debug(F111,"doinput Connection failed","returning 0",y);
  6598.                 return(0);
  6599.             }
  6600.             if (inintr) {
  6601.                 debug(F111,"doinput","inintr",inintr);
  6602.                 if ((icn = conchk()) > 0) { /* Interrupted from keyboard? */
  6603.                     debug(F101,"input interrupted from keyboard","",icn);
  6604.                     kbchar = coninc(0);
  6605.                     if (kbchar >= 0) {
  6606.                         while (--icn > 0) {
  6607.                             debug(F110,"doinput","absorbing",0);
  6608.                             coninc(0);      /* Yes, absorb what was typed. */
  6609.                         }
  6610.                         instatus = INP_UI;  /* Fail and remember why. */
  6611.                         break;
  6612.                     }
  6613.                 }
  6614.             }
  6615.         } else {                        /* Another for remote */
  6616.             y = coninc(rt);
  6617.             debug(F101,"doinput coninc(rt) returns","",y);
  6618.         }
  6619.         if (y > -1) {                   /* A character arrived */
  6620.             debug(F111,"doinput","a character arrived",y);
  6621.             if (timo == 0)
  6622.               waiting--;
  6623. #ifndef OS2
  6624. #define TN_NOLO
  6625. #endif /* OS2 */
  6626. #ifdef NOLOCAL
  6627. #define TN_NOLO
  6628. #endif /* NOLOCAL */
  6629.  
  6630. #ifdef TN_NOLO
  6631.             debug(F100,"doinput TN_NOLO","",0);
  6632. #ifdef TNCODE
  6633.             /* Check for telnet protocol negotiation */
  6634.             if (is_tn) {
  6635.                 switch (y & 0xff) {
  6636.                   case IAC:
  6637.                     cr = 0;
  6638.                     myflsh();   /* Break from input burst for tn_doop() */
  6639. #ifdef CK_BURST
  6640.                     burst = 0;
  6641. #endif /* CK_BURST */
  6642.                     waiting -= 2;       /* (not necessarily...) */
  6643.                     switch (tn_doop((CHAR)(y & 0xff),duplex,ttinc)) {
  6644.                       case 2: duplex = 0; continue;
  6645.                       case 1: duplex = 1; continue;
  6646. #ifdef IKS_OPTION
  6647.                       case 4:
  6648.                         if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6649.                              !tcp_incoming) {
  6650.                             instatus = INP_IKS;
  6651.                             printf(
  6652.  " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6653.                                    );
  6654.                             break;
  6655.                         }
  6656.                         continue;
  6657. #endif /* IKS_OPTION */
  6658.                       case 6:           /* TELNET DO LOGOUT received */
  6659.                       default: continue;
  6660.                     }
  6661.                   case CR:
  6662.                     cr = 1;
  6663.                     break;
  6664.                   case NUL:
  6665.                     if (!TELOPT_U(TELOPT_BINARY) && cr) {
  6666.                         cr = 0;
  6667.                         continue;
  6668.                     }
  6669.                     cr = 0;
  6670.                     break;
  6671.                   default:
  6672.                     cr = 0;
  6673.                 }
  6674.                 /* I'm echoing remote chars */
  6675.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6676.                   ttoc((char)y);
  6677.             }
  6678. #endif /* TNCODE */
  6679. #ifdef CK_AUTODL
  6680.             /* Check for file transfer packets */
  6681.             if (inautodl) autodown(y);
  6682. #endif /* CK_AUTODL */
  6683. #else  /* TN_NOLO */
  6684.             debug(F100,"doinput !TN_NOLO","",0);
  6685. #ifdef TNCODE
  6686.             /* Check for telnet protocol negotiation */
  6687.             if (is_tn) {
  6688.                 int tx;
  6689.                 switch (y & 0xff) {
  6690.                   case IAC:
  6691.                     myflsh();   /* Break from input burst for tn_doop() */
  6692. #ifdef CK_BURST
  6693.                     burst = 0;
  6694. #endif /* CK_BURST */
  6695. #ifdef IKS_OPTION
  6696.                     tx = scriptwrtbuf((USHORT)y);
  6697.                     if (tx == 4) {
  6698.                         if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6699.                             !tcp_incoming
  6700.                             ) {
  6701.                             instatus = INP_IKS;
  6702.                             printf(
  6703.   " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6704.                                    );
  6705.                             break;
  6706.                         }
  6707.                     } else if (tx == 6) {
  6708.                         /* TELNET DO LOGOUT received */
  6709.  
  6710.                     }
  6711. #else /* IKS_OPTION */
  6712.                     /* Handles Telnet negotiations */
  6713.                     tx = scriptwrtbuf((USHORT)y);
  6714.                     if (tx == 6) {
  6715.                         /* TELNET DO LOGOUT received */
  6716.                     }
  6717. #endif /* IKS_OPTION */
  6718.                     waiting -= 2;       /* (not necessarily...) */
  6719.                     cr = 0;
  6720.                     continue;           /* and autodownload check */
  6721.                   case CR:
  6722.                     cr = 1;
  6723.                     tx = scriptwrtbuf((USHORT)y);
  6724.                     if (tx == 6) {
  6725.                         /* TELNET DO LOGOUT received */
  6726.                     }
  6727.                     break;
  6728.                   case NUL:
  6729.                     cr = 0;
  6730.                     if (!TELOPT_U(TELOPT_BINARY) && cr)
  6731.                       continue;
  6732.                     tx = scriptwrtbuf((USHORT)y);
  6733.                     if (tx == 6) {
  6734.                         /* TELNET DO LOGOUT received */
  6735.                     }
  6736.                     break;
  6737.                   default:
  6738.                     cr = 0;
  6739.                     tx = scriptwrtbuf((USHORT)y);
  6740.                     if (tx == 6) {
  6741.                         /* TELNET DO LOGOUT received */
  6742.                     }
  6743.                 }
  6744.                 /* I'm echoing remote chars */
  6745.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6746.                   ttoc((CHAR)y);
  6747.             } else
  6748. #endif /* TNCODE */
  6749.               /* Handles terminal emulation responses */
  6750.               scriptwrtbuf((USHORT)y);
  6751. #endif /* TN_NOLO */
  6752.  
  6753.             /* Real input character to be checked */
  6754.  
  6755. #ifdef CK_BURST
  6756.             burst--;                    /* One less character waiting */
  6757.             debug(F101,"doinput burst","",burst);
  6758. #endif /* CK_BURST */
  6759.             c = (CHAR) (imask & (CHAR) y); /* Mask off any parity */
  6760.             inchar[0] = c;              /* Remember character for \v(inchar) */
  6761. #ifdef COMMENT
  6762. #ifdef CK_BURST
  6763.             /* Update "lastchar" time only once during input burst */
  6764.             if (burst <= 0)
  6765. #endif /* CK_BURST */
  6766. #endif /* COMMENT */
  6767.               lastchar = gtimer();      /* Remember when it came */
  6768.  
  6769.             if (c == '\0') {            /* NUL, we can't use it */
  6770.                 if (anychar) {          /* Except if any character will do? */
  6771.                     x = 1;              /* Yes, done. */
  6772.                     incount = 1;        /* This must be the first and only. */
  6773.                     break;
  6774.                 } else goto refill;     /* Otherwise continue INPUTting */
  6775.             }
  6776.             *inpbp++ = c;               /* Store char in circular buffer */
  6777.             incount++;                  /* Count it for \v(incount) */
  6778.  
  6779.             /* Don't NUL-terminate here - it's a circular buffer. */
  6780.  
  6781.             if (inpbp >= inpbuf + inbufsize) { /* Time to wrap around? */
  6782.                 wrapped++;
  6783.                 *inpbp = NUL ;          /* Make it null-terminated */
  6784.                 inpbp = inpbuf;         /* Yes. */
  6785.             }
  6786.             if (matchbuf) {
  6787.                 if (matchindex < MATCHBUFSIZ) {
  6788.                     matchbuf[matchindex++] = c;
  6789.                     matchbuf[matchindex] = NUL;
  6790.                 }
  6791.             }
  6792. #ifdef MAC
  6793.             {
  6794.                 extern char *ttermw;    /* fake pointer cast */
  6795.                 if (inecho) {
  6796.                     outchar(ttermw, c); /* echo to terminal window */
  6797.                     /* this might be too much overhead to do here ? */
  6798.                     updatecommand(ttermw);
  6799.                 }
  6800.             }
  6801. #else /* Not MAC */
  6802.             if (inecho) {               /* Buffer console output */
  6803.                 conbuf[concnt++] = c;
  6804.             }
  6805. #endif /* MAC */
  6806. #ifndef OS2
  6807.             if (seslog) {
  6808. #ifdef UNIX
  6809.                 if (sessft != 0 || c != '\r')
  6810. #else
  6811. #ifdef OSK
  6812.                 if (sessft != 0 || c != '\012')
  6813. #endif /* OSK */
  6814. #endif /* UNIX */
  6815.                   sesbuf[sescnt++] = c; /* Buffer session log output */
  6816.             }
  6817. #endif /* OS2 */
  6818.             if (anychar) {              /* Any character will do? */
  6819.                 x = 1;
  6820.                 break;
  6821.             }
  6822.             if (!inpcas[cmdlvl]) {      /* Ignore alphabetic case? */
  6823.                 if (isupper(c))         /* Yes, convert input char to lower */
  6824.                   c = (CHAR) tolower(c);
  6825.             }
  6826.             debug(F000,"doinput char","",c);
  6827.  
  6828.             /* Here is the matching section */
  6829.  
  6830.             y = -1;                     /* Loop thru search strings */
  6831.             while ((s = ms[++y])) {     /* ...as many as we have. */
  6832.                 if (mp[y]) {            /* Pattern match? */
  6833. #ifdef COMMENT
  6834.                     int j;
  6835.                     /* This is gross but it works... */
  6836.                     /* We could just as easily have prepended '*' to the  */
  6837.                     /* pattern and skipped the loop, except then we would */
  6838.                     /* not have any way to identify the matching string.  */
  6839.                     for (j = 0; j < matchindex; j++) {
  6840.                         if (ckmatch(s,&matchbuf[j],1,1)) {
  6841.                             matchindex = j;
  6842.                             x = 1;
  6843.                             break;
  6844.                         }
  6845.                     }
  6846.                     if (x > 0)
  6847.                       break;
  6848. #else
  6849.                     /* July 2001 - ckmatch() returns match position. */
  6850.                     /* It works and it's not gross. */
  6851.                     x = ckmatch(s,matchbuf,1,1+4); /* (4 = floating pattern) */
  6852.                     if (x > 0) {
  6853.                         matchindex = x - 1;
  6854.                         x = 1;
  6855.                         break;
  6856.                     }
  6857. #endif /* COMMENT */
  6858.                     continue;
  6859.                 }                       /* Literal match. */
  6860.                 i = mi[y];              /* Match-position in search string. */
  6861.                 debug(F000,"compare char","",(CHAR)s[i]);
  6862.                 if (c == (CHAR) s[i]) { /* Check for match */
  6863.                     i++;                /* Got one, go to next character */
  6864.                 } else {                /* Don't have a match */
  6865.                     int j;
  6866.                     for (j = i; i > 0; ) { /* Back up in search string */
  6867.                         i--; /* (Do this here to prevent compiler foulup) */
  6868.                         /* j is the length of the substring that matched */
  6869.                         if (c == (CHAR) s[i]) {
  6870.                             if (!strncmp(s,&s[j-i],i)) {
  6871.                                 i++;          /* c actually matches -- cfk */
  6872.                                 break;
  6873.                             }
  6874.                         }
  6875.                     }
  6876.                 }
  6877.                 if ((CHAR) s[i] == (CHAR) '\0') { /* Matched to end? */
  6878.                     ckstrncpy(matchbuf,ms[y],MATCHBUFSIZ);
  6879.                     matchindex = 0;
  6880.                     x = 1;              /* Yes, */
  6881.                     break;              /* done. */
  6882.                 }
  6883.                 mi[y] = i;              /* No, remember match-position */
  6884.             }
  6885.             if (x == 1) {               /* Set \v(minput) result */
  6886.                 m_found = y + 1;
  6887.                 break;
  6888.             }
  6889.         }
  6890. #ifdef CK_BURST
  6891.         else if (y <= -1 && burst > 0) {
  6892.             debug(F111,"doinput (y<=-1&&burst>0)","burst",burst);
  6893.                                         /* a timo occurred so there can't   */
  6894.             burst = 0;                  /* be data waiting; must check timo */
  6895.         }
  6896.       refill:
  6897.         if (burst <= 0) {               /* No buffered chars remaining... */
  6898.             myflsh();                   /* Flush buffered output */
  6899.             if (local) {                /* Get size of next input burst */
  6900.                 burst = ttchk();
  6901.                 if (burst < 0) {        /* ttchk() says connection is closed */
  6902.                     instatus = INP_IO;  /* Status = i/o error */
  6903. #ifndef NOLOCAL
  6904. #ifdef OS2
  6905.                     term_io = term_io_save;
  6906. #endif /* OS2 */
  6907. #endif /* NOLOCAL */
  6908.                     printf("Fatal error - disconnected.\n");
  6909.                     ttclos(1);
  6910.                     break;
  6911.                 }
  6912.                 if (inintr) {
  6913.                     if ((icn = conchk()) > 0) { /* Interrupt from keyboard? */
  6914.                         kbchar = coninc(0);
  6915.                         debug(F101,"input interrupted from keyboard","",icn);
  6916.                         while (--icn > 0) coninc(0); /* Yes, absorb chars. */
  6917.                         break;          /* And fail. */
  6918.                     }
  6919.                 }
  6920.             } else {
  6921.                 burst = conchk();
  6922.             }
  6923.             debug(F101,"doinput burst","",burst);
  6924.             /* Prevent overflow of "conbuf" and "sesbuf" */
  6925.             if (burst > MAXBURST)
  6926.               burst = MAXBURST;
  6927.  
  6928.             /* Did not match, timer exceeded? */
  6929.             t = gtimer();
  6930.             debug(F111,"doinput gtimer","burst",t);
  6931.             debug(F101,"doinput timo","",timo);
  6932.             if ((t >= timo) && (timo > 0))
  6933.               break;
  6934.             else if (insilence > 0 && (t - lastchar) > insilence)
  6935.               break;
  6936.         } else {
  6937.             debug(F111,"doinput (burst > 0)","burst",burst);
  6938.         }
  6939. #else
  6940.         myflsh();                       /* Flush buffered output */
  6941.         /* Did not match, timer exceeded? */
  6942.         t = gtimer();
  6943.         debug(F111,"doinput gtimer","no burst",t);
  6944.         debug(F101,"doinput timo","",timo);
  6945.         if ((t >= timo) && (timo > -1))
  6946.           break;
  6947.         else if (insilence > 0 && (t - lastchar) > insilence)
  6948.           break;
  6949. #endif /* CK_BURST */
  6950.     }                                   /* Still have time left, continue. */
  6951.     myflsh();                           /* Flush buffered output. */
  6952.     if (x > 0)
  6953.       instatus = 0;
  6954. #ifndef NOLOCAL
  6955. #ifdef OS2
  6956.     term_io = term_io_save;
  6957. #endif /* OS2 */
  6958. #endif /* NOLOCAL */
  6959. #ifdef COMMENT
  6960. #ifdef IKS_OPTION
  6961. #ifdef CK_AUTODL
  6962.     if (is_tn && TELOPT_ME(TELOPT_KERMIT) && inautodl) {
  6963.         tn_siks(KERMIT_STOP);           /* Send Kermit-Server Stop */
  6964.     }
  6965. #endif /* CK_AUTODL */
  6966. #endif /* IKS_OPTION */
  6967. #endif /* COMMENT */
  6968.  
  6969. #ifdef GFTIMER
  6970.     fpt = gftimer();                    /* Get elapsed time */
  6971.  
  6972. /* If a long is 32 bits, it would take about 50 days for this to overflow. */
  6973.  
  6974.     inetime = (int)(fpt * (CKFLOAT)1000.0);
  6975. #else
  6976.     inetime = (int)(gtimer() * 1000);
  6977. #endif /* GFTIMER */
  6978.  
  6979.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  6980.     return(x);                          /* Return the return code. */
  6981. }
  6982. #endif /* NOSPL */
  6983.  
  6984. #ifndef NOSPL
  6985. /* REINPUT Command */
  6986.  
  6987. /*
  6988.   Note, the timeout parameter is required, but ignored.  Syntax is compatible
  6989.   with MS-DOS Kermit except timeout can't be omitted.  This function only
  6990.   looks at the characters already received and does not read any new
  6991.   characters from the connection.
  6992. */
  6993. int
  6994. doreinp(timo,s,pat) int timo; char *s; int pat; {
  6995.     int x, y, i;
  6996.     char *xx, *xp, *xq = (char *)0;
  6997.     CHAR c;
  6998.  
  6999.     if (!s) s = "";
  7000.     debug(F101,"doreinput pat","",pat);
  7001.  
  7002.     y = (int)strlen(s);
  7003.     debug(F111,"doreinput search",s,y);
  7004.  
  7005.     if (y > inbufsize) {                /* If search string longer than */
  7006.         debug(F101,"doreinput inbufsize","",inbufsize);
  7007.         return(0);                      /* input buffer, fail. */
  7008.     }
  7009.     makestr(&inpmatch,NULL);
  7010.     if (!matchbuf)
  7011.       matchbuf = malloc(MATCHBUFSIZ+1);
  7012.     matchindex = 0;
  7013.  
  7014.     x = 0;                              /* Return code, assume failure */
  7015.     i = 0;                              /* String pattern match position */
  7016.  
  7017.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  7018.         xp = malloc(y+2);               /* Make a separate copy of the */
  7019.         if (!xp) {                      /* search string. */
  7020.             printf("?malloc error 6\n");
  7021.             return(x);
  7022.         } else xq = xp;                 /* Keep pointer to beginning. */
  7023.         while (*s) {                    /* Yes, convert to lowercase */
  7024.             *xp = *s;
  7025.             if (isupper(*xp)) *xp = (char) tolower(*xp);
  7026.             xp++; s++;
  7027.         }
  7028.         *xp = NUL;                      /* Terminate it! */
  7029.         s = xq;                         /* Move search pointer to it. */
  7030.     }
  7031.     xx = *inpbp ? inpbp : inpbuf;       /* Current INPUT buffer pointer */
  7032.     do {
  7033.         c = *xx++;                      /* Get next character */
  7034.         if (!c) break;
  7035.         if (xx >= inpbuf + inbufsize)   /* Wrap around if necessary */
  7036.           xx = inpbuf;
  7037.         if (!inpcas[cmdlvl]) {          /* Ignore alphabetic case? */
  7038.             if (isupper(c)) c = (CHAR) tolower(c); /* Yes */
  7039.         }
  7040.         if (pat) {
  7041.             int j;
  7042.             if (matchbuf) {
  7043.                 if (matchindex < MATCHBUFSIZ) {
  7044.                     matchbuf[matchindex++] = c;
  7045.                     matchbuf[matchindex] = NUL;
  7046.                 }
  7047.                 for (j = 0; j < matchindex; j++) { /* Gross but effective */
  7048.                     if (ckmatch(s,&matchbuf[j],1,1)) {
  7049.                         debug(F101,"GOT IT","",j);
  7050.                         matchindex = j;
  7051.                         x = 1;
  7052.                         break;
  7053.                     }
  7054.                 }
  7055.             }
  7056.             if (x > 0)
  7057.               break;
  7058.             continue;
  7059.         }
  7060.         debug(F000,"doreinp char","",c);
  7061.         debug(F000,"compare char","",(CHAR) s[i]);
  7062.         if (((char) c) == ((char) s[i])) { /* Check for match */
  7063.             i++;                        /* Got one, go to next character */
  7064.         } else {                        /* Don't have a match */
  7065.             int j;
  7066.             for (j = i; i > 0; ) {      /* [jrs] search backwards for it  */
  7067.                 i--;
  7068.                 if (((char) c) == ((char) s[i])) {
  7069.                     if (!strncmp(s,&s[j-i],i)) {
  7070.                         i++;
  7071.                         break;
  7072.                     }
  7073.                 }
  7074.             }
  7075.         }                               /* [jrs] or return to zero from -1 */
  7076.         if (s[i] == '\0') {             /* Matched all the way to end? */
  7077.             ckstrncpy(matchbuf,s,MATCHBUFSIZ);
  7078.             matchindex = 0;
  7079.             x = 1;                      /* Yes, */
  7080.             break;                      /* done. */
  7081.         }
  7082.     } while (xx != inpbp && x < 1);     /* Until back where we started. */
  7083.  
  7084.     if (!inpcas[cmdlvl]) if (xq) free(xq); /* Free this if it was malloc'd. */
  7085.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  7086.     return(x);                          /* Return search result. */
  7087. }
  7088.  
  7089. /*  X X S T R I N G  --  Interpret strings containing backslash escapes  */
  7090. /*  Z Z S T R I N G  --  (new name...)  */
  7091. /*
  7092.  Copies result to new string.
  7093.   strips enclosing braces or doublequotes.
  7094.   interprets backslash escapes.
  7095.   returns 0 on success, nonzero on failure.
  7096.   tries to be compatible with MS-DOS Kermit.
  7097.  
  7098.  Syntax of input string:
  7099.   string = chars | "chars" | {chars}
  7100.   chars = (c*e*)*
  7101.   where c = any printable character, ascii 32-126
  7102.   and e = a backslash escape
  7103.   and * means 0 or more repetitions of preceding quantity
  7104.   backslash escape = \operand
  7105.   operand = {number} | number | fname(operand) | v(name) | $(name) | m(name)
  7106.   number = [r]n[n[n]]], i.e. an optional radix code followed by 1-3 digits
  7107.   radix code is oO (octal), xX (hex), dD or none (decimal) (see xxesc()).
  7108. */
  7109.  
  7110. #ifndef NOFRILLS
  7111. int
  7112. yystring(s,s2) char *s; char **s2; {    /* Reverse a string */
  7113.     int x;
  7114.     static char *new;
  7115.     new = *s2;
  7116.     if (!s || !new) return(-1);         /* Watch out for null pointers. */
  7117.     if ((x = (int)strlen(s)) == 0) {    /* Recursion done. */
  7118.         *new = '\0';
  7119.         return(0);
  7120.     }
  7121.     x--;                                /* Otherwise, call self */
  7122.     *new++ = s[x];                      /* to reverse rest of string. */
  7123.     s[x] = 0;
  7124.     return(yystring(s,&new));
  7125. }
  7126. #endif /* NOFRILLS */
  7127.  
  7128. static char ipabuf[16] = { NUL };       /* IP address buffer */
  7129.  
  7130. static char *
  7131. getip(s) char *s; {
  7132.     char c=NUL;                         /* Workers... */
  7133.     int i=0, p=0, d=0;
  7134.     int state = 0;                      /* State of 2-state FSA */
  7135.  
  7136.     while ((c = *s++)) {
  7137.         switch(state) {
  7138.           case 0:                       /* Find first digit */
  7139.             i = 0;                      /* Output buffer index */
  7140.             ipabuf[i] = NUL;            /* Initialize output buffer */
  7141.             p = 0;                      /* Period counter */
  7142.             d = 0;                      /* Digit counter */
  7143.             if (isdigit(c)) {           /* Have first digit */
  7144.                 d = 1;                  /* Count it */
  7145.                 ipabuf[i++] = c;        /* Copy it */
  7146.                 state = 1;              /* Change state */
  7147.             }
  7148.             break;
  7149.  
  7150.           case 1:                       /* In numeric field */
  7151.             if (isdigit(c)) {           /* Have digit */
  7152.                 if (++d > 3)            /* Too many */
  7153.                   state = 0;            /* Start over */
  7154.                 else                    /* Not too many */
  7155.                   ipabuf[i++] = c;      /* Keep it */
  7156.             } else if (c == '.' && p < 3) { /* Have a period */
  7157.                 p++;                    /* Count it */
  7158.                 if (d == 0)             /* Not preceded by a digit */
  7159.                   state = 0;            /* Start over */
  7160.                 else                    /* OK */
  7161.                   ipabuf[i++] = c;      /* Keep it */
  7162.                 d = 0;                  /* Reset digit counter */
  7163.             } else if (p == 3 && d > 0) { /* Not part of address */
  7164.                 ipabuf[i] = NUL;        /* If we have full IP address */
  7165.                 return((char *)ipabuf); /* Return it */
  7166.             } else {                    /* Otherwise */
  7167.                 state = 0;              /* Start over */
  7168.                 ipabuf[0] = NUL;        /* (in case no more chars left) */
  7169.             }
  7170.         }
  7171.     }                                   /* Fall thru at end of string */
  7172.     ipabuf[i] = NUL;                    /* Maybe we have one */
  7173.     return((p == 3 && d > 0) ? (char *)ipabuf : "");
  7174. }
  7175. #endif /* NOSPL */
  7176.  
  7177. /* Date Routines */
  7178.  
  7179. /* Z J D A T E  --  Convert yyyymmdd date to Day of Year */
  7180.  
  7181. static int jdays[12] = {  0,31,59,90,120,151,181,212,243,273,304,334 };
  7182. static int ldays[12] = {  0,31,60,91,121,152,182,213,244,274,305,335 };
  7183. static char zjdbuf[12] = { NUL, NUL };
  7184. /*
  7185.   Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat,
  7186.   statuimus bissextum quarto quoque anno (uti mos est) continuari debere,
  7187.   praeterquam in centesimis annis; qui, quamvis bissextiles antea semper
  7188.   fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps
  7189.   consequentur centesimi non omnes bissextiles sint, sed in quadringentis
  7190.   quibusque annis primi quique tres centesimi sine bissexto transigantur,
  7191.   quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC,
  7192.   MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus
  7193.   intercaletur, februario dies XXIX continente, idemque ordo intermittendi
  7194.   intercalandique bissextum diem in quadringentis quibusque annis perpetuo
  7195.   conservetur.  - Gregorius XIII, Anno Domini MDLXXXII.
  7196. */
  7197. char *
  7198. zjdate(date) char * date; {             /* date = yyyymmdd */
  7199.     char year[5];
  7200.     char month[3];
  7201.     char day[3];
  7202.     int d, m, x, y;
  7203.     int leapday, j;
  7204.     char * time = NULL;
  7205.  
  7206.     if (!date) date = "";               /* Validate arg */
  7207.     x = strlen(date);
  7208.     if (x < 1) return("0");
  7209.     if (x < 8) return("-1");
  7210.     for (x = 0; x < 8; x++)
  7211.       if (!isdigit(date[x]))
  7212.         return("-1");
  7213.  
  7214.     if (date[8]) if (date[9])
  7215.       time = date + 9;
  7216.  
  7217.     year[0] = date[0];                  /* Isolate year */
  7218.     year[1] = date[1];
  7219.     year[2] = date[2];
  7220.     year[3] = date[3];
  7221.     year[4] = '\0';
  7222.  
  7223.     month[0] = date[4];                 /* Month */
  7224.     month[1] = date[5];
  7225.     month[2] = '\0';;
  7226.  
  7227.     day[0] = date[6];                   /* And day */
  7228.     day[1] = date[7];
  7229.     day[2] = '\0';
  7230.  
  7231.     leapday = 0;                        /* Assume no leap day */
  7232.     y = atoi(year);
  7233.     m = atoi(month);
  7234.     d = atoi(day);
  7235.     if (m > 2) {                        /* No Leap day before March */
  7236.         if (y % 4 == 0) {               /* If year is divisible by 4 */
  7237.             leapday = 1;                /* It's a Leap year */
  7238.             if (y % 100 == 0) {         /* Except if divisible by 100 */
  7239.                 if (y % 400 != 0)       /* but not by 400 */
  7240.                   leapday = 0;
  7241.             }
  7242.         }
  7243.     }
  7244.     j = jdays[m - 1] + d + leapday;     /* Day of year */
  7245.     if (time)
  7246.       sprintf(zjdbuf,"%04d%03d %s",y,j,time); /* SAFE */
  7247.     else
  7248.       sprintf(zjdbuf,"%04d%03d",y,j);   /* SAFE */
  7249.     return((char *)zjdbuf);
  7250. }
  7251.  
  7252. static char jzdbuf[32];
  7253.  
  7254. /* J Z D A T E  --  Convert Day of Year to yyyyddmm date */
  7255.  
  7256. char *
  7257. jzdate(date) char * date; {             /* date = yyyyddd */
  7258.     char year[5];                       /* with optional time */
  7259.     char day[4];
  7260.     char * time = NULL, * p;
  7261.     int d, m, x, y;
  7262.     int leapday, j;
  7263.     int * zz;
  7264.  
  7265.     if (!date) date = "";               /* Validate arg */
  7266.     x = strlen(date);
  7267.  
  7268.     debug(F111,"jzdate len",date,x);
  7269.  
  7270.     if (x < 1) return("0");
  7271.     if (x < 7) return("-1");
  7272.     if (x > 8) time = date + 8;
  7273.  
  7274.     for (x = 0; x < 7; x++)
  7275.       if (!isdigit(date[x]))
  7276.         return("-1");
  7277.  
  7278.     year[0] = date[0];                  /* Isolate year */
  7279.     year[1] = date[1];
  7280.     year[2] = date[2];
  7281.     year[3] = date[3];
  7282.     year[4] = '\0';
  7283.  
  7284.     debug(F110,"jzdate year",year,0);
  7285.  
  7286.     day[0] = date[4];                   /* And day */
  7287.     day[1] = date[5];
  7288.     day[2] = date[6];
  7289.     day[3] = '\0';
  7290.  
  7291.     debug(F110,"jzdate day",day,0);
  7292.  
  7293.     j = atoi(day);
  7294.     if (j > 366)
  7295.       return("-1");
  7296.  
  7297.     leapday = 0;                        /* Assume no leap day */
  7298.     y = atoi(year);
  7299.     if (y % 4 == 0) {                   /* If year is divisible by 4 */
  7300.         leapday = 1;                    /* It's a Leap year */
  7301.         if (y % 100 == 0) {             /* Except if divisible by 100 */
  7302.             if (y % 400 != 0)           /* but not by 400 */
  7303.               leapday = 0;
  7304.         }
  7305.     }
  7306.     debug(F101,"jzdate leapday","",leapday);
  7307.     zz = leapday ? ldays : jdays;
  7308.  
  7309.     for (x = 0; x < 11; x++)
  7310.       if (j > zz[x] && j <= zz[x+1])
  7311.         break;
  7312.     m = x + 1;
  7313.  
  7314.     debug(F101,"jzdate m","",m);
  7315.  
  7316.     d = j - zz[x];
  7317.  
  7318.     debug(F101,"jzdate d","",d);
  7319.  
  7320.     if (time)
  7321.       sprintf(jzdbuf,"%04d%02d%02d %s",y,m,d,time); /* SAFE */
  7322.     else
  7323.       sprintf(jzdbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7324.  
  7325.     debug(F101,"jzdate jzdbuf",jzdbuf,0);
  7326.  
  7327.     p = ckcvtdate((char *)jzdbuf, 0);   /* Convert to standard form */
  7328.     ckstrncpy(jzdbuf,p,32);
  7329.     if (!time) jzdbuf[8] = NUL;         /* Remove time if not wanted */
  7330.     return((char *)jzdbuf);
  7331. }
  7332.  
  7333. /* M J D  --  Modified Julian Date */
  7334. /*
  7335.   Call with:
  7336.     Standard-format date-time string: yyyymmdd[ hh:mm:ss].
  7337.     The time, if any, is ignored.
  7338.  
  7339.   Returns:
  7340.     -1L on error, otherwise:
  7341.     The number of days since 17 Nov 1858 as a whole number:
  7342.     16 Nov 1858 = -1, 17 Nov 1858 = 0, 18 Nov 1858 = 1, 19 Nov 1858 = 2, ...
  7343.  
  7344.   The Modified Julian Date is defined by the International Astronomical
  7345.   Union as the true Julian date minus 2400000.5 days.  The true Julian
  7346.   date is the number days since since noon of 1 January 4713 BCE of the
  7347.   Julian proleptic calendar.  Conversions between calendar dates and
  7348.   Julian dates, however, assume Gregorian dating.
  7349. */
  7350. long
  7351. mjd(date) char * date; {
  7352.     char year[5];
  7353.     char month[3];
  7354.     char day[3];
  7355.     int x, a, d, m, y;
  7356.     long z;
  7357.  
  7358.     if (!date) date = "";               /* Validate arg */
  7359.     x = strlen(date);
  7360.     if (x < 1) return(0L);
  7361.     if (x < 8) return(-1L);
  7362.     for (x = 0; x < 8; x++)
  7363.       if (!isdigit(date[x]))
  7364.         return(-1L);
  7365.  
  7366.     year[0] = date[0];                  /* Isolate year */
  7367.     year[1] = date[1];
  7368.     year[2] = date[2];
  7369.     year[3] = date[3];
  7370.     year[4] = '\0';
  7371.  
  7372.     month[0] = date[4];                 /* Month */
  7373.     month[1] = date[5];
  7374.     month[2] = '\0';;
  7375.     m = atoi(month);
  7376.  
  7377.     day[0] = date[6];                   /* And day */
  7378.     day[1] = date[7];
  7379.     day[2] = '\0';
  7380.     d = atoi(day);
  7381.  
  7382.     a = (14-m)/12;                      /* Calculate true Julian date */
  7383.     y = atoi(year) + 4800 - a;
  7384.     m = m + 12 * a - 3;
  7385.     z = d + (long)(306*m+5)/10 + (long)(y*365) + y/4 - y/100 + y/400 - 32045L;
  7386.  
  7387.     z -= 2400001L;                      /* Convert JD to MJD */
  7388.  
  7389.     return(z);
  7390. }
  7391.  
  7392. static char mjd2dbuf[32];
  7393.  
  7394. /*  M J D 2 D A T E  --  Converts MJD to yyyymmdd  */
  7395.  
  7396. char *
  7397. #ifdef CK_ANSIC
  7398. mjd2date(long mjd)
  7399. #else
  7400. mjd2date(mjd) long mjd;
  7401. #endif /* CK_ANSIC */
  7402. /* mjd2date */ {
  7403.     long jd, l, n;
  7404.     int d, m, y;
  7405.     jd = (long)(mjd + 2400001L);
  7406.     l = jd + 68569;
  7407.     n = 4 * l / 146097L;
  7408.     l = l - (146097 * n + 3) / 4;
  7409.     y = 4000 * (l + 1) / 1461001L;
  7410.     l = l - 1461 * y / 4 + 31;
  7411.     m = 80 * l / 2447;
  7412.     d = l - 2447 * m / 80;
  7413.     l = m / 11;
  7414.     m = m + 2 - 12 * l;
  7415.     y = 100 * (n - 49) + y + l;
  7416.     sprintf(mjd2dbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7417.     return((char *)mjd2dbuf);
  7418. }
  7419.  
  7420. #ifndef NOSPL
  7421. static char ** flist = (char **) NULL;  /* File list for \fnextfile() */
  7422. static int flistn = 0;                  /* Number of items in file list */
  7423.  
  7424. /*
  7425.   The function return-value buffer must be global, since fneval() returns a
  7426.   pointer to it.  fneval() is called only by zzstring(), which always copies
  7427.   the result out of this buffer to somewhere else, so it's OK to have only
  7428.   one buffer for this in most cases.  However, since function calls can be
  7429.   nested -- e.g. functions whose arguments are functions, or recursive
  7430.   functions, at some point we should convert this to an array of buffers,
  7431.   indexed by function depth (which might or might not be the same as the
  7432.   "depth" variable).  Also, since function results are potentially quite big,
  7433.   we'd need to allocate and deallocate dynamically as we descend and ascend
  7434.   function depth.  Left for a future release...
  7435. */
  7436. char fnval[FNVALL+2];                   /* Function return value  */
  7437. static int fndepth = 0;                 /* (we don't actually use this yet) */
  7438. int fnsuccess = 1;
  7439. extern int fnerror;
  7440.  
  7441. /* f p f o r m a t  --  Floating-point number nicely formatted.  */
  7442. /*
  7443.    Returns results from a circular 1K buffer.
  7444.    Don't count on too many results remaining available at once; it could
  7445.    be anywhere from 5 to maybe 100, depending on the sizes of the results.
  7446. */
  7447. #ifdef CKFLOAT
  7448. #define FPFMTSIZ 1024
  7449. static char fpfmtbuf[FPFMTSIZ] = { NUL, NUL };
  7450. static int fpfbufpos = 0;               /* (why was this char before?) */
  7451.  
  7452. char *
  7453. fpformat(fpresult,places,round) CKFLOAT fpresult; int places, round; {
  7454.     char fbuf[16];                      /* For creating printf format */
  7455.     int nines = 0, sign = 0, x, y, i, j, size = 0;
  7456.     char * buf;
  7457.     CKFLOAT ftmp;
  7458.  
  7459.     x = places ? places : (fp_digits ? fp_digits : 6);
  7460.  
  7461.     debug(F101,"fpformat fpresult","",fpresult);
  7462.     debug(F101,"fpformat places","",places);
  7463.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7464.  
  7465.     ftmp = fpresult;
  7466.     if (ftmp < 0.0) ftmp = 0.0 - fpresult;
  7467.  
  7468. #ifdef FNFLOAT
  7469.     if (!fp_rounding &&                 /* If printf doesn't round, */
  7470.         (places > 0 ||                  /* round result to decimal places. */
  7471.          (places == 0 && round)))
  7472.       fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  7473.     y = (ftmp == 0.0) ? 1 : (int)log10(ftmp);
  7474.     size = y + x + 3;                   /* Estimated length of result */
  7475.     if (fpresult < 0.0) size++;
  7476. #else
  7477.     size = 200;                         /* No way to estimate, be generous */
  7478. #endif /* FNFLOAT */
  7479.  
  7480.     debug(F101,"fpformat size","",size);
  7481.  
  7482.     if (fpfbufpos > (FPFMTSIZ - size))  /* Wrap around if necessary */
  7483.       fpfbufpos = 0;
  7484.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7485.  
  7486.     buf = &fpfmtbuf[fpfbufpos];
  7487.  
  7488.     if (places > 0) {                   /* If places specified */
  7489.         /* use specified places to write given number of digits */
  7490.         sprintf(fbuf,"%%0.%df",places); /* SAFE */
  7491.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7492.     } else {                            /* Otherwise... */
  7493.         /* Go for max precision */
  7494.         sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  7495.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7496.     }
  7497.     if (buf[0] == '-') sign = 1;
  7498.     debug(F111,"fpresult 1 errno",buf,errno); /* Check for over/underflow */
  7499.     debug(F111,"fpresult 1 fpfbufpos",buf,fpfbufpos);
  7500.     /* Give requested decimal places */
  7501.     for (i = sign; i < FPFMTSIZ && buf[i]; i++) {
  7502.         if (buf[i] == '.')              /* First find the decimal point */
  7503.           break;
  7504.         else if (i > fp_digits + sign - 1) /* replacing garbage */
  7505.           buf[i] = '0';                 /* digits with 0... */
  7506.     }
  7507.     if (buf[i] == '.') {                /* Have decimal point */
  7508.         int gotend = 0;
  7509.         /* places < 0 so truncate fraction */
  7510.         if (places < 0 || (places == 0 && round)) {
  7511.             buf[i] = NUL;
  7512.         } else if (places > 0) {        /* d > 0 so this many decimal places */
  7513.             i++;                           /* First digit after decimal */
  7514.             for (j = 0; j < places; j++) { /* Truncate after d decimal */
  7515.                 if (!buf[j+i])        /* places or extend to d  */
  7516.                   gotend = 1;              /* decimal places. */
  7517.                 if (gotend || j+i+sign > fp_digits)
  7518.                   buf[j+i] = '0';
  7519.             }
  7520.             buf[j+i] = NUL;
  7521.         } else {                        /* places == 0 so Do The Right Thing */
  7522.             for (j = (int)strlen(buf) - 1; j > i+1; j--) {
  7523.                 if ((j - sign) > fp_digits)
  7524.                   buf[j] = '0';
  7525.                 if (buf[j] == '0')
  7526.                   buf[j] = NUL; /* Strip useless trailing 0's. */
  7527.                 else
  7528.                   break;
  7529.             }
  7530.         }
  7531.     }
  7532.     fpfmtbuf[FPFMTSIZ-1] = NUL;
  7533.     j = strlen(buf);
  7534.     sign = 0;
  7535.     for (i = j-1; i >= 0; i--) {
  7536.         if (buf[i] == '9')
  7537.           nines++;
  7538.         else
  7539.           break;
  7540.     }
  7541.     /* Do something about xx.xx99999999... */
  7542.     if (nines > 5) {
  7543.         if (isdigit(buf[i]) && i < FPFMTSIZ - 2) {
  7544.             buf[i] = buf[i] + 1;
  7545.             buf[i+1] = '0';
  7546.             buf[i+2] = '\0';
  7547.         }
  7548.     }
  7549.     if (!strncmp(buf,"-0.0",FPFMTSIZ))
  7550.       ckstrncpy(buf,"0.0",FPFMTSIZ);
  7551.     fpfbufpos += (int)strlen(buf) + 1;
  7552.     return((char *)buf);
  7553. }
  7554. #endif /* CKFLOAT */
  7555.  
  7556. static VOID
  7557. evalerr(fn) char * fn; {
  7558.     if (fndiags) {
  7559.         if (divbyzero)
  7560.           ckmakmsg(fnval,FNVALL,"<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  7561.         else
  7562.           ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  7563.     }
  7564. }
  7565.  
  7566. char *
  7567. dokwval(s,sep) char * s, sep; {
  7568.     char c = '\0', * p, * kw = NULL, * vp = NULL;
  7569.     int x;
  7570.     if (!s) return("0");
  7571.     if (!*s) return("0");
  7572.     debug(F110,"kwval arg",s,0);
  7573.     debug(F110,"kwval sep",ckctoa(sep),0);
  7574.     p = (char *)malloc((int)strlen(s)+1);
  7575.     if (!p) return("0");
  7576.     strcpy(p,s);                        /* SAFE */
  7577.     s = p;
  7578.     while (*s < '!' && *s > '\0')       /* Get first nonblank */
  7579.       s++;
  7580.     if (!*s) return("0");
  7581.     if (*s == sep) return("0");
  7582.     kw = s;                             /* Keyword */
  7583.     while (*s > ' ') {
  7584.         if (*s == sep) {                /* keyword=... */
  7585.             c = *s;
  7586.             break;
  7587.         }
  7588.         s++;
  7589.     }
  7590.     *s++ = NUL;                         /* Terminate keyword */
  7591.     while (*s < '!' && *s > '\0')       /* Skip blanks */
  7592.       s++;
  7593.     if (!c && *s == sep) {
  7594.         c = *s++;                       /* Have separator */
  7595.         while (*s < '!' && *s > '\0')   /* Skip blanks */
  7596.           s++;
  7597.     }
  7598.     if (c) {
  7599.         vp = s;
  7600.         while (*s > ' ')                /* Skip to end */
  7601.           s++;
  7602.         *s = NUL;                       /* Terminate value */
  7603.     }
  7604.     debug(F110,"kwval c",ckctoa(c),0);
  7605.     debug(F110,"kwval keyword",kw,0);
  7606.     debug(F110,"kwval value",vp,0);
  7607.     x = c ? addmac(kw,vp) : -1;
  7608.     free(p);
  7609.     return((x < 0) ? "0" : "1");
  7610. }
  7611.  
  7612.  
  7613. static char *                           /* Evaluate builtin functions */
  7614. fneval(fn,argp,argn,xp) char *fn, *argp[]; int argn; char * xp; {
  7615.     int i=0, j=0, k=0, len1=0, len2=0, len3=0, n=0, t=0, x=0, y=0;
  7616.     int cx, failed = 0;                 /* Return code, 0 = ok */
  7617.     long z = 0L;
  7618.     char *bp[FNARGS + 1];               /* Pointers to malloc'd strings */
  7619.     char c = NUL;
  7620.     char *p = NULL, *s = NULL;
  7621.     char *val1 = NULL, *val2 = NULL;    /* Pointers to numeric string values */
  7622.  
  7623. #ifdef RECURSIVE
  7624.     int rsave = recursive;
  7625. #endif /* RECURSIVE */
  7626. #ifdef OS2
  7627.     int zsave = zxpn;
  7628. #endif /* OS2 */
  7629.  
  7630.     if (!fn) fn = "";                   /* Protect against null pointers */
  7631.     if (!*fn) return("");
  7632.  
  7633.     for (i = 0; i < FNARGS; i++)        /* Initialize argument pointers */
  7634.       bp[i] = NULL;
  7635. /*
  7636.   IMPORTANT: Note that argn is not an accurate count of the number of
  7637.   arguments.  We can't really tell if an argument is null until after we
  7638.   execute the code below.  So argn is really the maximum number of arguments
  7639.   we might have.  Argn should always be at least 1, even if the function is
  7640.   called with empty parentheses (but don't count on it).
  7641. */
  7642.     debug(F111,"fneval",fn,argn);
  7643.     debug(F110,"fneval",argp[0],0);
  7644.     if (argn > FNARGS)                  /* Discard excess arguments */
  7645.       argn = FNARGS;
  7646.  
  7647.     fndepth++;
  7648.     debug(F101,"fneval fndepth","",fndepth);
  7649.     p = fnval;
  7650.     fnval[0] = NUL;
  7651.     y = lookup(fnctab,fn,nfuncs,&x);    /* Look up the function name */
  7652.     cx = y;                             /* Because y is too generic... */
  7653.     if (cx < 0) {                        /* Not found */
  7654.         failed = 1;
  7655.         if (fndiags) {                  /* FUNCTION DIAGNOSTIC ON */
  7656.             int x;
  7657.             x = strlen(fn);
  7658.             /* The following sprintf's are safe */
  7659.             switch (cx) {
  7660.               case -1:
  7661.                 if (x + 32 < FNVALL)
  7662.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION:\\f%s()>",fn);
  7663.                 else
  7664.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION>");
  7665.                 break;
  7666.               case -2:
  7667.                 if (x + 26 < FNVALL)
  7668.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS:\\f%s()>",fn);
  7669.                 else
  7670.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS>");
  7671.                 break;
  7672.               case -3:
  7673.                 sprintf(fnval,"<ERROR:FUNCTION_NAME_MISSING:\\f()>");
  7674.                 break;
  7675.               default:
  7676.                 if (x + 26 < FNVALL)
  7677.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE:\\f%s()>",fn);
  7678.                 else
  7679.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE>");
  7680.                 break;
  7681.             }
  7682.         }
  7683.         goto fnend;                     /* Always leave via common exit */
  7684.     }
  7685.     fn = fnctab[x].kwd;                 /* Full name of function */
  7686.  
  7687.     if (argn < 0) {
  7688.         failed = 1;
  7689.         p = fnval;
  7690.         if (fndiags)
  7691.           sprintf(fnval,"<ERROR:MISSING_ARG:\\f%s()>",fn);
  7692.         goto fnend;
  7693.     }
  7694.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7695.         debug(F010,"flit",xp,0);
  7696.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7697.         goto fnend;
  7698.     }
  7699.  
  7700. #ifdef DEBUG
  7701.     if (deblog) {
  7702.         int j;
  7703.         for (j = 0; j < argn; j++)
  7704.           debug(F111,"fneval arg",argp[j],j);
  7705.     }
  7706. #endif /* DEBUG */
  7707.     for (j = argn-1; j >= 0; j--) {     /* Uncount empty trailing args */
  7708.         if (!argp[j])
  7709.           argn--;
  7710.         else if (!*(argp[j]))
  7711.           argn--;
  7712.         else break;
  7713.     }
  7714.     debug(F111,"fneval argn",fn,argn);
  7715. /*
  7716.   \fliteral() and \fcontents() are special functions that do not evaluate
  7717.   their arguments, and are treated specially here.  After these come the
  7718.   functions whose arguments are evaluated in the normal way.
  7719. */
  7720. #ifdef COMMENT
  7721.     /* (moved up) */
  7722.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7723.         debug(F110,"flit",xp,0);
  7724.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7725.         goto fnend;
  7726.     }
  7727. #endif /* COMMENT */
  7728.     if (cx == FN_CON) {                 /* Contents of variable, unexpanded. */
  7729.         char c;
  7730.         if (!(p = argp[0]) || !*p) {
  7731.             failed = 1;
  7732.             p = fnval;
  7733.             if (fndiags)
  7734.               sprintf(fnval,"<ERROR:MISSING_ARG:\\fcontents()>");
  7735.             goto fnend;
  7736.         }
  7737.         p = brstrip(p);
  7738.         if (*p == CMDQ) p++;
  7739.         if ((c = *p) == '%') {          /* Scalar variable. */
  7740.             c = *++p;                   /* Get ID character. */
  7741.             p = "";                     /* Assume definition is empty */
  7742.             if (!c) {                   /* Double paranoia */
  7743.                 failed = 1;
  7744.                 p = fnval;
  7745.                 if (fndiags)
  7746.                   sprintf(fnval,"<ERROR:ARG_BAD_VARIABLE:\\fcontents()>");
  7747.                 goto fnend;
  7748.             }
  7749.             if (c >= '0' && c <= '9') { /* Digit for macro arg */
  7750.                 if (maclvl < 0)         /* Digit variables are global */
  7751.                   p = g_var[c];         /* if no macro is active */
  7752.                 else                    /* otherwise */
  7753.                   p = m_arg[maclvl][c - '0']; /* they're on the stack */
  7754.             } else if (c == '*') {
  7755. #ifdef COMMENT
  7756.                 p = (maclvl > -1) ? m_line[maclvl] : topline;
  7757.                 if (!p) p = "";
  7758. #else
  7759.                 int nx = FNVALL;
  7760.                 char * sx = fnval;
  7761.                 p = fnval;
  7762. #ifdef COMMENT
  7763.                 if (cmdsrc() == 0 && topline)
  7764.                   p = topline;
  7765.                 else
  7766. #endif /* COMMENT */
  7767.                   if (zzstring("\\fjoin(&_[],{ },1)",&sx,&nx) < 0) {
  7768.                     failed = 1;
  7769.                     p = fnval;
  7770.                     if (fndiags)
  7771.                       sprintf(fnval,"<ERROR:OVERFLOW:\\fcontents()>");
  7772.             debug(F110,"zzstring fcontents(\\%*)",p,0);
  7773.                 }
  7774. #endif /* COMMENT */
  7775.             } else {
  7776.                 if (isupper(c)) c -= ('a'-'A');
  7777.                 p = g_var[c];           /* Letter for global variable */
  7778.             }
  7779.             if (!p) p = "";
  7780.             goto fnend;
  7781.         } else if (c == '&') {          /* Array reference. */
  7782.             int vbi, d;
  7783.             if (arraynam(p,&vbi,&d) < 0) { /* Get name and subscript */
  7784.                 failed = 1;
  7785.                 p = fnval;
  7786.                 if (fndiags)
  7787.                   sprintf(fnval,"<ERROR:ARG_BAD_ARRAY:\\fcontents()>");
  7788.                 goto fnend;
  7789.             }
  7790.             if (chkarray(vbi,d) > 0) {  /* Array is declared? */
  7791.                 vbi -= ARRAYBASE;       /* Convert name to index */
  7792.                 if (a_dim[vbi] >= d) {  /* If subscript in range */
  7793.                     char **ap;
  7794.                     ap = a_ptr[vbi];    /* get data pointer */
  7795.                     if (ap) {           /* and if there is one */
  7796.                         p = ap[d];
  7797.                         goto fnend;
  7798.                     }
  7799.                 }
  7800.             } else {
  7801.                 failed = 1;
  7802.                 p = fnval;
  7803.                 if (fndiags)
  7804.                   sprintf(fnval,"<ERROR:ARG_NOT_ARRAY:\\fcontents()>");
  7805.                 goto fnend;
  7806.             }
  7807.         } else {
  7808.             failed = 1;
  7809.             p = fnval;
  7810.             if (fndiags)
  7811.               sprintf(fnval,"<ERROR:ARG_NOT_VARIABLE:\\fcontents()>");
  7812.             goto fnend;
  7813.         }
  7814.     }
  7815.     p = fnval;                          /* Default result pointer */
  7816.     fnval[0] = NUL;                     /* Default result = empty string */
  7817.  
  7818.  
  7819.     for (i = 0; i < argn; i++) {        /* Loop to expand each argument */
  7820.         n = MAXARGLEN;                  /* Allow plenty of space */
  7821.         bp[i] = s = malloc(n+1);        /* Allocate space for this argument */
  7822.         if (bp[i] == NULL) {            /* Handle failure to get space */
  7823.             failed = 1;
  7824.             if (fndiags)
  7825.               ckmakmsg(fnval,FNVALL,"<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  7826.             goto fnend;
  7827.         }
  7828.         p = argp[i] ? argp[i] : "";     /* Point to this argument */
  7829.  
  7830. /*
  7831.   Trim leading and trailing spaces from the original argument, before
  7832.   evaluation.  This code new to edit 184.  Fixed in edit 199 to trim
  7833.   blanks BEFORE stripping braces.
  7834.  
  7835. */
  7836.         {
  7837.             int x, j;
  7838.             x = strlen(p);
  7839.             j = x - 1;                  /* Trim trailing whitespace */
  7840.             while (j > 0 && (*(p + j) == SP || *(p + j) == HT))
  7841.               *(p + j--) = NUL;
  7842.             while (*p == SP || *p == HT) /* Strip leading whitespace */
  7843.               p++;
  7844.             x = strlen(p);
  7845.             if (*p == '{' && *(p+x-1) == '}') { /* NOW strip braces */
  7846.                 p[x-1] = NUL;
  7847.                 p++;
  7848.                 x -= 2;
  7849.             }
  7850.         }
  7851.  
  7852. /* Now evaluate the argument */
  7853.  
  7854.         debug(F111,"fneval calling zzstring",p,n);
  7855.         t = zzstring(p,&s,&n);          /* Expand arg into new space */
  7856.         debug(F101,"fneval zzstring","",t);
  7857.         debug(F101,"fneval zzstring","",n);
  7858.         if (t < 0) {
  7859.             debug(F101,"fneval zzstring fails, arg","",i);
  7860.             failed = 1;
  7861.             if (fndiags) {
  7862.                 if (n == 0)
  7863.                   ckmakmsg(fnval,FNVALL,
  7864.                            "<ERROR:ARG_TOO_LONG:\\f",fn,"()>",NULL);
  7865.                 else
  7866.                   ckmakmsg(fnval,FNVALL,
  7867.                            "<ERROR:ARG_EVAL_FAILURE:\\f",fn,"()>",NULL);
  7868.             }
  7869.             goto fnend;
  7870.         }
  7871.         debug(F111,"fneval arg",bp[i],i);
  7872.     }
  7873.  
  7874. #ifdef DEBUG
  7875.     if (deblog) {
  7876.         int j;
  7877.         for (j = 0; j < argn; j++) {
  7878.             debug(F111,"fneval arg post eval",argp[j],j);
  7879.             debug(F111,"fneval evaluated arg",bp[j],j);
  7880.         }
  7881.     }
  7882. #endif /* DEBUG */
  7883. /*
  7884.   From this point on, bp[0..argn-1] are not NULL and all must be freed
  7885.   before returning.
  7886. */
  7887.     if (argn < 1) {                     /* Catch required args missing */
  7888.         switch (cx) {
  7889.           case FN_DEF:
  7890.           case FN_EVA:
  7891.           case FN_EXE:
  7892.           case FN_CHR:
  7893.           case FN_COD:
  7894.           case FN_MAX:
  7895.           case FN_MIN:
  7896.           case FN_MOD:
  7897.           case FN_FD:
  7898.           case FN_FS:
  7899.           case FN_TOD:
  7900.           case FN_FFN:
  7901.           case FN_BSN:
  7902.           case FN_RAW:
  7903.           case FN_CMD:
  7904.           case FN_2HEX:
  7905.           case FN_2OCT:
  7906.           case FN_DNAM:
  7907. #ifdef FN_ERRMSG
  7908.           case FN_ERRMSG:
  7909. #endif /* FN_ERRMSG */
  7910. #ifdef CK_KERBEROS
  7911.           case FN_KRB_TK:
  7912.           case FN_KRB_NX:
  7913.           case FN_KRB_IV:
  7914.           case FN_KRB_TT:
  7915.           case FN_KRB_FG:
  7916. #endif /* CK_KERBEROS */
  7917.           case FN_MJD2:
  7918.           case FN_N2TIM:
  7919.           case FN_DIM:
  7920.           case FN_DATEJ:
  7921.           case FN_PNCVT:
  7922.           case FN_PERM:
  7923.           case FN_ALOOK:
  7924.           case FN_TLOOK:
  7925.           case FN_ABS:
  7926.           case FN_AADUMP:
  7927.           case FN_JOIN:
  7928. #ifdef CKFLOAT
  7929.           case FN_FPABS:
  7930.           case FN_FPEXP:
  7931.           case FN_FPLOG:
  7932.           case FN_FPLN:
  7933.           case FN_FPMOD:
  7934.           case FN_FPSQR:
  7935.           case FN_FPADD:
  7936.           case FN_FPDIV:
  7937.           case FN_FPMUL:
  7938.           case FN_FPPOW:
  7939.           case FN_FPSUB:
  7940.           case FN_FPINT:
  7941.           case FN_FPROU:
  7942.           case FN_FPSIN:
  7943.           case FN_FPCOS:
  7944.           case FN_FPTAN:
  7945. #endif /* CKFLOAT */
  7946. #ifdef TCPSOCKET
  7947.           case FN_HSTADD:
  7948.           case FN_HSTNAM:
  7949. #endif /* TCPSOCKET */
  7950.           case FN_DELSEC:
  7951.           case FN_KWVAL:
  7952. #ifdef COMMENT
  7953.           case FN_SLEEP:
  7954.           case FN_MSLEEP:
  7955. #endif /* COMMENT */
  7956. #ifdef NT
  7957.           case FN_SNAME:
  7958.           case FN_LNAME:
  7959. #endif /* NT */
  7960.             failed = 1;
  7961.             p = fnval;
  7962.             if (fndiags)
  7963.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  7964.             goto fnend;
  7965.         }
  7966.     }
  7967.     p = fnval;                          /* Reset these again. */
  7968.     fnval[0] = NUL;
  7969.  
  7970.     switch (cx) {                       /* Do function on expanded args. */
  7971. #ifdef TCPSOCKET
  7972.       case FN_HSTADD:
  7973.         p = ckaddr2name(bp[0]);
  7974.         goto fnend;
  7975.       case FN_HSTNAM:
  7976.         p = ckname2addr(bp[0]);
  7977.         goto fnend;
  7978. #endif /* TCPSOCKET */
  7979.  
  7980.       case FN_DEF:                      /* \fdefinition(arg1) */
  7981.         k = mxlook(mactab,bp[0],nmac);
  7982.         p = (k > -1) ? mactab[k].mval : "";
  7983.         goto fnend;
  7984.  
  7985.       case FN_EVA:                      /* \fevaluate(arg1) */
  7986.         p = *(bp[0]) ? evalx(bp[0]) : "";
  7987.         if (!*p && fndiags) {
  7988.             failed = 1;
  7989.             p = fnval;
  7990.             evalerr(fn);
  7991.         }
  7992.         goto fnend;
  7993.  
  7994.       case FN_EXE:                      /* \fexecute(arg1) */
  7995.         j = (int)strlen(s = bp[0]);     /* Length of macro invocation */
  7996.         p = "";                         /* Initialize return value to null */
  7997.         if (j) {                        /* If there is a macro to execute */
  7998.             while (*s == SP) s++,j--;   /* strip leading spaces */
  7999.             p = s;                      /* remember beginning of macro name */
  8000.             for (i = 0; i < j; i++) {   /* find end of macro name */
  8001.                 if (*s == SP)
  8002.                   break;
  8003.                 s++;
  8004.             }
  8005.             if (*s == SP)       {       /* if there was a space after */
  8006.                 *s++ = NUL;             /* terminate the macro name */
  8007.                 while (*s == SP) s++;   /* skip past any extra spaces */
  8008.             } else
  8009.               s = "";                   /* maybe there are no arguments */
  8010.             if (p && *p) {
  8011.                 k = mlook(mactab,p,nmac); /* Look up the macro name */
  8012.                 debug(F111,"fexec mlook",p,k);
  8013.             } else
  8014.               k = -1;
  8015.             if (k < 0) {
  8016.                 char * p2 = p;
  8017.                 failed = 1;
  8018.                 p = fnval;
  8019.                 if (fndiags)
  8020.                   ckmakxmsg(fnval,FNVALL,
  8021.                             "<ERROR:NO_SUCH_MACRO:\\f",fn,"(",p2,")>",
  8022.                             NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  8023.                 goto fnend;
  8024.             }
  8025. /*
  8026.   This is just a WEE bit dangerous because we are copying up to 9 arguments
  8027.   into the space reserved for one.  It won't overrun the buffer, but if there
  8028.   are lots of long arguments we might lose some.  The other problem is that if
  8029.   the macro has more than 3 arguments, the 4th through last are all
  8030.   concatenated onto the third.  (The workaround is to use spaces rather than
  8031.   commas to separate them.)  Leaving it like this to avoid having to allocate
  8032.   tons more buffers.
  8033. */
  8034.             if (argn > 1) {             /* Commas used instead of spaces */
  8035.                 int i;
  8036.                 char *p = bp[0];        /* Reuse this space */
  8037.                 *p = NUL;               /* Make into dodo() arg list */
  8038.                 for (i = 1; i < argn; i++) {
  8039.                     strncat(p,bp[i],MAXARGLEN);
  8040.                     strncat(p," ",MAXARGLEN);
  8041.                 }
  8042.                 s = bp[0];              /* Point to new list */
  8043.             }
  8044.             p = "";                     /* Initialize return value */
  8045.             if (k >= 0) {               /* If macro found in table */
  8046.                 /* Go set it up (like DO cmd) */
  8047.                 if ((j = dodo(k,s,cmdstk[cmdlvl].ccflgs)) > 0) {
  8048.                     if (cmpush() > -1) { /* Push command parser state */
  8049.                         extern int ifc;
  8050.                         int ifcsav = ifc; /* Push IF condition on stack */
  8051.                         k = parser(1);  /* Call parser to execute the macro */
  8052.                         cmpop();        /* Pop command parser */
  8053.                         ifc = ifcsav;   /* Restore IF condition */
  8054.                         if (k == 0) {   /* No errors, ignore action cmds. */
  8055.                             p = mrval[maclvl+1]; /* If OK, set return value. */
  8056.                             if (p == NULL) p = "";
  8057.                         }
  8058.                     } else {            /* Can't push any more */
  8059.                         debug(F100,"zzstring fneval fexec failure","",0);
  8060.                         printf("\n?\\fexec() too deeply nested\n");
  8061.                         while (cmpop() > -1) ;
  8062.                         p = "";
  8063.                     }
  8064.                 }
  8065.             }
  8066.         }
  8067.         debug(F110,"zzstring fneval fexecute final p",p,0);
  8068.         goto fnend;
  8069.  
  8070. #ifdef RECURSIVE
  8071.       case FN_RDIR:                     /* \frdir..() - Recursive dir count */
  8072.       case FN_RFIL:                     /* \frfiles() - Recursive file count */
  8073.         /* recursive = 2; */            /* fall thru... */
  8074. #endif /* RECURSIVE */
  8075.       case FN_FC:                       /* \ffiles() - File count. */
  8076.       case FN_DIR: {                    /* \ffdir.() - Directory count. */
  8077.           char abuf[16], *s;
  8078.           char ** ap = NULL;
  8079.           int x, xflags = 0;
  8080.           if (matchdot)
  8081.             xflags |= ZX_MATCHDOT;
  8082.           if (cx == FN_RDIR || cx == FN_RFIL) {
  8083.               xflags |= ZX_RECURSE;
  8084. #ifdef CKSYMLINK
  8085.               /* Recursive - don't follow symlinks */
  8086.               xflags |= ZX_NOLINKS;
  8087. #endif /* CKSYMLINK */
  8088.           }
  8089.           failed = 0;
  8090.           if (argn < 1) {
  8091.               p = "0";
  8092.               goto fnend;
  8093.           }
  8094.           if (cx == FN_DIR || cx == FN_RDIR) { /* Only list directories */
  8095.               xflags |= ZX_DIRONLY;
  8096. #ifdef OS2
  8097.               zxpn = 1;                 /* Use the alternate list */
  8098. #endif /* OS2 */
  8099.           } else {                      /* List only files */
  8100.               xflags |= ZX_FILONLY;
  8101. #ifdef OS2
  8102.               zxpn = 1;                 /* Use the alternate list */
  8103. #endif /* OS2 */
  8104.           }
  8105.           if (*(bp[0])) {
  8106.               k = nzxpand(bp[0],xflags);
  8107.               if (k < 0) k = 0;
  8108.               sprintf(fnval,"%d",k);    /* SAFE */
  8109.               p = fnval;
  8110.           } else
  8111.             p = "0";
  8112.  
  8113.           if (argn > 1) {               /* Assign list to array */
  8114.               fnval[0] = NUL;           /* Initial return value */
  8115.               ckstrncpy(abuf,bp[1],16); /* Get array reference */
  8116.               s = abuf;
  8117.               if (*s == CMDQ) s++;
  8118.               failed = 1;               /* Assume it's bad */
  8119.               p = fnval;                /* Point to result */
  8120.               if (fndiags)              /* Default is this error message */
  8121.                 ckmakmsg(fnval,FNVALL,
  8122.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  8123.               if (s[0] != '&')          /* "Address" of array */
  8124.                 goto fnend;
  8125.               if (s[2])
  8126.                 if (s[2] != '[' || s[3] != ']')
  8127.                   goto fnend;
  8128.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  8129.                 s[1] += 32;
  8130.               if ((x = dclarray(s[1],k)) < 0) /* File list plus count */
  8131.                 goto fnend;
  8132.               failed = 0;               /* Unset failure flag */
  8133.               ap = a_ptr[x];            /* Point to array we just declared */
  8134.               sprintf(fnval,"%d",k);    /* SAFE */
  8135.           }
  8136. #ifdef OS2
  8137.           if (ap) {                     /* We are making an array */
  8138.               int i;
  8139.               char tmp[16];
  8140.               ap[0] = NULL;             /* Containing number of files    */
  8141.               makestr(&(ap[0]),ckitoa(k));
  8142.  
  8143.               ckstrncpy(tmp,fnval,16);  /* Save return value */
  8144.  
  8145.               for (i = 1; i <= k; i++) { /* Fill it */
  8146.                   ap[i] = NULL;
  8147.                   znext(fnval);         /* Next filename */
  8148.                   if (!*fnval)          /* No more, done */
  8149.                     break;              /* In case a premature end */
  8150.                   makestr(&(ap[i]),fnval);
  8151.               }
  8152. #ifdef ZXREWIND
  8153.               k = zxrewind();           /* Reset the file expansion */
  8154. #else
  8155.               k = nzxpand(bp[0],xflags);
  8156. #endif /* ZXREWIND */
  8157.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8158.           }
  8159. #else /* OS2 */
  8160.           {                             /* Make copies of the list */
  8161.               int i; char tmp[16];
  8162.               if (flist) {              /* Free old file list, if any */
  8163.                   for (i = 0; flist[i]; i++) { /* and each string */
  8164.                       free(flist[i]);
  8165.                       flist[i] = NULL;
  8166.                   }
  8167.                   free((char *)flist);
  8168.               }
  8169.               ckstrncpy(tmp,fnval,16);  /* Save our return value */
  8170.               flist = (char **) malloc((k+1) * sizeof(char *)); /* New array */
  8171.               if (flist) {
  8172.                   for (i = 0; i <= k; i++) { /* Fill it */
  8173.                       flist[i] = NULL;
  8174.                       znext(fnval);     /* Next filename */
  8175.                       if (!*fnval)      /* No more, done */
  8176.                         break;
  8177.                       makestr(&(flist[i]),fnval);
  8178.                   }
  8179.                   if (ap) {             /* If array pointer given */
  8180.                       ap[0] = NULL;
  8181.                       makestr(&(ap[0]),ckitoa(k));
  8182.                       for (i = 0; i < k; i++) { /* Copy file list to array */
  8183.                           ap[i+1] = NULL;
  8184.                           makestr(&(ap[i+1]),flist[i]);
  8185.                       }
  8186.                   }
  8187.               }
  8188.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8189.               flistn = 0;               /* Reset global list pointer */
  8190.           }
  8191. #endif /* OS2 */
  8192. #ifdef RECURSIVE
  8193.           recursive = rsave;
  8194. #endif /* RECURSIVE */
  8195. #ifdef OS2
  8196.           zxpn = zsave;
  8197. #endif /* OS2 */
  8198.       }
  8199.       goto fnend;
  8200.  
  8201.       case FN_FIL:                      /* \fnextfile() - Next file in list. */
  8202.         p = fnval;                      /* (no args) */
  8203.         *p = NUL;
  8204. #ifdef OS2
  8205.         zxpn = 1;                       /* OS/2 - use the alternate list */
  8206.         znext(p);                       /* Call system-dependent function */
  8207.         zxpn = zsave;                   /* Restore original list */
  8208. #else
  8209.         if (flist)                      /* Others, use our own list. */
  8210.           if (flist[flistn])
  8211.             p = flist[flistn++];
  8212. #endif /* OS2 */
  8213.         goto fnend;
  8214.  
  8215.     } /* Break up big switch... */
  8216.  
  8217.     switch (cx) {
  8218.       case FN_IND:                      /* \findex(s1,s2,start) */
  8219.       case FN_RIX:                      /* \frindex(s1,s2,start) */
  8220.       case FN_SEARCH:                   /* \fsearch(pat,string,start) */
  8221.       case FN_RSEARCH: {                /* \frsearch(pat,string,start) */
  8222.         int i = 0, right = 0, search = 0;
  8223.         right = (cx == FN_RIX || cx == FN_RSEARCH);
  8224.         search = (cx == FN_SEARCH || cx == FN_RSEARCH);
  8225.         p = "0";
  8226.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8227.             int start = 0;
  8228.             char * pat = NULL;
  8229.             len1 = (int)strlen(pat = bp[0]); /* length of string to look for */
  8230.             len2 = (int)strlen(s = bp[1]); /* length of string to look in */
  8231.             if (len1 < 1 || len2 < 1)   /* Watch out for empty strings */
  8232.               goto fnend;
  8233.             start = right ? -1 : 0;     /* Default starting position */
  8234.             if (argn > 2) {
  8235.                 val1 = *(bp[2]) ? evalx(bp[2]) : "1";
  8236.                 if (chknum(val1)) {
  8237.                     int t;
  8238.                     t = atoi(val1);
  8239.                     if (!search) {      /* Index or Rindex */
  8240.                         j = len2 - len1; /* Length difference */
  8241.                         t--;             /* Convert position to 0-based */
  8242.                         if (t < 0) t = 0;
  8243.                         start = t;
  8244.                         if (!right && start < 0) start = 0;
  8245.                     } else {            /* Search or Rsearch */
  8246.                         int x;
  8247.                         if (t < 0) t = 0;
  8248.                         if (right) {    /* Right to left */
  8249.                             if (t > len2) t = len2;
  8250.                             start = len2 - t - 1;
  8251.                             if (start < 0)
  8252.                               goto fnend;
  8253.                             x = len2 - t;
  8254.                             s[x] = NUL;
  8255.                         } else {        /* Left to right */
  8256.                             start = t - 1;
  8257.                             if (start < 0) start = 0;
  8258.                             if (start >= len2)
  8259.                               goto fnend;
  8260.                         }
  8261.                     }
  8262.                 } else {
  8263.                     failed = 1;
  8264.                     evalerr(fn);
  8265.                     p = fnval;
  8266.                     goto fnend;
  8267.                 }
  8268.             }
  8269.             if (search) {               /* \fsearch() or \frsearch() */
  8270.                 if (right && pat[0] == '^') {
  8271.                     right = 0;
  8272.                     start = 0;
  8273.                 }
  8274.                 if (right) {
  8275.                     if (start < 0) start = len2 - 1;
  8276.                     for (i = start;
  8277.                          i >= 0 && !ckmatch(pat,s+i,inpcas[cmdlvl],1+4);
  8278.                          i--) ;
  8279.                     if (i < 0) i = 0; else i++;
  8280.                 } else {
  8281.                     i = ckmatch(pat,&s[start],inpcas[cmdlvl],1+4);
  8282.                     if (start > 0) i += start;
  8283.                 }
  8284.             } else {
  8285.                 i = ckindex(pat,bp[1],start,right,inpcas[cmdlvl]);
  8286.             }
  8287.             sprintf(fnval,"%d",i);      /* SAFE */
  8288.             p = fnval;
  8289.         }
  8290.         goto fnend;
  8291.       }
  8292.  
  8293.       case FN_RPL:                      /* \freplace(s1,s2,s3) */
  8294.       /*
  8295.         s = bp[0] = source string
  8296.             bp[1] = match string
  8297.             bp[2] = replacement string
  8298.             bp[3] = which occurrence (default = all);
  8299.         p = fnval = destination (result) string
  8300.       */
  8301.         if (argn < 1)                   /* Nothing */
  8302.           goto fnend;
  8303.         if (argn < 2) {                 /* Only works if we have 2 or 3 args */
  8304.             ckstrncpy(p,bp[0],FNVALL);
  8305.         } else {
  8306.             int occur = 0, xx = 0, j2;
  8307.             len1 = (int)strlen(bp[0]);  /* length of string to look in */
  8308.             len2 = (int)strlen(bp[1]);  /* length of string to look for */
  8309.             len3 = (argn < 3) ? 0 : (int)strlen(bp[2]); /* Len of replacemnt */
  8310.             j = len1 - len2 + 1;
  8311.             j2 = j;
  8312.             if (argn > 3) {
  8313.                 if (chknum(bp[3])) {
  8314.                     occur = atoi(bp[3]);
  8315.                 } else {
  8316.                     failed = 1;
  8317.                     if (fndiags)
  8318.                       ckmakmsg(fnval,FNVALL,
  8319.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8320.                     goto fnend;
  8321.                 }
  8322.             }
  8323.             /* If args out of whack... */
  8324.             if (j < 1 || len1 == 0 || len2 == 0) {
  8325.                 ckstrncpy(p,bp[0],FNVALL); /* just return original string */
  8326.                 p[FNVALL] = NUL;
  8327.             } else {
  8328.               ragain:
  8329.                 s = bp[0];              /* Point to beginning of string */
  8330.                 while (j-- > 0) {       /* For each character */
  8331.                     if (!ckstrcmp(bp[1],s,len2,inpcas[cmdlvl]) &&
  8332.                         (occur == 0 || occur == ++xx)) {
  8333.                         if (len3) {
  8334.                             ckstrncpy(p,bp[2],FNVALL);
  8335.                             p += len3;
  8336.                         }
  8337.                         s += len2;      /* and skip past it. */
  8338.                     } else {            /* No, */
  8339.                         *p++ = *s++;    /* just copy this character */
  8340.                     }
  8341.                 }
  8342.                 *p = NUL;
  8343.                 while ((*p++ = *s++));
  8344.                 if (occur < 0) {        /* cheap... */
  8345.                     occur = xx + occur + 1;
  8346.                     xx = 0;
  8347.                     p = fnval;
  8348.                     j = j2;
  8349.                     if (occur > 0)
  8350.                       goto ragain;
  8351.                 }
  8352.             }
  8353.         }
  8354.         p = fnval;
  8355.         goto fnend;
  8356.  
  8357.       case FN_CHR:                      /* \fcharacter(arg1) */
  8358.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8359.         if (chknum(val1)) {             /* Must be numeric */
  8360.             i = atoi(val1);
  8361.             if (i >= 0 && i < 256) {    /* Must be an 8-bit value */
  8362.                 p = fnval;
  8363.                 *p++ = (char) i;
  8364.                 *p = NUL;
  8365.                 p = fnval;
  8366.             } else {
  8367.                 failed = 1;
  8368.                 if (fndiags)
  8369.                   ckmakmsg(fnval,FNVALL,
  8370.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  8371.             }
  8372.         } else {
  8373.             failed = 1;
  8374.             evalerr(fn);
  8375.         }
  8376.         goto fnend;
  8377.  
  8378.       case FN_COD:                      /* \fcode(char) */
  8379.         if ((int)strlen(bp[0]) > 0) {
  8380.             p = fnval;
  8381.             i = *bp[0];
  8382.             sprintf(p,"%d",(i & 0xff)); /* SAFE */
  8383.         } else p = "";                  /* Can't happen */
  8384.         goto fnend;
  8385.  
  8386.       case FN_LEN:                      /* \flength(arg1) */
  8387.         if (argn > 0) {
  8388.             p = fnval;
  8389.             sprintf(p,"%d",(int)strlen(bp[0])); /* SAFE */
  8390.         } else p = "0";
  8391.         goto fnend;
  8392.  
  8393.       case FN_LOW:                      /* \flower(arg1) */
  8394.         s = bp[0] ? bp[0] : "";
  8395.         p = fnval;
  8396.         while (*s) {
  8397.             if (isupper(*s))
  8398.               *p = (char) tolower(*s);
  8399.             else
  8400.               *p = *s;
  8401.             p++; s++;
  8402.         }
  8403.         *p = NUL;
  8404.         p = fnval;
  8405.         goto fnend;
  8406.  
  8407.       case FN_MAX:                      /* \fmax(arg1,arg2) */
  8408.       case FN_MIN:                      /* \fmin(arg1,arg2) */
  8409.       case FN_MOD:                      /* \fmod(arg1,arg2) */
  8410.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8411. #ifdef COMMENT
  8412.         /* No longer necessary because evalx() no longer overwrites its */
  8413.         /* result every time it's called (2000/09/23). */
  8414.         free(bp[0]);
  8415.         bp[0] = NULL;
  8416. #endif /* COMMENT */
  8417.         if (argn > 1) {
  8418. #ifdef COMMENT
  8419.             /* Ditto... */
  8420.             bp[0] = malloc((int)strlen(val1)+1);
  8421.             if (bp[0])
  8422.               strcpy(bp[0],val1);       /* safe */
  8423.             val1 = bp[0];
  8424. #endif /* COMMENT */
  8425.             val2 = *(bp[1]) ? evalx(bp[1]) : "";
  8426.             if (chknum(val1) && chknum(val2)) {
  8427.                 i = atoi(val1);
  8428.                 j = atoi(val2);
  8429.                 switch (y) {
  8430.                   case FN_MAX:
  8431.                     if (j < i) j = i;
  8432.                     break;
  8433.                   case FN_MIN:
  8434.                     if (j > i) j = i;
  8435.                     break;
  8436.                   case FN_MOD:
  8437.                     if (j == 0) {
  8438.                         failed = 1;
  8439.                         if (fndiags)
  8440.                           ckmakmsg(fnval,FNVALL,
  8441.                                    "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  8442.                         else
  8443.                           fnval[0] = NUL;
  8444.                         goto fnend;
  8445.                     } else
  8446.                       j = i % j;
  8447.                 }
  8448.                 p = fnval;
  8449.                 sprintf(p,"%d",j);      /* SAFE */
  8450.             } else {
  8451.                 failed = 1;
  8452.                 evalerr(fn);
  8453.             }
  8454.         } else p = val1;
  8455.         goto fnend;
  8456.     } /* Break up big switch... */
  8457.  
  8458.     switch (y) {
  8459.       case FN_SUB:                      /* \fsubstr(arg1,arg2,arg3) */
  8460.       case FN_RIG:                      /* \fright(arg1,arg2) */
  8461.       case FN_LEF:                      /* \fleft(arg1,arg2) */
  8462.         if (argn < 1)
  8463.           goto fnend;
  8464.         val1 = "";
  8465.         if (argn > 1)
  8466.           if (*(bp[1]))
  8467.             val1 =  evalx(bp[1]);
  8468. #ifdef COMMENT
  8469.         if (bp[1]) free(bp[1]);         /* Have to copy this */
  8470.         bp[1] = malloc((int)strlen(val1)+1);
  8471.         if (!bp[1]) {
  8472.             failed = 1;
  8473.             if (fndiags) {
  8474.                 p = fnval;
  8475.                 ckmakmsg(fnval,FNVALL,
  8476.                          "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  8477.             }
  8478.             goto fnend;
  8479.         }
  8480.         strcpy(bp[1],val1);             /* safe */
  8481.         val1 = bp[1];
  8482. #endif /* COMMENT */
  8483.         val2 = "";
  8484.         if (argn > 2)
  8485.           if (*(bp[2]))
  8486.             val2 = evalx(bp[2]);
  8487.         if (
  8488.             ((argn > 1) && (int)strlen(val1) && !rdigits(val1)) ||
  8489.             ((cx == FN_SUB) &&
  8490.               ((argn > 2) && (int)strlen(val2) && !rdigits(val2)))
  8491.             ) {
  8492.             failed = 1;
  8493.             evalerr(fn);
  8494.         } else {
  8495.             int lx;
  8496.             p = fnval;                  /* pointer to result */
  8497.             lx = strlen(bp[0]);         /* length of arg1 */
  8498.             if (cx == FN_SUB) {         /* substring */
  8499.                 k = (argn > 2) ? atoi(val2) : MAXARGLEN; /* length */
  8500.                 j = (argn > 1) ? atoi(val1) : 1; /* start pos for substr */
  8501.             } else if (cx == FN_LEF) {  /* left */
  8502.                 k = (argn > 1) ? atoi(val1) : lx;
  8503.                 j = 1;
  8504.             } else {                             /* right */
  8505.                 k = (argn > 1) ? atoi(val1) : lx; /* length */
  8506.                 j = lx - k + 1;                  /* start pos for right */
  8507.                 if (j < 1) j = 1;
  8508.             }
  8509.             if (k > 0 && j <= lx) {              /* if start pos in range */
  8510.                 s = bp[0]+j-1;                   /* point to source string */
  8511.                 for (i = 0; (i < k) && (*p++ = *s++); i++) ;  /* copy */
  8512.             }
  8513.             *p = NUL;                   /* terminate the result */
  8514.             p = fnval;                  /* and point to it. */
  8515.         }
  8516.         goto fnend;
  8517.  
  8518.       case FN_UPP:                      /* \fupper(arg1) */
  8519.         s = bp[0] ? bp[0] : "";
  8520.         p = fnval;
  8521.         while (*s) {
  8522.             if (islower(*s))
  8523.               *p = (char) toupper(*s);
  8524.             else
  8525.               *p = *s;
  8526.             p++; s++;
  8527.         }
  8528.         *p = NUL;
  8529.         p = fnval;
  8530.         goto fnend;
  8531.  
  8532.       case FN_REP:                      /* \frepeat(text,number) */
  8533.         if (argn < 1)
  8534.           goto fnend;
  8535.         val1 = "1";
  8536.         if (argn > 1)
  8537.           if (*(bp[1]))
  8538.             val1 = evalx(bp[1]);
  8539.         if (chknum(val1)) {             /* Repeat count */
  8540.             n = atoi(val1);
  8541.             debug(F111,"SUNDAY frepeat n",val1,n);
  8542.             if (n > 0) {                /* Make n copies */
  8543.                 p = fnval;
  8544.                 *p = '\0';
  8545.                 k = (int)strlen(bp[0]); /* Make sure string has some length */
  8546.                 debug(F111,"SUNDAY frepeat k","",k);
  8547.                 debug(F111,"SUNDAY frepeat FNVALL","",FNVALL);
  8548.                 if (k * n >= FNVALL) {  /* But not too much... */
  8549.                     failed = 1;
  8550.                     if (fndiags)
  8551.                       ckmakmsg(fnval,FNVALL,
  8552.                                "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  8553.                     else
  8554.                       fnval[0] = NUL;
  8555.                     p = fnval;
  8556.                     goto fnend;
  8557.                 }
  8558.                 if (k > 0) {            /* If there is something to copy */
  8559.                     for (i = 0; i < n; i++) { /* Copy loop */
  8560.                         s = bp[0];
  8561.                         for (j = 0; j < k; j++) {
  8562.                             if ((p - fnval) >= FNVALL)
  8563.                               break;    /* shouldn't happen... */
  8564.                             else
  8565.                               *p++ = *s++;
  8566.                         }
  8567.                     }
  8568.                     *p = NUL;
  8569.                 }
  8570.             }
  8571.         } else {
  8572.             failed = 1;
  8573.             evalerr(fn);
  8574.         }
  8575.         p = fnval;
  8576.         goto fnend;
  8577.  
  8578. #ifndef NOFRILLS
  8579.       case FN_REV:                      /* \freverse() */
  8580.         if (argn < 1)
  8581.           goto fnend;
  8582.         yystring(bp[0],&p);
  8583.         goto fnend;
  8584. #endif /* NOFRILLS */
  8585.  
  8586.       case FN_RPA:                      /* \frpad() and \flpad() */
  8587.       case FN_LPA:
  8588.         if (argn < 1)
  8589.           goto fnend;
  8590.         val1 = "";
  8591.         if (argn > 1)
  8592.           if (*(bp[1]))
  8593.             val1 = evalx(bp[1]);
  8594.         if (argn == 1) {                /* If a number wasn't given */
  8595.             p = fnval;                  /* just return the original string */
  8596.             ckstrncpy(p,bp[0],FNVALL);
  8597.         } else if (argn > 1 &&  !*val1) {
  8598.             failed = 1;
  8599.             evalerr(fn);
  8600.         } else /* if (chknum(val1)) */ { /* Repeat count */
  8601.             char pc;
  8602.             n = atoi(val1);
  8603.             if (n >= 0) {
  8604.                 p = fnval;
  8605.                 k = (int)strlen(bp[0]); /* Length of string to be padded */
  8606.                 if (k >= n) {           /* It's already long enough */
  8607.                     ckstrncpy(p,bp[0],FNVALL);
  8608.                 } else {
  8609.                     if (n + k <= FNVALL) {
  8610.                         pc = (char) ((argn < 3) ? SP : *bp[2]);
  8611.                         if (!pc) pc = SP;
  8612.                         if (cx == FN_RPA) { /* RPAD */
  8613.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8614.                             p[k] = NUL;
  8615.                             p += k;
  8616.                             for (i = k; i < n; i++)
  8617.                               *p++ = pc;
  8618.                         } else {        /* LPAD */
  8619.                             n -= k;
  8620.                             for (i = 0; i < n; i++)
  8621.                               *p++ = pc;
  8622.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8623.                             p[k] = NUL;
  8624.                             p += k;
  8625.                         }
  8626.                     }
  8627.                     *p = NUL;
  8628.                 }
  8629.             }
  8630.         }
  8631.         p = fnval;
  8632.         goto fnend;
  8633.  
  8634. #ifdef ZFCDAT
  8635.       case FN_FD:                       /* \fdate(filename) */
  8636.         p = fnval;
  8637.         s = zfcdat(bp[0]);
  8638.         if (!s) s = "";
  8639.         if (!*s) {
  8640.             failed = 1;
  8641.             if (fndiags)
  8642.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8643.             goto fnend;
  8644.         }
  8645.         ckstrncpy(fnval,s,FNVALL);
  8646. #endif /* ZFCDAT */
  8647.         goto fnend;
  8648.  
  8649.     } /* Break up big switch... */
  8650.  
  8651.     switch (y) {
  8652.       case FN_FS:                       /* \fsize(filename) */
  8653.         p = fnval;
  8654.         z = zchki(bp[0]);
  8655.         if (z < 0) {
  8656.             failed = 1;
  8657.             if (fndiags) {
  8658.                 if (z == -1)
  8659.                   ckmakmsg(fnval,FNVALL,
  8660.                            "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8661.                 else if (z == -2)
  8662.                   ckmakmsg(fnval,FNVALL,
  8663.                            "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  8664.                 else if (z == -3)
  8665.                   ckmakmsg(fnval,FNVALL,
  8666.                            "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  8667.                 else
  8668.                   ckmakmsg(fnval,FNVALL,
  8669.                            "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  8670.             }
  8671.             goto fnend;
  8672.         }
  8673.         sprintf(fnval,"%ld",z);         /* SAFE */
  8674.         goto fnend;
  8675.  
  8676.       case FN_VER:                      /* \fverify() */
  8677.         p = "0";
  8678.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8679.             int start;
  8680.             char *s2, ch1, ch2;
  8681.             start = 0;
  8682.             if (argn > 2) {             /* Starting position specified */
  8683.                 val1 = *(bp[2]) ? evalx(bp[2]) : "0";
  8684.                 if (chknum(val1)) {
  8685.                     start = atoi(val1) /* - 1 */;
  8686.                     if (start < 0) start = 0;
  8687.                     if (start > (int)strlen(bp[1]))
  8688.                       goto verfin;
  8689.                 } else {
  8690.                     failed = 1;
  8691.                     evalerr(fn);
  8692.                     goto fnend;
  8693.                 }
  8694.             }
  8695.             i = start;
  8696.             p = "0";
  8697.             for (s = bp[1] + start; *s; s++,i++) {
  8698.                 ch1 = *s;
  8699.                 if (!inpcas[cmdlvl]) if (islower(ch1)) ch1 = toupper(ch1);
  8700.                 j = 0;
  8701.                 for (s2 = bp[0]; *s2; s2++) {
  8702.                     ch2 = *s2;
  8703.                     if (!inpcas[cmdlvl]) if (islower(ch2)) ch2 = toupper(ch2);
  8704.                     if (ch1 == ch2) {
  8705.                         j = 1;
  8706.                         break;
  8707.                     }
  8708.                 }
  8709.                 if (j == 0) {
  8710.                     sprintf(fnval,"%d",i+1); /* SAFE */
  8711.                     p = fnval;
  8712.                     break;
  8713.                 }
  8714.             }
  8715.         }
  8716.       verfin:
  8717.         goto fnend;
  8718.  
  8719.       case FN_IPA:                      /* Find and return IP address */
  8720.         if (argn > 0) {                 /* in argument string. */
  8721.             int start = 0;
  8722.             if (argn > 1) {             /* Starting position specified */
  8723.                 if (chknum(bp[1])) {
  8724.                     start = atoi(bp[1]) - 1;
  8725.                     if (start < 0) start = 0;
  8726.                 } else {
  8727.                     failed = 1;
  8728.                     if (fndiags)
  8729.                       ckmakmsg(fnval,FNVALL,
  8730.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8731.                     goto fnend;
  8732.                 }
  8733.             }
  8734.             p = getip(bp[0]+start);
  8735.         } else p = "";
  8736.         goto fnend;
  8737.  
  8738. #ifdef OS2
  8739.       case FN_CRY:
  8740.         p = "";
  8741.         if (argn > 0) {
  8742.             p = fnval;
  8743.             ckstrncpy(p,bp[0],FNVALL);
  8744.             ck_encrypt(p);
  8745.         }
  8746.         goto fnend;
  8747.  
  8748.       case FN_OOX:
  8749.         p = "";
  8750.         if (argn > 0)
  8751.           p = (char *) ck_oox(bp[0], (argn > 1) ? bp[1] : "");
  8752.         goto fnend;
  8753. #endif /* OS2 */
  8754.  
  8755.       case FN_HEX:                      /* \fhexify(arg1) */
  8756.         if (argn < 1)
  8757.           goto fnend;
  8758.         if ((int)strlen(bp[0]) < (FNVALL / 2)) {
  8759.             s = bp[0];
  8760.             p = fnval;
  8761.             while (*s) {
  8762.                 x = (*s >> 4) & 0x0f;
  8763.                 *p++ = hexdigits[x];
  8764.                 x = *s++ & 0x0f;
  8765.                 *p++ = hexdigits[x];
  8766.             }
  8767.             *p = NUL;
  8768.             p = fnval;
  8769.         }
  8770.         goto fnend;
  8771.  
  8772.       case FN_UNH: {                    /* \funhex(arg1) */
  8773.           int c[2], i;
  8774.           if (argn < 1)
  8775.             goto fnend;
  8776.           if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  8777.               s = bp[0];
  8778.               p = fnval;
  8779.               while (*s) {
  8780.                   for (i = 0; i < 2; i++) {
  8781.                       c[i] = *s++;
  8782.                       if (!c[i]) { p = ""; goto unhexfin; }
  8783.                       if (islower(c[i])) c[i] = toupper(c[i]);
  8784.                       if (c[i] >= '0' && c[i] <= '9') {
  8785.                           c[i] -= 0x30;
  8786.                       } else if (c[i] >= 'A' && c[i] <= 'F') {
  8787.                           c[i] -= 0x37;
  8788.                       } else {
  8789.                           failed = 1;
  8790.                           if (fndiags)
  8791.                             ckmakmsg(fnval,
  8792.                                      FNVALL,
  8793.                                      "<ERROR:ARG_OUT_OF_RANGE:\\f",
  8794.                                      fn,
  8795.                                      "()>",
  8796.                                      NULL
  8797.                                      );
  8798.                           goto fnend;
  8799.                       }
  8800.                   }
  8801.                   *p++ = ((c[0] << 4) & 0xf0) | (c[1] & 0x0f);
  8802.               }
  8803.               *p = NUL;
  8804.               p = fnval;
  8805.           }
  8806.         unhexfin:
  8807.           goto fnend;
  8808.       }
  8809.  
  8810.       case FN_BRK: {                    /* \fbreak() */
  8811.           char * c;                     /* Characters to break on */
  8812.           char c2, s2;
  8813.           int start = 0;
  8814.           int done = 0;
  8815.           if (argn < 1)
  8816.             goto fnend;
  8817.           if (argn > 2) {
  8818.               s = bp[2] ? bp[2] : "0";
  8819.               if (chknum(s)) {
  8820.                   start = atoi(s);
  8821.                   if (start < 0) start = 0;
  8822.                   if (start > (int)strlen(bp[0]))
  8823.                     goto brkfin;
  8824.               } else {
  8825.                   failed = 1;
  8826.                   if (fndiags)
  8827.                     ckmakmsg(fnval,FNVALL,
  8828.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8829.                   goto fnend;
  8830.               }
  8831.           }
  8832.           s = bp[0] + start;            /* Source pointer */
  8833.  
  8834.           while (*s && !done) {
  8835.               s2 = *s;
  8836.               if (!inpcas[cmdlvl] && islower(s2)) s2 = toupper(s2);
  8837.               c = bp[1] ? bp[1] : "";   /* Character to break on */
  8838.               while (*c) {
  8839.                   c2 = *c;
  8840.                   if (!inpcas[cmdlvl] && islower(c2)) c2 = toupper(c2);
  8841.                   if (c2 == s2) {
  8842.                       done = 1;
  8843.                       break;
  8844.                   }
  8845.                   c++;
  8846.               }
  8847.               if (done) break;
  8848.               *p++ = *s++;
  8849.           }
  8850.           *p = NUL;                     /* terminate the result */
  8851.           p = fnval;                    /* and point to it. */
  8852.         brkfin:
  8853.           goto fnend;
  8854.       }
  8855.  
  8856.       case FN_SPN: {                    /* \fspan() */
  8857.           char *q;
  8858.           char c1, c2;
  8859.           int start = 0;
  8860.           if (argn < 1)
  8861.             goto fnend;
  8862.           if (argn > 2) {               /* Starting position */
  8863.               s = bp[2] ? bp[2] : "0";
  8864.               if (chknum(s)) {
  8865.                   start = atoi(s);
  8866.                   if (start < 0) start = 0;
  8867.               } else {
  8868.                   failed = 1;
  8869.                   if (fndiags)
  8870.                     ckmakmsg(fnval,FNVALL,
  8871.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8872.                   goto fnend;
  8873.               }
  8874.           }
  8875.           s = bp[0] + start;            /* Source pointer */
  8876.           if (argn > 1 &&
  8877.               (int)strlen(bp[1]) > 0 &&
  8878.               start <= (int)strlen(bp[0])) {
  8879.               while (*s) {              /* Loop thru source string */
  8880.                   q = bp[1];            /* Span string */
  8881.                   c1 = *s;
  8882.                   if (!inpcas[cmdlvl])
  8883.                     if (islower(c1)) c1 = toupper(c1);
  8884.                   x = 0;
  8885.                   while ((c2 = *q++)) {
  8886.                       if (!inpcas[cmdlvl])
  8887.                         if (islower(c2)) c2 = toupper(c2);
  8888.                       if (c1 == c2) { x = 1; break; }
  8889.                   }
  8890.                   if (!x) break;
  8891.                   *p++ = *s++;
  8892.               }
  8893.               *p = NUL;                 /* Terminate and return the result */
  8894.               p = fnval;
  8895.           }
  8896.           goto fnend;
  8897.       }
  8898.     } /* Break up big switch... */
  8899.  
  8900.     switch (y) {
  8901.       case FN_TRM:                      /* \ftrim(s1[,s2]) */
  8902.       case FN_LTR:                      /* \fltrim(s1[,s2]) */
  8903.         if (argn < 1)
  8904.           goto fnend;
  8905.         if ((len1 = (int)strlen(bp[0])) > 0) {
  8906.             if (len1 > FNVALL)
  8907.               len1 = FNVALL;
  8908.             s = " \t\r\n";
  8909.             if (argn > 1)               /* Trim list given */
  8910.               s = bp[1];
  8911.             len2 = (int)strlen(s);
  8912.             if (len2 < 1) {             /* or not... */
  8913.                 s = " \t\r\n";          /* Default is to trim whitespace */
  8914.                 len2 = 2;
  8915.             }
  8916.             if (cx == FN_TRM) {         /* Trim from right */
  8917.                 char * q, p2, q2;
  8918.                 ckstrncpy(fnval,bp[0],FNVALL); /* Copy string to output */
  8919.                 p = fnval + len1 - 1;   /* Point to last character */
  8920.  
  8921.                 while (p >= (char *)fnval) { /* Go backwards */
  8922.                     q = s;              /* Point to trim list */
  8923.                     p2 = *p;
  8924.                     if (!inpcas[cmdlvl])
  8925.                       if (islower(p2)) p2 = toupper(p2);
  8926.                     while (*q) {        /* Is this char in trim list? */
  8927.                         q2 = *q;
  8928.                         if (!inpcas[cmdlvl])
  8929.                           if (islower(q2)) q2 = toupper(q2);
  8930.                         if (p2 == q2) { /* Yes, null it out */
  8931.                             *p = NUL;
  8932.                             break;
  8933.                         }
  8934.                         q++;
  8935.                     }
  8936.                     if (!*q)            /* Trim list exhausted */
  8937.                       break;            /* So we're done. */
  8938.                     p--;                /* Else keep trimming */
  8939.                 }
  8940.             } else {                    /* Trim from left */
  8941.                 char * q, p2, q2;
  8942.                 p = bp[0];              /* Source */
  8943.                 while (*p) {
  8944.                     p2 = *p;
  8945.                     if (!inpcas[cmdlvl])
  8946.                       if (islower(p2)) p2 = toupper(p2);
  8947.                     q = s;
  8948.                     while (*q) {        /* Is this char in trim list? */
  8949.                         q2 = *q;
  8950.                         if (!inpcas[cmdlvl])
  8951.                           if (islower(q2)) q2 = toupper(q2);
  8952.                         if (p2 == q2) { /* Yes, point past it */
  8953.                             p++;        /* and try next source character */
  8954.                             break;
  8955.                         }
  8956.                         q++;            /* No, try next trim character */
  8957.                     }
  8958.                     if (!*q)            /* Trim list exhausted */
  8959.                       break;            /* So we're done. */
  8960.                 }
  8961.                 ckstrncpy(fnval,p,FNVALL);
  8962.             }
  8963.             p = fnval;
  8964.         } else p = "";
  8965.         goto fnend;
  8966.  
  8967.       case FN_CAP:                      /* \fcapitalize(arg1) */
  8968.         if (argn < 1)
  8969.           goto fnend;
  8970.         s = bp[0];
  8971.         p = fnval;
  8972.         x = 0;
  8973.         while ((c = *s++)) {
  8974.             if (isalpha(c)) {
  8975.                 if (x == 0) {
  8976.                     x = 1;
  8977.                     if (islower(c))
  8978.                       c = toupper(c);
  8979.                 } else if (isupper(c))
  8980.                   c = tolower(c);
  8981.             }
  8982.             *p++ = c;
  8983.         }
  8984.         *p = NUL;
  8985.         p = fnval;
  8986.         goto fnend;
  8987.  
  8988. #ifdef COMMENT
  8989.       case FN_TOD:                      /* Time of day to secs since midnite */
  8990.         sprintf(fnval,"%ld",tod2sec(bp[0])); /* SAFE */
  8991.         goto fnend;
  8992. #endif /* COMMENT */
  8993.  
  8994.       case FN_FFN:                      /* Full pathname of file */
  8995.         zfnqfp(bp[0],FNVALL,p);
  8996.         if (!p) p = "";
  8997.         goto fnend;
  8998.  
  8999.       case FN_CHK: {                    /* \fchecksum() */
  9000.           long chk = 0;
  9001.           p = (argn > 0) ? bp[0] : "";
  9002.           while (*p) chk += *p++;
  9003.           sprintf(fnval,"%lu",chk);     /* SAFE */
  9004.           p = fnval;
  9005.           goto fnend;
  9006.       }
  9007.  
  9008. #ifndef NOXFER
  9009.       case FN_CRC:                      /* \fcrc16() */
  9010.         if (argn > 0)
  9011.           sprintf(fnval,"%u",           /* SAFE */
  9012.                   chk3((CHAR *)bp[0],(int)strlen(bp[0])));
  9013.         else
  9014.           p = "0";
  9015.         goto fnend;
  9016. #endif /* NOXFER */
  9017.  
  9018.       case FN_BSN:                      /* \fbasename() */
  9019.         zstrip(bp[0],&p);
  9020.         goto fnend;
  9021.  
  9022. #ifndef NOLOCAL
  9023. #ifdef OS2
  9024.       case FN_SCRN_CX:                  /* \fscrncurx() */
  9025.         p = fnval;
  9026.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->x); /* SAFE */
  9027.         goto fnend;
  9028.  
  9029.       case FN_SCRN_CY:                  /* \fscrncury() */
  9030.         p = fnval;
  9031.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->y); /* SAFE */
  9032.         goto fnend;
  9033.  
  9034.       case FN_SCRN_STR: {               /* \fscrnstr() */
  9035.           videoline * line = NULL;
  9036.           viocell * cells = NULL;
  9037.           int row = 0, col = 0, len = 0;
  9038.           /* NOTE: On Unicode systems, the screen contents are stored in */
  9039.           /* in Unicode.  Therefore, we should really be performing a    */
  9040.           /* conversion to the local character set.                      */
  9041.  
  9042.           /* 6/18/2000 - added the translation to lcs */
  9043.  
  9044.           if (bp[0] == NULL || bp[0][0] == '\0') {
  9045.               row = 0;
  9046.           } else {
  9047.               if (chknum(bp[0])) {
  9048.                   row = atoi(bp[0]);
  9049.                   if (row < 0)
  9050.                     row = 0;
  9051.               } else {
  9052.                   failed = 1;
  9053.                   if (fndiags)
  9054.                     ckmakmsg(fnval,FNVALL,
  9055.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9056.                   goto fnend;
  9057.               }
  9058.           }
  9059.           line = VscrnGetLineFromTop( VTERM, (USHORT) row );
  9060.           if (line != NULL) {
  9061.               if (bp[1] == NULL || bp[1][0] == '\0')
  9062.                 col = 0;
  9063.               else {
  9064.                   if (chknum(bp[0])) {
  9065.                       col = atoi(bp[1]);
  9066.                       if (col < 0 || col >= line->width)
  9067.                         col = 0;
  9068.                   } else {
  9069.                       failed = 1;
  9070.                       if (fndiags)
  9071.                         ckmakmsg(fnval,FNVALL,
  9072.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9073.                       goto fnend;
  9074.                   }
  9075.               }
  9076.               if (bp[2] == NULL || bp[2][0] == '\0') {
  9077.                   len = line->width - (col+1);
  9078.               } else {
  9079.                   if (!chknum(bp[2])) {
  9080.                       failed = 1;
  9081.                       if (fndiags)
  9082.                         ckmakmsg(fnval,FNVALL,
  9083.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9084.                       goto fnend;
  9085.                   }
  9086.                   len = atoi(bp[2]);
  9087.                   if (len < 0 || len > line->width)
  9088.                     len = line->width;
  9089.               }
  9090.               cells = line->cells;
  9091.               for (i = 0; i < len; i++) {
  9092.                   int pos = i + col;
  9093.                   if (pos < line->width) {
  9094.                       if (isunicode())
  9095.                         fnval[i] = (CHAR) utolxlat(cells[pos].c);
  9096.                       else
  9097.                         fnval[i] = (CHAR) (cells[pos].c & 0xFF);
  9098.                       if (fnval[i] == 0)
  9099.                         fnval[i] = SP;
  9100.                   } else
  9101.                     fnval[i] = SP;
  9102.               }
  9103.               fnval[i] = '\0';
  9104.           } else {
  9105.               fnval[0] = '\0';
  9106.           }
  9107.           p = fnval;
  9108.           goto fnend;
  9109.       }
  9110. #endif /* OS2 */
  9111. #endif /* NOLOCAL */
  9112.  
  9113. #ifndef NOPUSH
  9114.       case FN_RAW:                      /* \frawcommand() */
  9115.       case FN_CMD: {                    /* \fcommand() */
  9116.           int x, c, n = FNVALL;
  9117.           x = 0;                        /* Completion flag */
  9118. /*
  9119.   ZIFILE can be safely used because we can't possibly be transferring a file
  9120.   while executing this function.
  9121. */
  9122.           if (!nopush && zxcmd(ZIFILE,bp[0]) > 0) { /* Open the command */
  9123.               while (n-- > -1) {        /* Read from it */
  9124.                   if ((c = zminchar()) < 0) {
  9125.                       x = 1;             /* EOF - set completion flag */
  9126.                       if (cx == FN_CMD) { /* If not "rawcommand" */
  9127.                           p--;           /* remove trailing newlines */
  9128.                           while (*p == CR || *p == LF)
  9129.                             p--;
  9130.                           p++;
  9131.                       }
  9132.                       *p = NUL;         /* Terminate the string */
  9133.                       break;
  9134.                   } else                /* Command still running */
  9135.                     *p++ = c;           /* Copy the bytes */
  9136.               }
  9137.               zclose(ZIFILE);           /* Close the command */
  9138.           }
  9139.           /* Return null string if command's output was too long. */
  9140.           p = fnval;
  9141.           if (!x) {
  9142.               failed = 1;
  9143.               if (fndiags)
  9144.                 ckmakmsg(fnval,FNVALL,
  9145.                          "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  9146.           }
  9147.           goto fnend;
  9148.       }
  9149. #endif /* NOPUSH */
  9150.     } /* Break up big switch... */
  9151.  
  9152.     switch (y) {
  9153.       case FN_STX:                      /* \fstripx(string,c) */
  9154.         if (!(s = bp[0]))               /* Make sure there is a string */
  9155.           goto fnend;
  9156.         c = '.';                        /* Character to strip from */
  9157.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9158.         n = ckstrncpy(fnval,bp[0],FNVALL);
  9159.         while (--n >= 0) {
  9160.             if (fnval[n] == c) {
  9161.                 fnval[n] = NUL;
  9162.                 break;
  9163.             }
  9164.         }
  9165.         p = fnval;
  9166.         goto fnend;
  9167.  
  9168.       case FN_STL:                      /* \flop(string,c) */
  9169.         if (!(s = bp[0]))               /* Make sure there is a string */
  9170.           goto fnend;
  9171.         c = '.';                        /* Character to strip to */
  9172.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9173.         x = 0;
  9174.         while (*s++) {
  9175.             if (*(s-1) == c) {
  9176.                 x = 1;
  9177.                 break;
  9178.             }
  9179.         }
  9180.         if (!x) s = bp[0];
  9181.         ckstrncpy(fnval,s,FNVALL);
  9182.         p = fnval;
  9183.         goto fnend;
  9184.  
  9185.       case FN_STN:                      /* \fstripn(string,n) */
  9186.         if (argn < 1)                   /* Remove n chars from right */
  9187.           goto fnend;
  9188.         val1 = "0";
  9189.         if (argn > 1)
  9190.           if (*(bp[1]))
  9191.             val1 = evalx(bp[1]);
  9192.         if (!chknum(val1)) {
  9193.             failed = 1;
  9194.             evalerr(fn);
  9195.             goto fnend;
  9196.         }
  9197.         n = atoi(val1);
  9198.         if (n < 0) n = 0;
  9199.         k = (int)strlen(s = bp[0]) - n;
  9200.         if (k < 0) k = 0;
  9201.         p = fnval;
  9202.         while (k-- > 0)
  9203.           *p++ = *s++;
  9204.         *p = NUL;
  9205.         p = fnval;
  9206.         goto fnend;
  9207.  
  9208.       case FN_STB: {                    /* \fstripb(string,c) */
  9209.           char c2 = NUL;
  9210.           int i, k = 0;
  9211.           char * gr_opn = "\"{'([<";    /* Group open brackets */
  9212.           char * gr_cls = "\"}')]>";    /* Group close brackets */
  9213.  
  9214.           p = fnval;
  9215.           *p = NUL;
  9216.           if (!(s = bp[0]))             /* Make sure there is a string */
  9217.             goto fnend;
  9218.           if ((x = strlen(s)) < 1)
  9219.             goto fnend;
  9220.           c = NUL;                      /* Brace/bracket kind */
  9221.           if (argn > 1) {
  9222.               if (*bp[1]) {
  9223.                   if (chknum(bp[1])) {
  9224.                       k = atoi(bp[1]);
  9225.                       if (k < 0) k = 63;
  9226.                       for (i = 0; i < 6; i++) {
  9227.                           if (k & (1<<i)) {
  9228.                               if (s[0] == gr_opn[i] && s[x-1] == gr_cls[i]) {
  9229.                                   ckstrncpy(fnval,s+1,FNVALL);
  9230.                                   fnval[x-2] = NUL;
  9231.                                   goto fnend;
  9232.                               }
  9233.                           }
  9234.                       }
  9235.                       ckstrncpy(fnval,s,FNVALL); /* No match */
  9236.                       goto fnend;
  9237.                   }
  9238.               }
  9239.           }
  9240.           c = *bp[1];
  9241.           if (!c) c = s[0];
  9242.           if (argn > 2) if (*bp[2]) c2 = *bp[2];
  9243.           if (*s == c) {
  9244.               if (!c2) {
  9245.                   switch (c) {
  9246.                     case '(': c2 = ')'; break;
  9247.                     case '[': c2 = ']'; break;
  9248.                     case '{': c2 = '}'; break;
  9249.                     case '<': c2 = '>'; break;
  9250.                     case '"': c2 = '"'; break;
  9251.                     case 39:  c2 = 39;  break;
  9252.                     case 96:  c2 = 39;  break;
  9253.                     default:
  9254.                       if (argn == 2) {
  9255.                           c2 = c;
  9256.                       } else {
  9257.                           strncpy(fnval,s,x); /* Leave it like this */
  9258.                           fnval[x] = NUL;
  9259.                           goto fnend;
  9260.                       }
  9261.                   }
  9262.               }
  9263.               if (s[x-1] == c2) {
  9264.                   strncpy(fnval,s+1,x-2); /* Leave it like this */
  9265.                   fnval[x-2] = NUL;
  9266.                   goto fnend;
  9267.               }
  9268.           }
  9269.           strncpy(fnval,s,x);
  9270.           fnval[x] = NUL;
  9271.           goto fnend;
  9272.       }
  9273.  
  9274.       case FN_2HEX:                     /* Number to hex */
  9275.       case FN_2OCT:                     /* Number to octal */
  9276.         val1 = evalx(bp[0]);
  9277.         if (!*val1) {
  9278.             failed = 1;
  9279.             evalerr(fn);
  9280.             goto fnend;
  9281.         }
  9282.         sprintf(fnval, cx == FN_2HEX ? "%lx" : "%lo", atol(val1)); /* SAFE */
  9283.         if (cx == FN_2HEX && (int)(strlen(fnval)&1))
  9284.           sprintf(fnval,"0%lx",atol(val1)); /* SAFE */
  9285.         p = fnval;
  9286.         goto fnend;
  9287.  
  9288.       case FN_DNAM: {                   /* Directory part of file name */
  9289.           char *s;
  9290.           zfnqfp(bp[0],FNVALL,p);       /* Get full name */
  9291.           if (!isdir(p)) {              /* Is it already a directory? */
  9292.               zstrip(p,&s);             /* No get basename */
  9293.               if (*s) {
  9294.                   x = ckindex(s,p,0,0,0); /* Pos of latter in former */
  9295.                   if (x > 0) p[x-1] = NUL;
  9296.               }
  9297.           }
  9298.           if (!p) p = "";
  9299.           goto fnend;
  9300.       }
  9301.  
  9302. #ifndef NORANDOM
  9303.       case FN_RAND:                     /* Random number */
  9304. #ifdef CK_SSL
  9305.         if (RAND_bytes((unsigned char *)&k,sizeof(k)) < 0)
  9306. #endif /* CK_SSL */
  9307.           k = rand();
  9308.         x = 0;
  9309.         if (argn > 0) {
  9310.             if (!chknum(bp[0])) {
  9311.                 failed = 1;
  9312.                 if (fndiags)
  9313.                   ckmakmsg(fnval,FNVALL,
  9314.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9315.                 goto fnend;
  9316.             }
  9317.             x = atoi(bp[0]);
  9318.         }
  9319. #ifdef COMMENT
  9320.         sprintf(fnval,"%d", (x > 0 && k > 0) || (x < 0 && k < 0) ? k % x : 
  9321.                 (x == 0 ? 0 : (0 - (k % (-x)))));
  9322. #else
  9323.         debug(F111,"rand",ckitoa(x),k);
  9324. #ifdef SUNOS4
  9325. /* This is really strange but on SunOS, if we are requesting random numbers */
  9326. /* between 0 and 4 or less, they always come out in sequence: 0 1 2 3 0 1 2 */
  9327. /* Shifting the result of rand() in this case gives a more random result.   */
  9328.         if (x < 5)
  9329.           k = k >> 5;
  9330. #endif /* SUNOS4 */
  9331.         if ((x > 0 && k > 0) || (x < 0 && k < 0))
  9332.           x = k % x;
  9333.         else if (x == 0)
  9334.           x = 0;
  9335.         else
  9336.           x = 0 - (k % (-x));
  9337.         debug(F101,"rand x","",x);
  9338.         sprintf(fnval,"%d", x);         /* SAFE */
  9339. #endif /* COMMENT */
  9340.         p = fnval;
  9341.         goto fnend;
  9342. #endif /* NORANDOM */
  9343.     } /* Break up big switch... */
  9344.  
  9345.     switch (y) {
  9346.       case FN_SPLIT:                    /* \fsplit(s1,a,s2,s3,mask) */
  9347.       case FN_WORD: {                   /* \fword(s1,n,s2,s3,mask) */
  9348.           int wordnum = 0;
  9349.           int splitting = 0;
  9350.           int x;
  9351.           int array = 0;
  9352.           int grouping = 0;
  9353.           int nocollapse = 0;
  9354.           char * sep = "";
  9355.           char * notsep = "";
  9356.           char * bp0 = NULL;
  9357.           char * bp1 = NULL;
  9358.           char   abuf[16];
  9359.           struct stringarray * q = NULL;
  9360.  
  9361.           splitting = (cx == FN_SPLIT); /* Our job */
  9362.  
  9363.           fnval[0] = splitting ? '0' : NUL; /* Initial return value */
  9364.           fnval[1] = NUL;
  9365.           p = fnval;
  9366.           bp0 = bp[0];                  /* Source string */
  9367.           if (!bp0) bp0 = "";
  9368.           debug(F111,"fsplit bp[0]",bp0,argn);
  9369.           if (argn < 1 || !*bp0)        /* If none, return default value */
  9370.             goto fnend;
  9371.  
  9372.           bp1 = bp[1];                  /* Function-dependent arg */
  9373.           if (!bp1) bp1 = "";           /* (array or number) */
  9374.           debug(F110,"fsplit bp[1]",bp1,0);
  9375.           if (bp[5]) {
  9376.               if (!chknum(bp[5])) {
  9377.                   failed = 1;
  9378.                   ckmakmsg(fnval,FNVALL,
  9379.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9380.                   goto fnend;
  9381.               }
  9382.               x = atoi(bp[5]);
  9383.               nocollapse = x;
  9384.           }
  9385.           if (!splitting) {             /* \fword(): n = desired word number */
  9386.               val1 = "1";               /* Default is first word */
  9387.               if (argn > 1)             /* Word number supplied */
  9388.                 if (*bp1)
  9389.                   val1 = evalx(bp1);
  9390.               if (!chknum(val1)) {
  9391.                   failed = 1;
  9392.                   ckmakmsg(fnval,FNVALL,
  9393.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9394.                   goto fnend;
  9395.               }
  9396.               n = atoi(val1);
  9397.           } else if (argn > 1 && *bp1) { /* \fsplit(): n = word count */
  9398.               ckstrncpy(abuf,bp1,16);   /* Get array reference */
  9399.               debug(F110,"fsplit abuf 1",abuf,0);
  9400.               failed = 1;               /* Assume it's bad */
  9401.               if (fndiags)              /* Default is this error message */
  9402.                 ckmakmsg(fnval,FNVALL,
  9403.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9404.               if (abuf[0] != '&')       /* "Address" of array */
  9405.                 goto fnend;             /* It's bad */
  9406.               if (abuf[2]) {            /* Check for brackets */
  9407.                   if (abuf[2] != '[' || abuf[3] != ']') {
  9408.                       goto fnend;       /* Bad */
  9409.                   }
  9410.               }
  9411.               debug(F110,"fsplit abuf 2",abuf,0);
  9412.               if (abuf[1] > 64 && abuf[1] < 91) /* Convert upper to lower */
  9413.                 abuf[1] += 32;
  9414.               if (abuf[1] < 97 || abuf[1] > 122) { /* Check for a-z */
  9415.                   goto fnend;
  9416.               }
  9417.               debug(F110,"fsplit abuf 3",abuf,0);
  9418.               array = 1;
  9419.               fnval[0] = NUL;           /* No error, erase message */
  9420.               failed = 0;               /* Unset failure flag */
  9421.               n = 0;                    /* Initialize word counter */
  9422.           }
  9423.           if (argn > 2)                 /* Have break set? */
  9424.             sep = bp[2];
  9425.           debug(F111,"fsplit sep",sep,argn);
  9426.           if (argn > 3)                 /* Have include set? */
  9427.             notsep = bp[3];
  9428.           debug(F111,"fsplit notsep",notsep,argn);
  9429.           if (argn > 4) {               /* Have grouping set? */
  9430.               char * bp4 = bp[4];
  9431.               debug(F111,"fsplit bp4",bp4,argn);
  9432.               if (!bp4) bp4 = "0";
  9433.               if (!*bp4) bp4 = "0";
  9434.               if (chknum(bp4)) {
  9435.                   grouping = atoi(bp4);
  9436.                   if (grouping == -1)
  9437.                     grouping = 127;
  9438.               } else {
  9439.                   failed = 1;
  9440.                   if (fndiags)
  9441.                     ckmakmsg(fnval,FNVALL,
  9442.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9443.                   goto fnend;
  9444.               }
  9445.           }
  9446.           /* Args parsed, now do the work */
  9447.  
  9448.           debug(F111,"fsplit bp0",bp0,n);
  9449.           q = cksplit(splitting,n,bp0,sep,notsep,grouping,0,nocollapse);
  9450.  
  9451.           wordnum = q ? q->a_size : -1; /* Check result */
  9452.           if (wordnum < 0) {
  9453.               failed = 1;               /* Failure */
  9454.               if (fndiags)
  9455.                 ckmakmsg(fnval,FNVALL,
  9456.                          (wordnum == -1) ?
  9457.                          "<ERROR:MALLOC_FAILURE:\\f" :
  9458.                          "<ERROR:TOO_MANY_WORDS:\\f",
  9459.                          fn,
  9460.                          "()>",
  9461.                          NULL
  9462.                          );
  9463.               goto fnend;
  9464.           }
  9465.           if (splitting) {              /* \fsplit() result */
  9466.               ckstrncpy(fnval,ckitoa(wordnum),FNVALL);
  9467.               if (array) {              /* Array was not declared. */
  9468.                   int i;
  9469.                   if ((x = dclarray(abuf[1],wordnum)) < 0) { /* Declare it. */
  9470.                       failed = 1;
  9471.                       if (fndiags)
  9472.                         ckmakmsg(fnval,FNVALL,
  9473.                                  "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  9474.                       goto fnend;
  9475.                   }
  9476.                   for (i = 1; i <= wordnum; i++) { /* Copy results */
  9477.                       makestr(&(a_ptr[x][i]),q->a_head[i]);
  9478.                   }
  9479.                   a_ptr[x][0] = NULL;   /* Array is 1-based */
  9480.                   makestr(&(a_ptr[x][0]),fnval); /* Element = size */
  9481.               }
  9482.           } else {                      /* \fword() result */
  9483.               char * s;
  9484.               s = q->a_head[1];
  9485.               if (!s) s = "";
  9486.               ckstrncpy(fnval,s,FNVALL);
  9487.           }
  9488.           goto fnend;                   /* Done */
  9489.       }
  9490.  
  9491.     } /* Break up big switch... */
  9492.  
  9493.     switch (y) {
  9494.  
  9495. #ifdef CK_KERBEROS
  9496.       case FN_KRB_TK:                   /* Kerberos tickets */
  9497.       case FN_KRB_NX:                   /* Kerberos next ticket */
  9498.       case FN_KRB_IV:                   /* Kerberos ticket is valid */
  9499.       case FN_KRB_FG:                   /* Kerberos Ticket flags */
  9500.       case FN_KRB_TT: {                 /* Kerberos ticket time */
  9501.           int kv = 0;                   /* Kerberos version */
  9502.           int n = 0;
  9503.           char * s = NULL;
  9504.           if (rdigits(bp[0])) {
  9505.               kv = atoi(bp[0]);
  9506.           } else {
  9507.               failed = 1;
  9508.               if (fndiags)
  9509.                 ckmakmsg(fnval,FNVALL,
  9510.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9511.               goto fnend;
  9512.           }
  9513.           if (kv != 4 && kv != 5) {
  9514.               failed = 1;
  9515.               if (fndiags)
  9516.                 ckmakmsg(fnval,FNVALL,
  9517.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9518.               goto fnend;
  9519.           }
  9520.           if ((cx == FN_KRB_IV || cx == FN_KRB_TT || cx == FN_KRB_FG) &&
  9521.                argn < 2) {
  9522.               failed = 1;
  9523.               if (fndiags)
  9524.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9525.               goto fnend;
  9526.           }
  9527.           switch (y) {
  9528.             case FN_KRB_TK:             /* Number of Kerberos tickets */
  9529. #ifdef CK_AUTHENTICATION
  9530.               switch (kv) {
  9531.                 case 4:
  9532.                   n = ck_krb4_get_tkts();
  9533.                   sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9534.                   goto fnend;
  9535.                 case 5: {
  9536.                     extern char * krb5_d_cc;
  9537.                     n = ck_krb5_get_tkts(krb5_d_cc);
  9538.                     sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9539.                     goto fnend;
  9540.                 }
  9541.               }
  9542. #else
  9543.               sprintf(fnval,"%d",0);    /* SAFE */
  9544. #endif /* CK_AUTHENTICATION */
  9545.               goto fnend;
  9546.  
  9547.             case FN_KRB_NX:             /* Kerberos next ticket */
  9548. #ifdef CK_AUTHENTICATION
  9549.               switch (kv) {
  9550.                 case 4:
  9551.                   s = ck_krb4_get_next_tkt();
  9552.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9553.                   goto fnend;
  9554.                 case 5:
  9555.                   s = ck_krb5_get_next_tkt();
  9556.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9557.                   goto fnend;
  9558.               }
  9559. #else
  9560.               sprintf(fnval,"k%d next-ticket-string",kv); /* SAFE */
  9561. #endif /* CK_AUTHENTICATION */
  9562.               goto fnend;
  9563.  
  9564.             case FN_KRB_IV:             /* Kerberos ticket is valid */
  9565. #ifdef CK_AUTHENTICATION
  9566.               /* Return 1 if valid, 0 if not */
  9567.               switch (kv) {
  9568.                 case 4:
  9569.                   n = ck_krb4_tkt_isvalid(bp[1]);
  9570.                   sprintf(fnval, "%d", n > 0 ? 1 : 0); /* SAVE */
  9571.                   goto fnend;
  9572.                 case 5: {
  9573.                     extern char * krb5_d_cc;
  9574.                     n = ck_krb5_tkt_isvalid(krb5_d_cc,bp[1]);
  9575.                     sprintf(fnval,"%d", n > 0 ? 1 : 0); /* SAFE */
  9576.                     goto fnend;
  9577.                 }
  9578.               }
  9579. #else
  9580.               sprintf(fnval,"%d",0);    /* SAFE */
  9581. #endif /* CK_AUTHENTICATION */
  9582.               goto fnend;
  9583.  
  9584.             case FN_KRB_TT:             /* Kerberos ticket time */
  9585. #ifdef CK_AUTHENTICATION
  9586.               switch (kv) {
  9587.                 case 4:
  9588.                   n = ck_krb4_tkt_time(bp[1]);
  9589.                   sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9590.                   goto fnend;
  9591.                 case 5: {
  9592.                     extern char * krb5_d_cc;
  9593.                     n = ck_krb5_tkt_time(krb5_d_cc,bp[1]);
  9594.                     sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9595.                     goto fnend;
  9596.                 }
  9597.               }
  9598. #else
  9599.               ckstrncpy(fnval,"600",FNVALL); /* Some time */
  9600. #endif /* CK_AUTHENTICATION */
  9601.               goto fnend;
  9602.  
  9603.             case FN_KRB_FG:             /* Kerberos ticket flags */
  9604. #ifdef CK_AUTHENTICATION
  9605.               switch (kv) {
  9606.                 case 4:
  9607.                   fnval[0] = '\0';
  9608.                   goto fnend;
  9609.                 case 5: {
  9610.                     extern char * krb5_d_cc;
  9611.                     ckstrncpy(fnval,ck_krb5_tkt_flags(krb5_d_cc,bp[1]),FNVALL);
  9612.                     goto fnend;
  9613.                 }
  9614.               }
  9615. #else
  9616.               fnval[0] = '\0';
  9617. #endif /* CK_AUTHENTICATION */
  9618.               goto fnend;
  9619.           }
  9620.           p = fnval;
  9621.           goto fnend;
  9622.       }
  9623. #endif /* CK_KERBEROS */
  9624.  
  9625. #ifdef FN_ERRMSG
  9626.       case FN_ERRMSG:
  9627.         if (rdigits(bp[0])) {
  9628.             k = atoi(bp[0]);
  9629.         } else {
  9630.             failed = 1;
  9631.             if (fndiags)
  9632.              ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9633.             goto fnend;
  9634.         }
  9635. #ifdef VMS
  9636.         ckstrncpy(fnval,ckvmserrstr(k),FNVALL);
  9637. #else
  9638.         x = errno;
  9639.         errno = k;
  9640.         ckstrncpy(fnval,ck_errstr(),FNVALL);
  9641.         errno = x;
  9642. #endif /* VMS */
  9643.         p = fnval;
  9644.         goto fnend;
  9645. #endif /* FN_ERRMSG */
  9646.  
  9647.       case FN_DIM: {
  9648.           int max;
  9649.           char abuf[16], *s;
  9650.           fnval[0] = NUL;               /* Initial return value */
  9651.           ckstrncpy(abuf,bp[0],16);     /* Get array reference */
  9652.           s = abuf;
  9653.           if (*s == CMDQ) s++;
  9654.           failed = 1;                   /* Assume it's bad */
  9655.           p = fnval;                    /* Point to result */
  9656.           if (fndiags)                  /* Default is this error message */
  9657.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9658.           if (s[0] != '&') {            /* "Address" of array */
  9659.               goto fnend;
  9660.           }
  9661.           if (s[2]) {
  9662.               if (s[2] != '[' || s[3] != ']') {
  9663.                   goto fnend;
  9664.               }
  9665.           }
  9666.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  9667.             s[1] += 32;
  9668.           if (s[1] < 95 || s[1] > 122) { /* Check for a-z */
  9669.               goto fnend;                       /* Bad */
  9670.           }
  9671.           if ((max = chkarray(s[1],1)) < 1)
  9672.             max = 0;
  9673.           failed = 0;                   /* Unset failure flag */
  9674.           sprintf(fnval,"%d",max);      /* SAFE */
  9675.           goto fnend;
  9676.       }
  9677.  
  9678.     } /* Break up big switch... */
  9679.  
  9680.     switch (y) {
  9681.       case FN_JDATE:
  9682.         if (argn < 1)                   /* Check number of args */
  9683.           p = ckdate();                 /* None, get today's date-time */
  9684.         else                            /* Some */
  9685.           p = bp[0];                    /* Use first */
  9686.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9687.         ckstrncpy(fnval,zjdate(p),FNVALL); /* Convert to Julian */
  9688.         p = fnval;                      /* Point to result */
  9689.         failed = 0;
  9690.         if (*p == '-') {
  9691.             failed = 1;
  9692.             if (fndiags)                /* Default is this error message */
  9693.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9694.         }
  9695.         goto fnend;
  9696.  
  9697.       case FN_DATEJ:
  9698.         ckstrncpy(fnval,jzdate(bp[0]),FNVALL); /* Convert to yyyy<dayofyear> */
  9699.         p = fnval;                      /* Point to result */
  9700.         failed = 0;
  9701.         if (*p == '-') {
  9702.             failed = 1;
  9703.             if (fndiags)                /* Default is this error message */
  9704.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9705.         }
  9706.         goto fnend;
  9707.  
  9708.       case FN_DTIM:                     /* \fcvtdate() */
  9709.       case FN_TIME:                     /* Free-format time to hh:mm:ss */
  9710.       case FN_NTIM:                     /* Time to sec since midnight */
  9711.         s = (argn > 0) ? bp[0] : "";
  9712.         if (!s) s = "";
  9713.         if (!*s)
  9714.           p = ckdate();                 /* None, get today's date */
  9715.         else                            /* Some */
  9716.           p = bp[0];                    /* Use first */
  9717.         p = ckcvtdate(p,2);             /* Convert to standard form */
  9718.         if (*p == '<') {
  9719.             failed = 1;
  9720.             if (fndiags)                /* Default is this error message */
  9721.               ckmakmsg(fnval,FNVALL,
  9722.                        "<ERROR:ARG_BAD_DATE_OR_TIME:\\f",fn,"()>",NULL);
  9723.             p = fnval;
  9724.             goto fnend;
  9725.         }
  9726.         if (argn > 1) {
  9727.             s = bp[1];
  9728.             if (!s) s = "";
  9729.             if (!*s) s = "0";
  9730.             if (!chknum(s)) {
  9731.                 failed = 1;
  9732.                 if (fndiags)
  9733.                   ckmakmsg(fnval,FNVALL,
  9734.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9735.                 p = fnval;
  9736.                 goto fnend;
  9737.             }
  9738.             x = atoi(s);
  9739.             if (x) p = shuffledate(p,x);
  9740.         }
  9741.         if (cx == FN_TIME) {
  9742.             p += 9;
  9743.         } else if (cx == FN_NTIM) {
  9744.             long sec = 0L;
  9745.             p[11] = NUL;
  9746.             p[14] = NUL;
  9747.             sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  9748.             sprintf(fnval,"%ld",sec);   /* SAFE */
  9749.             p = fnval;
  9750.         }
  9751.         goto fnend;
  9752.  
  9753.       case FN_MJD:                      /* Modified Julian Date */
  9754.         if (argn < 1)                   /* Check number of args */
  9755.           p = zzndate();                /* None, get today's date-time */
  9756.         else                            /* Some */
  9757.           p = bp[0];                    /* Use first */
  9758.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9759.         if (*p == '-') {
  9760.             failed = 1;
  9761.             if (fndiags)                /* Default is this error message */
  9762.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9763.             goto fnend;
  9764.         }
  9765.         /* Convert to modified Julian date */
  9766.         sprintf(fnval,"%ld",mjd(p));    /* SAFE */
  9767.         p = fnval;                      /* Point to result */
  9768.         goto fnend;
  9769.  
  9770.       case FN_MJD2: {
  9771.           long k = 0L;
  9772.           int n = 0;
  9773.           p = evalx(bp[0]);
  9774.           if (*p == '-') {
  9775.               p++;
  9776.               n = 1;
  9777.           }
  9778.           if (!rdigits(p)) {
  9779.               failed = 1;
  9780.               evalerr(fn);
  9781.               p = fnval;
  9782.               goto fnend;
  9783.           } else {
  9784.               k = atol(p);
  9785.               if (n) k = -k;
  9786.           }
  9787.           ckstrncpy(fnval,mjd2date(k),FNVALL); /* Convert to Date */
  9788.           p = fnval;                    /* Point to result */
  9789.           failed = 0;
  9790.           goto fnend;
  9791.       }
  9792.  
  9793. #ifndef NODIAL
  9794.       case FN_PNCVT: {                  /* Convert phone number */
  9795.           extern char * pncvt();
  9796.           failed = 0;
  9797.           p = pncvt(bp[0]);
  9798.           if (!p) p = "";
  9799.           if (!*p) {
  9800.             failed = 1;
  9801.             if (fndiags)                /* Default is this error message */
  9802.               ckmakmsg(fnval,FNVALL,
  9803.                        "<ERROR:ARG_BAD_PHONENUM:\\f",fn,"()>",NULL);
  9804.         }
  9805.         goto fnend;
  9806.       }
  9807. #endif /* NODIAL */
  9808.  
  9809.       case FN_DAY:
  9810.       case FN_NDAY:
  9811.         if (argn < 1)                   /* Check number of args */
  9812.           p = zzndate();                /* None, get today's date-time */
  9813.         else                            /* Some */
  9814.           p = bp[0];                    /* Use first */
  9815.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9816.         if (*p == '-') {
  9817.             failed = 1;
  9818.             if (fndiags)                /* Default is this error message */
  9819.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9820.             goto fnend;
  9821.         }
  9822.         failed = 0;
  9823.         z = mjd(p);                     /* Convert to modified Julian date */
  9824.         z = z % 7L;
  9825.         if (z < 0) {
  9826.             z = 0 - z;
  9827.             k = 6 - ((int)z + 3) % 7;
  9828.         } else {
  9829.             k = ((int)z + 3) % 7;    /* Day of week */
  9830.         }
  9831.         p = fnval;                      /* Point to result */
  9832.         if (cx == FN_NDAY)
  9833.           sprintf(fnval,"%d",k);        /* SAFE */
  9834.         else
  9835.           ckstrncpy(fnval,wkdays[k],FNVALL);
  9836.         goto fnend;
  9837.  
  9838.       case FN_N2TIM: {                  /* Sec since midnight to hh:mm:ss */
  9839.           long k = 0L;
  9840.           int n = 0, hh, mm, ss;
  9841.           char * s = bp[0];
  9842.           if (argn < 1)                 /* If no arg substitute 0 */
  9843.             s = "0";
  9844.           p = evalx(s);                 /* Evaluate expression silently */
  9845.           if (*p == '-') {              /* Check result for minus sign */
  9846.               p++;
  9847.               n = 1;
  9848.           }
  9849.           if (!rdigits(p)) { /* Check for numeric */
  9850.               failed = 1;
  9851.               ckmakmsg(fnval,FNVALL,
  9852.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9853.               p = fnval;
  9854.               goto fnend;
  9855.           } else {
  9856.               k = atol(p);
  9857.               if (n) k = -k;
  9858.           }
  9859.           if (k < 0) {                  /* Check for negative */
  9860.               failed = 1;
  9861.               if (fndiags)
  9862.                 ckmakmsg(fnval,FNVALL,
  9863.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9864.               p = fnval;
  9865.               goto fnend;
  9866.           }
  9867.           hh = k / 3600L;               /* Have positive number */
  9868.           mm = (k % 3600L) / 60L;       /* break it down... */
  9869.           ss = ((k % 3600L) % 60L);
  9870.  
  9871.           sprintf(fnval,"%02d:%02d:%02d",hh,mm,ss); /* SAFE */
  9872.           p = fnval;
  9873.           failed = 0;
  9874.           goto fnend;
  9875.       }
  9876.  
  9877.       case FN_PERM: {                   /* File permissions */
  9878.           p = fnval;
  9879.           z = zchki(bp[0]);
  9880.           if (z < 0) {
  9881.               failed = 1;
  9882.               if (fndiags) {
  9883.                   if (z == -1)
  9884.                     ckmakmsg(fnval,FNVALL,
  9885.                              "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  9886.                   else if (z == -2)
  9887.                     ckmakmsg(fnval,FNVALL,
  9888.                              "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  9889.                   else if (z == -3)
  9890.                     ckmakmsg(fnval,FNVALL,
  9891.                              "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  9892.                   else
  9893.                     ckmakmsg(fnval,FNVALL,
  9894.                              "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  9895.               }
  9896.               goto fnend;
  9897.           }
  9898. #ifdef CK_PERMS
  9899.           ckstrncpy(fnval,ziperm(bp[0]),FNVALL);
  9900. #else
  9901.           ckstrncpy(fnval,"(unknown)",FNVALL);
  9902. #endif /* CK_PERMS */
  9903.           goto fnend;
  9904.       }
  9905.       case FN_TLOOK:                    /* tablelook() */
  9906.       case FN_ALOOK: {                  /* arraylook() */
  9907.           int i, x, hi, lo, max, cmdlen;
  9908.           char abuf[16], *s, *pat;
  9909.           char kwbuf[256];
  9910.           char delim = ':';
  9911.           failed = 1;                   /* Assume failure */
  9912.           ckstrncpy(fnval,"-1",FNVALL);
  9913.           pat = bp[0];                  /* Point to search pattern */
  9914.           if (!pat) pat = "";           /* Watch out for NULL pointer */
  9915.           cmdlen = strlen(pat);         /* Get pattern length */
  9916.           if (argn < 2 /* || cmdlen < 1 */ ) { /* Need two args */
  9917.               if (fndiags)
  9918.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9919.               goto fnend;
  9920.           }
  9921.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  9922.           if (argn > 2)
  9923.             delim = *(bp[2]);
  9924.           s = abuf;
  9925.           if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Get index and bounds */
  9926.               if (fndiags)
  9927.                ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9928.               goto fnend;
  9929.           }
  9930.           p = fnval;                    /* Point to result */
  9931.           max = a_dim[x];               /* Size of array */
  9932.           if (lo < 0) lo = 0;           /* Use given range if any */
  9933.           if (lo > max) lo = max;
  9934.           if (hi < 0) hi = max;
  9935.           if (hi > max) hi = max;
  9936.           failed = 0;                   /* Unset failure flag */
  9937.           if (max < 1)
  9938.             goto fnend;
  9939.           kwbuf[255] = NUL;
  9940.           for (i = lo; i <= hi; i++) {
  9941.               if (!a_ptr[x][i])
  9942.                 continue;
  9943.               if (cx == FN_ALOOK) {
  9944.                   if (ckmatch(pat,a_ptr[x][i],inpcas[cmdlvl],1+4)) {
  9945.                       sprintf(fnval,"%d",i); /* SAFE */
  9946.                       goto fnend;
  9947.                   }
  9948.               } else if (cx == FN_TLOOK) {
  9949.                   char * aa;
  9950.                   int j = 0, v = 0, len;
  9951.                   if (i == hi)
  9952.                     break;
  9953.                   aa = a_ptr[x][i];     /* Point to this array element */
  9954.                   if (!aa) aa = "";
  9955.                   while (j < 254 && *aa) { /* Isolate keyword */
  9956.                       if (*aa == delim)
  9957.                         break;
  9958.                       kwbuf[j++] = *aa++;
  9959.                   }
  9960.                   kwbuf[j] = NUL;
  9961.                   len = j;
  9962.                   v = 0;
  9963.                   if ((len == cmdlen && !ckstrcmp(kwbuf,pat,len,0)) ||
  9964.                       ((v = !ckstrcmp(kwbuf,pat,cmdlen,0)) &&
  9965.                        ckstrcmp(a_ptr[x][i+1],pat,cmdlen,0))) {
  9966.                       sprintf(fnval,"%d",i); /* SAFE */
  9967.                       goto fnend;
  9968.                   }
  9969.                   if (v) {              /* Ambiguous */
  9970.                       ckstrncpy(fnval,"-2",FNVALL);
  9971.                       goto fnend;
  9972.                   }
  9973.               }
  9974.           }
  9975.           if (cx == FN_TLOOK) {         /* tablelook() last element */
  9976.               ckstrncpy(fnval,"-1",FNVALL);
  9977.               if (!ckstrcmp(a_ptr[x][hi],pat,cmdlen,0))
  9978.                 sprintf(fnval,"%d",hi); /* SAFE */
  9979.           }
  9980.           goto fnend;
  9981.       }
  9982.       case FN_TOB64:                    /* Base-64 conversion */
  9983.       case FN_FMB64:
  9984.         p = fnval;
  9985.         *p = NUL;
  9986.         if (argn < 1)
  9987.           goto fnend;
  9988.         if (cx == FN_TOB64) {
  9989.             x = b8tob64(bp[0],-1,fnval,FNVALL);
  9990.         } else {
  9991.             x = strlen(bp[0]);
  9992.             if (x % 4) {                /* length must be multiple of 4 */
  9993.                 failed = 1;
  9994.                 ckmakmsg(fnval,FNVALL,
  9995.                          "<ERROR:ARG_INCOMPLETE:\\f",fn,"()>",NULL);
  9996.                 goto fnend;
  9997.             }
  9998.             b64tob8(NULL,0,NULL,0);     /* Reset */
  9999.             x = b64tob8(bp[0],-1,fnval,FNVALL);
  10000.             b64tob8(NULL,0,NULL,0);     /* Reset again */
  10001.         }
  10002.         if (x < 0) {
  10003.             failed = 1;
  10004.             if (fndiags) {
  10005.                 char * m = "INTERNAL_ERROR";
  10006.                 switch (x) {
  10007.                   case -1: m = "ARG_TOO_LONG"; break;
  10008.                   case -2: m = "ARG_OUT_OF_RANGE"; break;
  10009.                 }
  10010.                 if (ckmakmsg(fnval,FNVALL,"<ERROR:",m,"\\f",fn) > 0)
  10011.                   ckstrncat(fnval,"()>",FNVALL);
  10012.             }
  10013.         }
  10014.         goto fnend;
  10015.  
  10016.       case FN_ABS: {
  10017.           char * s;
  10018.           s = bp[0];
  10019.           if (*s == '-' || *s == '+')
  10020.             s++;
  10021.           if (!rdigits(s)) {
  10022.               if (fndiags)
  10023.                 ckmakmsg(fnval,FNVALL,
  10024.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10025.               goto fnend;
  10026.           }
  10027.           ckstrncpy(fnval,s,FNVALL);
  10028.           goto fnend;
  10029.       }
  10030.  
  10031.       case FN_AADUMP: {
  10032.           char abuf[16], *s = NULL, **ap = NULL, **vp = NULL;
  10033.           char pattern[VNAML];
  10034.           int slen, i, j, k, first = -1;
  10035.           extern int xdelmac();
  10036.           p = fnval;
  10037.           if (argn < 2) {
  10038.               if (fndiags)
  10039.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG2:\\f",fn,"()>",NULL);
  10040.               goto fnend;
  10041.           }
  10042.           debug(F101,"aaconvert argn","",argn);
  10043.           s = bp[0];
  10044.           slen = strlen(s);
  10045.  
  10046.           /* Count elements so we can create the array */
  10047.  
  10048.           ckmakmsg(pattern,VNAML,s,"<*>",NULL,NULL);
  10049.           for (k = 0, i = 0; i < nmac; i++) {
  10050.               if (ckmatch(pattern,mactab[i].kwd,0,1)) {
  10051.                   if (first < 0)        /* Remember location of first match */
  10052.                     first = i;
  10053.                   k++;
  10054.               }
  10055.           }
  10056.           debug(F101,"aaconvert matches","",k);
  10057.           debug(F101,"aaconvert first","",first);
  10058.           fnval[0] = NUL;               /* Initial return value */
  10059.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  10060.           s = abuf;
  10061.           if (*s == CMDQ) s++;
  10062.           p = fnval;                    /* Point to result */
  10063.           if (fndiags)                  /* Default is this error message */
  10064.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10065.           if (s[0] != '&')              /* Address of array */
  10066.             goto fnend;
  10067.           if (s[2])
  10068.             if (s[2] != '[' || s[3] != ']')
  10069.               goto fnend;
  10070.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  10071.             s[1] += 32;
  10072.           if ((x = dclarray(s[1],k)) < 0) /* Declare array to size */
  10073.             goto fnend;
  10074.           ap = a_ptr[x];                /* Point to array we just declared */
  10075.           debug(F111,"aaconvert array 1",abuf,ap);
  10076.           abuf[0] = NUL;
  10077.           if (argn > 2) {
  10078.               ckstrncpy(abuf,bp[2],16); /* Get value array reference */
  10079.               s = abuf;
  10080.               if (*s == CMDQ) s++;
  10081.               if (s[0] != '&')          /* Address of array */
  10082.                 goto fnend;
  10083.               if (s[2])
  10084.                 if (s[2] != '[' || s[3] != ']')
  10085.                   goto fnend;
  10086.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  10087.                 s[1] += 32;
  10088.               if ((x = dclarray(s[1],k)) < 0)
  10089.                 goto fnend;
  10090.               vp = a_ptr[x];            /* Point to array we just declared */
  10091.           }
  10092.           debug(F111,"aaconvert array 2",abuf,vp);
  10093.           makestr(&ap[0],ckitoa(k));
  10094.           if (vp) makestr(&vp[0],ckitoa(k));
  10095.           if (fndiags)
  10096.            ckmakmsg(fnval,FNVALL,"<ERROR:ASSOCIATIVE_ARRAY:\\f",fn,"()>",NULL);
  10097.  
  10098.           /* Copy macro index & value to the arrays and then remove the */
  10099.           /* macro, so the 'first' pointer keeps indicating the next one. */
  10100.           /* We could combine the initial counting loop with this one but */
  10101.           /* then it would be harder to create the array and anyway this */
  10102.           /* function is plenty fast as it is. */
  10103.  
  10104.           for (i = 1; i <= k; ) {
  10105.               if (!ckmatch(pattern,mactab[first].kwd,0,1)) {
  10106.                   debug(F111,"aaconvert oddball",mactab[first].kwd,first);
  10107.                   first++;
  10108.                   continue;
  10109.               }
  10110.               ckstrncpy(tmpbuf,mactab[first].kwd,TMPBUFSIZ); /* Macro name */
  10111.               s = tmpbuf;                       /* Make writeable copy */
  10112.               s += slen;                        /* Isolate "index" */
  10113.               j = strlen(s) - 1;
  10114.               if (*s != '<' || *(s+j) != '>') { /* Check syntax */
  10115.                   /* This shouldn't happen */
  10116.                   debug(F111,"aaconvert ERROR",mactab[first].kwd,first);
  10117.                   goto fnend;
  10118.               }
  10119.               *(s+j) = NUL;             /* Remove final '>' */
  10120.               debug(F111,"aaconvert",s+1,i);
  10121.               makestr(&(ap[i]),s+1);    /* Set first array to index */
  10122.               if (vp)
  10123.                 makestr(&(vp[i]),mactab[first].mval); /* 2nd to value */
  10124.               if (xdelmac(first) < 0)
  10125.                 goto fnend;
  10126.               i++;
  10127.           }
  10128.           sprintf(fnval,"%d",k);        /* SAFE */
  10129.           p = fnval;                    /* Return size of array */
  10130.           debug(F110,"aaconvert return",p,0);
  10131.           failed = 0;                   /* Unset failure flag */
  10132.           goto fnend;
  10133.       }
  10134.  
  10135.     } /* End of switch() */
  10136.  
  10137. #ifdef FNFLOAT
  10138. /*
  10139.   Floating-point functions.  To be included only if FNFLOAT is defined, which
  10140.   should happen only if CKFLOAT is also defined, and if the math library is
  10141.   linked in.  Even then, we might have float-vs-double confusion as well as
  10142.   confusion about what the final "%f" format effector is supposed to reference
  10143.   (32 bits, 64 bits, etc).  Expect trouble if CKFLOAT does not match the data
  10144.   type of math library functions or args.
  10145. */
  10146.     if (cx == FN_FPABS ||               /* Floating-point functions */
  10147.         cx == FN_FPADD ||
  10148.         cx == FN_FPDIV ||
  10149.         cx == FN_FPEXP ||
  10150.         cx == FN_FPLOG ||
  10151.         cx == FN_FPLN  ||
  10152.         cx == FN_FPMOD ||
  10153.         cx == FN_FPMAX ||
  10154.         cx == FN_FPMIN ||
  10155.         cx == FN_FPMUL ||
  10156.         cx == FN_FPPOW ||
  10157.         cx == FN_FPSQR ||
  10158.         cx == FN_FPINT ||
  10159.         cx == FN_FPSUB ||
  10160.         cx == FN_FPROU ||
  10161.         cx == FN_FPSIN ||
  10162.         cx == FN_FPCOS ||
  10163.         cx == FN_FPTAN) {
  10164.         CKFLOAT farg[2], fpresult = 0.0;
  10165.         char fpbuf[64], * bp0;
  10166.         double dummy;
  10167.         /* int sign = 0; */
  10168.         int i, j, places = 0;
  10169.         int argcount = 1;
  10170.  
  10171.         failed = 1;
  10172.         p = fnval;
  10173.         bp0 = bp[0];
  10174.         if (!bp0)
  10175.           bp0 = "0";
  10176.         else if (!*bp0)
  10177.           bp0 = "0";
  10178.         if (!isfloat(bp0,0)) {
  10179.             k = mxlook(mactab,bp0,nmac);
  10180.             bp0 = (k > -1) ? mactab[k].mval : NULL;
  10181.             if (bp0) {
  10182.                 if (!isfloat(bp0,0)) {
  10183.                     if (fndiags)
  10184.                       ckmakmsg(fnval,FNVALL,
  10185.                                "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10186.                     goto fnend;
  10187.                 }
  10188.             }
  10189.         }
  10190.         if (cx == FN_FPINT) {           /* Float to int */
  10191.             failed = 0;
  10192.             ckstrncpy(fnval,bp0,FNVALL);
  10193.             for (i = 0; fnval[i]; i++) {
  10194.                 if (fnval[i] == '.') {
  10195.                     fnval[i] = NUL;
  10196.                     break;
  10197.                 }
  10198.             }
  10199.             goto fnend;
  10200.         }
  10201.         switch (y) {                    /* These need 2 args */
  10202.           case FN_FPADD:
  10203.           case FN_FPDIV:
  10204.           case FN_FPMOD:
  10205.           case FN_FPMAX:
  10206.           case FN_FPMIN:
  10207.           case FN_FPMUL:
  10208.           case FN_FPPOW:
  10209.           case FN_FPSUB:
  10210.             argcount = 2;
  10211.         }
  10212.         /* Missing arguments are supplied as 0.0 */
  10213.  
  10214.         debug(F111,fn,"argcount",argcount);
  10215.         for (i = 0; i < argcount; i++) { /* Get floating-point args */
  10216. #ifdef DEBUG
  10217.             if (deblog) {
  10218.                 ckmakmsg(fpbuf,
  10219.                          64,
  10220.                          "bp[",
  10221.                          ckitoa(i),
  10222.                          bp[i] ? bp[i] : "(null)",
  10223.                          "]"
  10224.                          );
  10225.                 debug(F100,fpbuf,"",0);
  10226.             }
  10227. #endif /* DEBUG */
  10228.             if (!bp[i]) {
  10229.                 farg[i] = 0.0;
  10230.             } else if (!*(bp[i])) {
  10231.                 farg[i] = 0.0;
  10232.             } else if (!isfloat(bp[i],0)) {
  10233.                 char * tmp;
  10234.                 k = mxlook(mactab,bp[i],nmac);
  10235.                 tmp = (k > -1) ? mactab[k].mval : NULL;
  10236.                 if (tmp) {
  10237.                     if (!isfloat(tmp,0)) {
  10238.                         if (fndiags)
  10239.                           ckmakmsg(fnval,FNVALL,
  10240.                                    "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10241.                         goto fnend;
  10242.                     }
  10243.                 }
  10244.             }
  10245.             farg[i] = floatval;
  10246.  
  10247. #ifdef DEBUG
  10248.             if (deblog) {
  10249.                 sprintf(fpbuf,"farg[%d]=%f",i,farg[i]); /* SAFE */
  10250.                 debug(F100,fpbuf,"",0);
  10251.             }
  10252. #endif /* DEBUG */
  10253.         }
  10254.         if (bp[argcount]) {             /* Get decimal places */
  10255.             char * s;
  10256.             s = bp[argcount];
  10257.             if (!s) s = "";
  10258.             if (!*s) s = "0";
  10259.             s = evalx(s);
  10260.             if (!s) s = "";
  10261.             if (!*s) {
  10262.                 evalerr(fn);
  10263.                 goto fnend;
  10264.             }
  10265.             places = atoi(s);
  10266.         }
  10267.         errno = 0;
  10268.         failed = 0;
  10269.         switch (y) {                    /* Now do the requested function */
  10270.           case FN_FPABS:                /* Floating-point absolute value */
  10271. #ifndef COMMENT
  10272.             fpresult = fabs(farg[0]);
  10273. #else
  10274.             if (farg[0] < 0.0)
  10275.               fpresult = 0.0 - farg[0];
  10276. #endif /* COMMENT */
  10277.             break;
  10278.           case FN_FPADD:                /* FP add */
  10279.             fpresult = farg[0] + farg[1];
  10280.             break;
  10281.           case FN_FPDIV:                /* FP divide */
  10282.           case FN_FPMOD:                /* FP modulus */
  10283.             if (!farg[1]) {
  10284.                 failed = 1;
  10285.                 if (fndiags)
  10286.                   ckmakmsg(fnval,FNVALL,
  10287.                            "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  10288.             } else
  10289.               fpresult = (cx == FN_FPDIV) ?
  10290.                 (farg[0] / farg[1]) :
  10291.                   fmod(farg[0],farg[1]);
  10292.             break;
  10293.           case FN_FPEXP:                /* FP e to the x */
  10294.             fpresult = (CKFLOAT) exp(farg[0]);
  10295.             break;
  10296.           case FN_FPLOG:                /* FP base-10 logarithm */
  10297.           case FN_FPLN:                 /* FP natural logarithm */
  10298.             if (farg[0] < 0.0) {
  10299.                 failed = 1;
  10300.                 if (fndiags)
  10301.                   ckmakmsg(fnval,FNVALL,
  10302.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10303.             } else
  10304.               fpresult = (cx == FN_FPLOG) ? log10(farg[0]) : log(farg[0]);
  10305.             break;
  10306.           case FN_FPMUL:                /* FP multiply */
  10307.             fpresult = farg[0] * farg[1];
  10308.             break;
  10309.           case FN_FPPOW:                /* FP raise to a power */
  10310.             fpresult = modf(farg[1],&dummy);
  10311.             if ((!farg[0] && farg[1] <= 0.0) ||
  10312.                 (farg[0] < 0.0 && fpresult)) {
  10313.                 failed = 1;
  10314.                 if (fndiags)
  10315.                   ckmakmsg(fnval,FNVALL,
  10316.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10317.             } else
  10318.               fpresult = pow(farg[0],farg[1]);
  10319.             break;
  10320.           case FN_FPSQR:                /* FP square root */
  10321.             if (farg[0] < 0.0) {
  10322.                 failed = 1;
  10323.                 if (fndiags)
  10324.                   ckmakmsg(fnval,FNVALL,
  10325.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10326.             } else
  10327.               fpresult = sqrt(farg[0]);
  10328.             break;
  10329.           case FN_FPSUB:                /* FP subtract */
  10330.             fpresult = farg[0] - farg[1];
  10331.             break;
  10332.           case FN_FPROU:                /* FP round */
  10333.             fpresult = farg[0];
  10334.             break;
  10335.           case FN_FPSIN:                /* FP sine */
  10336.             fpresult = (CKFLOAT) sin(farg[0]);
  10337.             break;
  10338.           case FN_FPCOS:                /* FP cosine */
  10339.             fpresult = (CKFLOAT) cos(farg[0]);
  10340.             break;
  10341.           case FN_FPTAN:                /* FP tangent */
  10342.             fpresult = (CKFLOAT) tan(farg[0]);
  10343.             break;
  10344.           case FN_FPMAX:
  10345.             fpresult = (farg[0] > farg[1]) ? farg[0] : farg[1];
  10346.             break;
  10347.           case FN_FPMIN:
  10348.             fpresult = (farg[0] < farg[1]) ? farg[0] : farg[1];
  10349.             break;
  10350.         }
  10351.  
  10352.         /* Get here with fpresult = function result */
  10353.  
  10354.         if (errno) {                    /* If range or domain error */
  10355.             failed = 1;
  10356.             if (fndiags)
  10357.               ckmakmsg(fnval,FNVALL,
  10358.                        "<ERROR:FLOATING-POINT-OP:\\f",fn,"()>",NULL);
  10359.         }
  10360.         if (failed)                     /* and/or any other kind of error, */
  10361.           goto fnend;                   /* fail. */
  10362. #ifndef COMMENT
  10363.         /* Call routine containing code that was formerly inline */
  10364.         ckstrncpy(fnval,fpformat(fpresult,places,cx == FN_FPROU),FNVALL);
  10365. #else
  10366.         {
  10367.             char fbuf[16];              /* For creating printf format */
  10368.             if (!fp_rounding &&         /* If printf doesn't round, */
  10369.                 (places > 0 ||          /* round result to decimal places. */
  10370.                  (places == 0 && cx == FN_FPROU)))
  10371.               fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  10372.             if (places > 0) {                   /* If places specified */
  10373.                 /* use specified places to write given number of digits */
  10374.                 sprintf(fbuf,"%%0.%df",places); /* SAFE */
  10375.                 sprintf(fnval,fbuf,fpresult);   /* SAFE */
  10376.             } else {                            /* Otherwise... */
  10377. #ifdef COMMENT
  10378. /*
  10379.   Here we want to print exactly fp_digits significant digits, no matter which
  10380.   side of the decimal point they are on.  That is, we want want the default
  10381.   format to show the maximum number of non-garbage digits, AND we want the last
  10382.   such digit to be rounded.  Of course there is no way to do that, since the
  10383.   digit after the last non-garbage digit is, well, garbage.  So the following
  10384.   clever ruse does no good.
  10385. */
  10386.                 int sign = 0, m = 0;
  10387.                 sprintf(fnval,"%f",fpresult);
  10388.                 if (fnval[0] == '-') sign = 1;
  10389.                 for (i = sign; i < FNVALL; i++) {
  10390.                     if (isdigit(fnval[i]))
  10391.                       m++;
  10392.                     else
  10393.                       break;
  10394.                 }
  10395.                 if (m > 1) {
  10396.                     int d = fp_digits - m;
  10397.                     if (d < 1) d = 1;
  10398.                     sprintf(fbuf,"%%%d.%df",fp_digits+sign+1,d);
  10399.                 } else {
  10400.                     sprintf(fbuf,"%%0.%df",fp_digits);
  10401.                 }
  10402.                 sprintf(fnval,fbuf,fpresult);
  10403. #else
  10404.                 /* Go for max precision */
  10405.                 sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  10406.                 sprintf(fnval,fbuf,fpresult); /* SAFE */
  10407.  
  10408. #endif /* COMMENT */
  10409.             }
  10410.             if (fnval[0] == '-') sign = 1;
  10411.         }
  10412.         debug(F111,"fpresult 1",fnval,errno); /* Check for over/underflow */
  10413.         for (i = sign; fnval[i]; i++) { /* Give requested decimal places */
  10414.             if (fnval[i] == '.')        /* First find the decimal point */
  10415.               break;
  10416.             else if (i > fp_digits + sign - 1) /* replacing garbage */
  10417.               fnval[i] = '0';           /* digits with 0... */
  10418.         }
  10419.         if (fnval[i] == '.') {          /* Have decimal point */
  10420.             int gotend = 0;
  10421.             /* d < 0 so truncate fraction */
  10422.             if (places < 0 || (places == 0 && cx == FN_FPROU)) {
  10423.                 fnval[i] = NUL;
  10424.             } else if (places > 0) {    /* d > 0 so this many decimal places */
  10425.                 i++;                           /* First digit after decimal */
  10426.                 for (j = 0; j < places; j++) { /* Truncate after d decimal */
  10427.                     if (!fnval[j+i])           /* places or extend to d  */
  10428.                       gotend = 1;              /* decimal places. */
  10429.                     if (gotend || j+i+sign > fp_digits)
  10430.                       fnval[j+i] = '0';
  10431.                 }
  10432.                 fnval[j+i] = NUL;
  10433.             } else {                    /* d == 0 so Do The Right Thing */
  10434.                 for (j = (int)strlen(fnval) - 1; j > i+1; j--) {
  10435.                     if ((j - sign) > fp_digits)
  10436.                       fnval[j] = '0';
  10437.                     if (fnval[j] == '0')
  10438.                       fnval[j] = NUL;   /* Strip useless trailing 0's. */
  10439.                     else
  10440.                       break;
  10441.                 }
  10442.             }
  10443.         }
  10444. #endif /* COMMENT */
  10445.         debug(F111,"fpresult 2",fnval,errno);
  10446.         goto fnend;
  10447.  
  10448.     }
  10449. #endif /* FNFLOAT */
  10450.  
  10451. #ifdef CKCHANNELIO
  10452.     if (cx == FN_FSTAT  ||              /* File functions */
  10453.         cx == FN_FPOS   ||
  10454.         cx == FN_FEOF   ||
  10455.         cx == FN_FGCHAR ||
  10456.         cx == FN_FGLINE ||
  10457.         cx == FN_FGBLK  ||
  10458.         cx == FN_FPCHAR ||
  10459.         cx == FN_FPLINE ||
  10460.         cx == FN_FPBLK  ||
  10461.         cx == FN_NLINE  ||
  10462.         cx == FN_FERMSG ||
  10463.         cx == FN_FILNO) {
  10464.         int x = 0, t = 0, channel;
  10465.         long z;
  10466.         extern int z_maxchan;
  10467.  
  10468.         failed = 1;                     /* Assume failure */
  10469.         p = fnval;                      /* until we validate args */
  10470.         if (cx == FN_FERMSG) {
  10471.             extern int z_error;
  10472.             if (argn < 1) {
  10473.                 x = z_error;
  10474.             } else if (chknum(bp[0])) {
  10475.                 x = atoi(bp[0]);
  10476.             } else if (fndiags)
  10477.               ckmakmsg(fnval,FNVALL,
  10478.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10479.             failed = 0;
  10480.             ckstrncpy(fnval,ckferror(x),FNVALL);
  10481.             goto fnend;
  10482.         }
  10483.         if (argn < 1) {                 /* All file functions need channel */
  10484.             if (fndiags)
  10485.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10486.             goto fnend;
  10487.         }
  10488.         if (rdigits(bp[0])) {           /* Channel must be numeric */
  10489.             channel = atoi(bp[0]);
  10490.         } else {                        /* Fail if it isn't */
  10491.             if (fndiags)
  10492.               ckmakmsg(fnval,FNVALL,
  10493.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10494.             goto fnend;
  10495.         }
  10496.         if (channel < 0 || channel > z_maxchan) { /* Check channel range */
  10497.             if (fndiags)
  10498.               ckmakmsg(fnval,FNVALL,
  10499.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10500.             goto fnend;
  10501.         }
  10502.         x = z_getmode(channel);         /* Find out about the channel */
  10503.  
  10504.         failed = 0;                     /* Assume success from here down */
  10505.         if (cx == FN_FSTAT) {           /* Status / modes of channel */
  10506.             if (x > -1)
  10507.               x &= FM_RWB;              /* Mask out irrelevant bits */
  10508.             else                        /* In this case not open is OK */
  10509.               x = 0;                    /* 0 if not open, 1-7 if open */
  10510.             sprintf(fnval,"%d",x);      /* SAFE */
  10511.             goto fnend;
  10512.         } else if (x < 1) {             /* Not \f_status() so must be open */
  10513.             failed = 1;
  10514.             if (fndiags)
  10515.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_OPEN:\\f",fn,"()>",NULL);
  10516.             goto fnend;
  10517.         }
  10518.         switch (y) {                    /* Do the requested function */
  10519.           case FN_FPOS:                 /* Get position */
  10520.             z = z_getpos(channel);
  10521.             sprintf(fnval,"%ld",z);     /* SAFE */
  10522.             goto fnend;
  10523.  
  10524.           case FN_NLINE:                /* Get line number */
  10525.             z = z_getline(channel);
  10526.             sprintf(fnval,"%ld",z);     /* SAFE */
  10527.             goto fnend;
  10528.  
  10529.           case FN_FEOF:                 /* Check EOF */
  10530.             t = 0;
  10531.             if (x & FM_EOF) t = 1;
  10532.             sprintf(fnval,"%d",t);      /* SAFE */
  10533.             goto fnend;
  10534.  
  10535.           case FN_FILNO:                /* Get file handle */
  10536.             x = z_getfnum(channel);
  10537.             sprintf(fnval,"%d",x);      /* SAFE */
  10538.             goto fnend;
  10539.  
  10540.           case FN_FPBLK:                /* Read or write block */
  10541.           case FN_FGBLK:
  10542.             if (argn < 2) {
  10543.                 if (fndiags)
  10544.                   ckmakmsg(fnval,FNVALL,
  10545.                            "<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10546.                 goto fnend;
  10547.             }
  10548.             if (rdigits(bp[1])) {
  10549.                 t = atoi(bp[1]);
  10550.             } else {
  10551.                 if (fndiags)
  10552.                   ckmakmsg(fnval,FNVALL,
  10553.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10554.                 goto fnend;
  10555.             }
  10556.           case FN_FGCHAR:               /* Read or write character or line */
  10557.           case FN_FPCHAR:
  10558.           case FN_FGLINE:
  10559.           case FN_FPLINE:
  10560.             fnval[0] = NUL;
  10561.             switch (y) {
  10562.               case FN_FGCHAR: t = z_in(channel,fnval,FNVALL,1,1); break;
  10563.               case FN_FGLINE: t = z_in(channel,fnval,FNVALL,FNVALL-1,0); break;
  10564.               case FN_FGBLK:
  10565.                 if (t >= FNVALL) t = FNVALL - 1;
  10566.                 t = z_in(channel,fnval,FNVALL,t,1);
  10567.                 break;
  10568.               case FN_FPCHAR: t = z_out(channel,bp[1],1,1);  break;
  10569.               case FN_FPLINE: t = z_out(channel,bp[1],-1,0); break;
  10570.               case FN_FPBLK:  t = z_out(channel,bp[1],-1,1); break;
  10571.             }
  10572.             if (t < 0) {                /* Handle read/write error */
  10573.                 failed = 1;
  10574.                 if (fndiags && t != FX_EOF)
  10575.                   ckmakmsg(fnval,FNVALL,
  10576.                            "<ERROR:FILE_ERROR_%d:\\f",fn,"()>",NULL);
  10577.                 goto fnend;
  10578.             }
  10579.             if (cx == FN_FGCHAR)        /* Null terminate char */
  10580.               fnval[1] = NUL;
  10581.             /* Write (put) functions return numeric status code */
  10582.             if (cx == FN_FPCHAR || cx == FN_FPLINE || cx == FN_FPBLK)
  10583.               sprintf(fnval,"%d",t);    /* SAFE */
  10584.             goto fnend;
  10585.         }
  10586.     }
  10587. #endif /* CKCHANNELIO */
  10588.  
  10589.     if (cx == FN_PATTERN) {             /* \fpattern() */
  10590.         ispattern = 1;
  10591.         if (argn > 0) {
  10592.             p = fnval;
  10593.             ckstrncpy(fnval,bp[0],FNVALL);
  10594.         } else p = "";
  10595.         goto fnend;
  10596.     }
  10597.  
  10598.     if (cx == FN_HEX2N || cx == FN_OCT2N) { /* \fhex2n(), \foct2n() */
  10599.         p = "0";
  10600.         if (argn < 1)
  10601.           goto fnend;
  10602.         p = ckradix(bp[0], ((cx == FN_HEX2N) ? 16 : 8), 10);
  10603.         if (!p) {
  10604.             if (fndiags)
  10605.               ckmakmsg(fnval,FNVALL,
  10606.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10607.             goto fnend;
  10608.         }
  10609.         failed = 0;
  10610.         ckstrncpy(fnval,p,FNVALL);
  10611.         p = fnval;
  10612.         goto fnend;
  10613.     }
  10614.  
  10615.     if (cx == FN_HEX2IP) {
  10616.         int c[2], ip[4], i, k;
  10617.         p = "0";
  10618.         if (argn < 1)
  10619.           goto fnend;
  10620.         s = bp[0];
  10621.         if ((int)strlen(s) != 8) {
  10622.             failed = 1;
  10623.             if (fndiags)
  10624.               ckmakmsg(fnval,FNVALL,
  10625.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10626.             goto fnend;
  10627.         }
  10628.         p = fnval;
  10629.         for (k = 0; k < 8; k += 2) {
  10630.             for (i = 0; i < 2; i++) {
  10631.                 c[i] = *s++;
  10632.                 if (islower(c[i])) c[i] = toupper(c[i]);
  10633.                 if (c[i] >= '0' && c[i] <= '9') {
  10634.                     c[i] -= 0x30;
  10635.                 } else if (c[i] >= 'A' && c[i] <= 'F') {
  10636.                     c[i] -= 0x37;
  10637.                 } else {
  10638.                     failed = 1;
  10639.                     if (fndiags)
  10640.                       ckmakmsg(fnval,FNVALL,
  10641.                                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10642.                     goto fnend;
  10643.                 }
  10644.                 ip[k/2] = c[0] << 4 | c[1];
  10645.             }
  10646.             sprintf(p,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10647.         }
  10648.         goto fnend;
  10649.     }
  10650.     if (cx == FN_IP2HEX) {
  10651.         int ip[4], i;
  10652.         char * q;
  10653.         p = "00000000";
  10654.         if (argn < 1)
  10655.           goto fnend;
  10656.         s = bp[0];
  10657.         p = fnval;
  10658.         for (i = 0; i < 3; i++) {
  10659.             q = ckstrchr(s,'.');
  10660.             if (q) {
  10661.                 *q++ = NUL;
  10662.                 ip[i] = atoi(s);
  10663.                 s = q;
  10664.             } else {
  10665.                 failed = 1;
  10666.                 if (fndiags)
  10667.                   ckmakmsg(fnval,FNVALL,
  10668.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10669.                 goto fnend;
  10670.             }
  10671.         }
  10672.         ip[3] = atoi(s);
  10673.         sprintf(p,"%02x%02x%02x%02x",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10674.         goto fnend;
  10675.     }
  10676.     if (cx == FN_RADIX) {
  10677.         failed = 1;
  10678.         p = fnval;
  10679.         if (argn < 3) {
  10680.             if (fndiags)
  10681.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10682.             goto fnend;
  10683.         }
  10684.         if (!rdigits(bp[1]) || !rdigits(bp[2])) {
  10685.             if (fndiags)
  10686.               ckmakmsg(fnval,FNVALL,
  10687.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10688.             goto fnend;
  10689.         }
  10690.         p = ckradix(bp[0],atoi(bp[1]),atoi(bp[2]));
  10691.         if (!p) {
  10692.             if (fndiags)
  10693.               ckmakmsg(fnval,FNVALL,
  10694.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10695.             goto fnend;
  10696.         }
  10697.         failed = 0;
  10698.         ckstrncpy(fnval,p,FNVALL);
  10699.         p = fnval;
  10700.         goto fnend;
  10701.     }
  10702.     if (cx == FN_JOIN) {
  10703.         int i, x, y, z, flag, hi, lo, max, seplen, grouping = 0;
  10704.         char abuf[16], c, *s, *q, *sep = NULL;
  10705.         char * gr_opn = "\"{'([<";      /* Group open brackets */
  10706.         char * gr_cls = "\"}')]>";      /* Group close brackets */
  10707.         char lb[2], rb[2];              /* Selected left and right brackets */
  10708.  
  10709.         failed = 1;                     /* Assume failure */
  10710.         fnval[0] = NUL;
  10711.         debug(F101,"FNJOIN ARGN","",argn);
  10712.  
  10713.         ckstrncpy(abuf,bp[0],16);       /* Get array reference */
  10714.         s = abuf;
  10715.         if ((x = arraybounds(s,&lo,&hi)) < 0) {  /* Get index and bounds */
  10716.             if (fndiags)
  10717.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10718.             goto fnend;
  10719.         }
  10720.         p = fnval;                      /* Point to result */
  10721.         max = a_dim[x];                 /* Size of array */
  10722.         if (lo < 0) lo = 1;             /* Use given range if any */
  10723.         if (lo > max) lo = max;
  10724. #ifdef COMMENT
  10725.     hi = max;
  10726. #else
  10727. /*
  10728.   This is a workaround for the problem in which the dimension of the \&_[]
  10729.   array (but not its contents) grows upon entry to a SWITCH block.  But this
  10730.   code prevents the dimension from growing.  Go figure.
  10731. */
  10732.         if (hi < 0) {            /* Bounds not given */
  10733.             if (x)            /* Regular array */
  10734.           hi = max;
  10735.         else            /* Argument vector array */
  10736.           for (hi = max; hi >= lo; hi--) { /* ignore any trailing */
  10737.           if (!a_ptr[x][hi]) continue; /* empty elements */
  10738.           if (!*(a_ptr[x][hi])) continue;
  10739.           break;
  10740.           }
  10741.     }
  10742. #endif /* COMMENT */
  10743.         if (hi > max) hi = max;
  10744.         failed = 0;                     /* Unset failure flag */
  10745.         if (max < 1)
  10746.           goto fnend;
  10747.         sep = " ";                      /* Separator */
  10748.         if (argn > 1)
  10749.           if (bp[1])
  10750.             if (*bp[1])
  10751.               sep = bp[1];
  10752.         lb[0] = NUL;
  10753.         rb[0] = NUL;
  10754.         lb[1] = NUL;
  10755.         rb[1] = NUL;
  10756.         if (argn > 2) {                 /* Grouping? */
  10757.             char * bp2 = bp[2];
  10758.             if (!bp2) bp2 = "0";
  10759.             if (!*bp2) bp2 = "0";
  10760.             if (chknum(bp2)) {
  10761.                 grouping = atoi(bp2);
  10762.                 if (grouping < 0 || grouping > 63)
  10763.                   grouping = 1;
  10764.             } else {
  10765.                 failed = 1;
  10766.                 if (fndiags)
  10767.                   ckmakmsg(fnval,FNVALL,
  10768.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10769.                 goto fnend;
  10770.             }
  10771.             if (grouping) {             /* Take lowest-order one */
  10772.                 int j, k;               /* and set the others to 0 */
  10773.                 for (k = 0; k < 6; k++) {
  10774.                     j = 1 << k;
  10775.                     if (grouping & j) {
  10776.                         lb[0] = gr_opn[k];
  10777.                         rb[0] = gr_cls[k];
  10778.                         break;
  10779.                     }
  10780.                 }
  10781.             }
  10782.         }
  10783.         if (argn > 3)                   /* Nonzero 4th arg for no separator */
  10784.           if (chknum(bp[3]))
  10785.             if (atoi(bp[3]) > 0)
  10786.               sep = NULL;
  10787.         if (!sep) {
  10788.             sep = "";
  10789.             seplen = 0;
  10790.         } else
  10791.           seplen = strlen(sep);
  10792.         for (i = lo; i <= hi; i++) {    /* Loop thru selected array elements */
  10793.             s = a_ptr[x][i];            /* Get next element */
  10794.             if (!s)
  10795.               s = "";
  10796.             flag = 0;                   /* Buffer overrun flag */
  10797.             if (grouping) {             /* Does this element need quoting? */
  10798.                 q = s;                  /* Look for spaces */
  10799.                 while ((c = *q++)) { if (c == SP) { flag++; break; } }
  10800.             }
  10801.             y = strlen(s);              /* Get length of this element */
  10802.             if (cx == 0 && grouping)    /* If empty it might need quoting */
  10803.               flag = 1;
  10804.             if (flag) {                 /* Add grouping if needed */
  10805.                 char * s2 = NULL;
  10806.                 y += 2;
  10807.                 if ((q = (char *)malloc(y+1))) {
  10808.                     ckmakmsg(q,y+1,(char *)lb,s,(char *)rb,NULL);
  10809.                     makestr(&s2,q);
  10810.                     free(q);
  10811.                     s = s2;
  10812.                 }
  10813.             }
  10814.             z = 0;                      /* Number of chars copied */
  10815.             flag = 0;                   /* flag is now buffer-overrun flag */
  10816.             if (y > 0)                  /* If this string is not empty */
  10817.               z = ckstrncat(fnval,s,FNVALL); /* copy it. */
  10818.             if (z < y)                  /* Check for buffer overrun. */
  10819.               flag++;
  10820.             if (!flag && *sep && i < hi) { /* If buffer still has room */
  10821.                 z = ckstrncat(fnval,sep,FNVALL); /* copy delimiter */
  10822.                 if (z < seplen)
  10823.                   flag++;
  10824.             }
  10825.             if (flag) {
  10826.                 failed = 1;
  10827.                 if (fndiags)
  10828.                   ckmakmsg(fnval,FNVALL,
  10829.                            "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10830.                 goto fnend;
  10831.             }
  10832.         }
  10833.         goto fnend;
  10834.     }
  10835.     if (cx == FN_SUBST) {               /* \fsubstitute() */
  10836.         CHAR c, * s, * r, * tp[2], buf1[256], buf2[256], buf3[256];
  10837.         int len, i, j, state = 0, lo = 0, hi = 0;
  10838.  
  10839.         failed = 0;
  10840.         p = fnval;                      /* Result pointer */
  10841.         *p = NUL;
  10842.         if (!bp[0])                     /* No target, no result*/
  10843.           goto fnend;
  10844.  
  10845.         len = strlen(bp[0]);            /* Length of source */
  10846.         if (len == 0)
  10847.           goto fnend;
  10848.         if (len > FNVALL) {
  10849.             failed = 1;
  10850.             if (fndiags)
  10851.               ckmakmsg(fnval,FNVALL,
  10852.                        "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10853.             goto fnend;
  10854.         }
  10855.         if (!bp[1]) {
  10856.             ckstrncpy(bp[0],fnval,FNVALL);
  10857.             goto fnend;
  10858.         }
  10859.         tp[0] = buf1;                   /* For s2-s3 interpretation loop */
  10860.         tp[1] = buf2;
  10861.  
  10862.         for (i = 0; i < 256; i++) {     /* Initialize working buffers */
  10863.             buf1[i] = 0;                /* s2 expansion buffer */
  10864.             buf2[i] = 0;                /* s3 expansion buffer */
  10865.             buf3[i] = i;                /* Translation table */
  10866.         }
  10867.         for (i = 0; i < 2; i++) {       /* Interpret s2 and s3 */
  10868.             s = (CHAR *)bp[i+1];        /* Arg pointer */
  10869.             if (!s) s = (CHAR *)"";
  10870.             r = tp[i];                  /* To construct interpreted arg */
  10871.             j = 0;                      /* Output buf pointer */
  10872.             state = 0;                  /* Initial state */
  10873.             while (c = *s++) {          /* Loop thru arg chars */
  10874.                 if (j > 255)            /* Output buf full */
  10875.                   break;
  10876.                 switch (state) {
  10877.                   case 0:               /* Normal state */
  10878.                     switch (c) {
  10879.                       case '\\':        /* Have quote */
  10880.                         state = 1;
  10881.                         break;
  10882.                       case '[':         /* Have range starter */
  10883.                         state = 2;
  10884.                         break;
  10885.                       default:          /* Anything else */
  10886.                         r[j++] = c;
  10887.                         break;
  10888.                     }
  10889.                     continue;
  10890.                   case 1:               /* Quoted char */
  10891.                     r[j++] = c;
  10892.                     state = 0;
  10893.                     continue;
  10894.                   case 2:               /* Range bottom */
  10895.                     lo = c;
  10896.                     state++;
  10897.                     continue;
  10898.                   case 3:               /* Range separater */
  10899.                     if (c != '-') {
  10900.                         failed = 1;
  10901.                         if (fndiags)
  10902.                           ckmakmsg(fnval,FNVALL,
  10903.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  10904.                         goto fnend;
  10905.                     }
  10906.                     state++;
  10907.                     continue;
  10908.                   case 4:               /* Range top */
  10909.                     hi = c;
  10910.                     state++;
  10911.                     continue;
  10912.                   case 5:               /* Range end */
  10913.                     if (c != ']') {
  10914.                         failed = 1;
  10915.                         if (fndiags)
  10916.                           ckmakmsg(fnval,FNVALL,
  10917.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  10918.                         goto fnend;
  10919.                     }
  10920.                     for (k = lo; k <= hi && j < 255; k++) /* Fill in */
  10921.                       r[j++] = k;
  10922.                     lo = 0; hi = 0;     /* Reset */
  10923.                     state = 0;
  10924.                     continue;
  10925.                 }
  10926.             }
  10927.         }
  10928.         for (i = 0; i < 256 && buf1[i]; i++) {  /* Create translation table */
  10929.             k = (unsigned)buf1[i];
  10930.             buf3[k] = buf2[i];
  10931.         }
  10932.         s = (CHAR *)bp[0];              /* Point to source string */
  10933.         for (i = 0; i < len; i++) {     /* Translation loop */
  10934.             k = (unsigned)s[i];         /* Get next char */
  10935.             if (!buf3[k])               /* Remove this char */
  10936.               continue;
  10937.             *p++ = buf3[k];             /* Substitute this char */
  10938.         }
  10939.         *p = NUL;
  10940.         p = fnval;
  10941.         goto fnend;
  10942.     }
  10943.  
  10944. #ifndef NOSEXP
  10945.     if (cx == FN_SEXP) {                /* \fsexpression(arg1) */
  10946.         char * p2;
  10947.         fsexpflag++;
  10948.         p = (argn > 0) ? dosexp(bp[0]) : "";
  10949.         fsexpflag--;
  10950.         p2 = fnval;
  10951.         while ((*p2++ = *p++)) ;
  10952.         p = fnval;
  10953.         goto fnend;
  10954.     }
  10955. #endif /* NOSEXP */
  10956.  
  10957.     if (cx == FN_CMDSTK) {              /* \fcmdstack(n1,n2) */
  10958.         int i, j, k;
  10959.         char * s;
  10960.  
  10961.         if (bp[0])
  10962.           val1 = *(bp[0]) ? evalx(bp[0]) : ckitoa(cmdlvl);
  10963.         else
  10964.           val1 = ckitoa(cmdlvl);
  10965. #ifdef COMMENT
  10966.         free(bp[0]);                    /* (evalx() always uses same buffer) */
  10967.         bp[0] = NULL;                   /* (not any more!) */
  10968. #endif /* COMMENT */
  10969.         failed = 1;
  10970.         if (argn > 1) {
  10971. #ifdef COMMENT
  10972.             makestr(&(bp[0]),val1);
  10973.             val1 = bp[0];
  10974. #endif /* COMMENT */
  10975.             val2 = *(bp[1]) ? evalx(bp[1]) : "0";
  10976.             if (!(chknum(val1) && chknum(val2))) {
  10977.                 if (fndiags)
  10978.                   ckmakmsg(fnval,FNVALL,
  10979.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10980.                 goto fnend;
  10981.             }
  10982.         } else {
  10983.             val1 = ckitoa(cmdlvl);
  10984.             val2 = "0";
  10985.         }
  10986.         i = atoi(val1);                 /* Level */
  10987.         j = atoi(val2);                 /* Flags */
  10988.         if (i < 0 || i > cmdlvl) {
  10989.             if (fndiags)
  10990.               ckmakmsg(fnval,FNVALL,
  10991.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10992.             goto fnend;
  10993.         }
  10994.         failed = 0;
  10995.         p = fnval;
  10996.         k = cmdstk[i].src;              /* What (prompt, file, macro) */
  10997.         if (j) {
  10998.             ckstrncpy(fnval,ckitoa(k),FNVALL);
  10999.             goto fnend;
  11000.         }
  11001.         switch (k) {
  11002.           case CMD_KB:
  11003.             ckstrncpy(fnval,"(prompt)",FNVALL);
  11004.             break;
  11005.           case CMD_TF:
  11006.             s = tfnam[cmdstk[i].lvl];
  11007.             if (!zfnqfp(s,FNVALL,fnval))
  11008.               ckstrncpy(fnval,s,FNVALL);
  11009.             break;
  11010.           case CMD_MD:
  11011.             ckstrncpy(fnval,m_arg[cmdstk[i].lvl][0],FNVALL);
  11012.             break;
  11013.         }
  11014.         goto fnend;
  11015.     }
  11016. #ifdef CKFLOAT
  11017.     if (cx == FN_DIFDATE) {             /* \fdiffdates(d1,d2) */
  11018.         char * d1, * d2;
  11019.         d1 = bp[0] ? bp[0] : ckdate();
  11020.         d2 = bp[1] ? bp[1] : ckdate();
  11021.         p = (char *)cmdiffdate(d1,d2);
  11022.         if (!p) {
  11023.             failed = 1;
  11024.             if (fndiags) {
  11025.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11026.                 p = fnval;
  11027.             }
  11028.         }
  11029.         goto fnend;
  11030.     }
  11031. #endif /* CKFLOAT */
  11032.     if (cx == FN_CMPDATE) {             /* \fcmddates(d1,d2) */
  11033.         int x = 0;
  11034.         char d1[18], d2[18], * dp;
  11035.         failed = 0;
  11036.         d1[0] = NUL;
  11037.         d2[0] = NUL;
  11038.         p = fnval;
  11039.         dp = cmcvtdate(bp[0],1);
  11040.         if (dp) {
  11041.             ckstrncpy(d1,dp,18);
  11042.             if ((dp = cmcvtdate(bp[1],1))) {
  11043.                 ckstrncpy(d2,dp,18);
  11044.                 x = 1;
  11045.             }
  11046.         }
  11047.         if (x == 0) {
  11048.             failed = 1;
  11049.             if (fndiags)
  11050.               ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11051.         } else {
  11052.             x = strcmp(d1,d2);
  11053.             if (x > 0)
  11054.               x = 1;
  11055.             else if (x < 0)
  11056.               x = -1;
  11057.             sprintf(fnval,"%d",x);
  11058.         }
  11059.         goto fnend;
  11060.     }
  11061.     if (cx == FN_TOGMT) {               /* \futcdate(d1) */
  11062.         char * d1, * dp;
  11063.         char datebuf[32];
  11064.         char d2[32];
  11065.         p = fnval;
  11066.         failed = 1;
  11067.         if ((dp = cmcvtdate(bp[0],1))) { /* The given date */
  11068.             ckstrncpy(datebuf,dp,18);
  11069.             ckstrncpy(d2,dp,18);        /* local time */
  11070.             ckstrncat(datebuf,"Z",19);  /* Same time GMT */
  11071.             if ((dp = cmcvtdate(datebuf,1))) /* converted to local time */
  11072.               ckstrncpy(datebuf,dp,18);
  11073.             if ((p = (char *)cmdiffdate(d2,datebuf))) { /* Get offset */
  11074.                 ckstrncat(d2,p,32);     /* Append offset to local time */
  11075.                 if ((dp = cmcvtdate(d2,1))) {
  11076.                     failed = 0;
  11077.                     ckstrncpy(fnval,dp,FNVALL);
  11078.                     p = fnval;
  11079.                 }
  11080.             }
  11081.         }
  11082.         if (failed && fndiags)
  11083.           ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11084.         goto fnend;
  11085.     }
  11086.     if (cx == FN_DELSEC) {              /* \fdelta2secs(delta-time) */
  11087.         long secs;
  11088.         p = fnval;
  11089.         if ((x = delta2sec(bp[0],&secs)) < 0) {
  11090.             failed = 1;
  11091.             if (fndiags)
  11092.               ckmakmsg(fnval,FNVALL,
  11093.                        (x == -1) ?
  11094.                          "<ERROR:BAD_DELTA_TIME:\\f" :
  11095.                          "<ERROR:OVERFLOW:\\f",
  11096.                        fn,
  11097.                        "()>",
  11098.                        NULL
  11099.                        );
  11100.             goto fnend;
  11101.         }
  11102.         sprintf(p,"%ld",secs);
  11103.         goto fnend;
  11104.     }
  11105.     if (cx == FN_PC_DU) {
  11106.         char c, * s = bp[0];
  11107.         if (!s) s = "";
  11108.         p = fnval;
  11109.         while ((c = *s++)) {
  11110.             if (c == ':') {
  11111.                 if (*s != '\\')
  11112.                   *p++ = '/';
  11113.             } else if (c == '\\') {
  11114.                 *p++ = '/';
  11115.             } else {
  11116.                 *p++ = c;
  11117.             }
  11118.         }
  11119.         *p = NUL;
  11120.         p = fnval;
  11121.         goto fnend;
  11122.     }
  11123.     if (cx == FN_PC_UD) {               /* Unix to DOS path */
  11124.         char c, * s = bp[0];
  11125.         if (!s) s = "";
  11126.         if (*s == '~') {                /* Skip leading tilde */
  11127.             s++;
  11128.             if (*s == '/')
  11129.               s++;
  11130.         }
  11131.         p = fnval;
  11132.         while ((c = *s++))
  11133.           *p ++ = (c == '/') ? '\\' : c;
  11134.         *p = NUL;
  11135.         p = fnval;
  11136.         goto fnend;
  11137.     }
  11138.     if (cx == FN_KWVAL) {               /* Keyword=Value */
  11139.         p = dokwval(bp[0],bp[1]?*(bp[1]):'=');
  11140.         goto fnend;
  11141.     }
  11142. #ifdef COMMENT
  11143. /* Cute idea but doesn't work */
  11144.     if (cx == FN_SLEEP || cx == FN_MSLEEP) {
  11145.         p = "";
  11146.         if (chknum(bp[0])) {
  11147.             x = atoi(bp[0]);
  11148.         } else {
  11149.             failed = 1;
  11150.             if (fndiags) {
  11151.                 ckmakmsg(fnval,FNVALL,
  11152.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11153.                 p = fnval;
  11154.             }
  11155.             goto fnend;
  11156.         }
  11157.         if (cx == FN_SLEEP)
  11158.           x *= 1000;
  11159.         msleep(x);
  11160.         goto fnend;
  11161.     }
  11162. #endif /* COMMENT */
  11163.  
  11164. #ifdef NT
  11165.     if (cx == FN_SNAME) {
  11166.         GetShortPathName(bp[0],fnval,FNVALL);
  11167.         goto fnend;
  11168.     }
  11169.     if (cx == FN_LNAME) {
  11170.         ckGetLongPathName(bp[0],fnval,FNVALL);
  11171.         goto fnend;
  11172.     }
  11173. #endif /* NT */
  11174.  
  11175. /* Note: when adding new functions remember to update dohfunc in ckuus2.c. */
  11176.  
  11177.     failed = 1;
  11178.     if (fndiags)
  11179.       ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN_FUNCTION:\\f",fn,"()>",NULL);
  11180.  
  11181.   fnend:
  11182.     /* Free temporary storage for aguments */
  11183.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  11184.     fndepth--;
  11185.     if (failed) {                       /* Handle failure */
  11186.         debug(F111,"fnend",fnval,errno);
  11187.         if (!p) p = "";
  11188.         if (p[0]) {
  11189.             /* In case this wasn't caught above... */
  11190.             k = strlen(p);
  11191.             if (p[0] != '<' && p[k-1] != '>') {
  11192.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_ARG:\\f",fn,"()>",NULL);
  11193.                 p = fnval;
  11194.             }
  11195.         } else {
  11196.             ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN:\\f",fn,"()>",NULL);
  11197.             p = fnval;
  11198.         }
  11199.         if (fnerror)                    /* SET FUNCTION ERROR ON */
  11200.           fnsuccess = 0;                /* Make command fail (see ckuus5.c) */
  11201.         debug(F111,"fneval failed",p,fnsuccess);
  11202.         if (fndiags)                    /* SET FUNCTION DIAGNOSTICS ON */
  11203.           printf("?%s\n",p);            /* Print error message now. */
  11204.         else
  11205.           return("");                   /* Return nothing. */
  11206.     }
  11207.     return(p);
  11208. }
  11209. #endif /* NOSPL */
  11210.  
  11211. static char ckpidbuf[32] = "????";
  11212.  
  11213. #ifdef VMS
  11214. _PROTOTYP(long zgpid,(void));
  11215. #endif /* VMS */
  11216.  
  11217. char *
  11218. ckgetpid() {                            /* Return pid as string */
  11219. #ifdef CK_PID
  11220. #ifdef OS2
  11221. #define getpid _getpid
  11222.     unsigned long zz;
  11223. #else
  11224.     long zz;
  11225. #endif /* OS2 */
  11226. #ifdef VMS
  11227.     zz = zgpid();
  11228. #else
  11229.     zz = getpid();
  11230. #endif /* VMS */
  11231.     sprintf(ckpidbuf,"%ld",zz);         /* SAFE */
  11232. #endif /* CK_PID */
  11233.     return((char *)ckpidbuf);
  11234. }
  11235.  
  11236. #ifndef NOSPL
  11237. #define EMBUFLEN 128                    /* Error message buffer length */
  11238.  
  11239. static char embuf[EMBUFLEN+1];
  11240.  
  11241. char *                                  /* Evaluate builtin variable */
  11242. nvlook(s) char *s; {
  11243.     int x, y, cx;
  11244.     long z;
  11245.     char *p;
  11246. #ifndef NODIAL
  11247.     MDMINF * m;
  11248. #endif /* NODIAL */
  11249. #ifndef NOKVERBS                        /* Keyboard macro material */
  11250.     extern int keymac, keymacx;
  11251. #endif /* NOKVERBS */
  11252. #ifdef CK_LOGIN
  11253.     extern int isguest;
  11254. #endif /* CK_LOGIN */
  11255.     if (!s) s = "";
  11256.     x = strlen(s);
  11257.     if (fndiags) {                      /* FUNCTION DIAGNOSTIC ON */
  11258.         if (x + 32 < EMBUFLEN)
  11259.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE:\\v(%s)>",s); /* SAFE */
  11260.         else
  11261.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE>"); /* SAFE */
  11262.     } else                              /* FUNCTION DIAGNOSTIC OFF */
  11263.       embuf[0] = NUL;
  11264.     x = VVBUFL;
  11265.     p = vvbuf;
  11266.     if (zzstring(s,&p,&x) < 0) {        /* e.g. for \v(\%a) */
  11267.         y = -1;
  11268.     } else {
  11269.         s = vvbuf;
  11270.         y = lookup(vartab,s,nvars,&x);
  11271.     }
  11272.     cx = y;                             /* y is too generic */
  11273. #ifndef NODIAL
  11274.     m = (mdmtyp > 0) ? modemp[mdmtyp] : NULL; /* For \v(m_xxx) variables */
  11275. #endif /* NODIAL */
  11276.  
  11277.     debug(F101,"nvlook y","",y);
  11278.  
  11279.     switch (y) {
  11280.       case VN_ARGC:                     /* ARGC */
  11281.         sprintf(vvbuf,"%d",maclvl < 0 ? topargc : macargc[maclvl]); /* SAFE */
  11282.         return(vvbuf);
  11283.  
  11284.       case VN_ARGS:                     /* ARGS */
  11285.         sprintf(vvbuf,"%d",xargs);      /* SAFE */
  11286.         return(vvbuf);
  11287.  
  11288.       case VN_COUN:                     /* COUNT */
  11289.         sprintf(vvbuf,"%d",count[cmdlvl]); /* SAFE */
  11290.         return(vvbuf);
  11291.  
  11292.       case VN_DATE:                     /* DATE */
  11293.         ztime(&p);                      /* Get "asctime" string */
  11294.         if (p == NULL || *p == NUL) return(NULL);
  11295.         vvbuf[0] = p[8];                /* dd */
  11296.         vvbuf[1] = p[9];
  11297.         vvbuf[2] = SP;
  11298.         vvbuf[3] = p[4];                /* mmm */
  11299.         vvbuf[4] = p[5];
  11300.         vvbuf[5] = p[6];
  11301.         vvbuf[6] = SP;
  11302.         for (x = 20; x < 24; x++)       /* yyyy */
  11303.           vvbuf[x - 13] = p[x];
  11304.         vvbuf[11] = NUL;
  11305.         return(vvbuf);
  11306.  
  11307.       case VN_NDAT:                     /* Numeric date */
  11308.         ckstrncpy(vvbuf,zzndate(),VVBUFL);
  11309.         return(vvbuf);
  11310.  
  11311.       case VN_DIRE:                     /* DIRECTORY */
  11312.         s = zgtdir();                   /* Get current directory */
  11313.         if (!s)
  11314. #ifdef UNIXOROSK
  11315.           s = "./";
  11316. #else
  11317. #ifdef VMS
  11318.           s = "[]";
  11319. #else
  11320.           s = "";
  11321. #endif /* VMS */
  11322. #endif /* UNIXOROSK */
  11323.         ckstrncpy(vvbuf,s,VVBUFL);
  11324.         s = vvbuf;
  11325. #ifdef UNIXOROSK
  11326.         x = strlen(s);
  11327.         if (x < VVBUFL - 1) {
  11328.             if (s[x-1] != '/') {
  11329.                 s[x] = '/';
  11330.                 s[x+1] = NUL;
  11331.             }
  11332.         }
  11333. #endif /* UNIXOROSK */
  11334.         return(s);
  11335.  
  11336.       case VN_FILE:                     /* filespec */
  11337.         return(fspec);
  11338.  
  11339.       case VN_HOST:                     /* host name */
  11340.         if (*myhost) {                  /* If known */
  11341.             return(myhost);             /* return it. */
  11342.         } else {                        /* Otherwise */
  11343.             ckstrncpy(vvbuf,"unknown",VVBUFL); /* just say "unknown" */
  11344.             return(vvbuf);
  11345.         }
  11346.  
  11347.       case VN_SYST:                     /* System type */
  11348. #ifdef UNIX
  11349.         ckstrncpy(vvbuf,"UNIX",VVBUFL);
  11350. #else
  11351. #ifdef VMS
  11352.         ckstrncpy(vvbuf,"VMS",VVBUFL);
  11353. #else
  11354. #ifdef OSK
  11355.         ckstrncpy(vvbuf,"OS9/68K",VVBUFL);
  11356. #else
  11357. #ifdef AMIGA
  11358.         ckstrncpy(vvbuf,"Amiga",VVBUFL);
  11359. #else
  11360. #ifdef MAC
  11361.         ckstrncpy(vvbuf,"Macintosh",VVBUFL);
  11362. #else
  11363. #ifdef OS2
  11364. #ifdef NT
  11365.         ckstrncpy(vvbuf,"WIN32",VVBUFL) ;
  11366. #else /* NT */
  11367.         ckstrncpy(vvbuf,"OS/2",VVBUFL);
  11368. #endif /* NT */
  11369. #else
  11370. #ifdef datageneral
  11371.         ckstrncpy(vvbuf,"AOS/VS",VVBUFL);
  11372. #else
  11373. #ifdef GEMDOS
  11374.         ckstrncpy(vvbuf,"Atari_ST",VVBUFL);
  11375. #else
  11376. #ifdef STRATUS
  11377.         ckstrncpy(vvbuf,"Stratus_VOS",VVBUFL);
  11378. #else
  11379.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11380. #endif /* STRATUS */
  11381. #endif /* GEMDOS */
  11382. #endif /* datageneral */
  11383. #endif /* OS2 */
  11384. #endif /* MAC */
  11385. #endif /* AMIGA */
  11386. #endif /* OSK */
  11387. #endif /* VMS */
  11388. #endif /* UNIX */
  11389.         return(vvbuf);
  11390.  
  11391.       case VN_SYSV:                     /* System herald */
  11392. #ifdef IKSD
  11393. #ifdef CK_LOGIN
  11394.         if (inserver && isguest)
  11395.           return("");
  11396. #endif /* CK_LOGIN */
  11397. #endif /* IKSD */
  11398.         for (x = y = 0; x < VVBUFL; x++) {
  11399.             if (ckxsys[x] == SP && y == 0) continue;
  11400.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  11401.         }
  11402.         vvbuf[y] = NUL;
  11403.         return(vvbuf);
  11404.     } /* Break up long switch statements... */
  11405.  
  11406.     switch(y) {
  11407.       case VN_TIME:                     /* TIME. Assumes that ztime returns */
  11408.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11409.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11410.           return("");
  11411.         for (x = 11; x < 19; x++)       /* copy hh:mm:ss */
  11412.           vvbuf[x - 11] = p[x];         /* to vvbuf */
  11413.         vvbuf[8] = NUL;                 /* terminate */
  11414.         return(vvbuf);                  /* and return it */
  11415.  
  11416.       case VN_NTIM:                     /* Numeric time */
  11417.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11418.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11419.           return(NULL);
  11420.         z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  11421.         sprintf(vvbuf,"%ld",z);         /* SAFE */
  11422.         return(vvbuf);
  11423.  
  11424. #ifdef CK_TTYFD
  11425.       case VN_TTYF:                     /* TTY file descriptor */
  11426.         sprintf(vvbuf,"%d",             /* SAFE */
  11427. #ifdef VMS
  11428.                 vmsttyfd()
  11429. #else
  11430.                 ttyfd
  11431. #endif /* VMS */
  11432.                 );
  11433.         return(vvbuf);
  11434. #endif /* CK_TTYFD */
  11435.  
  11436.       case VN_VERS:                     /* Numeric Kermit version number */
  11437.         sprintf(vvbuf,"%ld",vernum);    /* SAFE */
  11438.         return(vvbuf);
  11439.  
  11440.       case VN_XVNUM:                    /* Product-specific version number */
  11441.         sprintf(vvbuf,"%ld",xvernum);   /* SAFE */
  11442.         return(vvbuf);
  11443.  
  11444.       case VN_HOME:                     /* Home directory */
  11445.         return(homepath());
  11446.  
  11447.       case VN_IBUF:                     /* INPUT buffer */
  11448.         return((char *)inpbuf);
  11449.  
  11450.       case VN_ICHR:                     /* INPUT character */
  11451.         inchar[1] = NUL;
  11452.         return((char *)inchar);
  11453.  
  11454.       case VN_ICNT:                     /* INPUT character count */
  11455.         sprintf(vvbuf,"%d",incount);    /* SAFE */
  11456.         return(vvbuf);
  11457.  
  11458.       case VN_SPEE: {                   /* Transmission SPEED */
  11459.           long t;
  11460.           t = ttgspd();
  11461.           if (t < 0L)
  11462.             sprintf(vvbuf,"unknown");   /* SAFE */
  11463.           else
  11464.             sprintf(vvbuf,"%ld",t);     /* SAFE */
  11465.           return(vvbuf);
  11466.       }
  11467.  
  11468.       case VN_SUCC:                     /* SUCCESS flag */
  11469.         /* Note inverted sense */
  11470.         sprintf(vvbuf,"%d",(success == 0) ? 1 : 0); /* SAFE */
  11471.         return(vvbuf);
  11472.  
  11473.       case VN_LINE: {                   /* LINE */
  11474. #ifdef DEBUG
  11475.           if (deblog) {
  11476.               debug(F111,"\\v(line) local",ttname,local);
  11477.               debug(F111,"\\v(line) inserver","",inserver);
  11478. #ifdef TNCODE
  11479.               debug(F111,"\\v(line) tcp_incoming","",tcp_incoming);
  11480. #endif /* TNCODE */
  11481. #ifdef CK_TAPI
  11482.               debug(F111,"\\v(line) tttapi","",tttapi);
  11483. #endif /* CK_TAPI */
  11484.           }
  11485. #endif /* DEBUG */
  11486.  
  11487. #ifdef CK_TAPI
  11488.           if (tttapi) {                 /* If I have made a TAPI connection */
  11489.               int i;                    /* return the TAPI device name */
  11490.               for (i = 0; i < ntapiline; i++) {
  11491.                   if (!strcmp(ttname,tapilinetab[i].kwd)) {
  11492.                       p = _tapilinetab[i].kwd;
  11493.                       return(p);
  11494.                   }
  11495.               }
  11496.           }
  11497. #endif /* CK_TAPI */
  11498. #ifndef NOXFER
  11499.           if (inserver                  /* If I am a TCP server */
  11500. #ifdef TNCODE
  11501.               || tcp_incoming
  11502. #endif /* TNCODE */
  11503.               )
  11504. #ifdef TCPSOCKET
  11505.             p = ckgetpeer();            /* return peer name */
  11506.           else
  11507. #endif /* TCPSOCKET */
  11508. #endif /* NOXFER */
  11509.           if (local)                    /* Otherwise if in local mode */
  11510.             p = (char *) ttname;        /* return SET LINE / SET HOST name */
  11511.           else                          /* Otherwise */
  11512.             p = "";                     /* return empty string */
  11513.           if (!p)                       /* In case ckgetpeer() returns */
  11514.             p = "";                     /* null pointer... */
  11515.           debug(F110,"\\v(line) p",p,0);
  11516.           if (!*p)
  11517.             p = (char *) ttname;
  11518.           return(p);
  11519.       }
  11520.       case VN_PROG:                     /* Program name */
  11521.         return("C-Kermit");
  11522.  
  11523.     } /* Break up long switch statements... */
  11524.  
  11525.     switch(y) {
  11526.       case VN_RET:                      /* Value of most recent RETURN */
  11527.         debug(F111,"\\v(return)",mrval[maclvl+1],maclvl+1);
  11528.         p = mrval[maclvl+1];
  11529.         if (p == NULL) p = "";
  11530.         return(p);
  11531.  
  11532.       case VN_FFC:                      /* Size of most recent file */
  11533.         sprintf(vvbuf, "%ld", ffc);     /* SAFE */
  11534.         return(vvbuf);
  11535.  
  11536.       case VN_TFC:                      /* Size of most recent file group */
  11537.         sprintf(vvbuf, "%ld", tfc);     /* SAFE */
  11538.         return(vvbuf);
  11539.  
  11540.       case VN_CPU:                      /* CPU type */
  11541. #ifdef IKSD
  11542. #ifdef CK_LOGIN
  11543.         if (inserver && isguest)
  11544.           return("");
  11545. #endif /* CK_LOGIN */
  11546. #endif /* IKSD */
  11547. #ifdef OS2
  11548.          {
  11549.             char * getcpu(void) ;
  11550.             return getcpu();
  11551.          }
  11552. #else /* OS2 */
  11553. #ifdef CKCPU
  11554.         return(CKCPU);                  /* Traditionally, compile-time value */
  11555. #else
  11556. #ifdef CK_UTSNAME
  11557.         {                               /* But if none, try runtime value */
  11558.             extern char unm_mch[];
  11559.             return((char *)unm_mch);
  11560.         }
  11561. #else
  11562.         return("unknown");
  11563. #endif /* CK_UTSNAME */
  11564. #endif /* CKCPU */
  11565. #endif /* OS2 */
  11566.  
  11567.       case VN_CMDL:                     /* Command level */
  11568.         sprintf(vvbuf, "%d", cmdlvl);   /* SAFE */
  11569.         return(vvbuf);
  11570.  
  11571.       case VN_DAY:                      /* Day of week */
  11572.         ztime(&p);
  11573.         if (p != NULL && *p != NUL)     /* ztime() succeeded. */
  11574.           ckstrncpy(vvbuf,p,4);
  11575.         else
  11576.           vvbuf[0] = NUL;               /* ztime() failed. */
  11577.         return(vvbuf);                  /* Return what we got. */
  11578.  
  11579.       case VN_NDAY: {                   /* Numeric day of week */
  11580.           long k;
  11581.           z = mjd(zzndate());           /* Get modified Julian date */
  11582.           k = (((int)(z % 7L)) + 3) % 7; /* Get day number */
  11583.           sprintf(vvbuf,"%ld",k);       /* SAFE */
  11584.           return(vvbuf);
  11585.       }
  11586.  
  11587.       case VN_LCL:                      /* Local (vs remote) mode */
  11588.         ckstrncpy(vvbuf, local ? "1" : "0",VVBUFL);
  11589.         return(vvbuf);
  11590.  
  11591.       case VN_CMDS:                     /* Command source */
  11592.         if (cmdstk[cmdlvl].src == CMD_KB)
  11593.           ckstrncpy(vvbuf,"prompt",VVBUFL);
  11594.         else if (cmdstk[cmdlvl].src == CMD_MD)
  11595.           ckstrncpy(vvbuf,"macro",VVBUFL);
  11596.         else if (cmdstk[cmdlvl].src == CMD_TF)
  11597.           ckstrncpy(vvbuf,"file",VVBUFL);
  11598.         else
  11599.           ckstrncpy(vvbuf,"unknown",VVBUFL);
  11600.         return(vvbuf);
  11601.  
  11602.       case VN_CMDF:                     /* Current command file name */
  11603. #ifdef COMMENT                          /* (see comments above) */
  11604.         if (tfnam[tlevel]) {            /* (near dblbs declaration) */
  11605.             dblbs(tfnam[tlevel],vvbuf,VVBUFL);
  11606.             return(vvbuf);
  11607.         } else return("");
  11608. #else
  11609.         if (tlevel < 0)
  11610.           return("");
  11611.         else
  11612.           return(tfnam[tlevel] ? tfnam[tlevel] : "");
  11613. #endif /* COMMENT */
  11614.  
  11615.       case VN_MAC:                      /* Current macro name */
  11616.         return((maclvl > -1) ? m_arg[maclvl][0] : "");
  11617.  
  11618.       case VN_EXIT:
  11619.         sprintf(vvbuf,"%d",xitsta);     /* SAFE */
  11620.         return(vvbuf);
  11621.  
  11622.     } /* Break up long switch statements... */
  11623.  
  11624.     switch(y) {
  11625.       case VN_PRTY: {                   /* Parity */
  11626.           char *ss;
  11627.           switch (parity) {
  11628.             case 0:   ss = "none";  break;
  11629.             case 'e': ss = "even";  break;
  11630.             case 'm': ss = "mark";  break;
  11631.             case 'o': ss = "odd";   break;
  11632.             case 's': ss = "space"; break;
  11633.             default:  ss = "unknown"; break;
  11634.           }
  11635.           ckstrncpy(vvbuf,ss,VVBUFL);
  11636.           return(vvbuf);
  11637.       }
  11638.  
  11639.       case VN_DIAL:
  11640.         sprintf(vvbuf,"%d",             /* SAFE */
  11641. #ifndef NODIAL
  11642.                 dialsta
  11643. #else
  11644.                 -1
  11645. #endif /* NODIAL */
  11646.                 );
  11647.         return(vvbuf);
  11648.  
  11649. #ifdef OS2
  11650.       case VN_KEYB:
  11651.         ckstrncpy(vvbuf,conkbg(),VVBUFL);
  11652.         return(vvbuf);
  11653.       case VN_SELCT: {
  11654. #ifndef NOLOCAL
  11655.           const char * selection = GetSelection();
  11656.           return( (char *) (selection ? selection : "" )) ;
  11657. #else
  11658.           return("");
  11659. #endif /* NOLOCAL */
  11660.       }
  11661. #endif /* OS2 */
  11662.  
  11663. #ifndef NOXFER
  11664.       case VN_CPS:
  11665.         sprintf(vvbuf,"%ld",tfcps);     /* SAFE */
  11666.         return(vvbuf);
  11667. #endif /* NOXFER */
  11668.  
  11669.       case VN_MODE:                     /* File transfer mode */
  11670.         switch (binary) {
  11671.           case XYFT_T: ckstrncpy(vvbuf,"text",VVBUFL); break;
  11672.           case XYFT_B:
  11673.           case XYFT_U: ckstrncpy(vvbuf,"binary",VVBUFL); break;
  11674.           case XYFT_I: ckstrncpy(vvbuf,"image",VVBUFL); break;
  11675.           case XYFT_L: ckstrncpy(vvbuf,"labeled",VVBUFL); break;
  11676.           case XYFT_M: ckstrncpy(vvbuf,"macbinary",VVBUFL); break;
  11677.           default:     ckstrncpy(vvbuf,"unknown",VVBUFL);
  11678.         }
  11679.         return(vvbuf);
  11680.  
  11681. #ifdef CK_REXX
  11682.       case VN_REXX:
  11683.         return(rexxbuf);
  11684. #endif /* CK_REXX */
  11685.  
  11686.       case VN_NEWL:                     /* System newline char or sequence */
  11687. #ifdef UNIX
  11688.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11689. #else
  11690. #ifdef datageneral
  11691.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11692. #else
  11693. #ifdef OSK
  11694.         ckstrncpy(vvbuf,"\15",VVBUFL);  /* Remember, these are octal... */
  11695. #else
  11696. #ifdef MAC
  11697.         ckstrncpy(vvbuf,"\15",VVBUFL);
  11698. #else
  11699. #ifdef OS2
  11700.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11701. #else
  11702. #ifdef STRATUS
  11703.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11704. #else
  11705. #ifdef VMS
  11706.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11707. #else
  11708. #ifdef AMIGA
  11709.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11710. #else
  11711. #ifdef GEMDOS
  11712.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11713. #else
  11714.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11715. #endif /* GEMDOS */
  11716. #endif /* AMIGA */
  11717. #endif /* VMS */
  11718. #endif /* STRATUS */
  11719. #endif /* OS2 */
  11720. #endif /* MAC */
  11721. #endif /* OSK */
  11722. #endif /* datageneral */
  11723. #endif /* UNIX */
  11724.         return(vvbuf);
  11725.  
  11726.       case VN_ROWS:                     /* ROWS */
  11727.       case VN_COLS:                     /* COLS */
  11728.         ckstrncpy(vvbuf,(cx == VN_ROWS) ? "24" : "80",VVBUFL); /* Default */
  11729. #ifdef CK_TTGWSIZ
  11730. #ifdef OS2
  11731.         if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  11732.           ttgwsiz();
  11733.         sprintf(vvbuf,"%d",             /* SAFE */
  11734.                 (cx == VN_ROWS) ? tt_rows[VTERM] : tt_cols[VTERM]);
  11735. #else /* OS2 */
  11736.         if (ttgwsiz() > 0)              /* Get window size */
  11737.           if (tt_cols > 0 && tt_rows > 0) /* sets tt_rows, tt_cols */
  11738.             sprintf(vvbuf,"%d",         /* SAFE */
  11739.                     (cx == VN_ROWS) ? tt_rows : tt_cols);
  11740. #endif /* OS2 */
  11741. #endif /* CK_TTGWSIZ */
  11742.         return(vvbuf);
  11743.  
  11744.       case VN_TTYP:
  11745. #ifdef NOTERM
  11746.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11747. #else
  11748. #ifdef OS2
  11749.         sprintf(vvbuf, "%s",            /* SAFE */
  11750.                 (tt_type >= 0 && tt_type <= max_tt) ?
  11751.                 tt_info[tt_type].x_name :
  11752.                 "unknown"
  11753.                 );
  11754. #else
  11755. #ifdef MAC
  11756.         ckstrncpy(vvbuf,"vt320",VVBUFL);
  11757. #else
  11758.         p = getenv("TERM");
  11759.         ckstrncpy(vvbuf,p ? p : "unknown",VVBUFL+1);
  11760. #endif /* MAC */
  11761. #endif /* OS2 */
  11762. #endif /* NOTERM */
  11763.         return(vvbuf);
  11764.  
  11765.       case VN_MINP:                     /* MINPUT */
  11766.         sprintf(vvbuf, "%d", m_found);  /* SAFE */
  11767.         return(vvbuf);
  11768.     } /* Break up long switch statements... */
  11769.  
  11770.     switch(y) {
  11771.       case VN_CONN:                     /* CONNECTION */
  11772.         if (!local) {
  11773.           ckstrncpy(vvbuf,"remote",VVBUFL);
  11774.         } else {
  11775.             if (!network)
  11776.               ckstrncpy(vvbuf,"serial",VVBUFL);
  11777. #ifdef TCPSOCKET
  11778.             else if (nettype == NET_TCPB || nettype == NET_TCPA) {
  11779.                 if (ttnproto == NP_TELNET)
  11780.                   ckstrncpy(vvbuf,"tcp/ip_telnet",VVBUFL);
  11781. #ifdef CK_SSL
  11782.                 else if (ttnproto == NP_SSL)
  11783.                   ckstrncpy(vvbuf,"tcp/ip_ssl",VVBUFL);
  11784.                 else if (ttnproto == NP_TLS)
  11785.                   ckstrncpy(vvbuf,"tcp/ip_tls",VVBUFL);
  11786. #endif /* CK_SSL */
  11787.                 else
  11788.                   ckstrncpy(vvbuf,"tcp/ip",VVBUFL);
  11789.             }
  11790. #endif /* TCPSOCKET */
  11791. #ifdef SSHBUILTIN
  11792.             else if (nettype == NET_SSH)
  11793.                   ckstrncpy(vvbuf,"tcp/ip_ssh",VVBUFL);
  11794. #endif /* SSHBUILTIN */
  11795. #ifdef ANYX25
  11796.             else if (nettype == NET_SX25 ||
  11797.                      nettype == NET_VX25 ||
  11798.                      nettype == NET_IX25
  11799.                      )
  11800.               ckstrncpy(vvbuf,"x.25",VVBUFL);
  11801. #endif /* ANYX25 */
  11802. #ifdef DECNET
  11803.             else if (nettype == NET_DEC) {
  11804.                 if (ttnproto == NP_LAT)
  11805.                   ckstrncpy(vvbuf,"decnet_lat",VVBUFL);
  11806.                 else if ( ttnproto == NP_CTERM )
  11807.                   ckstrncpy(vvbuf,"decnet_cterm",VVBUFL);
  11808.                 else
  11809.                   ckstrncpy(vvbuf,"decnet",VVBUFL);
  11810.             }
  11811. #endif /* DECNET */
  11812. #ifdef SUPERLAT
  11813.             else if (nettype == NET_SLAT)
  11814.               ckstrncpy(vvbuf,"superlat",VVBUFL);
  11815. #endif /* SUPERLAT */
  11816. #ifdef NETFILE
  11817.             else if (nettype == NET_FILE)
  11818.               ckstrncpy(vvbuf,"local_file",VVBUFL);
  11819. #endif /* NETFILE */
  11820. #ifdef NETCMD
  11821.             else if (nettype == NET_CMD)
  11822.               ckstrncpy(vvbuf,"pipe",VVBUFL);
  11823. #endif /* NETCMD */
  11824. #ifdef NETPTY
  11825.             else if (nettype == NET_PTY)
  11826.               ckstrncpy(vvbuf,"pseudoterminal",VVBUFL);
  11827. #endif /* NETPTY */
  11828. #ifdef NETDLL
  11829.             else if (nettype == NET_DLL)
  11830.               ckstrncpy(vvbuf,"dynamic_link_library",VVBUFL);
  11831. #endif /* NETDLL */
  11832.  
  11833. #ifdef NPIPE
  11834.             else if (nettype == NET_PIPE)
  11835.               ckstrncpy(vvbuf,"named_pipe",VVBUFL);
  11836. #endif /* NPIPE */
  11837. #ifdef CK_NETBIOS
  11838.             else if (nettype == NET_BIOS)
  11839.               ckstrncpy(vvbuf,"netbios",VVBUFL);
  11840. #endif /* CK_NETBIOS */
  11841.             else
  11842.               ckstrncpy(vvbuf,"unknown",VVBUFL);
  11843.         }
  11844.         return(vvbuf);
  11845.  
  11846. #ifndef NOXFER
  11847.       case VN_SYSI:                     /* System ID, Kermit code */
  11848.         return((char *)cksysid);
  11849. #endif /* NOXFER */
  11850.  
  11851. #ifdef OS2
  11852.       case VN_SPA: {
  11853.           unsigned long space = zdskspace(0);
  11854.           if (space > 0 && space < 1024)
  11855.             sprintf(vvbuf,"-1");
  11856.           else
  11857.             sprintf(vvbuf,"%lu",space); /* SAFE */
  11858.           return(vvbuf);
  11859.       }
  11860. #endif /* OS2 */
  11861.  
  11862. #ifndef NOXFER
  11863.       case VN_QUE: {
  11864.           extern char querybuf[];
  11865.           return(querybuf);
  11866.       }
  11867. #endif /* NOXFER */
  11868.  
  11869. #ifndef NOCSETS
  11870.       case VN_CSET:
  11871. #ifdef OS2
  11872.         sprintf(vvbuf,"cp%d",os2getcp()); /* SAFE */
  11873. #else
  11874.         ckstrncpy(vvbuf,fcsinfo[fcharset].keyword,VVBUFL+1);
  11875. #endif /* OS2 */
  11876.         return(vvbuf);
  11877. #endif /* NOCSETS */
  11878.  
  11879. #ifdef OS2
  11880.       case VN_EXEDIR:
  11881.         return(exedir);
  11882.       case VN_STAR:
  11883.         return(startupdir);
  11884. #else
  11885.       case VN_EXEDIR:
  11886.         return(exedir ? exedir : "");
  11887. #ifdef VMSORUNIX
  11888.       case VN_STAR:
  11889.         return(startupdir);
  11890. #endif /* VMSORUNIX */
  11891. #endif /* OS2 */
  11892.  
  11893.       case VN_INI:
  11894.         return(inidir);
  11895.  
  11896.       case VN_MDM:
  11897.         return(gmdmtyp());
  11898.  
  11899.       case VN_EVAL:
  11900.         return(evalbuf);
  11901.  
  11902. #ifndef NODIAL
  11903.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  11904.         return(diallcc ? diallcc : "");
  11905.  
  11906.       case VN_D_AC:                     /* DIAL AREA-CODE */
  11907.         return(diallac ? diallac : "");
  11908.  
  11909.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  11910.         return(dialixp ? dialixp : "");
  11911.  
  11912.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  11913.         return(dialldp ? dialldp : "");
  11914.  
  11915.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  11916.         return(diallcp ? diallcp : "");
  11917.  
  11918.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE that matched */
  11919.         return(matchpxx ? matchpxx : "");
  11920. #else
  11921.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  11922.       case VN_D_AC:                     /* DIAL AREA-CODE */
  11923.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  11924.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  11925.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  11926.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE */
  11927.         return("");
  11928. #endif /* NODIAL */
  11929.       case VN_UID:
  11930. #ifdef UNIX
  11931.         {
  11932.             extern char * whoami();     /* From ckufio.c... */
  11933. #ifdef IKSD
  11934.             if (inserver)
  11935.               return((char *)uidbuf);
  11936.             else
  11937. #endif /* IKSD */
  11938.               if (uidbuf[0])
  11939.                 return((char *)uidbuf);
  11940.               else
  11941.                 return(whoami());
  11942.         }
  11943. #else
  11944.         return((char *)uidbuf);
  11945. #endif /* UNIX */
  11946.     } /* Break up long switch statements... */
  11947.  
  11948.     switch(y) {
  11949.       case VN_PWD:
  11950. #ifdef OS2
  11951.         if (activecmd == XXOUT || activecmd == XXLNOUT) {
  11952.             ckstrncpy(vvbuf,pwbuf,VVBUFL);
  11953.             ck_encrypt((char *)vvbuf);
  11954.             return((char *)vvbuf);
  11955.         } else
  11956. #endif /* OS2 */
  11957.           return((char *)pwbuf);
  11958.  
  11959.       case VN_PRM:
  11960.         return((char *)prmbuf);
  11961.  
  11962.       case VN_PROTO:
  11963. #ifdef NOXFER
  11964.         return("none");
  11965. #else
  11966. #ifdef CK_XYZ
  11967.         return(ptab[protocol].p_name);
  11968. #else
  11969.         return("kermit");
  11970. #endif /* CK_XYZ */
  11971. #endif /* NOXFER */
  11972.  
  11973. #ifndef NOXFER
  11974. #ifdef CK_TMPDIR
  11975.       case VN_DLDIR:
  11976.         return(dldir ? dldir : "");
  11977. #endif /* CK_TMPDIR */
  11978. #endif /* NOXFER */
  11979.  
  11980. #ifndef NODIAL
  11981.       case VN_M_INI:                    /* Modem init string */
  11982.         return(dialini ? dialini : (m ? m->wake_str : ""));
  11983.  
  11984.       case VN_M_DCM:                    /* Modem dial command */
  11985.         return(dialcmd ? dialcmd : (m ? m->dial_str : ""));
  11986.  
  11987.       case VN_M_DCO:                    /* Modem data compression on */
  11988.         return(dialdcon ? dialdcon : (m ? m->dc_on_str : ""));
  11989.  
  11990.       case VN_M_DCX:                    /* Modem data compression off */
  11991.         return(dialdcoff ? dialdcoff : (m ? m->dc_off_str : ""));
  11992.  
  11993.       case VN_M_ECO:                    /* Modem error correction on */
  11994.         return(dialecon ? dialecon : (m ? m->ec_on_str : ""));
  11995.  
  11996.       case VN_M_ECX:                    /* Modem error correction off */
  11997.         return(dialecoff ? dialecoff : (m ? m->ec_off_str : ""));
  11998.  
  11999.       case VN_M_AAO:                    /* Modem autoanswer on */
  12000.         return(dialaaon ? dialaaon : (m ? m->aa_on_str : ""));
  12001.  
  12002.       case VN_M_AAX:                    /* Modem autoanswer off */
  12003.         return(dialaaoff ? dialaaoff : (m ? m->aa_off_str : ""));
  12004.  
  12005.       case VN_M_HUP:                    /* Modem hangup command */
  12006.         return(dialhcmd ? dialhcmd : (m ? m->hup_str : ""));
  12007.  
  12008.       case VN_M_HWF:                    /* Modem hardware flow command */
  12009.         return(dialhwfc ? dialhwfc : (m ? m->hwfc_str : ""));
  12010.  
  12011.       case VN_M_SWF:                    /* Modem software flow command */
  12012.         return(dialswfc ? dialswfc : (m ? m->swfc_str : ""));
  12013.  
  12014.       case VN_M_NFC:                    /* Modem no flow-control command */
  12015.         return(dialnofc ? dialnofc : (m ? m->nofc_str : ""));
  12016.  
  12017.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  12018.         return(dialpulse ? dialpulse : (m ? m->pulse : ""));
  12019.  
  12020.       case VN_M_TDM:                    /* Modem tone dialing mode */
  12021.         return(dialtone ? dialtone : (m ? m->tone : ""));
  12022.  
  12023.       case VN_M_NAM:                    /* Modem full name */
  12024.         return(dialname ? dialname : (m ? m->name : ""));
  12025. #else
  12026.       case VN_M_INI:                    /* Modem init string */
  12027.       case VN_M_DCM:                    /* Modem dial command */
  12028.       case VN_M_DCO:                    /* Modem data compression on */
  12029.       case VN_M_DCX:                    /* Modem data compression off */
  12030.       case VN_M_ECO:                    /* Modem error correction on */
  12031.       case VN_M_ECX:                    /* Modem error correction off */
  12032.       case VN_M_AAO:                    /* Modem autoanswer on */
  12033.       case VN_M_AAX:                    /* Modem autoanswer off */
  12034.       case VN_M_HUP:                    /* Modem hangup command */
  12035.       case VN_M_HWF:                    /* Modem hardware flow command */
  12036.       case VN_M_SWF:                    /* Modem software flow command */
  12037.       case VN_M_NFC:                    /* Modem no flow-control command */
  12038.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  12039.       case VN_M_TDM:                    /* Modem tone dialing mode */
  12040.       case VN_M_NAM:
  12041.         return("");
  12042. #endif /* NODIAL */
  12043.  
  12044.       case VN_ISTAT:                    /* INPUT status */
  12045.         sprintf(vvbuf, "%d", instatus); /* SAFE */
  12046.         return(vvbuf);
  12047.  
  12048.       case VN_TEMP:                     /* Temporary directory */
  12049.         if (tempdir) {
  12050.             p = tempdir;
  12051.         } else {
  12052. #ifdef OS2
  12053. #ifdef NT
  12054.             p = getenv("K95TMP");
  12055. #else
  12056.             p = getenv("K2TMP");
  12057. #endif /* NT */
  12058.             if ( !p )
  12059. #endif /* OS2 */
  12060.               p = getenv("CK_TMP");
  12061.             if (!p) p = getenv("TMPDIR");
  12062.             if (!p) p = getenv("TEMP");
  12063.             if (!p) p = getenv("TMP");
  12064.  
  12065. #ifdef OS2ORUNIX
  12066.             if (p) {
  12067.                 int len = strlen(p);
  12068.                 if (p[len-1] != '/'
  12069. #ifdef OS2
  12070.                     && p[len-1] != '\\'
  12071. #endif /* OS2 */
  12072.                      ) {
  12073.                     static char foo[CKMAXPATH];
  12074.                     ckstrncpy(foo,p,CKMAXPATH);
  12075.                     ckstrncat(foo,"/",CKMAXPATH);
  12076.                     p = foo;
  12077.                 }
  12078.             } else
  12079. #else /* OS2ORUNIX */
  12080.             if (!p)
  12081. #endif /* OS2ORUNIX */
  12082. #ifdef UNIX                             /* Systems that have a standard */
  12083.               p = "/tmp/";              /* temporary directory... */
  12084. #else
  12085. #ifdef datageneral
  12086.               p = ":TMP:";
  12087. #else
  12088.               p = "";
  12089. #endif /* datageneral */
  12090. #endif /* UNIX */
  12091.         }
  12092.         ckstrncpy(vvbuf,p,VVBUFL);
  12093.         p = vvbuf;
  12094.  
  12095. /* This needs generalizing for VOS, AOS/VS, etc... */
  12096.  
  12097.         while (*p) {
  12098. #ifdef OS2
  12099.             if (*p == '\\') *p = '/';
  12100. #endif /* OS2 */
  12101.             p++;
  12102.         }
  12103. #ifndef VMS
  12104.         if (p > vvbuf) {
  12105.             char c =                    /* Directory termination character */
  12106. #ifdef MAC
  12107.               ':'
  12108. #else
  12109. #ifdef datageneral
  12110.               ':'
  12111. #else
  12112. #ifdef STRATUS
  12113.               '>'
  12114. #else
  12115.               '/'
  12116. #endif /* STRATUS */
  12117. #endif /* datageneral */
  12118. #endif /* MAC */
  12119.                 ;
  12120.  
  12121.             if (*(p-1) != c) {
  12122.                 *p++ = c;
  12123.                 *p = NUL;
  12124.             }
  12125.         }
  12126. #endif /* VMS */
  12127.         return(vvbuf);
  12128.     } /* Break up long switch statements... */
  12129.  
  12130.     switch(y) {
  12131.       case VN_ERRNO:                    /* Error number */
  12132. #ifdef VMS
  12133.         {
  12134.             extern int vms_lasterr;
  12135.             sprintf(vvbuf, "%d", vms_lasterr); /* SAFE */
  12136.         }
  12137. #else
  12138.         sprintf(vvbuf, "%d", errno);    /* SAFE */
  12139. #endif /* VMS */
  12140.         return(vvbuf);
  12141.  
  12142.       case VN_ERSTR:                    /* Error string */
  12143.         ckstrncpy(vvbuf,ck_errstr(),VVBUFL);
  12144.         return(vvbuf);
  12145.  
  12146. #ifndef NOXFER
  12147.       case VN_RPSIZ:                    /* RECEIVE packet-length */
  12148.         sprintf(vvbuf,"%d",urpsiz);     /* SAFE */
  12149.         return(vvbuf);
  12150.  
  12151.       case VN_WINDO:                    /* WINDOW slots */
  12152.         sprintf(vvbuf,"%d",wslotr);     /* SAFE */
  12153.         return(vvbuf);
  12154. #endif /* NOXFER */
  12155.  
  12156.       case VN_TFLN:                     /* TAKE-file line number */
  12157.         if (tlevel > -1) {
  12158.             sprintf(vvbuf, "%d", tfline[tlevel]); /* SAFE */
  12159.             return(vvbuf);
  12160.         } else
  12161.           return("0");
  12162.  
  12163.       case VN_MDMSG:                    /* DIALRESULT */
  12164. #ifndef NODIAL
  12165.         return((char *)modemmsg);
  12166. #else
  12167.         return("");
  12168. #endif /* NODIAL */
  12169.  
  12170.       case VN_DNUM:                     /* DIALNUMBER */
  12171. #ifndef NODIAL
  12172.         return(dialnum ? (char *) dialnum : "");
  12173. #else
  12174.         return("");
  12175. #endif /* NODIAL */
  12176.  
  12177.       case VN_APC:
  12178.         sprintf(vvbuf, "%d",            /* SAFE */
  12179. #ifdef CK_APC
  12180.                 apcactive
  12181. #else
  12182.                 0
  12183. #endif /* CK_APC */
  12184.                 );
  12185.         return((char *)vvbuf);
  12186.  
  12187. #ifdef OS2
  12188. #ifndef NOKVERBS
  12189.       case VN_TRMK:
  12190.           sprintf(vvbuf, "%d", keymac); /* SAFE */
  12191.         return((char *)vvbuf);
  12192. #endif /* NOKVERBS */
  12193. #endif /* OS2 */
  12194.  
  12195.       case VN_IPADDR:
  12196. #ifdef TCPSOCKET
  12197. #ifndef OSK
  12198.       /* This dumps core on OS-9 for some reason, but only if executed */
  12199.       /* before we have made a TCP connection.  This is obviously not */
  12200.       /* the ideal fix. */
  12201.         if (!myipaddr[0])
  12202.           getlocalipaddr();
  12203. #endif /* OSK */
  12204. #endif /* TCPSOCKET */
  12205.         ckstrncpy(vvbuf,
  12206. #ifdef TCPSOCKET
  12207.                 (char *)myipaddr,
  12208. #else
  12209.                 "",
  12210. #endif /* TCPSOCKET */
  12211.                 VVBUFL);
  12212.         return((char *)vvbuf);
  12213.  
  12214. #ifndef NOXFER
  12215.       case VN_CRC16:                    /* CRC-16 of most recent transfer */
  12216.         sprintf(vvbuf,"%d",crc16);      /* SAFE */
  12217.         return(vvbuf);
  12218. #endif /* NOXFER */
  12219.  
  12220. #ifdef CK_PID
  12221.       case VN_PID:
  12222. #ifdef IKSD
  12223. #ifdef CK_LOGIN
  12224.         if (inserver && isguest)
  12225.           return("");
  12226. #endif /* CK_LOGIN */
  12227. #endif /* IKSD */
  12228.         return(ckgetpid());
  12229. #endif /* CK_PID */
  12230.  
  12231. #ifndef NOXFER
  12232.       case VN_FNAM: {                   /* \v(filename) */
  12233.           extern char filnam[], ofn1[], *sfspec, *rrfspec;
  12234.           char * tmp;
  12235.           switch (what) {               /* File transfer is in progress */
  12236. #ifdef NEWFTP
  12237.             case (W_FTP|W_RECV):
  12238.             case (W_FTP|W_SEND):
  12239.               return((char *)filnam);
  12240. #endif /* NEWFTP */
  12241.             case W_RECV:
  12242.             case W_REMO:
  12243.               return((char *)ofn1);
  12244.             default:                    /* Most recent file transferred */
  12245.               if (filnam[0]) {          /* (if any) */
  12246.                   return((char *)filnam);
  12247.               } else if (lastxfer & W_SEND && sfspec) {
  12248.                   if (fnspath == PATH_OFF)
  12249.                     zstrip(sfspec,&tmp);
  12250.                   else
  12251.                     tmp = sfspec;
  12252.                   return(tmp);
  12253.               } else if (lastxfer & W_RECV && rrfspec) {
  12254.                   if (fnrpath == PATH_OFF)
  12255.                     zstrip(rrfspec,&tmp);
  12256.                   else
  12257.                     tmp = rrfspec;
  12258.                   return(tmp);
  12259.               } else
  12260.                 return("");
  12261.           }
  12262.       }
  12263.       case VN_FNUM:                     /* \v(filenum) */
  12264.         sprintf(vvbuf,"%ld",filcnt);    /* SAFE */
  12265.         return((char *)vvbuf);
  12266. #endif /* NOXFER */
  12267.  
  12268. #ifdef PEXITSTAT
  12269.       case VN_PEXIT: {
  12270.           extern int pexitstat;
  12271.           sprintf(vvbuf,"%d",pexitstat); /* SAFE */
  12272.           return((char *)vvbuf);
  12273.       }
  12274. #endif /* PEXITSTAT */
  12275.  
  12276. #ifndef NOXFER
  12277.       case VN_P_8BIT:
  12278.         vvbuf[0] = parity ? ebq : NUL;
  12279.         vvbuf[1] = NUL;
  12280.         return((char *)vvbuf);
  12281.  
  12282.       case VN_P_CTL: {
  12283.           extern CHAR myctlq;
  12284.           vvbuf[0] = myctlq;
  12285.           vvbuf[1] = NUL;
  12286.           return((char *)vvbuf);
  12287.       }
  12288.       case VN_P_RPT: {
  12289.           extern int rptena;
  12290.           vvbuf[0] = rptena ? rptq : NUL;
  12291.           vvbuf[1] = NUL;
  12292.           return((char *)vvbuf);
  12293.       }
  12294. #endif /* NOXFER */
  12295.  
  12296. #ifdef OS2
  12297.       case VN_REGN:
  12298.         return(get_reg_name());
  12299.       case VN_REGO:
  12300.         return(get_reg_corp());
  12301.       case VN_REGS:
  12302.         return(get_reg_sn());
  12303. #endif /* OS2 */
  12304.     } /* Break up long switch statements... */
  12305.  
  12306.     switch(y) {
  12307.       case VN_XPROG:
  12308. #ifdef OS2
  12309. #ifdef NT
  12310. #ifdef KUI
  12311.         return("K-95G");
  12312. #else
  12313.         return("K-95");
  12314. #endif /* KUI */
  12315. #else
  12316.         return("K/2");
  12317. #endif /* NT */
  12318. #else
  12319.         return("C-Kermit");
  12320. #endif /* OS2 */
  12321.  
  12322.       case VN_EDITOR:
  12323. #ifdef NOFRILLS
  12324.         return("");
  12325. #else
  12326. #ifdef NOPUSH
  12327.         return("");
  12328. #else
  12329.         {
  12330.             extern char editor[];
  12331.             char *ss;
  12332.             if (!editor[0]) {
  12333.                 ss = getenv("EDITOR");
  12334.                 if (ss) {
  12335.                     ckstrncpy(editor,ss,CKMAXPATH);
  12336.                 }
  12337.             }
  12338.             debug(F110,"\\v(editor)",editor,0);
  12339.             return(editor[0] ? (char *)editor : "");
  12340.         }
  12341. #endif /* NOPUSH */
  12342. #endif /* NOFRILLS */
  12343.  
  12344.       case VN_EDOPT:
  12345. #ifdef NOFRILLS
  12346.         return("");
  12347. #else
  12348. #ifdef NOPUSH
  12349.         return("");
  12350. #else
  12351.         {
  12352.             extern char editopts[];
  12353.             return(editopts[0] ? (char *)editopts : "");
  12354.         }
  12355. #endif /* NOPUSH */
  12356. #endif /* NOFRILLS */
  12357.  
  12358.       case VN_EDFILE:
  12359. #ifdef NOFRILLS
  12360.         return("");
  12361. #else
  12362. #ifdef NOPUSH
  12363.         return("");
  12364. #else
  12365.         {
  12366.             extern char editfile[];
  12367.             return(editfile[0] ? (char *)editfile : "");
  12368.         }
  12369. #endif /* NOPUSH */
  12370. #endif /* NOFRILLS */
  12371.  
  12372. #ifdef BROWSER
  12373.       case VN_BROWSR: {
  12374.           extern char browser[];
  12375.           if (!browser[0]) {
  12376.               s = getenv("BROWSER");
  12377.               if (s) ckstrncpy(browser,s,CKMAXPATH);
  12378.           }
  12379.           return(browser[0] ? (char *)browser : "");
  12380.       }
  12381.       case VN_BROPT: {
  12382.           extern char browsopts[];
  12383.           return(browsopts[0] ? (char *)browsopts : "");
  12384.       }
  12385.       case VN_URL: {
  12386.           extern char browsurl[];
  12387.           return(browsurl[0] ? (char *)browsurl : "");
  12388.       }
  12389. #endif /* BROWSER */
  12390.       case VN_HERALD:
  12391.         return((char *)versio);
  12392.  
  12393.       case VN_TEST: {                   /* test */
  12394.           extern char * ck_s_test, * ck_s_tver;
  12395.           if (!ck_s_test) ck_s_test = "";
  12396.           if (!ck_s_tver) ck_s_tver = "";
  12397.           if (*ck_s_test) {
  12398.               ckstrncpy(vvbuf,ck_s_test,VVBUFL);
  12399.               if (*ck_s_tver) {
  12400.                   ckstrncat(vvbuf,".",VVBUFL);
  12401.                   ckstrncat(vvbuf,ck_s_tver,VVBUFL);
  12402.               }
  12403.           } else
  12404.             ckstrncpy(vvbuf,"0",VVBUFL);
  12405.           return((char *)vvbuf);
  12406.       }
  12407.  
  12408. #ifndef NOXFER
  12409.       case VN_XFSTAT:                   /* xferstatus */
  12410.         x = xferstat;                   /* Like success */
  12411.         if (x > -1) x = (x == 0) ? 1 : 0; /* External value is reversed */
  12412.         sprintf(vvbuf,"%d",x);          /* SAFE */
  12413.         return((char *)vvbuf);
  12414.  
  12415.       case VN_XFMSG:                    /* xfermsg */
  12416.         return((char *)epktmsg);
  12417.  
  12418. #ifndef NOMSEND
  12419.       case VN_SNDL: {                   /* sendlist */
  12420.           extern int filesinlist;
  12421.           sprintf(vvbuf,"%d",filesinlist); /* SAFE */
  12422.           return((char *)vvbuf);
  12423.       }
  12424. #endif /* NOMSEND */
  12425. #endif /* NOXFER */
  12426.  
  12427. #ifdef CK_TRIGGER
  12428.       case VN_TRIG: {
  12429.           extern char * triggerval;
  12430.           return(triggerval ? triggerval : "");
  12431.       }
  12432. #endif /* CK_TRIGGER */
  12433. #ifdef OS2MOUSE
  12434. #ifdef OS2
  12435.       case VN_MOU_X: {
  12436.           extern int MouseCurX;
  12437.           sprintf(vvbuf,"%d",MouseCurX); /* SAFE */
  12438.           return((char *)vvbuf);
  12439.       }
  12440.       case VN_MOU_Y: {
  12441.           extern int MouseCurY;
  12442.           sprintf(vvbuf,"%d",MouseCurY); /* SAFE */
  12443.           return((char *)vvbuf);
  12444.       }
  12445. #endif /* OS2 */
  12446. #endif /* OS2MOUSE */
  12447.       case VN_PRINT: {
  12448.           extern int printpipe;
  12449.           extern char * printername;
  12450. #ifdef PRINTSWI
  12451.           extern int noprinter;
  12452.           if (noprinter) return("");
  12453. #endif /* PRINTSWI */
  12454.           ckmakmsg(vvbuf,VVBUFL,
  12455.                    printpipe ? "|" : "",
  12456.                    printername ? printername :
  12457. #ifdef OS2
  12458.                    "PRN",
  12459. #else
  12460.                    "(default)",
  12461. #endif /* OS2 */
  12462.                    NULL,
  12463.                    NULL
  12464.                    );
  12465.           return((char *)vvbuf);
  12466.       }
  12467.     } /* Break up long switch statements... */
  12468.  
  12469.     switch(y) {
  12470.       case VN_ESC:                      /* Escape character */
  12471.         sprintf(vvbuf,"%d",escape);     /* SAFE */
  12472.         return((char *)vvbuf);
  12473.  
  12474.       case VN_INTIME:
  12475.         sprintf(vvbuf,"%ld",inetime);   /* SAFE */
  12476.         return((char *)vvbuf);
  12477.  
  12478.       case VN_INTMO:
  12479.         sprintf(vvbuf,"%d",inwait);     /* SAFE */
  12480.         return((char *)vvbuf);
  12481.  
  12482.       case VN_SECURE:
  12483.         if (0
  12484. #ifdef SSHBUILTIN
  12485.             || IS_SSH()
  12486. #endif /* SSHBUILTIN */
  12487. #ifdef CK_ENCRYPTION
  12488.             || ck_tn_encrypting() && ck_tn_decrypting()
  12489. #endif /* CK_ENCRYPTION */
  12490. #ifdef CK_SSL
  12491.             || tls_active_flag || ssl_active_flag
  12492. #endif /* CK_SSL */
  12493.             )
  12494.           return("1");
  12495.         else
  12496.           return("0");
  12497.  
  12498.       case VN_AUTHN:
  12499. #ifdef CK_AUTHENTICATION
  12500.         {
  12501.             extern char szUserNameAuthenticated[];
  12502.             return((char *)szUserNameAuthenticated);
  12503.         }
  12504. #else /* CK_AUTHENTICATION */
  12505.         return((char *)"");
  12506. #endif /* CK_AUTHENTICATION */
  12507.  
  12508.       case VN_AUTHS:
  12509. #ifdef CK_AUTHENTICATION
  12510.         switch (ck_tn_auth_valid()) {
  12511.           case AUTH_UNKNOWN:
  12512.             return((char *)"unknown");
  12513.           case AUTH_OTHER:
  12514.             return((char *)"other");
  12515.           case AUTH_USER:
  12516.             return((char *)"user");
  12517.           case AUTH_VALID:
  12518.             return((char *)"valid");
  12519.           case AUTH_REJECT:
  12520.           default:
  12521.             return((char *)"rejected");
  12522.         }
  12523. #else /* CK_AUTHENTICATION */
  12524.         return((char *)"rejected");
  12525. #endif /* CK_AUTHENTICATION */
  12526.  
  12527.       case VN_AUTHT:
  12528. #ifdef CK_AUTHENTICATION
  12529. #ifdef CK_SSL
  12530.         if ((ssl_active_flag || tls_active_flag) &&
  12531.             ck_tn_auth_valid() == AUTH_VALID &&
  12532.             (sstelnet ? (!TELOPT_U(TELOPT_AUTHENTICATION)) :
  12533.                         (!TELOPT_ME(TELOPT_AUTHENTICATION))) ||
  12534.              ck_tn_authenticated() == AUTHTYPE_NULL ||
  12535.              ck_tn_authenticated() == AUTHTYPE_AUTO)
  12536.           return("X_509_CERTIFICATE");
  12537.         else
  12538. #endif /* CK_SSL */
  12539.           return(AUTHTYPE_NAME(ck_tn_authenticated()));
  12540. #else /* CK_AUTHENTICATION */
  12541.         return((char *)"NULL");
  12542. #endif /* CK_AUTHENTICATION */
  12543.  
  12544. #ifdef CK_KERBEROS
  12545.       case VN_K4PRN: {
  12546.           extern char * krb4_d_principal;
  12547.           if (krb4_d_principal)
  12548.             ckstrncpy(vvbuf,krb4_d_principal,VVBUFL+1);
  12549.           else
  12550.             *vvbuf = NUL;
  12551.           return((char *)vvbuf);
  12552.       }
  12553.       case VN_K5PRN: {
  12554.           extern char * krb5_d_principal;
  12555.           if (krb5_d_principal)
  12556.             ckstrncpy(vvbuf,krb5_d_principal,VVBUFL+1);
  12557.           else
  12558.             *vvbuf = NUL;
  12559.           return((char *)vvbuf);
  12560.       }
  12561.       case VN_K4RLM: {
  12562.           extern char * krb4_d_realm;
  12563.           if (krb4_d_realm) {
  12564.               ckstrncpy(vvbuf,krb4_d_realm,VVBUFL+1);
  12565.           } else {
  12566.               char * s = ck_krb4_getrealm();
  12567.               ckstrncpy(vvbuf,s ? s : "",VVBUFL+1);
  12568.           }
  12569.           return((char *)vvbuf);
  12570.       }
  12571.       case VN_K4SRV: {
  12572.           extern char * krb4_d_srv;
  12573.           if (krb4_d_srv)
  12574.             ckstrncpy(vvbuf,krb4_d_srv,VVBUFL+1);
  12575.           else
  12576.             ckstrncpy(vvbuf,"rcmd",VVBUFL);
  12577.           return((char *)vvbuf);
  12578.       }
  12579.       case VN_K5RLM: {
  12580.           extern char * krb5_d_realm;
  12581.           extern char * krb5_d_cc;
  12582.           if (krb5_d_realm) {
  12583.               ckstrncpy(vvbuf,krb5_d_realm,VVBUFL+1);
  12584.           } else {
  12585.               char * s = ck_krb5_getrealm(krb5_d_cc);
  12586.               ckstrncpy(vvbuf,s,VVBUFL+1);
  12587.           }
  12588.           return((char *)vvbuf);
  12589.       }
  12590.       case VN_K5CC: {
  12591.           extern char * krb5_d_cc;
  12592.           if (krb5_d_cc)
  12593.             ckstrncpy(vvbuf,krb5_d_cc,VVBUFL+1);
  12594.           else
  12595.             ckstrncpy(vvbuf,ck_krb5_get_cc_name(),VVBUFL+1);
  12596.           return((char *)vvbuf);
  12597.       }
  12598.       case VN_K5SRV: {
  12599.           extern char * krb5_d_srv;
  12600.           if (krb5_d_srv)
  12601.             ckstrncpy(vvbuf,krb5_d_srv,VVBUFL+1);
  12602.           else
  12603.             ckstrncpy(vvbuf,"host",VVBUFL);
  12604.           return((char *)vvbuf);
  12605.       }
  12606.       case VN_K4ENO: {
  12607.         extern char * krb4_errno;
  12608.         sprintf(vvbuf,"%d",krb4_errno); /* SAFE */
  12609.         return((char *)vvbuf);
  12610.       }
  12611.       case VN_K5ENO: {
  12612.         extern char * krb5_errno;
  12613.         sprintf(vvbuf,"%d",krb5_errno); /* SAFE */
  12614.         return((char *)vvbuf);
  12615.       }
  12616.       case VN_K4EMSG: {
  12617.         extern char * krb4_errmsg;
  12618.         ckstrncpy(vvbuf,krb4_errmsg?krb4_errmsg:"",VVBUFL+1);
  12619.         return((char *)vvbuf);
  12620.       }
  12621.       case VN_K5EMSG: {
  12622.         extern char * krb5_errmsg;
  12623.         ckstrncpy(vvbuf,krb5_errmsg,VVBUFL+1);
  12624.         return((char *)vvbuf);
  12625.       }
  12626. #endif /* CK_KERBEROS */
  12627. #ifdef CK_SSL
  12628.       case VN_X509_S:
  12629.         if (ssl_active_flag)
  12630.           ckstrncpy(vvbuf,ssl_get_subject_name(ssl_con),VVBUFL+1);
  12631.         else if (tls_active_flag)
  12632.           ckstrncpy(vvbuf,ssl_get_subject_name(tls_con),VVBUFL+1);
  12633.         else
  12634.           ckstrncpy(vvbuf,"",VVBUFL+1);
  12635.         return((char *)vvbuf);
  12636.       case VN_X509_I:
  12637.         if (ssl_active_flag)
  12638.           ckstrncpy(vvbuf,ssl_get_issuer_name(ssl_con),VVBUFL+1);
  12639.         else if (tls_active_flag)
  12640.           ckstrncpy(vvbuf,ssl_get_issuer_name(tls_con),VVBUFL+1);
  12641.         else
  12642.           ckstrncpy(vvbuf,"",VVBUFL+1);
  12643.         return((char *)vvbuf);
  12644. #endif /* CK_SSL */
  12645.  
  12646.       case VN_OSNAM:
  12647. #ifdef IKSD
  12648. #ifdef CK_LOGIN
  12649.         if (inserver && isguest)
  12650.           return("");
  12651. #endif /* CK_LOGIN */
  12652. #endif /* IKSD */
  12653. #ifdef CK_UTSNAME
  12654.         {
  12655.             extern char unm_nam[];
  12656.             return((char *)unm_nam);
  12657.         }
  12658. #else
  12659.         for (x = y = 0; x < VVBUFL; x++) {
  12660.             if (ckxsys[x] == SP && cx == 0) continue;
  12661.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  12662.         }
  12663.         vvbuf[y] = NUL;
  12664.         return(vvbuf);
  12665. #endif /* CK_UTSNAME */
  12666.  
  12667.       case VN_OSVER: {
  12668. #ifdef CK_UTSNAME
  12669.           extern char unm_ver[];
  12670. #ifdef IKSD
  12671. #ifdef CK_LOGIN
  12672.           if (inserver && isguest)
  12673.             return("");
  12674. #endif /* CK_LOGIN */
  12675. #endif /* IKSD */
  12676.           return((char *)unm_ver);
  12677. #else
  12678.           return("");
  12679. #endif /* CK_UTSNAME */
  12680.       }
  12681.  
  12682.       case VN_OSREL: {
  12683. #ifdef CK_UTSNAME
  12684.           extern char unm_rel[];
  12685. #ifdef IKSD
  12686. #ifdef CK_LOGIN
  12687.           if (inserver && isguest)
  12688.             return("");
  12689. #endif /* CK_LOGIN */
  12690. #endif /* IKSD */
  12691.           return((char *)unm_rel);
  12692. #else
  12693.           return("");
  12694. #endif /* CK_UTSNAME */
  12695.       }
  12696.     } /* Break up long switch statements... */
  12697.  
  12698.     switch(y) {
  12699.       case VN_NAME: {
  12700.           extern char * myname;
  12701.           return(myname);
  12702.       }
  12703.  
  12704.       case VN_MODL: {
  12705. #ifdef CK_UTSNAME
  12706.           extern char unm_mod[], unm_mch[];
  12707.           int y = VVBUFL - 1;
  12708.           char * s = unm_mod;
  12709. #endif /* CK_UTSNAME */
  12710. #ifdef IKSD
  12711. #ifdef CK_LOGIN
  12712.           if (inserver && isguest)
  12713.             return("");
  12714. #endif /* CK_LOGIN */
  12715. #endif /* IKSD */
  12716.  
  12717. #ifdef COMMENT                          /* was HPUX */
  12718.           if (!unm_mod[0] && !nopush)
  12719.             zzstring("\\fcommand(model)",&s,&y);
  12720. /*
  12721.    Another possibility would be:
  12722.      "\\fcommand(ksh -c 'whence model 1>&- && model || uname -m')"
  12723.    But that would depend on having ksh.
  12724. */
  12725. #else
  12726. #ifdef OSF32                            /* Digital UNIX 3.2 and higher... */
  12727. /* Note: Ultrix has /etc/sizer, but it is not publicly executable. */
  12728. /* sizer -c outputs 'cpu:<tab><tab>"DECxxxx"' */
  12729.           if (!unm_mod[0]) {
  12730.               char * p;
  12731.               int flag = 0;
  12732.               zzstring("\\fcommand(/usr/sbin/sizer -c)",&s,&y);
  12733.               debug(F110,"DU model",unm_mod,0);
  12734.               s = unm_mod;
  12735.               p = unm_mod;
  12736.               while (*p) {              /* Extract the part in quotes */
  12737.                   if (*p == '"') {
  12738.                       if (flag)
  12739.                         break;
  12740.                       flag = 1;
  12741.                       p++;
  12742.                       continue;
  12743.                   }
  12744.                   if (flag)
  12745.                     *s++ = *p;
  12746.                   p++;
  12747.               }
  12748.               *s = NUL;
  12749.           }
  12750. #endif /* OSF32 */
  12751. #endif /* COMMENT */
  12752.  
  12753. #ifdef CK_UTSNAME
  12754.           if (unm_mod[0])
  12755.             return((char *)unm_mod);
  12756.           else
  12757.             return((char *)unm_mch);
  12758. #else
  12759.           return("");
  12760. #endif /* CK_UTSNAME */
  12761.       }
  12762.  
  12763. #ifdef IBMX25
  12764.       /* X.25 variables (local and remote address) */
  12765.       case VN_X25LA:
  12766.         if (!local_nua[0] && !x25local_nua(local_nua))
  12767.           *vvbuf = NULL;
  12768.         else
  12769.           ckstrncpy(vvbuf,local_nua,VVBUFL+1);
  12770.         return((char *)vvbuf);
  12771.  
  12772.       case VN_X25RA:
  12773.         if (!remote_nua[0])
  12774.           *vvbuf = NULL;
  12775.         else
  12776.           ckstrncpy(vvbuf,remote_nua,VVBUFL+1);
  12777.         return((char *)vvbuf);
  12778. #endif /* IBMX25 */
  12779.  
  12780. #ifndef NODIAL
  12781.       case VN_PDSFX: {
  12782.           extern char pdsfx[];
  12783.           return((char *)pdsfx);
  12784.       }
  12785.       case VN_DTYPE: {
  12786.           extern int dialtype;
  12787.           sprintf(vvbuf,"%d",dialtype); /* SAFE */
  12788.           return((char *)vvbuf);
  12789.       }
  12790. #endif /* NODIAL */
  12791.  
  12792. #ifdef UNIX
  12793.       case VN_LCKPID: {
  12794.           extern char lockpid[];
  12795.           return((char *)lockpid);
  12796.       }
  12797. #endif /* UNIX */
  12798.  
  12799. #ifndef NOXFER
  12800.       case VN_BLK:
  12801.         sprintf(vvbuf,"%d",bctr);       /* SAFE */
  12802.         return((char *)vvbuf);
  12803.  
  12804.       case VN_TFTIM:
  12805.         sprintf(vvbuf,                  /* SAFE */
  12806. #ifdef GFTIMER
  12807.                 "%ld", (long)(fptsecs + 0.5)
  12808. #else
  12809.                 "%d", tsecs
  12810. #endif /* GFTIMER */
  12811.                 );
  12812.         return((char *)vvbuf);
  12813. #endif /* NOXFER */
  12814.  
  12815.       case VN_HWPAR:
  12816.       case VN_SERIAL: {
  12817.           int sb;
  12818.           char c, * ss;
  12819.           extern int stopbits;
  12820.           vvbuf[0] = NUL;
  12821.           if (hwparity && local && !network)
  12822.             ss = parnam((char)hwparity);
  12823.           else
  12824.             ss = parnam((char)parity);
  12825.           if (cx == VN_HWPAR) {
  12826.               ckstrncpy(vvbuf,ss,VVBUFL);
  12827.               return((char *)vvbuf);
  12828.           }
  12829.           c = ss[0];
  12830.           if (islower(c)) c = toupper(c);
  12831.           sb = stopbits;
  12832.           if (sb < 1)
  12833.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  12834.           if (hwparity)
  12835.             sprintf(vvbuf," 8%c%d",c,sb); /* SAFE */
  12836.           else if (parity)
  12837.             sprintf(vvbuf," 7%c%d",c,sb); /* SAFE */
  12838.           else
  12839.             sprintf(vvbuf," 8N%d",sb);  /* SAFE */
  12840.           return((char *)vvbuf);
  12841.       }
  12842.  
  12843. #ifdef UNIX
  12844.       case VN_LCKDIR: {
  12845. #ifndef NOUUCP
  12846.           extern char * uucplockdir;
  12847.           ckstrncpy(vvbuf,uucplockdir,VVBUFL);
  12848.           x = strlen(vvbuf);
  12849.           if (x > 0) {
  12850.               if (vvbuf[x-1] != '/') {
  12851.                   vvbuf[x] = '/';
  12852.                   vvbuf[x+1] = NUL;
  12853.               }
  12854.           }
  12855. #else
  12856.           vvbuf[0] = NUL;
  12857. #endif /* NOUUCP */
  12858.           return((char *)vvbuf);
  12859.       }
  12860. #endif /* UNIX */
  12861.     } /* Break up long switch statements... */
  12862.  
  12863.     switch(y) {
  12864. #ifndef NODIAL
  12865.       case VN_DM_LP:
  12866.       case VN_DM_SP:
  12867.       case VN_DM_PD:
  12868.       case VN_DM_TD:
  12869.       case VN_DM_WA:
  12870.       case VN_DM_WD:
  12871.       case VN_DM_HF:
  12872.       case VN_DM_WB:
  12873.       case VN_DM_RC: {
  12874.           extern char * getdm();
  12875.           ckstrncpy(vvbuf,getdm(y),VVBUFL);
  12876.           return((char *)vvbuf);
  12877.       }
  12878. #endif /* NODIAL */
  12879.  
  12880.       case VN_TY_LN:
  12881.       case VN_TY_LC: {
  12882.           extern int typ_lines;
  12883.           sprintf(vvbuf,"%d",typ_lines); /* SAFE */
  12884.           return((char *)vvbuf);
  12885.       }
  12886.       case VN_TY_LM: {
  12887.           extern int typ_mtchs;
  12888.           sprintf(vvbuf,"%d",typ_mtchs); /* SAFE */
  12889.           return((char *)vvbuf);
  12890.       }
  12891.       case VN_MACLVL:
  12892.         sprintf(vvbuf,"%d",maclvl);     /* SAFE */
  12893.         return((char *)vvbuf);
  12894.     } /* Break up long switch statements... */
  12895.  
  12896.     switch(y) {
  12897. #ifndef NOXFER
  12898.       case VN_XF_BC:
  12899.         sprintf(vvbuf,"%d",crunched);   /* SAFE */
  12900.         return((char *)vvbuf);
  12901.  
  12902.       case VN_XF_TM:
  12903.         sprintf(vvbuf,"%d",timeouts);   /* SAFE */
  12904.         return((char *)vvbuf);
  12905.  
  12906.       case VN_XF_RX:
  12907.         sprintf(vvbuf,"%d",retrans);    /* SAFE */
  12908.         return((char *)vvbuf);
  12909. #endif /* NOXFER */
  12910.  
  12911.       case VN_MS_CD:                    /* Modem signals */
  12912.       case VN_MS_CTS:
  12913.       case VN_MS_DSR:
  12914.       case VN_MS_DTR:
  12915.       case VN_MS_RI:
  12916.       case VN_MS_RTS: {
  12917.           int x, z = -1;
  12918.           x = ttgmdm();                 /* Try to get them */
  12919.           if (x > -1) {
  12920.               switch (y) {
  12921.                 case VN_MS_CD:  z = (x & BM_DCD) ? 1 : 0; break;
  12922.                 case VN_MS_DSR: z = (x & BM_DSR) ? 1 : 0; break;
  12923.                 case VN_MS_CTS: z = (x & BM_CTS) ? 1 : 0; break;
  12924. #ifdef MAC
  12925.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  12926. #else
  12927. #ifndef STRATUS
  12928.                 case VN_MS_RI:  z = (x & BM_RNG) ? 1 : 0; break;
  12929. #ifndef NT
  12930.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  12931.                 case VN_MS_RTS: z = (x & BM_RTS) ? 1 : 0; break;
  12932. #endif /* NT */
  12933. #endif /* STRATUS */
  12934. #endif /* MAC */
  12935.               }
  12936.           }
  12937.           sprintf(vvbuf,"%d",z);        /* SAFE */
  12938.           return((char *)vvbuf);
  12939.       }
  12940.       case VN_MATCH:                    /* INPUT MATCH */
  12941.         return(inpmatch ? inpmatch : "");
  12942.  
  12943.       case VN_SLMSG: {                  /* SET LINE / HOST message */
  12944.           extern char * slmsg;
  12945.           vvbuf[0] = NUL;
  12946.           if (slmsg)
  12947.             ckstrncpy(vvbuf,slmsg,VVBUFL);
  12948.          return(vvbuf);
  12949.       }
  12950.  
  12951.       case VN_TXTDIR:                   /* TEXTDIR */
  12952.         return(k_info_dir ? k_info_dir : "");
  12953.  
  12954. #ifdef FNFLOAT
  12955.       case VN_MA_PI:
  12956.         return(math_pi);
  12957.  
  12958.       case VN_MA_E:
  12959.         return(math_e);
  12960.  
  12961.       case VN_MA_PR:
  12962.         sprintf(vvbuf,"%d",fp_digits);  /* SAFE */
  12963.         return(vvbuf);
  12964. #endif /* FNFLOAT */
  12965.  
  12966.       case VN_CMDBL:
  12967.         sprintf(vvbuf,"%d",CMDBL);      /* SAFE */
  12968.         return(vvbuf);
  12969.  
  12970. #ifdef CKCHANNELIO
  12971.       case VN_FERR: {
  12972.           extern int z_error;
  12973.           sprintf(vvbuf,"%d",z_error);  /* SAFE */
  12974.           return(vvbuf);
  12975.       }
  12976.       case VN_FMAX: {
  12977.           extern int z_maxchan;
  12978.           sprintf(vvbuf,"%d",z_maxchan); /* SAFE */
  12979.           return(vvbuf);
  12980.       }
  12981.       case VN_FCOU: {
  12982.           extern int z_filcount;
  12983.           sprintf(vvbuf,"%d",z_filcount); /* SAFE */
  12984.           return(vvbuf);
  12985.       }
  12986. #endif /* CKCHANNELIO */
  12987.  
  12988. #ifndef NODIAL
  12989.       case VN_DRTR: {
  12990.           extern int dialcount;
  12991.           sprintf(vvbuf,"%d",dialcount); /* SAFE */
  12992.           return(vvbuf);
  12993.       }
  12994. #endif /* NODIAL */
  12995.  
  12996. #ifndef NOLOGDIAL
  12997. #ifndef NOLOCAL
  12998.       case VN_CXTIME:
  12999.         sprintf(vvbuf,"%ld",dologshow(0)); /* SAFE */
  13000.         return(vvbuf);
  13001. #endif /* NOLOCAL */
  13002. #endif /* NOLOGDIAL */
  13003.  
  13004.       case VN_BYTE:
  13005.         sprintf(vvbuf,"%d",byteorder);  /* SAFE */
  13006.         return(vvbuf);
  13007.  
  13008.       case VN_KBCHAR:
  13009.         vvbuf[0] = NUL;
  13010.         vvbuf[1] = NUL;
  13011.         if (kbchar > 0)
  13012.           vvbuf[0] = (kbchar & 0xff);
  13013.         return(vvbuf);
  13014.  
  13015.       case VN_TTYNAM: {
  13016. #ifdef HAVECTTNAM
  13017.           extern char cttnam[];
  13018.           return((char *)cttnam);
  13019. #else
  13020.           return(CTTNAM);
  13021. #endif /* HAVECTTNAM */
  13022.       }
  13023.  
  13024.       case VN_PROMPT:
  13025.         return(cmgetp());
  13026.  
  13027.       case VN_BUILD: {
  13028.           extern char * buildid;
  13029.           return(buildid);
  13030.       }
  13031.  
  13032. #ifndef NOSEXP
  13033.       case VN_SEXP: {
  13034.           extern char * lastsexp;
  13035.           return(lastsexp ? lastsexp : "");
  13036.       }
  13037.       case VN_VSEXP: {
  13038.           extern char * sexpval;
  13039.           return(sexpval ? sexpval : "");
  13040.       }
  13041.       case VN_LSEXP: {
  13042.           extern int sexpdep;
  13043.           ckstrncpy(vvbuf,ckitoa(sexpdep),VVBUFL);
  13044.           return(vvbuf);
  13045.       }
  13046. #endif /* NOSEXP */
  13047.  
  13048. #ifdef GFTIMER
  13049.       case VN_FTIME: {
  13050.           CKFLOAT f;
  13051.           ztime(&p);
  13052.           if (p == NULL || *p == NUL)
  13053.             return(NULL);
  13054.           z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  13055.           f = (CKFLOAT)z + ((CKFLOAT)ztusec) / 1000000.0;
  13056.           sprintf(vvbuf,"%f",f);        /* SAFE */
  13057.           return(vvbuf);
  13058.       }
  13059. #endif /* GFTIMER */
  13060.  
  13061. #ifndef NOHTTP
  13062.       case VN_HTTP_C: {                 /* HTTP Code */
  13063.           extern int http_code;
  13064.           return(ckitoa(http_code));
  13065.       }
  13066.       case VN_HTTP_N:                   /* HTTP Connected */
  13067.         return( http_isconnected() ? "1" : "0");
  13068.       case VN_HTTP_H:                   /* HTTP Host */
  13069.         return( (char *)http_host() );
  13070.       case VN_HTTP_M: {                 /* HTTP Message */
  13071.           extern char http_reply_str[];
  13072.           return((char *)http_reply_str);
  13073.       }
  13074.       case VN_HTTP_S:                   /* HTTP Security */
  13075.         return((char *)http_security());
  13076. #endif /* NOHTTP */
  13077.  
  13078. #ifdef NEWFTP
  13079.       case VN_FTP_B:
  13080.         return((char *)ftp_cpl_mode());
  13081.       case VN_FTP_D:
  13082.         return((char *)ftp_dpl_mode());
  13083.       case VN_FTP_Z:
  13084.         return((char *)ftp_authtype());
  13085.       case VN_FTP_C: {
  13086.           extern int ftpcode;
  13087.           return(ckitoa(ftpcode));
  13088.       }
  13089.       case VN_FTP_M: {
  13090.           extern char ftp_reply_str[];
  13091.           if (isdigit(ftp_reply_str[0]) &&
  13092.               isdigit(ftp_reply_str[1]) &&
  13093.               isdigit(ftp_reply_str[2]) &&
  13094.               ftp_reply_str[3] == ' ')
  13095.             return(&ftp_reply_str[4]);
  13096.           else
  13097.             return(ftp_reply_str);
  13098.       }
  13099.       case VN_FTP_S: {
  13100.           extern char ftp_srvtyp[];
  13101.           return((char *)ftp_srvtyp);
  13102.       }
  13103.       case VN_FTP_H: {
  13104.           extern char * ftp_host;
  13105.           return(ftp_host ? ftp_host : "");
  13106.       }
  13107.       case VN_FTP_X: {                  /* FTP Connected */
  13108.           extern int ftpisconnected();
  13109.           return(ftpisconnected() ? "1" : "0");
  13110.       }
  13111.       case VN_FTP_L: {                  /* FTP Logged in */
  13112.           extern int ftpisloggedin();
  13113.           return(ftpisloggedin() ? "1" : "0");
  13114.       }
  13115.       case VN_FTP_G: {                  /* FTP GET-PUT-REMOTE */
  13116.           extern int ftpget;
  13117.           char * s = "";
  13118.           switch (ftpget) {
  13119.             case 0: s = "kermit"; break;
  13120.             case 1: s = "ftp"; break;
  13121.             case 2: s = "auto"; break;
  13122.           }
  13123.           return(s);
  13124.       }
  13125. #endif /* NEWFTP */
  13126.  
  13127. #ifndef NOLOCAL
  13128.       case VN_CX_STA: {                 /* CONNECT status */
  13129.           extern int cx_status;
  13130.           return(ckitoa(cx_status));
  13131.       }
  13132. #endif /* NOLOCAL */
  13133.       case VN_NOW:                      /* Timestamp */
  13134.         return(ckcvtdate(p,0));
  13135.  
  13136.       case VN_HOUR:                     /* Hour of the day */
  13137.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  13138.         if (!p) p = "";
  13139.         if (!*p) return(p);
  13140.         vvbuf[0] = p[11];
  13141.         vvbuf[1] = p[12];
  13142.         vvbuf[2] = NUL;
  13143.         return(vvbuf);                  /* and return it */
  13144.  
  13145.       case VN_LOG_CON:            /* \v(...) for log files */
  13146. #ifdef CKLOGDIAL
  13147.         return(diafil);
  13148. #else 
  13149.         return("");
  13150. #endif
  13151.       case VN_LOG_PKT:
  13152. #ifndef NOXFER
  13153.         return(pktfil);
  13154. #else
  13155.         return("");
  13156. #endif
  13157.       case VN_LOG_SES:
  13158. #ifndef NOLOCAL
  13159.         return(sesfil);
  13160. #else
  13161.         return("");
  13162. #endif
  13163.       case VN_LOG_TRA:
  13164. #ifdef TLOG
  13165.         return(trafil);
  13166. #else
  13167.         return("");
  13168. #endif
  13169.       case VN_LOG_DEB:
  13170. #ifdef DEBUG
  13171.         return(debfil);
  13172. #else
  13173.         return("");
  13174. #endif
  13175.     }
  13176.  
  13177. #ifndef NODIAL
  13178.     switch (y) {                        /* Caller ID values */
  13179.       extern char
  13180.         * callid_date, * callid_time, * callid_name,
  13181.         * callid_nmbr, * callid_mesg;
  13182.  
  13183.       case VN_CI_DA:
  13184.         return(callid_date ? callid_date : "");
  13185.  
  13186.       case VN_CI_TI:
  13187.         return(callid_time ? callid_time : "");
  13188.  
  13189.       case VN_CI_NA:
  13190.         return(callid_name ? callid_name : "");
  13191.  
  13192.       case VN_CI_NU:
  13193.         return(callid_nmbr ? callid_nmbr : "");
  13194.  
  13195.       case VN_CI_ME:
  13196.         return(callid_mesg ? callid_mesg : "");
  13197.  
  13198.     } /* End of variable-name switches */
  13199. #endif /* NODIAL */
  13200.  
  13201. #ifdef NT
  13202.     switch (y) {
  13203.       case VN_PERSONAL:
  13204.         p = (char *)GetPersonal();
  13205.         if (p) {
  13206.             GetShortPathName(p,vvbuf,VVBUFL);
  13207.             return(vvbuf);
  13208.         }
  13209.         return("");
  13210.       case VN_DESKTOP:
  13211.           p = (char *)GetDesktop();
  13212.           if (p) {
  13213.               GetShortPathName(p,vvbuf,VVBUFL);
  13214.               return(vvbuf);
  13215.           }
  13216.           return("");
  13217.       case VN_COMMON:
  13218.         p = (char *)GetAppData(1);
  13219.         if (p) {
  13220.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  13221.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  13222.             return(vvbuf);
  13223.         }
  13224.         return("");
  13225.       case VN_APPDATA:
  13226.         p = (char *)GetAppData(0);
  13227.         if (p) {
  13228.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  13229.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  13230.             return(vvbuf);
  13231.         }
  13232.         return("");
  13233.     }
  13234. #endif /* NT */
  13235.  
  13236. #ifdef TN_COMPORT
  13237.     switch (y) {
  13238.       case VN_TNC_SIG: {
  13239.         p = (char *) tnc_get_signature();
  13240.         ckstrncpy(vvbuf,p ? p : "",VVBUFL);
  13241.         return(vvbuf);
  13242.       }
  13243.     }
  13244. #endif /* TN_COMPORT */
  13245.  
  13246. #ifdef KUI
  13247.     switch (y) {
  13248.       case VN_GUI_RUN: {
  13249.       extern HWND getHwndKUI();
  13250.       if ( IsIconic(getHwndKUI()) )
  13251.             return("minimized");
  13252.       if ( IsZoomed(getHwndKUI()) )
  13253.             return("maximized");
  13254.       return("restored");
  13255.       }
  13256.       case VN_GUI_XP:
  13257.         sprintf(vvbuf,"%d",get_gui_window_pos_x());  /* SAFE */
  13258.         return(vvbuf);
  13259.       case VN_GUI_YP:
  13260.         sprintf(vvbuf,"%d",get_gui_window_pos_y());  /* SAFE */
  13261.         return(vvbuf);
  13262.       case VN_GUI_XR:
  13263.         sprintf(vvbuf,"%d",GetSystemMetrics(SM_CXSCREEN));  /* SAFE */
  13264.         return(vvbuf);
  13265.       case VN_GUI_YR:
  13266.         sprintf(vvbuf,"%d",GetSystemMetrics(SM_CYSCREEN));  /* SAFE */
  13267.         return(vvbuf);
  13268.       case VN_GUI_FNM:
  13269.           if ( ntermfont > 0 ) {
  13270.               int i;
  13271.               for (i = 0; i < ntermfont; i++) {
  13272.                   if (tt_font == term_font[i].kwval) {
  13273.                       ckstrncpy(vvbuf,term_font[i].kwd,VVBUFL);
  13274.                       return(vvbuf);
  13275.                   }
  13276.               }
  13277.           }
  13278.           return("(unknown)");
  13279.       case VN_GUI_FSZ:
  13280.           ckstrncpy(vvbuf,ckitoa(tt_font_size/2),VVBUFL);
  13281.           if ( tt_font_size % 2 )
  13282.               ckstrncat(vvbuf,".5",VVBUFL);
  13283.           return(vvbuf);
  13284.     }
  13285. #endif /* KUI */
  13286.  
  13287.     fnsuccess = 0;
  13288.     if (fnerror) {
  13289.         fnsuccess = 0;
  13290.     }
  13291.     if (fndiags) {
  13292.         if (!embuf)
  13293.           ckstrncpy(embuf,"<ERROR:NO_SUCH_VARIABLE>",EMBUFLEN);
  13294.         printf("?%s\n",embuf);
  13295.         return((char *)embuf);
  13296.     } else
  13297.       return("");
  13298. }
  13299. #endif /* NOSPL */
  13300.  
  13301.  
  13302. /*
  13303.   X X S T R I N G  --  Expand variables and backslash codes.
  13304.  
  13305.     int xxtstring(s,&s2,&n);
  13306.  
  13307.   Expands \ escapes via recursive descent.
  13308.   Argument s is a pointer to string to expand (source).
  13309.   Argument s2 is the address of where to put result (destination).
  13310.   Argument n is the length of the destination string (to prevent overruns).
  13311.   Returns -1 on failure, 0 on success,
  13312.     with destination string null-terminated and s2 pointing to the
  13313.     terminating null, so that subsequent characters can be added.
  13314. */
  13315.  
  13316. #define XXDEPLIM 100                    /* Recursion depth limit */
  13317.  
  13318. int
  13319. zzstring(s,s2,n) char *s; char **s2; int *n; {
  13320.     int x,                              /* Current character */
  13321.         y,                              /* Worker */
  13322.         pp,                             /* Paren level */
  13323.         kp,                             /* Brace level */
  13324.         argn,                           /* Function argument counter */
  13325.         n2,                             /* Local copy of n */
  13326.         d,                              /* Array dimension */
  13327.         vbi,                            /* Variable id (integer form) */
  13328.         argl,                           /* String argument length */
  13329.         nx;                             /* Save original length */
  13330.  
  13331.     char vb,                            /* Variable id (char form) */
  13332.         *vp,                            /* Pointer to variable definition */
  13333.         *new,                           /* Local pointer to target string */
  13334. #ifdef COMMENT
  13335.         *old,                           /* Save original target pointer */
  13336. #endif /* COMMENT */
  13337.         *p,                             /* Worker */
  13338.         *q,                             /* Worker */
  13339.         *s3;                            /* Worker */
  13340.     int  x3;                            /* Worker */
  13341.     char *r  = (char *)0;               /* For holding function args */
  13342.     char *r2 = (char *)0;
  13343.     char *r3p;
  13344.  
  13345. #ifndef NOSPL
  13346. #ifdef DYNAMIC
  13347.     char * vnambuf = NULL;              /* Buffer for variable/function name */
  13348. #else /* DYNAMIC */
  13349.     char vnambuf[VNAML];                /* Buffer for variable/function name */
  13350. #endif /* DYNAMIC */
  13351.     char *argp[FNARGS];                 /* Pointers to function args */
  13352. #endif /* NOSPL */
  13353.  
  13354.     static int depth = 0;               /* Call depth, avoid overflow */
  13355.  
  13356.     n2 = *n;                            /* Make local copies of args */
  13357.     nx = n2;
  13358.  
  13359.     new = *s2;                          /* for one less level of indirection */
  13360. #ifdef COMMENT
  13361.     old = new;
  13362. #endif /* COMMENT */
  13363.  
  13364. #ifndef NOSPL
  13365.     ispattern = 0;                      /* For \fpattern() */
  13366. #endif /* NOSPL */
  13367.     depth++;                            /* Sink to a new depth */
  13368.     if (depth > XXDEPLIM) {             /* Too deep? */
  13369.         printf("?definition is circular or too deep\n");
  13370.         debug(F101,"zzstring fail","",depth);
  13371.         depth = 0;
  13372.         *new = NUL;
  13373.         return(-1);
  13374.     }
  13375.     if (!s || !new) {                   /* Watch out for null pointers */
  13376.         debug(F101,"zzstring fail 2","",depth);
  13377.         if (new)
  13378.           *new = NUL;
  13379.         depth = 0;
  13380.         return(-1);
  13381.     }
  13382.     s3 = s;
  13383.     argl = 0;
  13384.     while (*s3++) argl++;              /* Get length of source string */
  13385.     debug(F010,"zzstring entry",s,0);
  13386.     if (argl == 0) {                    /* Empty string */
  13387.         debug(F111,"zzstring empty arg",s,argl);
  13388.         depth = 0;
  13389.         *new = NUL;
  13390.         return(0);
  13391.     }
  13392.     if (argl < 0) {                     /* Watch out for garbage */
  13393.         debug(F101,"zzstring fail 3","",depth);
  13394.         *new = NUL;
  13395.         depth = 0;
  13396.         return(-1);
  13397.     }
  13398. #ifndef NOSPL
  13399. #ifdef DYNAMIC
  13400.     debug(F100,"vnambuf malloc...","",0);
  13401.     vnambuf = malloc(VNAML);
  13402.     if (vnambuf == NULL) {
  13403.         printf("?Out of memory");
  13404.         return(-1);
  13405.     }
  13406.     debug(F100,"vnambuf malloc ok","",0);
  13407. #endif /* DYNAMIC */
  13408. #endif /* NOSPL */
  13409.  
  13410.     while ((x = *s)) {                  /* Loop for all characters */
  13411.         if (x != CMDQ) {                /* Is it the command-quote char? */
  13412.             *new++ = *s++;              /* No, normal char, just copy */
  13413.             if (--n2 < 0) {             /* and count it, careful of overflow */
  13414.                 debug(F101,"zzstring overflow 1","",depth);
  13415.                 depth = 0;
  13416. #ifndef NOSPL
  13417. #ifdef DYNAMIC
  13418.                 if (vnambuf) free(vnambuf);
  13419. #endif /* DYNAMIC */
  13420. #endif /* NOSPL */
  13421.                 return(-1);
  13422.             }
  13423.             continue;
  13424.         }
  13425.  
  13426. /* We have the command-quote character. */
  13427.  
  13428.         x = *(s+1);                     /* Get the following character. */
  13429.         if (isupper(x)) x = tolower(x);
  13430.         switch (x) {                    /* Act according to variable type */
  13431. #ifndef NOSPL
  13432.           case 0:                       /* It's a lone backslash */
  13433.             *new++ = *s++;
  13434.             if (--n2 < 0) {
  13435.                 debug(F101,"zzstring overflow 2","",0);
  13436. #ifdef DYNAMIC
  13437. #ifndef NOSPL
  13438.                 if (vnambuf) free(vnambuf);
  13439. #endif /* NOSPL */
  13440. #endif /* DYNAMIC */
  13441.                 return(-1);
  13442.             }
  13443.             break;
  13444.           case '%':                     /* Variable */
  13445.             s += 2;                     /* Get the letter or digit */
  13446.             vb = *s++;                  /* and move source pointer past it */
  13447.             vp = NULL;                  /* Assume definition is empty */
  13448.             if (vb >= '0' && vb <= '9') { /* Digit for macro arg */
  13449.                 if (maclvl < 0)         /* Digit variables are global */
  13450.                   vp = g_var[vb];       /* if no macro is active */
  13451.                 else                    /* otherwise */
  13452.                   vp = m_arg[maclvl][vb - '0']; /* they're on the stack */
  13453.             } else if (vb == '*') {     /* Macro args string */
  13454. #ifdef COMMENT
  13455.                 /* This doesn't take changes into account */
  13456.                 vp = (maclvl >= 0) ? m_line[maclvl] : topline;
  13457.                 if (!vp) vp = "";
  13458. #else
  13459.         char * ss = new;
  13460.                 if (zzstring("\\fjoin(&_[],,1)",&new,&n2) < 0)
  13461.                   return(-1);
  13462.         debug(F110,"zzstring \\%*",ss,0);
  13463.                 break;
  13464. #endif /* COMMENT */
  13465.             } else {
  13466.                 if (isupper(vb)) vb += ('a'-'A');
  13467.                 vp = g_var[vb];         /* Letter for global variable */
  13468.             }
  13469.             if (!vp) vp = "";
  13470. #ifdef COMMENT
  13471.             if (vp) {                   /* If definition not empty */
  13472. #endif /* COMMENT */
  13473.                 debug(F010,"zzstring %n vp",vp,0);
  13474.                 if (zzstring(vp,&new,&n2) < 0) { /* call self to evaluate it */
  13475.                     debug(F101,"zzstring fail 6","",depth);
  13476. #ifdef DYNAMIC
  13477. #ifndef NOSPL
  13478.                     if (vnambuf) free(vnambuf);
  13479. #endif /* NOSPL */
  13480. #endif /* DYNAMIC */
  13481.                     return(-1);         /* Pass along failure */
  13482.                 }
  13483. #ifdef COMMENT
  13484.             } else {
  13485.                 debug(F110,"zzstring %n vp","(NULL)",0);
  13486.                 n2 = nx;
  13487.                 new = old;
  13488.                 *new = NUL;
  13489.             }
  13490. #endif /* COMMENT */
  13491.             break;
  13492.           case '&':                     /* An array reference */
  13493.             x = arraynam(s,&vbi,&d);    /* Get name and subscript */
  13494.             debug(F111,"zzstring arraynam",s,x);
  13495.             if (x < 0) {
  13496.                 debug(F101,"zzstring fail 7","",depth);
  13497. #ifdef DYNAMIC
  13498. #ifndef NOSPL
  13499.                 if (vnambuf) free(vnambuf);
  13500. #endif /* NOSPL */
  13501. #endif /* DYNAMIC */
  13502.                 return(-1);
  13503.             }
  13504.             pp = 0;                     /* Bracket counter */
  13505.             while (*s) {                /* Advance source pointer... */
  13506.                 if (*s == '[') pp++;
  13507.                 if (*s == ']' && --pp == 0) break;
  13508.                 s++;
  13509.             }
  13510.             if (*s == ']') s++;         /* ...past the closing bracket. */
  13511.  
  13512.             x = chkarray(vbi,d);        /* Array is declared? */
  13513.             debug(F101,"zzstring chkarray","",x);
  13514.             if (x > 0) {
  13515. #ifdef COMMENT
  13516.                 char * s1 = NULL;
  13517. #endif /* COMMENT */
  13518.                 vbi -= ARRAYBASE;       /* Convert name to index */
  13519.  
  13520. #ifdef COMMENT
  13521.                 if (vbi == 0) {         /* Argument vector array */
  13522.                     extern char ** toparg, ** m_xarg[];
  13523.                     extern int n_xarg[];
  13524.                     if (maclvl < 0) {
  13525.                         if (topargc >= d) {
  13526.                             s1 = toparg[d];
  13527.                         }
  13528.                     } else {
  13529.                         if (n_xarg[maclvl] >= d) {
  13530.                             s1 = m_xarg[maclvl][d];
  13531.                         }
  13532.                     }
  13533.                     if (s1) {
  13534.                         if (zzstring(s1,&new,&n2) < 0) { /* evaluate */
  13535.                             debug(F101,"zzstring fail 7.5","",depth);
  13536. #ifdef DYNAMIC
  13537. #ifndef NOSPL
  13538.                             if (vnambuf) free(vnambuf);
  13539. #endif /* NOSPL */
  13540. #endif /* DYNAMIC */
  13541.                             return(-1); /* Pass along failure */
  13542.                         }
  13543.                     } else {
  13544.                         /* old = new; */
  13545.                         n2 = nx;
  13546.                     }
  13547.                 } else
  13548. #endif /* COMMENT */
  13549.                   if (a_dim[vbi] >= d) {        /* If subscript in range */
  13550.                     char **ap;
  13551. #ifndef COMMENT
  13552.                     debug(F110,"zzstring a_ptr[vbi]",a_ptr[vbi],0);
  13553.                     debug(F110,"zzstring a_ptr[vbi][d]",a_ptr[vbi][d],0);
  13554. #endif /* COMMENT */
  13555.                     ap = a_ptr[vbi];    /* get data pointer */
  13556.                     if (ap) {           /* and if there is one */
  13557.                         if (ap[d]) {    /* If definition not empty */
  13558.                             debug(F111,"zzstring ap[d]",ap[d],d);
  13559.                             if (zzstring(ap[d],&new,&n2) < 0) { /* evaluate */
  13560.                                 debug(F101,"zzstring fail 8","",depth);
  13561. #ifdef DYNAMIC
  13562. #ifndef NOSPL
  13563.                                 if (vnambuf) free(vnambuf);
  13564. #endif /* NOSPL */
  13565. #endif /* DYNAMIC */
  13566.                                 return(-1); /* Pass along failure */
  13567.                             }
  13568.                         }
  13569.                     } else {
  13570.                         /* old = new; */
  13571.                         n2 = nx;
  13572.                     }
  13573.                 }
  13574.             }
  13575.             break;
  13576.  
  13577.           case 'f':                     /* A builtin function */
  13578.             q = vnambuf;                /* Copy the name */
  13579.             y = 0;                      /* into a separate buffer */
  13580.             s += 2;                     /* point past 'F' */
  13581.             while (y++ < VNAML) {
  13582.                 if (*s == '(') { s++; break; } /* Look for open paren */
  13583.                 if ((*q = *s) == NUL) break;   /* or end of string */
  13584.                 s++; q++;
  13585.             }
  13586.             *q = NUL;                   /* Terminate function name */
  13587.             if (y >= VNAML) {           /* Handle pathological case */
  13588.                 while (*s && (*s != '(')) /* of very long string entered */
  13589.                   s++;                    /* as function name. */
  13590.                 if (*s == ')') s++;       /* Skip past it. */
  13591.             }
  13592.             r = r2 = malloc(argl+2);    /* And make a place to copy args */
  13593.             /* debug(F101,"zzstring r2","",r2); */
  13594.             if (!r2) {                  /* Watch out for malloc failure */
  13595.                 debug(F101,"zzstring fail 9","",depth);
  13596.                 *new = NUL;
  13597.                 depth = 0;
  13598. #ifdef DYNAMIC
  13599. #ifndef NOSPL
  13600.                 if (vnambuf) free(vnambuf);
  13601. #endif /* NOSPL */
  13602. #endif /* DYNAMIC */
  13603.                 return(-1);
  13604.             }
  13605.             if (r3) free(r3); /* And another to copy literal arg string */
  13606.             r3 = malloc(argl+2);
  13607.             /* debug(F101,"zzstring r3","",r3); */
  13608.             if (!r3) {
  13609.                 debug(F101,"zzstring fail 10","",depth);
  13610.                 depth = 0;
  13611.                 *new = NUL;
  13612.                 if (r2) free(r2);
  13613. #ifdef DYNAMIC
  13614. #ifndef NOSPL
  13615.                 if (vnambuf) free(vnambuf);
  13616. #endif /* NOSPL */
  13617. #endif /* DYNAMIC */
  13618.                 return(-1);
  13619.             } else
  13620.               r3p = r3;
  13621.             argn = 0;                   /* Argument counter */
  13622.             argp[argn++] = r;           /* Point to first argument */
  13623.             y = 0;                      /* Completion flag */
  13624.             pp = 1;                     /* Paren level (already have one). */
  13625.             kp = 0;
  13626.             while (1) {                 /* Copy each argument, char by char. */
  13627.                 *r3p++ = *s;            /* This is a literal copy for \flit */
  13628.                 if (!*s) break;
  13629.  
  13630.                 if (*s == '{') {        /* Left brace */
  13631.                     kp++;
  13632.                 }
  13633.                 if (*s == '}') {        /* Right brace */
  13634.                     kp--;
  13635.                 }
  13636.                 if (*s == '(' && kp <= 0) { /* Open paren not in brace */
  13637.                     pp++;               /* Count it */
  13638.                 }
  13639.                 *r = *s;                /* Now copy resulting byte */
  13640.                 if (!*r)                /* If NUL, done. */
  13641.                   break;
  13642.                 if (*r == ')' && kp <= 0) { /* Closing paren, count it. */
  13643.                     if (--pp == 0) {    /* Final one? */
  13644.                         *r = NUL;       /* Make it a terminating null */
  13645.                         *(r3p - 1) = NUL;
  13646.                         s++;            /* Point past it in source string */
  13647.                         y = 1;          /* Flag we've got all the args */
  13648.                         break;          /* Done with while loop */
  13649.                     }
  13650.                 }
  13651.                 if (*r == ',' && kp <= 0) { /* Comma */
  13652.                     if (pp == 1) {          /* If not within ()'s, */
  13653.                         if (argn >= FNARGS) { /* Too many args */
  13654.                             s++; r++;   /* Keep collecting flit() string */
  13655.                             continue;
  13656.                         }
  13657.                         *r = NUL;           /* New arg, skip past comma */
  13658.                         argp[argn++] = r+1; /* In range, point to new arg */
  13659.                     }                   /* Otherwise just skip past  */
  13660.                 }
  13661.                 s++; r++;               /* Advance pointers */
  13662.             }
  13663.             if (!y)                     /* If we didn't find closing paren */
  13664.               argn = -1;
  13665. #ifdef DEBUG
  13666.             if (deblog) {
  13667.                 char buf[24];
  13668.                 debug(F111,"zzstring function name",vnambuf,y);
  13669.                 debug(F010,"zzstring function r3",r3,0);
  13670.                 for (y = 0; y < argn; y++) {
  13671.                     sprintf(buf,"arg %2d ",y);
  13672.                     debug(F010,buf,argp[y],0);
  13673.                 }
  13674.             }
  13675. #endif /* DEBUG */
  13676.             vp = fneval(vnambuf,argp,argn,r3); /* Evaluate the function. */
  13677.             if (vp) {                      /* If definition not empty */
  13678.                 while ((*new++ = *vp++)) { /* copy it to output string */
  13679.                     if (--n2 < 0) {        /* watch out for overflow */
  13680.                         debug(F101,"zzstring fail 12","",depth);
  13681.                         if (r2) { free(r2); r2 = NULL; }
  13682.                         if (r3) { free(r3); r3 = NULL; }
  13683. #ifdef DYNAMIC
  13684. #ifndef NOSPL
  13685.                         if (vnambuf) free(vnambuf);
  13686. #endif /* NOSPL */
  13687. #endif /* DYNAMIC */
  13688.                         return(-1);
  13689.                     }
  13690.                 }
  13691.                 new--;                  /* Back up over terminating null */
  13692.                 n2++;                   /* to allow for further deposits. */
  13693.             }
  13694.             if (r2) { free(r2); r2 = NULL; }
  13695.             if (r3) { free(r3); r3 = NULL; }
  13696.             break;
  13697.           case '$':                     /* An environment variable */
  13698.           case 'v':                     /* Or a named builtin variable. */
  13699.           case 'm':                     /* Or a macro /long variable */
  13700.           case 's':                     /* 196 Macro substring */
  13701.           case ':':                     /* 196 \-variable substring */
  13702.             pp = 0;
  13703.             p = s+2;                    /* $/V/M must be followed by (name) */
  13704.             if (*p != '(') {            /* as in \$(HOME) or \V(count) */
  13705.                 *new++ = *s++;          /* If not, just copy it */
  13706.                 if (--n2 < 0) {
  13707.                     debug(F101,"zzstring overflow 3","",depth);
  13708. #ifdef DYNAMIC
  13709. #ifndef NOSPL
  13710.                     if (vnambuf) free(vnambuf);
  13711. #endif /* NOSPL */
  13712. #endif /* DYNAMIC */
  13713.                     return(-1);
  13714.                 }
  13715.                 break;
  13716.             }
  13717.             pp++;
  13718.             p++;                        /* Point to 1st char of name */
  13719.             q = vnambuf;                /* Copy the name */
  13720.             y = 0;                      /* into a separate buffer */
  13721.             while (y++ < VNAML) {       /* Watch out for name too long */
  13722.                 if (*p == '(') {        /* Parens can be nested... */
  13723.                     pp++;
  13724.                 } else if (*p == ')') { /* Name properly terminated with ')' */
  13725.                     pp--;
  13726.                     if (pp == 0) {
  13727.                         p++;            /* Move source pointer past ')' */
  13728.                         break;
  13729.                     }
  13730.                 }
  13731.                 if ((*q = *p) == NUL)   /* String ends before ')' */
  13732.                   break;
  13733.                 p++; q++;               /* Advance pointers */
  13734.             }
  13735.             *q = NUL;                   /* Terminate the variable name */
  13736.             if (y >= VNAML) {           /* Handle pathological case */
  13737.                 while (*p && (*p != ')')) /* of very long string entered */
  13738.                   p++;                    /* as variable name. */
  13739.                 if (*p == ')') p++;       /* Skip ahead to the end of it. */
  13740.             }
  13741.             s = p;                      /* Adjust global source pointer */
  13742.             s3 = vnambuf;
  13743.             x3 = 0;
  13744.             while (*s3++) x3++;
  13745.             p = malloc(x3 + 1);         /* Make temporary space */
  13746.             if (p) {                    /* If we got the space */
  13747.                 vp = vnambuf;           /* Point to original */
  13748.                 strcpy(p,vp);           /* (safe) Make a copy of it */
  13749.                 y = VNAML;              /* Length of name buffer */
  13750.                 zzstring(p,&vp,&y);     /* Evaluate the copy */
  13751.                 free(p);                /* Free the temporary space */
  13752.                 p = NULL;
  13753.             }
  13754.             debug(F110,"zzstring vname",vnambuf,0);
  13755.             q = NULL;
  13756.             if (x == '$') {             /* Look up its value */
  13757.                 vp = getenv(vnambuf);   /* This way for environment variable */
  13758.             } else if (x == 'm' || x == 's' || x == ':') { /* Macro / substr */
  13759.                 int k, x1 = -1, x2 = -1;
  13760.                 k = strlen(vnambuf);
  13761.                 /* \s(name[n:m]) -- Compact substring notation */
  13762.                 if ((x == 's' || x == ':') && (k > 1)) { /* Substring wanted */
  13763.                     if (vnambuf[k-1] == ']') {
  13764.                         int i;
  13765.                         for (i = k-1; i > 0; i--) {
  13766.                             if (vnambuf[i] == '[') {
  13767.                                 char * p = NULL;
  13768.                                 p = (char *)malloc(k - i + 8);
  13769.                                 if (p) {
  13770.                                     /* Now this is a dirty trick... */
  13771.                                     ckmakmsg(p,
  13772.                                              k-i+8,
  13773.                                              "\\&a",
  13774.                                              &vnambuf[i],
  13775.                                              NULL,
  13776.                                              NULL
  13777.                                              );
  13778.                                     arraybounds(p,&x1,&x2);
  13779.                                     if (x1 < 1) x1 = 1;
  13780.                                     x1--; /* Adjust to 0-base */
  13781.                                     free(p);
  13782.                                     vnambuf[i] = NUL;
  13783.                                 }
  13784.                             }
  13785.                         }
  13786.                     }
  13787.                 }
  13788.                 if (x == ':') {
  13789.                     vp = vnambuf;
  13790.                 } else {
  13791.                     y = mxlook(mactab,vnambuf,nmac); /* get definition */
  13792.                     if (y > -1) {               /* Got definition */
  13793.                         vp = mactab[y].mval;
  13794.                     } else {
  13795.                         vp = NULL;
  13796.                     }
  13797.                 }
  13798.                 if (vp) {
  13799.                     if ((x == 's' || x == ':') && (k > 1)) {
  13800.                         /* Compact substring notation */
  13801.                         if (x2 == 0) {  /* Length */
  13802.                             vp = NULL;
  13803.                         } else if (x1 > -1) { /* Start */
  13804.                             k = strlen(vp);
  13805.                             if (x1 > k) {  /* If it's off the end, */
  13806.                                 vp = NULL; /* result is empty */
  13807.                             } else if (k > 0) {
  13808.                                 if ((q = malloc(k+1))) {
  13809.                                     strcpy(q,vp); /* safe */
  13810.                                     if ((x2 > -1) && ((x1 + x2) <= k)) {
  13811.                                         q[x1+x2] = NUL;
  13812.                                     }
  13813.                                     vp = q+x1;
  13814.                                 }  else vp = NULL;
  13815.                             } else vp = NULL;
  13816.                         }
  13817. #ifdef DEBUG
  13818.                         if (deblog) {
  13819.                             if (!vp) {
  13820.                             } else {
  13821.                                 k = strlen(vp);
  13822.                             }
  13823.                         }
  13824. #endif /* DEBUG */
  13825.                     }
  13826.                 }
  13827.             } else {                    /* or */
  13828.                 vp = nvlook(vnambuf);   /* this way for builtin variable */
  13829.             }
  13830.             if (vp) {                   /* If definition not empty */
  13831.                 while ((*new++ = *vp++)) /* copy it to output string. */
  13832.                   if (--n2 < 0) {
  13833.                       if (q) free(q);
  13834.                       debug(F101,"zzstring overflow 4","",depth);
  13835. #ifdef DYNAMIC
  13836. #ifndef NOSPL
  13837.                       if (vnambuf) free(vnambuf);
  13838. #endif /* NOSPL */
  13839. #endif /* DYNAMIC */
  13840.                       return(-1);
  13841.                   }
  13842.                 new--;                  /* Back up over terminating null */
  13843.                 n2++;                   /* to allow for further deposits. */
  13844.             }
  13845.             if (q) {
  13846.                 free(q);
  13847.                 q = NULL;
  13848.             }
  13849.             break;
  13850. #endif /* NOSPL */                      /* Handle \nnn even if NOSPL. */
  13851.  
  13852. #ifndef NOKVERBS
  13853.         case 'K':
  13854.         case 'k': {
  13855.             extern struct keytab kverbs[];
  13856.             extern int nkverbs;
  13857. #define K_BUFLEN 30
  13858.             char kbuf[K_BUFLEN + 1];    /* Key verb name buffer */
  13859.             int x, y, z, brace = 0;
  13860.             s += 2;
  13861. /*
  13862.   We assume that the verb name is {braced}, or it extends to the end of the
  13863.   string, s, or it ends with a space, control character, or backslash.
  13864. */
  13865.             p = kbuf;                   /* Copy verb name into local buffer */
  13866.             x = 0;
  13867.             if (*s == '{')  {
  13868.                 s++;
  13869.                 brace++;
  13870.             }
  13871.             while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  13872.                 if (brace && *s == '}') {
  13873.                     s++;
  13874.                     break;
  13875.                 }
  13876.                 *p++ = *s++;
  13877.             }
  13878.             brace = 0;
  13879.             *p = NUL;                   /* Terminate. */
  13880.             p = kbuf;                   /* Point back to beginning */
  13881.             debug(F110,"zzstring kverb",p,0);
  13882.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  13883.             debug(F101,"zzstring lookup",0,y);
  13884.             if (y > -1) {
  13885.                 dokverb(VCMD,y);
  13886. #ifndef NOSPL
  13887.             } else {                    /* Is it a macro? */
  13888.                 y = mxlook(mactab,p,nmac);
  13889.                 if (y > -1) {
  13890.                     debug(F111,"zzstring mxlook",p,y);
  13891.                     if ((z = dodo(y,NULL,cmdstk[cmdlvl].ccflgs)) > 0) {
  13892.                         if (cmpush() > -1) {  /* Push command parser state */
  13893.                             extern int ifc;
  13894.                             int ifcsav = ifc; /* Push IF condition on stack */
  13895.                             y = parser(1);    /* New parser to execute macro */
  13896.                             cmpop();          /* Pop command parser */
  13897.                             ifc = ifcsav;     /* Restore IF condition */
  13898.                             if (y == 0) {     /* No errors, ignore actions */
  13899.                                 p = mrval[maclvl+1]; /* If OK set return val */
  13900.                                 if (p == NULL) p = "";
  13901.                             }
  13902.                         } else {                /* Can't push any more */
  13903.                             debug(F101,"zzstring pushed too deep","",depth);
  13904.                             printf(
  13905.                                "\n?Internal error: zzstring stack overflow\n"
  13906.                                    );
  13907.                             while (cmpop() > -1);
  13908.                             p = "";
  13909.                         }
  13910.                     }
  13911.                 }
  13912. #endif /* NOSPL */
  13913.             }
  13914.             break;
  13915.         }
  13916. #endif /* NOKVERBS */
  13917.  
  13918.         default:                        /* Maybe it's a backslash code */
  13919.           y = xxesc(&s);                /* Go interpret it */
  13920.           if (y < 0) {                  /* Upon failure */
  13921.               *new++ = (char) x;        /* Just quote the next character */
  13922.               s += 2;                   /* Move past the pair */
  13923.               n2 -= 2;
  13924.               if (n2 < 0) {
  13925.                   debug(F101,"zzstring overflow 5","",depth);
  13926. #ifdef DYNAMIC
  13927. #ifndef NOSPL
  13928.                   if (vnambuf) free(vnambuf);
  13929. #endif /* NOSPL */
  13930. #endif /* DYNAMIC */
  13931.                   return(-1);
  13932.               }
  13933.               continue;                 /* and go back for more */
  13934.           } else {
  13935.               *new++ = (char) y;        /* else deposit interpreted value */
  13936.               if (--n2 < 0) {
  13937.                   debug(F101,"zzstring overflow 6","",depth);
  13938. #ifdef DYNAMIC
  13939. #ifndef NOSPL
  13940.                   if (vnambuf) free(vnambuf);
  13941. #endif /* NOSPL */
  13942. #endif /* DYNAMIC */
  13943.                   return(-1);
  13944.               }
  13945.           }
  13946.         }
  13947.     }
  13948.     *new = NUL;                         /* Terminate the new string */
  13949.     debug(F010,"zzstring while exit",*s2,0);
  13950.  
  13951.     depth--;                            /* Adjust stack depth gauge */
  13952.     *s2 = new;                          /* Copy results back into */
  13953.     *n = n2;                            /* the argument addresses */
  13954.     debug(F101,"zzstring ok","",depth);
  13955. #ifdef DYNAMIC
  13956. #ifndef NOSPL
  13957.     if (vnambuf) free(vnambuf);
  13958. #endif /* NOSPL */
  13959. #endif /* DYNAMIC */
  13960.     return(0);                          /* and return. */
  13961. }
  13962. #endif /* NOICP */
  13963.