home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku201.zip / ckuus4.c < prev    next >
C/C++ Source or Header  |  2002-02-06  |  477KB  |  13,764 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. extern xx_strp xxstring;
  72.  
  73. #ifdef DEC_TCPIP
  74. #include <descrip>
  75. #include <dvidef>
  76. #include <dcdef>
  77. #endif /* DEC_TCPIP */
  78.  
  79. #ifdef FNFLOAT
  80. #include <math.h>                       /* Floating-point functions */
  81. #endif /* FNFLOAT */
  82.  
  83. extern int quiet, network, xitsta, escape, nopush, xferstat,
  84.   exitonclose, tn_exit, ttnproto, autodl, flow, byteorder, what, lastxfer;
  85.  
  86. extern int filepeek, nscanfile, makestrlen;
  87. extern char * k_info_dir;
  88.  
  89. #ifndef MAC
  90. #ifndef AMIGA
  91. extern int ttyfd;
  92. #endif /* MAC */
  93. #endif /* AMIGA */
  94.  
  95. #ifdef TNCODE
  96. extern int tn_nlm, tn_b_nlm, tn_b_xfer, tn_sb_bug;
  97. extern int tn_rem_echo;
  98. extern int tn_b_meu, tn_b_ume;
  99. #endif /* TNCODE */
  100.  
  101. char * xferfile = NULL;
  102. int xferlog = 0;
  103.  
  104. extern int local, xargc, stayflg, rcflag, bgset, backgrd, cfilef,
  105.   inserver, srvcdmsg, success;
  106.  
  107. #ifdef VMS
  108. extern int batch;
  109. #endif /* VMS */
  110.  
  111. extern char cmdfil[], *versio, *ckxsys, **xargv;
  112. #ifdef DEBUG
  113. extern char debfil[];                   /* Debug log file name */
  114. extern int debtim;
  115. #endif /* DEBUG */
  116.  
  117. extern int noinit;
  118.  
  119. static char ndatbuf[10];
  120.  
  121. char *months[] = {
  122.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  123.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  124. };
  125.  
  126. char *
  127. zzndate() {                             /* Returns today's date as yyyymmdd */
  128.     char * p;
  129.     int x;
  130.  
  131. /* WARNING - This will fail if asctime() returns non-English month names */
  132.  
  133.     ztime(&p);                          /* Get "asctime" string */
  134.     if (p == NULL || *p == NUL) return("");
  135.     for (x = 20; x < 24; x++)           /* yyyy */
  136.       ndatbuf[x - 20] = p[x];
  137.     ndatbuf[6] = (char) ((p[8] == ' ') ? '0' : p[8]);
  138.     ndatbuf[7] = p[9];                  /* dd */
  139.     for (x = 0; x < 12; x++)            /* mm */
  140.       if (!strncmp(p+4,months[x],3)) break;
  141.     if (x == 12) {
  142.         ndatbuf[4] = ndatbuf[5] = '?';
  143.     } else {
  144.         x++;
  145.         ndatbuf[4] = (char) ((x < 10) ? '0' : '1');
  146.         ndatbuf[5] = (char) ((x % 10) + 48);
  147.     }
  148.     ndatbuf[8] = NUL;
  149.     return((char *)ndatbuf);
  150. }
  151.  
  152. #ifdef DCMDBUF
  153. extern struct cmdptr *cmdstk;
  154. extern char *line, *tmpbuf;
  155. #else
  156. extern struct cmdptr cmdstk[];
  157. extern char line[], tmpbuf[];
  158. #endif /* DCMDBUF */
  159.  
  160. #ifdef OS2
  161. extern char exedir[];
  162. #else
  163. extern char * exedir;
  164. #endif /* OS2 */
  165.  
  166. extern int nettype;
  167.  
  168. #ifndef NOICP                           /* Most of this file... */
  169.  
  170. #ifndef AMIGA
  171. #ifndef MAC
  172. #include <signal.h>
  173. #endif /* MAC */
  174. #endif /* AMIGA */
  175.  
  176. #ifdef STRATUS                          /* Stratus Computer, Inc.  VOS */
  177. #ifdef putchar
  178. #undef putchar
  179. #endif /* putchar */
  180. #define putchar(x) conoc(x)
  181. #ifdef getchar
  182. #undef getchar
  183. #endif /* getchar */
  184. #define getchar(x) coninc(0)
  185. #endif /* STRATUS */
  186.  
  187.  
  188. #ifdef ANYX25
  189. extern int revcall, closgr, cudata;
  190. int x25ver;
  191. extern char udata[];
  192. #ifndef IBMX25
  193. extern int npadx3;
  194. extern CHAR padparms[];
  195. extern struct keytab padx3tab[];
  196. #endif /* !IBMX25 */
  197. #ifdef IBMX25
  198. /* global variables only available for IBM X.25 - possibly interesting for
  199.  * other implementations
  200.  */
  201. extern x25addr_t local_nua;
  202. extern x25addr_t remote_nua;
  203. #endif /* IBMX25 */
  204. #endif /* ANYX25 */
  205.  
  206. #ifdef NETCONN
  207. #ifndef NODIAL
  208. extern int nnetdir;
  209. extern char *netdir[];
  210. #endif /* NODIAL */
  211. extern char ipaddr[];
  212.  
  213. #ifdef CK_NETBIOS
  214. extern unsigned short netbiosAvail;
  215. extern unsigned long NetbeuiAPI;
  216. extern unsigned char NetBiosName[];
  217. extern unsigned char NetBiosAdapter;
  218. extern unsigned char NetBiosLSN;
  219. #endif /* CK_NETBIOS */
  220.  
  221. #ifdef TCPSOCKET
  222. extern char myipaddr[];
  223. extern int tcp_rdns;
  224. #ifdef CK_DNS_SRV
  225. extern int tcp_dns_srv;
  226. #endif /* CK_DNS_SRV */
  227. extern char * tcp_address;
  228. #ifndef NOHTTP
  229. extern char * tcp_http_proxy;
  230. #endif /* NOHTTP */
  231. #ifdef NT
  232. #ifdef CK_SOCKS
  233. extern char * tcp_socks_svr;
  234. #ifdef CK_SOCKS_NS
  235. extern char * tcp_socks_ns;
  236. #endif /* CK_SOCKS_NS */
  237. #endif /* CK_SOCKS */
  238. #endif /* NT */
  239.  
  240. #ifndef NOTCPOPTS
  241. #ifdef SOL_SOCKET
  242. #ifdef SO_LINGER
  243. extern int tcp_linger;
  244. extern int tcp_linger_tmo;
  245. #endif /* SO_LINGER */
  246. #ifdef SO_DONTROUTE
  247. extern int tcp_dontroute;
  248. #endif /* SO_DONTROUTE */
  249. #ifdef TCP_NODELAY
  250. extern int tcp_nodelay;
  251. #endif /* TCP_NODELAY */
  252. #ifdef SO_SNDBUF
  253. extern int tcp_sendbuf;
  254. #endif /* SO_SNDBUF */
  255. #ifdef SO_RCVBUF
  256. extern int tcp_recvbuf;
  257. #endif /* SO_RCVBUF */
  258. #ifdef SO_KEEPALIVE
  259. extern int tcp_keepalive;
  260. #endif /* SO_KEEPALIVE */
  261. #endif /* SOL_SOCKET */
  262. #endif /* NOTCPOPTS */
  263. #endif /* TCPSOCKET */
  264. #endif /* NETCONN */
  265.  
  266. extern char * floname[];
  267.  
  268. #ifndef NOSPL
  269. extern int fndiags;                     /* Function diagnostics on/off */
  270. extern int divbyzero;
  271. int ispattern = 0;
  272. #ifdef CK_APC
  273. extern int apcactive;                   /* Nonzero = APC command was rec'd */
  274. extern int apcstatus;                   /* Are APC commands being processed? */
  275. #ifdef DCMDBUF
  276. extern char *apcbuf;                    /* APC command buffer */
  277. #else
  278. extern char apcbuf[];
  279. #endif /* DCMDBUF */
  280. #endif /* CK_APC */
  281.  
  282. extern char evalbuf[];                  /* EVALUATE result */
  283. extern char uidbuf[], pwbuf[], prmbuf[];
  284. _PROTOTYP( static char * fneval, (char *, char * [], int, char * ) );
  285. _PROTOTYP( static VOID myflsh, (void) );
  286. _PROTOTYP( static char * getip, (char *) );
  287. _PROTOTYP( int delta2sec, (char *, long *) );
  288.  
  289. #ifdef NEWFTP
  290. _PROTOTYP( char * ftp_cpl_mode, (void) );
  291. _PROTOTYP( char * ftp_dpl_mode, (void) );
  292. _PROTOTYP( char * ftp_authtype, (void) );
  293. #endif /* NEWFTP */
  294.  
  295. #ifndef NOHTTP
  296. _PROTOTYP( char * http_host, (void) );
  297. _PROTOTYP( int http_isconnected, (void) );
  298. _PROTOTYP( char * http_security, (void) );
  299. #endif /* NOHTTP */
  300.  
  301. #ifndef NOSEXP
  302. _PROTOTYP( char * dosexp, (char *) );
  303. int fsexpflag = 0;
  304. #endif /* NOSEXP */
  305.  
  306. static char hexdigits[16] = {
  307.     '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  308. };
  309. extern char * tempdir;
  310.  
  311. #ifdef CK_REXX
  312. extern char rexxbuf[];
  313. #endif /* CK_REXX */
  314.  
  315. extern int tfline[];
  316.  
  317. /* These need to be internationalized... */
  318.  
  319. static
  320. char *wkdays[] = {
  321.     "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  322. };
  323. #endif /* NOSPL */
  324.  
  325. #ifdef OS2
  326. extern char startupdir[], inidir[];
  327. #else
  328. #ifdef VMSORUNIX
  329. extern char startupdir[];
  330. #endif /* VMSORUNIX */
  331. #endif /* OS2 */
  332.  
  333. #ifdef OS2
  334. _PROTOTYP (int os2getcp, (void) );
  335. #ifdef TCPSOCKET
  336. extern char tcpname[];
  337. #endif /* TCPSOCKET */
  338. extern int tcp_avail;
  339. #ifdef DECNET
  340. extern int dnet_avail;
  341. #endif /* DECNET */
  342. #ifdef SUPERLAT
  343. extern int slat_avail;
  344. #endif /* SUPERLAT */
  345.  
  346. #ifndef NOTERM
  347. extern int tt_type, max_tt;
  348. extern struct tt_info_rec tt_info[];
  349. #endif /* NOTERM */
  350. extern int tt_rows[], tt_cols[];
  351. #else /* OS2 */
  352. extern int tt_rows, tt_cols;
  353. #endif /* OS2 */
  354.  
  355. #ifdef CK_TAPI
  356. extern int tttapi;
  357. extern int tapipass;
  358. extern struct keytab * tapilinetab;
  359. extern struct keytab * _tapilinetab;
  360. extern int ntapiline;
  361. #endif /* CK_TAPI */
  362.  
  363. extern struct keytab colxtab[];
  364. extern int ncolx;
  365.  
  366. extern char ttname[], *zinptr, *kermrc;
  367. extern char inidir[];
  368.  
  369. extern int activecmd, remonly, cmd_rows, cmd_cols, parity, seslog,
  370.   sessft, sosi, hwparity, tsecs, xargs, zincnt, tlevel, insilence, cmdmsk,
  371.   timint, timef, inbufsize, dialog, binary, carrier, cdtimo, cmask, duplex,
  372.   fmask, inecho, nmac, turnch, turn, kbchar;
  373.  
  374. #ifndef NOXFER
  375. extern CHAR eol,  mypadc, mystch, padch, seol, stchr, * epktmsg, feol;
  376. extern char *cksysid;
  377. extern struct ck_p ptab[];
  378. extern int
  379.   protocol, prefixing, xfrbel, xfrcan, xfrint, xfrchr, xfrnum, pktpaus,
  380.   lscapr, lscapu, xfermode, dest, slostart, maxrps, maxsps, maxtry, mypadn,
  381.   npad, pkttim, bigrbsiz, bigsbsiz, keep, atcapr, autopar, bctr, bctu,
  382.   crunched, ckdelay, ebq, ebqflg, pktlog, retrans, rpackets, rptflg, rptq,
  383.   rtimo, spackets, spsiz, spsizf, spsizr, timeouts, fncact, fncnv, urpsiz,
  384.   wmax, wslotn, wslotr, fdispla, spmax, fnrpath, fnspath, crc16;
  385. #endif /* NOXFER */
  386.  
  387. #ifdef OS2
  388. extern int zxpn;
  389. extern int viewonly;
  390. #endif /* OS2 */
  391.  
  392. #ifndef NOXFER
  393. #ifdef GFTIMER
  394. extern CKFLOAT fptsecs, fpxfsecs;
  395. #endif /* GFTIMER */
  396. extern long xfsecs, tfcps;
  397.  
  398. #ifdef CK_TMPDIR
  399. extern char *dldir;
  400. #endif /* CK_TMPDIR */
  401. #endif /* NOXFER */
  402.  
  403. #ifdef RECURSIVE
  404. extern int recursive;
  405. #endif /* RECURSIVE */
  406.  
  407. #ifdef VMS
  408.   extern int frecl;
  409. #endif /* VMS */
  410.  
  411. extern long
  412.   ffc, filcnt, rptn, speed, tfc, tlci, tlco, ccu, ccp, vernum, xvernum;
  413.  
  414. #ifndef NOSPL
  415. extern char fspec[], myhost[];
  416. #endif /* NOSPL */
  417.  
  418. extern char *tfnam[];                   /* Command file names */
  419.  
  420. extern char pktfil[],                   /* Packet log file name */
  421. #ifdef TLOG
  422.   trafil[],                             /* Transaction log file name */
  423. #endif /* TLOG */
  424.   sesfil[];                             /* Session log file name */
  425.  
  426. #ifndef NOXMIT                          /* TRANSMIT command variables */
  427. extern char xmitbuf[];
  428. extern int xmitf, xmitl, xmitx, xmits, xmitw, xmitt;
  429. #endif /* NOXMIT */
  430.  
  431. extern int cmdlvl;
  432.  
  433. #ifndef NOSPL
  434. /* Script programming language items */
  435. extern char **a_ptr[];                  /* Arrays */
  436. extern int a_dim[];
  437. static char * inpmatch = NULL;
  438. extern char * inpbuf, inchar[];         /* Buffers for INPUT and REINPUT */
  439. extern char *inpbp;                     /* And pointer to same */
  440. static char *r3 = (char *)0;
  441. extern int incount;                     /* INPUT character count */
  442. extern int m_found;                     /* MINPUT result */
  443. extern int maclvl;                      /* Macro invocation level */
  444. extern struct mtab *mactab;             /* Macro table */
  445. extern char *mrval[];
  446. extern int macargc[], topargc;
  447.  
  448. #ifdef COMMENT
  449. extern char *m_line[];
  450. extern char *topline;
  451. #endif /* COMMENT */
  452.  
  453. extern char *m_arg[MACLEVEL][10]; /* You have to put in the dimensions */
  454. extern char *g_var[GVARS];        /* for external 2-dimensional arrays. */
  455. #ifdef DCMDBUF
  456. extern int *count, *inpcas;
  457. #else
  458. extern int count[], inpcas[];
  459. #endif /* DCMDBUF */
  460. #endif /* NOSPL */
  461.  
  462. #ifdef UNIX
  463. extern int haslock;                     /* For UUCP locks */
  464. extern char flfnam[];
  465. #ifndef USETTYLOCK
  466. extern char lock2[];
  467. #endif /* USETTYLOCK */
  468. #endif /* UNIX */
  469.  
  470. #ifdef OS2ORUNIX
  471. extern int maxnam, maxpath;             /* Longest name, path length */
  472. #endif /* OS2ORUNIX */
  473.  
  474. extern int mdmtyp, mdmsav;
  475.  
  476. #ifndef NODIAL
  477. /* DIAL-related variables */
  478. extern char modemmsg[];
  479. extern MDMINF *modemp[];                /* Pointers to modem info structs */
  480. extern int nmdm, dialhng, dialtmo, dialksp, dialdpy, dialsrt, dialsta;
  481. extern int dialrtr, dialint, dialrstr, dialcon, dialcq, dialfld;
  482. extern int mdmspd, dialec, dialdc, dialmth, dialmauto, dialesc;
  483. extern char *dialnum,   *dialini,  *dialdir[], *dialcmd,  *dialnpr,
  484.  *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd, *diallac,
  485.  *dialhwfc, *dialswfc,  *dialnofc, *dialpulse, *dialtone, *dialname,
  486.  *dialaaon, *dialaaoff, *dialmac;
  487. extern char *diallcc,   *dialixp,  *dialixs,   *dialldp,  *diallds,
  488.  *dialpxi,  *dialpxo,   *dialsfx,  *dialtfp;
  489. extern char *diallcp,   *diallcs;
  490. extern int ntollfree, ndialpxx, nlocalac;
  491. extern char *dialtfc[], *diallcac[], *dialpxx[], *matchpxx;
  492. extern int ndialpucc, ndialtocc;
  493. extern char *dialtocc[], *dialpucc[];
  494. extern int ndialdir, dialcnf, dialcvt, dialidt, dialpace;
  495. extern long dialmax, dialcapas;
  496.  
  497. extern struct keytab mdmtab[];
  498.  
  499. #ifdef BIGBUFOK
  500. #define ARGBUFSIZ 8191
  501. #else
  502. #define ARGBUFSIZ 1023
  503. #endif /* BIGBUFOK */
  504.  
  505. #ifdef BIGBUFOK
  506. extern char * dialmsg[];
  507. #endif /* BIGBUFOK */
  508.  
  509. #endif /* NODIAL */
  510.  
  511. #ifndef NOCSETS
  512. /* Translation stuff */
  513. extern int fcharset, tcharset, tslevel, language, nlng, tcsr, tcsl;
  514. extern int dcset7, dcset8;
  515. extern struct keytab lngtab[];
  516. extern struct csinfo fcsinfo[], tcsinfo[];
  517. extern struct langinfo langs[];
  518. #ifdef CK_ANSIC
  519. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  520. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  521. #else
  522. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(); /* Character set */
  523. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(); /* translation functions. */
  524. #endif /* CK_ANSIC */
  525. #ifdef UNICODE
  526.     extern int ucsbom, ucsorder;
  527. #endif /* UNICODE */
  528. #endif /* NOCSETS */
  529.  
  530. #ifndef NOSPL
  531. /* Built-in variable names, maximum length VNAML (20 characters) */
  532.  
  533. struct keytab vartab[] = {
  534.     { "_line",     VN_TFLN,  CM_INV},   /* 192 */
  535. #ifdef OS2
  536.     { "_regname",  VN_REGN,  CM_INV},   /* 1.1.12 */
  537.     { "_regorg",   VN_REGO,  CM_INV},   /* 1.1.12 */
  538.     { "_regnum",   VN_REGS,  CM_INV},   /* 1.1.12 */
  539. #endif /* OS2 */
  540.     { "apcactive", VN_APC,   CM_INV},   /* 192 */
  541. #ifdef NT
  542.     { "appdata",   VN_APPDATA, 0},      /* 201 */
  543. #endif /* NT */
  544.     { "argc",      VN_ARGC,  0},
  545.     { "args",      VN_ARGS,  0},
  546.     { "authname",  VN_AUTHN, 0},        /* 196 */
  547.     { "authstate", VN_AUTHS, 0},        /* 195 */
  548.     { "authtype",  VN_AUTHT, 0},        /* 195 */
  549.     { "blockcheck",VN_BLK,   0},        /* 195 */
  550. #ifdef BROWSER
  551.     { "browser",   VN_BROWSR,0},        /* 193 */
  552.     { "browsopts", VN_BROPT, 0},        /* 193 */
  553.     { "browsurl",  VN_URL,   0},        /* 193 */
  554.     { "buildid",   VN_BUILD, 0},        /* 199 */
  555. #endif /* BROWSER */
  556.     { "byteorder", VN_BYTE,  0},        /* 195 */
  557. #ifndef NOCSETS
  558.     { "charset",   VN_CSET,  0},        /* 192 */
  559. #endif /* NOCSETS */
  560.     { "cmdbufsize",VN_CMDBL, 0},        /* 195 */
  561.     { "cmdfile",   VN_CMDF,  0},
  562.     { "cmdlevel",  VN_CMDL,  0},
  563.     { "cmdsource", VN_CMDS,  0},
  564.     { "cols",      VN_COLS,  0},        /* 190 */
  565. #ifdef NT
  566.     { "common",    VN_COMMON, 0},       /* 201 */
  567. #endif /* NT */
  568.     { "connection",VN_CONN,  0},        /* 190 */
  569.     { "count",     VN_COUN,  0},
  570. #ifndef NOXFER
  571.     { "cps",       VN_CPS,   0},        /* 190 */
  572. #endif /* NOXFER */
  573.     { "cpu",       VN_CPU,   0},
  574. #ifndef NOXFER
  575.     { "crc16",     VN_CRC16, 0},        /* 192 */
  576.     { "ctty",      VN_TTYNAM,0},        /* 196 */
  577. #endif /* NOXFER */
  578. #ifndef NOLOGDIAL
  579. #ifndef NOLOCAL
  580.     { "cx_time",   VN_CXTIME,0},        /* 195 */
  581.     { "cx_status", VN_CX_STA,0},        /* 199 */
  582. #endif /* NOLOCAL */
  583. #endif /* NOLOGDIAL */
  584. #ifndef NODIAL
  585.     { "d$ac",      VN_D_AC,  0},        /* 192 */
  586.     { "d$cc",      VN_D_CC,  0},        /* 192 */
  587.     { "d$ip",      VN_D_IP,  0},        /* 192 */
  588.     { "d$lc",      VN_D_LCP, 0},        /* 193 */
  589.     { "d$lcp",     VN_D_LCP, CM_INV},   /* 193 */
  590.     { "d$lp",      VN_D_LP,  0},        /* 192 */
  591.     { "d$px",      VN_D_PXX, 0},        /* 195 */
  592.     { "d$pxx",     VN_D_PXX, CM_INV},   /* 195 */
  593. #endif /* NODIAL */
  594.     { "date",      VN_DATE,  0},
  595.     { "day",       VN_DAY,   0},
  596. #ifndef NODIAL
  597.     { "dialcount", VN_DRTR,  0},        /* 195 */
  598.     { "dialnumber",VN_DNUM,  0},        /* 192 */
  599.     { "dialresult",VN_MDMSG, 0},        /* 192 */
  600.     { "dialstatus",VN_DIAL,  0},        /* 190 */
  601.     { "dialsuffix",VN_PDSFX, 0},        /* 193 */
  602.     { "dialtype",  VN_DTYPE, 0},        /* 193 */
  603. #endif /* NODIAL */
  604.     { "directory", VN_DIRE,  0},
  605. #ifndef NODIAL
  606.     { "dm_hf",     VN_DM_HF, 0},        /* 199 */
  607.     { "dm_lp",     VN_DM_LP, 0},        /* 195 */
  608.     { "dm_sp",     VN_DM_SP, 0},        /* 195 */
  609.     { "dm_pd",     VN_DM_PD, 0},        /* 195 */
  610.     { "dm_td",     VN_DM_TD, 0},        /* 195 */
  611.     { "dm_wa",     VN_DM_WA, 0},        /* 195 */
  612.     { "dm_wb",     VN_DM_WB, 0},        /* 199 */
  613.     { "dm_wd",     VN_DM_WD, 0},        /* 195 */
  614.     { "dm_rc",     VN_DM_RC, 0},        /* 195 */
  615. #endif /* NODIAL */
  616. #ifndef NOXFER
  617.     { "download",  VN_DLDIR, 0},        /* 192 */
  618. #endif /* NOXFER */
  619.     { "editor",    VN_EDITOR,0},
  620.     { "editfile",  VN_EDFILE,0},
  621.     { "editopts",  VN_EDOPT, 0},
  622.     { "errno",     VN_ERRNO, 0},        /* 192 */
  623.     { "errstring", VN_ERSTR, 0},        /* 192 */
  624.     { "escape",    VN_ESC,   0},        /* 193 */
  625.     { "evaluate",  VN_EVAL,  0},        /* 190 */
  626. #ifdef OS2ORUNIX
  627.     { "exedir",    VN_EXEDIR,0},        /* 192 */
  628. #endif /* OS2ORUNIX */
  629.     { "exitstatus",VN_EXIT,  0},
  630. #ifdef CKCHANNELIO
  631.     { "f_count",   VN_FCOU,  0},        /* 195 */
  632.     { "f_error",   VN_FERR,  0},        /* 195 */
  633.     { "f_max",     VN_FMAX,  0},        /* 195 */
  634.     { "fileerror", VN_FERR,  CM_INV},   /* 195 */
  635.     { "filemax",   VN_FERR,  CM_INV},   /* 195 */
  636. #endif /* CKCHANNELIO */
  637.     { "filename",  VN_FNAM,  0},        /* 193 */
  638.     { "filenumber",VN_FNUM,  0},        /* 193 */
  639.     { "filespec",  VN_FILE,  0},
  640.     { "fsize",     VN_FFC,   0},        /* 190 */
  641. #ifdef GFTIMER
  642.     { "ftime",     VN_FTIME, 0},        /* 199 */
  643. #else
  644.     { "ftime",     VN_NTIM,  CM_INV},
  645. #endif /* GFTIMER */
  646. #ifndef NOFTP
  647. #ifndef SYSFTP
  648.     { "ftp_code",         VN_FTP_C, 0}, /* 199 */
  649.     { "ftp_cpl",          VN_FTP_B, 0}, /* 199 */
  650.     { "ftp_connected",    VN_FTP_X, 0}, /* 199 */
  651.     { "ftp_dpl",          VN_FTP_D, 0}, /* 199 */
  652.     { "ftp_getputremote", VN_FTP_G, 0}, /* 199 */
  653.     { "ftp_host",         VN_FTP_H, 0}, /* 199 */
  654.     { "ftp_loggedin",     VN_FTP_L, 0}, /* 199 */
  655.     { "ftp_message",      VN_FTP_M, 0}, /* 199 */
  656.     { "ftp_msg",          VN_FTP_M, CM_INV}, /* 199 */
  657.     { "ftp_security",     VN_FTP_Z, 0}, /* 199 */
  658.     { "ftp_server",       VN_FTP_S, 0}, /* 199 */
  659. #endif /* SYSFTP */
  660. #endif /* NOFTP */
  661.     { "ftype",     VN_MODE,  0},        /* 190 */
  662.     { "herald",    VN_HERALD,0},
  663.     { "home",      VN_HOME,  0},
  664.     { "host",      VN_HOST,  0},
  665.     { "hour",      VN_HOUR,  0},        /* 200 */
  666. #ifndef NOHTTP
  667.     { "http_code",      VN_HTTP_C, 0},  /* 199 */
  668.     { "http_connected", VN_HTTP_N, 0},  /* 199 */
  669.     { "http_host",      VN_HTTP_H, 0},  /* 199 */
  670.     { "http_message",   VN_HTTP_M, 0},  /* 199 */
  671.     { "http_security",  VN_HTTP_S, 0},  /* 199 */
  672. #endif /* NOHTTP */
  673.     { "hwparity",  VN_HWPAR, 0},        /* 195 */
  674.     { "input",     VN_IBUF,  0},
  675.     { "inchar",    VN_ICHR,  0},
  676.     { "incount",   VN_ICNT,  0},
  677.     { "inidir",    VN_INI,   0},        /* 192 */
  678.     { "inmatch",   VN_MATCH, 0},        /* 196 */
  679.     { "instatus",  VN_ISTAT, 0},        /* 192 */
  680.     { "intime",    VN_INTIME,0},        /* 193 */
  681.     { "inwait",    VN_INTMO, 0},        /* 195 */
  682.     { "ip",        VN_IPADDR, CM_ABR|CM_INV},
  683.     { "ipaddress", VN_IPADDR,0},        /* 192 */
  684.     { "iprompt",   VN_PROMPT,0},        /* 199 */
  685.     { "kbchar",    VN_KBCHAR,0},        /* 196 */
  686. #ifndef NOLOCAL
  687. #ifdef OS2
  688.     { "keyboard",  VN_KEYB,  0},
  689. #endif /* OS2 */
  690. #endif /* NOLOCAL */
  691. #ifdef CK_KERBEROS
  692.     { "krb4errmsg",    VN_K4EMSG,0},
  693.     { "krb4errno",     VN_K4ENO, 0},
  694.     { "krb4principal", VN_K4PRN, 0},
  695.     { "krb4realm",     VN_K4RLM, 0},
  696.     { "krb4service",   VN_K4SRV, 0},
  697.     { "krb5cc",        VN_K5CC,  0},
  698.     { "krb5errmsg",    VN_K5EMSG,0},
  699.     { "krb5errno",     VN_K5ENO, 0},
  700.     { "krb5principal", VN_K5PRN, 0},
  701.     { "krb5realm",     VN_K5RLM, 0},
  702.     { "krb5service",   VN_K5SRV, 0},
  703. #endif /* CK_KERBEROS */
  704.     { "line",      VN_LINE,  0},
  705.     { "local",     VN_LCL,   0},
  706. #ifdef UNIX
  707.     { "lockdir",   VN_LCKDIR,0},        /* 195 */
  708.     { "lockpid",   VN_LCKPID,0},        /* 195 */
  709. #endif /* UNIX */
  710.     { "maclevel",  VN_MACLVL,0},        /* 195 */
  711.     { "macro",     VN_MAC,   0},
  712. #ifdef FNFLOAT
  713.     { "math_e",    VN_MA_E,  0},        /* 195 */
  714.     { "math_pi",   VN_MA_PI, 0},        /* 195 */
  715.     { "math_precision", VN_MA_PR, 0},   /* 195 */
  716. #endif /* FNFLOAT */
  717.     { "minput",    VN_MINP,  0},        /* 192 */
  718.     { "model",     VN_MODL,  0},        /* 193 */
  719.     { "modem",     VN_MDM,   0},
  720. #ifndef NOLOCAL
  721. #ifdef OS2
  722.     { "mousecurx", VN_MOU_X, 0},        /* K95 1.1.14 */
  723.     { "mousecury", VN_MOU_Y, 0},        /* K95 1.1.14 */
  724. #endif /* OS2 */
  725. #endif /* NOLOCAL */
  726. #ifndef NODIAL
  727.     { "m_aa_off",  VN_M_AAX, 0},        /* all 192... */
  728.     { "m_aa_on",   VN_M_AAO, 0},
  729.     { "m_dc_off",  VN_M_DCX, 0},
  730.     { "m_dc_on",   VN_M_DCO, 0},
  731.     { "m_dial",    VN_M_DCM, 0},
  732.     { "m_ec_off",  VN_M_ECX, 0},
  733.     { "m_ec_on",   VN_M_ECO, 0},
  734.     { "m_fc_hw",   VN_M_HWF, 0},
  735.     { "m_fc_no",   VN_M_NFC, 0},
  736.     { "m_fc_sw",   VN_M_SWF, 0},
  737.     { "m_hup",     VN_M_HUP, 0},
  738.     { "m_init",    VN_M_INI, 0},
  739.     { "m_name",    VN_M_NAM, 0},        /* 195 */
  740.     { "m_pulse",   VN_M_PDM, 0},
  741.     { "m_sig_cd",  VN_MS_CD, 0},        /* 195 */
  742.     { "m_sig_cts", VN_MS_CTS,0},        /* 195 */
  743.     { "m_sig_dsr", VN_MS_DSR,0},        /* 195 */
  744.     { "m_sig_dtr", VN_MS_DTR,0},        /* 195 */
  745.     { "m_sig_ri",  VN_MS_RI, 0},        /* 195 */
  746.     { "m_sig_rts", VN_MS_RTS,0},        /* 195 */
  747.     { "m_tone",    VN_M_TDM, 0},
  748. #endif /* NODIAL */
  749.     { "name",      VN_NAME,  0},
  750.     { "ndate",     VN_NDAT,  0},
  751.     { "nday",      VN_NDAY,  0},
  752.     { "newline",   VN_NEWL,  0},
  753.     { "ntime",     VN_NTIM,  0},
  754.     { "osname",    VN_OSNAM, 0},        /* 193 */
  755.     { "osrelease", VN_OSREL, 0},        /* 193 */
  756.     { "osversion", VN_OSVER, 0},        /* 193 */
  757. #ifndef NOXFER
  758.     { "packetlen", VN_RPSIZ, 0},        /* 192 */
  759. #endif /* NOXFER */
  760.     { "parity",    VN_PRTY,  0},        /* 190 */
  761.     { "password",  VN_PWD,   CM_INV},   /* 192 */
  762. #ifdef NT
  763.     { "personal",  VN_PERSONAL, 0},     /* 201 */
  764. #endif /* NT */
  765. #ifdef PEXITSTAT
  766.     { "pexitstat", VN_PEXIT, 0},        /* 193 */
  767. #endif /* PEXITSTAT */
  768. #ifdef CK_PID
  769.     { "pid",       VN_PID,   0},        /* 193 */
  770. #endif /* CK_PID */
  771.     { "platform",  VN_SYSV,  0},
  772.     { "printer",   VN_PRINT, 0},        /* 193 */
  773.     { "program",   VN_PROG,  0},
  774.     { "prompt",    VN_PRM,   CM_INV},   /* 192 */
  775. #ifndef NOXFER
  776.     { "protocol",  VN_PROTO, 0},        /* 192 */
  777.     { "p_8bit",    VN_P_8BIT,0},        /* 193 */
  778.     { "p_ctl",     VN_P_CTL, 0},        /* 193 */
  779.     { "p_rpt",     VN_P_RPT, 0},        /* 193 */
  780.     { "query",     VN_QUE,   0},        /* 190 */
  781. #endif /* NOXFER */
  782.     { "return",    VN_RET,   0},
  783. #ifdef CK_REXX
  784.     { "rexx",      VN_REXX,  0},        /* 190 */
  785. #endif /* CK_REXX */
  786.     { "rows",      VN_ROWS,  0},        /* 190 */
  787. #ifndef NOSEXP
  788.     { "sdepth",    VN_LSEXP,0},         /* 199 */
  789. #endif /* NOSEXP */
  790.     { "secure",    VN_SECURE, 0},       /* 199 */
  791. #ifndef NOLOCAL
  792. #ifdef OS2
  793.     { "select",    VN_SELCT, 0},        /* 192 */
  794. #endif /* OS2 */
  795. #endif /* NOLOCAL */
  796.     { "sendlist",  VN_SNDL,  0},
  797.     { "serial",    VN_SERIAL,0},        /* 195 */
  798.     { "setlinemsg",VN_SLMSG, 0},        /* 195 */
  799. #ifndef NOSEXP
  800.     { "sexpression",VN_SEXP, 0},        /* 199 */
  801. #endif /* NOSEXP */
  802.     { "speed",     VN_SPEE,  0},
  803. #ifdef OS2
  804.     { "space",     VN_SPA,   0},
  805.     { "startup",   VN_STAR,  0},        /* 190 */
  806. #else
  807. #ifdef UNIX
  808.     { "startup",   VN_STAR,  0},        /* 193 */
  809. #else
  810. #ifdef VMS
  811.     { "startup",   VN_STAR,  0},        /* 193 */
  812. #endif /* VMS */
  813. #endif /* UNIX */
  814. #endif /* OS2 */
  815.     { "status",    VN_SUCC,  0},
  816. #ifndef NOSEXP
  817.     { "svalue",    VN_VSEXP, 0},        /* 199 */
  818. #endif /* NOSEXP */
  819. #ifndef NOXFER
  820.     { "sysid",     VN_SYSI,  0},
  821. #endif /* NOXFER */
  822.     { "system",    VN_SYST,  0},
  823.     { "terminal",  VN_TTYP,  0},
  824. #ifdef OS2
  825. #ifndef NOKVERBS
  826.     { "termkey",   VN_TRMK,  CM_INV},   /* 192 */
  827. #endif /* NOKVERBS */
  828. #endif /* OS2 */
  829.     { "test",      VN_TEST,  0},        /* 193 */
  830.     { "textdir",   VN_TXTDIR,0},        /* 195 */
  831. #ifndef NOXFER
  832.     { "tfsize",    VN_TFC,   0},
  833.     { "tftime",    VN_TFTIM, 0},        /* 195 */
  834. #endif /* NOXFER */
  835.     { "time",      VN_TIME,  0},
  836.     { "timestamp", VN_NOW,   0},        /* 200 */
  837.     { "tmpdir",    VN_TEMP,  0},        /* 192 */
  838. #ifdef CK_TRIGGER
  839.     { "trigger",   VN_TRIG,  0},        /* 193 */
  840. #endif /* CK_TRIGGER */
  841. #ifdef CK_TTYFD
  842.     { "ttyfd",     VN_TTYF,  0},
  843. #endif /* CK_TTYFD */
  844.     { "ty_ln",     VN_TY_LN, 0},        /* 195 */
  845.     { "ty_lc",     VN_TY_LC, 0},        /* 195 */
  846.     { "ty_lm",     VN_TY_LM, 0},        /* 195 */
  847. #ifdef BROWSER
  848.     { "url",       VN_URL,   CM_INV},   /* 193 */
  849. #endif /* BROWSER */
  850.     { "userid",    VN_UID,   0},        /* 192 */
  851.     { "version",   VN_VERS,  0},
  852. #ifndef NOXFER
  853.     { "window",    VN_WINDO, 0},        /* 192 */
  854. #endif /* NOXFER */
  855. #ifdef IBMX25
  856.     { "x25local_nua", VN_X25LA, 0},     /* 193 */
  857.     { "x25remote_nua", VN_X25RA, 0},    /* 193 */
  858. #endif /* IBMX25 */
  859. #ifdef CK_SSL
  860.     { "x509_issuer",  VN_X509_I, 0},
  861.     { "x509_subject", VN_X509_S, 0},
  862. #endif /* CK_SSL */
  863. #ifndef NOXFER
  864.     { "xferstatus",VN_XFSTAT,0},        /* 193 */
  865.     { "xfermsg",   VN_XFMSG, 0},        /* 193 */
  866.     { "xfer_badpackets", VN_XF_BC, 0},  /* 195 */
  867.     { "xfer_timeouts",   VN_XF_TM, 0},  /* 195 */
  868.     { "xfer_retransmits",VN_XF_RX, 0},  /* 195 */
  869. #endif /* NOXFER */
  870.     { "xprogram",  VN_XPROG, 0},        /* 193 */
  871.     { "xversion",  VN_XVNUM, 0}         /* 192 */
  872. };
  873. int nvars = (sizeof(vartab) / sizeof(struct keytab));
  874. #endif /* NOSPL */
  875.  
  876. #ifndef NOSPL
  877. struct keytab fnctab[] = {              /* Function names */
  878. #ifdef OS2
  879.     { ".oox",       FN_OOX, CM_INV},    /* ... */
  880. #endif /* OS2 */
  881.  
  882. #ifdef CKCHANNELIO
  883.     { "_eof",       FN_FEOF,   0},
  884.     { "_errmsg",    FN_FERMSG, 0},
  885.     { "_getblock",  FN_FGBLK,  0},
  886.     { "_getchar",   FN_FGCHAR, 0},
  887.     { "_getline",   FN_FGLINE, 0},
  888.     { "_handle",    FN_FILNO,  0},
  889.     { "_line",      FN_NLINE,  0},
  890.     { "_pos",       FN_FPOS,   0},
  891.     { "_putblock",  FN_FPBLK,  0},
  892.     { "_putchar",   FN_FPCHAR, 0},
  893.     { "_putline",   FN_FPLINE, 0},
  894.     { "_status",    FN_FSTAT,  0},
  895. #endif /* CKCHANNELIO */
  896.  
  897.     { "aaconvert",  FN_AADUMP, 0},      /* Associative Array conversion */
  898.     { "absolute",   FN_ABS,  0},        /* Absolute value */
  899. #ifdef TCPSOCKET
  900.     { "addr2name",  FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  901.     { "addrtoname", FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  902. #endif /* TCPSOCKET */
  903.     { "arraylook",  FN_ALOOK,0},        /* Array lookup */
  904.     { "b64decode",  FN_FMB64,0},        /* Base-64 conversion */
  905.     { "b64encode",  FN_TOB64,0},        /* ... */
  906.     { "basename",   FN_BSN,  0},        /* Basename */
  907.     { "break",      FN_BRK,  0},        /* Break (as in Snobol) */
  908.     { "ca",         FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  909.     { "cap",        FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  910.     { "capitalize", FN_CAP,  0},        /* First Letter -> uppercase */
  911.     { "caps",       FN_CAP,  CM_INV},   /* ditto */
  912.     { "character",  FN_CHR,  0},        /* Character from code */
  913.     { "checksum",   FN_CHK,  0},        /* Checksum */
  914.     { "cmdstack",   FN_CMDSTK,0},       /* Command stack */
  915.     { "cmpdates",   FN_CMPDATE,0},      /* Compare dates */
  916.     { "code",       FN_COD,  0},        /* Code from character */
  917. #ifndef NOPUSH
  918.     { "command",    FN_CMD,  0},        /* Output from a command */
  919. #endif /* NOPUSH */
  920.     { "contents",   FN_CON,  0},        /* Definition (contents) of variable */
  921.     { "crc16",      FN_CRC,  0},        /* CRC-16 */
  922. #ifdef OS2
  923.     { "crypt",      FN_CRY, CM_INV},
  924. #endif /* OS2 */
  925.     { "cvtdate",    FN_DTIM, 0},        /* Convert free date/time to std */
  926. #ifdef ZFCDAT
  927.     { "date",       FN_FD,   0},        /* File modification/creation date */
  928. #endif /* ZFCDAT */
  929.     { "day",        FN_DAY,  0},        /* Day of week */
  930.     { "dayofyear",  FN_JDATE,0},        /* Date to Day of Year */
  931.     { "definition", FN_DEF,  0},        /* Return definition of given macro */
  932.     { "delta2secs", FN_DELSEC, 0},      /* Delta time to seconds */
  933.     { "deltatosecs", FN_DELSEC, CM_INV}, /* Delta time to seconds */
  934. #ifndef NODIAL
  935.     { "dialconvert",FN_PNCVT,0},        /* Convert portable phone number */
  936. #endif /* NODIAL */
  937.     { "diffdates",  FN_DIFDATE,0},      /* Difference of two date-times */
  938.     { "dimension",  FN_DIM,  0},        /* Dimension of array */
  939.     { "directories",FN_DIR,  0},        /* List of directories */
  940.     { "dirname",    FN_DNAM, 0},        /* Directory part of filename */
  941.     { "dos2unixpath",FN_PC_DU, },       /* DOS to UNIX path */
  942.     { "dostounixpath",FN_PC_DU, CM_INV}, /* DOS to UNIX path */
  943.     { "doy",        FN_JDATE,CM_INV},   /* Date to Day of Year */
  944.     { "doy2date",   FN_DATEJ,0},        /* Day of Year to date */
  945.     { "doytodate",  FN_DATEJ,CM_INV},   /* Day of Year to date */
  946. #ifdef FN_ERRMSG
  947.     { "errstring",  FN_ERRMSG,0},       /* Error code to message */
  948. #endif /* FN_ERRMSG */
  949.     { "evaluate",   FN_EVA,  0},        /* Evaluate given arith expression */
  950.     { "execute",    FN_EXE,  0},        /* Execute given macro */
  951.     { "files",      FN_FC,   0},        /* File count */
  952. #ifdef FNFLOAT
  953.     { "fpabsolute", FN_FPABS, 0},       /* Floating-point absolute value */
  954.     { "fpadd",      FN_FPADD, 0},       /* FP add */
  955.     { "fpcosine",   FN_FPCOS, 0},       /* FP cosine */
  956.     { "fpdivide",   FN_FPDIV, 0},       /* FP divide */
  957.     { "fpexp",      FN_FPEXP, 0},       /* FP e to the x */
  958.     { "fpint",      FN_FPINT, 0},       /* FP to integer */
  959.     { "fplog10",    FN_FPLOG, 0},       /* FP base-10 logarithm */
  960.     { "fplogn",     FN_FPLN,  0},       /* FP natural logarithm */
  961.     { "fpmaximum",  FN_FPMAX, 0},       /* FP maxinum */
  962.     { "fpminimum",  FN_FPMIN, 0},       /* FP mininum */
  963.     { "fpmodulus",  FN_FPMOD, 0},       /* FP modulus */
  964.     { "fpmultiply", FN_FPMUL, 0},       /* FP multiply */
  965.     { "fpraise",    FN_FPPOW, 0},       /* FP raise to a power */
  966.     { "fpround",    FN_FPROU, 0},       /* FP round */
  967.     { "fpsine",     FN_FPSIN, 0},       /* FP sine */
  968.     { "fpsqrt",     FN_FPSQR, 0},       /* FP square root */
  969.     { "fpsubtract", FN_FPSUB, 0},       /* FP subtract */
  970.     { "fptangent",  FN_FPTAN, 0},       /* FP tangent */
  971. #endif /* FNFLOAT */
  972.     { "hex2ip",     FN_HEX2IP,0},       /* Hex to IP address */
  973.     { "hextoip",    FN_HEX2IP,CM_INV},  /* Hex to IP address */
  974.     { "hex2n",      FN_HEX2N, CM_INV},  /* Hex to decimal number */
  975.     { "hexify",     FN_HEX,   0},       /* Hexify (string) */
  976.     { "index",      FN_IND,   0},       /* Index (string search) */
  977.     { "ip2hex",     FN_IP2HEX,0},       /* IP address to hex */
  978.     { "iptohex",    FN_IP2HEX,CM_INV},  /* IP address to hex */
  979.     { "ipaddress",  FN_IPA,   0},       /* Find and return IP address */
  980.     { "jdate",      FN_JDATE, CM_INV},  /* Date to Day of Year */
  981.     { "join",       FN_JOIN,  0},       /* Join array elements */
  982.     { "keywordvalue",  FN_KWVAL, 0},    /* Keyword=Value */
  983. #ifdef CK_KERBEROS
  984.     { "krbflags",      FN_KRB_FG, 0},   /* Kerberos functions */
  985.     { "krbisvalid",    FN_KRB_IV, 0},
  986.     { "krbnextticket", FN_KRB_NX, 0},
  987.     { "krbtickets",    FN_KRB_TK, 0},
  988.     { "krbtimeleft",   FN_KRB_TT, 0},
  989. #endif /* CK_KERBEROS */
  990.     { "left",       FN_LEF,  0},        /* Leftmost n characters of string */
  991.     { "length",     FN_LEN,  0},        /* Return length of argument */
  992.     { "literal",    FN_LIT,  0},        /* Return argument literally */
  993.     { "lop",        FN_STL,  0},        /* Lop */
  994.     { "lower",      FN_LOW,  0},        /* Return lowercased argument */
  995.     { "lpad",       FN_LPA,  0},        /* Return left-padded argument */
  996.     { "ltrim",      FN_LTR,  0},        /* Left-Trim */
  997.     { "maximum",    FN_MAX,  0},        /* Return maximum of two arguments */
  998.     { "minimum",    FN_MIN,  0},        /* Return minimum of two arguments */
  999.     { "mjd",        FN_MJD,  0},        /* Date to Modified Julian Date */
  1000.     { "mjd2date",   FN_MJD2, 0},        /* MJD to Date */
  1001.     { "mjdtodate",  FN_MJD2, CM_INV},   /* MJD to Date */
  1002.     { "modulus",    FN_MOD,  0},        /* Return modulus of two arguments */
  1003. #ifdef COMMENT
  1004.     { "msleep",     FN_MSLEEP,0},       /* Sleep for n milliseconds */
  1005. #endif /* COMMENT */
  1006.     { "n2hex",      FN_2HEX, CM_INV},   /* Number to hex */
  1007.     { "n2octal",    FN_2OCT, CM_INV},   /* Number to octal */
  1008.     { "n2time",     FN_N2TIM,0},        /* Number to hh:mm:ss */
  1009. #ifdef TCPSOCKET
  1010.     { "name2addr",  FN_HSTNAM,CM_INV},  /* Hostname to IP Address */
  1011. #endif /* TCPSOCKET */
  1012.     { "nday",       FN_NDAY, 0},        /* Numeric day of week */
  1013.     { "nextfile",   FN_FIL,  0},        /* Next file in list */
  1014.     { "ntime",      FN_NTIM, 0},        /* Time to seconds since midnight */
  1015.     { "ntohex",     FN_2HEX, CM_INV},   /* Number to hex */
  1016.     { "ntooctal",   FN_2OCT, CM_INV},   /* Number to octal */
  1017.     { "ntotime",    FN_N2TIM,CM_INV},   /* Number to hh:mm:ss */
  1018.     { "oct2n",      FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1019.     { "octton",     FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1020.     { "pathname",   FN_FFN,  0},        /* Full file name */
  1021.     { "pattern",    FN_PATTERN, 0},     /* Pattern (for INPUT) */
  1022. #ifdef CK_PERMS
  1023.     { "permissions",FN_PERM, 0},        /* Permissions of file */
  1024. #else
  1025.     { "permissions",FN_PERM, CM_INV},   /* Permissions of file */
  1026. #endif /* CK_PERMS */
  1027.     { "radix",      FN_RADIX,0},        /* Radix conversion */
  1028. #ifndef NORANDOM
  1029.     { "random",     FN_RAND, 0},        /* Random number */
  1030. #endif /* NORANDOM */
  1031. #ifndef NOPUSH
  1032.     { "rawcommand", FN_RAW,  0},        /* Output from a command (raw) */
  1033. #endif /* NOPUSH */
  1034. #ifdef RECURSIVE
  1035.     { "rdirectories", FN_RDIR, 0},      /* Recursive directory list */
  1036.     { "rfiles",       FN_RFIL, 0},      /* Recursive file list */
  1037. #endif /* RECURSIVE */
  1038.     { "rep",        FN_REP, CM_INV|CM_ABR},
  1039.     { "repeat",     FN_REP,  0},        /* Repeat argument given # of times */
  1040.     { "replace",    FN_RPL,  0},        /* Replace characters in string */
  1041.     { "reverse",    FN_REV,  0},        /* Reverse the argument string */
  1042.     { "right",      FN_RIG,  0},        /* Rightmost n characters of string */
  1043.     { "rindex",     FN_RIX,  0},        /* Right index */
  1044.     { "rpad",       FN_RPA,  0},        /* Right-pad the argument */
  1045.     { "rsearch",    FN_RSEARCH, 0},     /* R-L Search for pattern in string */
  1046. #ifdef OS2
  1047.     { "scrncurx",   FN_SCRN_CX,  0},    /* Screen Cursor X Pos */
  1048.     { "scrncury",   FN_SCRN_CY,  0},    /* Screen Cursor Y Pos */
  1049.     { "scrnstr",    FN_SCRN_STR, 0},    /* Screen String */
  1050. #endif /* OS2 */
  1051.     { "search",     FN_SEARCH, 0},      /* L-R Search for pattern in string */
  1052. #ifndef NOSEXP
  1053.     { "sexpression",FN_SEXP, 0},        /* S-Expression */
  1054. #endif /* NOSEXP */
  1055.     { "size",       FN_FS,   0},        /* File size */
  1056. #ifdef COMMENT
  1057.     { "sleep",      FN_SLEEP,0},        /* Sleep for n seconds */
  1058. #endif /* COMMENT */
  1059.     { "span",       FN_SPN,  0},        /* Span - like Snobol */
  1060.     { "split",      FN_SPLIT,0},        /* Split string into words */
  1061.     { "stripb",     FN_STB,  0},        /* Strip enclosing braces/brackets */
  1062.     { "stripn",     FN_STN,  0},        /* Strip n chars */
  1063.     { "stripx",     FN_STX,  0},        /* Strip suffix */
  1064.     { "su",         FN_SUB,  CM_INV|CM_ABR},
  1065.     { "sub",        FN_SUB,  CM_INV|CM_ABR},
  1066.     { "subs",       FN_SUB,  CM_INV|CM_ABR},
  1067.     { "subst",      FN_SUB,  CM_INV|CM_ABR},
  1068.     { "substitute", FN_SUBST,0},        /* Substitute chars */
  1069.     { "substring",  FN_SUB,  0},        /* Extract substring from argument */
  1070.     { "tablelook",  FN_TLOOK,0},        /* Table lookup */
  1071.     { "time",       FN_TIME, 0},        /* Free-format time to hh:mm:ss */
  1072.     { "tod2secs",   FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1073.     { "todtosecs",  FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1074.     { "trim",       FN_TRM,  0},        /* Trim */
  1075.     { "unhexify",   FN_UNH,  0},        /* Unhexify */
  1076.     { "unix2dospath",FN_PC_UD, 0},      /* UNIX to DOS path */
  1077.     { "unixtodospath",FN_PC_UD, CM_INV}, /* UNIX to DOS path */
  1078.     { "upper",      FN_UPP,  0},        /* Return uppercased argument */
  1079.     { "utcdate",    FN_TOGMT,0},        /* Date-time to UTC (GMT) */
  1080.     { "verify",     FN_VER,  0},        /* Verify */
  1081.     { "word",       FN_WORD, 0},        /* Extract a word */
  1082.     { "", 0, 0}
  1083. };
  1084. int nfuncs = (sizeof(fnctab) / sizeof(struct keytab)) - 1;
  1085. #endif /* NOSPL */
  1086.  
  1087. #ifndef NOSPL                           /* Buffer for expansion of */
  1088. #ifdef BIGBUFOK                         /* built-in variables. */
  1089. #define VVBUFL 1024
  1090. #else
  1091. #define VVBUFL 256
  1092. #endif /* BIGBUFOK */
  1093. char vvbuf[VVBUFL+1];
  1094. #endif /* NOSPL */
  1095.  
  1096. struct keytab disptb[] = {              /* Log file disposition */
  1097.     { "append",    1,  0},
  1098.     { "new",       0,  0}
  1099. };
  1100.  
  1101. #ifdef CKFLOAT
  1102.  
  1103. /* I N I T F L O A T  --  Deduce floating-point precision by inspection */
  1104.  
  1105. int fp_rounding = 0;                /* Nonzero if printf("%f") rounds */
  1106. int fp_digits = 0;                  /* Digits of floating point precision */
  1107.  
  1108. #ifdef COMMENT
  1109. /* For looking at internal floating-point representations */
  1110. static char fp_xbuf[128];
  1111. static char *
  1112. tohex(s, n) CHAR * s; int n; {
  1113.     int x;
  1114.     char * p = fp_xbuf;
  1115.     while (n-- > 0) {
  1116.         x = (*s >> 4) & 0x0f;
  1117.         *p++ = hexdigits[x];
  1118.         x = *s++ & 0x0f;
  1119.         *p++ = hexdigits[x];
  1120.     }
  1121.     *p = NUL;
  1122.     return((char *)fp_xbuf);
  1123. }
  1124. #endif /* COMMENT */
  1125.  
  1126. char math_pi[] = "3.1415926535897932384626433832795";
  1127. char math_e[] =  "2.7182818284590452353602874713527";
  1128.  
  1129. VOID
  1130. initfloat() {
  1131.     char * buf = NULL;
  1132.     int i, x, y;
  1133. /*
  1134.   We malloc a big temporary buffer for sprintf() to minimize likelihood of
  1135.   (and damage from) sprintf buffer overflows.  In any case, the only way this
  1136.   could happen would be if sprintf() itself had bugs, since the format
  1137.   descriptor says to cut it off at 250 decimal places.
  1138. */
  1139.     if ((buf = (char *)malloc(4096))) {
  1140.         sprintf(buf,"%0.250f",(10.0 / 3.0));
  1141.         for (i = 2; i < 250 && buf[i] == '3'; i++) ;
  1142.         x = i - 1;
  1143.         debug(F111,"initfloat 10.0/3.0",buf,x);
  1144.         sprintf(buf,"%0.250f",(4.0 / 9.0));
  1145.         for (i = 2; i < 250 && buf[i] == '4'; i++) ;
  1146.         y = i - 1;
  1147.         debug(F111,"initfloat 4.0/9.0",buf,y);
  1148.         fp_digits = (x < y) ? x : y;
  1149.         if (fp_digits < sizeof(math_pi) - 1) {
  1150.             math_pi[fp_digits+1] = NUL;
  1151.             math_e[fp_digits+1] = NUL;
  1152.         }
  1153.         sprintf(buf,"%0.6f",(7.0 / 9.0));
  1154.         if (buf[7] == '8') fp_rounding = 1;
  1155.         debug(F111,"initfloat 7.0/9.0",buf,fp_rounding);
  1156.         debug(F101,"initfloat precision","",fp_digits);
  1157.         free(buf);
  1158.     }
  1159. }
  1160. #endif /* CKFLOAT */
  1161.  
  1162. /*
  1163.   P R E S C A N -- A quick look through the command-line options for
  1164.   items that must be handled before the initialization file is executed.
  1165. */
  1166. #ifdef NT
  1167. extern int StartedFromDialer;
  1168. #endif /* NT */
  1169. #ifdef OS2
  1170. extern int k95stdio;
  1171. unsigned long startflags = 0L;
  1172. #endif /* OS2 */
  1173.  
  1174. static char *
  1175. findinpath(arg) char * arg; {
  1176. #ifdef OS2
  1177.     char * scriptenv, * keymapenv;
  1178.     int len;
  1179. #endif /* OS2 */
  1180. #ifdef DCMDBUF
  1181.     extern char * cmdbuf;
  1182. #else
  1183.     extern char cmdbuf[];
  1184. #endif /* DCMDBUF */
  1185.     char takepath[4096];
  1186.     char * s;
  1187.     int x, z;
  1188.  
  1189.     /* Set up search path... */
  1190. #ifdef OS2
  1191.     char * appdata0 = NULL, *appdata1 = NULL;
  1192. #ifdef NT
  1193.     scriptenv = getenv("K95SCRIPTS");
  1194.     keymapenv = getenv("K95KEYMAPS");
  1195.     makestr(&appdata0,(char *)GetAppData(0));
  1196.     makestr(&appdata1,(char *)GetAppData(1));
  1197. #else /* NT */
  1198.     scriptenv = getenv("K2SCRIPTS");
  1199.     keymapenv = getenv("K2KEYMAPS");
  1200. #endif /* NT */
  1201.     if (!scriptenv)
  1202.       scriptenv = getenv("CK_SCRIPTS");
  1203.     if (!scriptenv)
  1204.       scriptenv = "";
  1205.     if (!keymapenv)
  1206.       keymapenv = getenv("CK_KEYMAPS");
  1207.     if (!keymapenv)
  1208.       keymapenv = "";
  1209.  
  1210.     debug(F110,"startupdir",startupdir,0);
  1211.     debug(F110,"common appdata directory",appdata1,0);
  1212.     debug(F110,"appdata directory",appdata0,0);
  1213.     debug(F110,"inidir",inidir,0);
  1214.     debug(F110,"home",zhome(),0);
  1215.     debug(F110,"exedir",exedir,0);
  1216.  
  1217.     len = strlen(scriptenv) + strlen(keymapenv) + 3*strlen(startupdir)
  1218.         + 3*strlen(inidir) + 3*strlen(zhome()) + 3*strlen(exedir)
  1219.         + (appdata0 ? 3*strlen(appdata0) : 0) 
  1220.         + (appdata1 ? 3*strlen(appdata1) : 0)
  1221.         + 6*strlen("SCRIPTS/") + 6*strlen("KEYMAPS/") + 16;
  1222.  
  1223.     if (len >= 4096) {                  /* SAFE (length is checked) */
  1224.         takepath[0] = '\0';
  1225.         debug(F111,"findinpath error - path length too long","len",len);
  1226.     } else
  1227.       sprintf(takepath,
  1228.               /* semicolon-separated path list */
  1229.     "%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",
  1230.               scriptenv,
  1231.               (scriptenv[0] && scriptenv[strlen(scriptenv)-1]==';')?"":";",
  1232.               keymapenv,
  1233.               (keymapenv[0] && keymapenv[strlen(keymapenv)-1]==';')?"":";",
  1234.               startupdir,
  1235.               startupdir, "SCRIPTS/",
  1236.               startupdir, "KEYMAPS/",
  1237.               appdata1 ? appdata1 : "", 
  1238.               appdata1 ? "Kermit 95;" : "",
  1239.               appdata1 ? appdata1 : "",
  1240.               appdata1 ? "Kermit 95/SCRIPTS/;" : "",
  1241.               appdata1 ? appdata1 : "",
  1242.               appdata1 ? "Kermit 95/KEYMAPS/;" : "",
  1243.               appdata0 ? appdata0 : "",
  1244.               appdata0 ? "Kermit 95;" : "",
  1245.               appdata0 ? appdata0 : "",
  1246.               appdata0 ? "Kermit 95/SCRIPTS/;" : "",
  1247.               appdata0 ? appdata0 : "",
  1248.               appdata0 ? "Kermit 95/KEYMAPS/;" : "",
  1249.               inidir,
  1250.               inidir, "SCRIPTS/",
  1251.               inidir, "KEYMAPS/",
  1252.               zhome(),
  1253.               zhome(), "SCRIPTS/",
  1254.               zhome(), "KEYMAPS/",
  1255.               exedir,
  1256.               exedir, "SCRIPTS/",
  1257.               exedir, "KEYMAPS/"
  1258.               );
  1259. #ifdef NT
  1260.     makestr(&appdata0,NULL);
  1261.     makestr(&appdata1,NULL);
  1262. #endif /* NT */
  1263. #else /* not OS2 */
  1264. #ifndef NOSPL
  1265.     z = 1024;                           /* Look in home directory */
  1266.     s = takepath;
  1267.     zzstring("\\v(home)",&s,&z);
  1268. #else
  1269.     takepath[0] = '\0';
  1270. #endif /* NOSPL */
  1271. #endif /* OS2 */
  1272. /*
  1273.   All the logic for searching the take path is in the command parser.
  1274.   So even though we aren't parsing commands, we initialize and call the
  1275.   parser from here, with the purported filename stuffed into the command
  1276.   buffer, followed by some carriage returns to make the parser return.
  1277.   If the file is not found, or otherwise not accessible, the parser prints
  1278.   an appropriate message, and then we just exit.
  1279. */
  1280.     cmdini();                           /* Allocate command buffers etc */
  1281.     cmini(0);                           /* Initialize them */
  1282.     /* Stuff filename into command buf with braces in case of spaces */
  1283.     ckmakmsg(cmdbuf,CMDBL,"{",arg,"}",NULL);
  1284.     debug(F110,"prescan cmdbuf",cmdbuf,0);
  1285.     ckstrncat(cmdbuf,"\r\r",CMDBL);     /* And some carriage returns */
  1286.     if (cmifip("","",&s,&x,0,takepath,xxstring) < 0)
  1287.       return(NULL);
  1288.     cmres();
  1289.     return(s);
  1290. }
  1291.  
  1292. static int tr_int;                      /* Flag if TRANSMIT interrupted */
  1293.  
  1294. #ifndef MAC
  1295. SIGTYP
  1296. #ifdef CK_ANSIC
  1297. trtrap(int foo)                         /* TRANSMIT interrupt trap */
  1298. #else
  1299. trtrap(foo) int foo;                    /* TRANSMIT interrupt trap */
  1300. #endif /* CK_ANSIC */
  1301. /* trtrap */ {
  1302. #ifdef __EMX__
  1303.     signal(SIGINT, SIG_ACK);
  1304. #endif
  1305.     tr_int = 1;                         /* (Need arg for ANSI C) */
  1306.     SIGRETURN;
  1307. }
  1308. #endif /* MAC */
  1309. #endif /* NOICP */
  1310.  
  1311. #ifdef UNIX
  1312. VOID
  1313. getexedir() {
  1314.     extern char * xarg0;
  1315.   /*
  1316.     Unix provides no standard service for this.  We look in argv[0], and if
  1317.     we're lucky there's a full pathname.  If not we do a PATH search.
  1318.   */
  1319.     if (ckstrchr(xarg0,'/')) {          /* Global copy of argv[0] */
  1320.         int i, k;
  1321.         char * p = NULL;
  1322.         if ((k = ckstrncpy(tmpbuf,xarg0,TMPBUFSIZ-2)) > 0) {
  1323.             p = tmpbuf;
  1324.             /* Convert to fully qualified pathname */
  1325.             if (tmpbuf[0]) if (tmpbuf[0] != '/') {
  1326.                 line[0] = NUL;
  1327.                 zfnqfp(tmpbuf,LINBUFSIZ-2,(char *)line);
  1328.                 if (line[0])
  1329.                   p = line;
  1330.             }
  1331.             if (zchki(p) > -1) {        /* Is the result an existing file? */
  1332.                 k = strlen(p);
  1333.                 for (i = k-1; i > 0; i--) { /* Yes, strip name part */
  1334.                     if (tmpbuf[i] == '/') {
  1335.                         if (i < k-1)
  1336.                           tmpbuf[i+1] = NUL;
  1337.                         break;
  1338.                     }
  1339.                 }
  1340.                 makestr(&exedir,p);     /* Save the result */
  1341.             }
  1342.         }
  1343.     }
  1344.     if (!exedir && xarg0) {             /* Not found? */
  1345.         char * p;
  1346.         p = getenv("PATH");             /* Search the PATH */
  1347.         if (p) {                        /* If there is one... */
  1348.             char * q, * PATH = NULL;
  1349.             int k;
  1350.             makestr(&PATH,p);           /* Pokeable copy of PATH string */
  1351.             if (PATH) {                 /* If malloc succeeded... */
  1352.                 p = PATH;
  1353.                 while (p && *p) {        /* Loop through segments */
  1354.                     q = ckstrchr(p,':'); /* End of this segment */
  1355.                     if (q == p) {       /* Null PATH segment */
  1356.                         p++;            /* Skip over colon */
  1357.                         continue;
  1358.                     }
  1359.                     if (q)              /* If not at end of PATH string */
  1360.                       *q++ = NUL;       /* zero out the colon */
  1361.                     if ((k = ckstrncpy(tmpbuf,p,TMPBUFSIZ)) > 0) {
  1362.                         if (tmpbuf[k-1] != '/') { /* Copy this PATH segment */
  1363.                             tmpbuf[k++] = '/';    /* Append '/' if needed */
  1364.                             tmpbuf[k] = NUL;
  1365.                         }
  1366.                         /* Append the argv[0] value */
  1367.                         if (ckstrncpy(&tmpbuf[k],xarg0,TMPBUFSIZ) > 0) {
  1368.                             if (zchki(tmpbuf) > -1) { /* File exists? */
  1369.                                 tmpbuf[k] = NUL;      /* Yes, we're done */
  1370.                                 zfnqfp(tmpbuf,LINBUFSIZ,(char *)line);
  1371.                                 makestr(&exedir,line);
  1372.                                 break;
  1373.                             }
  1374.                         } else break;
  1375.                     } else break;
  1376.                     p = q;              /* Not found, go to next segment  */
  1377.                 } /* while */
  1378.                 free(PATH);             /* Free PATH copy */
  1379.             }
  1380.         }
  1381.         if (!exedir) {                  /* Still nothing? */
  1382.             if (zchki(xarg0) > -1) {    /* Maybe it's in the current dir */
  1383.                 zfnqfp(zgtdir(),LINBUFSIZ,(char *)line);
  1384.                 makestr(&exedir,line);
  1385.             }
  1386.         }
  1387.     }
  1388.     if (!exedir) {                      /* Still nothing? */
  1389.         makestr(&exedir,"/");           /* Fake it with with root. */
  1390.     }
  1391. }
  1392. #endif /* UNIX */
  1393.  
  1394. int arg_x = 0;
  1395. static int x_prescan = 0;
  1396.  
  1397. /*
  1398.   The argument y once meant something but I can't imagine what so now
  1399.   it's ignored.  (Prior to 22 Aug 98, prescan() was called twice by main(),
  1400.   and the arg differentiated the two calls.  But this caused all sorts of
  1401.   problems & confusion, so I commented out the second call.  This issue might
  1402.   need to be revisited.)
  1403. */
  1404. VOID
  1405. prescan(dummy) int dummy; {             /* Arg is ignored. */
  1406.     extern int howcalled;
  1407.     int yargc; char **yargv;
  1408.     char x;
  1409.     char *yp, *yy;
  1410. #ifdef DEBUG
  1411.     int debcount = 0;
  1412. #endif /* DEBUG */
  1413.     int z;
  1414.  
  1415.     if (x_prescan)                      /* Only run once */
  1416.       return;
  1417.     x_prescan = 1;
  1418.  
  1419.     yargc = xargc;                      /* Make copy of arg vector */
  1420.     yargv = xargv;
  1421.  
  1422. #ifndef NOICP
  1423. #ifdef DCMDBUF
  1424.     if (!kermrc)
  1425.       if (!(kermrc = (char *) malloc(KERMRCL+1)))
  1426.         fatal("prescan: no memory for kermrc");
  1427. #endif /* DCMDBUF */
  1428.     ckstrncpy(kermrc,KERMRC,KERMRCL);   /* Default init file name */
  1429. #endif /* NOICP */
  1430.  
  1431.  
  1432. #ifdef IKSD
  1433.     if (howcalled == I_AM_IKSD)         /* Internet Kermit Service daemon */
  1434.       inserver = 1;                     /* (See inserver section of ckcmai) */
  1435. #endif /* IKSD */
  1436.  
  1437. /* Command line options for Kermit */
  1438.  
  1439. #ifndef NOCMDL
  1440.     if (yargc > 1
  1441.         && *yargv[1] != '-'
  1442.         && (yargv[1][0] != '=')
  1443. #ifdef KERBANG
  1444.         && (yargv[1][0] != '+')
  1445. #endif /* KERBANG */
  1446. #ifdef IKSD
  1447.         && (howcalled != I_AM_IKSD)
  1448. #endif /* IKSD */
  1449.         ) {                             /* Filename as 1st argument */
  1450. #ifndef NOICP
  1451.         char *s;
  1452. #endif /* NOICP */
  1453. #ifndef NOURL
  1454.         extern int haveurl;
  1455.         extern struct urldata g_url;
  1456.         if (urlparse(yargv[1],&g_url)) {
  1457.             if (!ckstrcmp(g_url.svc,"ftp",-1,0) ||
  1458.                 !ckstrcmp(g_url.svc,"ftps",-1,0)) {
  1459.                 haveurl = 1;
  1460.                 howcalled = I_AM_FTP;
  1461.             } else if (!ckstrcmp(g_url.svc,"telnet",-1,0) ||
  1462.                        !ckstrcmp(g_url.svc,"telnets",-1,0)) {
  1463.                 haveurl = 1;
  1464.                 howcalled = I_AM_TELNET;
  1465.             } else if (!ckstrcmp(g_url.svc,"iksd",-1,0) ||
  1466.                        !ckstrcmp(g_url.svc,"kermit",-1,0)) {
  1467.                 haveurl = 1;
  1468.                 howcalled = I_AM_KERMIT;
  1469.             } else if (!ckstrcmp(g_url.svc,"http",-1,0) ||
  1470.                        !ckstrcmp(g_url.svc,"https",-1,0)) {
  1471.                 haveurl = 1;
  1472.                 howcalled = I_AM_HTTP;
  1473.             }
  1474.             if (haveurl) {
  1475.                 while (--yargc > 0) {   /* Go through command-line args */
  1476.                     yargv++;            /* looking for -Y and -d */
  1477.                     yp = *yargv+1;
  1478.                     if (**yargv == '-') {
  1479.                         x = *(*yargv+1);
  1480.                         while (x) {
  1481.                             switch (x) {
  1482.                               case 'Y':
  1483.                                 noinit++;
  1484.                                 break;
  1485.                               case 'h':
  1486.                                   noinit = 1;
  1487. #ifdef OS2
  1488.                                   startflags |= 2;    /* No network DLLs */
  1489.                                   startflags |= 4;    /* No TAPI DLLs */
  1490.                                   startflags |= 8;    /* No Security DLLs */
  1491.                                   startflags |= 16;   /* No Zmodem DLLs */
  1492.                                   startflags |= 32;   /* Stdin */
  1493.                                   startflags |= 64;   /* Stdout */
  1494. #endif /* OS2 */
  1495.                                   break;
  1496.                               case 'd': /* = SET DEBUG ON */
  1497. #ifdef DEBUG
  1498.                                 if (debcount++ > 0)
  1499.                                   debtim = 1;
  1500.                                 if (!deblog)
  1501.                                   deblog = debopn("debug.log",0);
  1502. #endif /* DEBUG */
  1503.                                 break;
  1504. #ifdef OS2
  1505.                               case 'W':
  1506.                                 if (*(yp+1))
  1507.                                   fatal("invalid argument bundling after -W");
  1508.                                 yargv++, yargc--;
  1509.                                 if (yargc < 1)
  1510.                                   fatal("Window handle missing");
  1511.                                 hwndDialer = (HWND) atol(*yargv);
  1512.                                 StartedFromDialer = 1;
  1513.                                 yargv++, yargc--;
  1514.                                 KermitDialerID = atol(*yargv) ;
  1515.                                 break;
  1516.                               case '#': /* K95 initialization options */
  1517.                                 if (*(yp+1)) {
  1518.                                     fatal("invalid argument bundling");
  1519.                                 }
  1520.                                 yargv++, yargc--;
  1521.                                 if (yargc < 1)
  1522.                                   fatal("-# argument missing");
  1523.                                 startflags |= atol(*yargv);
  1524.                                 break;
  1525. #endif /* OS2 */
  1526.                             }
  1527.                             if (!yp)
  1528.                               break;
  1529.                             x = *++yp;
  1530.                         }
  1531.                     }
  1532.                 }
  1533.                 return;
  1534.             }
  1535.         }
  1536.         /* after this point non-Kermit personalities must return */
  1537.         switch (howcalled) {
  1538.       case I_AM_KERMIT:
  1539.       case I_AM_IKSD:
  1540.       case I_AM_SSHSUB:
  1541.             break;
  1542.       default:
  1543.             return;
  1544.         }
  1545. #endif /* NOURL */
  1546.  
  1547. #ifndef NOICP
  1548.         /* If it is not a URL that we recognize, try to treat it as a file */
  1549.  
  1550.         if (!isabsolute(yargv[1]))      /* If not absolute */
  1551.           s = findinpath(yargv[1]);     /* Look in PATH */
  1552.         else
  1553.           s = yargv[1];
  1554.         if (!s)
  1555.           doexit(BAD_EXIT,xitsta);
  1556.         zfnqfp(s,CKMAXPATH,cmdfil);     /* In case of CD in file */
  1557.         yargc -= 1;                     /* Skip past the filename */
  1558.         yargv += 1;                     /* Otherwise we'll get an error */
  1559. #endif /* NOICP */
  1560.     }
  1561.  
  1562. #ifndef NOCMDL
  1563. #ifdef NEWFTP
  1564.     if (howcalled == I_AM_FTP) {        /* Kermit's FTP client personality */
  1565.         while (--yargc > 0) {           /* Go through command-line args */
  1566.             yargv++;                    /* looking for -Y and -d */
  1567.             yp = *yargv+1;
  1568.             if (**yargv == '-') {
  1569.                 x = *(*yargv+1);
  1570.                 while (x) {
  1571.                     switch (x) {
  1572.                       case 'Y':
  1573.                         noinit++;
  1574.                         break;
  1575.                       case 'h':
  1576.                         noinit = 1;
  1577. #ifdef OS2
  1578.                         startflags |= 2;    /* No network DLLs */
  1579.                         startflags |= 4;    /* No TAPI DLLs */
  1580.                         startflags |= 8;    /* No Security DLLs */
  1581.                         startflags |= 16;   /* No Zmodem DLLs */
  1582.                         startflags |= 32;   /* Stdin */
  1583.                         startflags |= 64;   /* Stdout */
  1584. #endif /* OS2 */
  1585.                         break;
  1586.                       case 'd':             /* = SET DEBUG ON */
  1587. #ifdef DEBUG
  1588.                         if (debcount++ > 0)
  1589.                           debtim = 1;
  1590.                         if (!deblog)
  1591.                           deblog = debopn("debug.log",0);
  1592. #endif /* DEBUG */
  1593.                         break;
  1594. #ifdef OS2
  1595.                       case 'W':
  1596.                         if (*(yp+1))
  1597.                           fatal("invalid argument bundling after -W");
  1598.                         yargv++, yargc--;
  1599.                         if (yargc < 1)
  1600.                           fatal("Window handle missing");
  1601.                         hwndDialer = (HWND) atol(*yargv);
  1602.                         StartedFromDialer = 1;
  1603.                         yargv++, yargc--;
  1604.                         KermitDialerID = atol(*yargv) ;
  1605.                         break;
  1606.                       case '#':         /* K95 initialization options */
  1607.                         if (*(yp+1)) {
  1608.                             fatal("invalid argument bundling");
  1609.                         }
  1610.                         yargv++, yargc--;
  1611.                         if (yargc < 1)
  1612.                           fatal("-# argument missing");
  1613.                         startflags |= atol(*yargv);
  1614.                         break;
  1615. #endif /* OS2 */
  1616.                     }
  1617.                     if (!yp)
  1618.                       break;
  1619.                     x = *++yp;
  1620.                 }
  1621.             }
  1622.         }
  1623.         return;
  1624.     }
  1625. #endif /* NEWFTP */
  1626. #endif /* NOCMDL */
  1627.  
  1628.     while (--yargc > 0) {               /* Go through command-line args */
  1629.         yargv++;
  1630.         yp = *yargv+1;                  /* Pointer for bundled args */
  1631.         if (**yargv == '=')             /* Same rules as cmdlin()... */
  1632.           return;
  1633.         debug(F110,"prescan *yargv",*yargv,0);
  1634.  
  1635. #ifndef NOICP
  1636. #ifdef KERBANG
  1637.         yy = *yargv;
  1638.         if (!strcmp(yy,"+") || (*yy == '+' && *(yy+1) < (char)33)) {
  1639.             char * s;
  1640.             yargv++;
  1641.             noinit = 1;
  1642.             if (!*yargv)
  1643.               return;
  1644.             cfilef = 1;
  1645.             s = findinpath(*yargv);
  1646.             if (s) {
  1647.                 zfnqfp(s,CKMAXPATH,cmdfil);
  1648.                 return;
  1649.             } else
  1650.               doexit(BAD_EXIT,xitsta);
  1651.         }
  1652. #endif /* KERBANG */
  1653. #endif /* NOICP */
  1654.         if (!strcmp(*yargv,"--"))       /* getopt() conformance */
  1655.           return;
  1656. #ifdef VMS
  1657.         else if (**yargv == '/')
  1658.           continue;
  1659. #endif /* VMS */
  1660.         else if (**yargv == '-') {      /* Got an option (begins with dash) */
  1661.             x = *(*yargv+1);            /* Get option letter */
  1662.             while (x) {                 /* Allow for bundled options */
  1663.                 debug(F000,"prescan arg","",x);
  1664.                 switch (x) {
  1665. #ifndef NOICP
  1666.                   case '+':
  1667.                   case '-':
  1668.                     if (doxarg(yargv,1) < 0) {
  1669.                         fatal("Extended argument error");
  1670.                     }
  1671.                     yargv++, yargc--;
  1672.                     yp = *yargv;
  1673.                     break;
  1674. #endif /* NOICP */
  1675.  
  1676.                   case '7':             /* Undocumented... */
  1677.                     sstelnet = 1;       /* (because it doesn't work) */
  1678.                     break;
  1679. #ifdef IKSD
  1680.                   case 'A': {
  1681.                       char * p;
  1682.                       inserver = 1;     /* Flag that we are doing this */
  1683.                       srvcdmsg = 2;     /* Preset this */
  1684.                       /* See inserver section of ckcmai.c for more settings */
  1685. #ifdef OS2
  1686.                       if (*(yp+1)) {
  1687.                           fatal("invalid argument bundling after -A");
  1688.                       }
  1689. #ifdef NT
  1690.                       /* Support for Pragma Systems Telnet/Terminal Servers */
  1691.                       p = getenv("PRAGMASYS_INETD_SOCK");
  1692.                       if (p && atoi(p) != 0) {
  1693.                           ttname[0] = '$';
  1694.                           ckstrncpy(&ttname[1],p,TTNAMLEN-1);
  1695.                           break;
  1696.                       }
  1697. #endif /* NT */
  1698.                       yargv++, yargc--;
  1699.                       if (yargc < 1 || **yargv == '-') {
  1700.                           fatal("-A argument missing");
  1701.                       } else {
  1702.                           ttname[0] = '$';
  1703.                           ckstrncpy(&ttname[1],*yargv,TTNAMLEN-1);
  1704.                       }
  1705. #endif /* OS2 */
  1706.                       break;
  1707.                   }
  1708. #endif /* IKSD */
  1709.  
  1710. #ifdef OS2
  1711.                   case 'W':
  1712.                     if (*(yp+1))
  1713.                       fatal("invalid argument bundling after -W");
  1714.                     yargv++, yargc--;
  1715.                     if (yargc < 1)
  1716.                       fatal("Window handle missing");
  1717. #ifdef COMMENT
  1718.                     if (dummy) {
  1719.                         yargv++, yargc--;
  1720.                         break;
  1721.                     } else {
  1722. #endif /* COMMENT */
  1723.                         hwndDialer = (HWND) atol(*yargv);
  1724.                         StartedFromDialer = 1;
  1725.                         yargv++, yargc--;
  1726.                         KermitDialerID = atol(*yargv) ;
  1727. #ifdef COMMENT
  1728.                     }
  1729. #endif /* COMMENT */
  1730.                     break;
  1731.  
  1732.                   case '#':             /* K95 initialization options */
  1733.                     if (*(yp+1)) {
  1734.                         fatal("invalid argument bundling");
  1735.                     }
  1736.                     yargv++, yargc--;
  1737.                     if (yargc < 1)
  1738.                       fatal("-# argument missing");
  1739.                     startflags |= atol(*yargv);
  1740.                     break;
  1741. #endif /* OS2 */
  1742.  
  1743. #ifndef NOSPL
  1744.                   case 'M':                             /* My User Name */
  1745.                     if (*(yp+1)) {
  1746.                         fatal("invalid argument bundling");
  1747.                     }
  1748.                     yargv++, yargc--;
  1749.                     if ((yargc < 1) || (**yargv == '-')) {
  1750.                         fatal("missing username");
  1751.                     }
  1752.                     if ((int)strlen(*yargv) > UIDBUFLEN) {
  1753.                         fatal("username too long");
  1754.                     }
  1755. #ifdef COMMENT
  1756. /*
  1757.   This can't work.  uidbuf is overwritten in sysinit() which has yet to be
  1758.   called.  This cannot be set in prescan().
  1759. */
  1760. #ifdef IKSD
  1761.                     if (!inserver)
  1762. #endif /* IKSD */
  1763.                       ckstrncpy(uidbuf,*yargv,UIDBUFLEN);
  1764. #endif /* COMMENT */
  1765.                     break;
  1766. #endif /* NOSPL */
  1767.                   case 'R':             /* Remote-only advisory */
  1768. #ifdef CK_IFRO
  1769.                     remonly = 1;
  1770. #endif /* CK_IFRO */
  1771.                     break;
  1772.                   case 'S':             /* STAY */
  1773.                     stayflg = 1;
  1774.                     break;
  1775.                   case 'h':
  1776.                     noinit = 1;
  1777. #ifdef OS2
  1778.                     startflags |= 2;    /* No network DLLs */
  1779.                     startflags |= 4;    /* No TAPI DLLs */
  1780.                     startflags |= 8;    /* No Security DLLs */
  1781.                     startflags |= 16;   /* No Zmodem DLLs */
  1782.                     startflags |= 32;   /* Stdin */
  1783.                     startflags |= 64;   /* Stdout */
  1784. #endif /* OS2 */
  1785.                     break;
  1786. #ifndef NOICP
  1787.                   case 'Y':             /* No init file */
  1788.                     noinit = 1;
  1789.                     break;
  1790. #endif /* NOICP */
  1791.                   case 'd':             /* = SET DEBUG ON */
  1792. #ifdef DEBUG
  1793.                     if (debcount++ > 0)
  1794.                       debtim = 1;
  1795.                     if (!deblog)
  1796.                       deblog = debopn("debug.log",0);
  1797. #endif /* DEBUG */
  1798.                     break;
  1799.  
  1800.                   case 'x':             /* Server */
  1801.                     arg_x = 1;          /* Note in advance */
  1802.                     break;
  1803. #ifndef NOICP
  1804.                   case 'y':             /* Alternative init file */
  1805.                     noinit = 0;
  1806.                     yargv++, yargc--;
  1807.                     if (yargc < 1) fatal("missing name in -y");
  1808.                     /* Replace init file name */
  1809.                     ckstrncpy(kermrc,*yargv,KERMRCL);
  1810.                     rcflag = 1;         /* Flag that this has been done */
  1811.                     debug(F111,"prescan kermrc",kermrc,rcflag);
  1812.                     break;
  1813. #endif /* NOICP */
  1814.                   case 'z':             /* = SET BACKGROUND OFF */
  1815.                     bgset = 0;
  1816.                     backgrd = 0;
  1817. #ifdef VMS
  1818.                     batch = 0;
  1819. #endif /* VMS */
  1820.                     break;
  1821.  
  1822.                   case 'B':             /* Force background (batch) */
  1823.                     bgset = 1;
  1824.                     backgrd = 1;
  1825. #ifdef VMS
  1826.                     batch = 1;
  1827. #endif /* VMS */
  1828.                     break;
  1829.  
  1830. #ifdef CK_NETBIOS
  1831.                   case 'N':
  1832.                     {
  1833.                         int n ;
  1834.                         yargv++, yargc--;
  1835. #ifdef COMMENT
  1836.                         if (y)
  1837.                           break;
  1838. #endif /* COMMENT */
  1839.                         if (strlen(*yargv) != 1 || (*yargv)[0] == 'X') {
  1840.                             NetBiosAdapter = -1;
  1841.                         } else {
  1842.                             n = atoi(*yargv);
  1843.                             if (n >= 0 && n <= 9)
  1844.                               NetBiosAdapter = n;
  1845.                             else
  1846.                               NetBiosAdapter = -1;
  1847.                         }
  1848.                     }
  1849.                     break;
  1850. #endif /* CK_NETBIOS */
  1851.                   default:
  1852.                     break;
  1853.                 }
  1854.                 if (!yp)
  1855.                   break;
  1856.                 x = *++yp;              /* See if options are bundled */
  1857.             }
  1858.         }
  1859.     }
  1860. #endif /* NOCMDL */
  1861. }
  1862.  
  1863. /*  G E T T C S  --  Get Transfer (Intermediate) Character Set  */
  1864.  
  1865. /*
  1866.   Given two file character sets, this routine picks out the appropriate
  1867.   "transfer" character set to use for translating between them.
  1868.   The transfer character set number is returned.
  1869.  
  1870.   Translation between two file character sets is done, for example,
  1871.   by the CONNECT, TRANSMIT, and TRANSLATE commands.
  1872.  
  1873.   Translation between Kanji character sets is not yet supported.
  1874. */
  1875. int
  1876. gettcs(cs1,cs2) int cs1, cs2; {
  1877. #ifdef NOCSETS                          /* No character-set support */
  1878.     return(0);                          /* so no translation */
  1879. #else
  1880.     int tcs = TC_TRANSP;
  1881. #ifdef KANJI
  1882. /* Kanji not supported yet */
  1883.     if (fcsinfo[cs1].alphabet == AL_JAPAN ||
  1884.         fcsinfo[cs2].alphabet == AL_JAPAN )
  1885.       tcs = TC_TRANSP;
  1886.     else
  1887. #endif /* KANJI */
  1888. #ifdef CYRILLIC
  1889. /*
  1890.   I can't remember why we don't test both sets here, but I think there
  1891.   must have been a reason...
  1892. */
  1893.       if (fcsinfo[cs2].alphabet == AL_CYRIL)
  1894.         tcs = TC_CYRILL;
  1895.       else
  1896. #endif /* CYRILLIC */
  1897. #ifdef HEBREW
  1898.           if (fcsinfo[cs1].alphabet == AL_HEBREW ||
  1899.               fcsinfo[cs2].alphabet == AL_HEBREW )
  1900.             tcs = TC_HEBREW;
  1901.           else
  1902. #endif /* HEBREW */
  1903. #ifdef GREEK
  1904.           if (fcsinfo[cs1].alphabet == AL_GREEK ||
  1905.               fcsinfo[cs2].alphabet == AL_GREEK )
  1906.             tcs = TC_GREEK;
  1907.           else
  1908. #endif /* GREEK */
  1909.  
  1910.             /* Roman sets ... */
  1911.  
  1912. #ifdef LATIN2                           /* East European */
  1913.         if (cs1 == FC_2LATIN  || cs2 == FC_2LATIN || /* Latin-2 */
  1914.             cs1 == FC_CP852   || cs2 == FC_CP852  || /* CP852 */
  1915.             cs1 == FC_CP1250  || cs2 == FC_CP1250 || /* Windows Latin-2 */
  1916.             cs1 == FC_MAZOVIA || cs2 == FC_MAZOVIA)  /* Polish Mazovia */
  1917.           tcs = TC_2LATIN;
  1918.         else
  1919. #endif /* LATIN2 */
  1920.                                         /* West European Euro-aware */
  1921.           if (cs1 == FC_CP858 || cs1 == FC_9LATIN ||
  1922.               cs2 == FC_CP858 || cs2 == FC_9LATIN)
  1923.             tcs = TC_9LATIN;
  1924.           else                          /* Traditional West European */
  1925.             tcs = TC_1LATIN;
  1926.     return(tcs);
  1927. #endif /* NOCSETS */
  1928. }
  1929.  
  1930. #ifndef NOLOCAL
  1931. /*  D O C O N E C T  --  Do the connect command  */
  1932. /*
  1933.   q = 0 means issue normal informational message about how to get back, etc.
  1934.   q != 0 means to skip the message.
  1935. */
  1936.  
  1937. int
  1938. doconect(q,async) int q, async; {
  1939.     int x;                              /* Return code */
  1940. #ifdef CK_AUTODL
  1941.     extern CHAR ksbuf[];
  1942. #endif /* CK_AUTODL */
  1943. #ifndef NOKVERBS                        /* Keyboard macro material */
  1944.     extern int keymac, keymacx;
  1945. #endif /* NOKVERBS */
  1946.     extern int justone, adl_err;
  1947.     int qsave;                          /* For remembering "quiet" value */
  1948. #ifdef OS2
  1949.     extern int term_io;
  1950.     extern int display_demo;
  1951.     int term_io_save;
  1952. #ifdef KUI
  1953.     extern int kui_async;
  1954. #endif /* KUI */
  1955. #endif /* OS2 */
  1956.     int is_tn = 0;
  1957.  
  1958. #ifdef IKSD
  1959.     if (inserver) {
  1960.         if (!quiet)
  1961.           printf("?Sorry, IKSD cannot CONNECT.\r\n");
  1962.         return(success = 0);
  1963.     }
  1964. #endif /* IKSD */
  1965.  
  1966.     is_tn =
  1967. #ifdef TNCODE
  1968.       (local && network && IS_TELNET()) || (!local && sstelnet)
  1969. #else
  1970.         0
  1971. #endif /* TNCODE */
  1972.           ;
  1973. /*
  1974.   Saving, changing, and restoring the global "quiet" variable around calls
  1975.   to conect() to control whether the verbose CONNECT message is printed is
  1976.   obviously less elegant than passing a parameter to conect(), but we do it
  1977.   this way to avoid the need to change all of the ck?con.c modules.  NOTE:
  1978.   it is important to restore the value immediately upon return in case there
  1979.   is an autodownload or APC.
  1980. */
  1981.     qsave = quiet;                      /* Save it */
  1982.     if (!quiet && q > -1)
  1983.       quiet = q;                        /* Use argument temporarily */
  1984.     conres();                           /* Put console back to normal */
  1985.     debug(F101,"doconect justone 1","",justone);
  1986. #ifdef CK_AUTODL
  1987.     ksbuf[0] = NUL;                     /* Autodownload packet buffer */
  1988. #endif /* CK_AUTODL */
  1989. #ifdef OS2
  1990.     display_demo = 1;                   /* Remember to display demo */
  1991. #endif /* OS2 */
  1992.  
  1993. #ifdef IKS_OPTION
  1994.     if (is_tn && TELOPT_U(TELOPT_KERMIT) && ttchk() >= 0
  1995. #ifdef OS2
  1996.        && !viewonly
  1997. #endif /* OS2 */
  1998.         ) {
  1999.         /* If the remote side is in a state of IKS START-SERVER    */
  2000.         /* we request that the state be changed.  We will detect   */
  2001.         /* a failure to adhere to the request when we call ttinc() */
  2002.         if (!iks_wait(KERMIT_REQ_STOP,0) && !tcp_incoming) {
  2003.             if (!quiet) {
  2004.                 printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2005.                 printf(
  2006. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2007.                 printf(" SEND and GET for file transfer.\r\n");
  2008.                 printf(" REMOTE commands for file management.\r\n");
  2009.                 printf(" FINISH to terminate Client/Server mode.\r\n");
  2010.                 printf(" BYE to terminate and close connection.\r\n");
  2011.                 printf(" REMOTE HELP for additional information.\r\n\r\n");
  2012.             }
  2013.             quiet = qsave;
  2014.             return(0);      /* Failure */
  2015.         }
  2016.     }
  2017.  
  2018.     /* Let our peer know our state. */
  2019. #ifdef CK_AUTODL
  2020.     if (is_tn && TELOPT_ME(TELOPT_KERMIT)
  2021. #ifdef OS2
  2022.         && !viewonly
  2023. #endif /* OS2 */
  2024.          ) {
  2025.         if (autodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2026.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  2027.         } else if (!autodl && TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2028.             tn_siks(KERMIT_STOP);
  2029.         }
  2030.     }
  2031. #else /* CK_AUTODL */
  2032.     if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2033.         tn_siks(KERMIT_STOP);
  2034.     }
  2035. #endif /* CK_AUTODL */
  2036. #endif /* IKS_OPTION */
  2037.  
  2038.     debug(F101,"doconect flow","",flow);
  2039. #ifdef OS2
  2040.     debug(F101,"doconect async","",async);
  2041. #ifdef KUI
  2042.     if (kui_async)
  2043.       async = 1;;
  2044. #endif /* KUI */
  2045.     x = conect(async);                  /* Connect the first time */
  2046. #else /* OS2 */
  2047.     x = conect();
  2048. #endif /* OS2 */
  2049.     debok = 1;
  2050.  
  2051. #ifdef IKS_OPTION
  2052.     if (TELOPT_U(TELOPT_KERMIT) &&
  2053.         TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  2054.         !tcp_incoming && !quiet && ttchk() >= 0
  2055.         ) {
  2056.         printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2057.         printf(
  2058. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2059.         printf(" SEND and GET for file transfer.\r\n");
  2060.         printf(" REMOTE commands for file management.\r\n");
  2061.         printf(" FINISH to terminate Client/Server mode.\r\n");
  2062.         printf(" BYE to terminate and close connection.\r\n");
  2063.         printf(" REMOTE HELP for additional information.\r\n\r\n");
  2064.     }
  2065. #endif /* IKS_OPTION */
  2066.  
  2067.     quiet = qsave;                      /* Restore "quiet" value */
  2068.     debug(F101,"doconect justone 2","",justone);
  2069.  
  2070. #ifdef NETCONN
  2071.     if (network && tn_exit && ttchk() < 0)
  2072.       doexit(GOOD_EXIT,xitsta);         /* Exit with good status */
  2073. #endif /* NETCONN */
  2074.  
  2075. #ifdef OS2ORUNIX
  2076.     /* Exit on disconnect if the port is not open or carrier detect */
  2077.     if (exitonclose && (ttchk() < 0))
  2078.       doexit(GOOD_EXIT,xitsta);
  2079. #endif /* OS2ORUNIX */
  2080.  
  2081. #ifdef CKCONINTB4CB
  2082.     /* The order makes a difference in HP-UX 8.00. */
  2083.     /* The other order makes it think it's in the background when it */
  2084.     /* returns from CONNECT (Apr 1999). */
  2085.     setint();
  2086.     concb((char)escape);                /* Restore console for commands */
  2087. #else
  2088.     /* This is how it has always been so better leave it */
  2089.     /* this way for all non-HP-UX-8.00 builds. */
  2090.     concb((char)escape);                /* Restore console for commands */
  2091.     setint();
  2092. #endif /* CKCONINTB4CB */
  2093.  
  2094. #ifdef OS2
  2095.     if (!async) {
  2096.         term_io_save = term_io;         /* Disable I/O by emulator */
  2097.         term_io = 0;
  2098. #endif /* OS2 */
  2099.  
  2100. #ifdef CK_APC
  2101. /*
  2102.   If an APC command was received during CONNECT mode, we define it now
  2103.   as a macro, execute the macro, and then return to CONNECT mode.
  2104.   We do this in a WHILE loop in case additional APCs come during subsequent
  2105.   CONNECT sessions.
  2106. */
  2107.         debug(F101,"doconect apcactive","",apcactive);
  2108.         debug(F101,"doconect success","",success);
  2109.  
  2110.         while (x > 0 && (apcactive == APC_LOCAL ||
  2111.                          (apcactive == APC_REMOTE && apcstatus != APC_OFF))) {
  2112.             debug(F101,"doconect justone 3","",justone);
  2113.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  2114.                 debug(F110,"doconect about to execute APC",apcbuf,0);
  2115.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  2116.                 delmac("_apc_commands",1);
  2117. #ifdef DEBUG
  2118.             } else {
  2119.                 debug(F100,"doconect APC in progress","",0);
  2120. #endif /* DEBUG */
  2121.             }
  2122.             debug(F101,"doconect apcactive after domac","",apcactive);
  2123.             if (!apcactive) {               /* In case CLEAR APC was in APC */
  2124.                 debug(F101,"doconect quit APC loop: apcactive","",apcactive);
  2125.                 break;
  2126.             }
  2127.             /* Also don't reconnect if autodownload failed - very confusing! */
  2128.             /* Let them view the local screen to see what happened. - fdc */
  2129.  
  2130.             /* This should be conditional.  If someone is relying on the */
  2131.             /* connect mode autodownload for the kermit server to use with */
  2132.             /* a remotely executed script we should be able to return to */
  2133.             /* connect mode on the failure.  What we really need to do is */
  2134.             /* report the status of the transfer and then return to CONNECT. */
  2135.             /* In unix this would simply be a printf(), but in K95 it could */
  2136.             /* use a popup dialog to report the status. - Jeff */
  2137.  
  2138. #ifndef NOXFER
  2139.             debug(F101,"doconect xferstat","",xferstat);
  2140.             if (apcactive == APC_LOCAL && !xferstat && adl_err != 0) {
  2141.                 debug(F101,"doconect quit APC loop: xferstat","",xferstat);
  2142.                 apcactive = APC_INACTIVE;
  2143.                 break;
  2144.             }
  2145. #endif /* NOXFER */
  2146. #ifdef OS2
  2147.             msleep(250);
  2148. #endif /* OS2 */
  2149.             debug(F101,"doconect justone 4","",justone);
  2150.             qsave = quiet;              /* Do this again... */
  2151.             if (!quiet && q > -1)
  2152.               quiet = q;
  2153. #ifdef CK_AUTODL
  2154.             ksbuf[0] = NUL;
  2155. #endif /* CK_AUTODL */
  2156. #ifdef IKS_OPTION
  2157. #ifdef CK_AUTODL
  2158.             if (is_tn &&
  2159.                 TELOPT_ME(TELOPT_KERMIT) &&
  2160.                 !TELOPT_SB(TELOPT_KERMIT).kermit.me_start &&
  2161.                 autodl
  2162. #ifdef CK_APC
  2163.                 && !apcactive
  2164. #endif /* CK_APC */
  2165. #ifdef OS2
  2166.                 && !viewonly
  2167. #endif /* OS2 */
  2168.                 ) {
  2169.                 tn_siks(KERMIT_START);  /* Send Kermit-Server Start */
  2170.             }
  2171. #endif /* CK_AUTODL */
  2172. #endif /* IKS_OPTION */
  2173. #ifndef OS2
  2174.             x = conect();               /* Re-CONNECT. */
  2175. #else /* OS2 */
  2176.             x = conect(0);
  2177.             term_io = term_io_save;
  2178. #endif /* OS2 */
  2179.             debok = 1;
  2180.             quiet = qsave;
  2181.             debug(F101,"doconect justone 5","",justone);
  2182. #ifdef NETCONN
  2183.             if (network && ttchk() < 0) {
  2184.                 if (tn_exit || exitonclose)
  2185.                   doexit(GOOD_EXIT,xitsta);
  2186.                 else
  2187.                   break;
  2188.             }
  2189. #endif /* NETCONN */
  2190.  
  2191. #ifdef OS2ORUNIX
  2192.             /* If connection dropped */
  2193.             if (ttchk() < 0) {
  2194.                 concb((char)escape);    /* Restore console. */
  2195.                 if (exitonclose)
  2196.                   doexit(GOOD_EXIT,xitsta);
  2197.                 else
  2198.                   break;
  2199.             }
  2200. #endif /* OS2ORUNIX */
  2201.         } /* Loop back for more. */
  2202. #endif /* CK_APC */
  2203.  
  2204. #ifndef NOKVERBS
  2205.         if ((keymac > 0) && (keymacx > -1)) { /* Executing a keyboard macro? */
  2206.             /* Set up the macro and return */
  2207.             /* Do not clear the keymac flag */
  2208.             return(dodo(keymacx,NULL,CF_KMAC|cmdstk[cmdlvl].ccflgs));
  2209.         }
  2210. #endif /* NOKVERBS */
  2211. #ifdef OS2
  2212.         term_io = term_io_save;
  2213.     } /* if (!async) */
  2214. #endif /* OS2 */
  2215.  
  2216. #ifdef CKCONINTB4CB
  2217.     /* The order makes a difference in HP-UX 8.00. */
  2218.     /* The other order makes it think it's in the background when it */
  2219.     /* returns from CONNECT (Apr 1999). */
  2220.     setint();
  2221.     concb((char)escape);                /* Restore console for commands */
  2222. #else
  2223.     /* This is how it has always been so better leave it */
  2224.     /* this way for all non-HP-UX-8.00 builds. */
  2225.     concb((char)escape);                /* Restore console for commands */
  2226.     setint();
  2227. #endif /* CKCONINTB4CB */
  2228. #ifdef OS2
  2229.     if (!async)
  2230. #endif /* OS2 */
  2231.       what = W_COMMAND;                 /* Back in command mode. */
  2232.     return(x);                          /* Done. */
  2233. }
  2234. #endif /* NOLOCAL */
  2235.  
  2236. #ifndef NOICP
  2237. #ifdef COMMENT
  2238. /*
  2239.   It seemed that this was needed for OS/2, in which \v(cmdfile) and other
  2240.   file-oriented variables or functions can return filenames containing
  2241.   backslashes, which are subsequently interpreted as quotes rather than
  2242.   directory separators (e.g. see commented section for VN_CMDF below).
  2243.   But the problem can't be cured at this level.  Example:
  2244.  
  2245.     type \v(cmdfile)
  2246.  
  2247.   Without doubling, the filename is parsed correctly, but then when passed
  2248.   to UNIX 'cat' through the shell, the backslash is removed, and then cat
  2249.   can't open the file.  With doubling, the filename is not parsed correctly
  2250.   and the TYPE command fails immediately with a "file not found" error.
  2251. */
  2252. /*
  2253.   Utility routine to double all backslashes in a string.
  2254.   s1 is pointer to source string, s2 is pointer to destination string,
  2255.   n is length of destination string, both NUL-terminated.
  2256.   Returns 0 if OK, -1 if not OK (destination string too short).
  2257. */
  2258. int
  2259. dblbs(s1,s2,n) char *s1, *s2; int n; {
  2260.     int i = 0;
  2261.     while (*s1) {
  2262.         if (*s1 == '\\') {
  2263.             if (++i > n) return(-1);
  2264.             *s2++ = '\\';
  2265.         }
  2266.         if (++i > n) return(-1);
  2267.         *s2++ = *s1++;
  2268.     }
  2269.     *s2 = NUL;
  2270.     return(0);
  2271. }
  2272. #endif /* COMMENT */
  2273.  
  2274. char *
  2275. gmdmtyp() {                             /* Get modem type */
  2276. #ifndef NODIAL
  2277.     int i, x;
  2278.  
  2279.     debug(F111,"gmdmtyp","mdmtyp",mdmtyp);
  2280.     debug(F111,"gmdmtyp","mdmsav",mdmsav);
  2281.  
  2282.     x = mdmtyp;
  2283.     if (x < 0)                          /* In case of network dialing */
  2284.       x = mdmsav;
  2285.     if (x < 1)
  2286.       return("none");
  2287.     else
  2288.       for (i = 0; i < nmdm; i++)
  2289.         if ((mdmtab[i].kwval == x) && (mdmtab[i].flgs == 0))
  2290.           return(mdmtab[i].kwd);
  2291. #endif /* NODIAL */
  2292.     return("none");
  2293. }
  2294.  
  2295. #ifndef NOXMIT
  2296. #ifndef NOLOCAL
  2297. /*  T R A N S M I T  --  Raw upload  */
  2298.  
  2299. /*  Obey current line, duplex, parity, flow, text/binary settings. */
  2300. /*  Returns 0 upon apparent success, 1 on obvious failure.  */
  2301.  
  2302. /***
  2303.  Things to add:
  2304.  . Make both text and binary mode obey set file bytesize.
  2305.  . Maybe allow user to specify terminators other than CR?
  2306.  . Maybe allow user to specify prompts other than single characters?
  2307.  . Make STATISTICS also work for TRANSMIT.
  2308.  . If TRANSMIT is done without echo, make some kind of (optional) display.
  2309.  . Make the same optimization for binary-mode transmit that was done for
  2310.    text-mode (in the no-echo / no-prompt / no-pause case).
  2311. ***/
  2312.  
  2313. /*  T R A N S M I T  --  Raw upload  */
  2314.  
  2315. /*  s is the filename, t is the turnaround (prompt) character  */
  2316.  
  2317. /*
  2318.   Maximum number of characters to buffer.
  2319.   Must be less than LINBUFSIZ
  2320. */
  2321. #ifdef OS2
  2322. #define XMBUFS 4096                     /* For compatibility with XYZmodem */
  2323. #else /* OS2 */
  2324. #define XMBUFS 1024
  2325. #endif /* OS2 */
  2326.  
  2327. #ifdef TNCODE
  2328. #ifndef IAC
  2329. #define IAC 255
  2330. #endif /* IAC */
  2331. #endif /* TNCODE */
  2332.  
  2333. #define OUTXBUFSIZ 15
  2334. static CHAR inxbuf[OUTXBUFSIZ+1];       /* Host-to-screen expansion buffer */
  2335. static int inxcount = 0;                /* and count */
  2336. static CHAR outxbuf[OUTXBUFSIZ+1];      /* Keyboard-to-host expansion buf */
  2337. static int outxcount = 0;               /* and count */
  2338.  
  2339. /*  T R A N S M I T  --  Unguarded non-protocol file transmission  */
  2340. /*
  2341.   Call with:
  2342.     char * s:   Name of file to transmit.
  2343.     char t:     Turnaround char for text-mode transmission (normally LF).
  2344.     int xlate:  nonzero = charset translation for text-mode xfer, 0 = skip.
  2345.     int binary: nonzero = transmit in binary mode, 0 = in text mode.
  2346. */
  2347. #define XBBUFSIZ 252                    /* For binary blasting */
  2348. static CHAR xbbuf[XBBUFSIZ+4];
  2349.  
  2350. int
  2351. #ifdef CK_ANSIC
  2352. transmit(char * s, char t, int xlate, int binary, int xxecho)
  2353. #else
  2354. transmit(s,t,xlate,binary,xxecho) char *s; char t; int xlate, binary, xxecho;
  2355. #endif /* CK_ANSIC */
  2356. /* transmit */ {
  2357. #ifdef MAC
  2358.     extern char sstate;
  2359.     int count = 100;
  2360. #else
  2361.     int count = 0;
  2362. #ifdef OS2
  2363. #ifdef NT
  2364.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  2365. #else /* NT */
  2366.     SIGTYP (* volatile oldsig)(int);
  2367. #endif /* NT */
  2368.  
  2369. #else /* OS2 */
  2370.     SIGTYP (* oldsig)();
  2371. #endif /* OS2 */
  2372. #endif /* MAC */
  2373.     int eof = 0;                        /* End of File flag */
  2374.     int eol = 0;                        /* End of Line flag */
  2375.     int rc = 1;                         /* Return code. 0=fail, 1=succeed. */
  2376.     int myflow;                         /* Local copy of global flow... */
  2377.     int is_tn = 0;                      /* Do Telnet negotiations */
  2378.     int xbufsiz = XMBUFS;               /* Size of TRANSMIT buffer */
  2379.     int x, y, c, i;                     /* Int workers... */
  2380.     int control = 0;                    /* Echo loop control */
  2381.     long nbytes = 0;                    /* File byte count */
  2382.     long zz;                            /* Long worker */
  2383.     char *p;                            /* Char * worker */
  2384.  
  2385. #ifdef PIPESEND
  2386.     extern int pipesend;
  2387. #endif /* PIPESEND */
  2388.  
  2389. #ifndef NOCSETS
  2390.     int tcs = TC_TRANSP;                /* Intermediate (xfer) char set */
  2391.     int langsv = L_USASCII;             /* Save current language */
  2392.     int unicode = 0;
  2393.     int tcssize = 0;
  2394.  
  2395. #ifdef CK_ANSIC /* ANSI C prototypes... */
  2396.     CHAR (*sxo)(CHAR);
  2397.     CHAR (*rxo)(CHAR);
  2398.     CHAR (*sxi)(CHAR);
  2399.     CHAR (*rxi)(CHAR);
  2400. #else /* Not ANSI C... */
  2401.     CHAR (*sxo)();
  2402.     CHAR (*rxo)();
  2403.     CHAR (*sxi)();
  2404.     CHAR (*rxi)();
  2405. #endif /* CK_ANSIC */
  2406. #ifdef UNICODE
  2407.     union ck_short uc;
  2408.     int bomorder = 0;
  2409. #ifdef CK_ANSIC
  2410.     extern int (*xl_ufc[MAXFCSETS+1])(USHORT);  /* Unicode to FCS */
  2411.     extern USHORT (*xl_fcu[MAXFCSETS+1])(CHAR); /* FCS to Unicode */
  2412.     extern int (*xuf)(USHORT);
  2413.     extern USHORT (*xfu)(CHAR);
  2414. #else
  2415.     extern int (*xl_ufc[MAXFCSETS+1])();
  2416.     extern USHORT (*xl_fcu[MAXFCSETS+1])();
  2417.     extern int (*xuf)();
  2418.     extern USHORT (*xfu)();
  2419. #endif /* CK_ANSIC */
  2420. #endif /* UNICODE */
  2421. #endif /* NOCSETS */
  2422.  
  2423.     debug(F101,"xmit t","",t);
  2424.     debug(F101,"xmit xlate","",xlate);
  2425.     debug(F101,"xmit binary","",binary);
  2426.  
  2427. #ifdef PIPESEND
  2428.     if (pipesend) {
  2429.         if (nopush) return(-2);
  2430.         if (zxcmd(ZIFILE,s) < 1) {
  2431.             printf("?Can't start command: %s\n",s);
  2432.             return(0);
  2433.         }
  2434.     } else
  2435. #endif /* PIPESEND */
  2436.     if (zopeni(ZIFILE,s) == 0) {        /* Open the file to be transmitted */
  2437.         printf("?Can't open file %s\n",s);
  2438.         return(0);
  2439.     }
  2440.     x = -1;                             /* Open the communication channel */
  2441.     if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) {  /* (no harm if already open) */
  2442.         printf("Can't open device %s\n",ttname);
  2443.         return(0);
  2444.     }
  2445.     zz = x ? speed : -1L;
  2446.     if (binary) {                       /* Binary file transmission */
  2447.         myflow = (flow == FLO_XONX) ? FLO_NONE : flow;
  2448.  
  2449.         if (ttvt(zz,myflow) < 0) {      /* So no Xon/Xoff! */
  2450.             printf("Can't condition line\n");
  2451.             return(0);
  2452.         }
  2453.     } else {
  2454.         if (ttpkt(zz,flow,parity) < 0) { /* Put the line in "packet mode" */
  2455.             printf("Can't condition line\n"); /* so Xon/Xoff will work, etc. */
  2456.             return(0);
  2457.         }
  2458.     }
  2459.     is_tn =
  2460. #ifdef TNCODE
  2461.       (local && network && IS_TELNET()) || (!local && sstelnet)
  2462. #else
  2463.         0
  2464. #endif /* TNCODE */
  2465.           ;
  2466.  
  2467. #ifndef NOCSETS
  2468. /* Set up character set translations */
  2469.  
  2470.     tcs = 0;                            /* "Transfer" or "Other" charset */
  2471.     sxo = rxo = NULL;                   /* Initialize byte-to-byte functions */
  2472.     sxi = rxi = NULL;
  2473.     unicode = 0;                        /* Assume Unicode won't be involved */
  2474.     if (!binary && xlate) {             /* Set up charset translations */
  2475. /*
  2476.   In the SENDING direction, we are converting from the local file's
  2477.   character-set (fcharset) to the remote terminal charset (tcsr).  In the
  2478.   RECEIVING direction (echoing) we are converting from the remote end of the
  2479.   terminal charset (tcsr) to its local end (tcsl), which is not necessarily
  2480.   the same as the file character-set.  Especially when the file character
  2481.   set is UCS-2, which is not a valid terminal character set.  The various
  2482.   combinations are represented in this table:
  2483.  
  2484.   FCS = File Character Set
  2485.   RCS = Remote Terminal Character Set
  2486.   CCS = Console (Local Terminal) Character Set
  2487.  
  2488.    8   4   2   1
  2489.   FCS FCS RCS CCS
  2490.   UCS UTF UTF UTF
  2491.    0   0   0   0   =   0   =   No translation
  2492.    0   0   0   1   =   1   =   FCS -> RCS, Echo RCS -> UTF
  2493.    0   0   1   0   =   2   =   FCS -> UTF, Echo UTF -> CCS
  2494.    0   0   1   1   =   3   =   FCS -> UTF, Echo no translation
  2495.  
  2496.    0   1   0   0   =   4   =   UTF -> RCS, Echo RCS -> CCS
  2497.    0   1   0   1   =   5   =   UTF -> RCS, Echo RCS -> UTF
  2498.    0   1   1   0   =   6   =   UTF -> UTF, Echo UTF -> CCS
  2499.    0   1   1   1   =   7   =   No translation
  2500.  
  2501.    1   0   0   0   =   8   =   UCS -> RCS, Echo RCS -> CCS
  2502.    1   0   0   1   =   9   =   UCS -> RCS, Echo RCS -> UTF
  2503.    1   0   1   0   =  10   =   UCS -> UTF, Echo UTF -> CCS
  2504.    1   0   1   1   =  11   =   UCS -> UTF, Echo no translation
  2505. */
  2506. #ifdef UNICODE
  2507.         xfu = NULL;                     /* Unicode translation functions */
  2508.         xuf = NULL;
  2509.         bomorder = ucsorder;            /* UCS-2 byte order */
  2510.  
  2511.         if (fcharset == FC_UCS2)        /* File charset is UCS-2 */
  2512.           unicode |= 8;
  2513.         else if (fcharset == FC_UTF8)   /* File charset is UTF-8 */
  2514.           unicode |= 4;
  2515.         if (tcsr == FC_UTF8)            /* Remote term charset is UTF-8 */
  2516.           unicode |= 2;
  2517.         if (tcsl == FC_UTF8)            /* Local term charset is UTF-8 */
  2518.           unicode |= 1;
  2519. #endif /* UNICODE */
  2520. /*
  2521.   When Unicode not involved -- TCS is the intermediate (xfer) set, and:
  2522.   sxo = File-to-Intermediate charset function
  2523.   rxo = Intermediate-to-Remote-Terminal charset function
  2524.   sxi = Remote-Terminal-to-Intermediate
  2525.   rxi = Intermediate-to-Local-Terminal
  2526. */
  2527.         tcs = gettcs(tcsr,fcharset);    /* Get intermediate set. */
  2528.         sxo = xls[tcs][fcharset];       /* translation function */
  2529.         rxo = xlr[tcs][tcsr];           /* pointers for output functions */
  2530.         sxi = xls[tcs][tcsr];           /* and for input functions. */
  2531.         rxi = xlr[tcs][tcsl];
  2532. /*
  2533.   At this point we have unicode nonzero if Unicode is involved in the
  2534.   conversion, and to 0 if it is not.
  2535.   The following is to prevent use of zmstuff() and zdstuff() by translation
  2536.   functions (stuffing works with file i/o, not with communication i/o).
  2537. */
  2538.         langsv = language;              /* Save current SET LANGUAGE */
  2539.         language = L_USASCII;           /* No language-specific translations */
  2540.     }
  2541. #endif /* NOCSETS */
  2542.  
  2543.     i = 0;                              /* Beginning of buffer. */
  2544. #ifndef MAC
  2545. #ifndef AMIGA
  2546.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  2547. #endif /* AMIGA */
  2548. #endif /* MAC */
  2549.     tr_int = 0;                         /* Have not been interrupted (yet). */
  2550.     rc = 1;                             /* Return code presumed good. */
  2551. #ifdef VMS
  2552.     conres();
  2553. #endif /* VMS */
  2554.  
  2555. #ifndef NOCSETS
  2556.     debug(F101,"XMIT unicode","",unicode);
  2557. #ifdef UNICODE
  2558.     debug(F101,"XMIT bomorder","",bomorder);
  2559. #endif /* UNICODE */
  2560. #endif /* NOCSETS */
  2561.  
  2562.     c = 0;                              /* Initial condition */
  2563.     while (c > -1 && !eof) {            /* Loop for all characters in file */
  2564.         eol = 0;
  2565. #ifdef MAC
  2566.         /*
  2567.          * It is expensive to run the miniparser so don't do it for
  2568.          * every character.
  2569.          */
  2570.         if (--count < 0) {
  2571.             count = 100;
  2572.             miniparser(1);
  2573.             if (sstate == 'a') {
  2574.                 sstate = '\0';
  2575.                 goto xmitfail;
  2576.             }
  2577.         }
  2578. #else /* Not MAC */
  2579.         if (tr_int) {                   /* Interrupted? */
  2580.             printf("^C...\n");          /* Print message */
  2581.             goto xmitfail;
  2582.         }
  2583. #endif /* MAC */
  2584.         c = zminchar();                 /* Get a file character */
  2585. #ifdef COMMENT
  2586. /* too much */
  2587. #ifdef DEBUG
  2588.         if (deblog) {
  2589.             if (c < 0)
  2590.               debug(F101,"XMIT zminchar","",c);
  2591.             else
  2592.               debug(F000,"XMIT zminchar","",c);
  2593.         }
  2594. #endif /* DEBUG */
  2595. #endif /* COMMENT */
  2596.         if (c < -1) {                   /* Other error */
  2597.             printf("?TRANSMIT file read error: %s\n",ck_errstr());
  2598.             goto xmitfail;
  2599.         } else if (c > -1) {
  2600.             nbytes++;
  2601.             c &= fmask;                 /* Apply SET FILE BYTESIZE mask */
  2602.         } else if (c == -1) {
  2603.             eof = 1;
  2604.             debug(F101,"XMIT eof","",eof);
  2605.         }
  2606.         if (binary) {                   /* Binary... */
  2607.             if (c == -1) {              /* If EOF */
  2608.                 rc = 1;                 /* Success */
  2609.                 eof = 1;
  2610.                 goto xmitexit;          /* Done */
  2611.             }
  2612.             if (!xmitw && !xxecho) {    /* Special "blast" mode */
  2613.                 if (count == XBBUFSIZ) { /* File input buffer full... */
  2614.                     while (count > 0) {
  2615.                         errno = 0;
  2616.                         y = ttol(xbbuf,count);
  2617.                         if (y < 0) {    /* try to send it. */
  2618.                             printf("?TRANSMIT output error: %s\n",
  2619.                                    ck_errstr());
  2620.                             debug(F111,"XMIT binary ttol error",
  2621.                                   ck_errstr(),errno);
  2622.                             rc = 0;
  2623.                             break;
  2624.                         }
  2625.                         if (y < 0) break;
  2626.                         count -= y;
  2627.                     }
  2628.                     count = 0;
  2629.                 }
  2630.                 xbbuf[count++] = c;
  2631. #ifdef TNCODE
  2632.                 if (c == IAC && is_tn)  /* Telnet IAC */
  2633.                   xbbuf[count++] = IAC; /* must be doubled */
  2634. #endif /* TNCODE */
  2635.                 continue;
  2636.             }
  2637.             if (ttoc(dopar((char) c)) < 0) { /* else just send the char */
  2638.                 printf("?Can't transmit character\n");
  2639.                 goto xmitfail;
  2640.             }
  2641. #ifdef TNCODE
  2642.             if (c == IAC && is_tn)      /* Quote Telnet IAC */
  2643.               ttoc((char)IAC);
  2644. #endif /* TNCODE */
  2645.  
  2646.             if (xmitw)                  /* Pause if requested */
  2647.               msleep(xmitw);
  2648.  
  2649.             if (xxecho) {               /* SET TRANSMIT ECHO ON? */
  2650.                 if (duplex) {           /* Yes, for half duplex */
  2651. #ifndef NOLOCAL
  2652. #ifdef OS2
  2653.                     /* Echo to emulator */
  2654.                     scriptwrtbuf((USHORT)(c & cmdmsk));
  2655. #endif /* OS2 */
  2656. #endif /* NOLOCAL */
  2657.                     if (conoc((char)(c & cmdmsk)) < 0) /* echo locally. */
  2658.                       goto xmitfail;
  2659.                 } else {                /* For full duplex, */
  2660.                     int i, n;           /* display whatever is there. */
  2661.                     n = ttchk();        /* See how many chars are waiting */
  2662.                     if (n < 0) {        /* Connection dropped? */
  2663.                         printf("?Connection lost\n");
  2664.                         goto xmitfail;
  2665.                     }
  2666.                     for (i = 0; i < n; i++) { /* Read and echo that many. */
  2667.                         x = ttinc(xmitt); /* Timed read just in case. */
  2668.                         if (x > -1) {   /* If no timeout */
  2669.                             if (parity) x &= 0x7f; /* display the char, */
  2670. #ifndef NOLOCAL
  2671. #ifdef OS2
  2672.                             /* Echo to emulator */
  2673.                             scriptwrtbuf((USHORT)x);
  2674. #endif /* OS2 */
  2675. #endif /* NOLOCAL */
  2676.                             if (conoc((char)(x & cmdmsk)) < 0) {
  2677.                                 printf("?Output error\n");
  2678.                                 goto xmitfail;
  2679.                             }
  2680.                         } else if (x == -2) {
  2681.                             printf("Connection closed.\n");
  2682.                             ttclos(1);
  2683.                             goto xmitfail;
  2684.                         } else if (x == -3) {
  2685.                             printf(
  2686.                             "Session Limit exceeded - closing connection.\n"
  2687.                                    );
  2688.                             ttclos(1);
  2689.                             goto xmitfail;
  2690.                         } else {
  2691.                             printf("?Communications error\n");
  2692.                             goto xmitfail;
  2693.                         }
  2694.                     }
  2695.                 }
  2696.             } else ttflui();            /* Not echoing, just flush input. */
  2697.  
  2698.         } else {                        /* Text mode, line at a time. */
  2699. #ifdef UNICODE
  2700.             if (fcharset == FC_UCS2 && xlate) { /* Special for UCS-2 */
  2701.                 char xbuf[8];
  2702.                 x = 1 - (nbytes & 1);   /* Odd or even byte */
  2703.                 if (x == 0)             /* Note: 1 = the 1st, 0 = 2nd, etc */
  2704.                   uc.x_short = 0;
  2705.                 if (bomorder)           /* Little Endian */
  2706.                   x = 1 - x;            /* Save byte in appropriate half */
  2707.                 debug(F101,"XMIT UCS2 x","",x);
  2708.                 uc.x_char[x] = (CHAR) (c & 0xff);
  2709.                 if (nbytes & 1)         /* First byte, go back for next */
  2710.                   continue;
  2711.                 if (nbytes == 2) {      /* UCS-2 Byte Order Mark */
  2712.                     if (uc.x_short == (USHORT) 0xfeff) {
  2713.                         debug(F100,"XMIT UCS2 BOM FEFF","",bomorder);
  2714.                         continue;
  2715.                     } else if (uc.x_short == (USHORT) 0xfffe) {
  2716.                         bomorder = 1 - bomorder;
  2717.                         debug(F100,"XMIT UCS2 BOM FFFE (swap)","",bomorder);
  2718.                         continue;
  2719.                     }
  2720.                 }
  2721.                 sprintf(xbuf,"%04X",uc.x_short); /* SAFE */
  2722.                 debug(F111,"XMIT UCS2",xbuf,uc.x_short);
  2723.                 if (nbytes & 1)         /* Special eol test for UCS-2 */
  2724.                   if (uc.x_short == '\n')
  2725.                     eol = 1;
  2726. #ifdef COMMENT
  2727.                 if (uc.x_short == 0x2028 || uc.x_short == 0x2029)
  2728.                     eol = 1;
  2729. #endif /* COMMENT */
  2730.             } else
  2731. #endif /* UNICODE */
  2732.               if (c == '\n') {          /* Normal eol test otherwise */
  2733.                   eol = 1;
  2734.             }
  2735.             if (eol) {                  /* End of line? */
  2736.                 int stuff = -1;
  2737.                 debug(F101,"XMIT eol length","",i);
  2738.                 if (i == 0) {           /* Blank line? */
  2739.                     if (xmitf)          /* Yes, insert fill if asked. */
  2740.                       line[i++] = dopar((char) xmitf);
  2741.                 }
  2742.                 if (i == 0 || ((char) line[i-1]) != ((char) dopar(CR)))
  2743.                   line[i++] = dopar(CR); /* Terminate it with CR */
  2744.                 if (xmitl) {
  2745.                     stuff = LF;
  2746. #ifdef TNCODE
  2747.                 } else if (is_tn && (tn_nlm != TNL_CR)) {
  2748.                     /* TELNET NEWLINE ON/OFF/RAW */
  2749.                     stuff = (tn_nlm == TNL_CRLF) ? LF : NUL;
  2750. #endif /* TNCODE */
  2751.                 }
  2752.                 if (stuff > -1)
  2753.                   line[i++] = dopar((char)stuff);
  2754.                 line[i] = NUL;
  2755.                 debug(F111,"XMIT eol line",line,i);
  2756.  
  2757.             } else if (c != -1) {       /* Not a newline, regular character */
  2758.                 int k, x;
  2759.                 outxbuf[0] = c;         /* In case of no translation */
  2760.                 outxcount = 1;          /* Assume result is one byte */
  2761. #ifndef NOCSETS
  2762.                 switch (unicode) {
  2763.                   case 0:               /* No Unicode involved */
  2764.                   case 1:
  2765.                     if (xlate) {        /* If not /TRANSPARENT */
  2766.                         /* Local-to-intermediate */
  2767.                         if (sxo) c = (*sxo)((char)c);
  2768.                         /* Intermediate-to-remote */
  2769.                         if (rxo) c = (*rxo)((char)c);
  2770.                         outxbuf[0] = c;
  2771.                     }
  2772.                     break;
  2773. #ifdef UNICODE
  2774.                   case 2:               /* Local byte to UTF-8 */
  2775.                   case 3:
  2776.                     xfu = xl_fcu[fcharset];
  2777.                     tcssize = fcsinfo[fcharset].size;
  2778.                     outxcount =
  2779.                       b_to_u((CHAR)c,outxbuf,OUTXBUFSIZ,tcssize);
  2780.                     break;
  2781.                   case 4:               /* Local UTF-8 to remote byte */
  2782.                   case 5:
  2783.                     xuf = xl_ufc[tcsr];
  2784.                     x = u_to_b((CHAR)c); /* Convert to byte */
  2785.                     if (x == -1) {      /* If more input bytes needed */
  2786.                         continue;       /* go back and get them */
  2787.                     } else if (x == -2) { /* LS or PS (shouldn't happen) */
  2788.                         outxbuf[0] = CR;
  2789.                     } else if (x == -9) { /* UTF-8 error */
  2790.                         outxbuf[0] = '?'; /* Insert error char */
  2791.                         outxbuf[1] = u_to_b2(); /* Insert next char */
  2792.                         outxcount = 2;
  2793.                     } else {
  2794.                         outxbuf[0] =    /* Otherwise store result */
  2795.                           (unsigned)(x & 0xff);
  2796.                     }
  2797.                     break;
  2798.                   case 6:               /* UTF-8 to UTF-8 */
  2799.                   case 7:
  2800.                     break;
  2801.                   case 8:               /* UCS-2 to byte */
  2802.                   case 9:
  2803.                     xuf = xl_ufc[tcsr];
  2804.                     outxbuf[0] = (*xuf)(uc.x_short);
  2805.                     break;
  2806.                   case 10:
  2807.                   case 11: {            /* UCS-2 to UTF-8 */
  2808.                       int j;
  2809.                       CHAR * buf = NULL;
  2810.                       x = ucs2_to_utf8(uc.x_short,&buf);
  2811.                       if (x < 0) {
  2812.                           outxbuf[0] = 0xff; /* (= U+FFFD) */
  2813.                           outxbuf[1] = 0xbd;
  2814.                           x = 2;
  2815.                       }
  2816.                       for (j = 0; j < x; j++)
  2817.                         outxbuf[j] = buf[j];
  2818.                       outxcount = x;
  2819.                       break;
  2820.                   }
  2821. #endif /* UNICODE */
  2822.                 }
  2823. #endif /* NOCSETS */
  2824.                 outxbuf[outxcount] = NUL;
  2825.                 debug(F111,"XMIT outxbuf",outxbuf,outxcount);
  2826. /*
  2827.   Now the input character (1 or more bytes) is translated into the output
  2828.   expansion buffer (1 or more bytes); outxcount = number of bytes to add to
  2829.   the TRANSMIT line buffer, which we do here, taking care of parity, SI/SO
  2830.   processing, and quoting Telnet IACs.
  2831. */
  2832.                 for (k = 0; k < outxcount; k++) {
  2833.                     c = outxbuf[k];
  2834.                     if (xmits && parity && (c & 0200)) { /* If shifting */
  2835.                         line[i++] = dopar(SO); /* needs to be done, */
  2836.                         line[i++] = dopar((char)c); /* do it here, */
  2837.                         line[i++] = dopar(SI); /* crudely. */
  2838.                     } else {
  2839.                         line[i++] = dopar((char)c);
  2840. #ifdef TNCODE
  2841.                         if (c == IAC && is_tn)
  2842.                           line[i++] = IAC;
  2843. #endif /* TNCODE */
  2844.                     }
  2845.                 }
  2846.             }
  2847. /*
  2848.   Send characters if buffer full, or at end of line, or at end of file.
  2849.   (End of line only if echoing, waiting for a prompt, or pausing.)
  2850. */
  2851.             debug(F000,"XMIT c",ckitoa(i),c);
  2852.             if (i >= xbufsiz || eof || (eol && (xxecho || xmitw || t))) {
  2853.                 p = line;
  2854.                 line[i] = '\0';
  2855.                 debug(F111,"transmit buf",p,i);
  2856.                 if (ttol((CHAR *)p,i) < 0) { /* try to send it. */
  2857.                     printf("?TRANSMIT output error: %s\n",ck_errstr());
  2858.                     rc = 0;
  2859.                     break;
  2860.                 }
  2861.                 i = 0;                  /* Reset buffer pointer. */
  2862. /*
  2863.   Now we handle the echo.  If the user wants to see it, or if we have to
  2864.   wait for the turnaround character, t.  If the echo is being displayed,
  2865.   and terminal character-set translation is required, we do it here.
  2866. */
  2867.                 if (duplex && xxecho) {  /* If local echo, echo it */
  2868.                     if (parity || cmdmsk == 0x7f) { /* Strip hi bits */
  2869.                         char *ss = line;             /* if necessary */
  2870.                         while (*ss) {
  2871.                             *ss &= 0x7f;
  2872.                             ss++;
  2873.                         }
  2874.                     }
  2875. #ifndef NOLOCAL
  2876. #ifdef OS2
  2877.                     {                   /* Echo to emulator */
  2878.                         char *ss = p;
  2879.                         while (*ss) {
  2880.                             scriptwrtbuf((USHORT)*ss);
  2881.                             ss++;
  2882.                         }
  2883.                     }
  2884. #endif /* OS2 */
  2885. #endif /* NOLOCAL */
  2886.                     if (conoll(p) < 0)
  2887.                       goto xmitfail;
  2888.                 }
  2889.                 if (xmitw)              /* Sleep TRANSMIT PAUSE interval */
  2890.                   msleep(xmitw);
  2891.  
  2892.                 control = 0;            /* Readback loop control */
  2893.                 if (t != 0 && eol)      /* TRANSMIT PROMPT given and at EOL */
  2894.                   control |= 1;
  2895.                 if (xxecho && !duplex)   /* Echo desired and is remote */
  2896.                   control |= 2;
  2897.  
  2898.                 if (control) {          /* Do this if reading back the echo */
  2899.                     int n;
  2900.                     x = 0;
  2901.                     while (1) {
  2902.                         if (control & 1) { /* Termination criterion */
  2903.                             if (x == t)    /* for turnaround */
  2904.                               break;
  2905.                         } else if (control & 2) { /* And for echoing */
  2906.                             if ((n = ttchk()) < 1)
  2907.                               break;
  2908.                         }
  2909.                         if ((x = ttinc(xmitt)) < 0) { /* Read with timeout */
  2910.                             switch (x) {
  2911.                               case -2:
  2912.                                 printf("Connection closed.\n");
  2913.                                 ttclos(1);
  2914.                                 goto xmitfail;
  2915.                               case -3:
  2916.                                 printf(
  2917.                               "Session Limit exceeded - closing connection.\n"
  2918.                                        );
  2919.                                 ttclos(1); /* full thru... */
  2920.                                 goto xmitfail;
  2921.                               default:
  2922.                                 printf("?Timeout\n");
  2923.                                 goto xmitfail;
  2924.                             }
  2925.                         }
  2926.                         if (x > -1 && (control & 2)) { /* Echo any echoes */
  2927.                             if (parity)
  2928.                               x &= 0x7f;
  2929.                             c = x;
  2930. #ifndef NOLOCAL
  2931. #ifdef OS2
  2932.                             scriptwrtbuf((USHORT)x);
  2933. #endif /* OS2 */
  2934. #endif /* NOLOCAL */
  2935.                             inxbuf[0] = c;
  2936.                             inxcount = 1;
  2937. #ifndef NOCSETS
  2938.                             switch (unicode & 3) { /* Remote bits */
  2939.                               case 0:
  2940.                                 if (xlate) {
  2941.                                     if (sxi) c = (*sxi)((CHAR)c);
  2942.                                     if (rxi) c = (*rxi)((CHAR)c);
  2943.                                     inxbuf[0] = c;
  2944.                                 }
  2945.                                 break;
  2946. #ifdef UNICODE
  2947.                               case 1:   /* Remote Byte to local UTF-8 */
  2948.                                 xfu = xl_fcu[tcsr];
  2949.                                 tcssize = fcsinfo[tcsr].size;
  2950.                                 inxcount =
  2951.                                   b_to_u((CHAR)c,
  2952.                                          inxbuf,
  2953.                                          OUTXBUFSIZ,
  2954.                                          tcssize
  2955.                                          );
  2956.                                 break;
  2957.                               case 2:   /* Remote UTF-8 to local Byte */
  2958.                                 xuf = xl_ufc[tcsl];
  2959.                                 x = u_to_b((CHAR)c);
  2960.                                 if (x < 0)
  2961.                                   continue;
  2962.                                 inxbuf[0] = (unsigned)(x & 0xff);
  2963.                                 break;
  2964.                               case 3:   /* UTF-8 to UTF-8 */
  2965.                                 break;
  2966. #endif /* UNICODE */
  2967.                             }
  2968. #endif /* NOCSETS */
  2969.                             inxbuf[inxcount] = NUL;
  2970.                             if (conxo(inxcount,(char *)inxbuf) < 0)
  2971.                               goto xmitfail;
  2972.                         }
  2973.                     }
  2974.                 } else                  /* Not echoing */
  2975.                   ttflui();             /* Just flush input buffer */
  2976.             } /* End of buffer-dumping block */
  2977.         } /* End of text mode */
  2978.         if (eof) {
  2979.             rc = 1;
  2980.             goto xmitexit;
  2981.         }
  2982.     } /* End of character-reading loop */
  2983.  
  2984.   xmitfail:                             /* Failure exit point */
  2985.     rc = 0;
  2986.  
  2987.   xmitexit:                             /* General exit point */
  2988.     if (rc > 0) {
  2989.         if (binary && !xmitw && !xxecho) { /* "blasting"? */
  2990.             while (count > 0) {            /* Partial buffer still to go? */
  2991.                 errno = 0;
  2992.                 y = ttol(xbbuf,count);
  2993.                 if (y < 0) {
  2994.                     printf("?TRANSMIT output error: %s\n",
  2995.                            ck_errstr());
  2996.                     debug(F111,"XMIT binary eof ttol error",
  2997.                           ck_errstr(),errno);
  2998.                     rc = 0;
  2999.                     break;
  3000.                 }
  3001.                 count -= y;
  3002.             }
  3003.         } else if (!binary && *xmitbuf) { /* Anything to send at EOF? */
  3004.             p = xmitbuf;                /* Yes, point to string. */
  3005.             while (*p)                  /* Send it. */
  3006.               ttoc(dopar(*p++));        /* Don't worry about echo here. */
  3007.         }
  3008.     }
  3009.  
  3010. #ifndef AMIGA
  3011. #ifndef MAC
  3012.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3013. #endif /* MAC */
  3014. #endif /* AMIGA */
  3015. #ifdef VMS
  3016.     concb(escape);                      /* Put terminal back, */
  3017. #endif /* VMS */
  3018.     zclose(ZIFILE);                     /* Close file, */
  3019. #ifndef NOCSETS
  3020.     language = langsv;                  /* restore language, */
  3021. #endif /* NOCSETS */
  3022.     ttres();                            /* and terminal modes, */
  3023.     return(rc);                         /* and return successfully. */
  3024. }
  3025. #endif /* NOLOCAL */
  3026. #endif /* NOXMIT */
  3027.  
  3028. #ifndef NOCSETS
  3029.  
  3030. _PROTOTYP( CHAR (*sxx), (CHAR) );       /* Local translation function */
  3031. _PROTOTYP( CHAR (*rxx), (CHAR) );       /* Local translation function */
  3032. _PROTOTYP( CHAR zl1as, (CHAR) );        /* Latin-1 to ascii */
  3033. _PROTOTYP( CHAR xl1as, (CHAR) );        /* ditto */
  3034.  
  3035. /*  X L A T E  --  Translate a local file from one character set to another */
  3036.  
  3037. /*
  3038.   Translates input file (fin) from character set csin to character set csout
  3039.   and puts the result in the output file (fout).  The two character sets are
  3040.   file character sets from fcstab.
  3041. */
  3042.  
  3043. int
  3044. xlate(fin, fout, csin, csout) char *fin, *fout; int csin, csout; {
  3045.  
  3046. #ifndef MAC
  3047. #ifdef OS2
  3048.     extern int k95stdout;
  3049.     extern int wherex[], wherey[];
  3050.     extern unsigned char colorcmd;
  3051. #ifdef NT
  3052.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  3053. #else /* NT */
  3054.     SIGTYP (* volatile oldsig)(int);    /* For saving old interrupt trap. */
  3055. #endif /* NT */
  3056. #else /* OS2 */
  3057.     SIGTYP (* oldsig)();
  3058. #endif /* OS2 */
  3059. #endif /* MAC */
  3060. #ifdef CK_ANSIC
  3061.     int (*fn)(char);                    /* Output function pointer */
  3062. #else
  3063.     int (*fn)();
  3064. #endif /* CK_ANSIC */
  3065.     extern int xlatype;
  3066.     int filecode;                       /* Code for output file */
  3067.     int scrnflg = 0;
  3068.  
  3069.     int z = 1;                          /* Return code. */
  3070.     int x, c, c2;                       /* Workers */
  3071. #ifndef UNICODE
  3072.     int tcs;
  3073. #endif /* UNICODE */
  3074.  
  3075.     ffc = 0L;
  3076.  
  3077.     if (zopeni(ZIFILE,fin) == 0) {      /* Open the file to be translated */
  3078. #ifdef COMMENT
  3079.         /* An error message was already printed by zopeni() */
  3080.         printf("?Can't open input file %s\n",fin);
  3081. #endif /* COMMENT */
  3082.         return(0);
  3083.     }
  3084. #ifdef MAC
  3085. /*
  3086.   If user specified no output file, it goes to the screen.  For the Mac,
  3087.   this must be done a special way (result goes to a new window); the Mac
  3088.   doesn't have a "controlling terminal" device name.
  3089. */
  3090.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZOFILE;
  3091. #else
  3092. #ifdef VMS
  3093.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZMFILE;
  3094. #else
  3095. #ifdef OS2
  3096.     filecode = (!stricmp(fout,"con") || !stricmp(fout,"con:")) ?
  3097.         ZCTERM : ZMFILE;
  3098.     if ((filecode == ZCTERM) && !k95stdout && !inserver)
  3099.         csout = FC_UCS2;
  3100. #else /* OS2 */
  3101.     filecode = ZOFILE;
  3102. #endif /* OS2 */
  3103. #endif /* VMS */
  3104. #endif /* MAC */
  3105.     if (zopeno(filecode,fout,NULL,NULL) == 0) { /* And the output file */
  3106.         printf("?Can't open output file %s\n",fout);
  3107.         return(0);
  3108.     }
  3109. #ifndef AMIGA
  3110. #ifndef MAC
  3111.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  3112. #endif /* MAC */
  3113. #endif /* AMIGA */
  3114.  
  3115.     scrnflg = (filecode == ZCTERM);     /* Set output function */
  3116.     if (scrnflg)
  3117.       fn = NULL;
  3118.     else if (filecode == ZMFILE)
  3119.       fn = putmfil;
  3120.     else
  3121.       fn = putfil;
  3122.  
  3123.     tr_int = 0;                         /* Have not been interrupted (yet). */
  3124.     z = 1;                              /* Return code presumed good. */
  3125.  
  3126.     if (!scrnflg && !quiet)
  3127.       printf(" %s (%s) => %s (%s)\n",   /* Say what we're doing. */
  3128.              fin, fcsinfo[csin].keyword,
  3129.              fout,fcsinfo[csout].keyword
  3130.              );
  3131.  
  3132. #ifndef UNICODE
  3133. /*
  3134.   Non-Unicode picks the "most appropriate" transfer character set as the
  3135.   intermediate set, which results in loss of any characters that the source
  3136.   and target sets have in common, but are lacking from the intermediate set.
  3137. */
  3138. #ifdef KANJI
  3139.     /* Special handling for Japanese... */
  3140.  
  3141.     if (fcsinfo[csin].alphabet == AL_JAPAN ||
  3142.          fcsinfo[csout].alphabet == AL_JAPAN) {
  3143.         USHORT eu;
  3144.         int c, x, y;
  3145.  
  3146.         xpnbyte(-1,0,0,NULL);           /* Reset output machine */
  3147.         xlatype = XLA_JAPAN;
  3148.  
  3149.         while ((c = xgnbyte(FC_JEUC,csin,NULL)) > -1) { /* Get an EUC byte */
  3150.             if (tr_int) {               /* Interrupted? */
  3151.                 printf("^C...\n");      /* Print message */
  3152.                 z = 0;
  3153.                 break;
  3154.             }
  3155.             /* Send EUC byte to output machine */
  3156.             if ((x = xpnbyte(c,TC_JEUC,csout,fn)) < 0) {
  3157.                 z = -1;
  3158.                 break;
  3159.             }
  3160.         }
  3161.         goto xxlate;
  3162.     }
  3163. #endif /* KANJI */
  3164.  
  3165.     /* Regular bytewise conversion... */
  3166.  
  3167.     tcs = gettcs(csin,csout);           /* Get intermediate set. */
  3168.     if (csin == csout) {                /* Input and output sets the same? */
  3169.         sxx = rxx = NULL;               /* If so, no translation. */
  3170.     } else {                            /* Otherwise, set up */
  3171.         if (tcs < 0 || tcs > MAXTCSETS ||
  3172.             csin < 0 || csin > MAXFCSETS ||
  3173.             csout < 0 || csout > MAXFCSETS) {
  3174.             debug(F100,"XLATE csets out of range","",0);
  3175.             sxx = rxx = NULL;
  3176.         } else {
  3177.             sxx = xls[tcs][csin];       /* translation function */
  3178.             rxx = xlr[tcs][csout];      /* pointers. */
  3179.             if (rxx == zl1as) rxx = xl1as;
  3180.         }
  3181.     }
  3182.     while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3183.         if (tr_int) {                   /* Interrupted? */
  3184.             printf("^C...\n");          /* Print message */
  3185.             z = 0;
  3186.             break;
  3187.         }
  3188.         if (sxx) c = (*sxx)((CHAR)c);   /* From fcs1 to tcs */
  3189.         if (rxx) c = (*rxx)((CHAR)c);   /* from tcs to fcs2 */
  3190.         if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3191.             z = -1;
  3192.             break;
  3193.         }
  3194.     }
  3195.     goto xxlate;                        /* Done. */
  3196.  
  3197. #else  /* UNICODE */
  3198. /*
  3199.    Use Unicode as the intermediate character set.  It's simple and gives
  3200.    little or no loss, but the overhead is a bit higher.
  3201. */
  3202.     initxlate(csin,csout);              /* Set up translation functions */
  3203.  
  3204.     if (xlatype == XLA_NONE) {
  3205.         while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3206.             if (tr_int) {               /* Interrupted? */
  3207.                 printf("^C...\n");      /* Print message */
  3208.                 z = 0;
  3209.                 break;
  3210.             }
  3211.             if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3212.                 z = -1;
  3213.                 break;
  3214.             }
  3215.         }
  3216.         goto xxlate;                    /* Done. */
  3217.     }
  3218.  
  3219.  
  3220. #ifndef NOLOCAL
  3221. #ifdef OS2
  3222.     if (csout == FC_UCS2 &&             /* we're translating to UCS-2 */
  3223.         filecode == ZCTERM &&           /* for the real screen... */
  3224.         !k95stdout && !inserver
  3225.         ) {
  3226.         union {
  3227.             USHORT ucs2;
  3228.             UCHAR  bytes[2];
  3229.         } output;
  3230.  
  3231.         while (1) {                     /* In this case we go two-by-two. */
  3232.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3233.               break;
  3234.             output.bytes[0] = c;
  3235.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3236.               break;
  3237.             output.bytes[1] = c;
  3238.  
  3239.             if (tr_int) {               /* Interrupted? */
  3240.                 printf("^C...\n");      /* Print message */
  3241.                 z = 0;
  3242.                 break;
  3243.             }
  3244.  
  3245.             VscrnWrtUCS2StrAtt(VCMD,
  3246.                                &output.ucs2,
  3247.                                1,
  3248.                                wherey[VCMD],
  3249.                                wherex[VCMD],
  3250.                                &colorcmd
  3251.                                );
  3252.         }
  3253.     } else
  3254. #endif /* OS2 */
  3255. #endif /* NOLOCAL */
  3256.  
  3257.       /* General case: Get next byte translated from fcs to UCS-2 */
  3258.  
  3259.       while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1 &&
  3260.               (c2 = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3261.           extern int fileorder;
  3262.  
  3263.           if (tr_int) {                 /* Interrupted? */
  3264.               printf("^C...\n");        /* Print message */
  3265.               z = 0;
  3266.               break;
  3267.           }
  3268.           debug(F001,"XLATE c","",c);
  3269.           debug(F001,"XLATE c2","",c2);
  3270.  
  3271.           /* And then send UCS-2 byte to translate-and-output machine */
  3272.  
  3273.           if ((x = xpnbyte(fileorder?c2:c,TC_UCS2,csout,fn)) < 0) {
  3274.               z = -1;
  3275.               break;
  3276.           }
  3277.           if ((x = xpnbyte(fileorder?c:c2,TC_UCS2,csout,fn)) < 0) {
  3278.               z = -1;
  3279.               break;
  3280.           }
  3281.       }
  3282. #endif /* UNICODE */
  3283.  
  3284.   xxlate:                               /* Common exit point */
  3285.  
  3286. #ifndef AMIGA
  3287. #ifndef MAC
  3288.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3289. #endif /* MAC */
  3290. #endif /* AMIGA */
  3291.     tr_int = 0;
  3292.     if (z < 0) {
  3293.         if (z == -1)
  3294.           printf("?File output error: %s\n",ck_errstr());
  3295.         z = 0;
  3296.     }
  3297.     zclose(ZIFILE);                     /* Close files */
  3298.     zclose(filecode);                   /* ... */
  3299.     return(success = z);                /* and return status. */
  3300. }
  3301.  
  3302. int
  3303. doxlate() {
  3304. #ifdef OS2ONLY
  3305.     extern int tt_font;
  3306. #endif /* OS2ONLY */
  3307. #ifdef UNIX
  3308.     extern char ** mtchs;               /* zxpand() file list */
  3309. #endif /* UNIX */
  3310.     extern int nfilc;
  3311.     extern struct keytab fcstab[];
  3312.     int x, y, incs, outcs, multiple = 0, wild = 0, fc = 0, len = 0;
  3313.     int ofisdir = 0;
  3314.     char * s, * tocs = "";
  3315.  
  3316.     if ((x = cmifi("File(s) to translate","",&s,&wild,xxstring)) < 0) {
  3317.         if (x == -3) {
  3318.             printf("?Name of an existing file\n");
  3319.             return(-9);
  3320.         } else
  3321.           return(x);
  3322.     }
  3323.     ckstrncpy(line,s,LINBUFSIZ);        /* Save copy of string just parsed. */
  3324.  
  3325.     if ((incs = cmkey(fcstab,nfilc,"from character-set","",xxstring)) < 0)
  3326.       return(incs);
  3327.  
  3328. #ifdef OS2
  3329.     if (isunicode())
  3330.       tocs = "ucs2";
  3331.     else
  3332. #endif /* OS2 */
  3333.       tocs = getdcset();
  3334.  
  3335.     if ((outcs = cmkey(fcstab,nfilc,"to character-set",tocs,xxstring)) < 0)
  3336.       return(outcs);
  3337.     if ((x = cmofi("output file",CTTNAM,&s,xxstring)) < 0) return(x);
  3338.     if (x > 1)
  3339.       ofisdir = 1;
  3340.  
  3341.     len = ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  3342.     if ((y = cmcfm()) < 0) return(y);   /* Confirm the command */
  3343.  
  3344.     if (len < 1)
  3345.       return(-2);
  3346.  
  3347.     if (ofisdir)
  3348.       multiple = 2;
  3349.     else if (wild) {
  3350.         if (isdir(tmpbuf))
  3351.           multiple = 2;
  3352.         else if (!strcmp(tmpbuf,CTTNAM))
  3353.           multiple = 1;
  3354. #ifdef OS2
  3355.         else if (!stricmp(tmpbuf,"con") || !stricmp(tmpbuf,"con:"))
  3356.           multiple = 1;
  3357. #else
  3358. #ifdef UNIXOROSK
  3359.         else if (!strncmp(tmpbuf,"/dev/",4))
  3360.           multiple = 1;
  3361. #endif /* UNIXOROSK */
  3362. #endif /* OS2 */
  3363.         if (!multiple) {
  3364.             printf("?A single file please\n");
  3365.             return(-9);
  3366.         }
  3367.     }
  3368.     if (!multiple) {                    /* Just one file */
  3369.         return(success = xlate(line,tmpbuf,incs,outcs));
  3370.     } else {                            /* Translate multiple files */
  3371.         char dirbuf[CKMAXPATH+4];
  3372.         int k;
  3373. #ifndef ZXREWIND
  3374.         int flags = ZX_FILONLY;
  3375. #endif /* ZXREWIND */
  3376.  
  3377.         if (multiple == 2) {            /* Target is a directory */
  3378.             k = ckstrncpy(dirbuf,tmpbuf,CKMAXPATH+1) - 1;
  3379.             if (k < 0)
  3380.               return(-2);
  3381. #ifdef OS2ORUNIX
  3382.             if (dirbuf[k] != '/') {
  3383.                 dirbuf[k+1] = '/';
  3384.                 dirbuf[k+2] = NUL;
  3385.             }
  3386. #else
  3387. #ifdef OSK
  3388.             if (dirbuf[k] != '/') {
  3389.                 dirbuf[k+1] = '/';
  3390.                 dirbuf[k+2] = NUL;
  3391.             }
  3392. #else
  3393. #ifdef VMS
  3394.             if (ckmatch("*.DIR;1",s,0,0))
  3395.               k = cvtdir(tmpbuf,dirbuf,TMPBUFSIZ);
  3396.             if (dirbuf[k] != ']' &&
  3397.                 dirbuf[k] != '>' &&
  3398.                 dirbuf[k] != ':')
  3399.               return(-2);
  3400. #else
  3401. #ifdef datageneral
  3402.             if (dirbuf[k] != ':') {
  3403.                 dirbuf[k+1] = ':';
  3404.                 dirbuf[k+2] = NUL;
  3405.             }
  3406. #else
  3407. #ifdef STRATUS
  3408.             if (dirbuf[k] != '>') {
  3409.                 dirbuf[k+1] = '>';
  3410.                 dirbuf[k+2] = NUL;
  3411.             }
  3412. #endif /* STRATUS */
  3413. #endif /* datageneral */
  3414. #endif /* VMS */
  3415. #endif /* OSK */
  3416. #endif /* OS2ORUNIX */
  3417.         }
  3418.  
  3419. #ifdef ZXREWIND
  3420.         fc = zxrewind();                /* Rewind the file list */
  3421. #else
  3422.         if (matchdot)  flags |= ZX_MATCHDOT;
  3423.         fc = nzxpand(line,flags);
  3424. #endif /* ZXREWIND */
  3425.  
  3426.         if (fc < 1) {
  3427.             printf("?Wildcard expansion error\n");
  3428.             return(-9);
  3429.         }
  3430. #ifdef UNIX
  3431.         sh_sort(mtchs,NULL,fc,0,0,filecase); /* Sort the file list */
  3432. #endif /* UNIX */
  3433.  
  3434.         while (1) {                     /* Loop through the files */
  3435.             znext(line);
  3436.             if (!line[0])
  3437.               break;
  3438.             if (multiple == 2)
  3439.               ckmakmsg(tmpbuf,TMPBUFSIZ,dirbuf,line,NULL,NULL);
  3440.             if (xlate(line,tmpbuf,incs,outcs) < 1)
  3441.               return(success = 0);
  3442.         }
  3443.     }
  3444.     return(success = 1);
  3445. }
  3446. #endif /* NOCSETS */
  3447.  
  3448. static char hompthbuf[CKMAXPATH+1];
  3449.  
  3450. char *
  3451. homepath() {
  3452.     int x;
  3453.     hompthbuf[0] = NUL;
  3454. #ifdef UNIXOROSK
  3455.     x = ckstrncpy(hompthbuf,zhome(),CKMAXPATH+1);
  3456.     if (x <= 0) {
  3457.         hompthbuf[0] = '/';
  3458.         hompthbuf[1] = NUL;
  3459.     } else if (x < CKMAXPATH - 2 && hompthbuf[x-1] != '/') {
  3460.         hompthbuf[x] = '/';
  3461.         hompthbuf[x+1] = NUL;
  3462.     }
  3463.     return(hompthbuf);
  3464. #else
  3465. #ifdef STRATUS
  3466.     if (strlen(zhome()) < CKMAXPATH)    /* SAFE */
  3467.       sprintf(hompthbuf,"%s>",zhome());
  3468.     return(hompthbuf);
  3469. #else
  3470.     return(zhome());
  3471. #endif /* STRATUS */
  3472. #endif /* UNIXOROSK */
  3473. }
  3474.  
  3475. /*  D O L O G  --  Do the log command  */
  3476.  
  3477. int
  3478. dolog(x) int x; {
  3479.     int y, disp; char *s = NULL, * p = NULL, * q = NULL;
  3480.     extern int isguest;
  3481. #ifdef ZFNQFP
  3482.     struct zfnfp * fnp;
  3483. #endif /* ZFNQFP */
  3484.  
  3485.     if (isguest) {
  3486.         printf("?Anonymous log creation not allowed\n");
  3487.         return(-9);
  3488.     }
  3489.     switch (x) {                        /* Which log... */
  3490.  
  3491. #ifdef DEBUG
  3492.       case LOGD:
  3493.         q = "debug.log";
  3494.         y = cmofi("Name of debugging log file",q,&s,xxstring);
  3495.         break;
  3496. #endif /* DEBUG */
  3497.  
  3498.       case LOGP:
  3499.         q = "packet.log";
  3500.         y = cmofi("Name of packet log file",q,&s,xxstring);
  3501.         break;
  3502.  
  3503. #ifndef NOLOCAL
  3504.       case LOGS:
  3505.         q = "session.log";
  3506.         y = cmofi("Name of session log file",q,&s,xxstring);
  3507.         break;
  3508. #endif /* NOLOCAL */
  3509.  
  3510. #ifdef TLOG
  3511.       case LOGT:
  3512.         q = "transact.log";
  3513.         y = cmofi("Name of transaction log file",q,&s,xxstring);
  3514.         break;
  3515. #endif /* TLOG */
  3516.  
  3517. #ifdef CKLOGDIAL
  3518.       case LOGM: {
  3519.           int m, n;
  3520.           char mypath[CKMAXPATH+1];
  3521.           q = CXLOGFILE;
  3522.           m = ckstrncpy(mypath,homepath(),CKMAXPATH);
  3523.           n = strlen(CXLOGFILE);
  3524.           if (m + n < CKMAXPATH)
  3525.             ckstrncat(mypath,CXLOGFILE,CKMAXPATH);
  3526.           else
  3527.             ckstrncpy(mypath,CXLOGFILE,CKMAXPATH);
  3528.           y = cmofi("Name of connection log file",mypath,&s,xxstring);
  3529.           break;
  3530.       }
  3531. #endif /* CKLOGDIAL */
  3532.  
  3533.       default:
  3534.         printf("\n?Unknown log designator - %d\n",x);
  3535.         return(-2);
  3536.     }
  3537.     if (y < 0) return(y);
  3538.     if (y == 2) {                       /* If they gave a directory name */
  3539.         int k;
  3540.         char * ds = "/";
  3541.         k = strlen(s);
  3542.         if (k > 0 && s[k-1] == '/') ds = "";
  3543.         ckmakmsg(tmpbuf,TMPBUFSIZ,s,ds,q,NULL);
  3544.         s = tmpbuf;
  3545.     }
  3546. #ifdef ZFNQFP
  3547. #ifdef OS2ORUNIX
  3548.     if (*s != '|')                      /* Allow for pipes */
  3549. #else
  3550. #ifdef OSK
  3551.     if (*s != '|')
  3552. #endif /* OSK */
  3553. #endif /* OS2ORUNIX */
  3554.       if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3555.           if (fnp->fpath)
  3556.             if ((int) strlen(fnp->fpath) > 0)
  3557.               s = fnp->fpath;
  3558.       } /* else if error keep original string */
  3559. #endif /* ZFNQFP */
  3560.  
  3561.     ckstrncpy(line,s,LINBUFSIZ);
  3562.     s = line;
  3563. #ifdef MAC
  3564.     y = 0;
  3565. #else
  3566.  
  3567.     p = "new";
  3568. #ifdef TLOG
  3569.     if ((x == LOGT && tlogfmt == 2) || x == LOGM)
  3570.       p = "append";
  3571. #endif /* TLOG */
  3572.  
  3573.     if ((y = cmkey(disptb,2,"Disposition",p,xxstring)) < 0)
  3574.       return(y);
  3575. #endif /* MAC */
  3576.     disp = y;
  3577.     if ((y = cmcfm()) < 0) return(y);
  3578.  
  3579.     switch (x) {
  3580.  
  3581. #ifdef DEBUG
  3582.       case LOGD:
  3583.         return(deblog = debopn(s,disp));
  3584. #endif /* DEBUG */
  3585.  
  3586. #ifndef NOXFER
  3587.       case LOGP:
  3588.         return(pktlog = pktopn(s,disp));
  3589. #endif /* NOXFER */
  3590.  
  3591. #ifndef NOLOCAL
  3592.       case LOGS:
  3593.         return(seslog = sesopn(s,disp));
  3594. #endif /* NOLOCAL */
  3595.  
  3596. #ifdef TLOG
  3597.       case LOGT:
  3598.         return(tralog = traopn(s,disp));
  3599. #endif /* TLOG */
  3600.  
  3601. #ifdef CKLOGDIAL
  3602.       case LOGM:
  3603.         return(dialog = diaopn(s,disp,0));
  3604. #endif /* CKLOGDIAL */
  3605.  
  3606.       default:
  3607.         return(-2);
  3608.     }
  3609. }
  3610.  
  3611. #ifndef NOXFER
  3612. int
  3613. pktopn(s,disp) char *s; int disp; {
  3614.     static struct filinfo xx;
  3615.  
  3616.     if (!s)
  3617.       s = "";
  3618.     if (!*s)
  3619.       return(0);
  3620.  
  3621.     debug(F111,"pktopn",s,disp);
  3622.  
  3623.     zclose(ZPFILE);
  3624.  
  3625. #ifdef OS2ORUNIX
  3626.     if (s[0] == '|') {                  /* Pipe */
  3627.         char * p = s + 1;
  3628.         debug(F110,"pktopn p",p,0);
  3629.         while (*p) {
  3630.             if (*p != ' ')
  3631.               break;
  3632.             else
  3633.               p++;
  3634.         }
  3635.         debug(F110,"pktopn pipe",p,0);
  3636.         pktlog = zxcmd(ZPFILE,p);
  3637.         debug(F101,"pktopn seslog","",seslog);
  3638.     } else {                            /* File */
  3639. #endif /* OS2ORUNIX */
  3640.         if (disp) {
  3641.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3642.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3643.             xx.lblopts = 0;
  3644.             pktlog = zopeno(ZPFILE,s,NULL,&xx);
  3645.         } else pktlog = zopeno(ZPFILE,s,NULL,NULL);
  3646.         if (!pktlog)
  3647.           printf("?%s - %s\n",s,ck_errstr());
  3648. #ifdef OS2ORUNIX
  3649.     }
  3650. #endif /* OS2ORUNIX */
  3651.     if (pktlog > 0)
  3652.       ckstrncpy(pktfil,s,CKMAXPATH+1);
  3653.     else
  3654.       *pktfil = '\0';
  3655.     return(pktlog);
  3656. }
  3657. #endif /* NOXFER */
  3658.  
  3659. int
  3660. traopn(s,disp) char *s; int disp; {
  3661. #ifdef TLOG
  3662.     static struct filinfo xx;
  3663.  
  3664.     if (!s)
  3665.       s = "";
  3666.     if (!*s)
  3667.       return(0);
  3668.  
  3669.     debug(F111,"traopn",s,disp);
  3670.     debug(F101,"traopn tlogfmt","",tlogfmt);
  3671.  
  3672.     zclose(ZTFILE);
  3673.  
  3674. #ifdef OS2ORUNIX
  3675.     if (tlogfmt == 2) {                 /* FTP format is special... */
  3676.         VOID doiklog();
  3677.         if (!disp)                      /* Append? */
  3678.           if (zchki(s) > -1)            /* No - does file exist? */
  3679.             (VOID) zdelet(s);           /* Yes - delete it. */
  3680.         xferlog = 1;
  3681.         ckstrncpy(trafil,s,CKMAXPATH);
  3682.         makestr(&xferfile,s);
  3683.         doiklog();
  3684.         return(1);
  3685.     }
  3686.     if (s[0] == '|') {                  /* Pipe */
  3687.         char * p = s + 1;
  3688.         debug(F110,"traopn p",p,0);
  3689.         while (*p) {
  3690.             if (*p != ' ')
  3691.               break;
  3692.             else
  3693.               p++;
  3694.         }
  3695.         debug(F110,"traopn pipe",p,0);
  3696.         tralog = zxcmd(ZTFILE,p);
  3697.         debug(F101,"traopn tralog","",tralog);
  3698.     }
  3699. #endif /* OS2ORUNIX */
  3700.  
  3701.     if (s[0] != '|') {                  /* File */
  3702.         if (disp) {
  3703.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3704.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3705.             xx.lblopts = 0;
  3706.             tralog = zopeno(ZTFILE,s,NULL,&xx);
  3707.         } else tralog = zopeno(ZTFILE,s,NULL,NULL);
  3708.     }
  3709.     if (!tralog)
  3710.       printf("?%s - %s\n",s,ck_errstr());
  3711.     if (tralog > 0 && tlogfmt > 0) {
  3712.         ckstrncpy(trafil,s,CKMAXPATH);
  3713.         tlog(F110,"Transaction Log:",versio,0L);
  3714. #ifndef MAC
  3715.         tlog(F100,ckxsys,"",0L);
  3716. #endif /* MAC */
  3717.         ztime(&s);
  3718.         tlog(F100,s,"",0L);
  3719.     } else
  3720.       *trafil = '\0';
  3721.     return(tralog);
  3722. #else
  3723.     return(0);
  3724. #endif /* TLOG */
  3725. }
  3726.  
  3727. #ifndef NOLOCAL
  3728. int
  3729. sesopn(s,disp) char * s; int disp; {
  3730.     static struct filinfo xx;
  3731.     extern int tsstate;
  3732.  
  3733.     tsstate = 0;                        /* Session log timestamp state */
  3734.  
  3735.     if (!s)
  3736.       s = "";
  3737.     if (!*s)
  3738.       return(0);
  3739.  
  3740.     debug(F111,"sesopn",s,disp);
  3741.  
  3742.     zclose(ZSFILE);
  3743.  
  3744. #ifdef OS2ORUNIX
  3745.     if (s[0] == '|') {                  /* Pipe */
  3746.         char * p = s + 1;
  3747.         debug(F110,"sesopn p",p,0);
  3748.         while (*p) {
  3749.             if (*p != ' ')
  3750.               break;
  3751.             else
  3752.               p++;
  3753.         }
  3754.         debug(F110,"sesopn pipe",p,0);
  3755.         seslog = zxcmd(ZSFILE,p);
  3756.         debug(F101,"sesopn seslog","",seslog);
  3757.     } else {                            /* File */
  3758. #endif /* OS2ORUNIX */
  3759.         if (disp) {
  3760.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3761.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3762.             xx.lblopts = 0;
  3763.             seslog = zopeno(ZSFILE,s,NULL,&xx);
  3764.         } else
  3765.           seslog = zopeno(ZSFILE,s,NULL,NULL);
  3766.         if (!seslog)
  3767.           printf("?%s - %s\n",s,ck_errstr());
  3768. #ifdef OS2ORUNIX
  3769.     }
  3770. #endif /* OS2ORUNIX */
  3771.     if (seslog > 0)
  3772.       ckstrncpy(sesfil,s,CKMAXPATH+1);
  3773.     else
  3774.       *sesfil = '\0';
  3775.     return(seslog);
  3776. }
  3777. #endif /* NOLOCAL */
  3778. #endif /* NOICP */
  3779.  
  3780. int
  3781. debopn(s,disp) char *s; int disp; {
  3782. #ifdef DEBUG
  3783. #ifdef CK_UTSNAME
  3784.     extern char unm_mch[], unm_nam[], unm_rel[], unm_ver[], unm_mod[];
  3785. #endif /* CK_UTSNAME */
  3786. #ifdef OS2
  3787.     extern char ckxsystem[];
  3788. #endif /* OS2 */
  3789.     char *tp;
  3790.     static struct filinfo xx;
  3791.  
  3792.     if (!s)
  3793.       s = "";
  3794.     if (!*s)
  3795.       return(0);
  3796.  
  3797.     zclose(ZDFILE);
  3798.  
  3799. #ifdef OS2ORUNIX
  3800.     if (s[0] == '|') {                  /* Pipe */
  3801.         char * p = s + 1;
  3802.         debug(F110,"debopn p",p,0);
  3803.         while (*p) {
  3804.             if (*p != ' ')
  3805.               break;
  3806.             else
  3807.               p++;
  3808.         }
  3809.         debug(F110,"debopn pipe",p,0);
  3810.         deblog = zxcmd(ZDFILE,p);
  3811.         debug(F101,"debopn deblog","",deblog);
  3812.     } else {                            /* File */
  3813. #endif /* OS2ORUNIX */
  3814.         if (disp) {
  3815.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3816.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3817.             xx.lblopts = 0;
  3818.             deblog = zopeno(ZDFILE,s,NULL,&xx);
  3819.         } else
  3820.           deblog = zopeno(ZDFILE,s,NULL,NULL);
  3821.         if (!deblog)
  3822.           printf("?%s - %s\n",s,ck_errstr());
  3823. #ifdef OS2ORUNIX
  3824.     }
  3825. #endif /* OS2ORUNIX */
  3826.     if (deblog > 0) {
  3827.         ckstrncpy(debfil,s,CKMAXPATH+1);
  3828.         debug(F110,"Debug Log ",versio,0);
  3829. #ifndef MAC
  3830. #ifdef OS2
  3831.         debug(F110,ckxsys,ckxsystem,0);
  3832. #else /* OS2 */
  3833.         debug(F100,ckxsys,"",0);
  3834. #endif /* OS2 */
  3835. #endif /* MAC */
  3836. #ifdef CK_UTSNAME
  3837.         if (unm_mch[0]) {
  3838.             debug(F110,"uname machine",unm_mch,0);
  3839.             if (unm_mod[0])
  3840.               debug(F110,"uname model  ",unm_mod,0);
  3841.             debug(F110,"uname sysname",unm_nam,0);
  3842.             debug(F110,"uname release",unm_rel,0);
  3843.             debug(F110,"uname version",unm_ver,0);
  3844.         }
  3845. #ifdef KTARGET
  3846.         {
  3847.             char * s;                   /* Makefile target */
  3848.             s = KTARGET;
  3849.             if (!s) s = "";
  3850.             if (!*s) s = "(unknown)";
  3851.             debug(F110,"build target",s,0);
  3852.         }
  3853. #endif /* KTARGET */
  3854.         deblog = 0;
  3855.         ztime(&tp);
  3856.         deblog = 1;
  3857.         debug(F100,tp,"",0);
  3858. #endif /* UTSNAME */
  3859.         debug(F101,"byteorder","",byteorder);
  3860. #ifndef NOICP
  3861. #ifndef NOLOCAL
  3862.         if (local) {
  3863.             debug(F110,"Active connection: ",ttname,0);
  3864.             if (!network) {
  3865.                 debug(F101,"Speed","",speed);
  3866.                 if (hwparity)
  3867.                   debug(F110,"Parity[hardware]",parnam((char)hwparity),0);
  3868.                 else
  3869.                   debug(F110,"Parity",parnam((char)parity),0);
  3870.                 deblog = 0;
  3871.                 debug(F110,"Modem",gmdmtyp(),0);
  3872.                 deblog = 1;
  3873.             }
  3874.         } else {
  3875.             debug(F110,"Active connection: ","none",0);
  3876.         }
  3877. #endif /* NOLOCAL */
  3878. #endif /* NOICP */
  3879.     } else *debfil = '\0';
  3880.     return(deblog);
  3881. #else
  3882.     return(0);
  3883. #endif /* MAC */
  3884. }
  3885.  
  3886.  
  3887. /*  C K D A T E  --  Returns current date/time in standard format  */
  3888.  
  3889. static char nowbuf[18];
  3890.  
  3891. char *
  3892. ckdate() {
  3893.     extern struct keytab cmonths[];
  3894.     int x;
  3895.     char * t;                   /* Substitute today's date */
  3896.     char dbuf[32];
  3897.     ztime(&t);
  3898.  
  3899. /*  012345678901234567890123 */
  3900. /*  Sat Jul  4 12:16:43 1998 */
  3901.  
  3902.     ckstrncpy(dbuf,t,32);
  3903.     t = dbuf;
  3904.     debug(F110,"ckdate dbuf",dbuf,0);
  3905.     nowbuf[0] = t[20];
  3906.     nowbuf[1] = t[21];
  3907.     nowbuf[2] = t[22];
  3908.     nowbuf[3] = t[23];
  3909.  
  3910.     nowbuf[4] = NUL;
  3911.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3912.  
  3913.     t[7] = NUL;
  3914.     if ((x = lookup(cmonths,t+4,12,NULL)) < 0) {
  3915.         debug(F110,"ckdate bad month",t,0);
  3916.         return("<BAD_MONTH>");
  3917.     }
  3918.     sprintf(nowbuf+4,"%02d",x);         /* SAFE */
  3919.     nowbuf[6] = (t[8] == SP) ? '0' : t[8];
  3920.     nowbuf[7] = t[9];
  3921.     nowbuf[8] = ' ';
  3922.  
  3923.     nowbuf[9] = NUL;
  3924.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3925.  
  3926.     for (x = 11; x < 19; x++) nowbuf[x-2] = t[x];
  3927.     nowbuf[17] = NUL;
  3928.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3929.  
  3930.     return((char *)nowbuf);
  3931. }
  3932.  
  3933. #ifndef NOICP
  3934. #ifdef CKLOGDIAL
  3935.  
  3936. /*
  3937.   fc = 0 for initial open, meaning open, then close immediately.
  3938.   fc > 0 for subsequent opens, meaning open for use, leave open.
  3939. */
  3940. int
  3941. diaopn(s,disp,fc) char *s; int disp, fc; {
  3942.     extern char diafil[];
  3943.     static struct filinfo xx;
  3944.  
  3945.     if (!s)
  3946.       s = "";
  3947.     if (!*s)
  3948.       return(0);
  3949.  
  3950.     debug(F110,"diaopn log",s,0);
  3951.     debug(F101,"diaopn fc",s,fc);
  3952.     debug(F101,"diaopn disp 1",s,disp);
  3953.     if (fc) disp = 1;                   /* Force append if open for use */
  3954.     debug(F101,"diaopn disp 2",s,disp);
  3955.  
  3956.     zclose(ZDIFIL);                     /* In case a log was already open */
  3957.  
  3958. #ifdef OS2ORUNIX
  3959.     if (s[0] == '|') {                  /* Pipe */
  3960.         char * p = s + 1;
  3961.         debug(F110,"diaopn p",p,0);
  3962.         while (*p) {
  3963.             if (*p != ' ')
  3964.               break;
  3965.             else
  3966.               p++;
  3967.         }
  3968.         debug(F110,"diaopn pipe",p,0);
  3969.         dialog = zxcmd(ZDIFIL,p);
  3970.         debug(F101,"diaopn dialog","",dialog);
  3971.     } else {                            /* File */
  3972. #endif /* OS2ORUNIX */
  3973.         if (disp) {
  3974.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3975.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3976.             xx.lblopts = 0;
  3977.             dialog = zopeno(ZDIFIL,s,NULL,&xx);
  3978.         } else dialog = zopeno(ZDIFIL,s,NULL,NULL);
  3979.         if (!dialog)
  3980.           printf("?%s - %s\n",s,ck_errstr());
  3981. #ifdef OS2ORUNIX
  3982.     }
  3983. #endif /* OS2ORUNIX */
  3984.     if (dialog > 0)
  3985.       ckstrncpy(diafil,s,CKMAXPATH+1);
  3986.     else
  3987.       *diafil = '\0';
  3988.     if (fc == 0)                        /* Initial open */
  3989.       zclose(ZDIFIL);                   /* close it */
  3990.     return(dialog);
  3991. }
  3992. #endif /* CKLOGDIAL */
  3993.  
  3994. #ifndef NOSHOW
  3995.  
  3996. /*  SHOW command routines */
  3997.  
  3998. char *
  3999. shoxm() {
  4000.     char * s;
  4001.     switch (binary) {
  4002.       case XYFT_T: s = "text";         break;
  4003. #ifdef VMS
  4004.       case XYFT_B: s = "binary fixed"; break;
  4005.       case XYFT_I: s = "image";        break;
  4006.       case XYFT_L: s = "labeled";      break;
  4007.       case XYFT_U: s = "binary undef"; break;
  4008. #else
  4009. #ifdef MAC
  4010.       case XYFT_B: s = "binary";       break;
  4011.       case XYFT_M: s = "macbinary";    break;
  4012. #else
  4013.       case XYFT_B: s = "binary";       break;
  4014. #ifdef CK_LABELED
  4015.       case XYFT_L: s = "labeled";      break;
  4016. #endif /* CK_LABELED */
  4017. #endif /* MAC */
  4018. #endif /* VMS */
  4019.       default: s = "unknown"; break;
  4020.     }
  4021.     return(s);
  4022. }
  4023.  
  4024. #ifndef NOXFER
  4025. VOID                                    /* SHOW TRANSFER */
  4026. shoxfer() {
  4027.     extern int docrc, usepipes, xfrxla;
  4028.     extern char * xfrmsg;
  4029.     printf("\n");
  4030.     printf(" Transfer Bell: %s\n",showoff(xfrbel));
  4031.     printf(" Transfer Interruption: %s\n",showoff(xfrint));
  4032.     printf(" Transfer Cancellation: %s\n",showoff(xfrcan));
  4033. #ifndef NOCSETS
  4034.     printf(" Transfer Translation:  %s\n",showoff(xfrxla));
  4035.     printf(" Transfer Character-set: ");
  4036.     if (tcharset == TC_TRANSP)
  4037.       printf("Transparent\n");
  4038.     else
  4039.       printf("%s\n",tcsinfo[tcharset].keyword);
  4040. #endif /* NOCSETS */
  4041.     printf(" Transfer CRC-calculation: %s\n",showoff(docrc));
  4042.     printf(" Transfer Display: ");
  4043.     switch (fdispla) {
  4044.       case XYFD_N: printf("%s\n","none"); break;
  4045.       case XYFD_R: printf("%s\n","serial"); break;
  4046.       case XYFD_C: printf("%s\n","fullscreen"); break;
  4047.       case XYFD_S: printf("%s\n","crt"); break;
  4048.       case XYFD_B: printf("%s\n","brief"); break;
  4049.     }
  4050.     printf(" Transfer Message: %s\n", xfrmsg ? xfrmsg : "(none)");
  4051.     printf(" Transfer Locking-shift: ");
  4052.     if (lscapu == 2) {
  4053.         printf("forced");
  4054.     } else {
  4055.         printf("%s", (lscapr ? "enabled" : "disabled"));
  4056.         if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  4057.     }
  4058.     printf("\n Transfer Mode: %s\n",
  4059.            xfermode == XMODE_A ?
  4060.            "automatic" :
  4061.            "manual"
  4062.            );
  4063.     printf(" Transfer Pipes: %s\n", showoff(usepipes));
  4064.     printf(" Transfer Protocol: %s\n",ptab[protocol].p_name);
  4065.     printf(" Transfer Slow-start: %s\n",showoff(slostart));
  4066.     printf("\n");
  4067. }
  4068. #endif /* NOXFER */
  4069.  
  4070. VOID
  4071. shoflow() {
  4072.     int i, x;
  4073.     extern int cxflow[], cxtype, ncxname, nfloname, autoflow;
  4074.     extern char * cxname[];
  4075.     printf("\nConnection type:        %s\n",cxname[cxtype]);
  4076.     if (autoflow) {
  4077.         printf("Current flow-control:   %s\n", floname[cxflow[cxtype]]);
  4078.         printf("Switches automatically: yes\n");
  4079.     } else {
  4080.         printf("Current flow-control:   %s\n", floname[flow]);
  4081.         printf("Switches automatically: no\n");
  4082.     }
  4083.     printf("\nDefaults by connection type:\n");
  4084.     debug(F111,"shoflow cxtype",cxname[cxtype],cxtype);
  4085.     debug(F101,"shoflow flow","",flow);
  4086.     for (i = 0; i < ncxname; i++) {
  4087. #ifdef NOLOCAL
  4088.         if (i > 0) break;
  4089. #endif /* NOLOCAL */
  4090. #ifndef NETCONN
  4091.         if (i > 2) break;
  4092. #endif /* NETCONN */
  4093. #ifndef DECNET
  4094.         if (i == CXT_DECNET) continue;
  4095. #endif /* DECNET */
  4096. #ifndef DECNET
  4097. #ifndef SUPERLAT
  4098.         if (i == CXT_LAT) continue;
  4099. #endif /* SUPERLAT */
  4100. #endif /* DECNET */
  4101. #ifndef CK_NETBIOS
  4102.         if (i == CXT_NETBIOS) continue;
  4103. #endif /* CK_NETBIOS */
  4104. #ifndef NPIPE
  4105.         if (i == CXT_NPIPE) continue;
  4106. #endif /* NPIPE */
  4107. #ifndef NETCMD
  4108.         if (i == CXT_PIPE) continue;
  4109. #endif /* NETCMD */
  4110. #ifndef ANYX25
  4111.         if (i == CXT_X25) continue;
  4112. #endif /* ANYX25 */
  4113.         x = cxflow[i];
  4114.         debug(F101,"shoflow x","",x);
  4115.         if (x < nfloname)
  4116.           printf("  %-14s: %s\n",cxname[i],floname[x]);
  4117.         else
  4118.           printf("  %-14s: (%d)\n",cxname[i],x);
  4119.     }
  4120.     printf("\n");
  4121. }
  4122.  
  4123. #ifndef NOLOCAL
  4124. #ifdef ANYX25
  4125. int
  4126. shox25(n) int n; {
  4127.     if (nettype == NET_SX25) {
  4128.         printf("SunLink X.25 V%d.%d",x25ver / 10,x25ver % 10);
  4129.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4130.         printf("\n");
  4131.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4132.         printf(" Reverse charge call %s",
  4133.                revcall ? "selected" : "not selected");
  4134.         printf (", Closed user group ");
  4135.         if (closgr > -1)
  4136.           printf ("%d",closgr);
  4137.         else
  4138.           printf ("not selected");
  4139.         printf("\n");
  4140.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4141.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4142.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4143.     } else if (nettype == NET_VX25) {
  4144.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4145.         printf("\n");
  4146.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4147.         printf(" Reverse charge call %s",
  4148.                revcall ? "selected" : "not selected");
  4149.         printf (", Closed user group [unsupported]");
  4150.         if (closgr > -1)
  4151.           printf ("%d",closgr);
  4152.         else
  4153.           printf ("not selected");
  4154.         printf (",");
  4155.         printf("\n");
  4156.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4157.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4158.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4159.     } else if (nettype == NET_IX25) {
  4160.         printf("AIX NPI X.25\n");
  4161.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4162.         printf("\n Reverse charge call %s",
  4163.                revcall ? "selected" : "not selected");
  4164.         printf (", Closed user group [unsupported]");
  4165.         if (closgr > -1)
  4166.           printf ("%d",closgr);
  4167.         else
  4168.           printf ("not selected");
  4169.         printf (",");
  4170.         printf("\n Call user data %s.\n", cudata ? udata : "not selected");
  4171.     }
  4172.     return(n);
  4173. }
  4174.  
  4175. #ifndef IBMX25
  4176. int
  4177. shopad(n) int n; {
  4178.     int i;
  4179.     printf("\nX.3 PAD Parameters:\n");
  4180.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4181.     for (i = 0; i < npadx3; i++) {
  4182.         printf(" [%d] %s %d\n",padx3tab[i].kwval,padx3tab[i].kwd,
  4183.                padparms[padx3tab[i].kwval]);
  4184.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4185.     }
  4186.     return(n);
  4187. }
  4188. #endif /* IBMX25 */
  4189. #endif /* ANYX25 */
  4190.  
  4191. VOID
  4192. shoparc() {
  4193.     extern int reliable, stopbits, clsondisc;
  4194.     int i; char *s;
  4195.     long zz;
  4196.  
  4197. #ifdef NEWFTP
  4198.     if (ftpisconnected()) {
  4199.         shoftp(1);
  4200.         printf("\n");
  4201.     }
  4202. #endif /* NEWFTP */
  4203.  
  4204.     printf("Communications Parameters:\n");
  4205.  
  4206.     if (network
  4207. #ifdef IKSD
  4208.          || inserver
  4209. #endif /* IKSD */
  4210.          ) {
  4211.         printf(" Network Host: %s%s",ttname,
  4212.                (reliable == SET_ON || (reliable == SET_AUTO && !local)
  4213. #ifdef TN_COMPORT
  4214.                && !istncomport()
  4215. #endif /* TN_COMPORT */
  4216. #ifdef IKSD
  4217.                || inserver
  4218. #endif /* IKSD */
  4219.                ) ? " (reliable)" : "");
  4220. #ifdef TN_COMPORT
  4221.         if (istncomport()) {
  4222.             int modemstate;
  4223.             char * oflow, * iflow = "", * parity, * stopsize;
  4224.             int baud = tnc_get_baud();
  4225.  
  4226.             switch (tnc_get_oflow()) {
  4227.               case TNC_CTL_OFLOW_NONE:
  4228.                 oflow = "none";
  4229.                 break;
  4230.               case TNC_CTL_OFLOW_XON_XOFF:
  4231.                 oflow = "xon/xoff";
  4232.                 break;
  4233.               case TNC_CTL_OFLOW_RTS_CTS:
  4234.                 oflow = "rts/cts";
  4235.                 break;
  4236.               case TNC_CTL_OFLOW_DCD:
  4237.                 oflow = "dcd";
  4238.                 break;
  4239.               case TNC_CTL_OFLOW_DSR:
  4240.                 oflow = "dsr";
  4241.                 break;
  4242.               default:
  4243.                 oflow = "(unknown)";
  4244.             }
  4245.             switch (tnc_get_iflow()) {
  4246.               case TNC_CTL_IFLOW_NONE:
  4247.                 iflow = "none";
  4248.                 break;
  4249.               case TNC_CTL_IFLOW_XON_XOFF:
  4250.                 iflow = "xon/xoff";
  4251.                 break;
  4252.               case TNC_CTL_IFLOW_RTS_CTS:
  4253.                 iflow = "rts/cts";
  4254.                 break;
  4255.               case TNC_CTL_IFLOW_DTR:
  4256.                 break;
  4257.               default:
  4258.                 iflow = oflow;
  4259.             }
  4260.             switch (tnc_get_parity()) {
  4261.               case TNC_PAR_NONE:
  4262.                 parity = "none";
  4263.                 break;
  4264.               case TNC_PAR_ODD:
  4265.                 parity = "odd";
  4266.                 break;
  4267.               case TNC_PAR_EVEN:
  4268.                 parity = "even";
  4269.                 break;
  4270.               case TNC_PAR_MARK:
  4271.                 parity = "mark";
  4272.                 break;
  4273.               case TNC_PAR_SPACE:
  4274.                 parity = "space";
  4275.                 break;
  4276.               default:
  4277.                 parity = "(unknown)";
  4278.             }
  4279.             switch (tnc_get_stopsize()) {
  4280.               case TNC_SB_1:
  4281.                 stopsize = "1";
  4282.                 break;
  4283.               case TNC_SB_1_5:
  4284.                 stopsize = "1.5";
  4285.                 break;
  4286.               case TNC_SB_2:
  4287.                 stopsize = "2";
  4288.                 break;
  4289.               default:
  4290.                 stopsize = "(unknown)";
  4291.             }
  4292.             printf("\n  Signature            : %s\n", tnc_get_signature());
  4293.             if (baud <= 0)
  4294.               printf("  Speed                : (unknown)\n");
  4295.             else
  4296.               printf("  Speed                : %d\n", baud);
  4297.             printf("  Outbound Flow Control: %s\n", oflow);
  4298.             printf("  Inbound Flow Control : %s\n", iflow);
  4299.             printf("  Parity               : %s\n", parity);
  4300.             printf("  Data Size            : %d\n", tnc_get_datasize());
  4301.             printf("  Stop Bits            : %s\n", stopsize);
  4302.             printf("  DTR Signal           : %d\n", tnc_get_dtr_state());
  4303.             printf("  RTS Signal           : %d\n", tnc_get_rts_state());
  4304.             printf("  Modem State:\n");
  4305.             modemstate = tnc_get_ms();
  4306.             if (modemstate & TNC_MS_EDGE_RING)
  4307.               printf("    Trailing Edge Ring Detector On\n");
  4308.             else
  4309.               printf("    Trailing Edge Ring Detector Off\n");
  4310.             if (modemstate & TNC_MS_CTS_SIG)
  4311.               printf("    CTS Signal On\n");
  4312.             else
  4313.               printf("    CTS Signal Off\n");
  4314.             if (modemstate & TNC_MS_DSR_SIG)
  4315.               printf("    DSR Signal On\n");
  4316.             else
  4317.               printf("    DSR Signal Off\n");
  4318.             if (modemstate & TNC_MS_RI_SIG)
  4319.               printf("    Ring Indicator On\n");
  4320.             else
  4321.               printf("    Ring Indicator Off\n");
  4322.             if (modemstate & TNC_MS_RLSD_SIG)
  4323.               printf("    RLSD (CD) Signal On\n");
  4324.             else
  4325.               printf("    RLSD (CD) Signal Off\n");
  4326.             printf("\n");
  4327.         }
  4328. #endif /* TN_COMPORT */
  4329.     } else {
  4330.  
  4331.         printf(" %s: %s%s, speed: ",
  4332. #ifdef OS2
  4333.                "Port",
  4334. #else
  4335.                "Line",
  4336. #endif /* OS2 */
  4337.                ttname,
  4338. #ifdef CK_TTYFD
  4339.                (local &&
  4340. #ifdef VMS
  4341.                 vmsttyfd() < 0
  4342. #else
  4343.                 ttyfd == -1
  4344. #endif /* VMS */
  4345.                 ) ?
  4346.                  " (closed)" :
  4347.                    (reliable == SET_ON ? " (reliable)" : "")
  4348. #else
  4349.                ""
  4350. #endif /* CK_TTYFD */
  4351.                );
  4352.         if (
  4353. #ifdef CK_TTYFD
  4354. #ifdef VMS
  4355.             vmsttyfd() < 0
  4356. #else
  4357.             ttyfd == -1
  4358. #endif /* VMS */
  4359.             ||
  4360. #endif /* CK_TTYFD */
  4361.             (zz = ttgspd()) < 0) {
  4362.             printf("unknown");
  4363.         } else {
  4364.             if (speed == 8880) printf("75/1200");
  4365.             else if (speed == 134) printf("134.5");
  4366.             else printf("%ld",zz);
  4367.         }
  4368.     }
  4369.     if (network
  4370. #ifdef IKSD
  4371.          || inserver
  4372. #endif /* IKSD */
  4373.          )
  4374.       printf("\n Mode: ");
  4375.     else
  4376.       printf(", mode: ");
  4377.     if (local) printf("local"); else printf("remote");
  4378.     if (network == 0
  4379. #ifdef IKSD
  4380.          && !inserver
  4381. #endif/* IKSD */
  4382.          ) {
  4383. #ifdef CK_TAPI
  4384.         if (tttapi && !tapipass )
  4385.           printf(", modem: %s","TAPI");
  4386.         else
  4387. #endif /* CK_TAPI */
  4388.         printf(", modem: %s",gmdmtyp());
  4389.     } else {
  4390. #ifdef NETCONN
  4391.        if (nettype == NET_TCPA) printf(", TCP/IP");
  4392.        if (nettype == NET_TCPB) printf(", TCP/IP");
  4393.        if (nettype == NET_DEC) {
  4394.            if (ttnproto == NP_LAT) printf(", DECnet LAT");
  4395.            else if ( ttnproto == NP_CTERM ) printf(", DECnet CTERM");
  4396.            else printf(", DECnet");
  4397.        }
  4398.        if (nettype == NET_SLAT) printf(", Meridian Technologies' SuperLAT");
  4399. #ifdef NETFILE
  4400.        if (nettype == NET_FILE) printf(", local file");
  4401. #endif /* NETFILE */
  4402. #ifdef NETCMD
  4403.        if (nettype == NET_CMD) printf(", pipe");
  4404. #endif /* NETCMD */
  4405. #ifdef NETPTY
  4406.        if (nettype == NET_PTY) printf(", pseudoterminal");
  4407. #endif /* NETPTY */
  4408. #ifdef NETDLL
  4409.        if (nettype == NET_DLL) printf(", dynamic load library");
  4410. #endif /* NETDLL */
  4411.        if (nettype == NET_PIPE) printf(", Named Pipes");
  4412. #ifdef SSHBUILTIN
  4413.        if (nettype == NET_SSH)
  4414.          printf(", Secure Shell protocol (SECURE)");
  4415. #endif /* SSHBUILTIN */
  4416. #ifdef ANYX25
  4417.        if (shox25(0) < 0) return;
  4418. #endif /* ANYX25 */
  4419.        if (IS_TELNET()) {
  4420.            printf(", telnet protocol");
  4421.            if (0
  4422. #ifdef CK_ENCRYPTION
  4423.                || ck_tn_encrypting() && ck_tn_decrypting()
  4424. #endif /* CK_ENCRYPTION */
  4425. #ifdef CK_SSL
  4426.                || tls_active_flag || ssl_active_flag
  4427. #endif /* CK_SSL */
  4428.                )
  4429.              printf(" (SECURE)");
  4430.        }
  4431. #ifdef RLOGCODE
  4432.        else if (ttnproto == NP_RLOGIN || ttnproto == NP_K4LOGIN ||
  4433.                 ttnproto == NP_K5LOGIN)
  4434.          printf(", rlogin protocol");
  4435.        else if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN)
  4436.          printf(", rlogin protocol (SECURE)");
  4437. #endif /* RLOGCODE */
  4438. #ifdef CK_KERBEROS
  4439. #ifdef KRB5
  4440.        else if (ttnproto == NP_K5U2U)
  4441.          printf(", Kerberos 5 User to User protocol (SECURE)");
  4442. #endif /* KRB5 */
  4443. #endif /* CK_KERBEROS */
  4444. #endif /* NETCONN */
  4445.     }
  4446.     printf("\n");
  4447.     if (hwparity && local && !network)
  4448.       s = parnam((char)hwparity);
  4449.     else
  4450.       s = parnam((char)parity);
  4451.     printf(" Parity: %s%s",hwparity ? "hardware " : "", s);
  4452. #ifndef NOLOCAL
  4453.     if (local && !network) {
  4454.         int sb;
  4455.         char c;
  4456.         c = s[0];
  4457.         if (islower(c)) c = toupper(c);
  4458.         sb = stopbits;
  4459.         if (sb < 1) {
  4460.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  4461.             printf(", stop-bits: (default)");
  4462.         } else {
  4463.             printf(", stop-bits: %d",sb);
  4464.         }
  4465.         if (hwparity)
  4466.           printf(" (8%c%d)",c,sb);
  4467.         else if (parity)
  4468.           printf(" (7%c%d)",c,sb);
  4469.         else
  4470.           printf(" (8N%d)",sb);
  4471.         printf("\n D");
  4472.     } else
  4473.       printf(", d");
  4474. #endif /* NOLOCAL */
  4475.  
  4476.     printf("uplex: %s, ", duplex ? "half" : "full");
  4477.     debug(F101,"shoparp flow","",flow);
  4478.     printf("flow: %s", floname[flow]);
  4479.     printf(", handshake: ");
  4480.     if (turn) printf("%d\n",turnch); else printf("none\n");
  4481. #ifdef COMMENT
  4482.     if (local && !network) {            /* SET CARRIER-WATCH */
  4483. #endif /* COMMENT */
  4484.         if (carrier == CAR_OFF) s = "off";
  4485.         else if (carrier == CAR_ON) s = "on";
  4486.         else if (carrier == CAR_AUT) s = "auto";
  4487.         else s = "unknown";
  4488.         printf(" Carrier-watch: %s", s);
  4489.         if (carrier == CAR_ON) {
  4490.             if (cdtimo) printf(", timeout: %d sec", cdtimo);
  4491.             else printf(", timeout: none");
  4492.         }
  4493. #ifdef COMMENT
  4494.     }
  4495. #endif /* COMMENT */
  4496.     printf(", close-on-disconnect: %s\n",showoff(clsondisc));
  4497.  
  4498. #ifdef UNIX                             /* UUCP lockfile, UNIX only */
  4499.     if (local) {
  4500. #ifndef NOUUCP
  4501.         if (!network && haslock && *flfnam)
  4502.           printf(" Lockfile: %s",flfnam);
  4503. #ifndef USETTYLOCK
  4504.         if (!network && haslock && lock2[0])
  4505.           printf("\n Secondary lockfile: %s",lock2);
  4506. #endif /* USETTYLOCK */
  4507. #else
  4508. #ifdef QNX
  4509.         {
  4510.             extern int qnxportlock, qnxopencount();
  4511.             if (local)
  4512.               printf(" Qnx-port-lock: %s, Open count: %d",
  4513.                      showoff(qnxportlock),
  4514.                      qnxopencount()
  4515.                      );
  4516.             else
  4517.               printf(" Qnx-port-lock: %s", showoff(qnxportlock));
  4518.         }
  4519. #endif /* QNX */
  4520. #endif /* NOUUCP */
  4521.         printf("\n");
  4522.     } else {
  4523.         char * s, * ttglckdir();
  4524.         s = ttglckdir();
  4525.         if (!s) s = "";
  4526.         printf(" Lockfile directory: %s\n", *s ? s : "(none)");
  4527.     }
  4528. #endif /* UNIX */
  4529.     if (!local) {
  4530.         printf(" Typical port device name: %s\n",ttgtpn());
  4531.     }
  4532.     if (local) {
  4533.         int i;
  4534.         i = parity ? 7 : 8;
  4535.         if (i == 8) i = (cmask == 0177) ? 7 : 8;
  4536.         printf(" Terminal bytesize: %d,",i);
  4537.         printf(" escape character: %d (^%c)\n",escape,ctl(escape));
  4538.     }
  4539. }
  4540.  
  4541. int
  4542. shotcp(n) int n; {
  4543. #ifdef TCPSOCKET
  4544.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  4545.         printf("SET TCP parameters:\n");
  4546.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4547.         printf(" Reverse DNS lookup: %s\n", showooa(tcp_rdns));
  4548.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4549.  
  4550. #ifdef CK_DNS_SRV
  4551.         printf(" DNS Service Records lookup: %s\n", showooa(tcp_dns_srv));
  4552.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4553. #endif /* CK_DNS_SRV */
  4554.  
  4555. #ifndef NOTCPOPTS
  4556. #ifdef SOL_SOCKET
  4557. #ifdef SO_KEEPALIVE
  4558.         printf(" Keepalive: %s\n", showoff(tcp_keepalive));
  4559.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4560. #endif /* SO_KEEPALIVE */
  4561.  
  4562. #ifdef SO_LINGER
  4563.         printf(" Linger: %s", tcp_linger ? "on, " : "off\n" );
  4564.         if (tcp_linger) {
  4565.             if (tcp_linger_tmo)
  4566.               printf("%d x 10 milliseconds\n",tcp_linger_tmo);
  4567.             else
  4568.               printf("no timeout\n");
  4569.         }
  4570.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4571. #endif /* SO_LINGER */
  4572.  
  4573. #ifdef SO_DONTROUTE
  4574.         printf(" DontRoute: %s\n", tcp_dontroute ? "on" : "off" );
  4575.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4576. #endif /* SO_DONTROUTE */
  4577.  
  4578. #ifdef TCP_NODELAY
  4579.         printf(" Nodelay: %s\n", showoff(tcp_nodelay));
  4580.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4581. #endif /* TCP_NODELAY */
  4582.  
  4583. #ifdef SO_SNDBUF
  4584.         if (tcp_sendbuf <= 0)
  4585.           printf(" Send buffer: (default size)\n");
  4586.         else
  4587.           printf(" Send buffer: %d bytes\n", tcp_sendbuf);
  4588.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4589. #endif /* SO_SNDBUF */
  4590. #ifdef SO_RCVBUF
  4591.         if (tcp_recvbuf <= 0)
  4592.           printf(" Receive buffer: (default size)\n");
  4593.         else
  4594.           printf(" Receive buffer: %d bytes\n", tcp_recvbuf);
  4595.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4596. #endif /* SO_RCVBUF */
  4597. #endif /* SOL_SOCKET */
  4598. #endif /* NOTCPOPTS */
  4599.         printf(" address: %s\n",tcp_address ? tcp_address : "(none)");
  4600.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4601. #ifndef NOHTTP
  4602.         printf(" http-proxy: %s\n",tcp_http_proxy ? tcp_http_proxy : "(none)");
  4603.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4604. #endif /* NOHTTP */
  4605. #ifdef NT
  4606. #ifdef CK_SOCKS
  4607.         printf(" socks-server: %s\n",tcp_socks_svr ? tcp_socks_svr : "(none)");
  4608.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4609. #ifdef CK_SOCKS_NS
  4610.         printf(" socks-name-server: %s\n",
  4611.                tcp_socks_ns ? tcp_socks_ns : "(none)");
  4612.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4613. #endif /* CK_SOCKS_NS */
  4614. #endif /* CK_SOCKS */
  4615. #endif /* NT */
  4616.     }
  4617. #endif /* TCPSOCKET */
  4618.     return(n);
  4619. }
  4620.  
  4621. #ifdef TNCODE
  4622. int
  4623. shotopt(n) int n; {
  4624.     int opt;
  4625.  
  4626.     printf("%-21s %12s %12s %12s %12s\n\n",
  4627.            "Telnet Option","Me (client)","U (client)",
  4628.            "Me (server)","U (server)");
  4629.     n += 2;
  4630.     if (n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4631.  
  4632.     for ( opt = TELOPT_FIRST; opt <= TELOPT_LAST; opt++) {
  4633.         switch (opt) {
  4634.           case TELOPT_AUTHENTICATION:
  4635.           case TELOPT_ENCRYPTION:
  4636.           case TELOPT_TTYPE:
  4637.           case TELOPT_NAWS:
  4638.           case TELOPT_BINARY:
  4639.           case TELOPT_NEWENVIRON:
  4640.           case TELOPT_SNDLOC:
  4641.           case TELOPT_XDISPLOC:
  4642.           case TELOPT_SGA:
  4643.           case TELOPT_ECHO:
  4644.           case TELOPT_KERMIT:
  4645.           case TELOPT_START_TLS:
  4646.           case TELOPT_FORWARD_X:
  4647.           case TELOPT_COMPORT:
  4648.             break;
  4649.           default:
  4650.             continue;
  4651.         }
  4652.         printf("%03d %-17s ",
  4653.                opt, TELOPT(opt)
  4654.                );
  4655.         printf("%12s %12s ",
  4656.                TELOPT_MODE(TELOPT_DEF_C_ME_MODE(opt)),
  4657.                TELOPT_MODE(TELOPT_DEF_C_U_MODE(opt))
  4658.                );
  4659.         printf("%12s %12s\n",
  4660.                TELOPT_MODE(TELOPT_DEF_S_ME_MODE(opt)),
  4661.                TELOPT_MODE(TELOPT_DEF_S_U_MODE(opt))
  4662.                );
  4663.  
  4664.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4665.         if (sstelnet)
  4666.           printf("%21s %12s %12s %12s %12s\n",
  4667.                  "",
  4668.                  "",
  4669.                  "",
  4670.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4671.                  (TELOPT_U(opt)?"DO":"DONT")
  4672.                  );
  4673.         else
  4674.           printf("%21s %12s %12s %12s %12s\n",
  4675.                  "",
  4676.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4677.                  (TELOPT_U(opt)?"DO":"DONT"),
  4678.                  "",
  4679.                  ""
  4680.                  );
  4681.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4682.     }
  4683.     return(n);
  4684. }
  4685.  
  4686. int
  4687. shotel(n) int n; {
  4688.     extern int tn_duplex;
  4689. #ifdef CK_ENVIRONMENT
  4690.     extern int tn_env_flg;
  4691.     extern char tn_env_acct[];
  4692.     extern char tn_env_job[];
  4693.     extern char tn_env_prnt[];
  4694.     extern char tn_env_sys[];
  4695.     extern char * tn_env_uservar[8][2];
  4696.     int x;
  4697. #endif /* CK_ENVIRONMENT */
  4698. #ifdef CK_SNDLOC
  4699.     extern char * tn_loc;
  4700. #endif /* CK_SNDLOC */
  4701.     printf("SET TELNET parameters:\n echo: %s\n NVT newline-mode: ",
  4702.            tn_duplex ? "local" : "remote");
  4703.     switch (tn_nlm) {
  4704.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4705.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4706.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4707.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4708.     }
  4709.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4710. #ifdef CK_AUTHENTICATION
  4711.     {
  4712.         int type = ck_tn_authenticated();
  4713.         printf(" authentication: ");
  4714.         switch (sstelnet ?
  4715.                 TELOPT_U_MODE(TELOPT_AUTHENTICATION) :
  4716.                  TELOPT_ME_MODE(TELOPT_AUTHENTICATION)
  4717.                 ) {
  4718.           case TN_NG_AC: printf( "accepted " ); break;
  4719.           case TN_NG_RF: printf( "refused  " ); break;
  4720.           case TN_NG_RQ: printf( "requested"); break;
  4721.           case TN_NG_MU: printf( "required "); break;
  4722.         }
  4723.  
  4724. #ifdef CK_SSL
  4725.         if ((ssl_active_flag || tls_active_flag) &&
  4726.              ck_tn_auth_valid() == AUTH_VALID &&
  4727.              (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  4728.                type == AUTHTYPE_NULL ||
  4729.                type == AUTHTYPE_AUTO))
  4730.             printf("   in use: X.509 certificate\n");
  4731.         else
  4732. #endif /* CK_SSL */
  4733.           printf("   in use: %s\n",AUTHTYPE_NAME(type));
  4734.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4735.         if (forward_flag)
  4736.           printf("  credentials forwarding requested %s\n",
  4737.                  forwarded_tickets ? "and completed" :
  4738.                  "but not completed");
  4739.         else
  4740.           printf("  credentials forwarding disabled\n");
  4741.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4742.     }
  4743. #endif /* CK_AUTHENTICATION */
  4744. #ifdef CK_ENCRYPTION
  4745.     {
  4746.         int i,x;
  4747.         int e_type = ck_tn_encrypting();
  4748.         int d_type = ck_tn_decrypting();
  4749.         char * e_str = NULL, * d_str = NULL;
  4750.         static struct keytab * tnetbl = NULL;
  4751.         static int ntnetbl = 0;
  4752.  
  4753.         x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  4754.  
  4755.         for (i = 0; i < ntnetbl; i++) {
  4756.             if (e_type == tnetbl[i].kwval)
  4757.               e_str = tnetbl[i].kwd;
  4758.             if (d_type == tnetbl[i].kwval)
  4759.               d_str = tnetbl[i].kwd;
  4760.         }
  4761.         printf(" encryption: ");
  4762.         switch (TELOPT_ME_MODE(TELOPT_ENCRYPTION)) {
  4763.           /* This should be changed to report both ME and U modes */
  4764.           case TN_NG_AC: printf( "accepted " ); break;
  4765.           case TN_NG_RF: printf( "refused  " ); break;
  4766.           case TN_NG_RQ: printf( "requested"); break;
  4767.           case TN_NG_MU: printf( "required "); break;
  4768.         }
  4769.         printf("       in use: ");
  4770.         switch ((e_type ? 1 : 0) | (d_type ? 2 : 0)) {
  4771.           case 0:
  4772.             printf("plain text in both directions");
  4773.             break;
  4774.           case 1:
  4775.             printf("%s output, plain text input",e_str);
  4776.             break;
  4777.           case 2:
  4778.             printf("plain text output, %s input",d_str);
  4779.             break;
  4780.           case 3:
  4781.             printf("%s output, %s input",e_str,d_str);
  4782.             break;
  4783.         }
  4784.         printf("\n");
  4785.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4786.     }
  4787. #endif /* CK_ENCRYPTION */
  4788. #ifdef IKS_OPTION
  4789.     printf(" kermit: ");
  4790.     switch (TELOPT_U_MODE(TELOPT_KERMIT)) {
  4791.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4792.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4793.       case TN_NG_RQ: printf( "u, requested; "); break;
  4794.       case TN_NG_MU: printf( "u, required;  "); break;
  4795.     }
  4796.     switch (TELOPT_ME_MODE(TELOPT_KERMIT)) {
  4797.       case TN_NG_AC: printf( "me, accepted;  " ); break;
  4798.       case TN_NG_RF: printf( "me, refused;   " ); break;
  4799.       case TN_NG_RQ: printf( "me, requested; "); break;
  4800.       case TN_NG_MU: printf( "me, required;  "); break;
  4801.     }
  4802.     if (TELOPT_U(TELOPT_KERMIT))
  4803.       printf(" u, %s",
  4804.              TELOPT_SB(TELOPT_KERMIT).kermit.u_start ?
  4805.              "started" :
  4806.              "stopped"
  4807.              );
  4808.     else
  4809.       printf(" u, n/a");
  4810.     if (TELOPT_ME(TELOPT_KERMIT))
  4811.       printf(" me, %s;",
  4812.              TELOPT_SB(TELOPT_KERMIT).kermit.me_start ?
  4813.              "started" :
  4814.              "stopped"
  4815.              );
  4816.     else
  4817.       printf(" me, n/a;");
  4818.     printf("\n");
  4819.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4820. #endif /* IKS_OPTION */
  4821.     printf(" BINARY newline-mode: ");
  4822.     switch (tn_b_nlm) {
  4823.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4824.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4825.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4826.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4827.     }
  4828.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4829.     printf(" binary-mode: ");
  4830.     switch (TELOPT_U_MODE(TELOPT_BINARY)) {
  4831.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4832.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4833.       case TN_NG_RQ: printf( "u, requested; "); break;
  4834.       case TN_NG_MU: printf( "u, required;  "); break;
  4835.     }
  4836.     switch (TELOPT_ME_MODE(TELOPT_BINARY)) {
  4837.       case TN_NG_AC: printf( "me, accepted; " ); break ;
  4838.       case TN_NG_RF: printf( "me, refused; " ); break;
  4839.       case TN_NG_RQ: printf( "me, requested; "); break;
  4840.       case TN_NG_MU: printf( "me, required;  "); break;
  4841.     }
  4842.     printf("u, %s; me, %s\n",
  4843.            TELOPT_U(TELOPT_BINARY) ? "BINARY" : "NVT",
  4844.            TELOPT_ME(TELOPT_BINARY) ? "BINARY" : "NVT"
  4845.            );
  4846.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4847.     printf(" binary-transfer-mode: %s\n",showoff(tn_b_xfer));
  4848.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4849.     printf(" bug binary-me-means-u-too: %s\n",showoff(tn_b_meu));
  4850.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4851.     printf(" bug binary-u-means-me-too: %s\n",showoff(tn_b_ume));
  4852.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4853.     printf(" bug sb-implies-will-do: %s\n",showoff(tn_sb_bug));
  4854.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4855.     printf(" terminal-type: ");
  4856.     if (tn_term) {
  4857.         printf("%s\n",tn_term);
  4858.     } else {
  4859.         char *p;
  4860. #ifdef OS2
  4861.         p = (tt_type >= 0 && tt_type <= max_tt) ?
  4862.           tt_info[tt_type].x_name :
  4863.             "UNKNOWN";
  4864. #else
  4865.         p = getenv("TERM");
  4866. #endif /* OS2 */
  4867.         if (p)
  4868.           printf("none (%s will be used)\n",p);
  4869.         else printf("none\n");
  4870.     }
  4871.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4872. #ifdef CK_ENVIRONMENT
  4873.     printf(" environment: %s\n", showoff(tn_env_flg));
  4874.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4875.     printf("   ACCOUNT: %s\n",tn_env_acct);
  4876.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4877.     printf("   DISPLAY: %s\n",(char *)tn_get_display() ?
  4878.             (char *)tn_get_display() : "");
  4879.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4880.     printf("   JOB    : %s\n",tn_env_job);
  4881.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4882.     printf("   PRINTER: %s\n",tn_env_prnt);
  4883.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4884. #ifndef NOSPL
  4885.     printf("   USER   : %s\n",uidbuf);
  4886.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4887. #endif /* NOSPL */
  4888.     printf("   SYSTEM : %s\n",tn_env_sys);
  4889.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4890.     for (x = 0; x < 8; x++) {
  4891.         if (tn_env_uservar[x][0] && tn_env_uservar[x][1]) {
  4892.             printf("   %-7s: %s\n",tn_env_uservar[x][0],
  4893.                    tn_env_uservar[x][1]);
  4894.             if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4895.         }
  4896.     }
  4897. #endif /* CK_ENVIRONMENT */
  4898. #ifdef CK_SNDLOC
  4899.     printf("  LOCATION: %s\n", tn_loc ? tn_loc : "");
  4900.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4901. #endif /* CK_SNDLOC */
  4902. #ifdef CK_FORWARD_X
  4903.     printf(" .Xauthority-file: %s\n", (char *)XauFileName() ?
  4904.             (char *)XauFileName() : "(none)");
  4905.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4906. #endif /* CK_FORWARD_X */
  4907.     return(n);
  4908. }
  4909. #endif /* TNCODE */
  4910.  
  4911. #ifdef CK_NETBIOS
  4912. static int
  4913. shonb(n) int n; {
  4914.     printf("NETBIOS parameters:\n");
  4915.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4916.     printf(" API       : %s\n",
  4917.            NetbeuiAPI ?
  4918.            "NETAPI.DLL - IBM Extended Services or Novell Netware Requester"
  4919.            : "ACSNETB.DLL - IBM Network Transport Services/2" ) ;
  4920.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4921.     printf(" Local Name: [%s]\n", NetBiosName);
  4922.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4923.     printf(" Adapter   : %d\n", NetBiosAdapter);
  4924.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4925.     if (NetBiosLSN > 0xFF) {
  4926.         printf(" Session   : %d\n", NetBiosLSN);
  4927.     } else {
  4928.         printf(" Session   : none active\n");
  4929.     }
  4930.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4931.     return(n);
  4932. }
  4933. #endif /* CK_NETBIOS */
  4934.  
  4935. #ifndef NONET
  4936. int
  4937. shonet() {
  4938.  
  4939. #ifndef NETCONN
  4940.     printf("\nNo networks are supported in this version of C-Kermit\n");
  4941.  
  4942. #else
  4943. #ifdef NOLOCAL
  4944.     printf("\nNo networks are supported in this version of C-Kermit\n");
  4945.  
  4946. #else /* rest of this routine */
  4947.  
  4948.     int i, n = 4;
  4949.  
  4950. #ifndef NODIAL
  4951.     if (nnetdir <= 1) {
  4952.         printf("\nNetwork directory: %s\n",netdir[0] ? netdir[0] : "(none)");
  4953.         n++;
  4954.     } else {
  4955.         int i;
  4956.         printf("\nNetwork directories:\n");
  4957.         for (i = 0; i < nnetdir; i++) {
  4958.             printf("%2d. %s\n",i,netdir[i]);
  4959.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4960.         }
  4961.     }
  4962. #endif /* NODIAL */
  4963.  
  4964. #ifdef SSHCMD
  4965.     {
  4966.         extern char * sshcmd;
  4967.         printf("SSH COMMAND: %s\n",sshcmd ? sshcmd : "ssh -e none");
  4968.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4969.     }
  4970. #endif /* SSHCMD */
  4971.  
  4972. #ifdef OS2
  4973.     printf("\nNetwork availability:\n");
  4974. #else
  4975.     printf("\nSupported networks:\n");
  4976. #endif /* OS2 */
  4977.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4978.  
  4979. #ifdef VMS
  4980.  
  4981. #ifdef TCPWARE
  4982.     printf(" Process Software Corporation TCPware for OpenVMS");
  4983. #else
  4984. #ifdef MULTINET
  4985.     printf(" TGV MultiNet TCP/IP");
  4986. #else
  4987. #ifdef WINTCP
  4988.     printf(" WOLLONGONG WIN/TCP");
  4989. #else
  4990. #ifdef DEC_TCPIP
  4991.     {
  4992.         static $DESCRIPTOR(tcp_desc,"_TCP0:");
  4993.         int status;
  4994.         long devclass;
  4995.         static int itmcod = DVI$_DEVCLASS;
  4996.  
  4997. #ifdef COMMENT
  4998.         status = LIB$GETDVI(&itmcod, 0, &tcp_desc, &devclass);
  4999. #else
  5000.         /* Martin Zinser 9/96 */
  5001.         status = lib$getdvi(&itmcod, 0, &tcp_desc, &devclass);
  5002. #endif /* COMMENT */
  5003.         if ((status & 1) && (devclass == DC$_SCOM))
  5004.           printf(" Process Software Corporation TCPware for OpenVMS");
  5005.         else
  5006. #ifdef UCX50
  5007.           printf(" DEC TCP/IP Services for (Open)VMS 5.0");
  5008. #else
  5009.           printf(" DEC TCP/IP Services for (Open)VMS");
  5010. #endif /* UCX50 */
  5011.     }
  5012. #else
  5013. #ifdef CMU_TCPIP
  5014.     printf(" CMU-OpenVMS/IP");
  5015. #else
  5016.     printf(" None");
  5017. #endif /* CMU_TCPIP */
  5018. #endif /* DEC_TCPIP */
  5019. #endif /* WINTCP */
  5020. #endif /* MULTINET */
  5021. #endif /* TCPWARE */
  5022.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5023. #ifdef TNCODE
  5024.     printf(", TELNET protocol\n\n");
  5025.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5026.     n = shotel(n);
  5027.     if (n < 0) return(0);
  5028.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5029. #endif /* TNCODE */
  5030.     printf("\n");
  5031.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5032.     printf("\n");
  5033.     n = shotcp(++n);
  5034.     if (n < 0) return(0);
  5035. #else /* Not VMS */
  5036.  
  5037. #ifdef SUNX25
  5038.     printf(" SunLink X.25\n");
  5039.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5040. #endif /* SUNX25 */
  5041.  
  5042. #ifdef STRATUSX25
  5043.     printf(" Stratus VOS X.25\n");
  5044.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5045. #endif /* STRATUSX25 */
  5046.  
  5047. #ifdef IBMX25
  5048.     printf(" IBM AIX X.25\n");
  5049.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5050. #endif /* IBMX25 */
  5051.  
  5052. #ifdef HPX25
  5053.     printf(" HP-UX X.25\n");
  5054.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5055. #endif /* HPX25 */
  5056.  
  5057. #ifdef SSHBUILTIN
  5058.     if (ck_ssleay_is_installed())
  5059.         printf(" SSH V1 and V2 protocols\n");
  5060.     else
  5061.         printf(" SSH V1 and V2 protocols - not available\n");
  5062. #endif /* SSHBUILTIN */
  5063.  
  5064. #ifdef DECNET
  5065. #ifdef OS2
  5066. #ifdef NT
  5067.     if (dnet_avail)
  5068.       printf(" DECnet, LAT and CTERM protocols\n");
  5069.     else
  5070.       printf(" DECnet, LAT and CTERM protocols - not available\n");
  5071.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5072. #else /* NT */
  5073.     if (dnet_avail)
  5074.       printf(" DECnet, LAT protocol\n");
  5075.     else
  5076.       printf(" DECnet, LAT protocol - not available\n");
  5077.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5078. #endif /* NT */
  5079. #else
  5080.     printf(" DECnet\n");
  5081.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5082. #endif /* OS2 */
  5083. #endif /* DECNET */
  5084.  
  5085. #ifdef NPIPE
  5086.     printf(" Named Pipes\n");
  5087.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5088. #endif /* NPIPE */
  5089.  
  5090. #ifdef CK_NETBIOS
  5091.     if (netbiosAvail)
  5092.       printf(" NETBIOS\n");
  5093.     else
  5094.       printf(" NETBIOS - not available\n");
  5095.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5096. #endif /* CK_NETBIOS */
  5097.  
  5098. #ifdef SUPERLAT
  5099.     if (slat_avail)
  5100.       printf(" SuperLAT\n");
  5101.     else
  5102.       printf(" SuperLAT - not available\n") ;
  5103.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5104. #endif /* SUPERLAT */
  5105.  
  5106. #ifdef TCPSOCKET
  5107.     if (
  5108. #ifdef OS2
  5109.         tcp_avail
  5110. #else
  5111.         1
  5112. #endif /* OS2 */
  5113.         ) {
  5114.         char ipaddr[16];
  5115.  
  5116.         if (getlocalipaddrs(ipaddr,16,0) < 0) {
  5117. #ifdef OS2ONLY
  5118.             printf(" TCP/IP via %s\n", tcpname);
  5119. #else
  5120.             printf(" TCP/IP\n");
  5121. #endif /* OS2ONLY */
  5122.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5123.         } else {
  5124.             int i = 1;
  5125. #ifdef OS2ONLY
  5126.           printf(" TCP/IP [%16s] via %s\n", ipaddr, tcpname);
  5127. #else
  5128.           printf(" TCP/IP [%16s]\n",ipaddr);
  5129. #endif /* OS2ONLY */
  5130.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5131.  
  5132.             while (getlocalipaddrs(ipaddr,16,i++) >= 0) {
  5133.                 printf("        [%16s]\n",ipaddr);
  5134.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5135.             }
  5136.         }
  5137.         if (nettype == NET_TCPB) {
  5138.             printf("\n");
  5139.             n = shotcp(++n);
  5140.             if (n < 0) return(0);
  5141. #ifdef TNCODE
  5142.             printf("\n");
  5143.             n = shotel(++n);
  5144.             if (n < 0) return(0);
  5145. #endif /* TNCODE */
  5146.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5147.         }
  5148. #ifdef OS2
  5149.     } else {
  5150.         printf(" TCP/IP - not available%s\n",tcpname[0] ? tcpname : "" );
  5151.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5152. #endif /* OS2 */
  5153.     }
  5154. #endif /* TCPSOCKET */
  5155.  
  5156. #ifdef CK_NETBIOS
  5157.     if (netbiosAvail && nettype == NET_BIOS) {
  5158.        printf("\n") ;
  5159.        if ((n = shonb(++n)) < 0) return(0);
  5160.        if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5161.     }
  5162. #endif /* CK_NETBIOS */
  5163.  
  5164. #endif /* VMS */
  5165.  
  5166.     printf("\nActive network connection:\n");
  5167.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5168.  
  5169.     if (network) {
  5170.         printf(" Host: %s",ttname);
  5171.         if ((nettype == NET_TCPA || nettype == NET_TCPB) && *ipaddr)
  5172.           printf(" [%s]",ipaddr);
  5173.     } else
  5174.       printf(" Host: none");
  5175.     printf(", via: ");
  5176.     if (nettype == NET_TCPA || nettype == NET_TCPB)
  5177.       printf("tcp/ip\n");
  5178.     else if (nettype == NET_SX25)
  5179.       printf("SunLink X.25\n");
  5180.     else if (nettype == NET_VX25)
  5181.       printf("Stratus VOS X.25\n");
  5182.     else if (nettype == NET_IX25)
  5183.       printf("IBM AIX X.25\n");
  5184.     else if (nettype == NET_HX25)
  5185.       printf("HP-UX X.25\n");
  5186.     else if (nettype == NET_DEC) {
  5187.         if ( ttnproto == NP_LAT )
  5188.           printf("DECnet LAT\n");
  5189.         else if ( ttnproto == NP_CTERM )
  5190.           printf("DECnet CTERM\n");
  5191.         else
  5192.           printf("DECnet\n");
  5193.     } else if (nettype == NET_PIPE)
  5194.       printf("Named Pipes\n");
  5195.     else if (nettype == NET_BIOS)
  5196.       printf("NetBIOS\n");
  5197.     else if (nettype == NET_SLAT)
  5198.       printf("SuperLAT\n");
  5199.  
  5200. #ifdef NETFILE
  5201.     else if ( nettype == NET_FILE )
  5202.       printf("local file\n");
  5203. #endif /* NETFILE */
  5204. #ifdef NETCMD
  5205.     else if ( nettype == NET_CMD )
  5206.       printf("pipe\n");
  5207. #endif /* NETCMD */
  5208. #ifdef NETPTY
  5209.     else if ( nettype == NET_PTY )
  5210.         printf("pseudoterminal\n");
  5211. #endif /* NETPTY */
  5212. #ifdef NETDLL
  5213.     else if ( nettype == NET_DLL )
  5214.       printf("dynamic link library\n");
  5215. #endif /* NETDLL */
  5216.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5217.  
  5218. #ifdef ANYX25
  5219.     if ((nettype == NET_SX25) ||
  5220.         (nettype == NET_VX25) ||
  5221.         (nettype == NET_IX25))
  5222.       if ((n = shox25(n)) < 0) return(0);
  5223. #endif /* ANYX25 */
  5224.  
  5225. #ifdef SSHBUILTIN
  5226.     if (nettype == NET_SSH) {
  5227.         printf("Secure Shell protocol\n");
  5228.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5229.     }
  5230. #endif /* SSHBUILTIN */
  5231.  
  5232.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  5233. #ifdef RLOGCODE
  5234.         if (ttnproto == NP_RLOGIN) {
  5235.             printf(" LOGIN (rlogin) protocol\n");
  5236.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5237.         }
  5238. #ifdef CK_KERBEROS
  5239.         else if (ttnproto == NP_K4LOGIN) {
  5240.             printf(" Kerberos 4 LOGIN (klogin) protocol\n");
  5241.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5242.         }
  5243.         else if (ttnproto == NP_EK4LOGIN) {
  5244.             printf(" Encrypted Kerberos 4 LOGIN (eklogin) protocol\n");
  5245.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5246.         }
  5247.         else if (ttnproto == NP_K5LOGIN) {
  5248.             printf(" Kerberos 5 LOGIN (klogin) protocol\n");
  5249.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5250.         }
  5251.         else if (ttnproto == NP_EK5LOGIN) {
  5252.             printf(" Encrypted Kerberos 5 LOGIN (eklogin) protocol\n");
  5253.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5254.         }
  5255. #endif /* CK_KERBEROS */
  5256. #endif /* RLOGCODE */
  5257. #ifdef CK_KERBEROS
  5258.         if (ttnproto == NP_K5U2U) {
  5259.             printf(" Kerberos 5 User to User protocol\n");
  5260.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5261.         }
  5262. #endif /* CK_KERBEROS */
  5263.  
  5264. #ifdef TNCODE
  5265.         if (IS_TELNET()) {
  5266.             printf(" TELNET protocol\n");
  5267.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5268.             printf(" Echoing is currently %s\n",duplex ? "local" : "remote");
  5269.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5270.         }
  5271. #endif /* TNCODE */
  5272.         if (ttnproto == NP_TCPRAW) {
  5273.             printf(" Raw TCP socket\n");
  5274.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5275.         }
  5276.     }
  5277.     printf("\n");
  5278. #endif /* NOLOCAL */
  5279. #endif /* NETCONN */
  5280.     return(0);
  5281. }
  5282. #endif /* NONET */
  5283.  
  5284. #ifndef NODIAL
  5285. VOID
  5286. shodial() {
  5287.     if (mdmtyp >= 0 || local != 0) doshodial();
  5288. }
  5289.  
  5290. VOID
  5291. shods(s) char *s; {                     /* Show a dial-related string */
  5292.     char c;
  5293.     if (s == NULL || !(*s)) {           /* Empty? */
  5294.         printf("(none)\n");
  5295.     } else {                            /* Not empty. */
  5296.         while ((c = *s++))              /* Can contain controls */
  5297.           if (c == '\\')                /* a backslash */
  5298.             printf("\\\\");
  5299.           else if (c > 31 && c < 127) {
  5300.               putchar(c);
  5301.           } else
  5302.             printf("\\{%d}",c);
  5303.         printf("\n");
  5304.     }
  5305. }
  5306.  
  5307. int
  5308. doshodial() {
  5309.  
  5310.     int i, n = 2;
  5311.  
  5312.     printf(" Dial status:  %d", dialsta);
  5313.  
  5314. #ifdef BIGBUFOK
  5315.     if (dialsta > 90)
  5316.       printf(" = Unknown error");
  5317.     else if (dialsta < 0)
  5318.       printf(" = (none)");
  5319.     else if (dialsta < 35 && dialmsg[dialsta])
  5320.       printf(" = %s", dialmsg[dialsta]);
  5321. #endif /* BIGBUFOK */
  5322.     n++;
  5323.     if (ndialdir <= 1) {
  5324.         printf("\n Dial directory: %s\n",dialdir[0] ? dialdir[0] : "(none)");
  5325.     } else {
  5326.         int i;
  5327.         printf("\n Dial directories:\n");
  5328.         for (i = 0; i < ndialdir; i++)
  5329.           printf("%2d. %s\n",i+1,dialdir[i]);
  5330.         n += ndialdir;
  5331.     }
  5332.     printf(" Dial method:  ");
  5333.     if      (dialmauto)         printf("auto   ");
  5334.     else if (dialmth == XYDM_D) printf("default");
  5335.     else if (dialmth == XYDM_P) printf("pulse  ");
  5336.     else if (dialmth == XYDM_T) printf("tone   ");
  5337.     printf("         Dial sort: %s\n",dialsrt ? "on" : "off");
  5338.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5339.     printf(" Dial hangup:  %s             Dial display: %s\n",
  5340.            dialhng ? "on " : "off", dialdpy ? "on" : "off");
  5341.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5342.     if (dialrtr > 0) {
  5343.         printf(" Dial retries: %-6d          Dial interval: %d\n",
  5344.                dialrtr, dialint);
  5345.     } else {
  5346.         printf(" Dial retries: (auto)          Dial interval: %d\n", dialint);
  5347.     }
  5348.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5349.     printf(" Dial timeout: ");
  5350. #ifdef CK_TAPI
  5351.     if (tttapi && !tapipass)
  5352.         printf("(tapi)");
  5353.     else
  5354. #endif /* CK_TAPI */
  5355.     if (dialtmo > 0)
  5356.       printf("%4d sec", dialtmo);
  5357.     else
  5358.       printf("0 (auto)");
  5359.     printf("        Redial number: %s\n",dialnum ? dialnum : "(none)");
  5360.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5361.     printf(" Dial confirmation: %s        Dial convert-directory: %s\n",
  5362.            dialcnf ? "on " : "off",
  5363.            dialcvt ? ((dialcvt == 1) ? "on" : "ask") : "off");
  5364.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5365.     printf(" Dial ignore-dialtone: %s", dialidt ? "on " : "off");
  5366.     printf("     Dial pacing: %d\n",dialpace);
  5367.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5368.     printf(
  5369. " Dial prefix:                  %s\n", dialnpr ? dialnpr : "(none)");
  5370.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5371.     printf(
  5372. " Dial suffix:                  %s\n", dialsfx ? dialsfx : "(none)");
  5373.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5374.     printf(
  5375. " Dial country-code:            %-12s", diallcc ? diallcc : "(none)");
  5376.     printf("Dial connect:  %s", dialcon ? ((dialcon == 1) ? "on" : "auto")
  5377.            : "off");
  5378.     if (dialcon != CAR_OFF)
  5379.       printf(" %s", dialcq ? "quiet" : "verbose");
  5380.     printf(
  5381. "\n Dial area-code:               %-12s", diallac ? diallac : "(none)");
  5382.     n++;
  5383.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5384.     printf("Dial restrict: ");
  5385.     if (dialrstr == 5) printf("international\n");
  5386.     else if (dialrstr == 4) printf("long-distance\n");
  5387.     else if (dialrstr == 2) printf("local\n");
  5388.     else if (dialrstr == 6) printf("none\n");
  5389.     else printf("?\n");
  5390.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5391.     printf(" Dial lc-area-codes:           ");
  5392.     if (nlocalac == 0)
  5393.       printf("(none)");
  5394.     else
  5395.       for (i = 0; i < nlocalac; i++)
  5396.         printf("%s ", diallcac[i]);
  5397.     printf(
  5398. "\n Dial lc-prefix:               %s\n", diallcp ? diallcp : "(none)");
  5399.     n++;
  5400.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5401.     printf(
  5402. " Dial lc-suffix:               %s\n", diallcs ? diallcs : "(none)");
  5403.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5404.     printf(
  5405. " Dial ld-prefix:               %s\n", dialldp ? dialldp : "(none)");
  5406.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5407.     printf(
  5408. " Dial ld-suffix:               %s\n", diallds ? diallds : "(none)");
  5409.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5410.     printf(
  5411. " Dial force-long-distance      %s\n", showoff(dialfld));
  5412.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5413.     printf(
  5414. " Dial intl-prefix:             %s\n", dialixp ? dialixp : "(none)");
  5415.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5416.     printf(
  5417. " Dial intl-suffix:             %s\n", dialixs ? dialixs : "(none)");
  5418.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5419.     printf(
  5420. " Dial toll-free-area-code:     ");
  5421.     if (ntollfree == 0)
  5422.       printf("(none)");
  5423.     else
  5424.       for (i = 0; i < ntollfree; i++)
  5425.         printf("%s ", dialtfc[i]);
  5426.     printf("\n");
  5427.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5428.  
  5429.     printf(
  5430. " Dial pulse-countries:         ");
  5431.     if (ndialpucc == 0)
  5432.       printf("(none)");
  5433.     else
  5434.       for (i = 0; i < ndialpucc; i++)
  5435.         printf("%s ", dialpucc[i]);
  5436.     printf("\n");
  5437.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5438.  
  5439.     printf(
  5440. " Dial tone-countries:          ");
  5441.     if (ndialtocc == 0)
  5442.       printf("(none)");
  5443.     else
  5444.       for (i = 0; i < ndialtocc; i++)
  5445.         printf("%s ", dialtocc[i]);
  5446.     printf("\n");
  5447.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5448.  
  5449.     printf(
  5450. " Dial toll-free-prefix:        %s\n",
  5451.            dialtfp ? dialtfp :
  5452.           (dialldp ? dialldp : "(none)")
  5453.           );
  5454.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5455.     printf(
  5456. #ifdef COMMENT
  5457. " Dial pbx-exchange:            %s\n", dialpxx ? dialpxx : "(none)");
  5458. #else
  5459. " Dial pbx-exchange:            ");
  5460.     if (ndialpxx == 0)
  5461.       printf("(none)");
  5462.     else
  5463.       for (i = 0; i < ndialpxx; i++)
  5464.         printf("%s ", dialpxx[i]);
  5465.     printf("\n");
  5466. #endif /* COMMENT */
  5467.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5468.     printf(
  5469. " Dial pbx-inside-prefix:       %s\n", dialpxi ? dialpxi : "(none)");
  5470.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5471.     printf(
  5472. " Dial pbx-outside-prefix:      %s\n", dialpxo ? dialpxo : "(none)");
  5473.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5474.     printf(
  5475. " Dial macro:                   %s\n", dialmac ? dialmac : "(none)");
  5476.     return(0);
  5477. }
  5478. #endif /* NODIAL */
  5479. #endif /* NOLOCAL */
  5480.  
  5481. /*  Show File Parameters */
  5482.  
  5483. static char *
  5484. pathval(x) int x; {
  5485.     switch (x) {
  5486.       case PATH_OFF:  return("off");
  5487.       case PATH_ABS:  return("absolute");
  5488.       case PATH_REL:  return("relative");
  5489.       case PATH_AUTO: return("auto");
  5490.       default: return("unknown");
  5491.     }
  5492. }
  5493.  
  5494. VOID
  5495. shofil() {
  5496.     char *s; int i = 0, n = 1;
  5497.     extern char * ifdnam[];
  5498. #ifdef UNIX
  5499.     extern int wildxpand;
  5500. #endif /* UNIX */
  5501.     extern char * snd_move, * snd_rename, * rcv_move, * rcv_rename;
  5502. #ifdef PATTERNS
  5503.     extern int patterns;
  5504. #endif /* PATTERNS */
  5505.     extern char * rfspec, * sfspec;
  5506. #ifdef UNIX
  5507.     extern int zobufsize, zofbuffer, zofblock;
  5508. #endif /* UNIX */
  5509. #ifdef CK_CTRLZ
  5510.     extern int eofmethod;
  5511. #endif /* CK_CTRLZ */
  5512.  
  5513.     printf("\n");
  5514.  
  5515. #ifdef VMS
  5516.     printf(" File record-Length:      %5d\n",frecl);
  5517.     n++;
  5518. #endif /* VMS */
  5519.  
  5520. #ifndef NOXFER
  5521.     printf(" Transfer mode:           %s\n",
  5522.            xfermode == XMODE_A ?
  5523.            "automatic" :
  5524.            "manual"
  5525.            );
  5526.     n++;
  5527. #ifdef PATTERNS
  5528.     printf(" File patterns:           %s", showooa(patterns));
  5529.     if (xfermode == XMODE_M && patterns)
  5530.       printf(" (but disabled by TRANSFER-MODE MANUAL)");
  5531.     else if (patterns)
  5532.       printf(" (SHOW PATTERNS for list)");
  5533.     printf("\n");
  5534.     n++;
  5535. #endif /* PATTERNS */
  5536.     if (filepeek)
  5537.       printf(" File scan:               on %d\n", nscanfile);
  5538.     else
  5539.       printf(" File scan:               off\n");
  5540.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5541.     if (xfermode == XMODE_A)
  5542.       printf(" Default file type:       %s\n",shoxm());
  5543.     else
  5544.       printf(" File type:               %s\n",shoxm());
  5545.     n++;
  5546.     if (fncnv == XYFN_L)
  5547.       s = "literal";
  5548.     else if (fncnv == XYFN_C)
  5549.       s = "converted";
  5550.     else
  5551.       s = "(unknown)";
  5552.     printf(" File names:              %s\n",s);
  5553.     n++;
  5554.     printf(" Send pathnames:          %s\n", pathval(fnspath));
  5555.     n++;
  5556.     printf(" Receive pathnames:       %s\n", pathval(fnrpath));
  5557.     n++;
  5558. #ifdef UNIXOROSK
  5559.     printf(" Match dot files:         %s\n", matchdot ? "yes" : "no");
  5560.     n++;
  5561. #ifdef UNIX
  5562.     printf(" Wildcard-expansion:      %s\n", wildxpand ? "shell" : "kermit");
  5563.     n++;
  5564. #endif /* UNIX */
  5565. #endif /* UNIXOROSK */
  5566.     printf(" File collision:          ");
  5567.     for (i = 0; i < ncolx; i++)
  5568.       if (colxtab[i].kwval == fncact) break;
  5569.     printf("%s\n", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5570.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5571.     printf(" File destination:        %s\n",
  5572.            (dest == DEST_D) ? "disk" :
  5573.            ((dest == DEST_S) ? "screen" :
  5574.             ((dest == DEST_N) ? "nowhere" :
  5575.             "printer"))
  5576.            );
  5577.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5578.     s = (keep >= 0 && keep <= 2) ? ifdnam[keep] : "keep";
  5579.     printf(" File incomplete:         %s\n",s);
  5580.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5581.     printf(" File bytesize:           %d\n",(fmask == 0177) ? 7 : 8);
  5582.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5583. #ifndef NOCSETS
  5584.     printf(" File character-set:      %s\n",fcsinfo[fcharset].keyword);
  5585.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5586.     printf(" File default 7-bit:      %s\n",fcsinfo[dcset7].keyword);
  5587.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5588.     printf(" File default 8-bit:      %s\n",fcsinfo[dcset8].keyword);
  5589.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5590. #ifdef UNICODE
  5591.     printf(" File UCS bom:            %s\n",showoff(ucsbom));
  5592.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5593.     printf(" File UCS byte-order:     %s-endian\n",
  5594.            ucsorder ? "little" : "big");
  5595.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5596.     printf(" Computer byteorder:      %s-endian\n",
  5597.            byteorder ? "little" : "big");
  5598.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5599. #endif /* UNICODE */
  5600. #endif /* NOCSETS */
  5601.  
  5602.     printf(" File end-of-line:        ");
  5603.     i = feol;
  5604.     switch (feol) {
  5605.       case XYFA_C: printf("%s\n","cr"); break;
  5606.       case XYFA_L: printf("%s\n","lf"); break;
  5607.       case XYFA_2: printf("%s\n","crlf"); break;
  5608.       default: printf("%d\n",i);
  5609.     }
  5610.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5611. #endif /* NOXFER */
  5612.  
  5613. #ifdef CK_CTRLZ
  5614.     printf(" File eof:                %s\n", eofmethod ? "ctrl-z" : "length");
  5615.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5616. #endif /* CK_CTRLZ */
  5617. #ifndef NOXFER
  5618. #ifdef CK_TMPDIR
  5619.     printf(" File download-directory: %s\n", dldir ? dldir : "(none)");
  5620.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5621. #ifdef COMMENT
  5622.     i = 256;
  5623.     s = line;
  5624.     zzstring("\\v(tmpdir)",&s,&i);
  5625.     printf(" Temporary directory:     %s\n", line);
  5626.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5627. #endif /* COMMENT */
  5628. #endif /* CK_TMPDIR */
  5629. #ifdef VMS
  5630.     {
  5631.         extern int vmssversions, vmsrversions;
  5632.         printf(" Send version-numbers:    %s\n",showoff(vmssversions));
  5633.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5634.         printf(" Receive version-numbers: %s\n",showoff(vmsrversions));
  5635.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5636.     }
  5637. #endif /* VMS */
  5638.     printf(" Send move-to:            %s\n",
  5639.            snd_move ? snd_move : "(none)");
  5640.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5641.     printf(" Send rename-to:          %s\n",
  5642.            snd_rename ? snd_rename : "(none)");
  5643.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5644.     printf(" Receive move-to:         %s\n",
  5645.            rcv_move ? rcv_move : "(none)");
  5646.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5647.     printf(" Receive rename-to:       %s\n",
  5648.            rcv_rename ? rcv_rename : "(none)");
  5649.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5650. #endif /* NOXFER */
  5651. #ifdef KERMRC
  5652.     printf(" Initialization file:     %s\n", noinit ? "(none)" :
  5653. #ifdef CK_SYSINI
  5654.            CK_SYSINI
  5655. #else
  5656.            kermrc
  5657. #endif /* CK_SYSINI */
  5658.            );
  5659. #endif /* KERMRC */
  5660.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5661.  
  5662.     if (k_info_dir) {
  5663.         printf(" Kermit doc files:        %s\n", k_info_dir);
  5664.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5665.     }
  5666.  
  5667. #ifdef CKROOT
  5668.     s = zgetroot();
  5669.     printf(" Root set:                %s\n", s ? s : "(none)");
  5670. #endif /* CKROOT */
  5671.  
  5672. #ifdef UNIX
  5673.     printf(" Disk output buffer:      %d (writes are %s, %s)\n",
  5674.            zobufsize,
  5675.            zofbuffer ? "buffered" : "unbuffered",
  5676.            zofblock ? "blocking" : "nonblocking"
  5677.            );
  5678.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5679. #ifdef DYNAMIC
  5680.     printf(" Stringspace:             %d\n", zsetfil(0,2));
  5681.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5682.     printf(" Listsize:                %d\n", zsetfil(0,4));
  5683.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5684. #endif /* DYNAMIC */
  5685. #endif /* UNIX */
  5686. #ifdef OS2ORUNIX
  5687.     printf(" Longest filename:        %d\n", maxnam);
  5688.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5689.     printf(" Longest pathname:        %d\n", maxpath);
  5690.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5691. #endif /* OS2ORUNIX */
  5692.  
  5693.     printf(" Last file sent:          %s\n", sfspec ? sfspec : "(none)");
  5694.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5695.     printf(" Last file received:      %s\n", rfspec ? rfspec : "(none)");
  5696.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5697.     printf("\n Also see:\n");
  5698.     n++;
  5699.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5700.     printf(" SHOW PROTOCOL, SHOW XFER");
  5701. #ifdef CK_LABELED
  5702.     printf(", SHOW LABELED");
  5703. #endif /* CK_LABELED */
  5704. #ifdef PATTERNS
  5705.     printf(", SHOW PATTERNS");
  5706. #endif /* PATTERNS */
  5707. #ifdef STREAMING
  5708.     printf(", SHOW STREAMING");
  5709. #endif /* STREAMING */
  5710. #ifndef NOCSETS
  5711.     printf(", SHOW CHARACTER-SETS");
  5712. #endif /* NOCSETS */
  5713.     printf("\n\n");
  5714. }
  5715.  
  5716. #ifndef NOXFER
  5717. VOID
  5718. shoparp() {                             /* Protocol */
  5719.     extern int docrc, skipbup;
  5720.     char *s;
  5721.  
  5722. #ifdef CK_TIMERS
  5723.     extern int rttflg;
  5724. #endif /* CK_TIMERS */
  5725.  
  5726.     printf("Protocol: %s\n",ptab[protocol].p_name);
  5727.  
  5728.     if (protocol == PROTO_K) {
  5729.         printf("\nProtocol Parameters:   Send    Receive");
  5730.         if (timef)
  5731.           printf("\n Timeout (used=%2d):%7d*%8d ", timint, rtimo, pkttim);
  5732.         else
  5733.           printf("\n Timeout (used=%2d):%7d%9d ",  timint, rtimo, pkttim);
  5734. #ifdef XFRCAN
  5735.         printf("       Cancellation:    %s",showoff(xfrcan));
  5736.         if (xfrcan)
  5737.           printf(" %d %d", xfrchr, xfrnum);
  5738. #endif /* XFRCAN */
  5739.         printf("\n Padding:      %11d%9d", npad,   mypadn);
  5740.         if (bctr == 4)
  5741.           printf("        Block Check: blank-free-2\n");
  5742.         else
  5743.           printf("        Block Check: %6d\n",bctr);
  5744.         printf(  " Pad Character:%11d%9d", padch,  mypadc);
  5745.         printf("        Delay:       %6d\n",ckdelay);
  5746.         printf(  " Pause:        %11d%9d", pktpaus, pktpaus);
  5747.         printf("        Attributes:      %s\n",showoff(atcapr));
  5748.         printf(  " Packet Start: %11d%9d", mystch, stchr);
  5749.         printf("        Max Retries: %6d%s\n",
  5750.                maxtry,
  5751.                (maxtry == 0) ? " (unlimited)" : ""
  5752.                );
  5753.         printf(  " Packet End:   %11d%9d", seol,   eol);
  5754.         if (ebqflg)
  5755.           printf("        8th-Bit Prefix: '%c'",ebq);
  5756.         else
  5757.           printf("        8th-Bit Prefix: ('%c' but not used)",ebq);
  5758.         printf(  "\n Packet Length:%11d ", spmax);
  5759.         printf("%8d     ",  urpsiz);
  5760.         if (rptflg)
  5761.           printf("   Repeat Prefix:  '%c'",rptq);
  5762.         else
  5763.           printf("   Repeat Prefix:  ('%c' but not used)",rptq);
  5764.         printf(  "\n Maximum Length: %9d%9d", maxsps, maxrps);
  5765.         printf("        Window Size:%7d set, %d used\n",wslotr,wmax);
  5766.         printf(    " Buffer Size:  %11d%9d", bigsbsiz, bigrbsiz);
  5767.         printf("        Locking-Shift:    ");
  5768.         if (lscapu == 2) {
  5769.             printf("forced");
  5770.         } else {
  5771.             printf("%s", (lscapr ? "enabled" : "disabled"));
  5772.             if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  5773.         }
  5774.         printf("\n\n");
  5775.  
  5776.         if (!(s = ptab[protocol].h_b_init)) s = "";
  5777.         printf(" Auto-upload command (binary): ");
  5778.         if (*s) {
  5779.             shostrdef((CHAR *)s);
  5780.             printf("\n");
  5781.         } else {
  5782.             printf("(none)\n");
  5783.         }
  5784.         if (!(s = ptab[protocol].h_t_init)) s = "";
  5785.         printf(" Auto-upload command (text):   ");
  5786.         if (*s) {
  5787.             shostrdef((CHAR *)s);
  5788.             printf("\n");
  5789.         } else {
  5790.             printf("(none)\n");
  5791.         }
  5792.         if (!(s = ptab[protocol].h_x_init)) s = "";
  5793.         printf(" Auto-server command:          ");
  5794.         if (*s) {
  5795.             shostrdef((CHAR *)s);
  5796.             printf("\n");
  5797.         } else {
  5798.             printf("(none)\n");
  5799.         }
  5800.         tmpbuf[0] = NUL;
  5801. #ifdef CK_TIMERS
  5802.         if (rttflg) {
  5803.             extern int mintime, maxtime;
  5804.             sprintf(tmpbuf," Packet timeouts: dynamic %d:%d", /* SAFE */
  5805.                     mintime,
  5806.                     maxtime);
  5807.         } else {
  5808.             sprintf(tmpbuf," Packet timeouts: fixed"); /* SAFE */
  5809.         }
  5810. #endif /* CK_TIMERS */
  5811.         if (tmpbuf[0])
  5812.           printf("%-31s",tmpbuf);
  5813.         printf("Send backup: %s\n",showoff(!skipbup));
  5814.  
  5815.         printf(" Transfer mode:   %s", xfermode == XMODE_A ?
  5816.                "automatic   " :
  5817.                "manual      "
  5818.                );
  5819.         printf(" Transfer slow-start: %s, crc: %s\n",
  5820.                showoff(slostart),
  5821.                showoff(docrc)
  5822.                );
  5823. #ifdef PIPESEND
  5824.         {
  5825.             extern int usepipes;
  5826.             printf(" Transfer pipes:  %s         ",usepipes ? "on " : "off");
  5827.         }
  5828. #endif /* PIPESEND */
  5829. #ifndef NOCSETS
  5830.         printf(" Transfer character-set: ");
  5831.         if (tcharset == TC_TRANSP)
  5832.           printf("transparent\n");
  5833.         else
  5834.           printf("%s\n", tcsinfo[tcharset].keyword );
  5835. #endif /* NOCSETS */
  5836. #ifdef PIPESEND
  5837.         {
  5838.             extern char * sndfilter, * rcvfilter;
  5839.             printf(" Send filter:     %s\n", sndfilter ? sndfilter : "(none)");
  5840.             printf(" Receive filter:  %s\n", rcvfilter ? rcvfilter : "(none)");
  5841.         }
  5842. #endif /* PIPESEND */
  5843.         printf("\nAlso see:\n");
  5844.         printf(" SHOW FILE, SHOW XFER");
  5845.  
  5846. #ifdef CK_LABELED
  5847.         printf(", SHOW LABELED");
  5848. #endif /* CK_LABELED */
  5849. #ifdef PATTERNS
  5850.         printf(", SHOW PATTERNS");
  5851. #endif /* PATTERNS */
  5852. #ifdef STREAMING
  5853.         printf(", SHOW STREAMING");
  5854. #endif /* STREAMING */
  5855. #ifndef NOCSETS
  5856.         printf(", SHOW CHARACTER-SETS");
  5857. #endif /* NOCSETS */
  5858.     }
  5859.  
  5860. #ifdef CK_XYZ
  5861. #ifdef XYZ_INTERNAL
  5862.     if (protocol != PROTO_K) {
  5863.         int i;
  5864.         int x;
  5865.         printf(" File type: %s\n", binary ? "binary" : "text");
  5866.         if (protocol == PROTO_Z) {              /* Zmodem */
  5867.             printf(" Window size:   ");
  5868.             if (ptab[protocol].winsize < 1)
  5869.               printf("none\n");
  5870.             else
  5871.               printf("%d\n",wslotr);
  5872. #ifdef COMMENT
  5873.             printf(" Packet (frame) length: ");
  5874.             if (ptab[protocol].spktlen < 0)
  5875.               printf("none\n");
  5876.             else
  5877.               printf("%d\n",spmax);
  5878. #endif /* COMMENT */
  5879.         } else {
  5880.             if (ptab[protocol].spktlen >= 1000)
  5881.               printf(" 1K packets\n");
  5882.             else
  5883.               printf(" 128-byte packets\n");
  5884.         }
  5885.         printf(" Pathname stripping when sending:   %s\n",
  5886.                showoff(ptab[protocol].fnsp)
  5887.                );
  5888.         printf(" Pathname stripping when receiving: %s\n",
  5889.                showoff(ptab[protocol].fnrp)
  5890.                );
  5891.         printf(" Filename collision action:         ");
  5892.         for (i = 0; i < ncolx; i++)
  5893.           if (colxtab[i].kwval == fncact) break;
  5894.         printf("%-12s", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5895.  
  5896.         printf("\n Escape control characters:          ");
  5897.         x = ptab[protocol].prefix;
  5898.         if (x == PX_ALL)
  5899.           printf("all\n");
  5900.         else if (x == PX_CAU || x==PX_WIL)
  5901.           printf("minimal\n");
  5902.         else
  5903.           printf("none\n");
  5904.         if (!(s = ptab[protocol].h_b_init))
  5905.           s = "";
  5906.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5907.         if (!(s = ptab[protocol].h_t_init))
  5908.           s = "";
  5909.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  5910.     }
  5911. #else
  5912.     if (protocol != PROTO_K) {
  5913.         printf("\nExecuted by external commands:\n\n");
  5914.         s = ptab[protocol].p_b_scmd;
  5915.         if (!s) s = "";
  5916.         printf(" SEND command (binary):        %s\n", *s ? s : "(none)");
  5917.         s = ptab[protocol].p_t_scmd;
  5918.         if (!s) s = "";
  5919.         printf(" SEND command (text):          %s\n", *s ? s : "(none)");
  5920.         s = ptab[protocol].p_b_rcmd;
  5921.         if (!s) s = "";
  5922.         printf(" RECEIVE command (binary):     %s\n", *s ? s : "(none)");
  5923.         s = ptab[protocol].p_t_rcmd;
  5924.         if (!s) s = "";
  5925.         printf(" RECEIVE command (text):       %s\n", *s ? s : "(none)");
  5926.         s = ptab[protocol].h_b_init;
  5927.         if (!s) s = "";
  5928.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5929.         s = ptab[protocol].h_t_init;
  5930.         if (!s) s = "";
  5931.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  5932.     }
  5933. #endif /* XYZ_INTERNAL */
  5934. #endif /* CK_XYZ */
  5935. }
  5936. #endif /* NOXFER */
  5937.  
  5938. #ifndef NOCSETS
  5939. /* Character-set items */
  5940.  
  5941. extern int s_cset, r_cset, axcset[], afcset[];
  5942. extern struct keytab xfrmtab[];
  5943.  
  5944. VOID
  5945. shoparl() {
  5946. #ifdef COMMENT
  5947.     int i;
  5948. /* Misleading... */
  5949.     printf("\nAvailable Languages:\n");
  5950.     for (i = 0; i < MAXLANG; i++) {
  5951.         printf(" %s\n",langs[i].description);
  5952.     }
  5953. #else
  5954.     printf("\nLanguage-specific translation rules: %s\n",
  5955.            language == L_USASCII ? "none" : langs[language].description);
  5956.     shocharset();
  5957.     printf("\n\n");
  5958. #endif /* COMMENT */
  5959. }
  5960.  
  5961. VOID
  5962. shocharset() {
  5963.     int x;
  5964. #ifdef COMMENT
  5965.     char * s = "Unknown";
  5966.     extern int xlatype;
  5967. #endif /* COMMENT */
  5968.  
  5969. #ifndef NOXFER
  5970.     extern int xfrxla;
  5971. #endif /* NOXFER */
  5972.  
  5973.     debug(F101,"SHOW FILE CHAR","",fcharset);
  5974.     printf("\n");
  5975. #ifndef NOXFER
  5976.     printf(" Transfer Translation: %s\n", showoff(xfrxla));
  5977.     if (!xfrxla) {
  5978.         printf(
  5979.       " Because transfer translation is off, the following are ignored:\n\n");
  5980.     }
  5981. #endif /* NOXFER */
  5982.     printf(" File Character-Set: %s (%s), ",
  5983.            fcsinfo[fcharset].keyword,
  5984.            fcsinfo[fcharset].name
  5985.            );
  5986.     if ((x = fcsinfo[fcharset].size) == 128)
  5987.       printf("7-bit");
  5988.     else if (x == 256)
  5989.       printf("8-bit");
  5990.     else
  5991.       printf("multibyte");
  5992.     printf("\n");
  5993.     printf(" File Scan: %s\n",showoff(filepeek));
  5994.     printf("   Default 7bit-Character-Set: %s\n",fcsinfo[dcset7].keyword);
  5995.     printf("   Default 8bit-Character-Set: %s\n",fcsinfo[dcset8].keyword);
  5996.     printf(" Transfer Character-Set");
  5997. #ifdef COMMENT
  5998.     if (tslevel == TS_L2)
  5999.       printf(": (international)");
  6000.     else
  6001. #endif /* COMMENT */
  6002.     if (tcharset == TC_TRANSP)
  6003.       printf(": Transparent");
  6004.     else
  6005.       printf(": %s (%s)",tcsinfo[tcharset].keyword, tcsinfo[tcharset].name);
  6006.     printf("\n");
  6007. #ifdef COMMENT
  6008.     switch (xlatype) {
  6009.       case XLA_NONE: s = "None"; break;
  6010.       case XLA_BYTE: s = "Byte"; break;
  6011.       case XLA_JAPAN: s = "Japanese"; break;
  6012.       case XLA_UNICODE: s = "Unicode"; break;
  6013.     }
  6014.     printf("\n Translation type: %s\n",s);
  6015. #endif /* COMMENT */
  6016.     printf(" SEND character-set-selection: %s\n",xfrmtab[s_cset].kwd);
  6017.     printf(" RECEIVE character-set-selection: %s\n",xfrmtab[r_cset].kwd);
  6018.     if (s_cset == XMODE_A || r_cset == XMODE_A)
  6019.       printf(
  6020.       " (Use SHOW ASSOCIATIONS to list automatic character-set selections.)\n"
  6021.              );
  6022. }
  6023.  
  6024. VOID
  6025. showassoc() {
  6026.     int i, k, n = 4;
  6027.     char * s;
  6028.     printf("\nFor incoming files:\n\n");
  6029.     printf("Transfer Character-Set   File Character-Set\n");
  6030.     for (i = 1; i <= MAXTCSETS; i++) {
  6031.         k = axcset[i];
  6032.         if (k < 0 || k > MAXFCSETS)
  6033.           s = "(none)";
  6034.         else
  6035.           s = fcsinfo[k].keyword;
  6036.         if (!s) s = "";
  6037.         if (!*s) s = "(none)";
  6038.         printf(" %-25s%s\n",tcsinfo[i].keyword,s);
  6039.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6040.     }
  6041.     printf("\nFor outbound files:\n\n");
  6042.     n += 2;
  6043.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6044.     printf("File Character-Set       Transfer Character-Set\n");
  6045.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6046.     for (i = 0; i <= MAXFCSETS; i++) {
  6047.         k = afcset[i];
  6048.         if (k < 0 || k > MAXTCSETS)
  6049.           s = "(none)";
  6050.         else
  6051.           s = tcsinfo[k].keyword;
  6052.         if (!s) s = "";
  6053.         if (!*s) s = "(none)";
  6054.         printf(" %-25s%s\n",fcsinfo[i].keyword,s);
  6055.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6056.     }
  6057. }
  6058. #endif /* NOCSETS */
  6059.  
  6060. VOID
  6061. shopar() {
  6062.     printf("Show what?  (Type \"show ?\" for a list of possiblities.)\n");
  6063. }
  6064. #endif /* NOSHOW */
  6065.  
  6066. #ifndef NOXFER
  6067. /*  D O S T A T  --  Display file transfer statistics.  */
  6068.  
  6069. int
  6070. dostat(brief) int brief; {
  6071.     extern long filrej, peakcps;
  6072.     extern int lastspmax, streamed, cleared, streamok;
  6073.     extern char whoareu[];
  6074.     int n = 0, ftp = 0;
  6075.     extern int docrc, interrupted, fatalio;
  6076.  
  6077.     ftp = lastxfer & W_FTP;
  6078.  
  6079. #ifdef CK_TTGWSIZ
  6080. #ifdef OS2
  6081.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  6082.       ttgwsiz();
  6083. #else /* OS2 */
  6084.     if (ttgwsiz() > 0) {
  6085.         if (tt_rows > 0 && tt_cols > 0) {
  6086.             cmd_rows = tt_rows;
  6087.             cmd_cols = tt_cols;
  6088.         }
  6089.     }
  6090. #endif /* OS2 */
  6091. #endif /* CK_TTGWSIZ */
  6092.  
  6093.     debug(F101,"dostat xferstat","",xferstat);
  6094.     if (xferstat < 0) {
  6095.         printf(" No file transfers yet.\n");
  6096.         return(1);
  6097.     }
  6098.     n = 0;
  6099.     if (brief) { printf("\n"); n++; };
  6100.     printf(" protocol               : %s\n",
  6101.            ftp ? "ftp" : ptab[protocol].p_name);
  6102.     n++;
  6103.     printf(" status                 : ");
  6104.     if (xferstat) printf("SUCCESS\n");
  6105.     else if (interrupted) printf("FAILURE (interrupted)\n");
  6106.     else if (fatalio) printf("FAILURE (i/o error)\n");
  6107.     else printf("FAILURE\n");
  6108. #ifndef XYZ_INTERNAL
  6109.     if (!ftp && protocol != PROTO_K) {
  6110.         printf("\n external protocol statistics not available\n");
  6111.         return(1);
  6112.     }
  6113. #endif /* XYZ_INTERNAL */
  6114.     n++;
  6115.     if (!ftp) {
  6116.         if (!xferstat > 0) {
  6117.             if (docrc)
  6118.               printf(" crc-16 of file(s)      : %ld\n", crc16);
  6119.             else
  6120.               printf(" crc-16 of file(s)      : (disabled)\n");
  6121.             n++;
  6122.         }
  6123.         if (!xferstat && *epktmsg) {
  6124.             printf(" reason                 : %s\n", epktmsg);
  6125.             n++;
  6126.         }
  6127.     }
  6128.     if (!brief) {
  6129. #ifdef NEWFTP
  6130.         if (ftp) {
  6131.             extern char ftp_srvtyp[];
  6132.             printf(" remote system type     : %s\n",ftp_srvtyp);
  6133.         } else
  6134. #endif /* NEWFTP */
  6135.           if (whoareu[0]) {
  6136.             printf(" remote system type     : %s\n",
  6137.                    getsysid((char *)whoareu));
  6138.             n++;
  6139.         }
  6140.         printf(" files transferred      : %ld\n",filcnt - filrej);
  6141.         if (!ftp)
  6142.           printf(" files not transferred  : %ld\n",filrej);
  6143.         printf(" characters last file   : %ld\n",ffc);
  6144.         printf(" total file characters  : %ld\n",tfc);
  6145.         n += ftp ? 3 : 4;
  6146.         if (!ftp) {
  6147.             printf(" communication line in  : %ld\n",tlci);
  6148.             printf(" communication line out : %ld\n",tlco);
  6149.             printf(" packets sent           : %d\n", spackets);
  6150.             printf(" packets received       : %d\n", rpackets);
  6151.             n += 4;
  6152.         }
  6153.     }
  6154.     if (ftp) goto dotimes;
  6155.  
  6156.     printf(" damaged packets rec'd  : %d\n", crunched);
  6157.     printf(" timeouts               : %d\n", timeouts);
  6158.     printf(" retransmissions        : %d\n", retrans);
  6159.     n += 3;
  6160.  
  6161.     if (!brief) {
  6162.         if (filcnt > 0) {
  6163.             printf(" parity                 : %s",parnam((char)parity));
  6164.             n++;
  6165.             if (autopar) { printf(" (detected automatically)"); n++; }
  6166.             printf(
  6167.                  "\n control characters     : %ld prefixed, %ld unprefixed\n",
  6168.                    ccp, ccu);
  6169.             n++;
  6170.             printf(" 8th bit prefixing      : ");
  6171.             n++;
  6172.             if (ebqflg) printf("yes [%c]\n",ebq); else printf("no\n");
  6173.             n++;
  6174.             printf(" locking shifts         : %s\n", lscapu ? "yes" : "no");
  6175.             n++;
  6176.         }
  6177.     }
  6178.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6179.     if (streamed > 0)
  6180.       printf(" window slots used      : (streaming)\n");
  6181.     else
  6182.       printf(" window slots used      : %d of %d\n", wmax, wslotr);
  6183.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6184.     printf(" reliable:              : %s%s\n",
  6185.            streamok ? "" : "not ", "negotiated");
  6186.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6187.     printf(" clearchannel:          : %s%s\n",
  6188.            cleared  ? "" : "not ", "negotiated");
  6189.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6190.  
  6191.     if (!brief) {
  6192.         printf(" packet length          : %d (send), %d (receive)\n",
  6193.                lastspmax, urpsiz);
  6194.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6195.         printf(" compression            : ");
  6196.         if (rptflg)
  6197.           printf("yes [%c] (%ld)\n",(char) rptq,rptn);
  6198.         else
  6199.           printf("no\n");
  6200.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6201.         if (bctu == 4)
  6202.           printf(" block check type used  : blank-free-2\n");
  6203.         else
  6204.           printf(" block check type used  : %d\n",bctu);
  6205.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6206.     }
  6207.  
  6208.   dotimes:
  6209.  
  6210. #ifdef GFTIMER
  6211. #ifdef COMMENT
  6212.     printf(" elapsed time           : %0.3f sec, %s\n", fptsecs,hhmmss(tsecs));
  6213. #endif /* COMMENT */
  6214.     printf(" elapsed time           : %s (%0.3f sec)\n",
  6215.            hhmmss((long)(fptsecs + 0.5)),fptsecs);
  6216. #else
  6217. #ifdef COMMENT
  6218.     printf(" elapsed time           : %s (%d sec)\n",hhmmss(tsecs),tsecs);
  6219. #endif /* COMMENT */
  6220.     printf(" elapsed time           : %d sec, %s\n",tsecs,hhmmss(tsecs));
  6221. #endif /* GFTIMER */
  6222.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6223.     if (!ftp && local && !network && !brief) {
  6224.         if (speed <= 0L) speed = ttgspd();
  6225.         if (speed > 0L) {
  6226.             if (speed == 8880)
  6227.               printf(" transmission rate      : 75/1200 bps\n");
  6228.             else
  6229.               printf(" transmission rate      : %ld bps\n",speed);
  6230.             if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6231.         }
  6232.     }
  6233.     if (!ftp && local && !network &&    /* Only makes sense for */
  6234.         mdmtyp == 0 &&                  /* direct serial connections */
  6235.         speed > 99L &&                  /* when we really know the speed */
  6236.         speed != 8880L
  6237.         ) {
  6238.         int eff;
  6239.         eff = (((tfcps * 100L) / (speed / 100L)) + 5L) / 10L;
  6240.         printf(" effective data rate    : %ld cps (%d%%)\n",tfcps,eff);
  6241.     } else
  6242.       printf(" effective data rate    : %ld cps\n", tfcps);
  6243.     if (!ftp && peakcps > 0L && peakcps > tfcps)
  6244.       printf(" peak data rate         : %ld cps\n", peakcps);
  6245.     if (brief)
  6246.       printf("\nUse STATISTICS /VERBOSE for greater detail.\n\n");
  6247.     return(1);
  6248. }
  6249. #endif /* NOXFER */
  6250.  
  6251. #ifndef NOSPL
  6252.  
  6253. /* The INPUT command */
  6254.  
  6255. /*
  6256.   NOTE: An INPUT timeout of 0 means to perform a nonblocking read of the
  6257.   material that has already arrived and is waiting to be read, and perform
  6258.   matches against it, without doing any further reads.  It should succeed
  6259.   or fail instantaneously.
  6260. */
  6261.  
  6262. /* Output buffering for "doinput" */
  6263.  
  6264. #ifdef pdp11
  6265. #define MAXBURST 16             /* Maximum size of input burst */
  6266. #else
  6267. #define MAXBURST 1024
  6268. #endif /* pdp11 */
  6269. #ifdef OSK
  6270. static CHAR *conbuf;            /* Buffer to hold output for console */
  6271. #else
  6272. static CHAR conbuf[MAXBURST];   /* Buffer to hold output for console */
  6273. #endif /* OSK */
  6274. static int concnt = 0;          /* Number of characters buffered */
  6275. #ifdef OSK
  6276. static CHAR *sesbuf;            /* Buffer to hold output for session log */
  6277. #else
  6278. static CHAR sesbuf[MAXBURST];   /* Buffer to hold output for session log */
  6279. #endif /* OSK */
  6280. static int sescnt = 0;          /* Number of characters buffered */
  6281.  
  6282. extern int debses;                      /* TERMINAL DEBUG ON/OFF */
  6283.  
  6284. static VOID                             /* Flush INPUT echoing */
  6285. myflsh() {                              /* and session log output. */
  6286.     if (concnt > 0) {
  6287.         if (debses) {                   /* Terminal debugging? */
  6288.             int i;
  6289.             for (i = 0; i < concnt; i++)
  6290.               conol(dbchr(conbuf[i]));
  6291.         } else
  6292.           conxo(concnt, (char *) conbuf);
  6293.         concnt = 0;
  6294.     }
  6295.     if (sescnt > 0) {
  6296.         logstr((char *) sesbuf, sescnt);
  6297.         sescnt = 0;
  6298.     }
  6299. }
  6300.  
  6301. /* Execute the INPUT and MINPUT commands */
  6302.  
  6303. int instatus = -1;
  6304. long inetime = -1L;
  6305. int inwait = 0;
  6306.  
  6307. /* For returning the input sequence that matched */
  6308.  
  6309. #ifdef BIGBUFOK
  6310. #define MATCHBUFSIZ 8191
  6311. #else
  6312. #define MATCHBUFSIZ 1023
  6313. #endif /* BIGBUFOK */
  6314. static char * matchbuf = NULL;
  6315. static int matchindex = 0;
  6316. /*
  6317.   timo = How long to wait:
  6318.          < 0 = Wait forever
  6319.            0 = Don't wait
  6320.          > 0 = Wait this many seconds
  6321.   ms   = Array of strings to wait for.
  6322.   mp   = Array of flags.
  6323.          If mp[i] == 0, ms[i] is literal, else it's a pattern.
  6324. */
  6325. int
  6326. doinput(timo,ms,mp) int timo; char *ms[]; int mp[]; {
  6327.     extern int inintr;
  6328. #ifdef CK_AUTODL
  6329.     extern int inautodl;
  6330. #endif /* CK_AUTODL */
  6331.     int x, y, i, t, rt, icn, anychar, mi[MINPMAX];
  6332. #ifdef GFTIMER
  6333.     CKFLOAT fpt = 0.0;
  6334. #endif /* GFTIMER */
  6335.     int lastchar = 0;
  6336.     int waiting = 0;
  6337.     char ch, *xp, *s;
  6338.     CHAR c;
  6339. #ifndef NOLOCAL
  6340. #ifdef OS2
  6341.     extern int term_io;
  6342.     int term_io_save;
  6343. #endif /* OS2 */
  6344. #endif /* NOLOCAL */
  6345. #ifdef TNCODE
  6346.     static int cr = 0;
  6347. #endif /* TNCODE */
  6348.     int is_tn = 0;
  6349.     int wrapped = 0;
  6350.  
  6351. #define CK_BURST
  6352. /*
  6353.   This enables the INPUT speedup code, which depends on ttchk() returning
  6354.   accurate information.  If INPUT fails with this code enabled, change the
  6355.   above "#define" to "#undef".
  6356. */
  6357. #ifdef CK_BURST
  6358.     int burst = 0;                      /* Chars remaining in input burst */
  6359. #endif /* CK_BURST */
  6360.  
  6361.     inwait = timo;                      /* For \v(inwait) */
  6362.     makestr(&inpmatch,NULL);
  6363.  
  6364.     if (!matchbuf) {
  6365.         matchbuf = malloc(MATCHBUFSIZ+1);
  6366.         matchbuf[0] = NUL;
  6367.     }
  6368.     matchindex = 0;
  6369.  
  6370.     is_tn =
  6371. #ifdef TNCODE
  6372.         (local && network && IS_TELNET()) || (!local && sstelnet)
  6373. #else
  6374.          0
  6375. #endif /* TNCODE */
  6376.           ;
  6377.  
  6378.     instatus = INP_IE;                  /* 3 = internal error */
  6379.     kbchar = 0;
  6380.  
  6381. #ifdef OSK
  6382.     if (conbuf == NULL) {
  6383.         if ((conbuf = (CHAR *)malloc(MAXBURST*2)) == NULL) {
  6384.             return(0);
  6385.         }
  6386.         sesbuf = conbuf + MAXBURST;
  6387.     }
  6388. #endif /* OSK */
  6389.  
  6390. #ifndef NOLOCAL
  6391.     if (local) {                        /* In local mode... */
  6392.         if ((waiting = ttchk()) < 0) {  /* check that connection is open */
  6393.             printf("?Connection %s %s is not open.\n",
  6394.                    network ? "to" : "on",
  6395.                    ttname
  6396.                    );
  6397.             instatus = INP_IO;
  6398.             return(0);
  6399.         }
  6400.         debug(F101,"doinput waiting","",waiting);
  6401.         y = ttvt(speed,flow);           /* Put line in "ttvt" mode */
  6402.         if (y < 0) {
  6403.             printf("?INPUT initialization error\n");
  6404.             instatus = INP_IO;
  6405.             return(0);                  /* Watch out for failure. */
  6406.         }
  6407.     }
  6408. #endif /* NOLOCAL */
  6409.  
  6410.     debug(F111,"doinput ms[0]",ms[0],waiting);
  6411.  
  6412.     if (!ms[0]) {                       /* If we were passed a NULL pointer */
  6413.         anychar = 1;                    /*  ... */
  6414.     } else {
  6415.         y = (int)strlen(ms[0]);         /* Or if search string is empty */
  6416.         anychar = (y < 1);              /* any input character will do. */
  6417.     }
  6418.     if (!anychar && waiting == 0 && timo == 0)
  6419.       return(0);
  6420.  
  6421. #ifndef NODEBUG
  6422.     if (deblog) {
  6423.         char xbuf[24];
  6424.         debug(F101,"doinput anychar","",anychar);
  6425.         debug(F101,"doinput timo","",timo);
  6426.         debug(F101,"doinput echo","",inecho);
  6427.         debug(F101,"doinput burst","",burst);
  6428.         y = -1;
  6429.         while (ms[++y]) {
  6430.             sprintf(xbuf,"doinput string %2d",y); /* SAFE (24) */
  6431.             debug(F111,xbuf,ms[y],mp[y]);
  6432.         }
  6433.     }
  6434. #endif /* NODEBUG */
  6435.  
  6436. #ifdef IKS_OPTION
  6437.     if (is_tn) {
  6438.         /* If the remote side is in a state of IKS START-SERVER    */
  6439.         /* we request that the state be changed.  We will detect   */
  6440.         /* a failure to adhere to the request when we call ttinc() */
  6441.         if (TELOPT_U(TELOPT_KERMIT) &&
  6442.             TELOPT_SB(TELOPT_KERMIT).kermit.u_start)
  6443.           iks_wait(KERMIT_REQ_STOP,0);  /* Send Request-Stop */
  6444. #ifdef CK_AUTODL
  6445.         /* If we are processing packets during INPUT and we have not */
  6446.         /* sent a START message, do so now.                          */
  6447.         if (inautodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  6448.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  6449.         }
  6450. #endif /* CK_AUTODL */
  6451.     }
  6452. #endif /* IKS_OPTION */
  6453.     x = 0;                              /* Return code, assume failure */
  6454.     instatus = INP_TO;                  /* Status, assume timeout */
  6455.  
  6456.     for (y = 0; y < MINPMAX; y++)
  6457.       mi[y] = 0;                        /* String pattern match position */
  6458.  
  6459.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  6460.         y = -1;
  6461.  
  6462.         while ((xp = ms[++y])) {
  6463.             while (*xp) {               /* Convert to lowercase */
  6464.                 if (isupper(*xp)) *xp = (char) tolower(*xp);
  6465.                 xp++;
  6466.             }
  6467.         }
  6468.     }
  6469.     rtimer();                           /* Reset timer. */
  6470. #ifdef GFTIMER
  6471.     rftimer();                          /* Floating-point timer too. */
  6472. #endif /* GFTIMER */
  6473.     inetime = -1L;                      /* Initialize elapsed time. */
  6474.     t = 0;                              /* Time now is 0. */
  6475.     m_found = 0;                        /* Default to timed-out */
  6476.     incount = 0;                        /* Character counter */
  6477.     rt = (timo == 0) ? 0 : 1;           /* Character-read timeout interval */
  6478.  
  6479. #ifndef NOLOCAL
  6480. #ifdef OS2
  6481.     term_io_save = term_io;             /* Disable I/O by emulator */
  6482.     term_io = 0;
  6483. #endif /* OS2 */
  6484. #endif /* NOLOCAL */
  6485.  
  6486.     while (1) {                         /* Character-getting loop */
  6487. #ifdef CK_APC
  6488.         /* Check to see if there is an Autodown or other APC command */
  6489.         if (apcactive == APC_LOCAL ||
  6490.             (apcactive == APC_REMOTE && apcstatus != APC_OFF)) {
  6491.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  6492.                 debug(F110,"doinput about to execute APC",apcbuf,0);
  6493.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  6494.                 delmac("_apc_commands",1);
  6495.                 apcactive = APC_INACTIVE;
  6496. #ifdef DEBUG
  6497.             } else {
  6498.                 debug(F100,"doinput APC in progress","",0);
  6499. #endif /* DEBUG */
  6500.             }
  6501.         }
  6502. #endif /* CK_APC */
  6503.  
  6504.         if (timo == 0 && waiting < 1) { /* Special exit criterion */
  6505.             instatus = INP_TO;          /* for timeout == 0 */
  6506.             break;
  6507.         }
  6508.         if (local) {                    /* One case for local */
  6509.             y = ttinc(rt);              /* Get character from comm device */
  6510.             debug(F101,"doinput ttinc(rt) returns","",y);
  6511.             if (y < -1) {               /* Connection failed. */
  6512.                 instatus = INP_IO;      /* Status = i/o error */
  6513. #ifndef NOLOCAL
  6514. #ifdef OS2
  6515.                 term_io = term_io_save;
  6516. #endif /* OS2 */
  6517. #endif /* NOLOCAL */
  6518.                 switch (y) {
  6519.                   case -2:              /* Connection lost */
  6520.                     if (local && !network && carrier != CAR_OFF) {
  6521.                         dologend();
  6522.                         printf("Connection closed.\n");
  6523.                         ttclos(1);
  6524.                     }
  6525.                     break;
  6526.                   case -3:
  6527.                     dologend();
  6528.                     printf("Session Limit exceeded - closing connection.\n");
  6529.                     ttclos(1);
  6530.                   default:
  6531.                     break;
  6532.                 }
  6533.                 debug(F111,"doinput Connection failed","returning 0",y);
  6534.                 return(0);
  6535.             }
  6536.             if (inintr) {
  6537.                 debug(F111,"doinput","inintr",inintr);
  6538.                 if ((icn = conchk()) > 0) { /* Interrupted from keyboard? */
  6539.                     debug(F101,"input interrupted from keyboard","",icn);
  6540.                     kbchar = coninc(0);
  6541.                     if (kbchar >= 0) {
  6542.                         while (--icn > 0) {
  6543.                             debug(F110,"doinput","absorbing",0);
  6544.                             coninc(0);      /* Yes, absorb what was typed. */
  6545.                         }
  6546.                         instatus = INP_UI;  /* Fail and remember why. */
  6547.                         break;
  6548.                     }
  6549.                 }
  6550.             }
  6551.         } else {                        /* Another for remote */
  6552.             y = coninc(rt);
  6553.             debug(F101,"doinput coninc(rt) returns","",y);
  6554.         }
  6555.         if (y > -1) {                   /* A character arrived */
  6556.             debug(F111,"doinput","a character arrived",y);
  6557.             if (timo == 0)
  6558.               waiting--;
  6559. #ifndef OS2
  6560. #define TN_NOLO
  6561. #endif /* OS2 */
  6562. #ifdef NOLOCAL
  6563. #define TN_NOLO
  6564. #endif /* NOLOCAL */
  6565.  
  6566. #ifdef TN_NOLO
  6567.             debug(F100,"doinput TN_NOLO","",0);
  6568. #ifdef TNCODE
  6569.             /* Check for telnet protocol negotiation */
  6570.             if (is_tn) {
  6571.                 switch (y & 0xff) {
  6572.                   case IAC:
  6573.                     cr = 0;
  6574.                     myflsh();   /* Break from input burst for tn_doop() */
  6575. #ifdef CK_BURST
  6576.                     burst = 0;
  6577. #endif /* CK_BURST */
  6578.                     waiting -= 2;       /* (not necessarily...) */
  6579.                     switch (tn_doop((CHAR)(y & 0xff),duplex,ttinc)) {
  6580.                       case 2: duplex = 0; continue;
  6581.                       case 1: duplex = 1; continue;
  6582. #ifdef IKS_OPTION
  6583.                       case 4:
  6584.                         if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6585.                              !tcp_incoming) {
  6586.                             instatus = INP_IKS;
  6587.                             printf(
  6588.  " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6589.                                    );
  6590.                             break;
  6591.                         }
  6592.                         continue;
  6593. #endif /* IKS_OPTION */
  6594.                       case 6:           /* TELNET DO LOGOUT received */
  6595.                       default: continue;
  6596.                     }
  6597.                   case CR:
  6598.                     cr = 1;
  6599.                     break;
  6600.                   case NUL:
  6601.                     if (!TELOPT_U(TELOPT_BINARY) && cr) {
  6602.                         cr = 0;
  6603.                         continue;
  6604.                     }
  6605.                     cr = 0;
  6606.                     break;
  6607.                   default:
  6608.                     cr = 0;
  6609.                 }
  6610.                 /* I'm echoing remote chars */
  6611.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6612.                   ttoc((char)y);
  6613.             }
  6614. #endif /* TNCODE */
  6615. #ifdef CK_AUTODL
  6616.             /* Check for file transfer packets */
  6617.             if (inautodl) autodown(y);
  6618. #endif /* CK_AUTODL */
  6619. #else  /* TN_NOLO */
  6620.             debug(F100,"doinput !TN_NOLO","",0);
  6621. #ifdef TNCODE
  6622.             /* Check for telnet protocol negotiation */
  6623.             if (is_tn) {
  6624.                 int tx;
  6625.                 switch (y & 0xff) {
  6626.                   case IAC:
  6627.                     myflsh();   /* Break from input burst for tn_doop() */
  6628. #ifdef CK_BURST
  6629.                     burst = 0;
  6630. #endif /* CK_BURST */
  6631. #ifdef IKS_OPTION
  6632.                     tx = scriptwrtbuf((USHORT)y);
  6633.                     if (tx == 4) {
  6634.                         if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6635.                             !tcp_incoming
  6636.                             ) {
  6637.                             instatus = INP_IKS;
  6638.                             printf(
  6639.   " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6640.                                    );
  6641.                             break;
  6642.                         }
  6643.                     } else if (tx == 6) {
  6644.                         /* TELNET DO LOGOUT received */
  6645.  
  6646.                     }
  6647. #else /* IKS_OPTION */
  6648.                     /* Handles Telnet negotiations */
  6649.                     tx = scriptwrtbuf((USHORT)y);
  6650.                     if (tx == 6) {
  6651.                         /* TELNET DO LOGOUT received */
  6652.                     }
  6653. #endif /* IKS_OPTION */
  6654.                     waiting -= 2;       /* (not necessarily...) */
  6655.                     cr = 0;
  6656.                     continue;           /* and autodownload check */
  6657.                   case CR:
  6658.                     cr = 1;
  6659.                     tx = scriptwrtbuf((USHORT)y);
  6660.                     if (tx == 6) {
  6661.                         /* TELNET DO LOGOUT received */
  6662.                     }
  6663.                     break;
  6664.                   case NUL:
  6665.                     cr = 0;
  6666.                     if (!TELOPT_U(TELOPT_BINARY) && cr)
  6667.                       continue;
  6668.                     tx = scriptwrtbuf((USHORT)y);
  6669.                     if (tx == 6) {
  6670.                         /* TELNET DO LOGOUT received */
  6671.                     }
  6672.                     break;
  6673.                   default:
  6674.                     cr = 0;
  6675.                     tx = scriptwrtbuf((USHORT)y);
  6676.                     if (tx == 6) {
  6677.                         /* TELNET DO LOGOUT received */
  6678.                     }
  6679.                 }
  6680.                 /* I'm echoing remote chars */
  6681.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6682.                   ttoc((CHAR)y);
  6683.             } else
  6684. #endif /* TNCODE */
  6685.               /* Handles terminal emulation responses */
  6686.               scriptwrtbuf((USHORT)y);
  6687. #endif /* TN_NOLO */
  6688.  
  6689.             /* Real input character to be checked */
  6690.  
  6691. #ifdef CK_BURST
  6692.             burst--;                    /* One less character waiting */
  6693.             debug(F101,"doinput burst","",burst);
  6694. #endif /* CK_BURST */
  6695.             c = (CHAR) (cmask & (CHAR) y); /* Mask off parity */
  6696.             inchar[0] = c;              /* Remember character for \v(inchar) */
  6697. #ifdef COMMENT
  6698. #ifdef CK_BURST
  6699.             /* Update "lastchar" time only once during input burst */
  6700.             if (burst <= 0)
  6701. #endif /* CK_BURST */
  6702. #endif /* COMMENT */
  6703.               lastchar = gtimer();      /* Remember when it came */
  6704.  
  6705.             if (c == '\0') {            /* NUL, we can't use it */
  6706.                 if (anychar) {          /* Except if any character will do? */
  6707.                     x = 1;              /* Yes, done. */
  6708.                     incount = 1;        /* This must be the first and only. */
  6709.                     break;
  6710.                 } else goto refill;     /* Otherwise continue INPUTting */
  6711.             }
  6712.             *inpbp++ = c;               /* Store char in circular buffer */
  6713.             incount++;                  /* Count it for \v(incount) */
  6714.  
  6715.             /* Don't NUL-terminate here - it's a circular buffer. */
  6716.  
  6717.             if (inpbp >= inpbuf + inbufsize) { /* Time to wrap around? */
  6718.                 wrapped++;
  6719.                 *inpbp = NUL ;          /* Make it null-terminated */
  6720.                 inpbp = inpbuf;         /* Yes. */
  6721.             }
  6722.             if (matchbuf) {
  6723.                 if (matchindex < MATCHBUFSIZ) {
  6724.                     matchbuf[matchindex++] = c;
  6725.                     matchbuf[matchindex] = NUL;
  6726.                 }
  6727.             }
  6728. #ifdef MAC
  6729.             {
  6730.                 extern char *ttermw;    /* fake pointer cast */
  6731.                 if (inecho) {
  6732.                     outchar(ttermw, c); /* echo to terminal window */
  6733.                     /* this might be too much overhead to do here ? */
  6734.                     updatecommand(ttermw);
  6735.                 }
  6736.             }
  6737. #else /* Not MAC */
  6738.             if (inecho) {               /* Buffer console output */
  6739.                 conbuf[concnt++] = c;
  6740.             }
  6741. #endif /* MAC */
  6742. #ifndef OS2
  6743.             if (seslog) {
  6744. #ifdef UNIX
  6745.                 if (sessft != 0 || c != '\r')
  6746. #else
  6747. #ifdef OSK
  6748.                 if (sessft != 0 || c != '\012')
  6749. #endif /* OSK */
  6750. #endif /* UNIX */
  6751.                   sesbuf[sescnt++] = c; /* Buffer session log output */
  6752.             }
  6753. #endif /* OS2 */
  6754.             if (anychar) {              /* Any character will do? */
  6755.                 x = 1;
  6756.                 break;
  6757.             }
  6758.             if (!inpcas[cmdlvl]) {      /* Ignore alphabetic case? */
  6759.                 if (isupper(c))         /* Yes, convert input char to lower */
  6760.                   c = (CHAR) tolower(c);
  6761.             }
  6762.             debug(F000,"doinput char","",c);
  6763.  
  6764.             /* Here is the matching section */
  6765.  
  6766.             y = -1;                     /* Loop thru search strings */
  6767.             while ((s = ms[++y])) {     /* ...as many as we have. */
  6768.                 if (mp[y]) {            /* Pattern match? */
  6769. #ifdef COMMENT
  6770.                     int j;
  6771.                     /* This is gross but it works... */
  6772.                     /* We could just as easily have prepended '*' to the  */
  6773.                     /* pattern and skipped the loop, except then we would */
  6774.                     /* not have any way to identify the matching string.  */
  6775.                     for (j = 0; j < matchindex; j++) {
  6776.                         if (ckmatch(s,&matchbuf[j],1,1)) {
  6777.                             matchindex = j;
  6778.                             x = 1;
  6779.                             break;
  6780.                         }
  6781.                     }
  6782.                     if (x > 0)
  6783.                       break;
  6784. #else
  6785.                     /* July 2001 - ckmatch() returns match position. */
  6786.                     /* It works and it's not gross. */
  6787.                     x = ckmatch(s,matchbuf,1,1+4); /* (4 = floating pattern) */
  6788.                     if (x > 0) {
  6789.                         matchindex = x - 1;
  6790.                         x = 1;
  6791.                         break;
  6792.                     }
  6793. #endif /* COMMENT */
  6794.                     continue;
  6795.                 }                       /* Literal match. */
  6796.                 i = mi[y];              /* Match-position in search string. */
  6797.                 debug(F000,"compare char","",(CHAR)s[i]);
  6798.                 if (c == (CHAR) s[i]) { /* Check for match */
  6799.                     i++;                /* Got one, go to next character */
  6800.                 } else {                /* Don't have a match */
  6801.                     int j;
  6802.                     for (j = i; i > 0; ) { /* Back up in search string */
  6803.                         i--; /* (Do this here to prevent compiler foulup) */
  6804.                         /* j is the length of the substring that matched */
  6805.                         if (c == (CHAR) s[i]) {
  6806.                             if (!strncmp(s,&s[j-i],i)) {
  6807.                                 i++;          /* c actually matches -- cfk */
  6808.                                 break;
  6809.                             }
  6810.                         }
  6811.                     }
  6812.                 }
  6813.                 if ((CHAR) s[i] == (CHAR) '\0') { /* Matched to end? */
  6814.                     ckstrncpy(matchbuf,ms[y],MATCHBUFSIZ);
  6815.                     matchindex = 0;
  6816.                     x = 1;              /* Yes, */
  6817.                     break;              /* done. */
  6818.                 }
  6819.                 mi[y] = i;              /* No, remember match-position */
  6820.             }
  6821.             if (x == 1) {               /* Set \v(minput) result */
  6822.                 m_found = y + 1;
  6823.                 break;
  6824.             }
  6825.         }
  6826. #ifdef CK_BURST
  6827.         else if (y <= -1 && burst > 0) {
  6828.             debug(F111,"doinput (y<=-1&&burst>0)","burst",burst);
  6829.                                         /* a timo occurred so there can't   */
  6830.             burst = 0;                  /* be data waiting; must check timo */
  6831.         }
  6832.       refill:
  6833.         if (burst <= 0) {               /* No buffered chars remaining... */
  6834.             myflsh();                   /* Flush buffered output */
  6835.             if (local) {                /* Get size of next input burst */
  6836.                 burst = ttchk();
  6837.                 if (burst < 0) {        /* ttchk() says connection is closed */
  6838.                     instatus = INP_IO;  /* Status = i/o error */
  6839. #ifndef NOLOCAL
  6840. #ifdef OS2
  6841.                     term_io = term_io_save;
  6842. #endif /* OS2 */
  6843. #endif /* NOLOCAL */
  6844.                     printf("Fatal error - disconnected.\n");
  6845.                     ttclos(1);
  6846.                     break;
  6847.                 }
  6848.                 if (inintr) {
  6849.                     if ((icn = conchk()) > 0) { /* Interrupt from keyboard? */
  6850.                         kbchar = coninc(0);
  6851.                         debug(F101,"input interrupted from keyboard","",icn);
  6852.                         while (--icn > 0) coninc(0); /* Yes, absorb chars. */
  6853.                         break;          /* And fail. */
  6854.                     }
  6855.                 }
  6856.             } else {
  6857.                 burst = conchk();
  6858.             }
  6859.             debug(F101,"doinput burst","",burst);
  6860.             /* Prevent overflow of "conbuf" and "sesbuf" */
  6861.             if (burst > MAXBURST)
  6862.               burst = MAXBURST;
  6863.  
  6864.             /* Did not match, timer exceeded? */
  6865.             t = gtimer();
  6866.             debug(F111,"doinput gtimer","burst",t);
  6867.             debug(F101,"doinput timo","",timo);
  6868.             if ((t >= timo) && (timo > 0))
  6869.               break;
  6870.             else if (insilence > 0 && (t - lastchar) > insilence)
  6871.               break;
  6872.         } else {
  6873.             debug(F111,"doinput (burst > 0)","burst",burst);
  6874.         }
  6875. #else
  6876.         myflsh();                       /* Flush buffered output */
  6877.         /* Did not match, timer exceeded? */
  6878.         t = gtimer();
  6879.         debug(F111,"doinput gtimer","no burst",t);
  6880.         debug(F101,"doinput timo","",timo);
  6881.         if ((t >= timo) && (timo > -1))
  6882.           break;
  6883.         else if (insilence > 0 && (t - lastchar) > insilence)
  6884.           break;
  6885. #endif /* CK_BURST */
  6886.     }                                   /* Still have time left, continue. */
  6887.     myflsh();                           /* Flush buffered output. */
  6888.     if (x > 0)
  6889.       instatus = 0;
  6890. #ifndef NOLOCAL
  6891. #ifdef OS2
  6892.     term_io = term_io_save;
  6893. #endif /* OS2 */
  6894. #endif /* NOLOCAL */
  6895. #ifdef COMMENT
  6896. #ifdef IKS_OPTION
  6897. #ifdef CK_AUTODL
  6898.     if (is_tn && TELOPT_ME(TELOPT_KERMIT) && inautodl) {
  6899.         tn_siks(KERMIT_STOP);           /* Send Kermit-Server Stop */
  6900.     }
  6901. #endif /* CK_AUTODL */
  6902. #endif /* IKS_OPTION */
  6903. #endif /* COMMENT */
  6904.  
  6905. #ifdef GFTIMER
  6906.     fpt = gftimer();                    /* Get elapsed time */
  6907.  
  6908. /* If a long is 32 bits, it would take about 50 days for this to overflow. */
  6909.  
  6910.     inetime = (int)(fpt * (CKFLOAT)1000.0);
  6911. #else
  6912.     inetime = (int)(gtimer() * 1000);
  6913. #endif /* GFTIMER */
  6914.  
  6915.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  6916.     return(x);                          /* Return the return code. */
  6917. }
  6918. #endif /* NOSPL */
  6919.  
  6920. #ifndef NOSPL
  6921. /* REINPUT Command */
  6922.  
  6923. /*
  6924.   Note, the timeout parameter is required, but ignored.  Syntax is compatible
  6925.   with MS-DOS Kermit except timeout can't be omitted.  This function only
  6926.   looks at the characters already received and does not read any new
  6927.   characters from the connection.
  6928. */
  6929. int
  6930. doreinp(timo,s,pat) int timo; char *s; int pat; {
  6931.     int x, y, i;
  6932.     char *xx, *xp, *xq = (char *)0;
  6933.     CHAR c;
  6934.  
  6935.     if (!s) s = "";
  6936.     debug(F101,"doreinput pat","",pat);
  6937.  
  6938.     y = (int)strlen(s);
  6939.     debug(F111,"doreinput search",s,y);
  6940.  
  6941.     if (y > inbufsize) {                /* If search string longer than */
  6942.         debug(F101,"doreinput inbufsize","",inbufsize);
  6943.         return(0);                      /* input buffer, fail. */
  6944.     }
  6945.     makestr(&inpmatch,NULL);
  6946.     if (!matchbuf)
  6947.       matchbuf = malloc(MATCHBUFSIZ+1);
  6948.     matchindex = 0;
  6949.  
  6950.     x = 0;                              /* Return code, assume failure */
  6951.     i = 0;                              /* String pattern match position */
  6952.  
  6953.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  6954.         xp = malloc(y+2);               /* Make a separate copy of the */
  6955.         if (!xp) {                      /* search string. */
  6956.             printf("?malloc error 6\n");
  6957.             return(x);
  6958.         } else xq = xp;                 /* Keep pointer to beginning. */
  6959.         while (*s) {                    /* Yes, convert to lowercase */
  6960.             *xp = *s;
  6961.             if (isupper(*xp)) *xp = (char) tolower(*xp);
  6962.             xp++; s++;
  6963.         }
  6964.         *xp = NUL;                      /* Terminate it! */
  6965.         s = xq;                         /* Move search pointer to it. */
  6966.     }
  6967.     xx = *inpbp ? inpbp : inpbuf;       /* Current INPUT buffer pointer */
  6968.     do {
  6969.         c = *xx++;                      /* Get next character */
  6970.         if (!c) break;
  6971.         if (xx >= inpbuf + inbufsize)   /* Wrap around if necessary */
  6972.           xx = inpbuf;
  6973.         if (!inpcas[cmdlvl]) {          /* Ignore alphabetic case? */
  6974.             if (isupper(c)) c = (CHAR) tolower(c); /* Yes */
  6975.         }
  6976.         if (pat) {
  6977.             int j;
  6978.             if (matchbuf) {
  6979.                 if (matchindex < MATCHBUFSIZ) {
  6980.                     matchbuf[matchindex++] = c;
  6981.                     matchbuf[matchindex] = NUL;
  6982.                 }
  6983.                 for (j = 0; j < matchindex; j++) { /* Gross but effective */
  6984.                     if (ckmatch(s,&matchbuf[j],1,1)) {
  6985.                         debug(F101,"GOT IT","",j);
  6986.                         matchindex = j;
  6987.                         x = 1;
  6988.                         break;
  6989.                     }
  6990.                 }
  6991.             }
  6992.             if (x > 0)
  6993.               break;
  6994.             continue;
  6995.         }
  6996.         debug(F000,"doreinp char","",c);
  6997.         debug(F000,"compare char","",(CHAR) s[i]);
  6998.         if (((char) c) == ((char) s[i])) { /* Check for match */
  6999.             i++;                        /* Got one, go to next character */
  7000.         } else {                        /* Don't have a match */
  7001.             int j;
  7002.             for (j = i; i > 0; ) {      /* [jrs] search backwards for it  */
  7003.                 i--;
  7004.                 if (((char) c) == ((char) s[i])) {
  7005.                     if (!strncmp(s,&s[j-i],i)) {
  7006.                         i++;
  7007.                         break;
  7008.                     }
  7009.                 }
  7010.             }
  7011.         }                               /* [jrs] or return to zero from -1 */
  7012.         if (s[i] == '\0') {             /* Matched all the way to end? */
  7013.             ckstrncpy(matchbuf,s,MATCHBUFSIZ);
  7014.             matchindex = 0;
  7015.             x = 1;                      /* Yes, */
  7016.             break;                      /* done. */
  7017.         }
  7018.     } while (xx != inpbp && x < 1);     /* Until back where we started. */
  7019.  
  7020.     if (!inpcas[cmdlvl]) if (xq) free(xq); /* Free this if it was malloc'd. */
  7021.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  7022.     return(x);                          /* Return search result. */
  7023. }
  7024.  
  7025. /*  X X S T R I N G  --  Interpret strings containing backslash escapes  */
  7026. /*  Z Z S T R I N G  --  (new name...)  */
  7027. /*
  7028.  Copies result to new string.
  7029.   strips enclosing braces or doublequotes.
  7030.   interprets backslash escapes.
  7031.   returns 0 on success, nonzero on failure.
  7032.   tries to be compatible with MS-DOS Kermit.
  7033.  
  7034.  Syntax of input string:
  7035.   string = chars | "chars" | {chars}
  7036.   chars = (c*e*)*
  7037.   where c = any printable character, ascii 32-126
  7038.   and e = a backslash escape
  7039.   and * means 0 or more repetitions of preceding quantity
  7040.   backslash escape = \operand
  7041.   operand = {number} | number | fname(operand) | v(name) | $(name) | m(name)
  7042.   number = [r]n[n[n]]], i.e. an optional radix code followed by 1-3 digits
  7043.   radix code is oO (octal), xX (hex), dD or none (decimal) (see xxesc()).
  7044. */
  7045.  
  7046. #ifndef NOFRILLS
  7047. int
  7048. yystring(s,s2) char *s; char **s2; {    /* Reverse a string */
  7049.     int x;
  7050.     static char *new;
  7051.     new = *s2;
  7052.     if (!s || !new) return(-1);         /* Watch out for null pointers. */
  7053.     if ((x = (int)strlen(s)) == 0) {    /* Recursion done. */
  7054.         *new = '\0';
  7055.         return(0);
  7056.     }
  7057.     x--;                                /* Otherwise, call self */
  7058.     *new++ = s[x];                      /* to reverse rest of string. */
  7059.     s[x] = 0;
  7060.     return(yystring(s,&new));
  7061. }
  7062. #endif /* NOFRILLS */
  7063.  
  7064. static char ipabuf[16] = { NUL };       /* IP address buffer */
  7065.  
  7066. static char *
  7067. getip(s) char *s; {
  7068.     char c=NUL;                         /* Workers... */
  7069.     int i=0, p=0, d=0;
  7070.     int state = 0;                      /* State of 2-state FSA */
  7071.  
  7072.     while ((c = *s++)) {
  7073.         switch(state) {
  7074.           case 0:                       /* Find first digit */
  7075.             i = 0;                      /* Output buffer index */
  7076.             ipabuf[i] = NUL;            /* Initialize output buffer */
  7077.             p = 0;                      /* Period counter */
  7078.             d = 0;                      /* Digit counter */
  7079.             if (isdigit(c)) {           /* Have first digit */
  7080.                 d = 1;                  /* Count it */
  7081.                 ipabuf[i++] = c;        /* Copy it */
  7082.                 state = 1;              /* Change state */
  7083.             }
  7084.             break;
  7085.  
  7086.           case 1:                       /* In numeric field */
  7087.             if (isdigit(c)) {           /* Have digit */
  7088.                 if (++d > 3)            /* Too many */
  7089.                   state = 0;            /* Start over */
  7090.                 else                    /* Not too many */
  7091.                   ipabuf[i++] = c;      /* Keep it */
  7092.             } else if (c == '.' && p < 3) { /* Have a period */
  7093.                 p++;                    /* Count it */
  7094.                 if (d == 0)             /* Not preceded by a digit */
  7095.                   state = 0;            /* Start over */
  7096.                 else                    /* OK */
  7097.                   ipabuf[i++] = c;      /* Keep it */
  7098.                 d = 0;                  /* Reset digit counter */
  7099.             } else if (p == 3 && d > 0) { /* Not part of address */
  7100.                 ipabuf[i] = NUL;        /* If we have full IP address */
  7101.                 return((char *)ipabuf); /* Return it */
  7102.             } else {                    /* Otherwise */
  7103.                 state = 0;              /* Start over */
  7104.                 ipabuf[0] = NUL;        /* (in case no more chars left) */
  7105.             }
  7106.         }
  7107.     }                                   /* Fall thru at end of string */
  7108.     ipabuf[i] = NUL;                    /* Maybe we have one */
  7109.     return((p == 3 && d > 0) ? (char *)ipabuf : "");
  7110. }
  7111. #endif /* NOSPL */
  7112.  
  7113. /* Date Routines */
  7114.  
  7115. /* Z J D A T E  --  Convert yyyymmdd date to Day of Year */
  7116.  
  7117. static int jdays[12] = {  0,31,59,90,120,151,181,212,243,273,304,334 };
  7118. static int ldays[12] = {  0,31,60,91,121,152,182,213,244,274,305,335 };
  7119. static char zjdbuf[12] = { NUL, NUL };
  7120. /*
  7121.   Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat,
  7122.   statuimus bissextum quarto quoque anno (uti mos est) continuari debere,
  7123.   praeterquam in centesimis annis; qui, quamvis bissextiles antea semper
  7124.   fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps
  7125.   consequentur centesimi non omnes bissextiles sint, sed in quadringentis
  7126.   quibusque annis primi quique tres centesimi sine bissexto transigantur,
  7127.   quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC,
  7128.   MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus
  7129.   intercaletur, februario dies XXIX continente, idemque ordo intermittendi
  7130.   intercalandique bissextum diem in quadringentis quibusque annis perpetuo
  7131.   conservetur.  - Gregorius XIII, Anno Domini MDLXXXII.
  7132. */
  7133. char *
  7134. zjdate(date) char * date; {             /* date = yyyymmdd */
  7135.     char year[5];
  7136.     char month[3];
  7137.     char day[3];
  7138.     int d, m, x, y;
  7139.     int leapday, j;
  7140.     char * time = NULL;
  7141.  
  7142.     if (!date) date = "";               /* Validate arg */
  7143.     x = strlen(date);
  7144.     if (x < 1) return("0");
  7145.     if (x < 8) return("-1");
  7146.     for (x = 0; x < 8; x++)
  7147.       if (!isdigit(date[x]))
  7148.         return("-1");
  7149.  
  7150.     if (date[8]) if (date[9])
  7151.       time = date + 9;
  7152.  
  7153.     year[0] = date[0];                  /* Isolate year */
  7154.     year[1] = date[1];
  7155.     year[2] = date[2];
  7156.     year[3] = date[3];
  7157.     year[4] = '\0';
  7158.  
  7159.     month[0] = date[4];                 /* Month */
  7160.     month[1] = date[5];
  7161.     month[2] = '\0';;
  7162.  
  7163.     day[0] = date[6];                   /* And day */
  7164.     day[1] = date[7];
  7165.     day[2] = '\0';
  7166.  
  7167.     leapday = 0;                        /* Assume no leap day */
  7168.     y = atoi(year);
  7169.     m = atoi(month);
  7170.     d = atoi(day);
  7171.     if (m > 2) {                        /* No Leap day before March */
  7172.         if (y % 4 == 0) {               /* If year is divisible by 4 */
  7173.             leapday = 1;                /* It's a Leap year */
  7174.             if (y % 100 == 0) {         /* Except if divisible by 100 */
  7175.                 if (y % 400 != 0)       /* but not by 400 */
  7176.                   leapday = 0;
  7177.             }
  7178.         }
  7179.     }
  7180.     j = jdays[m - 1] + d + leapday;     /* Day of year */
  7181.     if (time)
  7182.       sprintf(zjdbuf,"%04d%03d %s",y,j,time); /* SAFE */
  7183.     else
  7184.       sprintf(zjdbuf,"%04d%03d",y,j);   /* SAFE */
  7185.     return((char *)zjdbuf);
  7186. }
  7187.  
  7188. static char jzdbuf[32];
  7189.  
  7190. /* J Z D A T E  --  Convert Day of Year to yyyyddmm date */
  7191.  
  7192. char *
  7193. jzdate(date) char * date; {             /* date = yyyyddd */
  7194.     char year[5];                       /* with optional time */
  7195.     char day[4];
  7196.     char * time = NULL, * p;
  7197.     int d, m, x, y;
  7198.     int leapday, j;
  7199.     int * zz;
  7200.  
  7201.     if (!date) date = "";               /* Validate arg */
  7202.     x = strlen(date);
  7203.  
  7204.     debug(F111,"jzdate len",date,x);
  7205.  
  7206.     if (x < 1) return("0");
  7207.     if (x < 7) return("-1");
  7208.     if (x > 8) time = date + 8;
  7209.  
  7210.     for (x = 0; x < 7; x++)
  7211.       if (!isdigit(date[x]))
  7212.         return("-1");
  7213.  
  7214.     year[0] = date[0];                  /* Isolate year */
  7215.     year[1] = date[1];
  7216.     year[2] = date[2];
  7217.     year[3] = date[3];
  7218.     year[4] = '\0';
  7219.  
  7220.     debug(F110,"jzdate year",year,0);
  7221.  
  7222.     day[0] = date[4];                   /* And day */
  7223.     day[1] = date[5];
  7224.     day[2] = date[6];
  7225.     day[3] = '\0';
  7226.  
  7227.     debug(F110,"jzdate day",day,0);
  7228.  
  7229.     j = atoi(day);
  7230.     if (j > 366)
  7231.       return("-1");
  7232.  
  7233.     leapday = 0;                        /* Assume no leap day */
  7234.     y = atoi(year);
  7235.     if (y % 4 == 0) {                   /* If year is divisible by 4 */
  7236.         leapday = 1;                    /* It's a Leap year */
  7237.         if (y % 100 == 0) {             /* Except if divisible by 100 */
  7238.             if (y % 400 != 0)           /* but not by 400 */
  7239.               leapday = 0;
  7240.         }
  7241.     }
  7242.     debug(F101,"jzdate leapday","",leapday);
  7243.     zz = leapday ? ldays : jdays;
  7244.  
  7245.     for (x = 0; x < 11; x++)
  7246.       if (j > zz[x] && j <= zz[x+1])
  7247.         break;
  7248.     m = x + 1;
  7249.  
  7250.     debug(F101,"jzdate m","",m);
  7251.  
  7252.     d = j - zz[x];
  7253.  
  7254.     debug(F101,"jzdate d","",d);
  7255.  
  7256.     if (time)
  7257.       sprintf(jzdbuf,"%04d%02d%02d %s",y,m,d,time); /* SAFE */
  7258.     else
  7259.       sprintf(jzdbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7260.  
  7261.     debug(F101,"jzdate jzdbuf",jzdbuf,0);
  7262.  
  7263.     p = ckcvtdate((char *)jzdbuf, 0);   /* Convert to standard form */
  7264.     ckstrncpy(jzdbuf,p,32);
  7265.     if (!time) jzdbuf[8] = NUL;         /* Remove time if not wanted */
  7266.     return((char *)jzdbuf);
  7267. }
  7268.  
  7269. /* M J D  --  Modified Julian Date */
  7270. /*
  7271.   Call with:
  7272.     Standard-format date-time string: yyyymmdd[ hh:mm:ss].
  7273.     The time, if any, is ignored.
  7274.  
  7275.   Returns:
  7276.     -1L on error, otherwise:
  7277.     The number of days since 17 Nov 1858 as a whole number:
  7278.     16 Nov 1858 = -1, 17 Nov 1858 = 0, 18 Nov 1858 = 1, 19 Nov 1858 = 2, ...
  7279.  
  7280.   The Modified Julian Date is defined by the International Astronomical
  7281.   Union as the true Julian date minus 2400000.5 days.  The true Julian
  7282.   date is the number days since since noon of 1 January 4713 BCE of the
  7283.   Julian proleptic calendar.  Conversions between calendar dates and
  7284.   Julian dates, however, assume Gregorian dating.
  7285. */
  7286. long
  7287. mjd(date) char * date; {
  7288.     char year[5];
  7289.     char month[3];
  7290.     char day[3];
  7291.     int x, a, d, m, y;
  7292.     long z;
  7293.  
  7294.     if (!date) date = "";               /* Validate arg */
  7295.     x = strlen(date);
  7296.     if (x < 1) return(0L);
  7297.     if (x < 8) return(-1L);
  7298.     for (x = 0; x < 8; x++)
  7299.       if (!isdigit(date[x]))
  7300.         return(-1L);
  7301.  
  7302.     year[0] = date[0];                  /* Isolate year */
  7303.     year[1] = date[1];
  7304.     year[2] = date[2];
  7305.     year[3] = date[3];
  7306.     year[4] = '\0';
  7307.  
  7308.     month[0] = date[4];                 /* Month */
  7309.     month[1] = date[5];
  7310.     month[2] = '\0';;
  7311.     m = atoi(month);
  7312.  
  7313.     day[0] = date[6];                   /* And day */
  7314.     day[1] = date[7];
  7315.     day[2] = '\0';
  7316.     d = atoi(day);
  7317.  
  7318.     a = (14-m)/12;                      /* Calculate true Julian date */
  7319.     y = atoi(year) + 4800 - a;
  7320.     m = m + 12 * a - 3;
  7321.     z = d + (long)(306*m+5)/10 + (long)(y*365) + y/4 - y/100 + y/400 - 32045L;
  7322.  
  7323.     z -= 2400001L;                      /* Convert JD to MJD */
  7324.  
  7325.     return(z);
  7326. }
  7327.  
  7328. static char mjd2dbuf[32];
  7329.  
  7330. /*  M J D 2 D A T E  --  Converts MJD to yyyymmdd  */
  7331.  
  7332. char *
  7333. #ifdef CK_ANSIC
  7334. mjd2date(long mjd)
  7335. #else
  7336. mjd2date(mjd) long mjd;
  7337. #endif /* CK_ANSIC */
  7338. /* mjd2date */ {
  7339.     long jd, l, n;
  7340.     int d, m, y;
  7341.     jd = (long)(mjd + 2400001L);
  7342.     l = jd + 68569;
  7343.     n = 4 * l / 146097L;
  7344.     l = l - (146097 * n + 3) / 4;
  7345.     y = 4000 * (l + 1) / 1461001L;
  7346.     l = l - 1461 * y / 4 + 31;
  7347.     m = 80 * l / 2447;
  7348.     d = l - 2447 * m / 80;
  7349.     l = m / 11;
  7350.     m = m + 2 - 12 * l;
  7351.     y = 100 * (n - 49) + y + l;
  7352.     sprintf(mjd2dbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7353.     return((char *)mjd2dbuf);
  7354. }
  7355.  
  7356. #ifndef NOSPL
  7357. static char ** flist = (char **) NULL;  /* File list for \fnextfile() */
  7358. static int flistn = 0;                  /* Number of items in file list */
  7359.  
  7360. /*
  7361.   The function return-value buffer must be global, since fneval() returns a
  7362.   pointer to it.  fneval() is called only by zzstring(), which always copies
  7363.   the result out of this buffer to somewhere else, so it's OK to have only
  7364.   one buffer for this in most cases.  However, since function calls can be
  7365.   nested -- e.g. functions whose arguments are functions, or recursive
  7366.   functions, at some point we should convert this to an array of buffers,
  7367.   indexed by function depth (which might or might not be the same as the
  7368.   "depth" variable).  Also, since function results are potentially quite big,
  7369.   we'd need to allocate and deallocate dynamically as we descend and ascend
  7370.   function depth.  Left for a future release...
  7371. */
  7372. char fnval[FNVALL+2];                   /* Function return value  */
  7373. static int fndepth = 0;                 /* (we don't actually use this yet) */
  7374. int fnsuccess = 1;
  7375. extern int fnerror;
  7376.  
  7377. /* f p f o r m a t  --  Floating-point number nicely formatted.  */
  7378. /*
  7379.    Returns results from a circular 1K buffer.
  7380.    Don't count on too many results remaining available at once; it could
  7381.    be anywhere from 5 to maybe 100, depending on the sizes of the results.
  7382. */
  7383. #ifdef CKFLOAT
  7384. #define FPFMTSIZ 1024
  7385. static char fpfmtbuf[FPFMTSIZ] = { NUL, NUL };
  7386. static int fpfbufpos = 0;               /* (why was this char before?) */
  7387.  
  7388. char *
  7389. fpformat(fpresult,places,round) CKFLOAT fpresult; int places, round; {
  7390.     char fbuf[16];                      /* For creating printf format */
  7391.     int nines = 0, sign = 0, x, y, i, j, size = 0;
  7392.     char * buf;
  7393.     CKFLOAT ftmp;
  7394.  
  7395.     x = places ? places : (fp_digits ? fp_digits : 6);
  7396.  
  7397.     debug(F101,"fpformat fpresult","",fpresult);
  7398.     debug(F101,"fpformat places","",places);
  7399.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7400.  
  7401.     ftmp = fpresult;
  7402.     if (ftmp < 0.0) ftmp = 0.0 - fpresult;
  7403.  
  7404. #ifdef FNFLOAT
  7405.     if (!fp_rounding &&                 /* If printf doesn't round, */
  7406.         (places > 0 ||                  /* round result to decimal places. */
  7407.          (places == 0 && round)))
  7408.       fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  7409.     y = (ftmp == 0.0) ? 1 : (int)log10(ftmp);
  7410.     size = y + x + 3;                   /* Estimated length of result */
  7411.     if (fpresult < 0.0) size++;
  7412. #else
  7413.     size = 200;                         /* No way to estimate, be generous */
  7414. #endif /* FNFLOAT */
  7415.  
  7416.     debug(F101,"fpformat size","",size);
  7417.  
  7418.     if (fpfbufpos > (FPFMTSIZ - size))  /* Wrap around if necessary */
  7419.       fpfbufpos = 0;
  7420.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7421.  
  7422.     buf = &fpfmtbuf[fpfbufpos];
  7423.  
  7424.     if (places > 0) {                   /* If places specified */
  7425.         /* use specified places to write given number of digits */
  7426.         sprintf(fbuf,"%%0.%df",places); /* SAFE */
  7427.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7428.     } else {                            /* Otherwise... */
  7429.         /* Go for max precision */
  7430.         sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  7431.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7432.     }
  7433.     if (buf[0] == '-') sign = 1;
  7434.     debug(F111,"fpresult 1 errno",buf,errno); /* Check for over/underflow */
  7435.     debug(F111,"fpresult 1 fpfbufpos",buf,fpfbufpos);
  7436.     /* Give requested decimal places */
  7437.     for (i = sign; i < FPFMTSIZ && buf[i]; i++) {
  7438.         if (buf[i] == '.')              /* First find the decimal point */
  7439.           break;
  7440.         else if (i > fp_digits + sign - 1) /* replacing garbage */
  7441.           buf[i] = '0';                 /* digits with 0... */
  7442.     }
  7443.     if (buf[i] == '.') {                /* Have decimal point */
  7444.         int gotend = 0;
  7445.         /* places < 0 so truncate fraction */
  7446.         if (places < 0 || (places == 0 && round)) {
  7447.             buf[i] = NUL;
  7448.         } else if (places > 0) {        /* d > 0 so this many decimal places */
  7449.             i++;                           /* First digit after decimal */
  7450.             for (j = 0; j < places; j++) { /* Truncate after d decimal */
  7451.                 if (!buf[j+i])        /* places or extend to d  */
  7452.                   gotend = 1;              /* decimal places. */
  7453.                 if (gotend || j+i+sign > fp_digits)
  7454.                   buf[j+i] = '0';
  7455.             }
  7456.             buf[j+i] = NUL;
  7457.         } else {                        /* places == 0 so Do The Right Thing */
  7458.             for (j = (int)strlen(buf) - 1; j > i+1; j--) {
  7459.                 if ((j - sign) > fp_digits)
  7460.                   buf[j] = '0';
  7461.                 if (buf[j] == '0')
  7462.                   buf[j] = NUL; /* Strip useless trailing 0's. */
  7463.                 else
  7464.                   break;
  7465.             }
  7466.         }
  7467.     }
  7468.     fpfmtbuf[FPFMTSIZ-1] = NUL;
  7469.     j = strlen(buf);
  7470.     sign = 0;
  7471.     for (i = j-1; i >= 0; i--) {
  7472.         if (buf[i] == '9')
  7473.           nines++;
  7474.         else
  7475.           break;
  7476.     }
  7477.     /* Do something about xx.xx99999999... */
  7478.     if (nines > 5) {
  7479.         if (isdigit(buf[i]) && i < FPFMTSIZ - 2) {
  7480.             buf[i] = buf[i] + 1;
  7481.             buf[i+1] = '0';
  7482.             buf[i+2] = '\0';
  7483.         }
  7484.     }
  7485.     if (!strncmp(buf,"-0.0",FPFMTSIZ))
  7486.       ckstrncpy(buf,"0.0",FPFMTSIZ);
  7487.     fpfbufpos += (int)strlen(buf) + 1;
  7488.     return((char *)buf);
  7489. }
  7490. #endif /* CKFLOAT */
  7491.  
  7492. static VOID
  7493. evalerr(fn) char * fn; {
  7494.     if (fndiags) {
  7495.         if (divbyzero)
  7496.           ckmakmsg(fnval,FNVALL,"<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  7497.         else
  7498.           ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  7499.     }
  7500. }
  7501.  
  7502. char *
  7503. dokwval(s,sep) char * s, sep; {
  7504.     char c = '\0', * p, * kw = NULL, * vp = NULL;
  7505.     int x;
  7506.     if (!s) return("0");
  7507.     if (!*s) return("0");
  7508.     debug(F110,"kwval arg",s,0);
  7509.     debug(F110,"kwval sep",ckctoa(sep),0);
  7510.     p = (char *)malloc((int)strlen(s)+1);
  7511.     if (!p) return("0");
  7512.     strcpy(p,s);                        /* SAFE */
  7513.     s = p;
  7514.     while (*s < '!' && *s > '\0')       /* Get first nonblank */
  7515.       s++;
  7516.     if (!*s) return("0");
  7517.     if (*s == sep) return("0");
  7518.     kw = s;                             /* Keyword */
  7519.     while (*s > ' ') {
  7520.         if (*s == sep) {                /* keyword=... */
  7521.             c = *s;
  7522.             break;
  7523.         }
  7524.         s++;
  7525.     }
  7526.     *s++ = NUL;                         /* Terminate keyword */
  7527.     while (*s < '!' && *s > '\0')       /* Skip blanks */
  7528.       s++;
  7529.     if (!c && *s == sep) {
  7530.         c = *s++;                       /* Have separator */
  7531.         while (*s < '!' && *s > '\0')   /* Skip blanks */
  7532.           s++;
  7533.     }
  7534.     if (c) {
  7535.         vp = s;
  7536.         while (*s > ' ')                /* Skip to end */
  7537.           s++;
  7538.         *s = NUL;                       /* Terminate value */
  7539.     }
  7540.     debug(F110,"kwval c",ckctoa(c),0);
  7541.     debug(F110,"kwval keyword",kw,0);
  7542.     debug(F110,"kwval value",vp,0);
  7543.     x = c ? addmac(kw,vp) : -1;
  7544.     free(p);
  7545.     return((x < 0) ? "0" : "1");
  7546. }
  7547.  
  7548.  
  7549. static char *                           /* Evaluate builtin functions */
  7550. fneval(fn,argp,argn,xp) char *fn, *argp[]; int argn; char * xp; {
  7551.     int i=0, j=0, k=0, len1=0, len2=0, len3=0, n=0, t=0, x=0, y=0;
  7552.     int cx, failed = 0;                 /* Return code, 0 = ok */
  7553.     long z = 0L;
  7554.     char *bp[FNARGS + 1];               /* Pointers to malloc'd strings */
  7555.     char c = NUL;
  7556.     char *p = NULL, *s = NULL;
  7557.     char *val1 = NULL, *val2 = NULL;    /* Pointers to numeric string values */
  7558.  
  7559. #ifdef RECURSIVE
  7560.     int rsave = recursive;
  7561. #endif /* RECURSIVE */
  7562. #ifdef OS2
  7563.     int zsave = zxpn;
  7564. #endif /* OS2 */
  7565.  
  7566.     if (!fn) fn = "";                   /* Protect against null pointers */
  7567.     if (!*fn) return("");
  7568.  
  7569.     for (i = 0; i < FNARGS; i++)        /* Initialize argument pointers */
  7570.       bp[i] = NULL;
  7571. /*
  7572.   IMPORTANT: Note that argn is not an accurate count of the number of
  7573.   arguments.  We can't really tell if an argument is null until after we
  7574.   execute the code below.  So argn is really the maximum number of arguments
  7575.   we might have.  Argn should always be at least 1, even if the function is
  7576.   called with empty parentheses (but don't count on it).
  7577. */
  7578.     debug(F111,"fneval",fn,argn);
  7579.     debug(F110,"fneval",argp[0],0);
  7580.     if (argn > FNARGS)                  /* Discard excess arguments */
  7581.       argn = FNARGS;
  7582.  
  7583.     fndepth++;
  7584.     debug(F101,"fneval fndepth","",fndepth);
  7585.     p = fnval;
  7586.     fnval[0] = NUL;
  7587.     y = lookup(fnctab,fn,nfuncs,&x);    /* Look up the function name */
  7588.     cx = y;                             /* Because y is too generic... */
  7589.     if (cx < 0) {                        /* Not found */
  7590.         failed = 1;
  7591.         if (fndiags) {                  /* FUNCTION DIAGNOSTIC ON */
  7592.             int x;
  7593.             x = strlen(fn);
  7594.             /* The following sprintf's are safe */
  7595.             switch (cx) {
  7596.               case -1:
  7597.                 if (x + 32 < FNVALL)
  7598.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION:\\f%s()>",fn);
  7599.                 else
  7600.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION>");
  7601.                 break;
  7602.               case -2:
  7603.                 if (x + 26 < FNVALL)
  7604.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS:\\f%s()>",fn);
  7605.                 else
  7606.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS>");
  7607.                 break;
  7608.               case -3:
  7609.                 sprintf(fnval,"<ERROR:FUNCTION_NAME_MISSING:\\f()>");
  7610.                 break;
  7611.               default:
  7612.                 if (x + 26 < FNVALL)
  7613.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE:\\f%s()>",fn);
  7614.                 else
  7615.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE>");
  7616.                 break;
  7617.             }
  7618.         }
  7619.         goto fnend;                     /* Always leave via common exit */
  7620.     }
  7621.     fn = fnctab[x].kwd;                 /* Full name of function */
  7622.  
  7623.     if (argn < 0) {
  7624.         failed = 1;
  7625.         p = fnval;
  7626.         if (fndiags)
  7627.           sprintf(fnval,"<ERROR:MISSING_ARG:\\f%s()>",fn);
  7628.         goto fnend;
  7629.     }
  7630.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7631.         debug(F010,"flit",xp,0);
  7632.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7633.         goto fnend;
  7634.     }
  7635.  
  7636. #ifdef DEBUG
  7637.     if (deblog) {
  7638.         int j;
  7639.         for (j = 0; j < argn; j++)
  7640.           debug(F111,"fneval arg",argp[j],j);
  7641.     }
  7642. #endif /* DEBUG */
  7643.     for (j = argn-1; j >= 0; j--) {     /* Uncount empty trailing args */
  7644.         if (!argp[j])
  7645.           argn--;
  7646.         else if (!*(argp[j]))
  7647.           argn--;
  7648.         else break;
  7649.     }
  7650.     debug(F111,"fneval argn",fn,argn);
  7651. /*
  7652.   \fliteral() and \fcontents() are special functions that do not evaluate
  7653.   their arguments, and are treated specially here.  After these come the
  7654.   functions whose arguments are evaluated in the normal way.
  7655. */
  7656. #ifdef COMMENT
  7657.     /* (moved up) */
  7658.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7659.         debug(F110,"flit",xp,0);
  7660.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7661.         goto fnend;
  7662.     }
  7663. #endif /* COMMENT */
  7664.     if (cx == FN_CON) {                 /* Contents of variable, unexpanded. */
  7665.         char c;
  7666.         if (!(p = argp[0]) || !*p) {
  7667.             failed = 1;
  7668.             p = fnval;
  7669.             if (fndiags)
  7670.               sprintf(fnval,"<ERROR:MISSING_ARG:\\fcontents()>");
  7671.             goto fnend;
  7672.         }
  7673.         p = brstrip(p);
  7674.         if (*p == CMDQ) p++;
  7675.         if ((c = *p) == '%') {          /* Scalar variable. */
  7676.             c = *++p;                   /* Get ID character. */
  7677.             p = "";                     /* Assume definition is empty */
  7678.             if (!c) {                   /* Double paranoia */
  7679.                 failed = 1;
  7680.                 p = fnval;
  7681.                 if (fndiags)
  7682.                   sprintf(fnval,"<ERROR:ARG_BAD_VARIABLE:\\fcontents()>");
  7683.                 goto fnend;
  7684.             }
  7685.             if (c >= '0' && c <= '9') { /* Digit for macro arg */
  7686.                 if (maclvl < 0)         /* Digit variables are global */
  7687.                   p = g_var[c];         /* if no macro is active */
  7688.                 else                    /* otherwise */
  7689.                   p = m_arg[maclvl][c - '0']; /* they're on the stack */
  7690.             } else if (c == '*') {
  7691. #ifdef COMMENT
  7692.                 p = (maclvl > -1) ? m_line[maclvl] : topline;
  7693.                 if (!p) p = "";
  7694. #else
  7695.                 int nx = FNVALL;
  7696.                 char * sx = fnval;
  7697.                 p = fnval;
  7698. #ifdef COMMENT
  7699.                 if (cmdsrc() == 0 && topline)
  7700.                   p = topline;
  7701.                 else
  7702. #endif /* COMMENT */
  7703.                   if (zzstring("\\fjoin(&_[],{ },1)",&sx,&nx) < 0) {
  7704.                     failed = 1;
  7705.                     p = fnval;
  7706.                     if (fndiags)
  7707.                       sprintf(fnval,"<ERROR:OVERFLOW:\\fcontents()>");
  7708.                 }
  7709. #endif /* COMMENT */
  7710.             } else {
  7711.                 if (isupper(c)) c -= ('a'-'A');
  7712.                 p = g_var[c];           /* Letter for global variable */
  7713.             }
  7714.             if (!p) p = "";
  7715.             goto fnend;
  7716.         } else if (c == '&') {          /* Array reference. */
  7717.             int vbi, d;
  7718.             if (arraynam(p,&vbi,&d) < 0) { /* Get name and subscript */
  7719.                 failed = 1;
  7720.                 p = fnval;
  7721.                 if (fndiags)
  7722.                   sprintf(fnval,"<ERROR:ARG_BAD_ARRAY:\\fcontents()>");
  7723.                 goto fnend;
  7724.             }
  7725.             if (chkarray(vbi,d) > 0) {  /* Array is declared? */
  7726.                 vbi -= ARRAYBASE;       /* Convert name to index */
  7727.                 if (a_dim[vbi] >= d) {  /* If subscript in range */
  7728.                     char **ap;
  7729.                     ap = a_ptr[vbi];    /* get data pointer */
  7730.                     if (ap) {           /* and if there is one */
  7731.                         p = ap[d];
  7732.                         goto fnend;
  7733.                     }
  7734.                 }
  7735.             } else {
  7736.                 failed = 1;
  7737.                 p = fnval;
  7738.                 if (fndiags)
  7739.                   sprintf(fnval,"<ERROR:ARG_NOT_ARRAY:\\fcontents()>");
  7740.                 goto fnend;
  7741.             }
  7742.         } else {
  7743.             failed = 1;
  7744.             p = fnval;
  7745.             if (fndiags)
  7746.               sprintf(fnval,"<ERROR:ARG_NOT_VARIABLE:\\fcontents()>");
  7747.             goto fnend;
  7748.         }
  7749.     }
  7750.     p = fnval;                          /* Default result pointer */
  7751.     fnval[0] = NUL;                     /* Default result = empty string */
  7752.  
  7753.  
  7754.     for (i = 0; i < argn; i++) {        /* Loop to expand each argument */
  7755.         n = MAXARGLEN;                  /* Allow plenty of space */
  7756.         bp[i] = s = malloc(n+1);        /* Allocate space for this argument */
  7757.         if (bp[i] == NULL) {            /* Handle failure to get space */
  7758.             failed = 1;
  7759.             if (fndiags)
  7760.               ckmakmsg(fnval,FNVALL,"<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  7761.             goto fnend;
  7762.         }
  7763.         p = argp[i] ? argp[i] : "";     /* Point to this argument */
  7764.  
  7765. /*
  7766.   Trim leading and trailing spaces from the original argument, before
  7767.   evaluation.  This code new to edit 184.  Fixed in edit 199 to trim
  7768.   blanks BEFORE stripping braces.
  7769.  
  7770. */
  7771.         {
  7772.             int x, j;
  7773.             x = strlen(p);
  7774.             j = x - 1;                  /* Trim trailing whitespace */
  7775.             while (j > 0 && (*(p + j) == SP || *(p + j) == HT))
  7776.               *(p + j--) = NUL;
  7777.             while (*p == SP || *p == HT) /* Strip leading whitespace */
  7778.               p++;
  7779.             x = strlen(p);
  7780.             if (*p == '{' && *(p+x-1) == '}') { /* NOW strip braces */
  7781.                 p[x-1] = NUL;
  7782.                 p++;
  7783.                 x -= 2;
  7784.             }
  7785.         }
  7786.  
  7787. /* Now evaluate the argument */
  7788.  
  7789.         debug(F111,"fneval calling zzstring",p,n);
  7790.         t = zzstring(p,&s,&n);          /* Expand arg into new space */
  7791.         debug(F101,"fneval zzstring","",t);
  7792.         debug(F101,"fneval zzstring","",n);
  7793.         if (t < 0) {
  7794.             debug(F101,"fneval zzstring fails, arg","",i);
  7795.             failed = 1;
  7796.             if (fndiags) {
  7797.                 if (n == 0)
  7798.                   ckmakmsg(fnval,FNVALL,
  7799.                            "<ERROR:ARG_TOO_LONG:\\f",fn,"()>",NULL);
  7800.                 else
  7801.                   ckmakmsg(fnval,FNVALL,
  7802.                            "<ERROR:ARG_EVAL_FAILURE:\\f",fn,"()>",NULL);
  7803.             }
  7804.             goto fnend;
  7805.         }
  7806.         debug(F111,"fneval arg",bp[i],i);
  7807.     }
  7808.  
  7809. #ifdef DEBUG
  7810.     if (deblog) {
  7811.         int j;
  7812.         for (j = 0; j < argn; j++) {
  7813.             debug(F111,"fneval arg post eval",argp[j],j);
  7814.             debug(F111,"fneval evaluated arg",bp[j],j);
  7815.         }
  7816.     }
  7817. #endif /* DEBUG */
  7818. /*
  7819.   From this point on, bp[0..argn-1] are not NULL and all must be freed
  7820.   before returning.
  7821. */
  7822.     if (argn < 1) {                     /* Catch required args missing */
  7823.         switch (cx) {
  7824.           case FN_DEF:
  7825.           case FN_EVA:
  7826.           case FN_EXE:
  7827.           case FN_CHR:
  7828.           case FN_COD:
  7829.           case FN_MAX:
  7830.           case FN_MIN:
  7831.           case FN_MOD:
  7832.           case FN_FD:
  7833.           case FN_FS:
  7834.           case FN_TOD:
  7835.           case FN_FFN:
  7836.           case FN_BSN:
  7837.           case FN_RAW:
  7838.           case FN_CMD:
  7839.           case FN_2HEX:
  7840.           case FN_2OCT:
  7841.           case FN_DNAM:
  7842. #ifdef FN_ERRMSG
  7843.           case FN_ERRMSG:
  7844. #endif /* FN_ERRMSG */
  7845. #ifdef CK_KERBEROS
  7846.           case FN_KRB_TK:
  7847.           case FN_KRB_NX:
  7848.           case FN_KRB_IV:
  7849.           case FN_KRB_TT:
  7850.           case FN_KRB_FG:
  7851. #endif /* CK_KERBEROS */
  7852.           case FN_MJD2:
  7853.           case FN_N2TIM:
  7854.           case FN_DIM:
  7855.           case FN_DATEJ:
  7856.           case FN_PNCVT:
  7857.           case FN_PERM:
  7858.           case FN_ALOOK:
  7859.           case FN_TLOOK:
  7860.           case FN_ABS:
  7861.           case FN_AADUMP:
  7862.           case FN_JOIN:
  7863. #ifdef CKFLOAT
  7864.           case FN_FPABS:
  7865.           case FN_FPEXP:
  7866.           case FN_FPLOG:
  7867.           case FN_FPLN:
  7868.           case FN_FPMOD:
  7869.           case FN_FPSQR:
  7870.           case FN_FPADD:
  7871.           case FN_FPDIV:
  7872.           case FN_FPMUL:
  7873.           case FN_FPPOW:
  7874.           case FN_FPSUB:
  7875.           case FN_FPINT:
  7876.           case FN_FPROU:
  7877.           case FN_FPSIN:
  7878.           case FN_FPCOS:
  7879.           case FN_FPTAN:
  7880. #endif /* CKFLOAT */
  7881. #ifdef TCPSOCKET
  7882.           case FN_HSTADD:
  7883.           case FN_HSTNAM:
  7884. #endif /* TCPSOCKET */
  7885.           case FN_DELSEC:
  7886.           case FN_KWVAL:
  7887.           case FN_SLEEP:
  7888.           case FN_MSLEEP:
  7889.             failed = 1;
  7890.             p = fnval;
  7891.             if (fndiags)
  7892.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  7893.             goto fnend;
  7894.         }
  7895.     }
  7896.     p = fnval;                          /* Reset these again. */
  7897.     fnval[0] = NUL;
  7898.  
  7899.     switch (cx) {                       /* Do function on expanded args. */
  7900. #ifdef TCPSOCKET
  7901.       case FN_HSTADD:
  7902.         p = ckaddr2name(bp[0]);
  7903.         goto fnend;
  7904.       case FN_HSTNAM:
  7905.         p = ckname2addr(bp[0]);
  7906.         goto fnend;
  7907. #endif /* TCPSOCKET */
  7908.  
  7909.       case FN_DEF:                      /* \fdefinition(arg1) */
  7910.         k = mxlook(mactab,bp[0],nmac);
  7911.         p = (k > -1) ? mactab[k].mval : "";
  7912.         goto fnend;
  7913.  
  7914.       case FN_EVA:                      /* \fevaluate(arg1) */
  7915.         p = *(bp[0]) ? evalx(bp[0]) : "";
  7916.         if (!*p && fndiags) {
  7917.             failed = 1;
  7918.             p = fnval;
  7919.             evalerr(fn);
  7920.         }
  7921.         goto fnend;
  7922.  
  7923.       case FN_EXE:                      /* \fexecute(arg1) */
  7924.         j = (int)strlen(s = bp[0]);     /* Length of macro invocation */
  7925.         p = "";                         /* Initialize return value to null */
  7926.         if (j) {                        /* If there is a macro to execute */
  7927.             while (*s == SP) s++,j--;   /* strip leading spaces */
  7928.             p = s;                      /* remember beginning of macro name */
  7929.             for (i = 0; i < j; i++) {   /* find end of macro name */
  7930.                 if (*s == SP)
  7931.                   break;
  7932.                 s++;
  7933.             }
  7934.             if (*s == SP)       {       /* if there was a space after */
  7935.                 *s++ = NUL;             /* terminate the macro name */
  7936.                 while (*s == SP) s++;   /* skip past any extra spaces */
  7937.             } else
  7938.               s = "";                   /* maybe there are no arguments */
  7939.             if (p && *p) {
  7940.                 k = mlook(mactab,p,nmac); /* Look up the macro name */
  7941.                 debug(F111,"fexec mlook",p,k);
  7942.             } else
  7943.               k = -1;
  7944.             if (k < 0) {
  7945.                 char * p2 = p;
  7946.                 failed = 1;
  7947.                 p = fnval;
  7948.                 if (fndiags)
  7949.                   ckmakxmsg(fnval,FNVALL,
  7950.                             "<ERROR:NO_SUCH_MACRO:\\f",fn,"(",p2,")>",
  7951.                             NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  7952.                 goto fnend;
  7953.             }
  7954. /*
  7955.   This is just a WEE bit dangerous because we are copying up to 9 arguments
  7956.   into the space reserved for one.  It won't overrun the buffer, but if there
  7957.   are lots of long arguments we might lose some.  The other problem is that if
  7958.   the macro has more than 3 arguments, the 4th through last are all
  7959.   concatenated onto the third.  (The workaround is to use spaces rather than
  7960.   commas to separate them.)  Leaving it like this to avoid having to allocate
  7961.   tons more buffers.
  7962. */
  7963.             if (argn > 1) {             /* Commas used instead of spaces */
  7964.                 int i;
  7965.                 char *p = bp[0];        /* Reuse this space */
  7966.                 *p = NUL;               /* Make into dodo() arg list */
  7967.                 for (i = 1; i < argn; i++) {
  7968.                     strncat(p,bp[i],MAXARGLEN);
  7969.                     strncat(p," ",MAXARGLEN);
  7970.                 }
  7971.                 s = bp[0];              /* Point to new list */
  7972.             }
  7973.             p = "";                     /* Initialize return value */
  7974.             if (k >= 0) {               /* If macro found in table */
  7975.                 /* Go set it up (like DO cmd) */
  7976.                 if ((j = dodo(k,s,cmdstk[cmdlvl].ccflgs)) > 0) {
  7977.                     if (cmpush() > -1) { /* Push command parser state */
  7978.                         extern int ifc;
  7979.                         int ifcsav = ifc; /* Push IF condition on stack */
  7980.                         k = parser(1);  /* Call parser to execute the macro */
  7981.                         cmpop();        /* Pop command parser */
  7982.                         ifc = ifcsav;   /* Restore IF condition */
  7983.                         if (k == 0) {   /* No errors, ignore action cmds. */
  7984.                             p = mrval[maclvl+1]; /* If OK, set return value. */
  7985.                             if (p == NULL) p = "";
  7986.                         }
  7987.                     } else {            /* Can't push any more */
  7988.                         debug(F100,"zzstring fneval fexec failure","",0);
  7989.                         printf("\n?\\fexec() too deeply nested\n");
  7990.                         while (cmpop() > -1) ;
  7991.                         p = "";
  7992.                     }
  7993.                 }
  7994.             }
  7995.         }
  7996.         debug(F110,"zzstring fneval fexecute final p",p,0);
  7997.         goto fnend;
  7998.  
  7999. #ifdef RECURSIVE
  8000.       case FN_RDIR:                     /* \frdir..() - Recursive dir count */
  8001.       case FN_RFIL:                     /* \frfiles() - Recursive file count */
  8002.         /* recursive = 2; */            /* fall thru... */
  8003. #endif /* RECURSIVE */
  8004.       case FN_FC:                       /* \ffiles() - File count. */
  8005.       case FN_DIR: {                    /* \ffdir.() - Directory count. */
  8006.           char abuf[16], *s;
  8007.           char ** ap = NULL;
  8008.           int x, xflags = 0;
  8009.           if (matchdot)
  8010.             xflags |= ZX_MATCHDOT;
  8011.           if (cx == FN_RDIR || cx == FN_RFIL) {
  8012.               xflags |= ZX_RECURSE;
  8013. #ifdef CKSYMLINK
  8014.               /* Recursive - don't follow symlinks */
  8015.               xflags |= ZX_NOLINKS;
  8016. #endif /* CKSYMLINK */
  8017.           }
  8018.           failed = 0;
  8019.           if (argn < 1) {
  8020.               p = "0";
  8021.               goto fnend;
  8022.           }
  8023.           if (cx == FN_DIR || cx == FN_RDIR) { /* Only list directories */
  8024.               xflags |= ZX_DIRONLY;
  8025. #ifdef OS2
  8026.               zxpn = 1;                 /* Use the alternate list */
  8027. #endif /* OS2 */
  8028.           } else {                      /* List only files */
  8029.               xflags |= ZX_FILONLY;
  8030. #ifdef OS2
  8031.               zxpn = 1;                 /* Use the alternate list */
  8032. #endif /* OS2 */
  8033.           }
  8034.           if (*(bp[0])) {
  8035.               k = nzxpand(bp[0],xflags);
  8036.               if (k < 0) k = 0;
  8037.               sprintf(fnval,"%d",k);    /* SAFE */
  8038.               p = fnval;
  8039.           } else
  8040.             p = "0";
  8041.  
  8042.           if (argn > 1) {               /* Assign list to array */
  8043.               fnval[0] = NUL;           /* Initial return value */
  8044.               ckstrncpy(abuf,bp[1],16); /* Get array reference */
  8045.               s = abuf;
  8046.               if (*s == CMDQ) s++;
  8047.               failed = 1;               /* Assume it's bad */
  8048.               p = fnval;                /* Point to result */
  8049.               if (fndiags)              /* Default is this error message */
  8050.                 ckmakmsg(fnval,FNVALL,
  8051.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  8052.               if (s[0] != '&')          /* "Address" of array */
  8053.                 goto fnend;
  8054.               if (s[2])
  8055.                 if (s[2] != '[' || s[3] != ']')
  8056.                   goto fnend;
  8057.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  8058.                 s[1] += 32;
  8059.               if ((x = dclarray(s[1],k)) < 0) /* File list plus count */
  8060.                 goto fnend;
  8061.               failed = 0;               /* Unset failure flag */
  8062.               ap = a_ptr[x];            /* Point to array we just declared */
  8063.               sprintf(fnval,"%d",k);    /* SAFE */
  8064.           }
  8065. #ifdef OS2
  8066.           if (ap) {                     /* We are making an array */
  8067.               int i;
  8068.               char tmp[16];
  8069.               ap[0] = NULL;             /* Containing number of files    */
  8070.               makestr(&(ap[0]),ckitoa(k));
  8071.  
  8072.               ckstrncpy(tmp,fnval,16);  /* Save return value */
  8073.  
  8074.               for (i = 1; i <= k; i++) { /* Fill it */
  8075.                   ap[i] = NULL;
  8076.                   znext(fnval);         /* Next filename */
  8077.                   if (!*fnval)          /* No more, done */
  8078.                     break;              /* In case a premature end */
  8079.                   makestr(&(ap[i]),fnval);
  8080.               }
  8081. #ifdef ZXREWIND
  8082.               k = zxrewind();           /* Reset the file expansion */
  8083. #else
  8084.               k = nzxpand(bp[0],xflags);
  8085. #endif /* ZXREWIND */
  8086.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8087.           }
  8088. #else /* OS2 */
  8089.           {                             /* Make copies of the list */
  8090.               int i; char tmp[16];
  8091.               if (flist) {              /* Free old file list, if any */
  8092.                   for (i = 0; flist[i]; i++) { /* and each string */
  8093.                       free(flist[i]);
  8094.                       flist[i] = NULL;
  8095.                   }
  8096.                   free((char *)flist);
  8097.               }
  8098.               ckstrncpy(tmp,fnval,16);  /* Save our return value */
  8099.               flist = (char **) malloc((k+1) * sizeof(char *)); /* New array */
  8100.               if (flist) {
  8101.                   for (i = 0; i <= k; i++) { /* Fill it */
  8102.                       flist[i] = NULL;
  8103.                       znext(fnval);     /* Next filename */
  8104.                       if (!*fnval)      /* No more, done */
  8105.                         break;
  8106.                       makestr(&(flist[i]),fnval);
  8107.                   }
  8108.                   if (ap) {             /* If array pointer given */
  8109.                       ap[0] = NULL;
  8110.                       makestr(&(ap[0]),ckitoa(k));
  8111.                       for (i = 0; i < k; i++) { /* Copy file list to array */
  8112.                           ap[i+1] = NULL;
  8113.                           makestr(&(ap[i+1]),flist[i]);
  8114.                       }
  8115.                   }
  8116.               }
  8117.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8118.               flistn = 0;               /* Reset global list pointer */
  8119.           }
  8120. #endif /* OS2 */
  8121. #ifdef RECURSIVE
  8122.           recursive = rsave;
  8123. #endif /* RECURSIVE */
  8124. #ifdef OS2
  8125.           zxpn = zsave;
  8126. #endif /* OS2 */
  8127.       }
  8128.       goto fnend;
  8129.  
  8130.       case FN_FIL:                      /* \fnextfile() - Next file in list. */
  8131.         p = fnval;                      /* (no args) */
  8132.         *p = NUL;
  8133. #ifdef OS2
  8134.         zxpn = 1;                       /* OS/2 - use the alternate list */
  8135.         znext(p);                       /* Call system-dependent function */
  8136.         zxpn = zsave;                   /* Restore original list */
  8137. #else
  8138.         if (flist)                      /* Others, use our own list. */
  8139.           if (flist[flistn])
  8140.             p = flist[flistn++];
  8141. #endif /* OS2 */
  8142.         goto fnend;
  8143.  
  8144.     } /* Break up big switch... */
  8145.  
  8146.     switch (cx) {
  8147.       case FN_IND:                      /* \findex(s1,s2,start) */
  8148.       case FN_RIX:                      /* \frindex(s1,s2,start) */
  8149.       case FN_SEARCH:                   /* \fsearch(pat,string,start) */
  8150.       case FN_RSEARCH: {                /* \frsearch(pat,string,start) */
  8151.         int i = 0, right = 0, search = 0;
  8152.         right = (cx == FN_RIX || cx == FN_RSEARCH);
  8153.         search = (cx == FN_SEARCH || cx == FN_RSEARCH);
  8154.         p = "0";
  8155.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8156.             int start = 0;
  8157.             char * pat = NULL;
  8158.             len1 = (int)strlen(pat = bp[0]); /* length of string to look for */
  8159.             len2 = (int)strlen(s = bp[1]); /* length of string to look in */
  8160.             if (len1 < 1 || len2 < 1)   /* Watch out for empty strings */
  8161.               goto fnend;
  8162.             start = right ? -1 : 0;     /* Default starting position */
  8163.             if (argn > 2) {
  8164.                 val1 = *(bp[2]) ? evalx(bp[2]) : "1";
  8165.                 if (chknum(val1)) {
  8166.                     int t;
  8167.                     t = atoi(val1);
  8168.                     if (!search) {      /* Index or Rindex */
  8169.                         j = len2 - len1; /* Length difference */
  8170.                         t--;             /* Convert position to 0-based */
  8171.                         if (t < 0) t = 0;
  8172.                         start = t;
  8173.                         if (!right && start < 0) start = 0;
  8174.                     } else {            /* Search or Rsearch */
  8175.                         int x;
  8176.                         if (t < 0) t = 0;
  8177.                         if (right) {    /* Right to left */
  8178.                             if (t > len2) t = len2;
  8179.                             start = len2 - t - 1;
  8180.                             if (start < 0)
  8181.                               goto fnend;
  8182.                             x = len2 - t;
  8183.                             s[x] = NUL;
  8184.                         } else {        /* Left to right */
  8185.                             start = t - 1;
  8186.                             if (start < 0) start = 0;
  8187.                             if (start >= len2)
  8188.                               goto fnend;
  8189.                         }
  8190.                     }
  8191.                 } else {
  8192.                     failed = 1;
  8193.                     evalerr(fn);
  8194.                     p = fnval;
  8195.                     goto fnend;
  8196.                 }
  8197.             }
  8198.             if (search) {               /* \fsearch() or \frsearch() */
  8199.                 if (right && pat[0] == '^') {
  8200.                     right = 0;
  8201.                     start = 0;
  8202.                 }
  8203.                 if (right) {
  8204.                     if (start < 0) start = len2 - 1;
  8205.                     for (i = start;
  8206.                          i >= 0 && !ckmatch(pat,s+i,inpcas[cmdlvl],1+4);
  8207.                          i--) ;
  8208.                     if (i < 0) i = 0; else i++;
  8209.                 } else {
  8210.                     i = ckmatch(pat,&s[start],inpcas[cmdlvl],1+4);
  8211.                     if (start > 0) i += start;
  8212.                 }
  8213.             } else {
  8214.                 i = ckindex(pat,bp[1],start,right,inpcas[cmdlvl]);
  8215.             }
  8216.             sprintf(fnval,"%d",i);      /* SAFE */
  8217.             p = fnval;
  8218.         }
  8219.         goto fnend;
  8220.       }
  8221.  
  8222.       case FN_RPL:                      /* \freplace(s1,s2,s3) */
  8223.       /*
  8224.         s = bp[0] = source string
  8225.             bp[1] = match string
  8226.             bp[2] = replacement string
  8227.             bp[3] = which occurrence (default = all);
  8228.         p = fnval = destination (result) string
  8229.       */
  8230.         if (argn < 1)                   /* Nothing */
  8231.           goto fnend;
  8232.         if (argn < 2) {                 /* Only works if we have 2 or 3 args */
  8233.             ckstrncpy(p,bp[0],FNVALL);
  8234.         } else {
  8235.             int occur = 0, xx = 0, j2;
  8236.             len1 = (int)strlen(bp[0]);  /* length of string to look in */
  8237.             len2 = (int)strlen(bp[1]);  /* length of string to look for */
  8238.             len3 = (argn < 3) ? 0 : (int)strlen(bp[2]); /* Len of replacemnt */
  8239.             j = len1 - len2 + 1;
  8240.             j2 = j;
  8241.             if (argn > 3) {
  8242.                 if (chknum(bp[3])) {
  8243.                     occur = atoi(bp[3]);
  8244.                 } else {
  8245.                     failed = 1;
  8246.                     if (fndiags)
  8247.                       ckmakmsg(fnval,FNVALL,
  8248.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8249.                     goto fnend;
  8250.                 }
  8251.             }
  8252.             /* If args out of whack... */
  8253.             if (j < 1 || len1 == 0 || len2 == 0) {
  8254.                 ckstrncpy(p,bp[0],FNVALL); /* just return original string */
  8255.                 p[FNVALL] = NUL;
  8256.             } else {
  8257.               ragain:
  8258.                 s = bp[0];              /* Point to beginning of string */
  8259.                 while (j-- > 0) {       /* For each character */
  8260.                     if (!ckstrcmp(bp[1],s,len2,inpcas[cmdlvl]) &&
  8261.                         (occur == 0 || occur == ++xx)) {
  8262.                         if (len3) {
  8263.                             ckstrncpy(p,bp[2],FNVALL);
  8264.                             p += len3;
  8265.                         }
  8266.                         s += len2;      /* and skip past it. */
  8267.                     } else {            /* No, */
  8268.                         *p++ = *s++;    /* just copy this character */
  8269.                     }
  8270.                 }
  8271.                 *p = NUL;
  8272.                 while ((*p++ = *s++));
  8273.                 if (occur < 0) {        /* cheap... */
  8274.                     occur = xx + occur + 1;
  8275.                     xx = 0;
  8276.                     p = fnval;
  8277.                     j = j2;
  8278.                     if (occur > 0)
  8279.                       goto ragain;
  8280.                 }
  8281.             }
  8282.         }
  8283.         p = fnval;
  8284.         goto fnend;
  8285.  
  8286.       case FN_CHR:                      /* \fcharacter(arg1) */
  8287.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8288.         if (chknum(val1)) {             /* Must be numeric */
  8289.             i = atoi(val1);
  8290.             if (i >= 0 && i < 256) {    /* Must be an 8-bit value */
  8291.                 p = fnval;
  8292.                 *p++ = (char) i;
  8293.                 *p = NUL;
  8294.                 p = fnval;
  8295.             } else {
  8296.                 failed = 1;
  8297.                 if (fndiags)
  8298.                   ckmakmsg(fnval,FNVALL,
  8299.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  8300.             }
  8301.         } else {
  8302.             failed = 1;
  8303.             evalerr(fn);
  8304.         }
  8305.         goto fnend;
  8306.  
  8307.       case FN_COD:                      /* \fcode(char) */
  8308.         if ((int)strlen(bp[0]) > 0) {
  8309.             p = fnval;
  8310.             i = *bp[0];
  8311.             sprintf(p,"%d",(i & 0xff)); /* SAFE */
  8312.         } else p = "";                  /* Can't happen */
  8313.         goto fnend;
  8314.  
  8315.       case FN_LEN:                      /* \flength(arg1) */
  8316.         if (argn > 0) {
  8317.             p = fnval;
  8318.             sprintf(p,"%d",(int)strlen(bp[0])); /* SAFE */
  8319.         } else p = "0";
  8320.         goto fnend;
  8321.  
  8322.       case FN_LOW:                      /* \flower(arg1) */
  8323.         s = bp[0] ? bp[0] : "";
  8324.         p = fnval;
  8325.         while (*s) {
  8326.             if (isupper(*s))
  8327.               *p = (char) tolower(*s);
  8328.             else
  8329.               *p = *s;
  8330.             p++; s++;
  8331.         }
  8332.         *p = NUL;
  8333.         p = fnval;
  8334.         goto fnend;
  8335.  
  8336.       case FN_MAX:                      /* \fmax(arg1,arg2) */
  8337.       case FN_MIN:                      /* \fmin(arg1,arg2) */
  8338.       case FN_MOD:                      /* \fmod(arg1,arg2) */
  8339.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8340. #ifdef COMMENT
  8341.         /* No longer necessary because evalx() no longer overwrites its */
  8342.         /* result every time it's called (2000/09/23). */
  8343.         free(bp[0]);
  8344.         bp[0] = NULL;
  8345. #endif /* COMMENT */
  8346.         if (argn > 1) {
  8347. #ifdef COMMENT
  8348.             /* Ditto... */
  8349.             bp[0] = malloc((int)strlen(val1)+1);
  8350.             if (bp[0])
  8351.               strcpy(bp[0],val1);       /* safe */
  8352.             val1 = bp[0];
  8353. #endif /* COMMENT */
  8354.             val2 = *(bp[1]) ? evalx(bp[1]) : "";
  8355.             if (chknum(val1) && chknum(val2)) {
  8356.                 i = atoi(val1);
  8357.                 j = atoi(val2);
  8358.                 switch (y) {
  8359.                   case FN_MAX:
  8360.                     if (j < i) j = i;
  8361.                     break;
  8362.                   case FN_MIN:
  8363.                     if (j > i) j = i;
  8364.                     break;
  8365.                   case FN_MOD:
  8366.                     if (j == 0) {
  8367.                         failed = 1;
  8368.                         if (fndiags)
  8369.                           ckmakmsg(fnval,FNVALL,
  8370.                                    "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  8371.                         else
  8372.                           fnval[0] = NUL;
  8373.                         goto fnend;
  8374.                     } else
  8375.                       j = i % j;
  8376.                 }
  8377.                 p = fnval;
  8378.                 sprintf(p,"%d",j);      /* SAFE */
  8379.             } else {
  8380.                 failed = 1;
  8381.                 evalerr(fn);
  8382.             }
  8383.         } else p = val1;
  8384.         goto fnend;
  8385.     } /* Break up big switch... */
  8386.  
  8387.     switch (y) {
  8388.       case FN_SUB:                      /* \fsubstr(arg1,arg2,arg3) */
  8389.       case FN_RIG:                      /* \fright(arg1,arg2) */
  8390.       case FN_LEF:                      /* \fleft(arg1,arg2) */
  8391.         if (argn < 1)
  8392.           goto fnend;
  8393.         val1 = "";
  8394.         if (argn > 1)
  8395.           if (*(bp[1]))
  8396.             val1 =  evalx(bp[1]);
  8397. #ifdef COMMENT
  8398.         if (bp[1]) free(bp[1]);         /* Have to copy this */
  8399.         bp[1] = malloc((int)strlen(val1)+1);
  8400.         if (!bp[1]) {
  8401.             failed = 1;
  8402.             if (fndiags) {
  8403.                 p = fnval;
  8404.                 ckmakmsg(fnval,FNVALL,
  8405.                          "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  8406.             }
  8407.             goto fnend;
  8408.         }
  8409.         strcpy(bp[1],val1);             /* safe */
  8410.         val1 = bp[1];
  8411. #endif /* COMMENT */
  8412.         val2 = "";
  8413.         if (argn > 2)
  8414.           if (*(bp[2]))
  8415.             val2 = evalx(bp[2]);
  8416.         if (
  8417.             ((argn > 1) && (int)strlen(val1) && !rdigits(val1)) ||
  8418.             ((cx == FN_SUB) &&
  8419.               ((argn > 2) && (int)strlen(val2) && !rdigits(val2)))
  8420.             ) {
  8421.             failed = 1;
  8422.             evalerr(fn);
  8423.         } else {
  8424.             int lx;
  8425.             p = fnval;                  /* pointer to result */
  8426.             lx = strlen(bp[0]);         /* length of arg1 */
  8427.             if (cx == FN_SUB) {         /* substring */
  8428.                 k = (argn > 2) ? atoi(val2) : MAXARGLEN; /* length */
  8429.                 j = (argn > 1) ? atoi(val1) : 1; /* start pos for substr */
  8430.             } else if (cx == FN_LEF) {  /* left */
  8431.                 k = (argn > 1) ? atoi(val1) : lx;
  8432.                 j = 1;
  8433.             } else {                             /* right */
  8434.                 k = (argn > 1) ? atoi(val1) : lx; /* length */
  8435.                 j = lx - k + 1;                  /* start pos for right */
  8436.                 if (j < 1) j = 1;
  8437.             }
  8438.             if (k > 0 && j <= lx) {              /* if start pos in range */
  8439.                 s = bp[0]+j-1;                   /* point to source string */
  8440.                 for (i = 0; (i < k) && (*p++ = *s++); i++) ;  /* copy */
  8441.             }
  8442.             *p = NUL;                   /* terminate the result */
  8443.             p = fnval;                  /* and point to it. */
  8444.         }
  8445.         goto fnend;
  8446.  
  8447.       case FN_UPP:                      /* \fupper(arg1) */
  8448.         s = bp[0] ? bp[0] : "";
  8449.         p = fnval;
  8450.         while (*s) {
  8451.             if (islower(*s))
  8452.               *p = (char) toupper(*s);
  8453.             else
  8454.               *p = *s;
  8455.             p++; s++;
  8456.         }
  8457.         *p = NUL;
  8458.         p = fnval;
  8459.         goto fnend;
  8460.  
  8461.       case FN_REP:                      /* \frepeat(text,number) */
  8462.         if (argn < 1)
  8463.           goto fnend;
  8464.         val1 = "1";
  8465.         if (argn > 1)
  8466.           if (*(bp[1]))
  8467.             val1 = evalx(bp[1]);
  8468.         if (chknum(val1)) {             /* Repeat count */
  8469.             n = atoi(val1);
  8470.             debug(F111,"SUNDAY frepeat n",val1,n);
  8471.             if (n > 0) {                /* Make n copies */
  8472.                 p = fnval;
  8473.                 *p = '\0';
  8474.                 k = (int)strlen(bp[0]); /* Make sure string has some length */
  8475.                 debug(F111,"SUNDAY frepeat k","",k);
  8476.                 debug(F111,"SUNDAY frepeat FNVALL","",FNVALL);
  8477.                 if (k * n >= FNVALL) {  /* But not too much... */
  8478.                     failed = 1;
  8479.                     if (fndiags)
  8480.                       ckmakmsg(fnval,FNVALL,
  8481.                                "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  8482.                     else
  8483.                       fnval[0] = NUL;
  8484.                     p = fnval;
  8485.                     goto fnend;
  8486.                 }
  8487.                 if (k > 0) {            /* If there is something to copy */
  8488.                     for (i = 0; i < n; i++) { /* Copy loop */
  8489.                         s = bp[0];
  8490.                         for (j = 0; j < k; j++) {
  8491.                             if ((p - fnval) >= FNVALL)
  8492.                               break;    /* shouldn't happen... */
  8493.                             else
  8494.                               *p++ = *s++;
  8495.                         }
  8496.                     }
  8497.                     *p = NUL;
  8498.                 }
  8499.             }
  8500.         } else {
  8501.             failed = 1;
  8502.             evalerr(fn);
  8503.         }
  8504.         p = fnval;
  8505.         goto fnend;
  8506.  
  8507. #ifndef NOFRILLS
  8508.       case FN_REV:                      /* \freverse() */
  8509.         if (argn < 1)
  8510.           goto fnend;
  8511.         yystring(bp[0],&p);
  8512.         goto fnend;
  8513. #endif /* NOFRILLS */
  8514.  
  8515.       case FN_RPA:                      /* \frpad() and \flpad() */
  8516.       case FN_LPA:
  8517.         if (argn < 1)
  8518.           goto fnend;
  8519.         val1 = "";
  8520.         if (argn > 1)
  8521.           if (*(bp[1]))
  8522.             val1 = evalx(bp[1]);
  8523.         if (argn == 1) {                /* If a number wasn't given */
  8524.             p = fnval;                  /* just return the original string */
  8525.             ckstrncpy(p,bp[0],FNVALL);
  8526.         } else if (argn > 1 &&  !*val1) {
  8527.             failed = 1;
  8528.             evalerr(fn);
  8529.         } else /* if (chknum(val1)) */ { /* Repeat count */
  8530.             char pc;
  8531.             n = atoi(val1);
  8532.             if (n >= 0) {
  8533.                 p = fnval;
  8534.                 k = (int)strlen(bp[0]); /* Length of string to be padded */
  8535.                 if (k >= n) {           /* It's already long enough */
  8536.                     ckstrncpy(p,bp[0],FNVALL);
  8537.                 } else {
  8538.                     if (n + k <= FNVALL) {
  8539.                         pc = (char) ((argn < 3) ? SP : *bp[2]);
  8540.                         if (!pc) pc = SP;
  8541.                         if (cx == FN_RPA) { /* RPAD */
  8542.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8543.                             p[k] = NUL;
  8544.                             p += k;
  8545.                             for (i = k; i < n; i++)
  8546.                               *p++ = pc;
  8547.                         } else {        /* LPAD */
  8548.                             n -= k;
  8549.                             for (i = 0; i < n; i++)
  8550.                               *p++ = pc;
  8551.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8552.                             p[k] = NUL;
  8553.                             p += k;
  8554.                         }
  8555.                     }
  8556.                     *p = NUL;
  8557.                 }
  8558.             }
  8559.         }
  8560.         p = fnval;
  8561.         goto fnend;
  8562.  
  8563. #ifdef ZFCDAT
  8564.       case FN_FD:                       /* \fdate(filename) */
  8565.         p = fnval;
  8566.         s = zfcdat(bp[0]);
  8567.         if (!s) s = "";
  8568.         if (!*s) {
  8569.             failed = 1;
  8570.             if (fndiags)
  8571.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8572.             goto fnend;
  8573.         }
  8574.         ckstrncpy(fnval,s,FNVALL);
  8575. #endif /* ZFCDAT */
  8576.         goto fnend;
  8577.  
  8578.     } /* Break up big switch... */
  8579.  
  8580.     switch (y) {
  8581.       case FN_FS:                       /* \fsize(filename) */
  8582.         p = fnval;
  8583.         z = zchki(bp[0]);
  8584.         if (z < 0) {
  8585.             failed = 1;
  8586.             if (fndiags) {
  8587.                 if (z == -1)
  8588.                   ckmakmsg(fnval,FNVALL,
  8589.                            "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8590.                 else if (z == -2)
  8591.                   ckmakmsg(fnval,FNVALL,
  8592.                            "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  8593.                 else if (z == -3)
  8594.                   ckmakmsg(fnval,FNVALL,
  8595.                            "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  8596.                 else
  8597.                   ckmakmsg(fnval,FNVALL,
  8598.                            "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  8599.             }
  8600.             goto fnend;
  8601.         }
  8602.         sprintf(fnval,"%ld",z);         /* SAFE */
  8603.         goto fnend;
  8604.  
  8605.       case FN_VER:                      /* \fverify() */
  8606.         p = "0";
  8607.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8608.             int start;
  8609.             char *s2, ch1, ch2;
  8610.             start = 0;
  8611.             if (argn > 2) {             /* Starting position specified */
  8612.                 val1 = *(bp[2]) ? evalx(bp[2]) : "0";
  8613.                 if (chknum(val1)) {
  8614.                     start = atoi(val1) /* - 1 */;
  8615.                     if (start < 0) start = 0;
  8616.                     if (start > (int)strlen(bp[1]))
  8617.                       goto verfin;
  8618.                 } else {
  8619.                     failed = 1;
  8620.                     evalerr(fn);
  8621.                     goto fnend;
  8622.                 }
  8623.             }
  8624.             i = start;
  8625.             p = "0";
  8626.             for (s = bp[1] + start; *s; s++,i++) {
  8627.                 ch1 = *s;
  8628.                 if (!inpcas[cmdlvl]) if (islower(ch1)) ch1 = toupper(ch1);
  8629.                 j = 0;
  8630.                 for (s2 = bp[0]; *s2; s2++) {
  8631.                     ch2 = *s2;
  8632.                     if (!inpcas[cmdlvl]) if (islower(ch2)) ch2 = toupper(ch2);
  8633.                     if (ch1 == ch2) {
  8634.                         j = 1;
  8635.                         break;
  8636.                     }
  8637.                 }
  8638.                 if (j == 0) {
  8639.                     sprintf(fnval,"%d",i+1); /* SAFE */
  8640.                     p = fnval;
  8641.                     break;
  8642.                 }
  8643.             }
  8644.         }
  8645.       verfin:
  8646.         goto fnend;
  8647.  
  8648.       case FN_IPA:                      /* Find and return IP address */
  8649.         if (argn > 0) {                 /* in argument string. */
  8650.             int start = 0;
  8651.             if (argn > 1) {             /* Starting position specified */
  8652.                 if (chknum(bp[1])) {
  8653.                     start = atoi(bp[1]) - 1;
  8654.                     if (start < 0) start = 0;
  8655.                 } else {
  8656.                     failed = 1;
  8657.                     if (fndiags)
  8658.                       ckmakmsg(fnval,FNVALL,
  8659.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8660.                     goto fnend;
  8661.                 }
  8662.             }
  8663.             p = getip(bp[0]+start);
  8664.         } else p = "";
  8665.         goto fnend;
  8666.  
  8667. #ifdef OS2
  8668.       case FN_CRY:
  8669.         p = "";
  8670.         if (argn > 0) {
  8671.             p = fnval;
  8672.             ckstrncpy(p,bp[0],FNVALL);
  8673.             ck_encrypt(p);
  8674.         }
  8675.         goto fnend;
  8676.  
  8677.       case FN_OOX:
  8678.         p = "";
  8679.         if (argn > 0)
  8680.           p = (char *) ck_oox(bp[0], (argn > 1) ? bp[1] : "");
  8681.         goto fnend;
  8682. #endif /* OS2 */
  8683.  
  8684.       case FN_HEX:                      /* \fhexify(arg1) */
  8685.         if (argn < 1)
  8686.           goto fnend;
  8687.         if ((int)strlen(bp[0]) < (FNVALL / 2)) {
  8688.             s = bp[0];
  8689.             p = fnval;
  8690.             while (*s) {
  8691.                 x = (*s >> 4) & 0x0f;
  8692.                 *p++ = hexdigits[x];
  8693.                 x = *s++ & 0x0f;
  8694.                 *p++ = hexdigits[x];
  8695.             }
  8696.             *p = NUL;
  8697.             p = fnval;
  8698.         }
  8699.         goto fnend;
  8700.  
  8701.       case FN_UNH: {                    /* \funhex(arg1) */
  8702.           int c[2], i;
  8703.           if (argn < 1)
  8704.             goto fnend;
  8705.           if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  8706.               s = bp[0];
  8707.               p = fnval;
  8708.               while (*s) {
  8709.                   for (i = 0; i < 2; i++) {
  8710.                       c[i] = *s++;
  8711.                       if (!c[i]) { p = ""; goto unhexfin; }
  8712.                       if (islower(c[i])) c[i] = toupper(c[i]);
  8713.                       if (c[i] >= '0' && c[i] <= '9') {
  8714.                           c[i] -= 0x30;
  8715.                       } else if (c[i] >= 'A' && c[i] <= 'F') {
  8716.                           c[i] -= 0x37;
  8717.                       } else {
  8718.                           failed = 1;
  8719.                           if (fndiags)
  8720.                             ckmakmsg(fnval,
  8721.                                      FNVALL,
  8722.                                      "<ERROR:ARG_OUT_OF_RANGE:\\f",
  8723.                                      fn,
  8724.                                      "()>",
  8725.                                      NULL
  8726.                                      );
  8727.                           goto fnend;
  8728.                       }
  8729.                   }
  8730.                   *p++ = ((c[0] << 4) & 0xf0) | (c[1] & 0x0f);
  8731.               }
  8732.               *p = NUL;
  8733.               p = fnval;
  8734.           }
  8735.         unhexfin:
  8736.           goto fnend;
  8737.       }
  8738.  
  8739.       case FN_BRK: {                    /* \fbreak() */
  8740.           char * c;                     /* Characters to break on */
  8741.           char c2, s2;
  8742.           int start = 0;
  8743.           int done = 0;
  8744.           if (argn < 1)
  8745.             goto fnend;
  8746.           if (argn > 2) {
  8747.               s = bp[2] ? bp[2] : "0";
  8748.               if (chknum(s)) {
  8749.                   start = atoi(s);
  8750.                   if (start < 0) start = 0;
  8751.                   if (start > (int)strlen(bp[0]))
  8752.                     goto brkfin;
  8753.               } else {
  8754.                   failed = 1;
  8755.                   if (fndiags)
  8756.                     ckmakmsg(fnval,FNVALL,
  8757.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8758.                   goto fnend;
  8759.               }
  8760.           }
  8761.           s = bp[0] + start;            /* Source pointer */
  8762.  
  8763.           while (*s && !done) {
  8764.               s2 = *s;
  8765.               if (!inpcas[cmdlvl] && islower(s2)) s2 = toupper(s2);
  8766.               c = bp[1] ? bp[1] : "";   /* Character to break on */
  8767.               while (*c) {
  8768.                   c2 = *c;
  8769.                   if (!inpcas[cmdlvl] && islower(c2)) c2 = toupper(c2);
  8770.                   if (c2 == s2) {
  8771.                       done = 1;
  8772.                       break;
  8773.                   }
  8774.                   c++;
  8775.               }
  8776.               if (done) break;
  8777.               *p++ = *s++;
  8778.           }
  8779.           *p = NUL;                     /* terminate the result */
  8780.           p = fnval;                    /* and point to it. */
  8781.         brkfin:
  8782.           goto fnend;
  8783.       }
  8784.  
  8785.       case FN_SPN: {                    /* \fspan() */
  8786.           char *q;
  8787.           char c1, c2;
  8788.           int start = 0;
  8789.           if (argn < 1)
  8790.             goto fnend;
  8791.           if (argn > 2) {               /* Starting position */
  8792.               s = bp[2] ? bp[2] : "0";
  8793.               if (chknum(s)) {
  8794.                   start = atoi(s);
  8795.                   if (start < 0) start = 0;
  8796.               } else {
  8797.                   failed = 1;
  8798.                   if (fndiags)
  8799.                     ckmakmsg(fnval,FNVALL,
  8800.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8801.                   goto fnend;
  8802.               }
  8803.           }
  8804.           s = bp[0] + start;            /* Source pointer */
  8805.           if (argn > 1 &&
  8806.               (int)strlen(bp[1]) > 0 &&
  8807.               start <= (int)strlen(bp[0])) {
  8808.               while (*s) {              /* Loop thru source string */
  8809.                   q = bp[1];            /* Span string */
  8810.                   c1 = *s;
  8811.                   if (!inpcas[cmdlvl])
  8812.                     if (islower(c1)) c1 = toupper(c1);
  8813.                   x = 0;
  8814.                   while ((c2 = *q++)) {
  8815.                       if (!inpcas[cmdlvl])
  8816.                         if (islower(c2)) c2 = toupper(c2);
  8817.                       if (c1 == c2) { x = 1; break; }
  8818.                   }
  8819.                   if (!x) break;
  8820.                   *p++ = *s++;
  8821.               }
  8822.               *p = NUL;                 /* Terminate and return the result */
  8823.               p = fnval;
  8824.           }
  8825.           goto fnend;
  8826.       }
  8827.     } /* Break up big switch... */
  8828.  
  8829.     switch (y) {
  8830.       case FN_TRM:                      /* \ftrim(s1[,s2]) */
  8831.       case FN_LTR:                      /* \fltrim(s1[,s2]) */
  8832.         if (argn < 1)
  8833.           goto fnend;
  8834.         if ((len1 = (int)strlen(bp[0])) > 0) {
  8835.             if (len1 > FNVALL)
  8836.               len1 = FNVALL;
  8837.             s = " \t\r\n";
  8838.             if (argn > 1)               /* Trim list given */
  8839.               s = bp[1];
  8840.             len2 = (int)strlen(s);
  8841.             if (len2 < 1) {             /* or not... */
  8842.                 s = " \t\r\n";          /* Default is to trim whitespace */
  8843.                 len2 = 2;
  8844.             }
  8845.             if (cx == FN_TRM) {         /* Trim from right */
  8846.                 char * q, p2, q2;
  8847.                 ckstrncpy(fnval,bp[0],FNVALL); /* Copy string to output */
  8848.                 p = fnval + len1 - 1;   /* Point to last character */
  8849.  
  8850.                 while (p >= (char *)fnval) { /* Go backwards */
  8851.                     q = s;              /* Point to trim list */
  8852.                     p2 = *p;
  8853.                     if (!inpcas[cmdlvl])
  8854.                       if (islower(p2)) p2 = toupper(p2);
  8855.                     while (*q) {        /* Is this char in trim list? */
  8856.                         q2 = *q;
  8857.                         if (!inpcas[cmdlvl])
  8858.                           if (islower(q2)) q2 = toupper(q2);
  8859.                         if (p2 == q2) { /* Yes, null it out */
  8860.                             *p = NUL;
  8861.                             break;
  8862.                         }
  8863.                         q++;
  8864.                     }
  8865.                     if (!*q)            /* Trim list exhausted */
  8866.                       break;            /* So we're done. */
  8867.                     p--;                /* Else keep trimming */
  8868.                 }
  8869.             } else {                    /* Trim from left */
  8870.                 char * q, p2, q2;
  8871.                 p = bp[0];              /* Source */
  8872.                 while (*p) {
  8873.                     p2 = *p;
  8874.                     if (!inpcas[cmdlvl])
  8875.                       if (islower(p2)) p2 = toupper(p2);
  8876.                     q = s;
  8877.                     while (*q) {        /* Is this char in trim list? */
  8878.                         q2 = *q;
  8879.                         if (!inpcas[cmdlvl])
  8880.                           if (islower(q2)) q2 = toupper(q2);
  8881.                         if (p2 == q2) { /* Yes, point past it */
  8882.                             p++;        /* and try next source character */
  8883.                             break;
  8884.                         }
  8885.                         q++;            /* No, try next trim character */
  8886.                     }
  8887.                     if (!*q)            /* Trim list exhausted */
  8888.                       break;            /* So we're done. */
  8889.                 }
  8890.                 ckstrncpy(fnval,p,FNVALL);
  8891.             }
  8892.             p = fnval;
  8893.         } else p = "";
  8894.         goto fnend;
  8895.  
  8896.       case FN_CAP:                      /* \fcapitalize(arg1) */
  8897.         if (argn < 1)
  8898.           goto fnend;
  8899.         s = bp[0];
  8900.         p = fnval;
  8901.         x = 0;
  8902.         while ((c = *s++)) {
  8903.             if (isalpha(c)) {
  8904.                 if (x == 0) {
  8905.                     x = 1;
  8906.                     if (islower(c))
  8907.                       c = toupper(c);
  8908.                 } else if (isupper(c))
  8909.                   c = tolower(c);
  8910.             }
  8911.             *p++ = c;
  8912.         }
  8913.         *p = NUL;
  8914.         p = fnval;
  8915.         goto fnend;
  8916.  
  8917. #ifdef COMMENT
  8918.       case FN_TOD:                      /* Time of day to secs since midnite */
  8919.         sprintf(fnval,"%ld",tod2sec(bp[0])); /* SAFE */
  8920.         goto fnend;
  8921. #endif /* COMMENT */
  8922.  
  8923.       case FN_FFN:                      /* Full pathname of file */
  8924.         zfnqfp(bp[0],FNVALL,p);
  8925.         if (!p) p = "";
  8926.         goto fnend;
  8927.  
  8928.       case FN_CHK: {                    /* \fchecksum() */
  8929.           long chk = 0;
  8930.           p = (argn > 0) ? bp[0] : "";
  8931.           while (*p) chk += *p++;
  8932.           sprintf(fnval,"%lu",chk);     /* SAFE */
  8933.           p = fnval;
  8934.           goto fnend;
  8935.       }
  8936.  
  8937. #ifndef NOXFER
  8938.       case FN_CRC:                      /* \fcrc16() */
  8939.         if (argn > 0)
  8940.           sprintf(fnval,"%u",           /* SAFE */
  8941.                   chk3((CHAR *)bp[0],(int)strlen(bp[0])));
  8942.         else
  8943.           p = "0";
  8944.         goto fnend;
  8945. #endif /* NOXFER */
  8946.  
  8947.       case FN_BSN:                      /* \fbasename() */
  8948.         zstrip(bp[0],&p);
  8949.         goto fnend;
  8950.  
  8951. #ifndef NOLOCAL
  8952. #ifdef OS2
  8953.       case FN_SCRN_CX:                  /* \fscrncurx() */
  8954.         p = fnval;
  8955.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->x); /* SAFE */
  8956.         goto fnend;
  8957.  
  8958.       case FN_SCRN_CY:                  /* \fscrncury() */
  8959.         p = fnval;
  8960.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->y); /* SAFE */
  8961.         goto fnend;
  8962.  
  8963.       case FN_SCRN_STR: {               /* \fscrnstr() */
  8964.           videoline * line = NULL;
  8965.           viocell * cells = NULL;
  8966.           int row = 0, col = 0, len = 0;
  8967.           /* NOTE: On Unicode systems, the screen contents are stored in */
  8968.           /* in Unicode.  Therefore, we should really be performing a    */
  8969.           /* conversion to the local character set.                      */
  8970.  
  8971.           /* 6/18/2000 - added the translation to lcs */
  8972.  
  8973.           if (bp[0] == NULL || bp[0][0] == '\0') {
  8974.               row = 0;
  8975.           } else {
  8976.               if (chknum(bp[0])) {
  8977.                   row = atoi(bp[0]);
  8978.                   if (row < 0)
  8979.                     row = 0;
  8980.               } else {
  8981.                   failed = 1;
  8982.                   if (fndiags)
  8983.                     ckmakmsg(fnval,FNVALL,
  8984.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8985.                   goto fnend;
  8986.               }
  8987.           }
  8988.           line = VscrnGetLineFromTop( VTERM, (USHORT) row );
  8989.           if (line != NULL) {
  8990.               if (bp[1] == NULL || bp[1][0] == '\0')
  8991.                 col = 0;
  8992.               else {
  8993.                   if (chknum(bp[0])) {
  8994.                       col = atoi(bp[1]);
  8995.                       if (col < 0 || col >= line->width)
  8996.                         col = 0;
  8997.                   } else {
  8998.                       failed = 1;
  8999.                       if (fndiags)
  9000.                         ckmakmsg(fnval,FNVALL,
  9001.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9002.                       goto fnend;
  9003.                   }
  9004.               }
  9005.               if (bp[2] == NULL || bp[2][0] == '\0') {
  9006.                   len = line->width - (col+1);
  9007.               } else {
  9008.                   if (!chknum(bp[2])) {
  9009.                       failed = 1;
  9010.                       if (fndiags)
  9011.                         ckmakmsg(fnval,FNVALL,
  9012.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9013.                       goto fnend;
  9014.                   }
  9015.                   len = atoi(bp[2]);
  9016.                   if (len < 0 || len > line->width)
  9017.                     len = line->width;
  9018.               }
  9019.               cells = line->cells;
  9020.               for (i = 0; i < len; i++) {
  9021.                   int pos = i + col;
  9022.                   if (pos < line->width) {
  9023.                       if (isunicode())
  9024.                         fnval[i] = (CHAR) utolxlat(cells[pos].c);
  9025.                       else
  9026.                         fnval[i] = (CHAR) (cells[pos].c & 0xFF);
  9027.                       if (fnval[i] == 0)
  9028.                         fnval[i] = SP;
  9029.                   } else
  9030.                     fnval[i] = SP;
  9031.               }
  9032.               fnval[i] = '\0';
  9033.           } else {
  9034.               fnval[0] = '\0';
  9035.           }
  9036.           p = fnval;
  9037.           goto fnend;
  9038.       }
  9039. #endif /* OS2 */
  9040. #endif /* NOLOCAL */
  9041.  
  9042. #ifndef NOPUSH
  9043.       case FN_RAW:                      /* \frawcommand() */
  9044.       case FN_CMD: {                    /* \fcommand() */
  9045.           int x, c, n = FNVALL;
  9046.           x = 0;                        /* Completion flag */
  9047. /*
  9048.   ZIFILE can be safely used because we can't possibly be transferring a file
  9049.   while executing this function.
  9050. */
  9051.           if (!nopush && zxcmd(ZIFILE,bp[0]) > 0) { /* Open the command */
  9052.               while (n-- > -1) {        /* Read from it */
  9053.                   if ((c = zminchar()) < 0) {
  9054.                       x = 1;             /* EOF - set completion flag */
  9055.                       if (cx == FN_CMD) { /* If not "rawcommand" */
  9056.                           p--;           /* remove trailing newlines */
  9057.                           while (*p == CR || *p == LF)
  9058.                             p--;
  9059.                           p++;
  9060.                       }
  9061.                       *p = NUL;         /* Terminate the string */
  9062.                       break;
  9063.                   } else                /* Command still running */
  9064.                     *p++ = c;           /* Copy the bytes */
  9065.               }
  9066.               zclose(ZIFILE);           /* Close the command */
  9067.           }
  9068.           /* Return null string if command's output was too long. */
  9069.           p = fnval;
  9070.           if (!x) {
  9071.               failed = 1;
  9072.               if (fndiags)
  9073.                 ckmakmsg(fnval,FNVALL,
  9074.                          "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  9075.           }
  9076.           goto fnend;
  9077.       }
  9078. #endif /* NOPUSH */
  9079.     } /* Break up big switch... */
  9080.  
  9081.     switch (y) {
  9082.       case FN_STX:                      /* \fstripx(string,c) */
  9083.         if (!(s = bp[0]))               /* Make sure there is a string */
  9084.           goto fnend;
  9085.         c = '.';                        /* Character to strip from */
  9086.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9087.         n = ckstrncpy(fnval,bp[0],FNVALL);
  9088.         while (--n >= 0) {
  9089.             if (fnval[n] == c) {
  9090.                 fnval[n] = NUL;
  9091.                 break;
  9092.             }
  9093.         }
  9094.         p = fnval;
  9095.         goto fnend;
  9096.  
  9097.       case FN_STL:                      /* \flop(string,c) */
  9098.         if (!(s = bp[0]))               /* Make sure there is a string */
  9099.           goto fnend;
  9100.         c = '.';                        /* Character to strip to */
  9101.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9102.         x = 0;
  9103.         while (*s++) {
  9104.             if (*(s-1) == c) {
  9105.                 x = 1;
  9106.                 break;
  9107.             }
  9108.         }
  9109.         if (!x) s = bp[0];
  9110.         ckstrncpy(fnval,s,FNVALL);
  9111.         p = fnval;
  9112.         goto fnend;
  9113.  
  9114.       case FN_STN:                      /* \fstripn(string,n) */
  9115.         if (argn < 1)                   /* Remove n chars from right */
  9116.           goto fnend;
  9117.         val1 = "0";
  9118.         if (argn > 1)
  9119.           if (*(bp[1]))
  9120.             val1 = evalx(bp[1]);
  9121.         if (!chknum(val1)) {
  9122.             failed = 1;
  9123.             evalerr(fn);
  9124.             goto fnend;
  9125.         }
  9126.         n = atoi(val1);
  9127.         if (n < 0) n = 0;
  9128.         k = (int)strlen(s = bp[0]) - n;
  9129.         if (k < 0) k = 0;
  9130.         p = fnval;
  9131.         while (k-- > 0)
  9132.           *p++ = *s++;
  9133.         *p = NUL;
  9134.         p = fnval;
  9135.         goto fnend;
  9136.  
  9137.       case FN_STB: {                    /* \fstripb(string,c) */
  9138.           char c2 = NUL;
  9139.           int i, k = 0;
  9140.           char * gr_opn = "\"{'([<";    /* Group open brackets */
  9141.           char * gr_cls = "\"}')]>";    /* Group close brackets */
  9142.  
  9143.           p = fnval;
  9144.           *p = NUL;
  9145.           if (!(s = bp[0]))             /* Make sure there is a string */
  9146.             goto fnend;
  9147.           if ((x = strlen(s)) < 1)
  9148.             goto fnend;
  9149.           c = NUL;                      /* Brace/bracket kind */
  9150.           if (argn > 1) {
  9151.               if (*bp[1]) {
  9152.                   if (chknum(bp[1])) {
  9153.                       k = atoi(bp[1]);
  9154.                       if (k < 0) k = 63;
  9155.                       for (i = 0; i < 6; i++) {
  9156.                           if (k & (1<<i)) {
  9157.                               if (s[0] == gr_opn[i] && s[x-1] == gr_cls[i]) {
  9158.                                   ckstrncpy(fnval,s+1,FNVALL);
  9159.                                   fnval[x-2] = NUL;
  9160.                                   goto fnend;
  9161.                               }
  9162.                           }
  9163.                       }
  9164.                       ckstrncpy(fnval,s,FNVALL); /* No match */
  9165.                       goto fnend;
  9166.                   }
  9167.               }
  9168.           }
  9169.           c = *bp[1];
  9170.           if (!c) c = s[0];
  9171.           if (argn > 2) if (*bp[2]) c2 = *bp[2];
  9172.           if (*s == c) {
  9173.               if (!c2) {
  9174.                   switch (c) {
  9175.                     case '(': c2 = ')'; break;
  9176.                     case '[': c2 = ']'; break;
  9177.                     case '{': c2 = '}'; break;
  9178.                     case '<': c2 = '>'; break;
  9179.                     case '"': c2 = '"'; break;
  9180.                     case 39:  c2 = 39;  break;
  9181.                     case 96:  c2 = 39;  break;
  9182.                     default:
  9183.                       if (argn == 2) {
  9184.                           c2 = c;
  9185.                       } else {
  9186.                           strncpy(fnval,s,x); /* Leave it like this */
  9187.                           fnval[x] = NUL;
  9188.                           goto fnend;
  9189.                       }
  9190.                   }
  9191.               }
  9192.               if (s[x-1] == c2) {
  9193.                   strncpy(fnval,s+1,x-2); /* Leave it like this */
  9194.                   fnval[x-2] = NUL;
  9195.                   goto fnend;
  9196.               }
  9197.           }
  9198.           strncpy(fnval,s,x);
  9199.           fnval[x] = NUL;
  9200.           goto fnend;
  9201.       }
  9202.  
  9203.       case FN_2HEX:                     /* Number to hex */
  9204.       case FN_2OCT:                     /* Number to octal */
  9205.         val1 = evalx(bp[0]);
  9206.         if (!*val1) {
  9207.             failed = 1;
  9208.             evalerr(fn);
  9209.             goto fnend;
  9210.         }
  9211.         sprintf(fnval, cx == FN_2HEX ? "%lx" : "%lo", atol(val1)); /* SAFE */
  9212.         if (cx == FN_2HEX && (int)(strlen(fnval)&1))
  9213.           sprintf(fnval,"0%lx",atol(val1)); /* SAFE */
  9214.         p = fnval;
  9215.         goto fnend;
  9216.  
  9217.       case FN_DNAM: {                   /* Directory part of file name */
  9218.           char *s;
  9219.           zfnqfp(bp[0],FNVALL,p);       /* Get full name */
  9220.           if (!isdir(p)) {              /* Is it already a directory? */
  9221.               zstrip(p,&s);             /* No get basename */
  9222.               if (*s) {
  9223.                   x = ckindex(s,p,0,0,0); /* Pos of latter in former */
  9224.                   if (x > 0) p[x-1] = NUL;
  9225.               }
  9226.           }
  9227.           if (!p) p = "";
  9228.           goto fnend;
  9229.       }
  9230.  
  9231. #ifndef NORANDOM
  9232.       case FN_RAND:                     /* Random number */
  9233.         k = rand();
  9234.         x = 0;
  9235.         if (argn > 0) {
  9236.             if (!chknum(bp[0])) {
  9237.                 failed = 1;
  9238.                 if (fndiags)
  9239.                   ckmakmsg(fnval,FNVALL,
  9240.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9241.                 goto fnend;
  9242.             }
  9243.             x = atoi(bp[0]);
  9244.         }
  9245. #ifdef COMMENT
  9246.         sprintf(fnval,"%d", x > 0 ? k % x : (x == 0 ? 0 : (0 - (k % (-x)))));
  9247. #else
  9248.         debug(F111,"rand",ckitoa(x),k);
  9249. #ifdef SUNOS4
  9250. /* This is really strange but on SunOS, if we are requesting random numbers */
  9251. /* between 0 and 4 or less, they always come out in sequence: 0 1 2 3 0 1 2 */
  9252. /* Shifting the result of rand() in this case gives a more random result.   */
  9253.         if (x < 5)
  9254.           k = k >> 5;
  9255. #endif /* SUNOS4 */
  9256.         if (x > 0)
  9257.           x = k % x;
  9258.         else if (x == 0)
  9259.           x = 0;
  9260.         else
  9261.           x = 0 - (k % (-x));
  9262.         debug(F101,"rand x","",x);
  9263.         sprintf(fnval,"%d", x);         /* SAFE */
  9264. #endif /* COMMENT */
  9265.         p = fnval;
  9266.         goto fnend;
  9267. #endif /* NORANDOM */
  9268.     } /* Break up big switch... */
  9269.  
  9270.     switch (y) {
  9271.       case FN_SPLIT:                    /* \fsplit(s1,a,s2,s3,mask) */
  9272.       case FN_WORD: {                   /* \fword(s1,n,s2,s3,mask) */
  9273.           int wordnum = 0;
  9274.           int splitting = 0;
  9275.           int x;
  9276.           int array = 0;
  9277.           int grouping = 0;
  9278.           int nocollapse = 0;
  9279.           char * sep = "";
  9280.           char * notsep = "";
  9281.           char * bp0 = NULL;
  9282.           char * bp1 = NULL;
  9283.           char   abuf[16];
  9284.           struct stringarray * q = NULL;
  9285.  
  9286.           splitting = (cx == FN_SPLIT); /* Our job */
  9287.  
  9288.           fnval[0] = splitting ? '0' : NUL; /* Initial return value */
  9289.           fnval[1] = NUL;
  9290.           p = fnval;
  9291.           bp0 = bp[0];                  /* Source string */
  9292.           if (!bp0) bp0 = "";
  9293.           debug(F111,"fsplit bp[0]",bp0,argn);
  9294.           if (argn < 1 || !*bp0)        /* If none, return default value */
  9295.             goto fnend;
  9296.  
  9297.           bp1 = bp[1];                  /* Function-dependent arg */
  9298.           if (!bp1) bp1 = "";           /* (array or number) */
  9299.           debug(F110,"fsplit bp[1]",bp1,0);
  9300.           if (bp[5]) {
  9301.               if (!chknum(bp[5])) {
  9302.                   failed = 1;
  9303.                   ckmakmsg(fnval,FNVALL,
  9304.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9305.                   goto fnend;
  9306.               }
  9307.               x = atoi(bp[5]);
  9308.               nocollapse = x;
  9309.           }
  9310.           if (!splitting) {             /* \fword(): n = desired word number */
  9311.               val1 = "1";               /* Default is first word */
  9312.               if (argn > 1)             /* Word number supplied */
  9313.                 if (*bp1)
  9314.                   val1 = evalx(bp1);
  9315.               if (!chknum(val1)) {
  9316.                   failed = 1;
  9317.                   ckmakmsg(fnval,FNVALL,
  9318.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9319.                   goto fnend;
  9320.               }
  9321.               n = atoi(val1);
  9322.           } else if (argn > 1 && *bp1) { /* \fsplit(): n = word count */
  9323.               ckstrncpy(abuf,bp1,16);   /* Get array reference */
  9324.               debug(F110,"fsplit abuf 1",abuf,0);
  9325.               failed = 1;               /* Assume it's bad */
  9326.               if (fndiags)              /* Default is this error message */
  9327.                 ckmakmsg(fnval,FNVALL,
  9328.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9329.               if (abuf[0] != '&')       /* "Address" of array */
  9330.                 goto fnend;             /* It's bad */
  9331.               if (abuf[2]) {            /* Check for brackets */
  9332.                   if (abuf[2] != '[' || abuf[3] != ']') {
  9333.                       goto fnend;       /* Bad */
  9334.                   }
  9335.               }
  9336.               debug(F110,"fsplit abuf 2",abuf,0);
  9337.               if (abuf[1] > 64 && abuf[1] < 91) /* Convert upper to lower */
  9338.                 abuf[1] += 32;
  9339.               if (abuf[1] < 97 || abuf[1] > 122) { /* Check for a-z */
  9340.                   goto fnend;
  9341.               }
  9342.               debug(F110,"fsplit abuf 3",abuf,0);
  9343.               array = 1;
  9344.               fnval[0] = NUL;           /* No error, erase message */
  9345.               failed = 0;               /* Unset failure flag */
  9346.               n = 0;                    /* Initialize word counter */
  9347.           }
  9348.           if (argn > 2)                 /* Have break set? */
  9349.             sep = bp[2];
  9350.           debug(F111,"fsplit sep",sep,argn);
  9351.           if (argn > 3)                 /* Have include set? */
  9352.             notsep = bp[3];
  9353.           debug(F111,"fsplit notsep",notsep,argn);
  9354.           if (argn > 4) {               /* Have grouping set? */
  9355.               char * bp4 = bp[4];
  9356.               debug(F111,"fsplit bp4",bp4,argn);
  9357.               if (!bp4) bp4 = "0";
  9358.               if (!*bp4) bp4 = "0";
  9359.               if (chknum(bp4)) {
  9360.                   grouping = atoi(bp4);
  9361.                   if (grouping == -1)
  9362.                     grouping = 127;
  9363.               } else {
  9364.                   failed = 1;
  9365.                   if (fndiags)
  9366.                     ckmakmsg(fnval,FNVALL,
  9367.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9368.                   goto fnend;
  9369.               }
  9370.           }
  9371.           /* Args parsed, now do the work */
  9372.  
  9373.           debug(F111,"fsplit bp0",bp0,n);
  9374.           q = cksplit(splitting,n,bp0,sep,notsep,grouping,0,nocollapse);
  9375.  
  9376.           wordnum = q ? q->a_size : -1; /* Check result */
  9377.           if (wordnum < 0) {
  9378.               failed = 1;               /* Failure */
  9379.               if (fndiags)
  9380.                 ckmakmsg(fnval,FNVALL,
  9381.                          (wordnum == -1) ?
  9382.                          "<ERROR:MALLOC_FAILURE:\\f" :
  9383.                          "<ERROR:TOO_MANY_WORDS:\\f",
  9384.                          fn,
  9385.                          "()>",
  9386.                          NULL
  9387.                          );
  9388.               goto fnend;
  9389.           }
  9390.           if (splitting) {              /* \fsplit() result */
  9391.               ckstrncpy(fnval,ckitoa(wordnum),FNVALL);
  9392.               if (array) {              /* Array was not declared. */
  9393.                   int i;
  9394.                   if ((x = dclarray(abuf[1],wordnum)) < 0) { /* Declare it. */
  9395.                       failed = 1;
  9396.                       if (fndiags)
  9397.                         ckmakmsg(fnval,FNVALL,
  9398.                                  "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  9399.                       goto fnend;
  9400.                   }
  9401.                   for (i = 1; i <= wordnum; i++) { /* Copy results */
  9402.                       makestr(&(a_ptr[x][i]),q->a_head[i]);
  9403.                   }
  9404.                   a_ptr[x][0] = NULL;   /* Array is 1-based */
  9405.                   makestr(&(a_ptr[x][0]),fnval); /* Element = size */
  9406.               }
  9407.           } else {                      /* \fword() result */
  9408.               char * s;
  9409.               s = q->a_head[1];
  9410.               if (!s) s = "";
  9411.               ckstrncpy(fnval,s,FNVALL);
  9412.           }
  9413.           goto fnend;                   /* Done */
  9414.       }
  9415.  
  9416.     } /* Break up big switch... */
  9417.  
  9418.     switch (y) {
  9419.  
  9420. #ifdef CK_KERBEROS
  9421.       case FN_KRB_TK:                   /* Kerberos tickets */
  9422.       case FN_KRB_NX:                   /* Kerberos next ticket */
  9423.       case FN_KRB_IV:                   /* Kerberos ticket is valid */
  9424.       case FN_KRB_FG:                   /* Kerberos Ticket flags */
  9425.       case FN_KRB_TT: {                 /* Kerberos ticket time */
  9426.           int kv = 0;                   /* Kerberos version */
  9427.           int n = 0;
  9428.           char * s = NULL;
  9429.           if (rdigits(bp[0])) {
  9430.               kv = atoi(bp[0]);
  9431.           } else {
  9432.               failed = 1;
  9433.               if (fndiags)
  9434.                 ckmakmsg(fnval,FNVALL,
  9435.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9436.               goto fnend;
  9437.           }
  9438.           if (kv != 4 && kv != 5) {
  9439.               failed = 1;
  9440.               if (fndiags)
  9441.                 ckmakmsg(fnval,FNVALL,
  9442.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9443.               goto fnend;
  9444.           }
  9445.           if ((cx == FN_KRB_IV || cx == FN_KRB_TT || cx == FN_KRB_FG) &&
  9446.                argn < 2) {
  9447.               failed = 1;
  9448.               if (fndiags)
  9449.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9450.               goto fnend;
  9451.           }
  9452.           switch (y) {
  9453.             case FN_KRB_TK:             /* Number of Kerberos tickets */
  9454. #ifdef CK_AUTHENTICATION
  9455.               switch (kv) {
  9456.                 case 4:
  9457.                   n = ck_krb4_get_tkts();
  9458.                   sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9459.                   goto fnend;
  9460.                 case 5: {
  9461.                     extern char * krb5_d_cc;
  9462.                     n = ck_krb5_get_tkts(krb5_d_cc);
  9463.                     sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9464.                     goto fnend;
  9465.                 }
  9466.               }
  9467. #else
  9468.               sprintf(fnval,"%d",0);    /* SAFE */
  9469. #endif /* CK_AUTHENTICATION */
  9470.               goto fnend;
  9471.  
  9472.             case FN_KRB_NX:             /* Kerberos next ticket */
  9473. #ifdef CK_AUTHENTICATION
  9474.               switch (kv) {
  9475.                 case 4:
  9476.                   s = ck_krb4_get_next_tkt();
  9477.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9478.                   goto fnend;
  9479.                 case 5:
  9480.                   s = ck_krb5_get_next_tkt();
  9481.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9482.                   goto fnend;
  9483.               }
  9484. #else
  9485.               sprintf(fnval,"k%d next-ticket-string",kv); /* SAFE */
  9486. #endif /* CK_AUTHENTICATION */
  9487.               goto fnend;
  9488.  
  9489.             case FN_KRB_IV:             /* Kerberos ticket is valid */
  9490. #ifdef CK_AUTHENTICATION
  9491.               /* Return 1 if valid, 0 if not */
  9492.               switch (kv) {
  9493.                 case 4:
  9494.                   n = ck_krb4_tkt_isvalid(bp[1]);
  9495.                   sprintf(fnval, "%d", n > 0 ? 1 : 0); /* SAVE */
  9496.                   goto fnend;
  9497.                 case 5: {
  9498.                     extern char * krb5_d_cc;
  9499.                     n = ck_krb5_tkt_isvalid(krb5_d_cc,bp[1]);
  9500.                     sprintf(fnval,"%d", n > 0 ? 1 : 0); /* SAFE */
  9501.                     goto fnend;
  9502.                 }
  9503.               }
  9504. #else
  9505.               sprintf(fnval,"%d",0);    /* SAFE */
  9506. #endif /* CK_AUTHENTICATION */
  9507.               goto fnend;
  9508.  
  9509.             case FN_KRB_TT:             /* Kerberos ticket time */
  9510. #ifdef CK_AUTHENTICATION
  9511.               switch (kv) {
  9512.                 case 4:
  9513.                   n = ck_krb4_tkt_time(bp[1]);
  9514.                   sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9515.                   goto fnend;
  9516.                 case 5: {
  9517.                     extern char * krb5_d_cc;
  9518.                     n = ck_krb5_tkt_time(krb5_d_cc,bp[1]);
  9519.                     sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9520.                     goto fnend;
  9521.                 }
  9522.               }
  9523. #else
  9524.               ckstrncpy(fnval,"600",FNVALL); /* Some time */
  9525. #endif /* CK_AUTHENTICATION */
  9526.               goto fnend;
  9527.  
  9528.             case FN_KRB_FG:             /* Kerberos ticket flags */
  9529. #ifdef CK_AUTHENTICATION
  9530.               switch (kv) {
  9531.                 case 4:
  9532.                   fnval[0] = '\0';
  9533.                   goto fnend;
  9534.                 case 5: {
  9535.                     extern char * krb5_d_cc;
  9536.                     ckstrncpy(fnval,ck_krb5_tkt_flags(krb5_d_cc,bp[1]),FNVALL);
  9537.                     goto fnend;
  9538.                 }
  9539.               }
  9540. #else
  9541.               fnval[0] = '\0';
  9542. #endif /* CK_AUTHENTICATION */
  9543.               goto fnend;
  9544.           }
  9545.           p = fnval;
  9546.           goto fnend;
  9547.       }
  9548. #endif /* CK_KERBEROS */
  9549.  
  9550. #ifdef FN_ERRMSG
  9551.       case FN_ERRMSG:
  9552.         if (rdigits(bp[0])) {
  9553.             k = atoi(bp[0]);
  9554.         } else {
  9555.             failed = 1;
  9556.             if (fndiags)
  9557.              ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9558.             goto fnend;
  9559.         }
  9560. #ifdef VMS
  9561.         ckstrncpy(fnval,ckvmserrstr(k),FNVALL);
  9562. #else
  9563.         x = errno;
  9564.         errno = k;
  9565.         ckstrncpy(fnval,ck_errstr(),FNVALL);
  9566.         errno = x;
  9567. #endif /* VMS */
  9568.         p = fnval;
  9569.         goto fnend;
  9570. #endif /* FN_ERRMSG */
  9571.  
  9572.       case FN_DIM: {
  9573.           int max;
  9574.           char abuf[16], *s;
  9575.           fnval[0] = NUL;               /* Initial return value */
  9576.           ckstrncpy(abuf,bp[0],16);     /* Get array reference */
  9577.           s = abuf;
  9578.           if (*s == CMDQ) s++;
  9579.           failed = 1;                   /* Assume it's bad */
  9580.           p = fnval;                    /* Point to result */
  9581.           if (fndiags)                  /* Default is this error message */
  9582.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9583.           if (s[0] != '&') {            /* "Address" of array */
  9584.               goto fnend;
  9585.           }
  9586.           if (s[2]) {
  9587.               if (s[2] != '[' || s[3] != ']') {
  9588.                   goto fnend;
  9589.               }
  9590.           }
  9591.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  9592.             s[1] += 32;
  9593.           if (s[1] < 95 || s[1] > 122) { /* Check for a-z */
  9594.               goto fnend;                       /* Bad */
  9595.           }
  9596.           if ((max = chkarray(s[1],1)) < 1)
  9597.             max = 0;
  9598.           failed = 0;                   /* Unset failure flag */
  9599.           sprintf(fnval,"%d",max);      /* SAFE */
  9600.           goto fnend;
  9601.       }
  9602.  
  9603.     } /* Break up big switch... */
  9604.  
  9605.     switch (y) {
  9606.       case FN_JDATE:
  9607.         if (argn < 1)                   /* Check number of args */
  9608.           p = ckdate();                 /* None, get today's date-time */
  9609.         else                            /* Some */
  9610.           p = bp[0];                    /* Use first */
  9611.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9612.         ckstrncpy(fnval,zjdate(p),FNVALL); /* Convert to Julian */
  9613.         p = fnval;                      /* Point to result */
  9614.         failed = 0;
  9615.         if (*p == '-') {
  9616.             failed = 1;
  9617.             if (fndiags)                /* Default is this error message */
  9618.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9619.         }
  9620.         goto fnend;
  9621.  
  9622.       case FN_DATEJ:
  9623.         ckstrncpy(fnval,jzdate(bp[0]),FNVALL); /* Convert to yyyy<dayofyear> */
  9624.         p = fnval;                      /* Point to result */
  9625.         failed = 0;
  9626.         if (*p == '-') {
  9627.             failed = 1;
  9628.             if (fndiags)                /* Default is this error message */
  9629.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9630.         }
  9631.         goto fnend;
  9632.  
  9633.       case FN_DTIM:                     /* \fcvtdate() */
  9634.       case FN_TIME:                     /* Free-format time to hh:mm:ss */
  9635.       case FN_NTIM:                     /* Time to sec since midnight */
  9636.         s = (argn > 0) ? bp[0] : "";
  9637.         if (!s) s = "";
  9638.         if (!*s)
  9639.           p = ckdate();                 /* None, get today's date */
  9640.         else                            /* Some */
  9641.           p = bp[0];                    /* Use first */
  9642.         p = ckcvtdate(p,2);             /* Convert to standard form */
  9643.         if (*p == '<') {
  9644.             failed = 1;
  9645.             if (fndiags)                /* Default is this error message */
  9646.               ckmakmsg(fnval,FNVALL,
  9647.                        "<ERROR:ARG_BAD_DATE_OR_TIME:\\f",fn,"()>",NULL);
  9648.             p = fnval;
  9649.             goto fnend;
  9650.         }
  9651.         if (argn > 1) {
  9652.             s = bp[1];
  9653.             if (!s) s = "";
  9654.             if (!*s) s = "0";
  9655.             if (!chknum(s)) {
  9656.                 failed = 1;
  9657.                 if (fndiags)
  9658.                   ckmakmsg(fnval,FNVALL,
  9659.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9660.                 p = fnval;
  9661.                 goto fnend;
  9662.             }
  9663.             x = atoi(s);
  9664.             if (x) p = shuffledate(p,x);
  9665.         }
  9666.         if (cx == FN_TIME) {
  9667.             p += 9;
  9668.         } else if (cx == FN_NTIM) {
  9669.             long sec = 0L;
  9670.             p[11] = NUL;
  9671.             p[14] = NUL;
  9672.             sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  9673.             sprintf(fnval,"%ld",sec);   /* SAFE */
  9674.             p = fnval;
  9675.         }
  9676.         goto fnend;
  9677.  
  9678.       case FN_MJD:                      /* Modified Julian Date */
  9679.         if (argn < 1)                   /* Check number of args */
  9680.           p = zzndate();                /* None, get today's date-time */
  9681.         else                            /* Some */
  9682.           p = bp[0];                    /* Use first */
  9683.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9684.         if (*p == '-') {
  9685.             failed = 1;
  9686.             if (fndiags)                /* Default is this error message */
  9687.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9688.             goto fnend;
  9689.         }
  9690.         /* Convert to modified Julian date */
  9691.         sprintf(fnval,"%ld",mjd(p));    /* SAFE */
  9692.         p = fnval;                      /* Point to result */
  9693.         goto fnend;
  9694.  
  9695.       case FN_MJD2: {
  9696.           long k = 0L;
  9697.           int n = 0;
  9698.           p = evalx(bp[0]);
  9699.           if (*p == '-') {
  9700.               p++;
  9701.               n = 1;
  9702.           }
  9703.           if (!rdigits(p)) {
  9704.               failed = 1;
  9705.               evalerr(fn);
  9706.               p = fnval;
  9707.               goto fnend;
  9708.           } else {
  9709.               k = atol(p);
  9710.               if (n) k = -k;
  9711.           }
  9712.           ckstrncpy(fnval,mjd2date(k),FNVALL); /* Convert to Date */
  9713.           p = fnval;                    /* Point to result */
  9714.           failed = 0;
  9715.           goto fnend;
  9716.       }
  9717.  
  9718. #ifndef NODIAL
  9719.       case FN_PNCVT: {                  /* Convert phone number */
  9720.           extern char * pncvt();
  9721.           failed = 0;
  9722.           p = pncvt(bp[0]);
  9723.           if (!p) p = "";
  9724.           if (!*p) {
  9725.             failed = 1;
  9726.             if (fndiags)                /* Default is this error message */
  9727.               ckmakmsg(fnval,FNVALL,
  9728.                        "<ERROR:ARG_BAD_PHONENUM:\\f",fn,"()>",NULL);
  9729.         }
  9730.         goto fnend;
  9731.       }
  9732. #endif /* NODIAL */
  9733.  
  9734.       case FN_DAY:
  9735.       case FN_NDAY:
  9736.         if (argn < 1)                   /* Check number of args */
  9737.           p = zzndate();                /* None, get today's date-time */
  9738.         else                            /* Some */
  9739.           p = bp[0];                    /* Use first */
  9740.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9741.         if (*p == '-') {
  9742.             failed = 1;
  9743.             if (fndiags)                /* Default is this error message */
  9744.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9745.             goto fnend;
  9746.         }
  9747.         failed = 0;
  9748.         z = mjd(p);                     /* Convert to modified Julian date */
  9749.         z = z % 7L;
  9750.         if (z < 0) z = 0 - z;
  9751.         k = ((int)z + 3) % 7;           /* Day of week */
  9752.         p = fnval;                      /* Point to result */
  9753.         if (cx == FN_NDAY)
  9754.           sprintf(fnval,"%d",k);        /* SAFE */
  9755.         else
  9756.           ckstrncpy(fnval,wkdays[k],FNVALL);
  9757.         goto fnend;
  9758.  
  9759.       case FN_N2TIM: {                  /* Sec since midnight to hh:mm:ss */
  9760.           long k = 0L;
  9761.           int n = 0, hh, mm, ss;
  9762.           char * s = bp[0];
  9763.           if (argn < 1)                 /* If no arg substitute 0 */
  9764.             s = "0";
  9765.           p = evalx(s);                 /* Evaluate expression silently */
  9766.           if (*p == '-') {              /* Check result for minus sign */
  9767.               p++;
  9768.               n = 1;
  9769.           }
  9770.           if (!rdigits(p)) { /* Check for numeric */
  9771.               failed = 1;
  9772.               ckmakmsg(fnval,FNVALL,
  9773.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9774.               p = fnval;
  9775.               goto fnend;
  9776.           } else {
  9777.               k = atol(p);
  9778.               if (n) k = -k;
  9779.           }
  9780.           if (k < 0) {                  /* Check for negative */
  9781.               failed = 1;
  9782.               if (fndiags)
  9783.                 ckmakmsg(fnval,FNVALL,
  9784.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9785.               p = fnval;
  9786.               goto fnend;
  9787.           }
  9788.           hh = k / 3600L;               /* Have positive number */
  9789.           mm = (k % 3600L) / 60L;       /* break it down... */
  9790.           ss = ((k % 3600L) % 60L);
  9791.  
  9792.           sprintf(fnval,"%02d:%02d:%02d",hh,mm,ss); /* SAFE */
  9793.           p = fnval;
  9794.           failed = 0;
  9795.           goto fnend;
  9796.       }
  9797.  
  9798.       case FN_PERM: {                   /* File permissions */
  9799.           p = fnval;
  9800.           z = zchki(bp[0]);
  9801.           if (z < 0) {
  9802.               failed = 1;
  9803.               if (fndiags) {
  9804.                   if (z == -1)
  9805.                     ckmakmsg(fnval,FNVALL,
  9806.                              "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  9807.                   else if (z == -2)
  9808.                     ckmakmsg(fnval,FNVALL,
  9809.                              "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  9810.                   else if (z == -3)
  9811.                     ckmakmsg(fnval,FNVALL,
  9812.                              "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  9813.                   else
  9814.                     ckmakmsg(fnval,FNVALL,
  9815.                              "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  9816.               }
  9817.               goto fnend;
  9818.           }
  9819. #ifdef CK_PERMS
  9820.           ckstrncpy(fnval,ziperm(bp[0]),FNVALL);
  9821. #else
  9822.           ckstrncpy(fnval,"(unknown)",FNVALL);
  9823. #endif /* CK_PERMS */
  9824.           goto fnend;
  9825.       }
  9826.       case FN_TLOOK:                    /* tablelook() */
  9827.       case FN_ALOOK: {                  /* arraylook() */
  9828.           int i, x, hi, lo, max, cmdlen;
  9829.           char abuf[16], *s, *pat;
  9830.           char kwbuf[256];
  9831.           char delim = ':';
  9832.           failed = 1;                   /* Assume failure */
  9833.           ckstrncpy(fnval,"-1",FNVALL);
  9834.           pat = bp[0];                  /* Point to search pattern */
  9835.           if (!pat) pat = "";           /* Watch out for NULL pointer */
  9836.           cmdlen = strlen(pat);         /* Get pattern length */
  9837.           if (argn < 2 /* || cmdlen < 1 */ ) { /* Need two args */
  9838.               if (fndiags)
  9839.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9840.               goto fnend;
  9841.           }
  9842.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  9843.           if (argn > 2)
  9844.             delim = *(bp[2]);
  9845.           s = abuf;
  9846.           if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Get index and bounds */
  9847.               if (fndiags)
  9848.                ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9849.               goto fnend;
  9850.           }
  9851.           p = fnval;                    /* Point to result */
  9852.           max = a_dim[x];               /* Size of array */
  9853.           if (lo < 0) lo = 0;           /* Use given range if any */
  9854.           if (lo > max) lo = max;
  9855.           if (hi < 0) hi = max;
  9856.           if (hi > max) hi = max;
  9857.           failed = 0;                   /* Unset failure flag */
  9858.           if (max < 1)
  9859.             goto fnend;
  9860.           kwbuf[255] = NUL;
  9861.           for (i = lo; i <= hi; i++) {
  9862.               if (!a_ptr[x][i])
  9863.                 continue;
  9864.               if (cx == FN_ALOOK) {
  9865.                   if (ckmatch(pat,a_ptr[x][i],inpcas[cmdlvl],1+4)) {
  9866.                       sprintf(fnval,"%d",i); /* SAFE */
  9867.                       goto fnend;
  9868.                   }
  9869.               } else if (cx == FN_TLOOK) {
  9870.                   char * aa;
  9871.                   int j = 0, v = 0, len;
  9872.                   if (i == hi)
  9873.                     break;
  9874.                   aa = a_ptr[x][i];     /* Point to this array element */
  9875.                   if (!aa) aa = "";
  9876.                   while (j < 254 && *aa) { /* Isolate keyword */
  9877.                       if (*aa == delim)
  9878.                         break;
  9879.                       kwbuf[j++] = *aa++;
  9880.                   }
  9881.                   kwbuf[j] = NUL;
  9882.                   len = j;
  9883.                   v = 0;
  9884.                   if ((len == cmdlen && !ckstrcmp(kwbuf,pat,len,0)) ||
  9885.                       ((v = !ckstrcmp(kwbuf,pat,cmdlen,0)) &&
  9886.                        ckstrcmp(a_ptr[x][i+1],pat,cmdlen,0))) {
  9887.                       sprintf(fnval,"%d",i); /* SAFE */
  9888.                       goto fnend;
  9889.                   }
  9890.                   if (v) {              /* Ambiguous */
  9891.                       ckstrncpy(fnval,"-2",FNVALL);
  9892.                       goto fnend;
  9893.                   }
  9894.               }
  9895.           }
  9896.           if (cx == FN_TLOOK) {         /* tablelook() last element */
  9897.               ckstrncpy(fnval,"-1",FNVALL);
  9898.               if (!ckstrcmp(a_ptr[x][hi],pat,cmdlen,0))
  9899.                 sprintf(fnval,"%d",hi); /* SAFE */
  9900.           }
  9901.           goto fnend;
  9902.       }
  9903.       case FN_TOB64:                    /* Base-64 conversion */
  9904.       case FN_FMB64:
  9905.         p = fnval;
  9906.         *p = NUL;
  9907.         if (argn < 1)
  9908.           goto fnend;
  9909.         if (cx == FN_TOB64) {
  9910.             x = b8tob64(bp[0],-1,fnval,FNVALL);
  9911.         } else {
  9912.             x = strlen(bp[0]);
  9913.             if (x % 4) {                /* length must be multiple of 4 */
  9914.                 failed = 1;
  9915.                 ckmakmsg(fnval,FNVALL,
  9916.                          "<ERROR:ARG_INCOMPLETE:\\f",fn,"()>",NULL);
  9917.                 goto fnend;
  9918.             }
  9919.             b64tob8(NULL,0,NULL,0);     /* Reset */
  9920.             x = b64tob8(bp[0],-1,fnval,FNVALL);
  9921.             b64tob8(NULL,0,NULL,0);     /* Reset again */
  9922.         }
  9923.         if (x < 0) {
  9924.             failed = 1;
  9925.             if (fndiags) {
  9926.                 char * m = "INTERNAL_ERROR";
  9927.                 switch (x) {
  9928.                   case -1: m = "ARG_TOO_LONG"; break;
  9929.                   case -2: m = "ARG_OUT_OF_RANGE"; break;
  9930.                 }
  9931.                 if (ckmakmsg(fnval,FNVALL,"<ERROR:",m,"\\f",fn) > 0)
  9932.                   ckstrncat(fnval,"()>",FNVALL);
  9933.             }
  9934.         }
  9935.         goto fnend;
  9936.  
  9937.       case FN_ABS: {
  9938.           char * s;
  9939.           s = bp[0];
  9940.           if (*s == '-' || *s == '+')
  9941.             s++;
  9942.           if (!rdigits(s)) {
  9943.               if (fndiags)
  9944.                 ckmakmsg(fnval,FNVALL,
  9945.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9946.               goto fnend;
  9947.           }
  9948.           ckstrncpy(fnval,s,FNVALL);
  9949.           goto fnend;
  9950.       }
  9951.  
  9952.       case FN_AADUMP: {
  9953.           char abuf[16], *s = NULL, **ap = NULL, **vp = NULL;
  9954.           char pattern[VNAML];
  9955.           int slen, i, j, k, first = -1;
  9956.           extern int xdelmac();
  9957.           p = fnval;
  9958.           if (argn < 2) {
  9959.               if (fndiags)
  9960.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG2:\\f",fn,"()>",NULL);
  9961.               goto fnend;
  9962.           }
  9963.           debug(F101,"aaconvert argn","",argn);
  9964.           s = bp[0];
  9965.           slen = strlen(s);
  9966.  
  9967.           /* Count elements so we can create the array */
  9968.  
  9969.           ckmakmsg(pattern,VNAML,s,"<*>",NULL,NULL);
  9970.           for (k = 0, i = 0; i < nmac; i++) {
  9971.               if (ckmatch(pattern,mactab[i].kwd,0,1)) {
  9972.                   if (first < 0)        /* Remember location of first match */
  9973.                     first = i;
  9974.                   k++;
  9975.               }
  9976.           }
  9977.           debug(F101,"aaconvert matches","",k);
  9978.           debug(F101,"aaconvert first","",first);
  9979.           fnval[0] = NUL;               /* Initial return value */
  9980.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  9981.           s = abuf;
  9982.           if (*s == CMDQ) s++;
  9983.           p = fnval;                    /* Point to result */
  9984.           if (fndiags)                  /* Default is this error message */
  9985.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9986.           if (s[0] != '&')              /* Address of array */
  9987.             goto fnend;
  9988.           if (s[2])
  9989.             if (s[2] != '[' || s[3] != ']')
  9990.               goto fnend;
  9991.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  9992.             s[1] += 32;
  9993.           if ((x = dclarray(s[1],k)) < 0) /* Declare array to size */
  9994.             goto fnend;
  9995.           ap = a_ptr[x];                /* Point to array we just declared */
  9996.           debug(F111,"aaconvert array 1",abuf,ap);
  9997.           abuf[0] = NUL;
  9998.           if (argn > 2) {
  9999.               ckstrncpy(abuf,bp[2],16); /* Get value array reference */
  10000.               s = abuf;
  10001.               if (*s == CMDQ) s++;
  10002.               if (s[0] != '&')          /* Address of array */
  10003.                 goto fnend;
  10004.               if (s[2])
  10005.                 if (s[2] != '[' || s[3] != ']')
  10006.                   goto fnend;
  10007.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  10008.                 s[1] += 32;
  10009.               if ((x = dclarray(s[1],k)) < 0)
  10010.                 goto fnend;
  10011.               vp = a_ptr[x];            /* Point to array we just declared */
  10012.           }
  10013.           debug(F111,"aaconvert array 2",abuf,vp);
  10014.           makestr(&ap[0],ckitoa(k));
  10015.           if (vp) makestr(&vp[0],ckitoa(k));
  10016.           if (fndiags)
  10017.            ckmakmsg(fnval,FNVALL,"<ERROR:ASSOCIATIVE_ARRAY:\\f",fn,"()>",NULL);
  10018.  
  10019.           /* Copy macro index & value to the arrays and then remove the */
  10020.           /* macro, so the 'first' pointer keeps indicating the next one. */
  10021.           /* We could combine the initial counting loop with this one but */
  10022.           /* then it would be harder to create the array and anyway this */
  10023.           /* function is plenty fast as it is. */
  10024.  
  10025.           for (i = 1; i <= k; ) {
  10026.               if (!ckmatch(pattern,mactab[first].kwd,0,1)) {
  10027.                   debug(F111,"aaconvert oddball",mactab[first].kwd,first);
  10028.                   first++;
  10029.                   continue;
  10030.               }
  10031.               ckstrncpy(tmpbuf,mactab[first].kwd,TMPBUFSIZ); /* Macro name */
  10032.               s = tmpbuf;                       /* Make writeable copy */
  10033.               s += slen;                        /* Isolate "index" */
  10034.               j = strlen(s) - 1;
  10035.               if (*s != '<' || *(s+j) != '>') { /* Check syntax */
  10036.                   /* This shouldn't happen */
  10037.                   debug(F111,"aaconvert ERROR",mactab[first].kwd,first);
  10038.                   goto fnend;
  10039.               }
  10040.               *(s+j) = NUL;             /* Remove final '>' */
  10041.               debug(F111,"aaconvert",s+1,i);
  10042.               makestr(&(ap[i]),s+1);    /* Set first array to index */
  10043.               if (vp)
  10044.                 makestr(&(vp[i]),mactab[first].mval); /* 2nd to value */
  10045.               if (xdelmac(first) < 0)
  10046.                 goto fnend;
  10047.               i++;
  10048.           }
  10049.           sprintf(fnval,"%d",k);        /* SAFE */
  10050.           p = fnval;                    /* Return size of array */
  10051.           debug(F110,"aaconvert return",p,0);
  10052.           failed = 0;                   /* Unset failure flag */
  10053.           goto fnend;
  10054.       }
  10055.  
  10056.     } /* End of switch() */
  10057.  
  10058. #ifdef FNFLOAT
  10059. /*
  10060.   Floating-point functions.  To be included only if FNFLOAT is defined, which
  10061.   should happen only if CKFLOAT is also defined, and if the math library is
  10062.   linked in.  Even then, we might have float-vs-double confusion as well as
  10063.   confusion about what the final "%f" format effector is supposed to reference
  10064.   (32 bits, 64 bits, etc).  Expect trouble if CKFLOAT does not match the data
  10065.   type of math library functions or args.
  10066. */
  10067.     if (cx == FN_FPABS ||               /* Floating-point functions */
  10068.         cx == FN_FPADD ||
  10069.         cx == FN_FPDIV ||
  10070.         cx == FN_FPEXP ||
  10071.         cx == FN_FPLOG ||
  10072.         cx == FN_FPLN  ||
  10073.         cx == FN_FPMOD ||
  10074.         cx == FN_FPMAX ||
  10075.         cx == FN_FPMIN ||
  10076.         cx == FN_FPMUL ||
  10077.         cx == FN_FPPOW ||
  10078.         cx == FN_FPSQR ||
  10079.         cx == FN_FPINT ||
  10080.         cx == FN_FPSUB ||
  10081.         cx == FN_FPROU ||
  10082.         cx == FN_FPSIN ||
  10083.         cx == FN_FPCOS ||
  10084.         cx == FN_FPTAN) {
  10085.         CKFLOAT farg[2], fpresult = 0.0;
  10086.         char fpbuf[64], * bp0;
  10087.         double dummy;
  10088.         /* int sign = 0; */
  10089.         int i, j, places = 0;
  10090.         int argcount = 1;
  10091.  
  10092.         failed = 1;
  10093.         p = fnval;
  10094.         bp0 = bp[0];
  10095.         if (!bp0)
  10096.           bp0 = "0";
  10097.         else if (!*bp0)
  10098.           bp0 = "0";
  10099.         if (!isfloat(bp0,0)) {
  10100.             k = mxlook(mactab,bp0,nmac);
  10101.             bp0 = (k > -1) ? mactab[k].mval : NULL;
  10102.             if (bp0) {
  10103.                 if (!isfloat(bp0,0)) {
  10104.                     if (fndiags)
  10105.                       ckmakmsg(fnval,FNVALL,
  10106.                                "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10107.                     goto fnend;
  10108.                 }
  10109.             }
  10110.         }
  10111.         if (cx == FN_FPINT) {           /* Float to int */
  10112.             failed = 0;
  10113.             ckstrncpy(fnval,bp0,FNVALL);
  10114.             for (i = 0; fnval[i]; i++) {
  10115.                 if (fnval[i] == '.') {
  10116.                     fnval[i] = NUL;
  10117.                     break;
  10118.                 }
  10119.             }
  10120.             goto fnend;
  10121.         }
  10122.         switch (y) {                    /* These need 2 args */
  10123.           case FN_FPADD:
  10124.           case FN_FPDIV:
  10125.           case FN_FPMOD:
  10126.           case FN_FPMAX:
  10127.           case FN_FPMIN:
  10128.           case FN_FPMUL:
  10129.           case FN_FPPOW:
  10130.           case FN_FPSUB:
  10131.             argcount = 2;
  10132.         }
  10133.         /* Missing arguments are supplied as 0.0 */
  10134.  
  10135.         debug(F111,fn,"argcount",argcount);
  10136.         for (i = 0; i < argcount; i++) { /* Get floating-point args */
  10137. #ifdef DEBUG
  10138.             if (deblog) {
  10139.                 ckmakmsg(fpbuf,
  10140.                          64,
  10141.                          "bp[",
  10142.                          ckitoa(i),
  10143.                          bp[i] ? bp[i] : "(null)",
  10144.                          "]"
  10145.                          );
  10146.                 debug(F100,fpbuf,"",0);
  10147.             }
  10148. #endif /* DEBUG */
  10149.             if (!bp[i]) {
  10150.                 farg[i] = 0.0;
  10151.             } else if (!*(bp[i])) {
  10152.                 farg[i] = 0.0;
  10153.             } else if (!isfloat(bp[i],0)) {
  10154.                 char * tmp;
  10155.                 k = mxlook(mactab,bp[i],nmac);
  10156.                 tmp = (k > -1) ? mactab[k].mval : NULL;
  10157.                 if (tmp) {
  10158.                     if (!isfloat(tmp,0)) {
  10159.                         if (fndiags)
  10160.                           ckmakmsg(fnval,FNVALL,
  10161.                                    "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10162.                         goto fnend;
  10163.                     }
  10164.                 }
  10165.             }
  10166.             farg[i] = floatval;
  10167.  
  10168. #ifdef DEBUG
  10169.             if (deblog) {
  10170.                 sprintf(fpbuf,"farg[%d]=%f",i,farg[i]); /* SAFE */
  10171.                 debug(F100,fpbuf,"",0);
  10172.             }
  10173. #endif /* DEBUG */
  10174.         }
  10175.         if (bp[argcount]) {             /* Get decimal places */
  10176.             char * s;
  10177.             s = bp[argcount];
  10178.             if (!s) s = "";
  10179.             if (!*s) s = "0";
  10180.             s = evalx(s);
  10181.             if (!s) s = "";
  10182.             if (!*s) {
  10183.                 evalerr(fn);
  10184.                 goto fnend;
  10185.             }
  10186.             places = atoi(s);
  10187.         }
  10188.         errno = 0;
  10189.         failed = 0;
  10190.         switch (y) {                    /* Now do the requested function */
  10191.           case FN_FPABS:                /* Floating-point absolute value */
  10192. #ifndef COMMENT
  10193.             fpresult = fabs(farg[0]);
  10194. #else
  10195.             if (farg[0] < 0.0)
  10196.               fpresult = 0.0 - farg[0];
  10197. #endif /* COMMENT */
  10198.             break;
  10199.           case FN_FPADD:                /* FP add */
  10200.             fpresult = farg[0] + farg[1];
  10201.             break;
  10202.           case FN_FPDIV:                /* FP divide */
  10203.           case FN_FPMOD:                /* FP modulus */
  10204.             if (!farg[1]) {
  10205.                 failed = 1;
  10206.                 if (fndiags)
  10207.                   ckmakmsg(fnval,FNVALL,
  10208.                            "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  10209.             } else
  10210.               fpresult = (cx == FN_FPDIV) ?
  10211.                 (farg[0] / farg[1]) :
  10212.                   fmod(farg[0],farg[1]);
  10213.             break;
  10214.           case FN_FPEXP:                /* FP e to the x */
  10215.             fpresult = (CKFLOAT) exp(farg[0]);
  10216.             break;
  10217.           case FN_FPLOG:                /* FP base-10 logarithm */
  10218.           case FN_FPLN:                 /* FP natural logarithm */
  10219.             if (farg[0] < 0.0) {
  10220.                 failed = 1;
  10221.                 if (fndiags)
  10222.                   ckmakmsg(fnval,FNVALL,
  10223.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10224.             } else
  10225.               fpresult = (cx == FN_FPLOG) ? log10(farg[0]) : log(farg[0]);
  10226.             break;
  10227.           case FN_FPMUL:                /* FP multiply */
  10228.             fpresult = farg[0] * farg[1];
  10229.             break;
  10230.           case FN_FPPOW:                /* FP raise to a power */
  10231.             fpresult = modf(farg[1],&dummy);
  10232.             if ((!farg[0] && farg[1] <= 0.0) ||
  10233.                 (farg[0] < 0.0 && fpresult)) {
  10234.                 failed = 1;
  10235.                 if (fndiags)
  10236.                   ckmakmsg(fnval,FNVALL,
  10237.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10238.             } else
  10239.               fpresult = pow(farg[0],farg[1]);
  10240.             break;
  10241.           case FN_FPSQR:                /* FP square root */
  10242.             if (farg[0] < 0.0) {
  10243.                 failed = 1;
  10244.                 if (fndiags)
  10245.                   ckmakmsg(fnval,FNVALL,
  10246.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10247.             } else
  10248.               fpresult = sqrt(farg[0]);
  10249.             break;
  10250.           case FN_FPSUB:                /* FP subtract */
  10251.             fpresult = farg[0] - farg[1];
  10252.             break;
  10253.           case FN_FPROU:                /* FP round */
  10254.             fpresult = farg[0];
  10255.             break;
  10256.           case FN_FPSIN:                /* FP sine */
  10257.             fpresult = (CKFLOAT) sin(farg[0]);
  10258.             break;
  10259.           case FN_FPCOS:                /* FP cosine */
  10260.             fpresult = (CKFLOAT) cos(farg[0]);
  10261.             break;
  10262.           case FN_FPTAN:                /* FP tangent */
  10263.             fpresult = (CKFLOAT) tan(farg[0]);
  10264.             break;
  10265.           case FN_FPMAX:
  10266.             fpresult = (farg[0] > farg[1]) ? farg[0] : farg[1];
  10267.             break;
  10268.           case FN_FPMIN:
  10269.             fpresult = (farg[0] < farg[1]) ? farg[0] : farg[1];
  10270.             break;
  10271.         }
  10272.  
  10273.         /* Get here with fpresult = function result */
  10274.  
  10275.         if (errno) {                    /* If range or domain error */
  10276.             failed = 1;
  10277.             if (fndiags)
  10278.               ckmakmsg(fnval,FNVALL,
  10279.                        "<ERROR:FLOATING-POINT-OP:\\f",fn,"()>",NULL);
  10280.         }
  10281.         if (failed)                     /* and/or any other kind of error, */
  10282.           goto fnend;                   /* fail. */
  10283. #ifndef COMMENT
  10284.         /* Call routine containing code that was formerly inline */
  10285.         ckstrncpy(fnval,fpformat(fpresult,places,cx == FN_FPROU),FNVALL);
  10286. #else
  10287.         {
  10288.             char fbuf[16];              /* For creating printf format */
  10289.             if (!fp_rounding &&         /* If printf doesn't round, */
  10290.                 (places > 0 ||          /* round result to decimal places. */
  10291.                  (places == 0 && cx == FN_FPROU)))
  10292.               fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  10293.             if (places > 0) {                   /* If places specified */
  10294.                 /* use specified places to write given number of digits */
  10295.                 sprintf(fbuf,"%%0.%df",places); /* SAFE */
  10296.                 sprintf(fnval,fbuf,fpresult);   /* SAFE */
  10297.             } else {                            /* Otherwise... */
  10298. #ifdef COMMENT
  10299. /*
  10300.   Here we want to print exactly fp_digits significant digits, no matter which
  10301.   side of the decimal point they are on.  That is, we want want the default
  10302.   format to show the maximum number of non-garbage digits, AND we want the last
  10303.   such digit to be rounded.  Of course there is no way to do that, since the
  10304.   digit after the last non-garbage digit is, well, garbage.  So the following
  10305.   clever ruse does no good.
  10306. */
  10307.                 int sign = 0, m = 0;
  10308.                 sprintf(fnval,"%f",fpresult);
  10309.                 if (fnval[0] == '-') sign = 1;
  10310.                 for (i = sign; i < FNVALL; i++) {
  10311.                     if (isdigit(fnval[i]))
  10312.                       m++;
  10313.                     else
  10314.                       break;
  10315.                 }
  10316.                 if (m > 1) {
  10317.                     int d = fp_digits - m;
  10318.                     if (d < 1) d = 1;
  10319.                     sprintf(fbuf,"%%%d.%df",fp_digits+sign+1,d);
  10320.                 } else {
  10321.                     sprintf(fbuf,"%%0.%df",fp_digits);
  10322.                 }
  10323.                 sprintf(fnval,fbuf,fpresult);
  10324. #else
  10325.                 /* Go for max precision */
  10326.                 sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  10327.                 sprintf(fnval,fbuf,fpresult); /* SAFE */
  10328.  
  10329. #endif /* COMMENT */
  10330.             }
  10331.             if (fnval[0] == '-') sign = 1;
  10332.         }
  10333.         debug(F111,"fpresult 1",fnval,errno); /* Check for over/underflow */
  10334.         for (i = sign; fnval[i]; i++) { /* Give requested decimal places */
  10335.             if (fnval[i] == '.')        /* First find the decimal point */
  10336.               break;
  10337.             else if (i > fp_digits + sign - 1) /* replacing garbage */
  10338.               fnval[i] = '0';           /* digits with 0... */
  10339.         }
  10340.         if (fnval[i] == '.') {          /* Have decimal point */
  10341.             int gotend = 0;
  10342.             /* d < 0 so truncate fraction */
  10343.             if (places < 0 || (places == 0 && cx == FN_FPROU)) {
  10344.                 fnval[i] = NUL;
  10345.             } else if (places > 0) {    /* d > 0 so this many decimal places */
  10346.                 i++;                           /* First digit after decimal */
  10347.                 for (j = 0; j < places; j++) { /* Truncate after d decimal */
  10348.                     if (!fnval[j+i])           /* places or extend to d  */
  10349.                       gotend = 1;              /* decimal places. */
  10350.                     if (gotend || j+i+sign > fp_digits)
  10351.                       fnval[j+i] = '0';
  10352.                 }
  10353.                 fnval[j+i] = NUL;
  10354.             } else {                    /* d == 0 so Do The Right Thing */
  10355.                 for (j = (int)strlen(fnval) - 1; j > i+1; j--) {
  10356.                     if ((j - sign) > fp_digits)
  10357.                       fnval[j] = '0';
  10358.                     if (fnval[j] == '0')
  10359.                       fnval[j] = NUL;   /* Strip useless trailing 0's. */
  10360.                     else
  10361.                       break;
  10362.                 }
  10363.             }
  10364.         }
  10365. #endif /* COMMENT */
  10366.         debug(F111,"fpresult 2",fnval,errno);
  10367.         goto fnend;
  10368.  
  10369.     }
  10370. #endif /* FNFLOAT */
  10371.  
  10372. #ifdef CKCHANNELIO
  10373.     if (cx == FN_FSTAT  ||              /* File functions */
  10374.         cx == FN_FPOS   ||
  10375.         cx == FN_FEOF   ||
  10376.         cx == FN_FGCHAR ||
  10377.         cx == FN_FGLINE ||
  10378.         cx == FN_FGBLK  ||
  10379.         cx == FN_FPCHAR ||
  10380.         cx == FN_FPLINE ||
  10381.         cx == FN_FPBLK  ||
  10382.         cx == FN_NLINE  ||
  10383.         cx == FN_FERMSG ||
  10384.         cx == FN_FILNO) {
  10385.         int x = 0, t = 0, channel;
  10386.         long z;
  10387.         extern int z_maxchan;
  10388.  
  10389.         failed = 1;                     /* Assume failure */
  10390.         p = fnval;                      /* until we validate args */
  10391.         if (cx == FN_FERMSG) {
  10392.             extern int z_error;
  10393.             if (argn < 1) {
  10394.                 x = z_error;
  10395.             } else if (chknum(bp[0])) {
  10396.                 x = atoi(bp[0]);
  10397.             } else if (fndiags)
  10398.               ckmakmsg(fnval,FNVALL,
  10399.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10400.             failed = 0;
  10401.             ckstrncpy(fnval,ckferror(x),FNVALL);
  10402.             goto fnend;
  10403.         }
  10404.         if (argn < 1) {                 /* All file functions need channel */
  10405.             if (fndiags)
  10406.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10407.             goto fnend;
  10408.         }
  10409.         if (rdigits(bp[0])) {           /* Channel must be numeric */
  10410.             channel = atoi(bp[0]);
  10411.         } else {                        /* Fail if it isn't */
  10412.             if (fndiags)
  10413.               ckmakmsg(fnval,FNVALL,
  10414.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10415.             goto fnend;
  10416.         }
  10417.         if (channel < 0 || channel > z_maxchan) { /* Check channel range */
  10418.             if (fndiags)
  10419.               ckmakmsg(fnval,FNVALL,
  10420.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10421.             goto fnend;
  10422.         }
  10423.         x = z_getmode(channel);         /* Find out about the channel */
  10424.  
  10425.         failed = 0;                     /* Assume success from here down */
  10426.         if (cx == FN_FSTAT) {           /* Status / modes of channel */
  10427.             if (x > -1)
  10428.               x &= FM_RWB;              /* Mask out irrelevant bits */
  10429.             else                        /* In this case not open is OK */
  10430.               x = 0;                    /* 0 if not open, 1-7 if open */
  10431.             sprintf(fnval,"%d",x);      /* SAFE */
  10432.             goto fnend;
  10433.         } else if (x < 1) {             /* Not \f_status() so must be open */
  10434.             failed = 1;
  10435.             if (fndiags)
  10436.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_OPEN:\\f",fn,"()>",NULL);
  10437.             goto fnend;
  10438.         }
  10439.         switch (y) {                    /* Do the requested function */
  10440.           case FN_FPOS:                 /* Get position */
  10441.             z = z_getpos(channel);
  10442.             sprintf(fnval,"%ld",z);     /* SAFE */
  10443.             goto fnend;
  10444.  
  10445.           case FN_NLINE:                /* Get line number */
  10446.             z = z_getline(channel);
  10447.             sprintf(fnval,"%ld",z);     /* SAFE */
  10448.             goto fnend;
  10449.  
  10450.           case FN_FEOF:                 /* Check EOF */
  10451.             t = 0;
  10452.             if (x & FM_EOF) t = 1;
  10453.             sprintf(fnval,"%d",t);      /* SAFE */
  10454.             goto fnend;
  10455.  
  10456.           case FN_FILNO:                /* Get file handle */
  10457.             x = z_getfnum(channel);
  10458.             sprintf(fnval,"%d",x);      /* SAFE */
  10459.             goto fnend;
  10460.  
  10461.           case FN_FPBLK:                /* Read or write block */
  10462.           case FN_FGBLK:
  10463.             if (argn < 2) {
  10464.                 if (fndiags)
  10465.                   ckmakmsg(fnval,FNVALL,
  10466.                            "<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10467.                 goto fnend;
  10468.             }
  10469.             if (rdigits(bp[1])) {
  10470.                 t = atoi(bp[1]);
  10471.             } else {
  10472.                 if (fndiags)
  10473.                   ckmakmsg(fnval,FNVALL,
  10474.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10475.                 goto fnend;
  10476.             }
  10477.           case FN_FGCHAR:               /* Read or write character or line */
  10478.           case FN_FPCHAR:
  10479.           case FN_FGLINE:
  10480.           case FN_FPLINE:
  10481.             fnval[0] = NUL;
  10482.             switch (y) {
  10483.               case FN_FGCHAR: t = z_in(channel,fnval,FNVALL,1,1); break;
  10484.               case FN_FGLINE: t = z_in(channel,fnval,FNVALL,FNVALL-1,0); break;
  10485.               case FN_FGBLK:
  10486.                 if (t >= FNVALL) t = FNVALL - 1;
  10487.                 t = z_in(channel,fnval,FNVALL,t,1);
  10488.                 break;
  10489.               case FN_FPCHAR: t = z_out(channel,bp[1],1,1);  break;
  10490.               case FN_FPLINE: t = z_out(channel,bp[1],-1,0); break;
  10491.               case FN_FPBLK:  t = z_out(channel,bp[1],-1,1); break;
  10492.             }
  10493.             if (t < 0) {                /* Handle read/write error */
  10494.                 failed = 1;
  10495.                 if (fndiags && t != FX_EOF)
  10496.                   ckmakmsg(fnval,FNVALL,
  10497.                            "<ERROR:FILE_ERROR_%d:\\f",fn,"()>",NULL);
  10498.                 goto fnend;
  10499.             }
  10500.             if (cx == FN_FGCHAR)        /* Null terminate char */
  10501.               fnval[1] = NUL;
  10502.             /* Write (put) functions return numeric status code */
  10503.             if (cx == FN_FPCHAR || cx == FN_FPLINE || cx == FN_FPBLK)
  10504.               sprintf(fnval,"%d",t);    /* SAFE */
  10505.             goto fnend;
  10506.         }
  10507.     }
  10508. #endif /* CKCHANNELIO */
  10509.  
  10510.     if (cx == FN_PATTERN) {             /* \fpattern() */
  10511.         ispattern = 1;
  10512.         if (argn > 0) {
  10513.             p = fnval;
  10514.             ckstrncpy(fnval,bp[0],FNVALL);
  10515.         } else p = "";
  10516.         goto fnend;
  10517.     }
  10518.  
  10519.     if (cx == FN_HEX2N || cx == FN_OCT2N) { /* \fhex2n(), \foct2n() */
  10520.         p = "0";
  10521.         if (argn < 1)
  10522.           goto fnend;
  10523.         p = ckradix(bp[0], ((cx == FN_HEX2N) ? 16 : 8), 10);
  10524.         if (!p) {
  10525.             if (fndiags)
  10526.               ckmakmsg(fnval,FNVALL,
  10527.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10528.             goto fnend;
  10529.         }
  10530.         failed = 0;
  10531.         ckstrncpy(fnval,p,FNVALL);
  10532.         p = fnval;
  10533.         goto fnend;
  10534.     }
  10535.  
  10536.     if (cx == FN_HEX2IP) {
  10537.         int c[2], ip[4], i, k;
  10538.         p = "0";
  10539.         if (argn < 1)
  10540.           goto fnend;
  10541.         s = bp[0];
  10542.         if ((int)strlen(s) != 8) {
  10543.             failed = 1;
  10544.             if (fndiags)
  10545.               ckmakmsg(fnval,FNVALL,
  10546.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10547.             goto fnend;
  10548.         }
  10549.         p = fnval;
  10550.         for (k = 0; k < 8; k += 2) {
  10551.             for (i = 0; i < 2; i++) {
  10552.                 c[i] = *s++;
  10553.                 if (islower(c[i])) c[i] = toupper(c[i]);
  10554.                 if (c[i] >= '0' && c[i] <= '9') {
  10555.                     c[i] -= 0x30;
  10556.                 } else if (c[i] >= 'A' && c[i] <= 'F') {
  10557.                     c[i] -= 0x37;
  10558.                 } else {
  10559.                     failed = 1;
  10560.                     if (fndiags)
  10561.                       ckmakmsg(fnval,FNVALL,
  10562.                                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10563.                     goto fnend;
  10564.                 }
  10565.                 ip[k/2] = c[0] << 4 | c[1];
  10566.             }
  10567.             sprintf(p,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10568.         }
  10569.         goto fnend;
  10570.     }
  10571.     if (cx == FN_IP2HEX) {
  10572.         int ip[4], i;
  10573.         char * q;
  10574.         p = "00000000";
  10575.         if (argn < 1)
  10576.           goto fnend;
  10577.         s = bp[0];
  10578.         p = fnval;
  10579.         for (i = 0; i < 3; i++) {
  10580.             q = ckstrchr(s,'.');
  10581.             if (q) {
  10582.                 *q++ = NUL;
  10583.                 ip[i] = atoi(s);
  10584.                 s = q;
  10585.             } else {
  10586.                 failed = 1;
  10587.                 if (fndiags)
  10588.                   ckmakmsg(fnval,FNVALL,
  10589.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10590.                 goto fnend;
  10591.             }
  10592.         }
  10593.         ip[3] = atoi(s);
  10594.         sprintf(p,"%02x%02x%02x%02x",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10595.         goto fnend;
  10596.     }
  10597.     if (cx == FN_RADIX) {
  10598.         failed = 1;
  10599.         p = fnval;
  10600.         if (argn < 3) {
  10601.             if (fndiags)
  10602.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10603.             goto fnend;
  10604.         }
  10605.         if (!rdigits(bp[1]) || !rdigits(bp[2])) {
  10606.             if (fndiags)
  10607.               ckmakmsg(fnval,FNVALL,
  10608.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10609.             goto fnend;
  10610.         }
  10611.         p = ckradix(bp[0],atoi(bp[1]),atoi(bp[2]));
  10612.         if (!p) {
  10613.             if (fndiags)
  10614.               ckmakmsg(fnval,FNVALL,
  10615.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10616.             goto fnend;
  10617.         }
  10618.         failed = 0;
  10619.         ckstrncpy(fnval,p,FNVALL);
  10620.         p = fnval;
  10621.         goto fnend;
  10622.     }
  10623.     if (cx == FN_JOIN) {
  10624.         int i, x, y, z, flag, hi, lo, max, seplen, grouping = 0;
  10625.         char abuf[16], c, *s, *q, *sep = NULL;
  10626.         char * gr_opn = "\"{'([<";      /* Group open brackets */
  10627.         char * gr_cls = "\"}')]>";      /* Group close brackets */
  10628.         char lb[2], rb[2];              /* Selected left and right brackets */
  10629.  
  10630.         failed = 1;                     /* Assume failure */
  10631.         fnval[0] = NUL;
  10632.         debug(F101,"FNJOIN ARGN","",argn);
  10633.  
  10634.         ckstrncpy(abuf,bp[0],16);       /* Get array reference */
  10635.         s = abuf;
  10636.         if ((x = arraybounds(s,&lo,&hi)) < 0) {  /* Get index and bounds */
  10637.             if (fndiags)
  10638.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10639.             goto fnend;
  10640.         }
  10641.         p = fnval;                      /* Point to result */
  10642.         max = a_dim[x];                 /* Size of array */
  10643.         if (lo < 0) lo = 1;             /* Use given range if any */
  10644.         if (lo > max) lo = max;
  10645.         if (hi < 0) hi = max;
  10646.         if (hi > max) hi = max;
  10647.         failed = 0;                     /* Unset failure flag */
  10648.         if (max < 1)
  10649.           goto fnend;
  10650.         sep = " ";                      /* Separator */
  10651.         if (argn > 1)
  10652.           if (bp[1])
  10653.             if (*bp[1])
  10654.               sep = bp[1];
  10655.         lb[0] = NUL;
  10656.         rb[0] = NUL;
  10657.         lb[1] = NUL;
  10658.         rb[1] = NUL;
  10659.         if (argn > 2) {                 /* Grouping? */
  10660.             char * bp2 = bp[2];
  10661.             if (!bp2) bp2 = "0";
  10662.             if (!*bp2) bp2 = "0";
  10663.             if (chknum(bp2)) {
  10664.                 grouping = atoi(bp2);
  10665.                 if (grouping < 0 || grouping > 63)
  10666.                   grouping = 1;
  10667.             } else {
  10668.                 failed = 1;
  10669.                 if (fndiags)
  10670.                   ckmakmsg(fnval,FNVALL,
  10671.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10672.                 goto fnend;
  10673.             }
  10674.             if (grouping) {             /* Take lowest-order one */
  10675.                 int j, k;               /* and set the others to 0 */
  10676.                 for (k = 0; k < 6; k++) {
  10677.                     j = 1 << k;
  10678.                     if (grouping & j) {
  10679.                         lb[0] = gr_opn[k];
  10680.                         rb[0] = gr_cls[k];
  10681.                         break;
  10682.                     }
  10683.                 }
  10684.             }
  10685.         }
  10686.         if (argn > 3)                   /* Nonzero 4th arg for no separator */
  10687.           if (chknum(bp[3]))
  10688.             if (atoi(bp[3]) > 0)
  10689.               sep = NULL;
  10690.         if (!sep) {
  10691.             sep = "";
  10692.             seplen = 0;
  10693.         } else
  10694.           seplen = strlen(sep);
  10695.         for (i = lo; i <= hi; i++) {    /* Loop thru selected array elements */
  10696.             s = a_ptr[x][i];            /* Get next element */
  10697.             if (!s)
  10698.               s = "";
  10699.             flag = 0;                   /* Buffer overrun flag */
  10700.             if (grouping) {             /* Does this element need quoting? */
  10701.                 q = s;                  /* Look for spaces */
  10702.                 while ((c = *q++)) { if (c == SP) { flag++; break; } }
  10703.             }
  10704.             y = strlen(s);              /* Get length of this element */
  10705.             if (cx == 0 && grouping)    /* If empty it might need quoting */
  10706.               flag = 1;
  10707.             if (flag) {                 /* Add grouping if needed */
  10708.                 char * s2 = NULL;
  10709.                 y += 2;
  10710.                 if ((q = (char *)malloc(y+1))) {
  10711.                     ckmakmsg(q,y+1,(char *)lb,s,(char *)rb,NULL);
  10712.                     makestr(&s2,q);
  10713.                     free(q);
  10714.                     s = s2;
  10715.                 }
  10716.             }
  10717.             z = 0;                      /* Number of chars copied */
  10718.             flag = 0;                   /* flag is now buffer-overrun flag */
  10719.             if (y > 0)                  /* If this string is not empty */
  10720.               z = ckstrncat(fnval,s,FNVALL); /* copy it. */
  10721.             if (z < y)                  /* Check for buffer overrun. */
  10722.               flag++;
  10723.             if (!flag && *sep && i < hi) { /* If buffer still has room */
  10724.                 z = ckstrncat(fnval,sep,FNVALL); /* copy delimiter */
  10725.                 if (z < seplen)
  10726.                   flag++;
  10727.             }
  10728.             if (flag) {
  10729.                 failed = 1;
  10730.                 if (fndiags)
  10731.                   ckmakmsg(fnval,FNVALL,
  10732.                            "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10733.                 goto fnend;
  10734.             }
  10735.         }
  10736.         goto fnend;
  10737.     }
  10738.     if (cx == FN_SUBST) {               /* \fsubstitute() */
  10739.         CHAR c, * s, * r, * tp[2], buf1[256], buf2[256], buf3[256];
  10740.         int len, i, j, state = 0, lo = 0, hi = 0;
  10741.  
  10742.         failed = 0;
  10743.         p = fnval;                      /* Result pointer */
  10744.         *p = NUL;
  10745.         if (!bp[0])                     /* No target, no result*/
  10746.           goto fnend;
  10747.  
  10748.         len = strlen(bp[0]);            /* Length of source */
  10749.         if (len == 0)
  10750.           goto fnend;
  10751.         if (len > FNVALL) {
  10752.             failed = 1;
  10753.             if (fndiags)
  10754.               ckmakmsg(fnval,FNVALL,
  10755.                        "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10756.             goto fnend;
  10757.         }
  10758.         if (!bp[1]) {
  10759.             ckstrncpy(bp[0],fnval,FNVALL);
  10760.             goto fnend;
  10761.         }
  10762.         tp[0] = buf1;                   /* For s2-s3 interpretation loop */
  10763.         tp[1] = buf2;
  10764.  
  10765.         for (i = 0; i < 256; i++) {     /* Initialize working buffers */
  10766.             buf1[i] = 0;                /* s2 expansion buffer */
  10767.             buf2[i] = 0;                /* s3 expansion buffer */
  10768.             buf3[i] = i;                /* Translation table */
  10769.         }
  10770.         for (i = 0; i < 2; i++) {       /* Interpret s2 and s3 */
  10771.             s = (CHAR *)bp[i+1];        /* Arg pointer */
  10772.             if (!s) s = (CHAR *)"";
  10773.             r = tp[i];                  /* To construct interpreted arg */
  10774.             j = 0;                      /* Output buf pointer */
  10775.             state = 0;                  /* Initial state */
  10776.             while (c = *s++) {          /* Loop thru arg chars */
  10777.                 if (j > 255)            /* Output buf full */
  10778.                   break;
  10779.                 switch (state) {
  10780.                   case 0:               /* Normal state */
  10781.                     switch (c) {
  10782.                       case '\\':        /* Have quote */
  10783.                         state = 1;
  10784.                         break;
  10785.                       case '[':         /* Have range starter */
  10786.                         state = 2;
  10787.                         break;
  10788.                       default:          /* Anything else */
  10789.                         r[j++] = c;
  10790.                         break;
  10791.                     }
  10792.                     continue;
  10793.                   case 1:               /* Quoted char */
  10794.                     r[j++] = c;
  10795.                     state = 0;
  10796.                     continue;
  10797.                   case 2:               /* Range bottom */
  10798.                     lo = c;
  10799.                     state++;
  10800.                     continue;
  10801.                   case 3:               /* Range separater */
  10802.                     if (c != '-') {
  10803.                         failed = 1;
  10804.                         if (fndiags)
  10805.                           ckmakmsg(fnval,FNVALL,
  10806.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  10807.                         goto fnend;
  10808.                     }
  10809.                     state++;
  10810.                     continue;
  10811.                   case 4:               /* Range top */
  10812.                     hi = c;
  10813.                     state++;
  10814.                     continue;
  10815.                   case 5:               /* Range end */
  10816.                     if (c != ']') {
  10817.                         failed = 1;
  10818.                         if (fndiags)
  10819.                           ckmakmsg(fnval,FNVALL,
  10820.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  10821.                         goto fnend;
  10822.                     }
  10823.                     for (k = lo; k <= hi && j < 255; k++) /* Fill in */
  10824.                       r[j++] = k;
  10825.                     lo = 0; hi = 0;     /* Reset */
  10826.                     state = 0;
  10827.                     continue;
  10828.                 }
  10829.             }
  10830.         }
  10831.         for (i = 0; i < 256 && buf1[i]; i++) {  /* Create translation table */
  10832.             k = (unsigned)buf1[i];
  10833.             buf3[k] = buf2[i];
  10834.         }
  10835.         s = (CHAR *)bp[0];              /* Point to source string */
  10836.         for (i = 0; i < len; i++) {     /* Translation loop */
  10837.             k = (unsigned)s[i];         /* Get next char */
  10838.             if (!buf3[k])               /* Remove this char */
  10839.               continue;
  10840.             *p++ = buf3[k];             /* Substitute this char */
  10841.         }
  10842.         *p = NUL;
  10843.         p = fnval;
  10844.         goto fnend;
  10845.     }
  10846.  
  10847. #ifndef NOSEXP
  10848.     if (cx == FN_SEXP) {                /* \fsexpression(arg1) */
  10849.         char * p2;
  10850.         fsexpflag++;
  10851.         p = (argn > 0) ? dosexp(bp[0]) : "";
  10852.         fsexpflag--;
  10853.         p2 = fnval;
  10854.         while ((*p2++ = *p++)) ;
  10855.         p = fnval;
  10856.         goto fnend;
  10857.     }
  10858. #endif /* NOSEXP */
  10859.  
  10860.     if (cx == FN_CMDSTK) {              /* \fcmdstack(n1,n2) */
  10861.         int i, j, k;
  10862.         char * s;
  10863.  
  10864.         if (bp[0])
  10865.           val1 = *(bp[0]) ? evalx(bp[0]) : ckitoa(cmdlvl);
  10866.         else
  10867.           val1 = ckitoa(cmdlvl);
  10868. #ifdef COMMENT
  10869.         free(bp[0]);                    /* (evalx() always uses same buffer) */
  10870.         bp[0] = NULL;                   /* (not any more!) */
  10871. #endif /* COMMENT */
  10872.         failed = 1;
  10873.         if (argn > 1) {
  10874. #ifdef COMMENT
  10875.             makestr(&(bp[0]),val1);
  10876.             val1 = bp[0];
  10877. #endif /* COMMENT */
  10878.             val2 = *(bp[1]) ? evalx(bp[1]) : "0";
  10879.             if (!(chknum(val1) && chknum(val2))) {
  10880.                 if (fndiags)
  10881.                   ckmakmsg(fnval,FNVALL,
  10882.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10883.                 goto fnend;
  10884.             }
  10885.         } else {
  10886.             val1 = ckitoa(cmdlvl);
  10887.             val2 = "0";
  10888.         }
  10889.         i = atoi(val1);                 /* Level */
  10890.         j = atoi(val2);                 /* Flags */
  10891.         if (i < 0 || i > cmdlvl) {
  10892.             if (fndiags)
  10893.               ckmakmsg(fnval,FNVALL,
  10894.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10895.             goto fnend;
  10896.         }
  10897.         failed = 0;
  10898.         p = fnval;
  10899.         k = cmdstk[i].src;              /* What (prompt, file, macro) */
  10900.         if (j) {
  10901.             ckstrncpy(fnval,ckitoa(k),FNVALL);
  10902.             goto fnend;
  10903.         }
  10904.         switch (k) {
  10905.           case CMD_KB:
  10906.             ckstrncpy(fnval,"(prompt)",FNVALL);
  10907.             break;
  10908.           case CMD_TF:
  10909.             s = tfnam[cmdstk[i].lvl];
  10910.             if (!zfnqfp(s,FNVALL,fnval))
  10911.               ckstrncpy(fnval,s,FNVALL);
  10912.             break;
  10913.           case CMD_MD:
  10914.             ckstrncpy(fnval,m_arg[cmdstk[i].lvl][0],FNVALL);
  10915.             break;
  10916.         }
  10917.         goto fnend;
  10918.     }
  10919. #ifdef CKFLOAT
  10920.     if (cx == FN_DIFDATE) {             /* \fdiffdates(d1,d2) */
  10921.         char * d1, * d2;
  10922.         d1 = bp[0] ? bp[0] : ckdate();
  10923.         d2 = bp[1] ? bp[1] : ckdate();
  10924.         p = (char *)cmdiffdate(d1,d2);
  10925.         if (!p) {
  10926.             failed = 1;
  10927.             if (fndiags) {
  10928.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  10929.                 p = fnval;
  10930.             }
  10931.         }
  10932.         goto fnend;
  10933.     }
  10934. #endif /* CKFLOAT */
  10935.     if (cx == FN_CMPDATE) {             /* \fcmddates(d1,d2) */
  10936.         int x = 0;
  10937.         char d1[18], d2[18], * dp;
  10938.         failed = 0;
  10939.         d1[0] = NUL;
  10940.         d2[0] = NUL;
  10941.         p = fnval;
  10942.         dp = cmcvtdate(bp[0],1);
  10943.         if (dp) {
  10944.             ckstrncpy(d1,dp,18);
  10945.             if ((dp = cmcvtdate(bp[1],1))) {
  10946.                 ckstrncpy(d2,dp,18);
  10947.                 x = 1;
  10948.             }
  10949.         }
  10950.         if (x == 0) {
  10951.             failed = 1;
  10952.             if (fndiags)
  10953.               ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  10954.         } else {
  10955.             x = strcmp(d1,d2);
  10956.             if (x > 0)
  10957.               x = 1;
  10958.             else if (x < 0)
  10959.               x = -1;
  10960.             sprintf(fnval,"%d",x);
  10961.         }
  10962.         goto fnend;
  10963.     }
  10964.     if (cx == FN_TOGMT) {               /* \futcdate(d1) */
  10965.         char * d1, * dp;
  10966.         char datebuf[32];
  10967.         char d2[32];
  10968.         p = fnval;
  10969.         failed = 1;
  10970.         if ((dp = cmcvtdate(bp[0],1))) { /* The given date */
  10971.             ckstrncpy(datebuf,dp,18);
  10972.             ckstrncpy(d2,dp,18);        /* local time */
  10973.             ckstrncat(datebuf,"Z",19);  /* Same time GMT */
  10974.             if ((dp = cmcvtdate(datebuf,1))) /* converted to local time */
  10975.               ckstrncpy(datebuf,dp,18);
  10976.             if ((p = (char *)cmdiffdate(d2,datebuf))) { /* Get offset */
  10977.                 ckstrncat(d2,p,32);     /* Append offset to local time */
  10978.                 if ((dp = cmcvtdate(d2,1))) {
  10979.                     failed = 0;
  10980.                     ckstrncpy(fnval,dp,FNVALL);
  10981.                     p = fnval;
  10982.                 }
  10983.             }
  10984.         }
  10985.         if (failed && fndiags)
  10986.           ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  10987.         goto fnend;
  10988.     }
  10989.     if (cx == FN_DELSEC) {              /* \fdelta2secs(delta-time) */
  10990.         long secs;
  10991.         p = fnval;
  10992.         if ((x = delta2sec(bp[0],&secs)) < 0) {
  10993.             failed = 1;
  10994.             if (fndiags)
  10995.               ckmakmsg(fnval,FNVALL,
  10996.                        (x == -1) ?
  10997.                          "<ERROR:BAD_DELTA_TIME:\\f" :
  10998.                          "<ERROR:OVERFLOW:\\f",
  10999.                        fn,
  11000.                        "()>",
  11001.                        NULL
  11002.                        );
  11003.             goto fnend;
  11004.         }
  11005.         sprintf(p,"%ld",secs);
  11006.         goto fnend;
  11007.     }
  11008.     if (cx == FN_PC_DU) {
  11009.         char c, * s = bp[0];
  11010.         if (!s) s = "";
  11011.         p = fnval;
  11012.         while ((c = *s++)) {
  11013.             if (c == ':') {
  11014.                 if (*s != '\\')
  11015.                   *p++ = '/';
  11016.             } else if (c == '\\') {
  11017.                 *p++ = '/';
  11018.             } else {
  11019.                 *p++ = c;
  11020.             }
  11021.         }
  11022.         *p = NUL;
  11023.         p = fnval;
  11024.         goto fnend;
  11025.     }
  11026.     if (cx == FN_PC_UD) {               /* Unix to DOS path */
  11027.         char c, * s = bp[0];
  11028.         if (!s) s = "";
  11029.         if (*s == '~') {                /* Skip leading tilde */
  11030.             s++;
  11031.             if (*s == '/')
  11032.               s++;
  11033.         }
  11034.         p = fnval;
  11035.         while ((c = *s++))
  11036.           *p ++ = (c == '/') ? '\\' : c;
  11037.         *p = NUL;
  11038.         p = fnval;
  11039.         goto fnend;
  11040.     }
  11041.     if (cx == FN_KWVAL) {               /* Keyword=Value */
  11042.         p = dokwval(bp[0],bp[1]?*(bp[1]):'=');
  11043.         goto fnend;
  11044.     }
  11045. #ifdef COMMENT
  11046. /* Cute idea but doesn't work */
  11047.     if (cx == FN_SLEEP || cx == FN_MSLEEP) {
  11048.         p = "";
  11049.         if (chknum(bp[0])) {
  11050.             x = atoi(bp[0]);
  11051.         } else {
  11052.             failed = 1;
  11053.             if (fndiags) {
  11054.                 ckmakmsg(fnval,FNVALL,
  11055.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11056.                 p = fnval;
  11057.             }
  11058.             goto fnend;
  11059.         }
  11060.         if (cx == FN_SLEEP)
  11061.           x *= 1000;
  11062.         msleep(x);
  11063.         goto fnend;
  11064.     }
  11065. #endif /* COMMENT */
  11066.  
  11067. /* Note: when adding new functions remember to update dohfunc in ckuus2.c. */
  11068.  
  11069.     failed = 1;
  11070.     if (fndiags)
  11071.       ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN_FUNCTION:\\f",fn,"()>",NULL);
  11072.  
  11073.   fnend:
  11074.     /* Free temporary storage for aguments */
  11075.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  11076.     fndepth--;
  11077.     if (failed) {                       /* Handle failure */
  11078.         debug(F111,"fnend",fnval,errno);
  11079.         if (!p) p = "";
  11080.         if (p[0]) {
  11081.             /* In case this wasn't caught above... */
  11082.             k = strlen(p);
  11083.             if (p[0] != '<' && p[k-1] != '>') {
  11084.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_ARG:\\f",fn,"()>",NULL);
  11085.                 p = fnval;
  11086.             }
  11087.         } else {
  11088.             ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN:\\f",fn,"()>",NULL);
  11089.             p = fnval;
  11090.         }
  11091.         if (fnerror)                    /* SET FUNCTION ERROR ON */
  11092.           fnsuccess = 0;                /* Make command fail (see ckuus5.c) */
  11093.         debug(F111,"fneval failed",p,fnsuccess);
  11094.         if (fndiags)                    /* SET FUNCTION DIAGNOSTICS ON */
  11095.           printf("?%s\n",p);            /* Print error message now. */
  11096.         else
  11097.           return("");                   /* Return nothing. */
  11098.     }
  11099.     return(p);
  11100. }
  11101. #endif /* NOSPL */
  11102.  
  11103. static char ckpidbuf[32] = "????";
  11104.  
  11105. #ifdef VMS
  11106. _PROTOTYP(long zgpid,(void));
  11107. #endif /* VMS */
  11108.  
  11109. char *
  11110. ckgetpid() {                            /* Return pid as string */
  11111. #ifdef CK_PID
  11112. #ifdef OS2
  11113. #define getpid _getpid
  11114.     unsigned long zz;
  11115. #else
  11116.     long zz;
  11117. #endif /* OS2 */
  11118. #ifdef VMS
  11119.     zz = zgpid();
  11120. #else
  11121.     zz = getpid();
  11122. #endif /* VMS */
  11123.     sprintf(ckpidbuf,"%ld",zz);         /* SAFE */
  11124. #endif /* CK_PID */
  11125.     return((char *)ckpidbuf);
  11126. }
  11127.  
  11128. #ifndef NOSPL
  11129. #define EMBUFLEN 128                    /* Error message buffer length */
  11130.  
  11131. static char embuf[EMBUFLEN+1];
  11132.  
  11133. char *                                  /* Evaluate builtin variable */
  11134. nvlook(s) char *s; {
  11135.     int x, y, cx;
  11136.     long z;
  11137.     char *p;
  11138. #ifndef NODIAL
  11139.     MDMINF * m;
  11140. #endif /* NODIAL */
  11141. #ifndef NOKVERBS                        /* Keyboard macro material */
  11142.     extern int keymac, keymacx;
  11143. #endif /* NOKVERBS */
  11144. #ifdef CK_LOGIN
  11145.     extern int isguest;
  11146. #endif /* CK_LOGIN */
  11147.     if (!s) s = "";
  11148.     x = strlen(s);
  11149.     if (fndiags) {                      /* FUNCTION DIAGNOSTIC ON */
  11150.         if (x + 32 < EMBUFLEN)
  11151.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE:\\v(%s)>",s); /* SAFE */
  11152.         else
  11153.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE>"); /* SAFE */
  11154.     } else                              /* FUNCTION DIAGNOSTIC OFF */
  11155.       embuf[0] = NUL;
  11156.     x = VVBUFL;
  11157.     p = vvbuf;
  11158.     if (zzstring(s,&p,&x) < 0) {        /* e.g. for \v(\%a) */
  11159.         y = -1;
  11160.     } else {
  11161.         s = vvbuf;
  11162.         y = lookup(vartab,s,nvars,&x);
  11163.     }
  11164.     cx = y;                             /* y is too generic */
  11165. #ifndef NODIAL
  11166.     m = (mdmtyp > 0) ? modemp[mdmtyp] : NULL; /* For \v(m_xxx) variables */
  11167. #endif /* NODIAL */
  11168.  
  11169.     debug(F101,"nvlook y","",y);
  11170.  
  11171.     switch (y) {
  11172.       case VN_ARGC:                     /* ARGC */
  11173.         sprintf(vvbuf,"%d",maclvl < 0 ? topargc : macargc[maclvl]); /* SAFE */
  11174.         return(vvbuf);
  11175.  
  11176.       case VN_ARGS:                     /* ARGS */
  11177.         sprintf(vvbuf,"%d",xargs);      /* SAFE */
  11178.         return(vvbuf);
  11179.  
  11180.       case VN_COUN:                     /* COUNT */
  11181.         sprintf(vvbuf,"%d",count[cmdlvl]); /* SAFE */
  11182.         return(vvbuf);
  11183.  
  11184.       case VN_DATE:                     /* DATE */
  11185.         ztime(&p);                      /* Get "asctime" string */
  11186.         if (p == NULL || *p == NUL) return(NULL);
  11187.         vvbuf[0] = p[8];                /* dd */
  11188.         vvbuf[1] = p[9];
  11189.         vvbuf[2] = SP;
  11190.         vvbuf[3] = p[4];                /* mmm */
  11191.         vvbuf[4] = p[5];
  11192.         vvbuf[5] = p[6];
  11193.         vvbuf[6] = SP;
  11194.         for (x = 20; x < 24; x++)       /* yyyy */
  11195.           vvbuf[x - 13] = p[x];
  11196.         vvbuf[11] = NUL;
  11197.         return(vvbuf);
  11198.  
  11199.       case VN_NDAT:                     /* Numeric date */
  11200.         ckstrncpy(vvbuf,zzndate(),VVBUFL);
  11201.         return(vvbuf);
  11202.  
  11203.       case VN_DIRE:                     /* DIRECTORY */
  11204.         s = zgtdir();                   /* Get current directory */
  11205.         if (!s)
  11206. #ifdef UNIXOROSK
  11207.           s = "./";
  11208. #else
  11209. #ifdef VMS
  11210.           s = "[]";
  11211. #else
  11212.           s = "";
  11213. #endif /* VMS */
  11214. #endif /* UNIXOROSK */
  11215.         ckstrncpy(vvbuf,s,VVBUFL);
  11216.         s = vvbuf;
  11217. #ifdef UNIXOROSK
  11218.         x = strlen(s);
  11219.         if (x < VVBUFL - 1) {
  11220.             if (s[x-1] != '/') {
  11221.                 s[x] = '/';
  11222.                 s[x+1] = NUL;
  11223.             }
  11224.         }
  11225. #endif /* UNIXOROSK */
  11226.         return(s);
  11227.  
  11228.       case VN_FILE:                     /* filespec */
  11229.         return(fspec);
  11230.  
  11231.       case VN_HOST:                     /* host name */
  11232.         if (*myhost) {                  /* If known */
  11233.             return(myhost);             /* return it. */
  11234.         } else {                        /* Otherwise */
  11235.             ckstrncpy(vvbuf,"unknown",VVBUFL); /* just say "unknown" */
  11236.             return(vvbuf);
  11237.         }
  11238.  
  11239.       case VN_SYST:                     /* System type */
  11240. #ifdef UNIX
  11241.         ckstrncpy(vvbuf,"UNIX",VVBUFL);
  11242. #else
  11243. #ifdef VMS
  11244.         ckstrncpy(vvbuf,"VMS",VVBUFL);
  11245. #else
  11246. #ifdef OSK
  11247.         ckstrncpy(vvbuf,"OS9/68K",VVBUFL);
  11248. #else
  11249. #ifdef AMIGA
  11250.         ckstrncpy(vvbuf,"Amiga",VVBUFL);
  11251. #else
  11252. #ifdef MAC
  11253.         ckstrncpy(vvbuf,"Macintosh",VVBUFL);
  11254. #else
  11255. #ifdef OS2
  11256. #ifdef NT
  11257.         ckstrncpy(vvbuf,"WIN32",VVBUFL) ;
  11258. #else /* NT */
  11259.         ckstrncpy(vvbuf,"OS/2",VVBUFL);
  11260. #endif /* NT */
  11261. #else
  11262. #ifdef datageneral
  11263.         ckstrncpy(vvbuf,"AOS/VS",VVBUFL);
  11264. #else
  11265. #ifdef GEMDOS
  11266.         ckstrncpy(vvbuf,"Atari_ST",VVBUFL);
  11267. #else
  11268. #ifdef STRATUS
  11269.         ckstrncpy(vvbuf,"Stratus_VOS",VVBUFL);
  11270. #else
  11271.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11272. #endif /* STRATUS */
  11273. #endif /* GEMDOS */
  11274. #endif /* datageneral */
  11275. #endif /* OS2 */
  11276. #endif /* MAC */
  11277. #endif /* AMIGA */
  11278. #endif /* OSK */
  11279. #endif /* VMS */
  11280. #endif /* UNIX */
  11281.         return(vvbuf);
  11282.  
  11283.       case VN_SYSV:                     /* System herald */
  11284. #ifdef IKSD
  11285. #ifdef CK_LOGIN
  11286.         if (inserver && isguest)
  11287.           return("");
  11288. #endif /* CK_LOGIN */
  11289. #endif /* IKSD */
  11290.         for (x = y = 0; x < VVBUFL; x++) {
  11291.             if (ckxsys[x] == SP && y == 0) continue;
  11292.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  11293.         }
  11294.         vvbuf[y] = NUL;
  11295.         return(vvbuf);
  11296.     } /* Break up long switch statements... */
  11297.  
  11298.     switch(y) {
  11299.       case VN_TIME:                     /* TIME. Assumes that ztime returns */
  11300.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11301.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11302.           return("");
  11303.         for (x = 11; x < 19; x++)       /* copy hh:mm:ss */
  11304.           vvbuf[x - 11] = p[x];         /* to vvbuf */
  11305.         vvbuf[8] = NUL;                 /* terminate */
  11306.         return(vvbuf);                  /* and return it */
  11307.  
  11308.       case VN_NTIM:                     /* Numeric time */
  11309.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11310.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11311.           return(NULL);
  11312.         z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  11313.         sprintf(vvbuf,"%ld",z);         /* SAFE */
  11314.         return(vvbuf);
  11315.  
  11316. #ifdef CK_TTYFD
  11317.       case VN_TTYF:                     /* TTY file descriptor */
  11318.         sprintf(vvbuf,"%d",             /* SAFE */
  11319. #ifdef VMS
  11320.                 vmsttyfd()
  11321. #else
  11322.                 ttyfd
  11323. #endif /* VMS */
  11324.                 );
  11325.         return(vvbuf);
  11326. #endif /* CK_TTYFD */
  11327.  
  11328.       case VN_VERS:                     /* Numeric Kermit version number */
  11329.         sprintf(vvbuf,"%ld",vernum);    /* SAFE */
  11330.         return(vvbuf);
  11331.  
  11332.       case VN_XVNUM:                    /* Product-specific version number */
  11333.         sprintf(vvbuf,"%ld",xvernum);   /* SAFE */
  11334.         return(vvbuf);
  11335.  
  11336.       case VN_HOME:                     /* Home directory */
  11337.         return(homepath());
  11338.  
  11339.       case VN_IBUF:                     /* INPUT buffer */
  11340.         return((char *)inpbuf);
  11341.  
  11342.       case VN_ICHR:                     /* INPUT character */
  11343.         inchar[1] = NUL;
  11344.         return((char *)inchar);
  11345.  
  11346.       case VN_ICNT:                     /* INPUT character count */
  11347.         sprintf(vvbuf,"%d",incount);    /* SAFE */
  11348.         return(vvbuf);
  11349.  
  11350.       case VN_SPEE: {                   /* Transmission SPEED */
  11351.           long t;
  11352.           t = ttgspd();
  11353.           if (t < 0L)
  11354.             sprintf(vvbuf,"unknown");   /* SAFE */
  11355.           else
  11356.             sprintf(vvbuf,"%ld",t);     /* SAFE */
  11357.           return(vvbuf);
  11358.       }
  11359.  
  11360.       case VN_SUCC:                     /* SUCCESS flag */
  11361.         /* Note inverted sense */
  11362.         sprintf(vvbuf,"%d",(success == 0) ? 1 : 0); /* SAFE */
  11363.         return(vvbuf);
  11364.  
  11365.       case VN_LINE: {                   /* LINE */
  11366. #ifdef DEBUG
  11367.           if (deblog) {
  11368.               debug(F111,"\\v(line) local",ttname,local);
  11369.               debug(F111,"\\v(line) inserver","",inserver);
  11370. #ifdef TNCODE
  11371.               debug(F111,"\\v(line) tcp_incoming","",tcp_incoming);
  11372. #endif /* TNCODE */
  11373. #ifdef CK_TAPI
  11374.               debug(F111,"\\v(line) tttapi","",tttapi);
  11375. #endif /* CK_TAPI */
  11376.           }
  11377. #endif /* DEBUG */
  11378.  
  11379. #ifdef CK_TAPI
  11380.           if (tttapi) {                 /* If I have made a TAPI connection */
  11381.               int i;                    /* return the TAPI device name */
  11382.               for (i = 0; i < ntapiline; i++) {
  11383.                   if (!strcmp(ttname,tapilinetab[i].kwd)) {
  11384.                       p = _tapilinetab[i].kwd;
  11385.                       return(p);
  11386.                   }
  11387.               }
  11388.           }
  11389. #endif /* CK_TAPI */
  11390. #ifndef NOXFER
  11391.           if (inserver                  /* If I am a TCP server */
  11392. #ifdef TNCODE
  11393.               || tcp_incoming
  11394. #endif /* TNCODE */
  11395.               )
  11396. #ifdef TCPSOCKET
  11397.             p = ckgetpeer();            /* return peer name */
  11398.           else
  11399. #endif /* TCPSOCKET */
  11400. #endif /* NOXFER */
  11401.           if (local)                    /* Otherwise if in local mode */
  11402.             p = (char *) ttname;        /* return SET LINE / SET HOST name */
  11403.           else                          /* Otherwise */
  11404.             p = "";                     /* return empty string */
  11405.           if (!p)                       /* In case ckgetpeer() returns */
  11406.             p = "";                     /* null pointer... */
  11407.           debug(F110,"\\v(line) p",p,0);
  11408.           if (!*p)
  11409.             p = (char *) ttname;
  11410.           return(p);
  11411.       }
  11412.       case VN_PROG:                     /* Program name */
  11413.         return("C-Kermit");
  11414.  
  11415.     } /* Break up long switch statements... */
  11416.  
  11417.     switch(y) {
  11418.       case VN_RET:                      /* Value of most recent RETURN */
  11419.         debug(F111,"\\v(return)",mrval[maclvl+1],maclvl+1);
  11420.         p = mrval[maclvl+1];
  11421.         if (p == NULL) p = "";
  11422.         return(p);
  11423.  
  11424.       case VN_FFC:                      /* Size of most recent file */
  11425.         sprintf(vvbuf, "%ld", ffc);     /* SAFE */
  11426.         return(vvbuf);
  11427.  
  11428.       case VN_TFC:                      /* Size of most recent file group */
  11429.         sprintf(vvbuf, "%ld", tfc);     /* SAFE */
  11430.         return(vvbuf);
  11431.  
  11432.       case VN_CPU:                      /* CPU type */
  11433. #ifdef IKSD
  11434. #ifdef CK_LOGIN
  11435.         if (inserver && isguest)
  11436.           return("");
  11437. #endif /* CK_LOGIN */
  11438. #endif /* IKSD */
  11439. #ifdef OS2
  11440.          {
  11441.             char * getcpu(void) ;
  11442.             return getcpu();
  11443.          }
  11444. #else /* OS2 */
  11445. #ifdef CKCPU
  11446.         return(CKCPU);                  /* Traditionally, compile-time value */
  11447. #else
  11448. #ifdef CK_UTSNAME
  11449.         {                               /* But if none, try runtime value */
  11450.             extern char unm_mch[];
  11451.             return((char *)unm_mch);
  11452.         }
  11453. #else
  11454.         return("unknown");
  11455. #endif /* CK_UTSNAME */
  11456. #endif /* CKCPU */
  11457. #endif /* OS2 */
  11458.  
  11459.       case VN_CMDL:                     /* Command level */
  11460.         sprintf(vvbuf, "%d", cmdlvl);   /* SAFE */
  11461.         return(vvbuf);
  11462.  
  11463.       case VN_DAY:                      /* Day of week */
  11464.         ztime(&p);
  11465.         if (p != NULL && *p != NUL)     /* ztime() succeeded. */
  11466.           ckstrncpy(vvbuf,p,4);
  11467.         else
  11468.           vvbuf[0] = NUL;               /* ztime() failed. */
  11469.         return(vvbuf);                  /* Return what we got. */
  11470.  
  11471.       case VN_NDAY: {                   /* Numeric day of week */
  11472.           long k;
  11473.           z = mjd(zzndate());           /* Get modified Julian date */
  11474.           k = (((int)(z % 7L)) + 3) % 7; /* Get day number */
  11475.           sprintf(vvbuf,"%ld",k);       /* SAFE */
  11476.           return(vvbuf);
  11477.       }
  11478.  
  11479.       case VN_LCL:                      /* Local (vs remote) mode */
  11480.         ckstrncpy(vvbuf, local ? "1" : "0",VVBUFL);
  11481.         return(vvbuf);
  11482.  
  11483.       case VN_CMDS:                     /* Command source */
  11484.         if (cmdstk[cmdlvl].src == CMD_KB)
  11485.           ckstrncpy(vvbuf,"prompt",VVBUFL);
  11486.         else if (cmdstk[cmdlvl].src == CMD_MD)
  11487.           ckstrncpy(vvbuf,"macro",VVBUFL);
  11488.         else if (cmdstk[cmdlvl].src == CMD_TF)
  11489.           ckstrncpy(vvbuf,"file",VVBUFL);
  11490.         else
  11491.           ckstrncpy(vvbuf,"unknown",VVBUFL);
  11492.         return(vvbuf);
  11493.  
  11494.       case VN_CMDF:                     /* Current command file name */
  11495. #ifdef COMMENT                          /* (see comments above) */
  11496.         if (tfnam[tlevel]) {            /* (near dblbs declaration) */
  11497.             dblbs(tfnam[tlevel],vvbuf,VVBUFL);
  11498.             return(vvbuf);
  11499.         } else return("");
  11500. #else
  11501.         if (tlevel < 0)
  11502.           return("");
  11503.         else
  11504.           return(tfnam[tlevel] ? tfnam[tlevel] : "");
  11505. #endif /* COMMENT */
  11506.  
  11507.       case VN_MAC:                      /* Current macro name */
  11508.         return((maclvl > -1) ? m_arg[maclvl][0] : "");
  11509.  
  11510.       case VN_EXIT:
  11511.         sprintf(vvbuf,"%d",xitsta);     /* SAFE */
  11512.         return(vvbuf);
  11513.  
  11514.     } /* Break up long switch statements... */
  11515.  
  11516.     switch(y) {
  11517.       case VN_PRTY: {                   /* Parity */
  11518.           char *ss;
  11519.           switch (parity) {
  11520.             case 0:   ss = "none";  break;
  11521.             case 'e': ss = "even";  break;
  11522.             case 'm': ss = "mark";  break;
  11523.             case 'o': ss = "odd";   break;
  11524.             case 's': ss = "space"; break;
  11525.             default:  ss = "unknown"; break;
  11526.           }
  11527.           ckstrncpy(vvbuf,ss,VVBUFL);
  11528.           return(vvbuf);
  11529.       }
  11530.  
  11531.       case VN_DIAL:
  11532.         sprintf(vvbuf,"%d",             /* SAFE */
  11533. #ifndef NODIAL
  11534.                 dialsta
  11535. #else
  11536.                 -1
  11537. #endif /* NODIAL */
  11538.                 );
  11539.         return(vvbuf);
  11540.  
  11541. #ifdef OS2
  11542.       case VN_KEYB:
  11543.         ckstrncpy(vvbuf,conkbg(),VVBUFL);
  11544.         return(vvbuf);
  11545.       case VN_SELCT: {
  11546. #ifndef NOLOCAL
  11547.           const char * selection = GetSelection();
  11548.           return( (char *) (selection ? selection : "" )) ;
  11549. #else
  11550.           return("");
  11551. #endif /* NOLOCAL */
  11552.       }
  11553. #endif /* OS2 */
  11554.  
  11555. #ifndef NOXFER
  11556.       case VN_CPS:
  11557.         sprintf(vvbuf,"%ld",tfcps);     /* SAFE */
  11558.         return(vvbuf);
  11559. #endif /* NOXFER */
  11560.  
  11561.       case VN_MODE:                     /* File transfer mode */
  11562.         switch (binary) {
  11563.           case XYFT_T: ckstrncpy(vvbuf,"text",VVBUFL); break;
  11564.           case XYFT_B:
  11565.           case XYFT_U: ckstrncpy(vvbuf,"binary",VVBUFL); break;
  11566.           case XYFT_I: ckstrncpy(vvbuf,"image",VVBUFL); break;
  11567.           case XYFT_L: ckstrncpy(vvbuf,"labeled",VVBUFL); break;
  11568.           case XYFT_M: ckstrncpy(vvbuf,"macbinary",VVBUFL); break;
  11569.           default:     ckstrncpy(vvbuf,"unknown",VVBUFL);
  11570.         }
  11571.         return(vvbuf);
  11572.  
  11573. #ifdef CK_REXX
  11574.       case VN_REXX:
  11575.         return(rexxbuf);
  11576. #endif /* CK_REXX */
  11577.  
  11578.       case VN_NEWL:                     /* System newline char or sequence */
  11579. #ifdef UNIX
  11580.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11581. #else
  11582. #ifdef datageneral
  11583.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11584. #else
  11585. #ifdef OSK
  11586.         ckstrncpy(vvbuf,"\15",VVBUFL);  /* Remember, these are octal... */
  11587. #else
  11588. #ifdef MAC
  11589.         ckstrncpy(vvbuf,"\15",VVBUFL);
  11590. #else
  11591. #ifdef OS2
  11592.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11593. #else
  11594. #ifdef STRATUS
  11595.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11596. #else
  11597. #ifdef VMS
  11598.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11599. #else
  11600. #ifdef AMIGA
  11601.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11602. #else
  11603. #ifdef GEMDOS
  11604.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11605. #else
  11606.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11607. #endif /* GEMDOS */
  11608. #endif /* AMIGA */
  11609. #endif /* VMS */
  11610. #endif /* STRATUS */
  11611. #endif /* OS2 */
  11612. #endif /* MAC */
  11613. #endif /* OSK */
  11614. #endif /* datageneral */
  11615. #endif /* UNIX */
  11616.         return(vvbuf);
  11617.  
  11618.       case VN_ROWS:                     /* ROWS */
  11619.       case VN_COLS:                     /* COLS */
  11620.         ckstrncpy(vvbuf,(cx == VN_ROWS) ? "24" : "80",VVBUFL); /* Default */
  11621. #ifdef CK_TTGWSIZ
  11622. #ifdef OS2
  11623.         if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  11624.           ttgwsiz();
  11625.         sprintf(vvbuf,"%d",             /* SAFE */
  11626.                 (cx == VN_ROWS) ? tt_rows[VTERM] : tt_cols[VTERM]);
  11627. #else /* OS2 */
  11628.         if (ttgwsiz() > 0)              /* Get window size */
  11629.           if (tt_cols > 0 && tt_rows > 0) /* sets tt_rows, tt_cols */
  11630.             sprintf(vvbuf,"%d",         /* SAFE */
  11631.                     (cx == VN_ROWS) ? tt_rows : tt_cols);
  11632. #endif /* OS2 */
  11633. #endif /* CK_TTGWSIZ */
  11634.         return(vvbuf);
  11635.  
  11636.       case VN_TTYP:
  11637. #ifdef NOTERM
  11638.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11639. #else
  11640. #ifdef OS2
  11641.         sprintf(vvbuf, "%s",            /* SAFE */
  11642.                 (tt_type >= 0 && tt_type <= max_tt) ?
  11643.                 tt_info[tt_type].x_name :
  11644.                 "unknown"
  11645.                 );
  11646. #else
  11647. #ifdef MAC
  11648.         ckstrncpy(vvbuf,"vt320",VVBUFL);
  11649. #else
  11650.         p = getenv("TERM");
  11651.         ckstrncpy(vvbuf,p ? p : "unknown",VVBUFL+1);
  11652. #endif /* MAC */
  11653. #endif /* OS2 */
  11654. #endif /* NOTERM */
  11655.         return(vvbuf);
  11656.  
  11657.       case VN_MINP:                     /* MINPUT */
  11658.         sprintf(vvbuf, "%d", m_found);  /* SAFE */
  11659.         return(vvbuf);
  11660.     } /* Break up long switch statements... */
  11661.  
  11662.     switch(y) {
  11663.       case VN_CONN:                     /* CONNECTION */
  11664.         if (!local) {
  11665.           ckstrncpy(vvbuf,"remote",VVBUFL);
  11666.         } else {
  11667.             if (!network)
  11668.               ckstrncpy(vvbuf,"serial",VVBUFL);
  11669. #ifdef TCPSOCKET
  11670.             else if (nettype == NET_TCPB || nettype == NET_TCPA) {
  11671.                 if (ttnproto == NP_TELNET)
  11672.                   ckstrncpy(vvbuf,"tcp/ip_telnet",VVBUFL);
  11673. #ifdef CK_SSL
  11674.                 else if (ttnproto == NP_SSL)
  11675.                   ckstrncpy(vvbuf,"tcp/ip_ssl",VVBUFL);
  11676.                 else if (ttnproto == NP_TLS)
  11677.                   ckstrncpy(vvbuf,"tcp/ip_tls",VVBUFL);
  11678. #endif /* CK_SSL */
  11679.                 else
  11680.                   ckstrncpy(vvbuf,"tcp/ip",VVBUFL);
  11681.             }
  11682. #endif /* TCPSOCKET */
  11683. #ifdef SSHBUILTIN
  11684.             else if (nettype == NET_SSH)
  11685.                   ckstrncpy(vvbuf,"tcp/ip_ssh",VVBUFL);
  11686. #endif /* SSHBUILTIN */
  11687. #ifdef ANYX25
  11688.             else if (nettype == NET_SX25 ||
  11689.                      nettype == NET_VX25 ||
  11690.                      nettype == NET_IX25
  11691.                      )
  11692.               ckstrncpy(vvbuf,"x.25",VVBUFL);
  11693. #endif /* ANYX25 */
  11694. #ifdef DECNET
  11695.             else if (nettype == NET_DEC) {
  11696.                 if (ttnproto == NP_LAT)
  11697.                   ckstrncpy(vvbuf,"decnet_lat",VVBUFL);
  11698.                 else if ( ttnproto == NP_CTERM )
  11699.                   ckstrncpy(vvbuf,"decnet_cterm",VVBUFL);
  11700.                 else
  11701.                   ckstrncpy(vvbuf,"decnet",VVBUFL);
  11702.             }
  11703. #endif /* DECNET */
  11704. #ifdef SUPERLAT
  11705.             else if (nettype == NET_SLAT)
  11706.               ckstrncpy(vvbuf,"superlat",VVBUFL);
  11707. #endif /* SUPERLAT */
  11708. #ifdef NETFILE
  11709.             else if (nettype == NET_FILE)
  11710.               ckstrncpy(vvbuf,"local_file",VVBUFL);
  11711. #endif /* NETFILE */
  11712. #ifdef NETCMD
  11713.             else if (nettype == NET_CMD)
  11714.               ckstrncpy(vvbuf,"pipe",VVBUFL);
  11715. #endif /* NETCMD */
  11716. #ifdef NETPTY
  11717.             else if (nettype == NET_PTY)
  11718.               ckstrncpy(vvbuf,"pseudoterminal",VVBUFL);
  11719. #endif /* NETPTY */
  11720. #ifdef NETDLL
  11721.             else if (nettype == NET_DLL)
  11722.               ckstrncpy(vvbuf,"dynamic_link_library",VVBUFL);
  11723. #endif /* NETDLL */
  11724.  
  11725. #ifdef NPIPE
  11726.             else if (nettype == NET_PIPE)
  11727.               ckstrncpy(vvbuf,"named_pipe",VVBUFL);
  11728. #endif /* NPIPE */
  11729. #ifdef CK_NETBIOS
  11730.             else if (nettype == NET_BIOS)
  11731.               ckstrncpy(vvbuf,"netbios",VVBUFL);
  11732. #endif /* CK_NETBIOS */
  11733.             else
  11734.               ckstrncpy(vvbuf,"unknown",VVBUFL);
  11735.         }
  11736.         return(vvbuf);
  11737.  
  11738. #ifndef NOXFER
  11739.       case VN_SYSI:                     /* System ID, Kermit code */
  11740.         return((char *)cksysid);
  11741. #endif /* NOXFER */
  11742.  
  11743. #ifdef OS2
  11744.       case VN_SPA: {
  11745.           unsigned long space = zdskspace(0);
  11746.           if (space > 0 && space < 1024)
  11747.             sprintf(vvbuf,"-1");
  11748.           else
  11749.             sprintf(vvbuf,"%lu",space); /* SAFE */
  11750.           return(vvbuf);
  11751.       }
  11752. #endif /* OS2 */
  11753.  
  11754. #ifndef NOXFER
  11755.       case VN_QUE: {
  11756.           extern char querybuf[];
  11757.           return(querybuf);
  11758.       }
  11759. #endif /* NOXFER */
  11760.  
  11761. #ifndef NOCSETS
  11762.       case VN_CSET:
  11763. #ifdef OS2
  11764.         sprintf(vvbuf,"cp%d",os2getcp()); /* SAFE */
  11765. #else
  11766.         ckstrncpy(vvbuf,fcsinfo[fcharset].keyword,VVBUFL+1);
  11767. #endif /* OS2 */
  11768.         return(vvbuf);
  11769. #endif /* NOCSETS */
  11770.  
  11771. #ifdef OS2
  11772.       case VN_EXEDIR:
  11773.         return(exedir);
  11774.       case VN_STAR:
  11775.         return(startupdir);
  11776. #else
  11777.       case VN_EXEDIR:
  11778.         return(exedir ? exedir : "");
  11779. #ifdef VMSORUNIX
  11780.       case VN_STAR:
  11781.         return(startupdir);
  11782. #endif /* VMSORUNIX */
  11783. #endif /* OS2 */
  11784.  
  11785.       case VN_INI:
  11786.         return(inidir);
  11787.  
  11788.       case VN_MDM:
  11789.         return(gmdmtyp());
  11790.  
  11791.       case VN_EVAL:
  11792.         return(evalbuf);
  11793.  
  11794. #ifndef NODIAL
  11795.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  11796.         return(diallcc ? diallcc : "");
  11797.  
  11798.       case VN_D_AC:                     /* DIAL AREA-CODE */
  11799.         return(diallac ? diallac : "");
  11800.  
  11801.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  11802.         return(dialixp ? dialixp : "");
  11803.  
  11804.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  11805.         return(dialldp ? dialldp : "");
  11806.  
  11807.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  11808.         return(diallcp ? diallcp : "");
  11809.  
  11810.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE that matched */
  11811.         return(matchpxx ? matchpxx : "");
  11812. #else
  11813.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  11814.       case VN_D_AC:                     /* DIAL AREA-CODE */
  11815.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  11816.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  11817.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  11818.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE */
  11819.         return("");
  11820. #endif /* NODIAL */
  11821.       case VN_UID:
  11822. #ifdef UNIX
  11823.         {
  11824.             extern char * whoami();     /* From ckufio.c... */
  11825. #ifdef IKSD
  11826.             if (inserver)
  11827.               return((char *)uidbuf);
  11828.             else
  11829. #endif /* IKSD */
  11830.               if (uidbuf[0])
  11831.                 return((char *)uidbuf);
  11832.               else
  11833.                 return(whoami());
  11834.         }
  11835. #else
  11836.         return((char *)uidbuf);
  11837. #endif /* UNIX */
  11838.     } /* Break up long switch statements... */
  11839.  
  11840.     switch(y) {
  11841.       case VN_PWD:
  11842. #ifdef OS2
  11843.         if (activecmd == XXOUT || activecmd == XXLNOUT) {
  11844.             ckstrncpy(vvbuf,pwbuf,VVBUFL);
  11845.             ck_encrypt((char *)vvbuf);
  11846.             return((char *)vvbuf);
  11847.         } else
  11848. #endif /* OS2 */
  11849.           return((char *)pwbuf);
  11850.  
  11851.       case VN_PRM:
  11852.         return((char *)prmbuf);
  11853.  
  11854.       case VN_PROTO:
  11855. #ifdef NOXFER
  11856.         return("none");
  11857. #else
  11858. #ifdef CK_XYZ
  11859.         return(ptab[protocol].p_name);
  11860. #else
  11861.         return("kermit");
  11862. #endif /* CK_XYZ */
  11863. #endif /* NOXFER */
  11864.  
  11865. #ifndef NOXFER
  11866. #ifdef CK_TMPDIR
  11867.       case VN_DLDIR:
  11868.         return(dldir ? dldir : "");
  11869. #endif /* CK_TMPDIR */
  11870. #endif /* NOXFER */
  11871.  
  11872. #ifndef NODIAL
  11873.       case VN_M_INI:                    /* Modem init string */
  11874.         return(dialini ? dialini : (m ? m->wake_str : ""));
  11875.  
  11876.       case VN_M_DCM:                    /* Modem dial command */
  11877.         return(dialcmd ? dialcmd : (m ? m->dial_str : ""));
  11878.  
  11879.       case VN_M_DCO:                    /* Modem data compression on */
  11880.         return(dialdcon ? dialdcon : (m ? m->dc_on_str : ""));
  11881.  
  11882.       case VN_M_DCX:                    /* Modem data compression off */
  11883.         return(dialdcoff ? dialdcoff : (m ? m->dc_off_str : ""));
  11884.  
  11885.       case VN_M_ECO:                    /* Modem error correction on */
  11886.         return(dialecon ? dialecon : (m ? m->ec_on_str : ""));
  11887.  
  11888.       case VN_M_ECX:                    /* Modem error correction off */
  11889.         return(dialecoff ? dialecoff : (m ? m->ec_off_str : ""));
  11890.  
  11891.       case VN_M_AAO:                    /* Modem autoanswer on */
  11892.         return(dialaaon ? dialaaon : (m ? m->aa_on_str : ""));
  11893.  
  11894.       case VN_M_AAX:                    /* Modem autoanswer off */
  11895.         return(dialaaoff ? dialaaoff : (m ? m->aa_off_str : ""));
  11896.  
  11897.       case VN_M_HUP:                    /* Modem hangup command */
  11898.         return(dialhcmd ? dialhcmd : (m ? m->hup_str : ""));
  11899.  
  11900.       case VN_M_HWF:                    /* Modem hardware flow command */
  11901.         return(dialhwfc ? dialhwfc : (m ? m->hwfc_str : ""));
  11902.  
  11903.       case VN_M_SWF:                    /* Modem software flow command */
  11904.         return(dialswfc ? dialswfc : (m ? m->swfc_str : ""));
  11905.  
  11906.       case VN_M_NFC:                    /* Modem no flow-control command */
  11907.         return(dialnofc ? dialnofc : (m ? m->nofc_str : ""));
  11908.  
  11909.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  11910.         return(dialpulse ? dialpulse : (m ? m->pulse : ""));
  11911.  
  11912.       case VN_M_TDM:                    /* Modem tone dialing mode */
  11913.         return(dialtone ? dialtone : (m ? m->tone : ""));
  11914.  
  11915.       case VN_M_NAM:                    /* Modem full name */
  11916.         return(dialname ? dialname : (m ? m->name : ""));
  11917. #else
  11918.       case VN_M_INI:                    /* Modem init string */
  11919.       case VN_M_DCM:                    /* Modem dial command */
  11920.       case VN_M_DCO:                    /* Modem data compression on */
  11921.       case VN_M_DCX:                    /* Modem data compression off */
  11922.       case VN_M_ECO:                    /* Modem error correction on */
  11923.       case VN_M_ECX:                    /* Modem error correction off */
  11924.       case VN_M_AAO:                    /* Modem autoanswer on */
  11925.       case VN_M_AAX:                    /* Modem autoanswer off */
  11926.       case VN_M_HUP:                    /* Modem hangup command */
  11927.       case VN_M_HWF:                    /* Modem hardware flow command */
  11928.       case VN_M_SWF:                    /* Modem software flow command */
  11929.       case VN_M_NFC:                    /* Modem no flow-control command */
  11930.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  11931.       case VN_M_TDM:                    /* Modem tone dialing mode */
  11932.       case VN_M_NAM:
  11933.         return("");
  11934. #endif /* NODIAL */
  11935.  
  11936.       case VN_ISTAT:                    /* INPUT status */
  11937.         sprintf(vvbuf, "%d", instatus); /* SAFE */
  11938.         return(vvbuf);
  11939.  
  11940.       case VN_TEMP:                     /* Temporary directory */
  11941.         if (tempdir) {
  11942.             p = tempdir;
  11943.         } else {
  11944. #ifdef OS2
  11945. #ifdef NT
  11946.             p = getenv("K95TMP");
  11947. #else
  11948.             p = getenv("K2TMP");
  11949. #endif /* NT */
  11950.             if ( !p )
  11951. #endif /* OS2 */
  11952.               p = getenv("CK_TMP");
  11953.             if (!p) p = getenv("TMPDIR");
  11954.             if (!p) p = getenv("TEMP");
  11955.             if (!p) p = getenv("TMP");
  11956.  
  11957. #ifdef OS2ORUNIX
  11958.             if (p) {
  11959.                 int len = strlen(p);
  11960.                 if (p[len-1] != '/'
  11961. #ifdef OS2
  11962.                     && p[len-1] != '\\'
  11963. #endif /* OS2 */
  11964.                      ) {
  11965.                     static char foo[CKMAXPATH];
  11966.                     ckstrncpy(foo,p,CKMAXPATH);
  11967.                     ckstrncat(foo,"/",CKMAXPATH);
  11968.                     p = foo;
  11969.                 }
  11970.             } else
  11971. #else /* OS2ORUNIX */
  11972.             if (!p)
  11973. #endif /* OS2ORUNIX */
  11974. #ifdef UNIX                             /* Systems that have a standard */
  11975.               p = "/tmp/";              /* temporary directory... */
  11976. #else
  11977. #ifdef datageneral
  11978.               p = ":TMP:";
  11979. #else
  11980.               p = "";
  11981. #endif /* datageneral */
  11982. #endif /* UNIX */
  11983.         }
  11984.         ckstrncpy(vvbuf,p,VVBUFL);
  11985.         p = vvbuf;
  11986.  
  11987. /* This needs generalizing for VOS, AOS/VS, etc... */
  11988.  
  11989.         while (*p) {
  11990. #ifdef OS2
  11991.             if (*p == '\\') *p = '/';
  11992. #endif /* OS2 */
  11993.             p++;
  11994.         }
  11995. #ifndef VMS
  11996.         if (p > vvbuf) {
  11997.             char c =                    /* Directory termination character */
  11998. #ifdef MAC
  11999.               ':'
  12000. #else
  12001. #ifdef datageneral
  12002.               ':'
  12003. #else
  12004. #ifdef STRATUS
  12005.               '>'
  12006. #else
  12007.               '/'
  12008. #endif /* STRATUS */
  12009. #endif /* datageneral */
  12010. #endif /* MAC */
  12011.                 ;
  12012.  
  12013.             if (*(p-1) != c) {
  12014.                 *p++ = c;
  12015.                 *p = NUL;
  12016.             }
  12017.         }
  12018. #endif /* VMS */
  12019.         return(vvbuf);
  12020.     } /* Break up long switch statements... */
  12021.  
  12022.     switch(y) {
  12023.       case VN_ERRNO:                    /* Error number */
  12024. #ifdef VMS
  12025.         {
  12026.             extern int vms_lasterr;
  12027.             sprintf(vvbuf, "%d", vms_lasterr); /* SAFE */
  12028.         }
  12029. #else
  12030.         sprintf(vvbuf, "%d", errno);    /* SAFE */
  12031. #endif /* VMS */
  12032.         return(vvbuf);
  12033.  
  12034.       case VN_ERSTR:                    /* Error string */
  12035.         ckstrncpy(vvbuf,ck_errstr(),VVBUFL);
  12036.         return(vvbuf);
  12037.  
  12038. #ifndef NOXFER
  12039.       case VN_RPSIZ:                    /* RECEIVE packet-length */
  12040.         sprintf(vvbuf,"%d",urpsiz);     /* SAFE */
  12041.         return(vvbuf);
  12042.  
  12043.       case VN_WINDO:                    /* WINDOW slots */
  12044.         sprintf(vvbuf,"%d",wslotr);     /* SAFE */
  12045.         return(vvbuf);
  12046. #endif /* NOXFER */
  12047.  
  12048.       case VN_TFLN:                     /* TAKE-file line number */
  12049.         if (tlevel > -1) {
  12050.             sprintf(vvbuf, "%d", tfline[tlevel]); /* SAFE */
  12051.             return(vvbuf);
  12052.         } else
  12053.           return("0");
  12054.  
  12055.       case VN_MDMSG:                    /* DIALRESULT */
  12056. #ifndef NODIAL
  12057.         return((char *)modemmsg);
  12058. #else
  12059.         return("");
  12060. #endif /* NODIAL */
  12061.  
  12062.       case VN_DNUM:                     /* DIALNUMBER */
  12063. #ifndef NODIAL
  12064.         return(dialnum ? (char *) dialnum : "");
  12065. #else
  12066.         return("");
  12067. #endif /* NODIAL */
  12068.  
  12069.       case VN_APC:
  12070.         sprintf(vvbuf, "%d",            /* SAFE */
  12071. #ifdef CK_APC
  12072.                 apcactive
  12073. #else
  12074.                 0
  12075. #endif /* CK_APC */
  12076.                 );
  12077.         return((char *)vvbuf);
  12078.  
  12079. #ifdef OS2
  12080. #ifndef NOKVERBS
  12081.       case VN_TRMK:
  12082.           sprintf(vvbuf, "%d", keymac); /* SAFE */
  12083.         return((char *)vvbuf);
  12084. #endif /* NOKVERBS */
  12085. #endif /* OS2 */
  12086.  
  12087.       case VN_IPADDR:
  12088. #ifdef TCPSOCKET
  12089. #ifndef OSK
  12090.       /* This dumps core on OS-9 for some reason, but only if executed */
  12091.       /* before we have made a TCP connection.  This is obviously not */
  12092.       /* the ideal fix. */
  12093.         if (!myipaddr[0])
  12094.           getlocalipaddr();
  12095. #endif /* OSK */
  12096. #endif /* TCPSOCKET */
  12097.         ckstrncpy(vvbuf,
  12098. #ifdef TCPSOCKET
  12099.                 (char *)myipaddr,
  12100. #else
  12101.                 "",
  12102. #endif /* TCPSOCKET */
  12103.                 VVBUFL);
  12104.         return((char *)vvbuf);
  12105.  
  12106. #ifndef NOXFER
  12107.       case VN_CRC16:                    /* CRC-16 of most recent transfer */
  12108.         sprintf(vvbuf,"%d",crc16);      /* SAFE */
  12109.         return(vvbuf);
  12110. #endif /* NOXFER */
  12111.  
  12112. #ifdef CK_PID
  12113.       case VN_PID:
  12114. #ifdef IKSD
  12115. #ifdef CK_LOGIN
  12116.         if (inserver && isguest)
  12117.           return("");
  12118. #endif /* CK_LOGIN */
  12119. #endif /* IKSD */
  12120.         return(ckgetpid());
  12121. #endif /* CK_PID */
  12122.  
  12123. #ifndef NOXFER
  12124.       case VN_FNAM: {                   /* \v(filename) */
  12125.           extern char filnam[], ofn1[], *sfspec, *rrfspec;
  12126.           char * tmp;
  12127.           switch (what) {               /* File transfer is in progress */
  12128. #ifdef NEWFTP
  12129.             case (W_FTP|W_RECV):
  12130.             case (W_FTP|W_SEND):
  12131.               return((char *)filnam);
  12132. #endif /* NEWFTP */
  12133.             case W_RECV:
  12134.             case W_REMO:
  12135.               return((char *)ofn1);
  12136.             default:                    /* Most recent file transferred */
  12137.               if (filnam[0]) {          /* (if any) */
  12138.                   return((char *)filnam);
  12139.               } else if (lastxfer & W_SEND && sfspec) {
  12140.                   if (fnspath == PATH_OFF)
  12141.                     zstrip(sfspec,&tmp);
  12142.                   else
  12143.                     tmp = sfspec;
  12144.                   return(tmp);
  12145.               } else if (lastxfer & W_RECV && rrfspec) {
  12146.                   if (fnrpath == PATH_OFF)
  12147.                     zstrip(rrfspec,&tmp);
  12148.                   else
  12149.                     tmp = rrfspec;
  12150.                   return(tmp);
  12151.               } else
  12152.                 return("");
  12153.           }
  12154.       }
  12155.       case VN_FNUM:                     /* \v(filenum) */
  12156.         sprintf(vvbuf,"%ld",filcnt);    /* SAFE */
  12157.         return((char *)vvbuf);
  12158. #endif /* NOXFER */
  12159.  
  12160. #ifdef PEXITSTAT
  12161.       case VN_PEXIT: {
  12162.           extern int pexitstat;
  12163.           sprintf(vvbuf,"%d",pexitstat); /* SAFE */
  12164.           return((char *)vvbuf);
  12165.       }
  12166. #endif /* PEXITSTAT */
  12167.  
  12168. #ifndef NOXFER
  12169.       case VN_P_8BIT:
  12170.         vvbuf[0] = parity ? ebq : NUL;
  12171.         vvbuf[1] = NUL;
  12172.         return((char *)vvbuf);
  12173.  
  12174.       case VN_P_CTL: {
  12175.           extern CHAR myctlq;
  12176.           vvbuf[0] = myctlq;
  12177.           vvbuf[1] = NUL;
  12178.           return((char *)vvbuf);
  12179.       }
  12180.       case VN_P_RPT: {
  12181.           extern int rptena;
  12182.           vvbuf[0] = rptena ? rptq : NUL;
  12183.           vvbuf[1] = NUL;
  12184.           return((char *)vvbuf);
  12185.       }
  12186. #endif /* NOXFER */
  12187.  
  12188. #ifdef OS2
  12189.       case VN_REGN:
  12190.         return(get_reg_name());
  12191.       case VN_REGO:
  12192.         return(get_reg_corp());
  12193.       case VN_REGS:
  12194.         return(get_reg_sn());
  12195. #endif /* OS2 */
  12196.     } /* Break up long switch statements... */
  12197.  
  12198.     switch(y) {
  12199.       case VN_XPROG:
  12200. #ifdef OS2
  12201. #ifdef NT
  12202. #ifdef KUI
  12203.         return("K-95G");
  12204. #else
  12205.         return("K-95");
  12206. #endif /* KUI */
  12207. #else
  12208.         return("K/2");
  12209. #endif /* NT */
  12210. #else
  12211.         return("C-Kermit");
  12212. #endif /* OS2 */
  12213.  
  12214.       case VN_EDITOR:
  12215. #ifdef NOFRILLS
  12216.         return("");
  12217. #else
  12218. #ifdef NOPUSH
  12219.         return("");
  12220. #else
  12221.         {
  12222.             extern char editor[];
  12223.             char *ss;
  12224.             if (!editor[0]) {
  12225.                 ss = getenv("EDITOR");
  12226.                 if (ss) {
  12227.                     ckstrncpy(editor,ss,CKMAXPATH);
  12228.                 }
  12229.             }
  12230.             debug(F110,"\\v(editor)",editor,0);
  12231.             return(editor[0] ? (char *)editor : "");
  12232.         }
  12233. #endif /* NOPUSH */
  12234. #endif /* NOFRILLS */
  12235.  
  12236.       case VN_EDOPT:
  12237. #ifdef NOFRILLS
  12238.         return("");
  12239. #else
  12240. #ifdef NOPUSH
  12241.         return("");
  12242. #else
  12243.         {
  12244.             extern char editopts[];
  12245.             return(editopts[0] ? (char *)editopts : "");
  12246.         }
  12247. #endif /* NOPUSH */
  12248. #endif /* NOFRILLS */
  12249.  
  12250.       case VN_EDFILE:
  12251. #ifdef NOFRILLS
  12252.         return("");
  12253. #else
  12254. #ifdef NOPUSH
  12255.         return("");
  12256. #else
  12257.         {
  12258.             extern char editfile[];
  12259.             return(editfile[0] ? (char *)editfile : "");
  12260.         }
  12261. #endif /* NOPUSH */
  12262. #endif /* NOFRILLS */
  12263.  
  12264. #ifdef BROWSER
  12265.       case VN_BROWSR: {
  12266.           extern char browser[];
  12267.           if (!browser[0]) {
  12268.               s = getenv("BROWSER");
  12269.               if (s) ckstrncpy(browser,s,CKMAXPATH);
  12270.           }
  12271.           return(browser[0] ? (char *)browser : "");
  12272.       }
  12273.       case VN_BROPT: {
  12274.           extern char browsopts[];
  12275.           return(browsopts[0] ? (char *)browsopts : "");
  12276.       }
  12277.       case VN_URL: {
  12278.           extern char browsurl[];
  12279.           return(browsurl[0] ? (char *)browsurl : "");
  12280.       }
  12281. #endif /* BROWSER */
  12282.       case VN_HERALD:
  12283.         return((char *)versio);
  12284.  
  12285.       case VN_TEST: {                   /* test */
  12286.           extern char * ck_s_test, * ck_s_tver;
  12287.           if (!ck_s_test) ck_s_test = "";
  12288.           if (!ck_s_tver) ck_s_tver = "";
  12289.           if (*ck_s_test) {
  12290.               ckstrncpy(vvbuf,ck_s_test,VVBUFL);
  12291.               if (*ck_s_tver) {
  12292.                   ckstrncat(vvbuf,".",VVBUFL);
  12293.                   ckstrncat(vvbuf,ck_s_tver,VVBUFL);
  12294.               }
  12295.           } else
  12296.             ckstrncpy(vvbuf,"0",VVBUFL);
  12297.           return((char *)vvbuf);
  12298.       }
  12299.  
  12300. #ifndef NOXFER
  12301.       case VN_XFSTAT:                   /* xferstatus */
  12302.         x = xferstat;                   /* Like success */
  12303.         if (x > -1) x = (x == 0) ? 1 : 0; /* External value is reversed */
  12304.         sprintf(vvbuf,"%d",x);          /* SAFE */
  12305.         return((char *)vvbuf);
  12306.  
  12307.       case VN_XFMSG:                    /* xfermsg */
  12308.         return((char *)epktmsg);
  12309.  
  12310. #ifndef NOMSEND
  12311.       case VN_SNDL: {                   /* sendlist */
  12312.           extern int filesinlist;
  12313.           sprintf(vvbuf,"%d",filesinlist); /* SAFE */
  12314.           return((char *)vvbuf);
  12315.       }
  12316. #endif /* NOMSEND */
  12317. #endif /* NOXFER */
  12318.  
  12319. #ifdef CK_TRIGGER
  12320.       case VN_TRIG: {
  12321.           extern char * triggerval;
  12322.           return(triggerval ? triggerval : "");
  12323.       }
  12324. #endif /* CK_TRIGGER */
  12325. #ifdef OS2MOUSE
  12326. #ifdef OS2
  12327.       case VN_MOU_X: {
  12328.           extern int MouseCurX;
  12329.           sprintf(vvbuf,"%d",MouseCurX); /* SAFE */
  12330.           return((char *)vvbuf);
  12331.       }
  12332.       case VN_MOU_Y: {
  12333.           extern int MouseCurY;
  12334.           sprintf(vvbuf,"%d",MouseCurY); /* SAFE */
  12335.           return((char *)vvbuf);
  12336.       }
  12337. #endif /* OS2 */
  12338. #endif /* OS2MOUSE */
  12339.       case VN_PRINT: {
  12340.           extern int printpipe;
  12341.           extern char * printername;
  12342. #ifdef PRINTSWI
  12343.           extern int noprinter;
  12344.           if (noprinter) return("");
  12345. #endif /* PRINTSWI */
  12346.           ckmakmsg(vvbuf,VVBUFL,
  12347.                    printpipe ? "|" : "",
  12348.                    printername ? printername :
  12349. #ifdef OS2
  12350.                    "PRN",
  12351. #else
  12352.                    "(default)",
  12353. #endif /* OS2 */
  12354.                    NULL,
  12355.                    NULL
  12356.                    );
  12357.           return((char *)vvbuf);
  12358.       }
  12359.     } /* Break up long switch statements... */
  12360.  
  12361.     switch(y) {
  12362.       case VN_ESC:                      /* Escape character */
  12363.         sprintf(vvbuf,"%d",escape);     /* SAFE */
  12364.         return((char *)vvbuf);
  12365.  
  12366.       case VN_INTIME:
  12367.         sprintf(vvbuf,"%ld",inetime);   /* SAFE */
  12368.         return((char *)vvbuf);
  12369.  
  12370.       case VN_INTMO:
  12371.         sprintf(vvbuf,"%d",inwait);     /* SAFE */
  12372.         return((char *)vvbuf);
  12373.  
  12374.       case VN_SECURE:
  12375.         if (0
  12376. #ifdef SSHBUILTIN
  12377.             || IS_SSH()
  12378. #endif /* SSHBUILTIN */
  12379. #ifdef CK_ENCRYPTION
  12380.             || ck_tn_encrypting() && ck_tn_decrypting()
  12381. #endif /* CK_ENCRYPTION */
  12382. #ifdef CK_SSL
  12383.             || tls_active_flag || ssl_active_flag
  12384. #endif /* CK_SSL */
  12385.             )
  12386.           return("1");
  12387.         else
  12388.           return("0");
  12389.  
  12390.       case VN_AUTHN:
  12391. #ifdef CK_AUTHENTICATION
  12392.         {
  12393.             extern char szUserNameAuthenticated[];
  12394.             return((char *)szUserNameAuthenticated);
  12395.         }
  12396. #else /* CK_AUTHENTICATION */
  12397.         return((char *)"");
  12398. #endif /* CK_AUTHENTICATION */
  12399.  
  12400.       case VN_AUTHS:
  12401. #ifdef CK_AUTHENTICATION
  12402.         switch (ck_tn_auth_valid()) {
  12403.           case AUTH_UNKNOWN:
  12404.             return((char *)"unknown");
  12405.           case AUTH_OTHER:
  12406.             return((char *)"other");
  12407.           case AUTH_USER:
  12408.             return((char *)"user");
  12409.           case AUTH_VALID:
  12410.             return((char *)"valid");
  12411.           case AUTH_REJECT:
  12412.           default:
  12413.             return((char *)"rejected");
  12414.         }
  12415. #else /* CK_AUTHENTICATION */
  12416.         return((char *)"rejected");
  12417. #endif /* CK_AUTHENTICATION */
  12418.  
  12419.       case VN_AUTHT:
  12420. #ifdef CK_AUTHENTICATION
  12421. #ifdef CK_SSL
  12422.         if ((ssl_active_flag || tls_active_flag) &&
  12423.             ck_tn_auth_valid() == AUTH_VALID &&
  12424.             (sstelnet ? (!TELOPT_U(TELOPT_AUTHENTICATION)) :
  12425.                         (!TELOPT_ME(TELOPT_AUTHENTICATION))) ||
  12426.              ck_tn_authenticated() == AUTHTYPE_NULL ||
  12427.              ck_tn_authenticated() == AUTHTYPE_AUTO)
  12428.           return("X_509_CERTIFICATE");
  12429.         else
  12430. #endif /* CK_SSL */
  12431.           return(AUTHTYPE_NAME(ck_tn_authenticated()));
  12432. #else /* CK_AUTHENTICATION */
  12433.         return((char *)"NULL");
  12434. #endif /* CK_AUTHENTICATION */
  12435.  
  12436. #ifdef CK_KERBEROS
  12437.       case VN_K4PRN: {
  12438.           extern char * krb4_d_principal;
  12439.           if (krb4_d_principal)
  12440.             ckstrncpy(vvbuf,krb4_d_principal,VVBUFL+1);
  12441.           else
  12442.             *vvbuf = NUL;
  12443.           return((char *)vvbuf);
  12444.       }
  12445.       case VN_K5PRN: {
  12446.           extern char * krb5_d_principal;
  12447.           if (krb5_d_principal)
  12448.             ckstrncpy(vvbuf,krb5_d_principal,VVBUFL+1);
  12449.           else
  12450.             *vvbuf = NUL;
  12451.           return((char *)vvbuf);
  12452.       }
  12453.       case VN_K4RLM: {
  12454.           extern char * krb4_d_realm;
  12455.           if (krb4_d_realm) {
  12456.               ckstrncpy(vvbuf,krb4_d_realm,VVBUFL+1);
  12457.           } else {
  12458.               char * s = ck_krb4_getrealm();
  12459.               ckstrncpy(vvbuf,s ? s : "",VVBUFL+1);
  12460.           }
  12461.           return((char *)vvbuf);
  12462.       }
  12463.       case VN_K4SRV: {
  12464.           extern char * krb4_d_srv;
  12465.           if (krb4_d_srv)
  12466.             ckstrncpy(vvbuf,krb4_d_srv,VVBUFL+1);
  12467.           else
  12468.             ckstrncpy(vvbuf,"rcmd",VVBUFL);
  12469.           return((char *)vvbuf);
  12470.       }
  12471.       case VN_K5RLM: {
  12472.           extern char * krb5_d_realm;
  12473.           extern char * krb5_d_cc;
  12474.           if (krb5_d_realm) {
  12475.               ckstrncpy(vvbuf,krb5_d_realm,VVBUFL+1);
  12476.           } else {
  12477.               char * s = ck_krb5_getrealm(krb5_d_cc);
  12478.               ckstrncpy(vvbuf,s,VVBUFL+1);
  12479.           }
  12480.           return((char *)vvbuf);
  12481.       }
  12482.       case VN_K5CC: {
  12483.           extern char * krb5_d_cc;
  12484.           if (krb5_d_cc)
  12485.             ckstrncpy(vvbuf,krb5_d_cc,VVBUFL+1);
  12486.           else
  12487.             ckstrncpy(vvbuf,ck_krb5_get_cc_name(),VVBUFL+1);
  12488.           return((char *)vvbuf);
  12489.       }
  12490.       case VN_K5SRV: {
  12491.           extern char * krb5_d_srv;
  12492.           if (krb5_d_srv)
  12493.             ckstrncpy(vvbuf,krb5_d_srv,VVBUFL+1);
  12494.           else
  12495.             ckstrncpy(vvbuf,"host",VVBUFL);
  12496.           return((char *)vvbuf);
  12497.       }
  12498.       case VN_K4ENO: {
  12499.         extern char * krb4_errno;
  12500.         sprintf(vvbuf,"%d",krb4_errno); /* SAFE */
  12501.         return((char *)vvbuf);
  12502.       }
  12503.       case VN_K5ENO: {
  12504.         extern char * krb5_errno;
  12505.         sprintf(vvbuf,"%d",krb5_errno); /* SAFE */
  12506.         return((char *)vvbuf);
  12507.       }
  12508.       case VN_K4EMSG: {
  12509.         extern char * krb4_errmsg;
  12510.         ckstrncpy(vvbuf,krb4_errmsg?krb4_errmsg:"",VVBUFL+1);
  12511.         return((char *)vvbuf);
  12512.       }
  12513.       case VN_K5EMSG: {
  12514.         extern char * krb5_errmsg;
  12515.         ckstrncpy(vvbuf,krb5_errmsg,VVBUFL+1);
  12516.         return((char *)vvbuf);
  12517.       }
  12518. #endif /* CK_KERBEROS */
  12519. #ifdef CK_SSL
  12520.       case VN_X509_S:
  12521.         if (ssl_active_flag)
  12522.           ckstrncpy(vvbuf,ssl_get_subject_name(ssl_con),VVBUFL+1);
  12523.         else if (tls_active_flag)
  12524.           ckstrncpy(vvbuf,ssl_get_subject_name(tls_con),VVBUFL+1);
  12525.         else
  12526.           ckstrncpy(vvbuf,"",VVBUFL+1);
  12527.         return((char *)vvbuf);
  12528.       case VN_X509_I:
  12529.         if (ssl_active_flag)
  12530.           ckstrncpy(vvbuf,ssl_get_issuer_name(ssl_con),VVBUFL+1);
  12531.         else if (tls_active_flag)
  12532.           ckstrncpy(vvbuf,ssl_get_issuer_name(tls_con),VVBUFL+1);
  12533.         else
  12534.           ckstrncpy(vvbuf,"",VVBUFL+1);
  12535.         return((char *)vvbuf);
  12536. #endif /* CK_SSL */
  12537.  
  12538.       case VN_OSNAM:
  12539. #ifdef IKSD
  12540. #ifdef CK_LOGIN
  12541.         if (inserver && isguest)
  12542.           return("");
  12543. #endif /* CK_LOGIN */
  12544. #endif /* IKSD */
  12545. #ifdef CK_UTSNAME
  12546.         {
  12547.             extern char unm_nam[];
  12548.             return((char *)unm_nam);
  12549.         }
  12550. #else
  12551.         for (x = y = 0; x < VVBUFL; x++) {
  12552.             if (ckxsys[x] == SP && cx == 0) continue;
  12553.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  12554.         }
  12555.         vvbuf[y] = NUL;
  12556.         return(vvbuf);
  12557. #endif /* CK_UTSNAME */
  12558.  
  12559.       case VN_OSVER: {
  12560. #ifdef CK_UTSNAME
  12561.           extern char unm_ver[];
  12562. #ifdef IKSD
  12563. #ifdef CK_LOGIN
  12564.           if (inserver && isguest)
  12565.             return("");
  12566. #endif /* CK_LOGIN */
  12567. #endif /* IKSD */
  12568.           return((char *)unm_ver);
  12569. #else
  12570.           return("");
  12571. #endif /* CK_UTSNAME */
  12572.       }
  12573.  
  12574.       case VN_OSREL: {
  12575. #ifdef CK_UTSNAME
  12576.           extern char unm_rel[];
  12577. #ifdef IKSD
  12578. #ifdef CK_LOGIN
  12579.           if (inserver && isguest)
  12580.             return("");
  12581. #endif /* CK_LOGIN */
  12582. #endif /* IKSD */
  12583.           return((char *)unm_rel);
  12584. #else
  12585.           return("");
  12586. #endif /* CK_UTSNAME */
  12587.       }
  12588.     } /* Break up long switch statements... */
  12589.  
  12590.     switch(y) {
  12591.       case VN_NAME: {
  12592.           extern char * myname;
  12593.           return(myname);
  12594.       }
  12595.  
  12596.       case VN_MODL: {
  12597. #ifdef CK_UTSNAME
  12598.           extern char unm_mod[], unm_mch[];
  12599.           int y = VVBUFL - 1;
  12600.           char * s = unm_mod;
  12601. #endif /* CK_UTSNAME */
  12602. #ifdef IKSD
  12603. #ifdef CK_LOGIN
  12604.           if (inserver && isguest)
  12605.             return("");
  12606. #endif /* CK_LOGIN */
  12607. #endif /* IKSD */
  12608.  
  12609. #ifdef COMMENT                          /* was HPUX */
  12610.           if (!unm_mod[0] && !nopush)
  12611.             zzstring("\\fcommand(model)",&s,&y);
  12612. /*
  12613.    Another possibility would be:
  12614.      "\\fcommand(ksh -c 'whence model 1>&- && model || uname -m')"
  12615.    But that would depend on having ksh.
  12616. */
  12617. #else
  12618. #ifdef OSF32                            /* Digital UNIX 3.2 and higher... */
  12619. /* Note: Ultrix has /etc/sizer, but it is not publicly executable. */
  12620. /* sizer -c outputs 'cpu:<tab><tab>"DECxxxx"' */
  12621.           if (!unm_mod[0]) {
  12622.               char * p;
  12623.               int flag = 0;
  12624.               zzstring("\\fcommand(/usr/sbin/sizer -c)",&s,&y);
  12625.               debug(F110,"DU model",unm_mod,0);
  12626.               s = unm_mod;
  12627.               p = unm_mod;
  12628.               while (*p) {              /* Extract the part in quotes */
  12629.                   if (*p == '"') {
  12630.                       if (flag)
  12631.                         break;
  12632.                       flag = 1;
  12633.                       p++;
  12634.                       continue;
  12635.                   }
  12636.                   if (flag)
  12637.                     *s++ = *p;
  12638.                   p++;
  12639.               }
  12640.               *s = NUL;
  12641.           }
  12642. #endif /* OSF32 */
  12643. #endif /* COMMENT */
  12644.  
  12645. #ifdef CK_UTSNAME
  12646.           if (unm_mod[0])
  12647.             return((char *)unm_mod);
  12648.           else
  12649.             return((char *)unm_mch);
  12650. #else
  12651.           return("");
  12652. #endif /* CK_UTSNAME */
  12653.       }
  12654.  
  12655. #ifdef IBMX25
  12656.       /* X.25 variables (local and remote address) */
  12657.       case VN_X25LA:
  12658.         if (!local_nua[0] && !x25local_nua(local_nua))
  12659.           *vvbuf = NULL;
  12660.         else
  12661.           ckstrncpy(vvbuf,local_nua,VVBUFL+1);
  12662.         return((char *)vvbuf);
  12663.  
  12664.       case VN_X25RA:
  12665.         if (!remote_nua[0])
  12666.           *vvbuf = NULL;
  12667.         else
  12668.           ckstrncpy(vvbuf,remote_nua,VVBUFL+1);
  12669.         return((char *)vvbuf);
  12670. #endif /* IBMX25 */
  12671.  
  12672. #ifndef NODIAL
  12673.       case VN_PDSFX: {
  12674.           extern char pdsfx[];
  12675.           return((char *)pdsfx);
  12676.       }
  12677.       case VN_DTYPE: {
  12678.           extern int dialtype;
  12679.           sprintf(vvbuf,"%d",dialtype); /* SAFE */
  12680.           return((char *)vvbuf);
  12681.       }
  12682. #endif /* NODIAL */
  12683.  
  12684. #ifdef UNIX
  12685.       case VN_LCKPID: {
  12686.           extern char lockpid[];
  12687.           return((char *)lockpid);
  12688.       }
  12689. #endif /* UNIX */
  12690.  
  12691. #ifndef NOXFER
  12692.       case VN_BLK:
  12693.         sprintf(vvbuf,"%d",bctr);       /* SAFE */
  12694.         return((char *)vvbuf);
  12695.  
  12696.       case VN_TFTIM:
  12697.         sprintf(vvbuf,                  /* SAFE */
  12698. #ifdef GFTIMER
  12699.                 "%ld", (long)(fptsecs + 0.5)
  12700. #else
  12701.                 "%d", tsecs
  12702. #endif /* GFTIMER */
  12703.                 );
  12704.         return((char *)vvbuf);
  12705. #endif /* NOXFER */
  12706.  
  12707.       case VN_HWPAR:
  12708.       case VN_SERIAL: {
  12709.           int sb;
  12710.           char c, * ss;
  12711.           extern int stopbits;
  12712.           vvbuf[0] = NUL;
  12713.           if (hwparity && local && !network)
  12714.             ss = parnam((char)hwparity);
  12715.           else
  12716.             ss = parnam((char)parity);
  12717.           if (cx == VN_HWPAR) {
  12718.               ckstrncpy(vvbuf,ss,VVBUFL);
  12719.               return((char *)vvbuf);
  12720.           }
  12721.           c = ss[0];
  12722.           if (islower(c)) c = toupper(c);
  12723.           sb = stopbits;
  12724.           if (sb < 1)
  12725.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  12726.           if (hwparity)
  12727.             sprintf(vvbuf," 8%c%d",c,sb); /* SAFE */
  12728.           else if (parity)
  12729.             sprintf(vvbuf," 7%c%d",c,sb); /* SAFE */
  12730.           else
  12731.             sprintf(vvbuf," 8N%d",sb);  /* SAFE */
  12732.           return((char *)vvbuf);
  12733.       }
  12734.  
  12735. #ifdef UNIX
  12736.       case VN_LCKDIR: {
  12737. #ifndef NOUUCP
  12738.           extern char * uucplockdir;
  12739.           ckstrncpy(vvbuf,uucplockdir,VVBUFL);
  12740.           x = strlen(vvbuf);
  12741.           if (x > 0) {
  12742.               if (vvbuf[x-1] != '/') {
  12743.                   vvbuf[x] = '/';
  12744.                   vvbuf[x+1] = NUL;
  12745.               }
  12746.           }
  12747. #else
  12748.           vvbuf[0] = NUL;
  12749. #endif /* NOUUCP */
  12750.           return((char *)vvbuf);
  12751.       }
  12752. #endif /* UNIX */
  12753.     } /* Break up long switch statements... */
  12754.  
  12755.     switch(y) {
  12756. #ifndef NODIAL
  12757.       case VN_DM_LP:
  12758.       case VN_DM_SP:
  12759.       case VN_DM_PD:
  12760.       case VN_DM_TD:
  12761.       case VN_DM_WA:
  12762.       case VN_DM_WD:
  12763.       case VN_DM_HF:
  12764.       case VN_DM_WB:
  12765.       case VN_DM_RC: {
  12766.           extern char * getdm();
  12767.           ckstrncpy(vvbuf,getdm(y),VVBUFL);
  12768.           return((char *)vvbuf);
  12769.       }
  12770. #endif /* NODIAL */
  12771.  
  12772.       case VN_TY_LN:
  12773.       case VN_TY_LC: {
  12774.           extern int typ_lines;
  12775.           sprintf(vvbuf,"%d",typ_lines); /* SAFE */
  12776.           return((char *)vvbuf);
  12777.       }
  12778.       case VN_TY_LM: {
  12779.           extern int typ_mtchs;
  12780.           sprintf(vvbuf,"%d",typ_mtchs); /* SAFE */
  12781.           return((char *)vvbuf);
  12782.       }
  12783.       case VN_MACLVL:
  12784.         sprintf(vvbuf,"%d",maclvl);     /* SAFE */
  12785.         return((char *)vvbuf);
  12786.     } /* Break up long switch statements... */
  12787.  
  12788.     switch(y) {
  12789. #ifndef NOXFER
  12790.       case VN_XF_BC:
  12791.         sprintf(vvbuf,"%d",crunched);   /* SAFE */
  12792.         return((char *)vvbuf);
  12793.  
  12794.       case VN_XF_TM:
  12795.         sprintf(vvbuf,"%d",timeouts);   /* SAFE */
  12796.         return((char *)vvbuf);
  12797.  
  12798.       case VN_XF_RX:
  12799.         sprintf(vvbuf,"%d",retrans);    /* SAFE */
  12800.         return((char *)vvbuf);
  12801. #endif /* NOXFER */
  12802.  
  12803.       case VN_MS_CD:                    /* Modem signals */
  12804.       case VN_MS_CTS:
  12805.       case VN_MS_DSR:
  12806.       case VN_MS_DTR:
  12807.       case VN_MS_RI:
  12808.       case VN_MS_RTS: {
  12809.           int x, z = -1;
  12810.           x = ttgmdm();                 /* Try to get them */
  12811.           if (x > -1) {
  12812.               switch (y) {
  12813.                 case VN_MS_CD:  z = (x & BM_DCD) ? 1 : 0; break;
  12814.                 case VN_MS_DSR: z = (x & BM_DSR) ? 1 : 0; break;
  12815.                 case VN_MS_CTS: z = (x & BM_CTS) ? 1 : 0; break;
  12816. #ifdef MAC
  12817.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  12818. #else
  12819. #ifndef STRATUS
  12820.                 case VN_MS_RI:  z = (x & BM_RNG) ? 1 : 0; break;
  12821. #ifndef NT
  12822.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  12823.                 case VN_MS_RTS: z = (x & BM_RTS) ? 1 : 0; break;
  12824. #endif /* NT */
  12825. #endif /* STRATUS */
  12826. #endif /* MAC */
  12827.               }
  12828.           }
  12829.           sprintf(vvbuf,"%d",z);        /* SAFE */
  12830.           return((char *)vvbuf);
  12831.       }
  12832.       case VN_MATCH:                    /* INPUT MATCH */
  12833.         return(inpmatch ? inpmatch : "");
  12834.  
  12835.       case VN_SLMSG: {                  /* SET LINE / HOST message */
  12836.           extern char * slmsg;
  12837.           vvbuf[0] = NUL;
  12838.           if (slmsg)
  12839.             ckstrncpy(vvbuf,slmsg,VVBUFL);
  12840.          return(vvbuf);
  12841.       }
  12842.  
  12843.       case VN_TXTDIR:                   /* TEXTDIR */
  12844.         return(k_info_dir ? k_info_dir : "");
  12845.  
  12846. #ifdef FNFLOAT
  12847.       case VN_MA_PI:
  12848.         return(math_pi);
  12849.  
  12850.       case VN_MA_E:
  12851.         return(math_e);
  12852.  
  12853.       case VN_MA_PR:
  12854.         sprintf(vvbuf,"%d",fp_digits);  /* SAFE */
  12855.         return(vvbuf);
  12856. #endif /* FNFLOAT */
  12857.  
  12858.       case VN_CMDBL:
  12859.         sprintf(vvbuf,"%d",CMDBL);      /* SAFE */
  12860.         return(vvbuf);
  12861.  
  12862. #ifdef CKCHANNELIO
  12863.       case VN_FERR: {
  12864.           extern int z_error;
  12865.           sprintf(vvbuf,"%d",z_error);  /* SAFE */
  12866.           return(vvbuf);
  12867.       }
  12868.       case VN_FMAX: {
  12869.           extern int z_maxchan;
  12870.           sprintf(vvbuf,"%d",z_maxchan); /* SAFE */
  12871.           return(vvbuf);
  12872.       }
  12873.       case VN_FCOU: {
  12874.           extern int z_filcount;
  12875.           sprintf(vvbuf,"%d",z_filcount); /* SAFE */
  12876.           return(vvbuf);
  12877.       }
  12878. #endif /* CKCHANNELIO */
  12879.  
  12880. #ifndef NODIAL
  12881.       case VN_DRTR: {
  12882.           extern int dialcount;
  12883.           sprintf(vvbuf,"%d",dialcount); /* SAFE */
  12884.           return(vvbuf);
  12885.       }
  12886. #endif /* NODIAL */
  12887.  
  12888. #ifndef NOLOGDIAL
  12889. #ifndef NOLOCAL
  12890.       case VN_CXTIME:
  12891.         sprintf(vvbuf,"%ld",dologshow(0)); /* SAFE */
  12892.         return(vvbuf);
  12893. #endif /* NOLOCAL */
  12894. #endif /* NOLOGDIAL */
  12895.  
  12896.       case VN_BYTE:
  12897.         sprintf(vvbuf,"%d",byteorder);  /* SAFE */
  12898.         return(vvbuf);
  12899.  
  12900.       case VN_KBCHAR:
  12901.         vvbuf[0] = NUL;
  12902.         vvbuf[1] = NUL;
  12903.         if (kbchar > 0)
  12904.           vvbuf[0] = (kbchar & 0xff);
  12905.         return(vvbuf);
  12906.  
  12907.       case VN_TTYNAM: {
  12908. #ifdef HAVECTTNAM
  12909.           extern char cttnam[];
  12910.           return((char *)cttnam);
  12911. #else
  12912.           return(CTTNAM);
  12913. #endif /* HAVECTTNAM */
  12914.       }
  12915.  
  12916.       case VN_PROMPT:
  12917.         return(cmgetp());
  12918.  
  12919.       case VN_BUILD: {
  12920.           extern char * buildid;
  12921.           return(buildid);
  12922.       }
  12923.  
  12924. #ifndef NOSEXP
  12925.       case VN_SEXP: {
  12926.           extern char * lastsexp;
  12927.           return(lastsexp ? lastsexp : "");
  12928.       }
  12929.       case VN_VSEXP: {
  12930.           extern char * sexpval;
  12931.           return(sexpval ? sexpval : "");
  12932.       }
  12933.       case VN_LSEXP: {
  12934.           extern int sexpdep;
  12935.           ckstrncpy(vvbuf,ckitoa(sexpdep),VVBUFL);
  12936.           return(vvbuf);
  12937.       }
  12938. #endif /* NOSEXP */
  12939.  
  12940. #ifdef GFTIMER
  12941.       case VN_FTIME: {
  12942.           CKFLOAT f;
  12943.           ztime(&p);
  12944.           if (p == NULL || *p == NUL)
  12945.             return(NULL);
  12946.           z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  12947.           f = (CKFLOAT)z + ((CKFLOAT)ztusec) / 1000000.0;
  12948.           sprintf(vvbuf,"%f",f);        /* SAFE */
  12949.           return(vvbuf);
  12950.       }
  12951. #endif /* GFTIMER */
  12952.  
  12953. #ifndef NOHTTP
  12954.       case VN_HTTP_C: {                 /* HTTP Code */
  12955.           extern int http_code;
  12956.           return(ckitoa(http_code));
  12957.       }
  12958.       case VN_HTTP_N:                   /* HTTP Connected */
  12959.         return( http_isconnected() ? "1" : "0");
  12960.       case VN_HTTP_H:                   /* HTTP Host */
  12961.         return( (char *)http_host() );
  12962.       case VN_HTTP_M: {                 /* HTTP Message */
  12963.           extern char http_reply_str[];
  12964.           return((char *)http_reply_str);
  12965.       }
  12966.       case VN_HTTP_S:                   /* HTTP Security */
  12967.         return((char *)http_security());
  12968. #endif /* NOHTTP */
  12969.  
  12970. #ifdef NEWFTP
  12971.       case VN_FTP_B:
  12972.         return((char *)ftp_cpl_mode());
  12973.       case VN_FTP_D:
  12974.         return((char *)ftp_dpl_mode());
  12975.       case VN_FTP_Z:
  12976.         return((char *)ftp_authtype());
  12977.       case VN_FTP_C: {
  12978.           extern int ftpcode;
  12979.           return(ckitoa(ftpcode));
  12980.       }
  12981.       case VN_FTP_M: {
  12982.           extern char ftp_reply_str[];
  12983.           if (isdigit(ftp_reply_str[0]) &&
  12984.               isdigit(ftp_reply_str[1]) &&
  12985.               isdigit(ftp_reply_str[2]) &&
  12986.               ftp_reply_str[3] == ' ')
  12987.             return(&ftp_reply_str[4]);
  12988.           else
  12989.             return(ftp_reply_str);
  12990.       }
  12991.       case VN_FTP_S: {
  12992.           extern char ftp_srvtyp[];
  12993.           return((char *)ftp_srvtyp);
  12994.       }
  12995.       case VN_FTP_H: {
  12996.           extern char * ftp_host;
  12997.           return(ftp_host ? ftp_host : "");
  12998.       }
  12999.       case VN_FTP_X: {                  /* FTP Connected */
  13000.           extern int ftpisconnected();
  13001.           return(ftpisconnected() ? "1" : "0");
  13002.       }
  13003.       case VN_FTP_L: {                  /* FTP Logged in */
  13004.           extern int ftpisloggedin();
  13005.           return(ftpisloggedin() ? "1" : "0");
  13006.       }
  13007.       case VN_FTP_G: {                  /* FTP GET-PUT-REMOTE */
  13008.           extern int ftpget;
  13009.           char * s = "";
  13010.           switch (ftpget) {
  13011.             case 0: s = "kermit"; break;
  13012.             case 1: s = "ftp"; break;
  13013.             case 2: s = "auto"; break;
  13014.           }
  13015.           return(s);
  13016.       }
  13017. #endif /* NEWFTP */
  13018.  
  13019. #ifndef NOLOCAL
  13020.       case VN_CX_STA: {                 /* CONNECT status */
  13021.           extern int cx_status;
  13022.           return(ckitoa(cx_status));
  13023.       }
  13024. #endif /* NOLOCAL */
  13025.       case VN_NOW:                      /* Timestamp */
  13026.         return(ckcvtdate(p,0));
  13027.  
  13028.       case VN_HOUR:                     /* Hour of the day */
  13029.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  13030.         if (!p) p = "";
  13031.         if (!*p) return(p);
  13032.         vvbuf[0] = p[11];
  13033.         vvbuf[1] = p[12];
  13034.         vvbuf[2] = NUL;
  13035.         return(vvbuf);                  /* and return it */
  13036.     }
  13037.  
  13038. #ifndef NODIAL
  13039.     switch (y) {                        /* Caller ID values */
  13040.       extern char
  13041.         * callid_date, * callid_time, * callid_name,
  13042.         * callid_nmbr, * callid_mesg;
  13043.  
  13044.       case VN_CI_DA:
  13045.         return(callid_date ? callid_date : "");
  13046.  
  13047.       case VN_CI_TI:
  13048.         return(callid_time ? callid_time : "");
  13049.  
  13050.       case VN_CI_NA:
  13051.         return(callid_name ? callid_name : "");
  13052.  
  13053.       case VN_CI_NU:
  13054.         return(callid_nmbr ? callid_nmbr : "");
  13055.  
  13056.       case VN_CI_ME:
  13057.         return(callid_mesg ? callid_mesg : "");
  13058.  
  13059.     } /* End of variable-name switches */
  13060. #endif /* NODIAL */
  13061.  
  13062. #ifdef NT
  13063.     switch (y) {
  13064.     case VN_PERSONAL:
  13065.         p = (char *)GetPersonal();
  13066.         if (p) {
  13067.             GetShortPathName(p,vvbuf,VVBUFL);
  13068.             return(vvbuf);
  13069.         }
  13070.         return("");
  13071.     case VN_COMMON:
  13072.         p = (char *)GetAppData(1);
  13073.         if (p) {
  13074.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  13075.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  13076.             return(vvbuf);
  13077.         }
  13078.         return("");
  13079.     case VN_APPDATA:
  13080.         p = (char *)GetAppData(0);
  13081.         if (p) {
  13082.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  13083.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  13084.             return(vvbuf);
  13085.         }
  13086.         return("");
  13087.     }
  13088. #endif /* NT */
  13089.  
  13090.     fnsuccess = 0;
  13091.     if (fnerror) {
  13092.         fnsuccess = 0;
  13093.     }
  13094.     if (fndiags) {
  13095.         if (!embuf)
  13096.           ckstrncpy(embuf,"<ERROR:NO_SUCH_VARIABLE>",EMBUFLEN);
  13097.         printf("?%s\n",embuf);
  13098.         return((char *)embuf);
  13099.     } else
  13100.       return("");
  13101. }
  13102. #endif /* NOSPL */
  13103.  
  13104.  
  13105. /*
  13106.   X X S T R I N G  --  Expand variables and backslash codes.
  13107.  
  13108.     int xxtstring(s,&s2,&n);
  13109.  
  13110.   Expands \ escapes via recursive descent.
  13111.   Argument s is a pointer to string to expand (source).
  13112.   Argument s2 is the address of where to put result (destination).
  13113.   Argument n is the length of the destination string (to prevent overruns).
  13114.   Returns -1 on failure, 0 on success,
  13115.     with destination string null-terminated and s2 pointing to the
  13116.     terminating null, so that subsequent characters can be added.
  13117. */
  13118.  
  13119. #define XXDEPLIM 100                    /* Recursion depth limit */
  13120.  
  13121. int
  13122. zzstring(s,s2,n) char *s; char **s2; int *n; {
  13123.     int x,                              /* Current character */
  13124.         y,                              /* Worker */
  13125.         pp,                             /* Paren level */
  13126.         kp,                             /* Brace level */
  13127.         argn,                           /* Function argument counter */
  13128.         n2,                             /* Local copy of n */
  13129.         d,                              /* Array dimension */
  13130.         vbi,                            /* Variable id (integer form) */
  13131.         argl,                           /* String argument length */
  13132.         nx;                             /* Save original length */
  13133.  
  13134.     char vb,                            /* Variable id (char form) */
  13135.         *vp,                            /* Pointer to variable definition */
  13136.         *new,                           /* Local pointer to target string */
  13137. #ifdef COMMENT
  13138.         *old,                           /* Save original target pointer */
  13139. #endif /* COMMENT */
  13140.         *p,                             /* Worker */
  13141.         *q,                             /* Worker */
  13142.         *s3;                            /* Worker */
  13143.     int  x3;                            /* Worker */
  13144.     char *r  = (char *)0;               /* For holding function args */
  13145.     char *r2 = (char *)0;
  13146.     char *r3p;
  13147.  
  13148. #ifndef NOSPL
  13149. #ifdef DYNAMIC
  13150.     char * vnambuf = NULL;              /* Buffer for variable/function name */
  13151. #else /* DYNAMIC */
  13152.     char vnambuf[VNAML];                /* Buffer for variable/function name */
  13153. #endif /* DYNAMIC */
  13154.     char *argp[FNARGS];                 /* Pointers to function args */
  13155. #endif /* NOSPL */
  13156.  
  13157.     static int depth = 0;               /* Call depth, avoid overflow */
  13158.  
  13159.     n2 = *n;                            /* Make local copies of args */
  13160.     nx = n2;
  13161.  
  13162.     new = *s2;                          /* for one less level of indirection */
  13163. #ifdef COMMENT
  13164.     old = new;
  13165. #endif /* COMMENT */
  13166.  
  13167. #ifndef NOSPL
  13168.     ispattern = 0;                      /* For \fpattern() */
  13169. #endif /* NOSPL */
  13170.     depth++;                            /* Sink to a new depth */
  13171.     if (depth > XXDEPLIM) {             /* Too deep? */
  13172.         printf("?definition is circular or too deep\n");
  13173.         debug(F101,"zzstring fail","",depth);
  13174.         depth = 0;
  13175.         *new = NUL;
  13176.         return(-1);
  13177.     }
  13178.     if (!s || !new) {                   /* Watch out for null pointers */
  13179.         debug(F101,"zzstring fail 2","",depth);
  13180.         if (new)
  13181.           *new = NUL;
  13182.         depth = 0;
  13183.         return(-1);
  13184.     }
  13185.     s3 = s;
  13186.     argl = 0;
  13187.     while (*s3++) argl++;              /* Get length of source string */
  13188.     debug(F010,"zzstring entry",s,0);
  13189.     if (argl == 0) {                    /* Empty string */
  13190.         debug(F111,"zzstring empty arg",s,argl);
  13191.         depth = 0;
  13192.         *new = NUL;
  13193.         return(0);
  13194.     }
  13195.     if (argl < 0) {                     /* Watch out for garbage */
  13196.         debug(F101,"zzstring fail 3","",depth);
  13197.         *new = NUL;
  13198.         depth = 0;
  13199.         return(-1);
  13200.     }
  13201. #ifndef NOSPL
  13202. #ifdef DYNAMIC
  13203.     debug(F100,"vnambuf malloc...","",0);
  13204.     vnambuf = malloc(VNAML);
  13205.     if (vnambuf == NULL) {
  13206.         printf("?Out of memory");
  13207.         return(-1);
  13208.     }
  13209.     debug(F100,"vnambuf malloc ok","",0);
  13210. #endif /* DYNAMIC */
  13211. #endif /* NOSPL */
  13212.  
  13213.     while ((x = *s)) {                  /* Loop for all characters */
  13214.         if (x != CMDQ) {                /* Is it the command-quote char? */
  13215.             *new++ = *s++;              /* No, normal char, just copy */
  13216.             if (--n2 < 0) {             /* and count it, careful of overflow */
  13217.                 debug(F101,"zzstring overflow 1","",depth);
  13218.                 depth = 0;
  13219. #ifndef NOSPL
  13220. #ifdef DYNAMIC
  13221.                 if (vnambuf) free(vnambuf);
  13222. #endif /* DYNAMIC */
  13223. #endif /* NOSPL */
  13224.                 return(-1);
  13225.             }
  13226.             continue;
  13227.         }
  13228.  
  13229. /* We have the command-quote character. */
  13230.  
  13231.         x = *(s+1);                     /* Get the following character. */
  13232.         if (isupper(x)) x = tolower(x);
  13233.         switch (x) {                    /* Act according to variable type */
  13234. #ifndef NOSPL
  13235.           case 0:                       /* It's a lone backslash */
  13236.             *new++ = *s++;
  13237.             if (--n2 < 0) {
  13238.                 debug(F101,"zzstring overflow 2","",0);
  13239. #ifdef DYNAMIC
  13240. #ifndef NOSPL
  13241.                 if (vnambuf) free(vnambuf);
  13242. #endif /* NOSPL */
  13243. #endif /* DYNAMIC */
  13244.                 return(-1);
  13245.             }
  13246.             break;
  13247.           case '%':                     /* Variable */
  13248.             s += 2;                     /* Get the letter or digit */
  13249.             vb = *s++;                  /* and move source pointer past it */
  13250.             vp = NULL;                  /* Assume definition is empty */
  13251.             if (vb >= '0' && vb <= '9') { /* Digit for macro arg */
  13252.                 if (maclvl < 0)         /* Digit variables are global */
  13253.                   vp = g_var[vb];       /* if no macro is active */
  13254.                 else                    /* otherwise */
  13255.                   vp = m_arg[maclvl][vb - '0']; /* they're on the stack */
  13256.             } else if (vb == '*') {     /* Macro args string */
  13257. #ifdef COMMENT
  13258.                 /* This doesn't take changes into account */
  13259.                 vp = (maclvl >= 0) ? m_line[maclvl] : topline;
  13260.                 if (!vp) vp = "";
  13261. #else
  13262.                 if (zzstring("\\fjoin(&_[],,1)",&new,&n2) < 0)
  13263.                   return(-1);
  13264.                 break;
  13265. #endif /* COMMENT */
  13266.             } else {
  13267.                 if (isupper(vb)) vb += ('a'-'A');
  13268.                 vp = g_var[vb];         /* Letter for global variable */
  13269.             }
  13270.             if (!vp) vp = "";
  13271. #ifdef COMMENT
  13272.             if (vp) {                   /* If definition not empty */
  13273. #endif /* COMMENT */
  13274.                 debug(F010,"zzstring %n vp",vp,0);
  13275.                 if (zzstring(vp,&new,&n2) < 0) { /* call self to evaluate it */
  13276.                     debug(F101,"zzstring fail 6","",depth);
  13277. #ifdef DYNAMIC
  13278. #ifndef NOSPL
  13279.                     if (vnambuf) free(vnambuf);
  13280. #endif /* NOSPL */
  13281. #endif /* DYNAMIC */
  13282.                     return(-1);         /* Pass along failure */
  13283.                 }
  13284. #ifdef COMMENT
  13285.             } else {
  13286.                 debug(F110,"zzstring %n vp","(NULL)",0);
  13287.                 n2 = nx;
  13288.                 new = old;
  13289.                 *new = NUL;
  13290.             }
  13291. #endif /* COMMENT */
  13292.             break;
  13293.           case '&':                     /* An array reference */
  13294.             x = arraynam(s,&vbi,&d);    /* Get name and subscript */
  13295.             debug(F111,"zzstring arraynam",s,x);
  13296.             if (x < 0) {
  13297.                 debug(F101,"zzstring fail 7","",depth);
  13298. #ifdef DYNAMIC
  13299. #ifndef NOSPL
  13300.                 if (vnambuf) free(vnambuf);
  13301. #endif /* NOSPL */
  13302. #endif /* DYNAMIC */
  13303.                 return(-1);
  13304.             }
  13305.             pp = 0;                     /* Bracket counter */
  13306.             while (*s) {                /* Advance source pointer... */
  13307.                 if (*s == '[') pp++;
  13308.                 if (*s == ']' && --pp == 0) break;
  13309.                 s++;
  13310.             }
  13311.             if (*s == ']') s++;         /* ...past the closing bracket. */
  13312.  
  13313.             x = chkarray(vbi,d);        /* Array is declared? */
  13314.             debug(F101,"zzstring chkarray","",x);
  13315.             if (x > 0) {
  13316. #ifdef COMMENT
  13317.                 char * s1 = NULL;
  13318. #endif /* COMMENT */
  13319.                 vbi -= ARRAYBASE;       /* Convert name to index */
  13320.  
  13321. #ifdef COMMENT
  13322.                 if (vbi == 0) {         /* Argument vector array */
  13323.                     extern char ** toparg, ** m_xarg[];
  13324.                     extern int n_xarg[];
  13325.                     if (maclvl < 0) {
  13326.                         if (topargc >= d) {
  13327.                             s1 = toparg[d];
  13328.                         }
  13329.                     } else {
  13330.                         if (n_xarg[maclvl] >= d) {
  13331.                             s1 = m_xarg[maclvl][d];
  13332.                         }
  13333.                     }
  13334.                     if (s1) {
  13335.                         if (zzstring(s1,&new,&n2) < 0) { /* evaluate */
  13336.                             debug(F101,"zzstring fail 7.5","",depth);
  13337. #ifdef DYNAMIC
  13338. #ifndef NOSPL
  13339.                             if (vnambuf) free(vnambuf);
  13340. #endif /* NOSPL */
  13341. #endif /* DYNAMIC */
  13342.                             return(-1); /* Pass along failure */
  13343.                         }
  13344.                     } else {
  13345.                         /* old = new; */
  13346.                         n2 = nx;
  13347.                     }
  13348.                 } else
  13349. #endif /* COMMENT */
  13350.                   if (a_dim[vbi] >= d) {        /* If subscript in range */
  13351.                     char **ap;
  13352. #ifndef COMMENT
  13353.                     debug(F110,"zzstring a_ptr[vbi]",a_ptr[vbi],0);
  13354.                     debug(F110,"zzstring a_ptr[vbi][d]",a_ptr[vbi][d],0);
  13355. #endif /* COMMENT */
  13356.                     ap = a_ptr[vbi];    /* get data pointer */
  13357.                     if (ap) {           /* and if there is one */
  13358.                         if (ap[d]) {    /* If definition not empty */
  13359.                             debug(F111,"zzstring ap[d]",ap[d],d);
  13360.                             if (zzstring(ap[d],&new,&n2) < 0) { /* evaluate */
  13361.                                 debug(F101,"zzstring fail 8","",depth);
  13362. #ifdef DYNAMIC
  13363. #ifndef NOSPL
  13364.                                 if (vnambuf) free(vnambuf);
  13365. #endif /* NOSPL */
  13366. #endif /* DYNAMIC */
  13367.                                 return(-1); /* Pass along failure */
  13368.                             }
  13369.                         }
  13370.                     } else {
  13371.                         /* old = new; */
  13372.                         n2 = nx;
  13373.                     }
  13374.                 }
  13375.             }
  13376.             break;
  13377.  
  13378.           case 'f':                     /* A builtin function */
  13379.             q = vnambuf;                /* Copy the name */
  13380.             y = 0;                      /* into a separate buffer */
  13381.             s += 2;                     /* point past 'F' */
  13382.             while (y++ < VNAML) {
  13383.                 if (*s == '(') { s++; break; } /* Look for open paren */
  13384.                 if ((*q = *s) == NUL) break;   /* or end of string */
  13385.                 s++; q++;
  13386.             }
  13387.             *q = NUL;                   /* Terminate function name */
  13388.             if (y >= VNAML) {           /* Handle pathological case */
  13389.                 while (*s && (*s != '(')) /* of very long string entered */
  13390.                   s++;                    /* as function name. */
  13391.                 if (*s == ')') s++;       /* Skip past it. */
  13392.             }
  13393.             r = r2 = malloc(argl+2);    /* And make a place to copy args */
  13394.             /* debug(F101,"zzstring r2","",r2); */
  13395.             if (!r2) {                  /* Watch out for malloc failure */
  13396.                 debug(F101,"zzstring fail 9","",depth);
  13397.                 *new = NUL;
  13398.                 depth = 0;
  13399. #ifdef DYNAMIC
  13400. #ifndef NOSPL
  13401.                 if (vnambuf) free(vnambuf);
  13402. #endif /* NOSPL */
  13403. #endif /* DYNAMIC */
  13404.                 return(-1);
  13405.             }
  13406.             if (r3) free(r3); /* And another to copy literal arg string */
  13407.             r3 = malloc(argl+2);
  13408.             /* debug(F101,"zzstring r3","",r3); */
  13409.             if (!r3) {
  13410.                 debug(F101,"zzstring fail 10","",depth);
  13411.                 depth = 0;
  13412.                 *new = NUL;
  13413.                 if (r2) free(r2);
  13414. #ifdef DYNAMIC
  13415. #ifndef NOSPL
  13416.                 if (vnambuf) free(vnambuf);
  13417. #endif /* NOSPL */
  13418. #endif /* DYNAMIC */
  13419.                 return(-1);
  13420.             } else
  13421.               r3p = r3;
  13422.             argn = 0;                   /* Argument counter */
  13423.             argp[argn++] = r;           /* Point to first argument */
  13424.             y = 0;                      /* Completion flag */
  13425.             pp = 1;                     /* Paren level (already have one). */
  13426.             kp = 0;
  13427.             while (1) {                 /* Copy each argument, char by char. */
  13428.                 *r3p++ = *s;            /* This is a literal copy for \flit */
  13429.                 if (!*s) break;
  13430.  
  13431.                 if (*s == '{') {        /* Left brace */
  13432.                     kp++;
  13433.                 }
  13434.                 if (*s == '}') {        /* Right brace */
  13435.                     kp--;
  13436.                 }
  13437.                 if (*s == '(' && kp <= 0) { /* Open paren not in brace */
  13438.                     pp++;               /* Count it */
  13439.                 }
  13440.                 *r = *s;                /* Now copy resulting byte */
  13441.                 if (!*r)                /* If NUL, done. */
  13442.                   break;
  13443.                 if (*r == ')' && kp <= 0) { /* Closing paren, count it. */
  13444.                     if (--pp == 0) {    /* Final one? */
  13445.                         *r = NUL;       /* Make it a terminating null */
  13446.                         *(r3p - 1) = NUL;
  13447.                         s++;            /* Point past it in source string */
  13448.                         y = 1;          /* Flag we've got all the args */
  13449.                         break;          /* Done with while loop */
  13450.                     }
  13451.                 }
  13452.                 if (*r == ',' && kp <= 0) { /* Comma */
  13453.                     if (pp == 1) {          /* If not within ()'s, */
  13454.                         if (argn >= FNARGS) { /* Too many args */
  13455.                             s++; r++;   /* Keep collecting flit() string */
  13456.                             continue;
  13457.                         }
  13458.                         *r = NUL;           /* New arg, skip past comma */
  13459.                         argp[argn++] = r+1; /* In range, point to new arg */
  13460.                     }                   /* Otherwise just skip past  */
  13461.                 }
  13462.                 s++; r++;               /* Advance pointers */
  13463.             }
  13464.             if (!y)                     /* If we didn't find closing paren */
  13465.               argn = -1;
  13466. #ifdef DEBUG
  13467.             if (deblog) {
  13468.                 char buf[24];
  13469.                 debug(F111,"zzstring function name",vnambuf,y);
  13470.                 debug(F010,"zzstring function r3",r3,0);
  13471.                 for (y = 0; y < argn; y++) {
  13472.                     sprintf(buf,"arg %2d ",y);
  13473.                     debug(F010,buf,argp[y],0);
  13474.                 }
  13475.             }
  13476. #endif /* DEBUG */
  13477.             vp = fneval(vnambuf,argp,argn,r3); /* Evaluate the function. */
  13478.             if (vp) {                      /* If definition not empty */
  13479.                 while ((*new++ = *vp++)) { /* copy it to output string */
  13480.                     if (--n2 < 0) {        /* watch out for overflow */
  13481.                         debug(F101,"zzstring fail 12","",depth);
  13482.                         if (r2) { free(r2); r2 = NULL; }
  13483.                         if (r3) { free(r3); r3 = NULL; }
  13484. #ifdef DYNAMIC
  13485. #ifndef NOSPL
  13486.                         if (vnambuf) free(vnambuf);
  13487. #endif /* NOSPL */
  13488. #endif /* DYNAMIC */
  13489.                         return(-1);
  13490.                     }
  13491.                 }
  13492.                 new--;                  /* Back up over terminating null */
  13493.                 n2++;                   /* to allow for further deposits. */
  13494.             }
  13495.             if (r2) { free(r2); r2 = NULL; }
  13496.             if (r3) { free(r3); r3 = NULL; }
  13497.             break;
  13498.           case '$':                     /* An environment variable */
  13499.           case 'v':                     /* Or a named builtin variable. */
  13500.           case 'm':                     /* Or a macro /long variable */
  13501.           case 's':                     /* 196 Macro substring */
  13502.           case ':':                     /* 196 \-variable substring */
  13503.             pp = 0;
  13504.             p = s+2;                    /* $/V/M must be followed by (name) */
  13505.             if (*p != '(') {            /* as in \$(HOME) or \V(count) */
  13506.                 *new++ = *s++;          /* If not, just copy it */
  13507.                 if (--n2 < 0) {
  13508.                     debug(F101,"zzstring overflow 3","",depth);
  13509. #ifdef DYNAMIC
  13510. #ifndef NOSPL
  13511.                     if (vnambuf) free(vnambuf);
  13512. #endif /* NOSPL */
  13513. #endif /* DYNAMIC */
  13514.                     return(-1);
  13515.                 }
  13516.                 break;
  13517.             }
  13518.             pp++;
  13519.             p++;                        /* Point to 1st char of name */
  13520.             q = vnambuf;                /* Copy the name */
  13521.             y = 0;                      /* into a separate buffer */
  13522.             while (y++ < VNAML) {       /* Watch out for name too long */
  13523.                 if (*p == '(') {        /* Parens can be nested... */
  13524.                     pp++;
  13525.                 } else if (*p == ')') { /* Name properly terminated with ')' */
  13526.                     pp--;
  13527.                     if (pp == 0) {
  13528.                         p++;            /* Move source pointer past ')' */
  13529.                         break;
  13530.                     }
  13531.                 }
  13532.                 if ((*q = *p) == NUL)   /* String ends before ')' */
  13533.                   break;
  13534.                 p++; q++;               /* Advance pointers */
  13535.             }
  13536.             *q = NUL;                   /* Terminate the variable name */
  13537.             if (y >= VNAML) {           /* Handle pathological case */
  13538.                 while (*p && (*p != ')')) /* of very long string entered */
  13539.                   p++;                    /* as variable name. */
  13540.                 if (*p == ')') p++;       /* Skip ahead to the end of it. */
  13541.             }
  13542.             s = p;                      /* Adjust global source pointer */
  13543.             s3 = vnambuf;
  13544.             x3 = 0;
  13545.             while (*s3++) x3++;
  13546.             p = malloc(x3 + 1);         /* Make temporary space */
  13547.             if (p) {                    /* If we got the space */
  13548.                 vp = vnambuf;           /* Point to original */
  13549.                 strcpy(p,vp);           /* (safe) Make a copy of it */
  13550.                 y = VNAML;              /* Length of name buffer */
  13551.                 zzstring(p,&vp,&y);     /* Evaluate the copy */
  13552.                 free(p);                /* Free the temporary space */
  13553.                 p = NULL;
  13554.             }
  13555.             debug(F110,"zzstring vname",vnambuf,0);
  13556.             q = NULL;
  13557.             if (x == '$') {             /* Look up its value */
  13558.                 vp = getenv(vnambuf);   /* This way for environment variable */
  13559.             } else if (x == 'm' || x == 's' || x == ':') { /* Macro / substr */
  13560.                 int k, x1 = -1, x2 = -1;
  13561.                 k = strlen(vnambuf);
  13562.                 /* \s(name[n:m]) -- Compact substring notation */
  13563.                 if ((x == 's' || x == ':') && (k > 1)) { /* Substring wanted */
  13564.                     if (vnambuf[k-1] == ']') {
  13565.                         int i;
  13566.                         for (i = k-1; i > 0; i--) {
  13567.                             if (vnambuf[i] == '[') {
  13568.                                 char * p = NULL;
  13569.                                 p = (char *)malloc(k - i + 8);
  13570.                                 if (p) {
  13571.                                     /* Now this is a dirty trick... */
  13572.                                     ckmakmsg(p,
  13573.                                              k-i+8,
  13574.                                              "\\&a",
  13575.                                              &vnambuf[i],
  13576.                                              NULL,
  13577.                                              NULL
  13578.                                              );
  13579.                                     arraybounds(p,&x1,&x2);
  13580.                                     if (x1 < 1) x1 = 1;
  13581.                                     x1--; /* Adjust to 0-base */
  13582.                                     free(p);
  13583.                                     vnambuf[i] = NUL;
  13584.                                 }
  13585.                             }
  13586.                         }
  13587.                     }
  13588.                 }
  13589.                 if (x == ':') {
  13590.                     vp = vnambuf;
  13591.                 } else {
  13592.                     y = mxlook(mactab,vnambuf,nmac); /* get definition */
  13593.                     if (y > -1) {               /* Got definition */
  13594.                         vp = mactab[y].mval;
  13595.                     } else {
  13596.                         vp = NULL;
  13597.                     }
  13598.                 }
  13599.                 if (vp) {
  13600.                     if ((x == 's' || x == ':') && (k > 1)) {
  13601.                         /* Compact substring notation */
  13602.                         if (x2 == 0) {  /* Length */
  13603.                             vp = NULL;
  13604.                         } else if (x1 > -1) { /* Start */
  13605.                             k = strlen(vp);
  13606.                             if (x1 > k) {  /* If it's off the end, */
  13607.                                 vp = NULL; /* result is empty */
  13608.                             } else if (k > 0) {
  13609.                                 if ((q = malloc(k+1))) {
  13610.                                     strcpy(q,vp); /* safe */
  13611.                                     if ((x2 > -1) && ((x1 + x2) <= k)) {
  13612.                                         q[x1+x2] = NUL;
  13613.                                     }
  13614.                                     vp = q+x1;
  13615.                                 }  else vp = NULL;
  13616.                             } else vp = NULL;
  13617.                         }
  13618. #ifdef DEBUG
  13619.                         if (deblog) {
  13620.                             if (!vp) {
  13621.                             } else {
  13622.                                 k = strlen(vp);
  13623.                             }
  13624.                         }
  13625. #endif /* DEBUG */
  13626.                     }
  13627.                 }
  13628.             } else {                    /* or */
  13629.                 vp = nvlook(vnambuf);   /* this way for builtin variable */
  13630.             }
  13631.             if (vp) {                   /* If definition not empty */
  13632.                 while ((*new++ = *vp++)) /* copy it to output string. */
  13633.                   if (--n2 < 0) {
  13634.                       if (q) free(q);
  13635.                       debug(F101,"zzstring overflow 4","",depth);
  13636. #ifdef DYNAMIC
  13637. #ifndef NOSPL
  13638.                       if (vnambuf) free(vnambuf);
  13639. #endif /* NOSPL */
  13640. #endif /* DYNAMIC */
  13641.                       return(-1);
  13642.                   }
  13643.                 new--;                  /* Back up over terminating null */
  13644.                 n2++;                   /* to allow for further deposits. */
  13645.             }
  13646.             if (q) {
  13647.                 free(q);
  13648.                 q = NULL;
  13649.             }
  13650.             break;
  13651. #endif /* NOSPL */                      /* Handle \nnn even if NOSPL. */
  13652.  
  13653. #ifndef NOKVERBS
  13654.         case 'K':
  13655.         case 'k': {
  13656.             extern struct keytab kverbs[];
  13657.             extern int nkverbs;
  13658. #define K_BUFLEN 30
  13659.             char kbuf[K_BUFLEN + 1];    /* Key verb name buffer */
  13660.             int x, y, z, brace = 0;
  13661.             s += 2;
  13662. /*
  13663.   We assume that the verb name is {braced}, or it extends to the end of the
  13664.   string, s, or it ends with a space, control character, or backslash.
  13665. */
  13666.             p = kbuf;                   /* Copy verb name into local buffer */
  13667.             x = 0;
  13668.             if (*s == '{')  {
  13669.                 s++;
  13670.                 brace++;
  13671.             }
  13672.             while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  13673.                 if (brace && *s == '}') {
  13674.                     s++;
  13675.                     break;
  13676.                 }
  13677.                 *p++ = *s++;
  13678.             }
  13679.             brace = 0;
  13680.             *p = NUL;                   /* Terminate. */
  13681.             p = kbuf;                   /* Point back to beginning */
  13682.             debug(F110,"zzstring kverb",p,0);
  13683.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  13684.             debug(F101,"zzstring lookup",0,y);
  13685.             if (y > -1) {
  13686.                 dokverb(VCMD,y);
  13687. #ifndef NOSPL
  13688.             } else {                    /* Is it a macro? */
  13689.                 y = mxlook(mactab,p,nmac);
  13690.                 if (y > -1) {
  13691.                     debug(F111,"zzstring mxlook",p,y);
  13692.                     if ((z = dodo(y,NULL,cmdstk[cmdlvl].ccflgs)) > 0) {
  13693.                         if (cmpush() > -1) {  /* Push command parser state */
  13694.                             extern int ifc;
  13695.                             int ifcsav = ifc; /* Push IF condition on stack */
  13696.                             y = parser(1);    /* New parser to execute macro */
  13697.                             cmpop();          /* Pop command parser */
  13698.                             ifc = ifcsav;     /* Restore IF condition */
  13699.                             if (y == 0) {     /* No errors, ignore actions */
  13700.                                 p = mrval[maclvl+1]; /* If OK set return val */
  13701.                                 if (p == NULL) p = "";
  13702.                             }
  13703.                         } else {                /* Can't push any more */
  13704.                             debug(F101,"zzstring pushed too deep","",depth);
  13705.                             printf(
  13706.                                "\n?Internal error: zzstring stack overflow\n"
  13707.                                    );
  13708.                             while (cmpop() > -1);
  13709.                             p = "";
  13710.                         }
  13711.                     }
  13712.                 }
  13713. #endif /* NOSPL */
  13714.             }
  13715.             break;
  13716.         }
  13717. #endif /* NOKVERBS */
  13718.  
  13719.         default:                        /* Maybe it's a backslash code */
  13720.           y = xxesc(&s);                /* Go interpret it */
  13721.           if (y < 0) {                  /* Upon failure */
  13722.               *new++ = (char) x;        /* Just quote the next character */
  13723.               s += 2;                   /* Move past the pair */
  13724.               n2 -= 2;
  13725.               if (n2 < 0) {
  13726.                   debug(F101,"zzstring overflow 5","",depth);
  13727. #ifdef DYNAMIC
  13728. #ifndef NOSPL
  13729.                   if (vnambuf) free(vnambuf);
  13730. #endif /* NOSPL */
  13731. #endif /* DYNAMIC */
  13732.                   return(-1);
  13733.               }
  13734.               continue;                 /* and go back for more */
  13735.           } else {
  13736.               *new++ = (char) y;        /* else deposit interpreted value */
  13737.               if (--n2 < 0) {
  13738.                   debug(F101,"zzstring overflow 6","",depth);
  13739. #ifdef DYNAMIC
  13740. #ifndef NOSPL
  13741.                   if (vnambuf) free(vnambuf);
  13742. #endif /* NOSPL */
  13743. #endif /* DYNAMIC */
  13744.                   return(-1);
  13745.               }
  13746.           }
  13747.         }
  13748.     }
  13749.     *new = NUL;                         /* Terminate the new string */
  13750.     debug(F010,"zzstring while exit",*s2,0);
  13751.  
  13752.     depth--;                            /* Adjust stack depth gauge */
  13753.     *s2 = new;                          /* Copy results back into */
  13754.     *n = n2;                            /* the argument addresses */
  13755.     debug(F101,"zzstring ok","",depth);
  13756. #ifdef DYNAMIC
  13757. #ifndef NOSPL
  13758.     if (vnambuf) free(vnambuf);
  13759. #endif /* NOSPL */
  13760. #endif /* DYNAMIC */
  13761.     return(0);                          /* and return. */
  13762. }
  13763. #endif /* NOICP */
  13764.