home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckuusx.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  275KB  |  9,417 lines

  1. #include "ckcsym.h"
  2.  
  3. /*  C K U U S X --  "User Interface" common functions. */
  4.  
  5. /*
  6.   Authors:
  7.     Frank da Cruz <fdc@columbia.edu>,
  8.       The Kermit Project, Columbia University, New York City
  9.     Jeffrey E Altman <jaltman@secure-endpoints.com>
  10.       Secure Endpoints Inc., New York City
  11.  
  12.   Copyright (C) 1985, 2005,
  13.     Trustees of Columbia University in the City of New York.
  14.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  15.     copyright text in the ckcmai.c module for disclaimer and permissions.
  16. */
  17.  
  18. /*
  19.   This module contains user interface functions needed by both the interactive
  20.   user interface and the command-line-only user interface.
  21. */
  22.  
  23. /* Includes */
  24.  
  25. #include "ckcdeb.h"
  26. #include "ckcasc.h"
  27. #include "ckcker.h"
  28. #include "ckuusr.h"
  29. #include "ckcxla.h"
  30.  
  31. #ifndef NOHTERMCAP
  32. #ifdef NOTERMCAP
  33. #define NOHTERMCAP
  34. #else
  35. #ifndef BSD44
  36. #define NOHTERMCAP
  37. #else
  38. #ifdef __bsdi__
  39. #define NOHTERMCAP
  40. #else
  41. #ifdef OPENBSD
  42. #define NOHTERMCAP
  43. #else
  44. #ifdef MACOSX
  45. #define NOHTERMCAP
  46. #endif /* MACOSX */
  47. #endif /* OPENBSD */
  48. #endif /* __bsdi__ */
  49. #endif /* BSD44 */
  50. #endif /* NOTERMCAP */
  51. #endif /* NOHTERMCAP */
  52.  
  53. #ifndef NOTERMCAP
  54. #ifdef BSD44
  55. #ifndef NOHTERMCAP
  56. #include <termcap.h>
  57. #endif /* NOHTERMCAP */
  58. #endif /* BSD44 */
  59. #else  /* !BSD44 */
  60. #ifdef linux
  61. #include <term.h>
  62. #endif /* linux */
  63. #endif /* NOTERMCAP */
  64.  
  65. #ifdef OS2
  66. #include <string.h>
  67. _PROTOTYP(char * os2_gethostname, (void));
  68. #define getpid _getpid
  69. #endif /* OS2 */
  70. #ifdef BSD44
  71. #include <errno.h>
  72. #endif /* BSD44 */
  73.  
  74. extern xx_strp xxstring;
  75.  
  76. #ifdef OS2
  77. #include "ckcnet.h"
  78. #else /* OS2 */
  79. _PROTOTYP( char * ckgetpeer, (VOID));
  80. _PROTOTYP(int getlocalipaddr, (void));
  81. _PROTOTYP(int istncomport, (void));
  82. #ifndef NOCKGETFQHOST
  83. _PROTOTYP( char * ckgetfqhostname,(char *));
  84. #endif    /* NOCKGETFQHOST */
  85. #ifndef NETCONN
  86. /*
  87.   We should just pull in ckcnet.h here, but it causes a conflict with curses.h.
  88. */
  89. #ifdef TCPSOCKET
  90. #define NETCONN
  91. #else
  92. #ifdef SUNX25
  93. #define NETCONN
  94. #else
  95. #ifdef STRATUSX25
  96. #define NETCONN
  97. #else
  98. #ifdef IBMX25
  99. #define NETCONN
  100. #else
  101. #ifdef HPX25
  102. #define NETCONN
  103. #else
  104. #ifdef DECNET
  105. #define NETCONN
  106. #else
  107. #ifdef NPIPE
  108. #define NETCONN
  109. #else
  110. #ifdef CK_NETBIOS
  111. #define NETCONN
  112. #ifdef SUPERLAT
  113. #define NETCONN
  114. #else
  115. #endif /* SUPERLAT */
  116. #endif /* TCPSOCKET */
  117. #endif /* SUNX25 */
  118. #endif /* STRATUSX25 */
  119. #endif /* IBMX25 */
  120. #endif /* HPX25 */
  121. #endif /* DECNET */
  122. #endif /* NPIPE */
  123. #endif /* CK_NETBIOS */
  124. #endif /* NETCONN */
  125. #endif /* OS2 */
  126.  
  127. #ifndef TCPSOCKET
  128. #ifdef MULTINET
  129. #define TCPSOCKET
  130. #endif /* MULTINET */
  131. #ifdef DEC_TCPIP
  132. #define TCPSOCKET
  133. #endif /* DEC_TCPIP */
  134. #ifdef WINTCP
  135. #define TCPSOCKET
  136. #endif /* WINTCP */
  137. #ifdef TCPWARE
  138. #define TCPSOCKET
  139. #endif /* TCPWARE */
  140. #endif /* TCPSOCKET */
  141.  
  142. #ifdef OS2
  143. #ifdef NT
  144. #include <windows.h>
  145. #include <tapi.h>
  146. #include "ckntap.h"
  147. #else /* NT */
  148. #define INCL_VIO
  149. #include <os2.h>
  150. #endif /* NT */
  151. #ifdef COMMENT                          /* Would you believe */
  152. #undef COMMENT                          /* <os2.h> defines this ? */
  153. #endif /* COMMENT */
  154. #ifdef CK_NETBIOS
  155. #include "ckonbi.h"
  156. #endif /* CK_NETBIOS */
  157.  
  158. #include "ckocon.h"
  159. extern ascreen commandscreen;
  160. #ifdef KUI
  161. #include "ikui.h"
  162. #endif /* KUI */
  163. #endif /* OS2 */
  164.  
  165. #ifdef NT
  166. #include "cknwin.h"
  167. #endif /* NT */
  168. #ifdef OS2
  169. #include "ckowin.h"
  170. #include "ckosyn.h"
  171. #endif /* OS2 */
  172.  
  173. #ifdef CK_TAPI
  174. extern int tttapi;
  175. extern int tapipass;
  176. #endif /* CK_TAPI */
  177.  
  178. #ifdef CK_KERBEROS
  179. #include "ckuath.h"
  180. #endif /* CK_KERBEROS */
  181.  
  182. #ifndef WINTCP
  183. #include <signal.h>
  184. #endif /* WINTCP */
  185.  
  186. #ifdef VMS
  187. #include <descrip.h>
  188. #include <ssdef.h>
  189. #include <stsdef.h>
  190. #ifndef OLD_VMS
  191. #include <lib$routines.h>  /* Not for VAX C 2.3 */
  192. #else
  193. #include <libdef.h>
  194. #endif /* OLD_VMS */
  195. #ifdef WINTCP
  196. #include <signal.h>
  197. #endif /* WINTCP */
  198. #endif /* VMS */
  199.  
  200. #ifdef DCLFDOPEN
  201. /* fdopen() needs declaring because it's not declared in <stdio.h> */
  202. _PROTOTYP( FILE * fdopen, (int, char *) );
  203. #endif /* DCLFDOPEN */
  204.  
  205. #ifdef DCLPOPEN
  206. /* popen() needs declaring because it's not declared in <stdio.h> */
  207. _PROTOTYP( FILE * popen, (char *, char *) );
  208. #endif /* DCLPOPEN */
  209.  
  210. int tt_crd = 0;                         /* Carriage return display */
  211. int tt_lfd = 0;                         /* Linefeed display */
  212. int interrupted = 0;                    /* Interrupted from keyboard flag */
  213. static int fxd_inited = 0;              /* Fullscreen stuff initialized */
  214.  
  215. #ifdef DEBUG
  216. char debfil[CKMAXPATH+1];               /* Debugging log file name */
  217. #endif /* DEBUG */
  218.  
  219. #ifdef TLOG
  220. char trafil[CKMAXPATH+1];               /* Transaction log file name */
  221. #endif /* TLOG */
  222.  
  223. char sesfil[CKMAXPATH+1];               /* Session log file name */
  224.  
  225. #ifdef CKLOGDIAL
  226. char diafil[CKMAXPATH+1];               /* Connection log file name */
  227. char cxlogbuf[CXLOGBUFL+1];             /* Connection log record buffer */
  228. int cx_active = 0;                      /* Connection is active */
  229. extern int dialog;
  230. #endif /* CKLOGDIAL */
  231.  
  232. #ifdef DYNAMIC
  233. static char *cmdstr = NULL;             /* Place to build generic command */
  234. #else
  235. #ifdef pdp11
  236. static char cmdstr[256];
  237. #else
  238. static char cmdstr[4096];
  239. #endif /* pdp11 */
  240. #endif /* DYNAMIC */
  241.  
  242. #ifndef NOMSEND
  243. char fspec[CMDBL+4];                    /* Filename string for \v(filespec) */
  244. int fspeclen = CMDBL;
  245. #else
  246. char fspec[CKMAXPATH+4];
  247. int fspeclen = CKMAXPATH;
  248. #endif /* NOMSEND */
  249.  
  250. char * rfspec = NULL;            /* Received filespec: local */
  251. char * prfspec = NULL;            /* Preliminary rfspec */
  252. char * sfspec = NULL;            /* Sent filespec: local */
  253. char * psfspec = NULL;            /* Preliminary sfspec */
  254. char * srfspec = NULL;            /* Received filespec: remote */
  255. char * psrfspec = NULL;            /* Preliminary srfspec */
  256. char * rrfspec = NULL;            /* Sent filespec: remote */
  257. char * prrfspec = NULL;            /* Preliminary rrfspec */
  258.  
  259. int success = 1,                        /* Command success/failure flag */
  260.     cmdlvl = 0,                         /* Command level */
  261.     action = 0,                /* Action selected on command line */
  262.     slogts = 0,                /* Session-log timestamps on/off */
  263. #ifdef UNIX
  264.     sessft = XYFT_T,                    /* Session log file type */
  265. #else
  266.     sessft = XYFT_B,            /* (text for UNIX binary for others) */
  267. #endif /* UNIX */
  268.     pflag = 1,                          /* Print prompt */
  269.     msgflg = 1;                         /* Print informational messages */
  270.  
  271. extern int xaskmore, saveask;        /* More-prompting */
  272.  
  273. #ifdef CK_APC
  274. extern int apcactive;
  275. #endif /* CK_APC */
  276. /* External variables */
  277.  
  278. extern int local, quiet, binary, network, what, parity, xitsta, escape,
  279.   tlevel, bgset, backgrd, xsuspend, cmdint, nettype, seslog, dfloc;
  280.  
  281. extern int cmd_rows, cmd_cols, xcmdsrc;
  282.  
  283. extern char cmdfil[];
  284.  
  285. #ifdef VMS
  286. extern int batch;
  287. #endif /* VMS */
  288.  
  289. #ifdef datageneral                      /* 2/12/92 ENH */
  290. #include <sysid.h>
  291. extern int con_reads_mt, conint_ch, conint_avl;
  292. #endif /* datageneral */
  293.  
  294. extern long speed;
  295.  
  296. extern char ttname[], *dftty, *cmarg, **cmlist, *versio, myhost[];
  297.  
  298. #ifndef NOCSETS
  299. extern int fcharset, tcharset, xfrxla;
  300. extern struct csinfo fcsinfo[], tcsinfo[];
  301. #endif /* NOCSETS */
  302.  
  303. #ifdef OS2
  304. extern unsigned char colorcmd;
  305. #endif /* OS2 */
  306.  
  307. #ifdef NOXFER
  308.  
  309. int fdispla = XYFD_N;
  310.  
  311. #else  /* NOXFER is not defined */
  312.  
  313. #ifdef OS2                              /* File transfer display type */
  314. int fdispla = XYFD_C;                   /* Curses (fullscreen) if we have it */
  315. #else
  316. #ifdef CK_CURSES
  317. int fdispla = XYFD_C;
  318. #else
  319. int fdispla = XYFD_S;                   /* Otherwise CRT */
  320. #endif /* CK_CURSES */
  321. #endif /* OS2 */
  322.  
  323. extern struct ck_p ptab[];
  324. extern int protocol, xfrbel, xfrint;
  325.  
  326. #ifdef STREAMING
  327. extern int streaming, streamok;
  328. #endif /* STREAMING */
  329.  
  330. /* Used internally */
  331.  
  332. #ifdef KUI
  333. _PROTOTYP( VOID screeng, (int, char, long, char *) );
  334. #endif    /* KUI */
  335. _PROTOTYP( VOID screenc, (int, char, CK_OFF_T, char *) );
  336.  
  337.  
  338. #ifdef CK_CURSES
  339. #ifndef DYNAMIC
  340. static char xtrmbuf[TRMBUFL];           /* tgetent() buffer */
  341. char * trmbuf = xtrmbuf;
  342. #else
  343. char * trmbuf = NULL;
  344. #endif /* DYNAMIC */
  345. _PROTOTYP( static VOID dpyinit, (void) );
  346. _PROTOTYP( static long shocps, (int, long, long) );
  347. _PROTOTYP( static long shoetl, (long, long, long, long) );
  348. #endif /* CK_CURSES */
  349.  
  350. static int ft_win = 0;  /* Fullscreen file transfer display window is active */
  351.  
  352. /* Variables declared here */
  353.  
  354. static char * skreason[] = {
  355.     "",                    /* 0 */
  356.     "Remote file not older",        /* SKP_DAT */
  357.     "Identical modification times",    /* SKP_EQU */
  358.     "Type",                /* SKP_TYP */
  359.     "Size",                /* SKP_SIZ */
  360.     "Name collision",            /* SKP_NAM */
  361.     "Exception List",            /* SKP_EXL */
  362.     "Dot file",                /* SKP_DOT */
  363.     "Backup file",            /* SKP_BKU */
  364.     "Recovery not needed",        /* SKP_RES */
  365.     "Access denied",            /* SKP_ACC */
  366.     "Not a regular file",        /* SKP_NRF */
  367.     "Simulated",            /* SKP_SIM */
  368.     "Simulated - Remote file older",    /* SKP_XUP */
  369.     "Simulated - No remote file",    /* SKP_XNX */
  370. };
  371. static int nskreason = (sizeof(skreason) / sizeof(char *));
  372.  
  373. char *
  374. gskreason(n) int n; {
  375.     return((n > 0 && n < nskreason) ? skreason[n] : "");
  376. }
  377.  
  378. char pktfil[CKMAXPATH+1];               /* Packet log file name */
  379.  
  380. #ifndef NOMSEND                         /* Multiple SEND */
  381. char *msfiles[MSENDMAX];
  382. #endif /* NOMSEND */
  383.  
  384. #ifdef CK_TIMERS
  385. extern long rttdelay;
  386. extern int  rttflg;
  387. #endif /* CK_TIMERS */
  388. extern int rcvtimo;
  389.  
  390. #ifdef CK_RESEND
  391. extern int sendmode;
  392. extern CK_OFF_T sendstart, rs_len;
  393. #endif /* CK_RESEND */
  394.  
  395. #ifdef CK_PCT_BAR                       /* File transfer thermometer */
  396. int thermometer = 1;                    /* ON by default */
  397. #endif /* CK_PCT_BAR */
  398.  
  399. #ifdef GFTIMER
  400. CKFLOAT gtv = -1.0, oldgtv = -1.0;
  401. #else
  402. #ifndef OS2
  403. static
  404. #endif /* OS2 */
  405.   long gtv = -1L, oldgtv = -1L;
  406. #endif /* GFTIMER */
  407.  
  408. extern int server, bctu, rptflg, ebqflg, spsiz, urpsiz, wmax, czseen, cxseen,
  409.   winlo, displa, timint, npad, ebq, bctr, rptq, atcapu, lpcapu,
  410.   swcapu, wslotn, wslotr, rtimo, mypadn, sq, capas, rpsiz, tsecs,
  411.   pktlog, lscapu, dest, srvdis, wslots, spackets, spktl, rpktl,
  412.   retrans, wcur, numerrs, fsecs, whatru, crunched, timeouts,
  413.   rpackets, fncnv, bye_active, discard, inserver, diractive, cdactive;
  414.  
  415. extern long filcnt, filrej, rptn, filcps, tfcps, cps, peakcps;
  416. extern CK_OFF_T ffc, tfc, fsize; 
  417.  
  418. long oldcps = 0L;
  419.  
  420. extern CHAR *rdatap, padch, seol, ctlq, mypadc, eol, *epktmsg;
  421. extern char *xfrmsg;
  422.  
  423. #ifdef IKSDB
  424. FILE * dbfp = NULL;                     /* File pointer to database file */
  425.  
  426. int dbenabled = 1;                      /* Flag for database is enabled */
  427. extern int ikdbopen;                    /* Flag for database is open */
  428.  
  429. unsigned long mydbseek = 0L;            /* Seek pointer to my record */
  430. int mydbslot = 0;                       /* My slot number */
  431. unsigned long myflags = 0L;             /* My flags */
  432. unsigned long myatype = 0L;             /* My authorization type */
  433. unsigned long myamode = 0L;             /* My authorization mode */
  434. unsigned long mystate = 0L;             /* My state (SEND, RECEIVE, etc) */
  435. unsigned long mypid = 0L;               /* My PID */
  436. unsigned long myip = 0L;                /* My IP address */
  437. unsigned long peerip = 0L;              /* My peer's IP address */
  438.  
  439. unsigned long dbip = 0L;                /* IP address in db record */
  440. unsigned long dbpid = 0L;               /* PID in db record */
  441. unsigned long dbflags = 0L;             /* Flags field in db record */
  442. unsigned long dblastused = 0L;          /* Last in-use record in db */
  443. char dbrec[DB_RECL];                    /* Database record buffer */
  444.  
  445. char * dbdir   = NULL;                  /* Database directory */
  446. char * dbfile  = NULL;                  /* Database file full pathname */
  447. char myhexip[33] = { NUL, NUL };        /* My IP address in hex */
  448. char peerhexip[33] = { NUL, NUL };      /* Client's IP address in hex */
  449. #endif /* IKSDB */
  450.  
  451. #ifdef GFTIMER
  452. extern CKFLOAT fpfsecs, fptsecs, fpxfsecs;
  453. #else
  454. extern long xfsecs;
  455. #endif /* GFTIMER */
  456. #endif /* NOXFER */
  457.  
  458. #ifdef TCPSOCKET
  459. #ifdef NEWFTP
  460. extern char * ftp_host, ftp_srvtyp[];
  461. extern int ftp_csx, ftp_csl, ftp_deb;
  462. #endif /* NEWFTP */
  463. extern char myipaddr[];
  464. #endif /* TCPSOCKET */
  465.  
  466. #ifndef NOICP
  467. #ifndef NOSPL
  468.     extern struct mtab *mactab;         /* For ON_EXIT macro. */
  469.     extern int nmac;
  470. #endif /* NOSPL */
  471. #ifdef DCMDBUF
  472. extern char *cmdbuf;                    /* Command buffer */
  473. #else
  474. extern char cmdbuf[];                   /* Command buffer */
  475. #endif /* DCMDBUF */
  476. extern int cmd_quoting;
  477. #endif /* NOICP */
  478.  
  479. #ifndef NOCCTRAP
  480. #ifdef NT
  481. #include <setjmpex.h>
  482. #else /* NT */
  483. #include <setjmp.h>
  484. #endif /* NT */
  485. #include "ckcsig.h"
  486. extern ckjmpbuf cmjbuf;
  487. #endif /* NOCCTRAP */
  488.  
  489. extern int xfiletype, nscanfile;
  490.  
  491. int
  492. shoesc(escape) int escape; {
  493.     extern char * ccntab[];        /* C0 control character name table */
  494.     extern int tt_escape;
  495.     if ((escape > 0 && escape < 32) || (escape == 127)) {
  496.     printf(" Escape character: Ctrl-%c (ASCII %d, %s): %s\r\n",
  497.            ctl(escape),
  498.            escape,
  499.            (escape == 127 ? "DEL" : ccntab[escape]),
  500.            tt_escape ? "enabled" : "disabled"
  501.            );
  502.     } else {
  503.     printf(" Escape character: Code %d",escape);
  504.     if (escape > 160 && escape < 256)
  505.       printf(" (%c)",escape);
  506.     printf(": %s\r\n", tt_escape ? "enabled" : "disabled");    
  507.     }
  508.     return(0);
  509. }
  510.  
  511. #ifndef NOXFER
  512. /*  P R E S E T  --  Reset global protocol variables  */
  513.  
  514. extern int recursive;
  515.  
  516. #ifdef PATTERNS
  517. int patterns = SET_AUTO;                /* Whether to use filename patterns */
  518. extern int g_patterns;            /* For saving and restoring */
  519. #else
  520. int patterns = SET_OFF;
  521. #endif /* PATTERNS */
  522.  
  523. #ifndef NOICP
  524. #ifdef CK_LABELED
  525. extern int g_lf_opts, lf_opts;
  526. #endif /* CK_LABELED */
  527. extern int g_matchdot, g_usepipes, usepipes;
  528. extern int g_binary, g_proto, g_displa, g_spath, g_rpath, g_fncnv;
  529. extern int g_recursive;
  530. extern int g_xfermode, xfermode;
  531. extern int g_urpsiz, g_spsizf, g_spsiz;
  532. extern int g_spsizr, g_spmax, g_wslotr, g_prefixing, g_fncact;
  533. extern int g_fnspath, g_fnrpath, g_skipbup;
  534. extern int nolinks;
  535. #ifdef CKSYMLINK
  536. extern int zgfs_link;
  537. #endif /* CKSYMLINK */
  538. #ifndef NOSPL
  539. extern int g_pflg, pwflg, g_pcpt, pwcrypt;
  540. extern char * g_pswd, pwbuf[];
  541. #endif /* NOSPL */
  542. #endif /* NOICP */
  543.  
  544. extern int spsizf, spsizr, spmax, prefixing, fncact, fnspath, fnrpath;
  545. extern int moving;                      /* SEND criteria */
  546. extern char sndafter[], sndbefore[], *sndexcept[], *rcvexcept[];
  547. extern CK_OFF_T sndlarger, sndsmaller, calibrate;
  548. extern int rmailf, rprintf, skipbup;
  549. extern char optbuf[];
  550.  
  551. #ifdef PIPESEND
  552. extern char * g_sfilter, * g_rfilter;
  553. extern char * sndfilter, * rcvfilter;
  554. #endif /* PIPESEND */
  555. extern char ** sndarray;
  556.  
  557. VOID
  558. ftreset() {
  559. #ifndef NOICP
  560.     int i;
  561.     extern char * filefile;
  562.     extern int reliable, xreliable, c_save, ss_save, slostart, urclear;
  563.     extern int oopts, omode, oname, opath, kactive, autopath;
  564.     extern char * snd_move;             /* Directory to move sent files to */
  565.     extern char * snd_rename;           /* What to rename sent files to */
  566.     extern char * rcv_move;
  567.     extern char * rcv_rename;
  568.     extern char * g_snd_move;
  569.     extern char * g_snd_rename;
  570.     extern char * g_rcv_move;
  571.     extern char * g_rcv_rename;
  572.  
  573. #ifdef CK_TMPDIR
  574.     extern int f_tmpdir;
  575.     extern char savdir[];
  576. #endif /* CK_TMPDIR */
  577.  
  578. #ifdef CK_SPEED
  579. #ifdef COMMENT
  580.     extern int f_ctlp;
  581.     extern short s_ctlp[], ctlp[];
  582. #endif /* COMMENT */
  583. #endif /* CK_SPEED */
  584.  
  585. #ifndef NOCSETS
  586.     extern int fcs_save, tcs_save;
  587.     extern int g_xfrxla, xfrxla;
  588. #endif /* NOCSETS */
  589.  
  590. /* Restore / reset per-command file-transfer switches */
  591.  
  592.     makestr(&snd_move,g_snd_move);
  593.     makestr(&rcv_move,g_rcv_move);
  594.     makestr(&snd_rename,g_snd_rename);
  595.     makestr(&rcv_rename,g_rcv_rename);
  596.  
  597.     kactive = 0;                        /* Kermit protocol no longer active */
  598.     oopts = -1;                         /* O-Packet Options */
  599.     omode = -1;                         /* O-Packet Transfer Mode */
  600.     oname = -1;                         /* O-Packet Filename Options */
  601.     opath = -1;                         /* O-Packet Pathname Options */
  602.  
  603. #ifdef CK_RESEND
  604.     rs_len = 0L;            /* REGET position */
  605. #endif /* CK_RESEND */
  606.  
  607. #ifdef COMMENT
  608. #ifdef CK_SPEED
  609.     if (f_ctlp) {
  610.         for (i = 0; i < 256; i++)
  611.           ctlp[i] = s_ctlp[i];
  612.         f_ctlp = 0;
  613.     }
  614. #endif /* CK_SPEED */
  615. #endif /* COMMENT */
  616.  
  617. #ifdef CK_TMPDIR
  618.     if (f_tmpdir) {            /* If we changed to download dir */
  619.     zchdir((char *) savdir);    /* Go back where we came from */
  620.     f_tmpdir = 0;
  621.     }
  622. #endif /* CK_TMPDIR */
  623.  
  624.     calibrate = 0L;                     /* Calibration run */
  625.     if (xreliable > -1) {
  626.     reliable = xreliable;
  627.     debug(F101,"ftreset reliable","",reliable);
  628.     }
  629.     urclear = 0;
  630.  
  631.     if (autopath) {                     /* SET RECEIVE PATHNAMES AUTO */
  632.         fnrpath = PATH_AUTO;
  633.         autopath = 0;
  634.     }
  635.     if (filefile) {                     /* File list */
  636.         zclose(ZMFILE);
  637.         makestr(&filefile,NULL);
  638.     }
  639.     if (c_save > -1) {                  /* Block Check Type */
  640.         bctr = c_save;
  641.         c_save = -1;
  642.     }
  643.     if (ss_save > -1) {                 /* Slow Start */
  644.         slostart = ss_save;
  645.         ss_save = -1;
  646.     }
  647. #ifdef CK_LABELED
  648.     if (g_lf_opts > -1) {
  649.         lf_opts = g_lf_opts;            /* Restore labeled transfer options */
  650.         g_lf_opts = -1;
  651.     }
  652. #endif /* CK_LABELED */
  653.  
  654. #ifndef NOCSETS
  655.     if (tcs_save > -1) {                /* Character sets */
  656.         tcharset = tcs_save;
  657.         tcs_save = -1;
  658.     }
  659.     if (fcs_save > -1) {
  660.         fcharset = fcs_save;
  661.         fcs_save = -1;
  662.     }
  663.     if (g_xfrxla > -1) {
  664.     xfrxla = g_xfrxla;
  665.     g_xfrxla = -1;
  666.     }
  667.     setxlatype(tcharset,fcharset);      /* Translation type */
  668. #endif /* NOCSETS */
  669.  
  670. #ifdef NETCONN
  671. #ifndef NOSPL
  672.     if (g_pswd) {
  673.         ckstrncpy(pwbuf,g_pswd,PWBUFL);
  674.         makestr(&g_pswd,NULL);
  675.     }
  676.     if (g_pflg > -1) {
  677.         pwflg = g_pflg;
  678.         g_pflg = -1;
  679.     }
  680.     if (g_pcpt > -1) {
  681.         pwcrypt = g_pcpt;
  682.         g_pcpt = -1;
  683.     }
  684. #endif /* NOSPL */
  685. #endif /* NETCONN */
  686.  
  687.     if (g_binary > -1) {                /* File type */
  688.         binary = g_binary;
  689.         g_binary = -1;
  690.     }
  691.     if (g_xfermode > -1) {              /* Transfer mode */
  692.         xfermode = g_xfermode;
  693.         g_xfermode = -1;
  694.     }
  695. #ifdef PATTERNS
  696.     if (g_patterns > -1) {              /* Filename patterns */
  697.         patterns = g_patterns;
  698.         g_patterns = -1;
  699.     }
  700. #endif /* PATTERNS */
  701.  
  702.     if (g_usepipes > -1) {
  703.         usepipes = g_usepipes;
  704.         g_usepipes = -1;
  705.     }
  706.     if (g_matchdot > -1) {
  707.         matchdot = g_matchdot;
  708.         g_matchdot = -1;
  709.     }
  710.     if (g_proto > -1) {                 /* Protocol */
  711.         protocol = g_proto;
  712.         g_proto = -1;
  713.     }
  714.     if (g_urpsiz > -1) {
  715.         urpsiz = g_urpsiz;
  716.         debug(F101,"ftreset restoring urpsiz","",urpsiz);
  717.         g_urpsiz = -1;
  718.     }
  719.     if (g_spsizf > -1) {
  720.         spsizf = g_spsizf;
  721.         debug(F101,"ftreset restoring spsizf","",spsizf);
  722.         g_spsizf = -1;
  723.     }
  724.     if (g_spsiz > -1) {
  725.         spsiz = g_spsiz;
  726.         debug(F101,"ftreset restoring spsiz","",spsiz);
  727.         g_spsiz = -1;
  728.     }
  729.     if (g_spsizr > -1) {
  730.         spsizr = g_spsizr;
  731.         debug(F101,"ftreset restoring spsizr","",spsizr);
  732.         g_spsizr = -1;
  733.     }
  734.     if (g_spmax > -1) {
  735.         spmax = g_spmax;
  736.         g_spmax = -1;
  737.     }
  738.     if (g_wslotr > -1) {
  739.         wslotr = g_wslotr;
  740.         g_wslotr = -1;
  741.     }
  742.     if (g_prefixing > -1) {
  743.         prefixing = g_prefixing;
  744.         g_prefixing = -1;
  745.     }
  746.     if (g_fncact > -1) {
  747.         fncact = g_fncact;
  748.         g_fncact = -1;
  749.     }
  750.     if (g_fncnv > -1) {
  751.         fncnv = g_fncnv;
  752.         g_fncnv = -1;
  753.     }
  754.     if (g_fnspath > -1) {
  755.         fnspath = g_fnspath;
  756.         g_fnspath = -1;
  757.     }
  758.     if (g_fnrpath > -1) {
  759.         fnrpath = g_fnrpath;
  760.         g_fnrpath = -1;
  761.     }
  762.     if (g_skipbup > -1) {
  763.         skipbup = g_skipbup;
  764.         g_skipbup = -1;
  765.     }
  766.     nolinks = 2;            /* /FOLLOWLINKS is never global */
  767.     recursive = 0;                      /* /RECURSIVE can never be global */
  768.     xfiletype = -1;
  769.  
  770.     if (g_displa > -1) {                /* File transfer display */
  771.         fdispla = g_displa;
  772.         g_displa = -1;
  773.     }
  774.     if (g_spath > -1) {                 /* Send pathnames */
  775.         fnspath = g_spath;
  776.         g_spath = -1;
  777.     }
  778.     if (g_rpath > -1) {                 /* Receive pathnames */
  779.         fnrpath = g_rpath;
  780.         g_rpath = -1;
  781.     }
  782.     if (g_fncnv > -1) {                 /* Filename conversion */
  783.         fncnv = g_fncnv;
  784.         g_fncnv = -1;
  785.     }
  786. #ifdef PIPESEND
  787.     makestr(&sndfilter,g_sfilter);      /* Send filter */
  788.     makestr(&rcvfilter,g_rfilter);      /* Receive filter */
  789. #endif /* PIPESEND */
  790.  
  791. #ifndef NOFRILLS
  792.     rmailf = rprintf = 0;               /* MAIL and PRINT modifiers for SEND */
  793.     optbuf[0] = NUL;                    /* MAIL and PRINT options */
  794. #endif /* NOFRILLS */
  795.  
  796.     moving = 0;                         /* Reset delete-after-send indicator */
  797.     sndafter[0]  = NUL;                 /* Reset SEND selection switches */
  798.     sndbefore[0] = NUL;
  799.  
  800.     for (i = 0; i < NSNDEXCEPT; i++) {
  801.         if (sndexcept[i])
  802.           free(sndexcept[i]);
  803.         sndexcept[i] = NULL;
  804.         if (rcvexcept[i])
  805.           free(rcvexcept[i]);
  806.         rcvexcept[i] = NULL;
  807.     }
  808.     sndlarger =  (CK_OFF_T)-1;
  809.     sndsmaller = (CK_OFF_T)-1;
  810.     debug(F101,"present sndsmaller","",sndsmaller);
  811. #ifdef GFTIMER
  812.     gtv = -1.0;
  813.     oldgtv = -1.0;
  814. #else
  815.     gtv = -1L;
  816.     oldgtv = -1L;
  817. #endif /* GFTIMER */
  818. #endif /* NOICP */
  819. }
  820. #endif /* NOXFER */
  821.  
  822. char *
  823. ttgtpn() {                /* Get typical port name */
  824. /*
  825.   Ideally this routine would be implemented in each of the cku?io.* modules,
  826.   but that requires changing the API definition.
  827. */
  828.     return(
  829. #ifdef OS2
  830. #ifdef OS2ONLY
  831. "COM1"
  832. #else  /* OS2ONLY */
  833. "TAPI [ name ] or COM1"
  834. #endif /* OS2ONLY */
  835. #else  /* OS2 */
  836. #ifdef VMS
  837. "TXA0:, TTA0:, or LTA0:"
  838. #else  /* VMS */
  839. #ifdef SOLARIS
  840. "/dev/cua/a"
  841. #else  /* SOLARIS */
  842. #ifdef HPUX10
  843. "/dev/cua0p0"
  844. #else  /* HPUX10 */
  845. #ifdef HPUX
  846. "/dev/cua00"
  847. #else  /* HPUX */
  848. #ifdef __FreeBSD__
  849. "/dev/cuaa0"
  850. #else  /* __FreeBSD__ */
  851. #ifdef __linux__
  852. "/dev/ttyS0"
  853. #else  /* __linux__ */
  854. #ifdef BSD44
  855. "/dev/tty00"
  856. #else  /* BSD44 */
  857. #ifdef OSK
  858. "/t1"
  859. #else  /* OSK */
  860. #ifdef QNX
  861. "/dev/ser1"
  862. #else  /* QNX */
  863. #ifdef QNX6
  864. "/dev/ser1"
  865. #else  /* QNX6 */
  866. #ifdef UNIXWARE
  867. "/dev/term/00 or /dev/tty00"
  868. #else  /* UNIXWARE */
  869. #ifdef CK_SCOV5
  870. "/dev/tty1A"
  871. #else  /* CK_SCOV5 */
  872. #ifdef CK_SCO32V4
  873. "/dev/tty1A"
  874. #else  /* CK_SCO32V4 */
  875. #ifdef M_XENIX
  876. "/dev/tty1A"
  877. #else  /* M_XENIX */
  878. #ifdef AIXRS
  879. "/dev/tty0"
  880. #else  /* AIXRS */
  881. #ifdef DGUX
  882. "/dev/tty00"
  883. #else  /* DGUX */
  884. #ifdef datageneral
  885. "@con1"
  886. #else  /* datageneral */
  887. #ifdef IRIX
  888. "/dev/ttym0"
  889. #else  /* IRIX */
  890. #ifdef SUNOS4
  891. "/dev/ttyh0"
  892. #else  /* SUNOS4 */
  893. #ifdef SV68R3V6
  894. "/dev/scc0"
  895. #else  /* SV68R3V6 */
  896. #ifdef MOTSV88R4
  897. "/dev/contty00"
  898. #else  /* MOTSV88R4 */
  899. #ifdef NEXT
  900. "/dev/cufa"
  901. #else
  902. #ifdef OSF
  903. "/dev/ttyd1"
  904. #else
  905. #ifdef SINIX
  906. "/dev/ttyc1"
  907. #else
  908. #ifdef UNIX
  909. "/dev/cua, /dev/acu, /dev/tty0, etc"
  910. #else  /* UNIX */
  911. "(sorry no example available)"
  912. #endif /* UNIX */
  913. #endif /* SINIX */
  914. #endif /* OSF */
  915. #endif /* NEXT */
  916. #endif /* MOTSV88R4 */
  917. #endif /* SV68R3V6 */
  918. #endif /* SUNOS4 */
  919. #endif /* IRIX */
  920. #endif /* datageneral */
  921. #endif /* DGUX */
  922. #endif /* AIX */
  923. #endif /* M_XENIX */
  924. #endif /* CK_SCO32V4 */
  925. #endif /* CK_SCOV5 */
  926. #endif /* UNIXWARE */
  927. #endif /* QNX6 */
  928. #endif /* QNX */
  929. #endif /* OSK */
  930. #endif /* BSD44 */
  931. #endif /* __linux__ */
  932. #endif /* __FreeBSD__ */
  933. #endif /* HPUX */
  934. #endif /* HPUX10 */
  935. #endif /* SOLARIS */
  936. #endif /* VMS */
  937. #endif /* OS2 */
  938.        );
  939. }
  940.  
  941. /*  C K _ E R R S T R  --  Return message from most recent system error */
  942.  
  943. #ifdef CKROOT
  944. extern int ckrooterr;
  945. #endif /* CKROOT */
  946.  
  947. char *
  948. ck_errstr() {
  949. #ifdef USE_STRERROR
  950. #ifndef CK_ANSILIBS
  951.     /* Should have been declared in <string.h> */
  952. _PROTOTYP( char * strerror, (int) );
  953. #endif /* CK_ANSILIBS */
  954. #ifdef CKROOT
  955.     if (ckrooterr)
  956.       return("Off limits");
  957. #endif /* CKROOT */
  958.     return(strerror(errno));
  959. #else  /* !USE_STRERROR */
  960. #ifdef VMS
  961.     extern char * ckvmserrstr(unsigned long);
  962. #ifdef CKROOT
  963.     if (ckrooterr)
  964.       return("Off limits");
  965. #endif /* CKROOT */
  966.     return(ckvmserrstr(0L));
  967. #else  /* !VMS */
  968. #ifdef BSD44
  969. #ifdef __386BSD__
  970. #ifndef NDSYSERRLIST
  971.     extern int sys_nerr;
  972.     extern char *sys_errlist[];
  973. #endif /* NDSYSERRLIST */
  974. #else  /* !__386BSD__ */
  975. #ifndef __bsdi__
  976. #ifndef NDSYSERRLIST
  977.     extern int sys_nerr;
  978.     extern const char *const sys_errlist[];
  979. #endif /* NDSYSERRLIST */
  980. #endif /* __bsdi__ */
  981. #endif /* __386BSD__ */
  982. #ifdef CKROOT
  983.     if (ckrooterr)
  984.       return("Off limits");
  985.     else
  986. #endif /* CKROOT */
  987.     if (errno >= sys_nerr)
  988.       return("Error number out of range");
  989.     else
  990.       return((char *) sys_errlist[errno]);
  991. #else /* !BSD44 */
  992. #ifdef ATTSV
  993. #ifndef NDSYSERRLIST
  994.     extern int sys_nerr;
  995.     extern char *sys_errlist[];
  996. #endif /* NDSYSERRLIST */
  997. #ifdef CKROOT
  998.     if (ckrooterr)
  999.       return("Off limits");
  1000.     else
  1001. #endif /* CKROOT */
  1002.     if (errno >= sys_nerr)
  1003.       return("Error number out of range");
  1004.     else
  1005.       return((char *) sys_errlist[errno]);
  1006. #else /* !ATTSV */
  1007. #ifdef BSD4
  1008. #ifndef NDSYSERRLIST
  1009.     extern int sys_nerr;
  1010.     extern char *sys_errlist[];
  1011. #endif /* NDSYSERRLIST */
  1012. #ifdef CKROOT
  1013.     if (ckrooterr)
  1014.       return("Off limits");
  1015.     else
  1016. #endif /* CKROOT */
  1017.     if (errno >= sys_nerr)
  1018.       return("Error number out of range");
  1019.     else
  1020.       return((char *) sys_errlist[errno]);
  1021. #else
  1022. #ifdef OS2
  1023. #ifndef NDSYSERRLIST
  1024.     extern char *sys_errlist[];
  1025. #endif /* NDSYSERRLIST */
  1026. #ifdef NT
  1027.     extern int_sys_nerr;
  1028. #endif /* NT */
  1029.     char *e;
  1030. #ifdef CKROOT
  1031.     if (ckrooterr)
  1032.       return("Off limits");
  1033. #endif /* CKROOT */
  1034.     e = (errno > -1
  1035. #ifdef NT
  1036.          && errno <= _sys_nerr
  1037. #endif /* NT */
  1038.          ) ?
  1039. #ifdef NT
  1040.          (char *) sys_errlist[errno]
  1041. #else /* NT */
  1042.          /* I don't know how to get a CLIB error string in OS/2 */
  1043.          strerror(errno)
  1044. #endif /* NT */
  1045.              : "";
  1046.     return(e ? e : "");
  1047. #else /* OS2 */
  1048.     return("");
  1049. #endif /* OS2 */
  1050. #endif /* BSD4 */
  1051. #endif /* ATTSV */
  1052. #endif /* BSD44 */
  1053. #endif /* VMS */
  1054. #endif /* USE_STRERROR */
  1055. }
  1056.  
  1057. #ifdef PATTERNS
  1058. /*
  1059.   Filename pattern recognition lists for automatic text/binary switching.
  1060.   These are somewhat passe after the addition of scanfile()  (7.0).
  1061.   But with the addition of FTP [M]GET, they're back in style (8.0).
  1062.  
  1063.   Although, with FTP the lists need to be used in the reverse.  With
  1064.   Kermit the list is used to imply the types of the local system.  Whereas
  1065.   with FTP, the list must be used to imply the type of the remote system.
  1066.   Therefore, all platforms must now support all of the lists.
  1067. */
  1068. char *txtpatterns[FTPATTERNS+1] = { NULL, NULL };
  1069. char *binpatterns[FTPATTERNS+1] = { NULL, NULL };
  1070. /*
  1071.   Default pattern lists for each platform...
  1072.  
  1073.   NOTE: In most cases we leave ".hlp", ".ini", and ".scr" alone; although they
  1074.   are traditionally text types, they are binary in Windows.  So they are
  1075.   handled by the prevailing SET FILE TYPE, rather than automatically.
  1076.   Similarly for ".dat", ".inf", and so on.  Also ".ps" since PostScript files
  1077.   are not always text.  ".log" is omitted since logs can be text or binary,
  1078.   except in VMS they are usually text, etc etc.
  1079.  
  1080.   Later (Sep 2003): Add PostScript to binary patterns.
  1081. */
  1082. static char *txtp[SYS_MAX][FTPATTERNS] = {
  1083.     /* UNKNOWN */ {
  1084.     NULL, NULL
  1085.     },
  1086.     {                    /* UNIX */
  1087.     "*.txt","*.c","*.h","*.r","*.w","*.cpp","*.cc","*.ksc","*.bwr","*.upd",
  1088.     "*.html","*.htm","*.mss","*.tex","*.nr","[Mm]akefile", "*.hex", "*.hqx",
  1089.     "*.for","*.f77","*.f","*.F","*.s","*.pas","*.java","*.el","*.lisp","*.sh",
  1090.     "*.m4","*.perl","*.pl","*.pod","*.pm","*.awk","*.sno","*.spt","*.sed",
  1091.     "*.ksc","*.TXT", "*read.me", "*READ.ME", ".*", "*/.*", "*.mem","*.mac",
  1092.     NULL
  1093.     },
  1094.     {                    /* WIN32 */
  1095.     "*.txt","*.ksc","*.htm","*.html","*.bat","*.cmd","*.jav","*.asm", "*.hex",
  1096.     "*.hqx", "*.c", "*.h", "*.cpp", "*.hpp", "*.cxx", "*.cxx", "*.w",
  1097.     "*.java", "*.bwr", "*.upd", "*.mak", "read.me", "*.map", "makefile",
  1098.     "*.mem","*.mac","*.cc","*.pl","*.pod","*.pm","*.m4",NULL
  1099.     },
  1100.     {                    /* VMS */
  1101.     "*.com","*.txt","*.c",  "*.for","*.pas","*.rno","*.rnh","*.mar","*.bli",
  1102.     "*.hlp","*.mss","*.doc","*.bwr","*.cld","*.hex","*.bas","*.ini","*.log",
  1103.     "*.mms","*.opt","*.ksc","*.perl","*.pl","*.pod","*.pm","*.sno","*.spt",
  1104.     "*.mem",NULL
  1105.     },
  1106.     {                    /* OS2 */
  1107.     "*.txt","*.ksc","*.htm","*.html","*.bat","*.cmd","*.jav","*.asm", "*.hex",
  1108.     "*.hqx", "*.c", "*.h", "*.cpp", "*.hpp", "*.cxx", "*.cxx", "*.w",
  1109.     "*.java", "*.bwr", "*.upd", "*.mak", "read.me", "*.map", "makefile",
  1110.     NULL
  1111.     },
  1112.     {                    /* DOS */
  1113.     "*.txt","*.ksc","*.htm","*.bat","*.cmd","*.jav","*.asm", "*.hex",
  1114.     "*.hqx", "*.c", "*.h", "*.cpp", "*.hpp", "*.cxx", "*.cxx", "*.w",
  1115.     "*.bwr", "*.upd", "*.mak", "read.me", "*.map", "makefile", NULL
  1116.     },
  1117.     {                    /* TOPS-10 */
  1118.     "*.cmd","*.hlp","*.doc","*.ini","*.txt","*.mac","*.for","*.sai","*.bli",
  1119.     "*.pas","*.sno","*.spt","*.pcl","*.mss","*.rno","*.b36","*.tex","*.pub",
  1120.     "*.req","*.r36","*.mem","*.bwr","*.ccl","*.ctl","*.rnh","*.ksc",NULL
  1121.     },
  1122.     {                    /* TOPS-20 */
  1123.     "*.cmd","*.hlp","*.doc","*.ini","*.txt","*.mac","*.for","*.sai","*.bli",
  1124.     "*.pas","*.sno","*.spt","*.pcl","*.mss","*.rno","*.b36","*.tex","*.pub",
  1125.     "*.req","*.r36","*.mem","*.bwr","*.ccl","*.ctl","*.rnh","*.ksc",NULL
  1126.     },
  1127.     {                    /* STRATUS VOS */
  1128.     "*.txt","*.ksc","*.htm","*.html","*.bat", "*.cmd","*.jav","*.asm","*.hex",
  1129.     "*.hqx","*.c",  "*.h",  "*.w",   "*.java","*.bwr","*.upd","*.ttp","*.cm",
  1130.     "*.pl1","*.emacs", "read.me", "*.pl", "makefile", NULL
  1131.     },
  1132.     {                    /* DG AOS/VS */
  1133.     "*.txt", "*.c", "*.h", "*.w", "*.er", "*.bwr", "*.upd", "read.me",
  1134.     "*.cli", "*.ksc", NULL
  1135.     },
  1136.     {                    /* OSK */
  1137.     "*.c","*.cpp","*.h","*.a","*akefile", /* program sources */
  1138.     "*.for","*.f77","*.f","*.F","*.s","*.pas","*.java","*.el","*.lisp",
  1139.     "*.sh","*.perl","*.awk","*.sno","*.spt","*.sed",
  1140.     "*.txt","*.w",            /* general text */
  1141.     "*.ksc","*.bwr","*.upd",
  1142.     "*.html","*.htm","*.mss","*.tex","*.nr","*.hex", "*.hqx",
  1143.     "*.TXT", "*read.me", "*READ.ME", ".*", "*/.*",
  1144.     NULL
  1145.     }
  1146. };
  1147.  
  1148. /* Note: .DOC added to (some) binary patterns June 1998... Microsoft wins. */
  1149.  
  1150. static char *binp[SYS_MAX][FTPATTERNS] = {
  1151.     {                    /* UNKNOWN */
  1152.     NULL, NULL
  1153.     },
  1154.     {                    /* UNIX */
  1155.     "*.gz","*.Z","*.tgz","*.gif", "*.tar","*.zip","*.o","*.so","*.a","*.out",
  1156.     "*.exe", "*.jpg", "*.jpeg", "*.tif","*.tiff", "*.pdf", "*.so.*", "*.class",
  1157.     "*.rpm", "*.bmp", "*.bz2", "*.BMP", "*.dll", "*.doc", "*.vxd", "*.dcx",
  1158.     "*.xl*", "*.lzh", "*.lhz", "*.au", "*.voc", "*.mpg", "*.mpeg","[wk]ermit",
  1159.     "*.ps", NULL
  1160.     },
  1161.     {                    /* WIN32 */
  1162.     "*.exe", "*.zip", "*.obj", "*.com", "*.gif", "*.jpg", "*.wav", "*.ram",
  1163.     "*.class","*.cla","*.dll", "*.drv", "*.ocx", "*.vbx", "*.lib", "*.ico",
  1164.     "*.bmp", "*.tif", "*.tar", "*.gz",  "*.tgz", "*.xl*", "*.doc", "*.vxd",
  1165.     "*.pdf", "*.lzh", "*.vxd", "*.snd", "*.au", "* .voc", "*.mpg", "*.mpeg",
  1166.     "*.ps", NULL
  1167.     },
  1168.     {                    /* VMS */
  1169.     "*.exe","*.obj","*.bak","*.bin","*.adf","*.stb","*.mai","*.sys","*.dmp",
  1170.     "*.ps", "*.dat","*.par", NULL
  1171.     },
  1172.     {                    /* OS2 */
  1173.     "*.exe", "*.zip", "*.obj", "*.com", "*.gif", "*.jpg", "*.wav", "*.ram",
  1174.     "*.class", "*.cla", "*.dll", "*.drv", "*.ocx", "*.vbx", "*.lib", "*.ico",
  1175.     "*.bmp", "*.tif", "*.tar", "*.gz", "*.tgz", "*.xl*", "*.doc", "*.vxd",
  1176.     "*.pdf", "*.ps", "*.lzh", NULL
  1177.     },
  1178.     {                    /* DOS */
  1179.     "*.exe", "*.zip", "*.obj", "*.com", "*.gif", "*.jpg", "*.wav", "*.ram",
  1180.     "*.cla", "*.dll", "*.drv", "*.ocx", "*.vbx", "*.lib", "*.ico",
  1181.     "*.bmp", "*.tif", "*.tar", "*.gz", "*.tgz", "*.xl*", "*.doc", "*.vxd",
  1182.     "*.pdf", "*.ps", "*.lzh", NULL
  1183.     },
  1184.     {                    /* TOPS10 */
  1185.     "*.exe","*.sav","*.bin","*.rim","*.rel","*.unv","*.lib","*.tap","*.dvi",
  1186.     "*.ps", NULL
  1187.     },
  1188.     {                    /* TOPS20 */
  1189.     "*.exe","*.sav","*.bin","*.rim","*.rel","*.unv","*.lib","*.tap","*.dvi",
  1190.     "*.ps", NULL
  1191.     },
  1192.     {                    /* STRATUS VOS */
  1193.     "*.exe", "*.zip", "*.obj", "*.com", "*.gif", "*.jpg", "*.wav", "*.ram",
  1194.     "*.class", "*.cla", "*.dll", "*.drv", "*.ocx", "*.vbx", "*.lib", "*.ico",
  1195.     "*.bmp", "*.tif", "*.tar", "*.gz", "*.tgz", "*.xl*", "*.doc", "*.vxd",
  1196.     "*.pdf", "*.ps", "*.lzh", "*.pm", NULL
  1197.     },
  1198.     {                    /* DG */
  1199.     "*.ob", "*.pr", "*.dmp", "*.ps", NULL
  1200.     },
  1201.     { /* OSK */
  1202.     "*.gz","*.Z","*.z","*.tgz","*.lhz","*.tar",    /* archivers */
  1203.     "*.zip","*.ar","*.zoo","*.rpm","*.lzh",
  1204.     /* object files, libraries, executables */
  1205.     "*.r","*.l","*.exe", "*.dll", "*.so.*", "*.class",
  1206.     /* images */
  1207.     "*.gif", "*.jpg", "*.jpeg", "*.tif","*.tiff", "*.pdf", "*.ps",
  1208.     "*.bmp", "*.bz2", "*.BMP","*.pcx",
  1209.     NULL
  1210.     }
  1211. };
  1212.  
  1213. /*
  1214.   Set up default pattern lists so they can be freed and re-malloc'd.
  1215.   Each pattern list must terminated by a null element.
  1216. */
  1217. VOID
  1218. initpat() {
  1219.     int i;
  1220.     for (i = 0; i < FTPATTERNS; i++) {
  1221.         txtpatterns[i] = NULL;
  1222.         binpatterns[i] = NULL;
  1223.     }
  1224.     for (i = 0; i < FTPATTERNS; i++) {
  1225. #ifdef UNIX
  1226.         makestr(&(txtpatterns[i]),txtp[SYS_UNIX][i]);
  1227. #else /* UNIX */
  1228. #ifdef OS2
  1229. #ifdef NT
  1230.         makestr(&(txtpatterns[i]),txtp[SYS_WIN32][i]);
  1231. #else /* NT */
  1232.         makestr(&(txtpatterns[i]),txtp[SYS_OS2][i]);
  1233. #endif /* NT */
  1234. #else /* OS2 */
  1235. #ifdef VMS
  1236.         makestr(&(txtpatterns[i]),txtp[SYS_VMS][i]);
  1237. #else /* VMS */
  1238. #ifdef STRATUS
  1239.         makestr(&(txtpatterns[i]),txtp[SYS_VOS][i]);
  1240. #else /* STRATUS */
  1241. #ifdef datageneral
  1242.         makestr(&(txtpatterns[i]),txtp[SYS_DG][i]);
  1243. #else /* datageneral */
  1244. #ifdef OSK
  1245.         makestr(&(txtpatterns[i]),txtp[SYS_OSK][i]);
  1246. #else /* OSK */
  1247.         makestr(&(txtpatterns[i]),txtp[SYS_UNK][i]);
  1248. #endif /* OSK */
  1249. #endif /* datageneral */
  1250. #endif /* STRATUS */
  1251. #endif /* VMS */
  1252. #endif /* OS2 */
  1253. #endif /* UNIX */
  1254.         if (!txtp[i])
  1255.           break;
  1256.     }
  1257.     for (i = 0; i < FTPATTERNS; i++) {
  1258. #ifdef UNIX
  1259.         makestr(&(binpatterns[i]),binp[SYS_UNIX][i]);
  1260. #else /* UNIX */
  1261. #ifdef OS2
  1262. #ifdef NT
  1263.         makestr(&(binpatterns[i]),binp[SYS_WIN32][i]);
  1264. #else /* NT */
  1265.         makestr(&(binpatterns[i]),binp[SYS_OS2][i]);
  1266. #endif /* NT */
  1267. #else /* OS2 */
  1268. #ifdef VMS
  1269.         makestr(&(binpatterns[i]),binp[SYS_VMS][i]);
  1270. #else /* VMS */
  1271. #ifdef STRATUS
  1272.         makestr(&(binpatterns[i]),binp[SYS_VOS][i]);
  1273. #else /* STRATUS */
  1274. #ifdef datageneral
  1275.         makestr(&(binpatterns[i]),binp[SYS_DG][i]);
  1276. #else /* datageneral */
  1277. #ifdef OSK
  1278.         makestr(&(binpatterns[i]),binp[SYS_OSK][i]);
  1279. #else /* OSK */
  1280.         makestr(&(binpatterns[i]),binp[SYS_UNK][i]);
  1281. #endif /* OSK */
  1282. #endif /* datageneral */
  1283. #endif /* STRATUS */
  1284. #endif /* VMS */
  1285. #endif /* OS2 */
  1286. #endif /* UNIX */
  1287.         if (!binp[i])
  1288.           break;
  1289.     }
  1290. }
  1291.  
  1292. /*
  1293.   m a t c h n a m e  --  Compare filename with text & binary name patterns.
  1294.  
  1295.   Returns:
  1296.     0 if name matches a text pattern but not a binary pattern.
  1297.     1 if name matches a binary pattern but not a text pattern.
  1298.    -1 if name matches no patterns.
  1299.    -2 if name matches a binary pattern and a text pattern.
  1300. */
  1301. int
  1302. matchname(filename, local, os) char * filename; int local; int os; {
  1303.     int rc = -1;            /* Return code */
  1304.     char * name, * p;
  1305. #ifdef OS2ORUNIX
  1306.     char tmpbuf[CKMAXPATH+1];
  1307. #endif /* OS2ORUNIX */
  1308.  
  1309.     name = filename ? filename : "";    /* Copy of original arg */
  1310.     if (patterns && *name) {        /* If PATTERNS ON... */
  1311.     int i;
  1312.  
  1313. #ifdef OS2ORUNIX
  1314.     if (ckmatch("*.~[1-9]*~",name,1,1)) { /* Name has backup suffix? */
  1315.         int k;
  1316.         k = ckstrncpy(tmpbuf,name,CKMAXPATH+1); /* Yes, copy and strip */
  1317.         for (i = k - 3; i > 4; i--) {
  1318.         if (tmpbuf[i] == '~' && tmpbuf[i-1] == '.') {
  1319.             tmpbuf[i-1] = NUL;
  1320.             break;
  1321.         }
  1322.         }
  1323.         name = tmpbuf;        /* And point to stripped copy */
  1324.     }
  1325. #endif /* OS2ORUNIX */
  1326.     zstrip(name,&p);        /* Strip pathname too */
  1327.     name = p;
  1328.  
  1329.         if (local) {
  1330.             if (txtpatterns[0]) {    /* Search text patterns */
  1331.                 for (i = 0; i < FTPATTERNS && txtpatterns[i]; i++) {
  1332.                     if (ckmatch(txtpatterns[i],name,filecase,1)) {
  1333.                         rc = 0;
  1334.                         break;
  1335.                     }
  1336.                 }
  1337.             }
  1338.             if (binpatterns[0]) {    /* And search binary patterns */
  1339.                 for (i = 0; i < FTPATTERNS && binpatterns[i]; i++) {
  1340.                     if (ckmatch(binpatterns[i],name,filecase,1)) {
  1341.                         rc = (rc > -1) ? -2 : 1;
  1342.                         break;
  1343.                     }
  1344.                 }
  1345.             }
  1346.     } else {
  1347.             if (os >= 0 && os < SYS_MAX) {
  1348.         if (txtp[os][0]) {
  1349.             for (i = 0; i < FTPATTERNS && txtp[os][i]; i++) {
  1350.             if (ckmatch(txtp[os][i],name,filecase,1)) {
  1351.                 rc = 0;
  1352.                 break;
  1353.             }
  1354.             }
  1355.         }
  1356.         if (binp[os][0]) {
  1357.             for (i = 0; i < FTPATTERNS && binp[os][i]; i++) {
  1358.             if (ckmatch(binp[os][i],name,filecase,1)) {
  1359.                 rc = (rc > -1) ? -2 : 1;
  1360.                 break;
  1361.             }
  1362.             }
  1363.         }
  1364.         }
  1365.         }
  1366.     }
  1367.     debug(F111,"matchname",name,rc);
  1368.     return(rc);
  1369. }
  1370. #endif /* PATTERNS */
  1371.  
  1372. #ifdef UNICODE
  1373. #ifndef NOEVENMAX
  1374. #define EVENMAX
  1375. #endif /* NOEVENMAX */
  1376. #endif /* UNICODE */
  1377.  
  1378. /*  S C A N F I L E  --  Analyze a file's contents  */
  1379.  
  1380. /*
  1381.   Call with:
  1382.     name:    Pointer to name of existing file.
  1383.     flag:    Pointer to int in which to return additional numeric data.
  1384.  
  1385.   Returns:
  1386.     -1 on failure (to open file or to read from it).
  1387.     Integer, 0..4, on success indicating file type:
  1388.      0 = 7-bit text (flag = -1)
  1389.      1 = UTF-8 text (flag = -1)
  1390.      2 = UCS-2 text (flag =  0: big-endian; flag = 1: little-endian)
  1391.      3 = 8-bit text (flag =  0: no C1 bytes; flag = 1: includes C1 bytes)
  1392.      4 = binary     (flag = -1)
  1393.  
  1394.   If UNICODE is defined:
  1395.  
  1396.    1. If file begins with a valid BOM, it is believed.  Otherwise we
  1397.       read the first 4K of the file (since it might be email with verbose
  1398.       headers) and analyze it:
  1399.  
  1400.    2. If file contains only valid UTF-8 sequences, we call it UTF-8;
  1401.       otherwise:
  1402.  
  1403.    3. If the file contains lots of alternate 0 bytes, we call it UCS-2, and
  1404.       set the polarity according to whether the preponderance of them are in
  1405.       even or odd positions; otherwise:
  1406.  
  1407.    4. If EVENMAX is defined and the file contains lots of alternate bytes that
  1408.       are identical, even if they aren't zero, and the number of such bytes
  1409.       is at least four times the length of the maximum run of alternating
  1410.       identical bytes of the opposite polarity, we call it UCS-2; otherwise:
  1411.  
  1412.    5. If the file contained no bytes with their 8th bits on and no controls
  1413.       other than CR, LF, HT, and FF, we call it ASCII; otherwise:
  1414.  
  1415.    6. If it contains C0 control characters other than CR, LF, HT, and FF, we
  1416.       call it binary; otherwise:
  1417.  
  1418.    7. We call it 8-bit text, character set unknown (could be Latin-1 or
  1419.       anything else).
  1420.  
  1421.    Note that malformed UTF-8 is not diagnosed as UTF-8.
  1422.  
  1423.    If UNICODE is not defined:
  1424.  
  1425.    1. If the file contains C0 control characters other than CR, LF, HT, and
  1426.       FF, we call it binary; otherwise:
  1427.  
  1428.    2. If the file contains any 8-bit bytes, we call it 8-bit text; otherwise:
  1429.  
  1430.    3. We call it 7-bit text.
  1431.  
  1432.    In the non-Unicode case, UCS-2 is diagnosed as binary, but UTF-8 as
  1433.    8-bit text.
  1434.  
  1435.    There is no significant speed difference between the Unicode and
  1436.    non-Unicode cases.
  1437. */
  1438. int
  1439. scanfile(name,flag,nscanfile) char * name; int * flag, nscanfile; {
  1440.     FILE * fp;                /* File pointer */
  1441.     unsigned char buf[SCANFILEBUF];    /* File data buffer for analysis */
  1442.     int x, val = -1, count = 0;        /* Workers */
  1443.     int rc = -1;            /* Return code */
  1444.     int pv = -1;            /* Pattern-match value */
  1445.     int eof = 0;            /* Flag for file EOF encountered */
  1446.     int bytes = 0;            /* Total byte count */
  1447. #ifdef UNICODE
  1448.     unsigned int c0, c1;        /* First 2 file bytes (for BOM) */
  1449. #endif /* UNICODE */
  1450.     extern int pipesend, filepeek;
  1451.  
  1452.     register int i;            /* Loop control */
  1453.     int readsize = 0;            /* How much to read */
  1454.     int eightbit = 0;            /* Number of bytes with 8th bit on */
  1455.     int c0controls = 0;            /* C0 non-text control-char counter */
  1456.     int c0noniso = 0;            /* C0 non-ISO control-char counter */
  1457.     int c1controls = 0;            /* C1 control-character counter */
  1458.     unsigned int c;            /* Current character */
  1459.     int runmax = 0;            /* Longest run of 0 bytes */
  1460.     int runzero = 0;            /* Run of 0 bytes */
  1461.     int pctzero = 0;            /* Percentage of 0 bytes */
  1462.     int txtcz = 0;
  1463. #ifdef CK_CTRLZ
  1464.     extern int eofmethod;
  1465. #endif /* CK_CTRLZ */
  1466.  
  1467. #ifdef UNICODE
  1468.     int notutf8 = 0;            /* Nonzero if definitely not UTF-8 */
  1469.     int utf8state = 0;            /* UTF-8 recognizer state */
  1470.     int oddzero = 0;            /* Number of 0 bytes in odd postions */
  1471.     int evenzero = 0;            /* and in even positions */
  1472.     int lfnul = 0;            /* Number of <LF><NUL> sequences */
  1473.     int crlf = 0;            /* Number of <CRLF> sequences */
  1474. #else
  1475.     int notutf8 = 1;
  1476. #endif /* UNICODE */
  1477.  
  1478. #ifdef COMMENT
  1479. #ifdef EVENMAX
  1480.     int oddrun = 0, oddmax = 0, oddbyte = 0, oddmaxbyte = 0;
  1481.     int evenrun = 0, evenmax = 0, evenbyte = 0, evenmaxbyte = 0;
  1482. #endif /* EVENMAX */
  1483. #endif /* COMMENT */
  1484.  
  1485. #ifndef NOXFER
  1486.     if (pipesend || calibrate || sndarray) /* Only for real files */
  1487.       return(-1);
  1488. #endif /* NOXFER */
  1489.     debug(F111,"scanfile",name,nscanfile);
  1490. #ifdef PATTERNS
  1491.     if (!filepeek) {
  1492.     pv = matchname(name,1,-1);
  1493.     if (pv < 0)
  1494.       rc = -1;
  1495.     else
  1496.       rc = (pv == 1) ? FT_BIN : FT_TEXT;
  1497.     debug(F111,"scanfile !filepeek result",name,rc);
  1498.     return(rc);
  1499.     }
  1500. #endif /* PATTERNS */
  1501.  
  1502. #ifdef VMS
  1503. /* We don't scan in VMS where text files have various record formats in  */
  1504. /* which record headers contain seemingly non-text bytes.  So the best   */
  1505. /* we can do in VMS is tell whether the file is text or binary, period.  */
  1506.     {
  1507.     int b, x;
  1508.     b = binary;            /* Save current binary setting */
  1509.     if (zopeni(ZIFILE,name) > 0) {    /* In VMS this sets binary */
  1510.         x = binary;            /* Get result */
  1511.         zclose(ZIFILE);        /* Close the file */
  1512.         binary = b;            /* Restore previous binary setting */
  1513.         rc = x ? FT_BIN : FT_TEXT;
  1514.         val = 0;
  1515.         goto xscanfile;
  1516.     }
  1517.     }
  1518. #endif /* VMS */
  1519.  
  1520.     eof = 0;                /* End-of-file reached indicator */
  1521. #ifdef OS2
  1522.     fp = fopen(name, "rb");        /* Open the file in binary mode */
  1523. #else
  1524.     fp = fopen(name, "r");
  1525. #endif /* OS2 */
  1526.  
  1527.     if (!fp)                /* Failed? */
  1528.       return(-1);
  1529.  
  1530.     while (1) {                /* One or more gulps from file */
  1531.     if (eof) {            /* EOF from last time? */
  1532.         debug(F111,"scanfile at EOF",name,bytes);
  1533.         if (runzero > runmax)
  1534.           runmax = runzero;
  1535.         break;
  1536.     }
  1537.     if (nscanfile < 0) {        /* Reading whole file */
  1538.         readsize = SCANFILEBUF;
  1539.     } else {            /* Reading first nscanfilee bytes */
  1540.         readsize = nscanfile - bytes;
  1541.         if (readsize < 1)
  1542.           break;
  1543.         if (readsize > SCANFILEBUF)
  1544.           readsize = SCANFILEBUF;
  1545.     }
  1546.     debug(F101,"scanfile readsize","",readsize);
  1547.     count = fread(buf,1,readsize,fp); /* Read a buffer */
  1548.     if (count == EOF || count == 0) {
  1549.         debug(F111,"scanfile EOF",name,count);
  1550.         break;
  1551.     }
  1552.     debug(F111,"scanfile buffer ok",name,count);
  1553.  
  1554.     if (bytes == 0 && count > 8) {
  1555.         /* PDF files can look like text in the beginning. */
  1556.         if (!ckstrcmp((char *)buf,"%PDF-1.",7,1)) {
  1557.         if (isdigit(buf[7])) {
  1558.             if (buf[8] == '\015' ||
  1559.             count > 9 && buf[8] == SP && buf[9] == '\015') {
  1560. #ifdef DEBUG
  1561.             buf[8] = NUL;
  1562.             debug(F110,"scanfile PDF",buf,0);
  1563. #endif /* DEBUG */
  1564.             binary = 1;    /* But they are binary. */
  1565.             break;
  1566.             }
  1567.         }
  1568.         } else if (!ckstrcmp((char *)buf,"%!PS-Ado",8,1)) {
  1569.         /* Ditto for PostScript */
  1570. #ifdef DEBUG
  1571.         int i;
  1572.         for (i = 8; i < count; i++) {
  1573.             if (buf[i] < '!') {
  1574.             buf[i] = NUL;
  1575.             break;
  1576.             }
  1577.         }
  1578.         debug(F110,"scanfile PostScript",buf,0);
  1579. #endif /* DEBUG */
  1580.         binary = 1;
  1581.         break;
  1582. #ifndef NOPCLSCAN
  1583.         } else if (!ckstrcmp((char *)buf,") HP-PCL",8,1)) {
  1584.         /* HP PCL printer language */
  1585. #ifdef DEBUG
  1586.         int i;
  1587.         for (i = 8; i < count; i++) {
  1588.             if (buf[i] < '!') {
  1589.             buf[i] = NUL;
  1590.             break;
  1591.             }
  1592.         }
  1593.         debug(F110,"scanfile PCL",buf,0);
  1594. #endif /* DEBUG */
  1595.         binary = 1;
  1596.         break;
  1597.         } 
  1598. #endif /* NOPCLSCAN */
  1599. #ifndef NOPJLSCAN
  1600.           else if (buf[0] == '\033' && (buf[1] == 'E' || buf[1] == '%')) {
  1601.         /* Ditto for PJL Job printer header */
  1602. #ifdef DEBUG
  1603.         int i;
  1604.         for (i = 2; i < count; i++) {
  1605.             if (buf[i] < '!') {
  1606.             buf[i] = NUL;
  1607.             break;
  1608.             }
  1609.         }
  1610.         debug(F110,"scanfile PJL Job printer header",buf,0);
  1611. #endif /* DEBUG */
  1612.         binary = 1;
  1613.         break;
  1614. #endif /* NOPJLSCAN */
  1615.         }
  1616.     }
  1617.  
  1618. #ifdef UNICODE
  1619.     if (bytes == 0 && count > 1) {
  1620.         int incl_cnt = 0;
  1621.  
  1622.         /* First look for BOM */
  1623.  
  1624.         c0 = (unsigned)((unsigned)buf[0]&0xFF); /* First file byte */
  1625.         c1 = (unsigned)((unsigned)buf[1]&0xFF); /* Second byte */
  1626.  
  1627.         if (c0 == 0xFE && c1 == 0xFF) {    /* UCS-2 BE */
  1628.         rc = FT_UCS2;
  1629.         val = 0;
  1630.         debug(F111,"scanfile UCS2 BOM BE",ckitoa(val),rc);
  1631.         incl_cnt++;
  1632.         } else if (c0 == 0xFF && c1 == 0xFE) { /* UCS-2 LE */
  1633.         rc = FT_UCS2;
  1634.         val = 1;
  1635.         debug(F111,"scanfile UCS2 BOM LE",ckitoa(val),rc);
  1636.         incl_cnt++;
  1637.         } else if (count > 2) if (c0 == 0xEF && c1 == 0xBB &&
  1638.                (unsigned)((unsigned)buf[2]&0xFF) == 0xBF) {
  1639.         rc = FT_UTF8;
  1640.         debug(F111,"scanfile UTF8 BOM",ckitoa(val),rc);
  1641.         incl_cnt++;
  1642.         }
  1643.         if (incl_cnt) {        /* Have BOM */
  1644.         bytes += count;
  1645.         goto xscanfile;
  1646.         }
  1647.     }
  1648. #endif /* UNICODE */
  1649.  
  1650.     bytes += count;            /* Count bytes read */
  1651.     eof = feof(fp);            /* Flag for at EOF  */
  1652.  
  1653.     for (i = 0; i < count; i++) {    /* For each byte... */
  1654.         c = (unsigned)buf[i];    /* For ease of reference */
  1655.         if (!c) {            /* Zero byte? */
  1656. #ifdef EVENMAX
  1657.         if (i&1)        /* In odd position */
  1658.           oddzero++;
  1659.         else
  1660.           evenzero++;        /* In even position */
  1661. #endif /* EVENMAX */
  1662.         runzero++;
  1663.         } else {            /* Not a zero byte */
  1664.         if (runzero > runmax)
  1665.           runmax = runzero;
  1666.         if (runmax > 2)        /* That's all we need to be certain */
  1667.           break;        /* it's a binary file. */
  1668.         runzero = 0;
  1669.         }
  1670.  
  1671. #ifdef COMMENT
  1672. #ifdef EVENMAX
  1673.  
  1674. /* This is to catch UCS-2 with a non-ASCII, non-Latin-1 repertoire  */
  1675.  
  1676.         if (i > 1) {          /* Look for runs of alternating chars */
  1677.         if (i&1) {
  1678.             if (c == buf[i-2]) { /* In odd positions */
  1679.             oddrun++;
  1680.             oddbyte = c;
  1681.             } else {
  1682.             oddmax = oddrun;
  1683.             oddmaxbyte = oddbyte;
  1684.             }
  1685.         } else {        /* and even positions */
  1686.             if (c == buf[i-2]) {
  1687.             evenrun++;
  1688.             evenbyte = c;
  1689.             } else {
  1690.             evenmax = evenrun;
  1691.             evenmaxbyte = evenbyte;
  1692.             }
  1693.         }
  1694.         }
  1695. #endif /* EVENMAX */
  1696. #endif /* COMMENT */
  1697.  
  1698.         if ((c & 0x80) == 0) {    /* We have a 7-bit byte */
  1699. #ifdef UNICODE
  1700.         if (i > 0 && c == 10) { /* Linefeed */
  1701.             if (buf[i-1] == 0) lfnul++; /* Preceded by NUL */
  1702.             else if (buf[i-1] == 13) crlf++; /* or by CR... */
  1703.         }
  1704. #endif /* UNICODE */
  1705.         if (c < ' ') {        /* Check for CO controls */
  1706.             if (c != LF && c != CR && c != HT && c != FF) {
  1707.             c0controls++;
  1708.             if (c != ESC && c != SO && c != SI)
  1709.               c0noniso++;
  1710.             }
  1711.             if ((c == '\032')    /* Ctrl-Z */
  1712. #ifdef COMMENT
  1713.             && eof && (i >= count - 2)
  1714. #endif /* COMMENT */
  1715.             ) {
  1716.             c0controls--;
  1717.             c0noniso--;
  1718. #ifdef CK_CTRLZ
  1719.             if (eofmethod == XYEOF_Z && txtcz == 0) {
  1720.                 if (c0controls == 0) /* All text prior to Ctrl-Z */
  1721.                   txtcz = 1;
  1722.             }
  1723. #endif /* CK_CTRLZ */
  1724.             }
  1725.         }
  1726. #ifdef UNICODE
  1727.         if (!notutf8 && utf8state) { /* In UTF-8 sequence? */
  1728.             utf8state = 0;
  1729.             debug(F000,"scanfile","7-bit byte in UTF8 sequence",c);
  1730.             notutf8++;        /* Then it's not UTF-8 */
  1731.             continue;
  1732.         }
  1733. #endif /* UNICODE */
  1734.         } else {            /* We have an 8-bit byte */
  1735.         eightbit++;        /* Count it */
  1736.         if (c >= 0x80 && c < 0xA0) /* Check for C1 controls */
  1737.           c1controls++;
  1738. #ifdef UNICODE
  1739.         if (!notutf8) {        /* If it might still be UTF8... */
  1740.             switch (utf8state) { /* Enter the UTF-8 state machine */
  1741.               case 0:         /* First byte... */
  1742.             if ((c & 0xE0) == 0xC0) { /* Tells number of */
  1743.                 utf8state = 1;        /* subsequent bytes */
  1744.             } else if ((c & 0xF0) == 0xE0) {
  1745.                 utf8state = 2;
  1746.             } else if ((c & 0xF8) == 0xF0) {
  1747.                 utf8state = 3;
  1748.             } else {
  1749.                 notutf8++;
  1750.             }
  1751.             break;
  1752.               case 1:        /* Subsequent byte */
  1753.               case 2:
  1754.               case 3:
  1755.             if ((c & 0xC0) != 0x80) { /* Must start with 10 */
  1756.                 debug(F000,"scanfile",
  1757.                   "bad byte in UTF8 sequence",c);
  1758.                 notutf8++;
  1759.                 break;
  1760.             }
  1761.             utf8state--;    /* Good, one less in this sequence */
  1762.             break;
  1763.               default:        /* Shouldn't happen */
  1764.             debug(F111,"scanfile","bad UTF8 state",utf8state);
  1765.             notutf8++;
  1766.             }
  1767.         }
  1768. #endif /* UNICODE */
  1769.         }
  1770.     }
  1771.     }
  1772.     fclose(fp);                /* Close the file */
  1773.     debug(F101,"scanfile bytes","",bytes);
  1774.  
  1775.     if (bytes == 0)            /* If nothing was read */
  1776.       return(-1);            /* we're done. */
  1777.  
  1778. #ifdef EVENMAX
  1779.     /* In case we had a run that never broke... */
  1780. #ifdef COMMENT
  1781.     if (oddmax == 0) {
  1782.     oddmax = oddrun;
  1783.     oddmaxbyte = oddbyte;
  1784.     }
  1785.     if (evenmax == 0) {
  1786.     evenmax = evenrun;
  1787.     evenmaxbyte = evenbyte;
  1788.     }
  1789. #endif /* COMMENT */
  1790.     if (runmax == 0) {
  1791.     runmax = runzero;
  1792.     }
  1793. #endif /* EVENMAX */
  1794.  
  1795. #ifdef UNICODE
  1796.     if (bytes > 100)            /* Bytes is not 0 */
  1797.       pctzero = (evenzero + oddzero) / (bytes / 100);
  1798.     else
  1799.       pctzero = ((evenzero + oddzero) * 100) / bytes;
  1800. #endif /* UNICODE */
  1801.  
  1802. #ifdef DEBUG
  1803.     if (deblog) {            /* If debugging, dump statistics */
  1804.     debug(F101,"scanfile c0controls ","",c0controls);
  1805.     debug(F101,"scanfile c0noniso   ","",c0noniso);
  1806.     debug(F101,"scanfile c1controls ","",c1controls);
  1807.     debug(F101,"scanfile eightbit   ","",eightbit);
  1808. #ifdef UNICODE
  1809.     debug(F101,"scanfile crlf       ","",crlf);
  1810.     debug(F101,"scanfile lfnul      ","",lfnul);
  1811.     debug(F101,"scanfile notutf8    ","",notutf8);
  1812.     debug(F101,"scanfile evenzero   ","",evenzero);
  1813.     debug(F101,"scanfile oddzero    ","",oddzero);
  1814.     debug(F101,"scanfile even/odd   ","",(evenzero / (oddzero + 1)));
  1815.     debug(F101,"scanfile odd/even   ","",(oddzero / (evenzero + 1)));
  1816.     debug(F101,"scanfile pctzero    ","",pctzero);
  1817. #endif /* UNICODE */
  1818. #ifdef COMMENT
  1819. #ifdef EVENMAX
  1820.     debug(F101,"scanfile oddmax     ","",oddmax);
  1821.     debug(F101,"scanfile oddmaxbyte ","",oddmaxbyte);
  1822.     debug(F101,"scanfile evenmax    ","",evenmax);
  1823.     debug(F101,"scanfile evenmaxbyte","",evenmaxbyte);
  1824. #endif /* EVENMAX */
  1825. #endif /* COMMENT */
  1826.     debug(F101,"scanfile runmax     ","",runmax);
  1827.     }
  1828. #endif /* DEBUG */
  1829.  
  1830. #ifdef UNICODE
  1831.     x = eightbit ? bytes / 20 : bytes / 4; /* For UCS-2... */
  1832.  
  1833.     if (runmax > 2) {            /* File has run of more than 2 NULs */
  1834.     debug(F100,"scanfile BIN runmax","",0);
  1835.     rc = FT_BIN;            /* so it can't be any kind of text. */
  1836.     goto xscanfile;
  1837.  
  1838.     } else if (rc == FT_UCS2 || (rc == FT_UTF8 && runmax == 0)) {
  1839.     goto xscanfile;            /* File starts with a BOM */
  1840.  
  1841.     } else if (eightbit > 0 && !notutf8) { /* File has 8-bit data */
  1842.     if (runmax > 0) {           /* and runs of NULs */
  1843.         debug(F100,"scanfile BIN (nnUTF8) runmax","",0);
  1844.         rc = FT_BIN;           /* UTF-8 doesn't have NULs */
  1845.     } else {               /* No NULs */
  1846.         debug(F100,"scanfile UTF8 (nnUTF8 + runmax == 0)","",0);
  1847.         rc = FT_UTF8;           /* and not not UTF-8, so is UTF-8 */
  1848.     }
  1849.     goto xscanfile;
  1850.     }
  1851. /*
  1852.   For UCS-2 detection, see if the text contains lines delimited by
  1853.   ASCII controls and containing spaces, ASCII digits, or other ASCII
  1854.   characters, thus forcing the presence of a certain percentage of zero bytes.
  1855.   For this purpose require 20% zero bytes, with at least six times as many
  1856.   in even (odd) positions as in odd (even) positions.
  1857. */
  1858.     if ((evenzero >= x && oddzero == 0) ||
  1859.     ((((evenzero / (oddzero + 1)) > 6) && (pctzero > 20)) &&
  1860.     (crlf == 0) &&
  1861.     (lfnul > 1))
  1862.     ) {
  1863.         debug(F100,"scanfile UCS2 noBOM BE (even/oddzero)","",0);
  1864.     rc = FT_UCS2;
  1865.     val = 0;
  1866.     } else if ((evenzero == 0 && oddzero >= x) ||
  1867.            ((((oddzero / (evenzero + 1)) > 6) && (pctzero > 20)) &&
  1868.            (crlf == 0) &&
  1869.            (lfnul > 1))
  1870.            ) {
  1871.     debug(F100,"scanfile UCS2 noBOM LE (even/oddzero)","",0);
  1872.     rc = FT_UCS2;
  1873.     val = 1;
  1874.  
  1875. #ifdef COMMENT
  1876. #ifdef EVENMAX
  1877. /*
  1878.   If the tests above fail, we still might have UCS-2 if there are significant
  1879.   runs of identical bytes in alternating positions, but only if it also has
  1880.   unusual C0 controls (otherwise we'd pick up hex files here).  NOTE: We
  1881.   don't actually do this -- EVENMAX is not defined (see comments above at
  1882.   first occurrence of EVENMAX).
  1883. */
  1884.     } else if (c0noniso && evenmax > bytes / 4) {
  1885.     debug(F100,"scanfile UCS2 BE (evenmax)","",0);
  1886.     rc = FT_UCS2;
  1887.     val = 0;
  1888.     } else if (c0noniso && oddmax > bytes / 4) {
  1889.     debug(F100,"scanfile UCS2 LE (evenmax)","",0);
  1890.     rc = FT_UCS2;
  1891.     val = 1;
  1892. #endif /* EVENMAX */
  1893. #endif /* COMMENT */
  1894.  
  1895.     }
  1896. /*
  1897.   It seems to be UCS-2 but let's be more certain since there is no BOM...
  1898.   If the number of 7- and 8-bit characters is approximately equal, it might
  1899.   be a compressed file.  In this case we decide based on the name.
  1900. */
  1901.     if (rc == FT_UCS2) {
  1902.     if (eightbit > 0) {
  1903.         int j, k;
  1904.         j = (c1controls * 100) / (c0controls + 1);
  1905.         debug(F101,"scanfile c1/c0      ","",j);
  1906.         k = (bytes * 100) / eightbit;
  1907.         debug(F101,"scanfile pct 8bit   ","",k);
  1908.         if (k > 40 && k < 60 && j > 60) {
  1909.         if (ckmatch("{*.Z,*.gz,*.zip,*.ZIP}",name,1,1)) {
  1910.             debug(F110,"scanfile 8-bit BIN compressed",name,0);
  1911.             rc = FT_BIN;
  1912.             goto xscanfile;
  1913.         }
  1914.         }
  1915.     }
  1916.     /* Small file - not enough evidence unless ... */
  1917.  
  1918.     if (bytes < 100) {
  1919.         if (oddzero != 0 && evenzero != 0) {
  1920.         debug(F100,"scanfile small UCS2 doubtful","",0);
  1921.         rc = FT_BIN;
  1922.         goto xscanfile;
  1923.         } else if (oddzero == 0 && evenzero == 0) {
  1924.         rc = eightbit ? FT_8BIT : FT_7BIT;
  1925.         }
  1926.     }
  1927.     goto xscanfile;            /* Seems to be UCS-2 */
  1928.     }
  1929.  
  1930. /* If none of the above, it's probably not Unicode.  */
  1931.  
  1932.     if (!eightbit) {            /* It's 7-bit */
  1933.     if (c0controls) {        /* This would be strange */
  1934.         if ((c0noniso > 0) && (txtcz == 0)) {
  1935.         debug(F100,"scanfile 7-bit BIN (c0coniso)","",0);
  1936.         rc = FT_BIN;
  1937.         } else {
  1938.         debug(F100,"scanfile 7-bit ISO2022 TEXT (no c0noniso)","",0);
  1939.         rc = FT_7BIT;
  1940.         }
  1941.     } else {            /* 7-bit text */
  1942.         debug(F100,"scanfile 7-bit TEXT (no c0controls)","",0);
  1943.         rc = FT_7BIT;
  1944.     }
  1945.     } else if (!c0noniso || txtcz) {    /* 8-bit text */
  1946.     debug(F100,"scanfile 8-bit TEXT (no c0noniso)","",0);
  1947.     rc = FT_8BIT;
  1948.     val = c1controls ? 1 : 0;
  1949.     } else {                /* 8-bit binary */
  1950.     debug(F100,"scanfile 8-bit BIN (c0noniso)","",0);
  1951.     rc = FT_BIN;
  1952.     }
  1953.  
  1954. #else  /* !UNICODE */
  1955.  
  1956.     if (c0noniso) {
  1957.     debug(F100,"scanfile 8-bit BIN (c0noniso)","",0);
  1958.     rc = FT_BIN;
  1959.     } else if (eightbit) {
  1960.     debug(F100,"scanfile 8-bit TEXT (no c0noniso)","",0);
  1961.     rc = FT_8BIT;
  1962.     val = c1controls ? 1 : 0;
  1963.     } else {
  1964.     debug(F100,"scanfile 7-bit TEXT (no c0noniso)","",0);
  1965.     rc = FT_7BIT;
  1966.     }
  1967.  
  1968. #endif /* UNICODE */
  1969.  
  1970.   xscanfile:
  1971.     if (flag) *flag = val;
  1972.     debug(F101,"scanfile result     ","",rc);
  1973.     return(rc);
  1974. }
  1975.  
  1976. /*  F I L E S E L E C T  --  Select this file for sending  */
  1977.  
  1978. int
  1979. #ifdef CK_ANSIC
  1980. fileselect(
  1981.     char *f, char *sa, char *sb, char *sna, char *snb,
  1982.     CK_OFF_T minsiz, CK_OFF_T maxsiz,
  1983.     int nbu, int nxlist,
  1984.     char ** xlist
  1985. )
  1986. #else
  1987. fileselect(f,sa,sb,sna,snb,minsiz,maxsiz,nbu,nxlist,xlist)
  1988.  char *f,*sa,*sb,*sna,*snb; CK_OFF_T minsiz,maxsiz;
  1989.  int nbu,nxlist; char ** xlist;
  1990. #endif /* CK_ANSIC */
  1991. /* fileselect */ {
  1992.     char *fdate;
  1993.     int n;
  1994.     CK_OFF_T z;
  1995.  
  1996.     debug(F111,"fileselect minsiz",ckfstoa(minsiz),minsiz);
  1997.     debug(F111,"fileselect maxsiz",ckfstoa(maxsiz),maxsiz);
  1998.     debug(F111,"fileselect (CK_OFF_T)-1",ckfstoa((CK_OFF_T)-1),(CK_OFF_T)-1);
  1999.  
  2000.     if (!sa) sa = "";
  2001.     if (!sb) sb = "";
  2002.     if (!sna) sna = "";
  2003.     if (!snb) snb = "";
  2004.  
  2005. #ifdef CKSYMLINK
  2006. #ifndef NOICP
  2007. #ifndef NOXFER
  2008.     if (nolinks) {
  2009.     CK_OFF_T zz;
  2010.     zz = zgetfs(f);
  2011.     debug(F111,"fileselect NOLINKS zgetfs",f,zz);
  2012.     if (zz < (CK_OFF_T)0)
  2013.       return(0);
  2014.     debug(F111,"fileselect NOLINKS zgfs_link",f,zgfs_link);
  2015.     if (zgfs_link)
  2016.       return(0);
  2017.     }
  2018. #endif /* NOXFER */
  2019. #endif /* NOICP */
  2020. #endif /* CKSYMLINK */
  2021.  
  2022.     debug(F110,"fileselect",f,0);
  2023.     if (*sa || *sb || *sna || *snb) {
  2024.     fdate = zfcdat(f);        /* Date/time of this file */
  2025.     if (!fdate) fdate = "";
  2026.     n = strlen(fdate);
  2027.     debug(F111,"fileselect fdate",fdate,n);
  2028.     if (n != 17)            /* Failed to get it */
  2029.       return(1);
  2030.     /* /AFTER: */
  2031.     if (sa[0] && (strcmp(fdate,(char *)sa) <= 0)) {
  2032.         debug(F110,"fileselect sa",sa,0);
  2033.         /* tlog(F110,"Skipping (too old)",f,0); */
  2034.         return(0);
  2035.     }
  2036.     /* /BEFORE: */
  2037.     if (sb[0] && (strcmp(fdate,(char *)sb) >= 0)) {
  2038.         debug(F110,"fileselect sb",sb,0);
  2039.         /* tlog(F110,"Skipping (too new)",f,0); */
  2040.         return(0);
  2041.     }
  2042.     /* /NOT-AFTER: */
  2043.     if (sna[0] && (strcmp(fdate,(char *)sna) > 0)) {
  2044.         debug(F110,"fileselect sna",sna,0);
  2045.         /* tlog(F110,"Skipping (too new)",f,0); */
  2046.         return(0);
  2047.     }
  2048.     /* /NOT-BEFORE: */
  2049.     if (snb[0] && (strcmp(fdate,(char *)snb) < 0)) {
  2050.         debug(F110,"fileselect snb",snb,0);
  2051.         /* tlog(F110,"Skipping (too old)",f,0); */
  2052.         return(0);
  2053.     }
  2054.     }
  2055.     /* Smaller or larger */
  2056.     if (minsiz > (CK_OFF_T)-1 || maxsiz > (CK_OFF_T)-1) {
  2057.     z = zchki(f);            /* Get size */
  2058.     debug(F101,"fileselect filesize","",z);
  2059.     if (z < (CK_OFF_T)0)
  2060.       return(1);
  2061.     if ((minsiz > (CK_OFF_T)-1) && (z >= minsiz)) {
  2062.         debug(F111,"fileselect minsiz skipping",f,minsiz);
  2063.         /* tlog(F111,"Skipping (too big)",f,z); */
  2064.         return(0);
  2065.     }
  2066.     if ((maxsiz > (CK_OFF_T)-1) && (z <= maxsiz)) {
  2067.         debug(F111,"fileselect maxsiz skipping",f,maxsiz);
  2068.         /* tlog(F110,"Skipping (too small)",f,0); */
  2069.         return(0);
  2070.     }
  2071.     }
  2072.     if (nbu) {                /* Skipping backup files? */
  2073.     if (ckmatch(
  2074. #ifdef CKREGEX
  2075.             "*.~[0-9]*~"    /* Not perfect but close enough. */
  2076. #else
  2077.             "*.~*~"        /* Less close. */
  2078. #endif /* CKREGEX */
  2079.             ,f,filecase,1)) {
  2080.         debug(F110,"fileselect skipping backup",f,0);
  2081.         return(0);
  2082.     }
  2083.     }
  2084.     for (n = 0; xlist && n < nxlist; n++) {
  2085.     if (!xlist[n]) {
  2086.         debug(F101,"fileselect xlist empty",0,n);
  2087.         break;
  2088.     }
  2089.     if (ckmatch(xlist[n],f,filecase,1)) {
  2090.         debug(F111,"fileselect xlist",xlist[n],n);
  2091.         debug(F110,"fileselect skipping",f,0);
  2092.         return(0);
  2093.     }
  2094.     }
  2095.     if (xfiletype > -1) {
  2096.     n = scanfile(f,NULL,nscanfile);
  2097.     if (n < 0) {
  2098.         n = binary ? 1 : 0;
  2099.     } else {
  2100.         n = (n == FT_BIN) ? 1 : 0;
  2101.     }
  2102.     if (n != xfiletype)
  2103.       return(0);
  2104.     }
  2105.     debug(F110,"fileselect selecting",f,0);
  2106.     return(1);
  2107. }
  2108.  
  2109.  
  2110. #ifdef TCPSOCKET
  2111. #ifdef NT
  2112. extern int WSASafeToCancel;
  2113. #endif /* NT */
  2114. #endif /* TCPSOCKET */
  2115.  
  2116. VOID
  2117. setflow() {
  2118.     extern int flow, autoflow, mdmtyp, cxtype, cxflow[];
  2119. #ifndef NODIAL
  2120.     extern int dialcapas, dialfc;
  2121.     extern MDMINF * modemp[];
  2122.     MDMINF * p = NULL;
  2123.     long bits = 0;
  2124. #endif /* NODIAL */
  2125.  
  2126.     debug(F101,"setflow autoflow","",autoflow);
  2127.  
  2128. /* #ifdef COMMENT */
  2129. /* WHY WAS THIS COMMENTED OUT? */
  2130.     if (!autoflow)                      /* Only if FLOW is AUTO */
  2131.       return;
  2132. /* #endif */ /* COMMENT */
  2133.  
  2134.     debug(F101,"setflow local","",local);
  2135.     debug(F101,"setflow network","",network);
  2136.     debug(F101,"setflow cxtype","",cxtype);
  2137.  
  2138. #ifdef TN_COMPORT
  2139.     if (network && istncomport()) {
  2140.     flow = cxflow[CXT_MODEM];
  2141.         debug(F101,"setflow TN_COMPORT flow","",flow);
  2142.         return;
  2143.     }
  2144. #endif /* TN_COMPORT */
  2145.  
  2146.     if (network || !local || cxtype == CXT_DIRECT) {
  2147.         flow = cxflow[cxtype];          /* Set appropriate flow control */
  2148.         debug(F101,"setflow flow","",flow);
  2149.         return;
  2150.     }
  2151.     if (cxtype != CXT_MODEM)            /* Connection type should be modem */
  2152.       return;
  2153.  
  2154. #ifndef NODIAL
  2155.     bits = dialcapas;                   /* Capability bits */
  2156.     if (!bits) {                        /* No bits? */
  2157.         p = modemp[mdmtyp];             /* Look in modem info structure */
  2158.         if (p)
  2159.           bits = p->capas;
  2160.     }
  2161.     if (dialfc == FLO_AUTO) {           /* If DIAL flow is AUTO */
  2162. #ifdef CK_RTSCTS                        /* If we can do RTS/CTS flow control */
  2163.         if (bits & CKD_HW)              /* and modem can do it too */
  2164.           flow = FLO_RTSC;              /* then switch to RTS/CTS */
  2165.         else                            /* otherwise */
  2166.           flow = FLO_XONX;              /* use Xon/Xoff. */
  2167. #else
  2168. #ifndef NEXT
  2169. #ifndef IRIX
  2170.         flow = FLO_XONX;                /* Use Xon/Xoff. */
  2171. #endif /* IRIX */
  2172. #endif /* NEXT */
  2173. #endif /* CK_RTSCTS */
  2174.     }
  2175. #endif /* NODIAL */
  2176.     debug(F101,"setflow modem flow","",flow);
  2177.     return;
  2178. }
  2179.  
  2180. #ifndef NOLOCAL
  2181. #ifdef CK_TRIGGER
  2182.  
  2183. /*  A U T O E X I T C H K  --  Check for CONNECT-mode trigger string  */
  2184. /*
  2185.   Returns -1 if trigger not found, or else the trigger index, 0 or greater.
  2186.   (Replace with fancier and more efficient matcher later...)
  2187.   NOTE: to prevent unnecessary function call overhead, call this way:
  2188.  
  2189.     x = tt_trigger[0] ? autoexitchk(c) : -1;
  2190.  
  2191. */
  2192. int
  2193. #ifdef CK_ANSIC
  2194. autoexitchk(CHAR c)
  2195. #else
  2196. autoexitchk(c) CHAR c;
  2197. #endif /* CK_ANSIC */
  2198. /* autoexitchk */ {
  2199.     extern CHAR * tt_trmatch[];
  2200.     extern char * tt_trigger[];
  2201.     int i;
  2202.     for (i = 0; i < TRIGGERS; i++) {
  2203.         if (!tt_trigger[i]) {           /* No more triggers in list */
  2204.             break;
  2205.         } else if (*tt_trigger[i]) {
  2206.             if (!tt_trmatch[i])         /* Just starting? */
  2207.               tt_trmatch[i] = (CHAR *)tt_trigger[i]; /* Set match pointer */
  2208.             if (c == *tt_trmatch[i]) {  /* Compare this character */
  2209.                 tt_trmatch[i]++;        /* It matches */
  2210.                 if (!*tt_trmatch[i]) {  /* End of match string? */
  2211.                     tt_trmatch[i] = (CHAR *) tt_trigger[i]; /* Yes, rewind, */
  2212.                     debug(F101,"autoexitchk",tt_trigger[i],i); /* log, */
  2213.                     return(i);          /* and return success */
  2214.                 }
  2215.             } else                      /* No match */
  2216.               tt_trmatch[i] = (CHAR *) tt_trigger[i]; /* Rewind match string */
  2217.         } /* and go on the next match string */
  2218.     }
  2219.     return(-1);                         /* No match found */
  2220. }
  2221. #endif /* CK_TRIGGER */
  2222.  
  2223. #ifndef NOSHOW
  2224. /*  S H O M D M  --  Show modem signals  */
  2225.  
  2226. VOID
  2227. shomdm() {
  2228. /*
  2229.   Note use of "\r\n" to make sure this report prints right, even when
  2230.   called during CONNECT mode.
  2231. */
  2232.     int y;
  2233.     y = ttgmdm();
  2234.     switch (y) {
  2235.       case -3: printf(
  2236.                  "Modem signals unavailable in this version of Kermit\r\n");
  2237.                break;
  2238.       case -2: printf("No modem control for this device\r\n"); break;
  2239.       case -1: printf("Modem signals unavailable\r\n"); break;
  2240.       default:
  2241. #ifndef MAC
  2242.         printf(
  2243.           " Carrier Detect      (CD):  %s\r\n",(y & BM_DCD) ? "On": "Off");
  2244.         printf(
  2245.           " Dataset Ready       (DSR): %s\r\n",(y & BM_DSR) ? "On": "Off");
  2246. #endif /* MAC */
  2247.         printf(
  2248.           " Clear To Send       (CTS): %s\r\n",(y & BM_CTS) ? "On": "Off");
  2249. #ifndef STRATUS
  2250. #ifndef MAC
  2251.         printf(
  2252.           " Ring Indicator      (RI):  %s\r\n",(y & BM_RNG) ? "On": "Off");
  2253. #endif /* MAC */
  2254.         printf(
  2255.           " Data Terminal Ready (DTR): %s\r\n",
  2256. #ifdef NT
  2257.           "(unknown)"
  2258. #else /* NT */
  2259.           (y & BM_DTR) ? "On": "Off"
  2260. #endif /* NT */
  2261.           );
  2262. #ifndef MAC
  2263.         printf(
  2264.           " Request To Send     (RTS): %s\r\n",
  2265. #ifdef NT
  2266.           "(unknown)"
  2267. #else /* NT */
  2268.           (y & BM_RTS) ? "On": "Off"
  2269. #endif /* NT */
  2270.           );
  2271. #endif /* MAC */
  2272. #endif /* STRATUS */
  2273.     }
  2274. #ifdef BETADEBUG
  2275. #ifdef CK_TAPI
  2276.     if (tttapi && !tapipass) {
  2277.         LPDEVCFG        lpDevCfg = NULL;
  2278.         LPCOMMCONFIG    lpCommConfig = NULL;
  2279.         LPMODEMSETTINGS lpModemSettings = NULL;
  2280.         DCB *           lpDCB = NULL;
  2281.  
  2282.         if (cktapiGetModemSettings(&lpDevCfg,&lpModemSettings,
  2283.                                     &lpCommConfig,&lpDCB)) {
  2284.             printf("\n");
  2285.             cktapiDisplayModemSettings(lpDevCfg,lpModemSettings,
  2286.                                        lpCommConfig,lpDCB);
  2287.         }
  2288.     }
  2289. #endif /* CK_TAPI */
  2290. #endif /* BETADEBUG */
  2291. }
  2292. #endif /* NOSHOW */
  2293. #endif /* NOLOCAL */
  2294.  
  2295. #ifndef NOXFER
  2296. /*  S D E B U  -- Record spar results in debugging log  */
  2297.  
  2298. VOID
  2299. sdebu(len) int len; {
  2300.     debug(F111,"spar: data",(char *) rdatap,len);
  2301.     debug(F101," spsiz ","", spsiz);
  2302.     debug(F101," timint","",timint);
  2303.     debug(F101," npad  ","",  npad);
  2304.     debug(F101," padch ","", padch);
  2305.     debug(F101," seol  ","",  seol);
  2306.     debug(F101," ctlq  ","",  ctlq);
  2307.     debug(F101," ebq   ","",   ebq);
  2308.     debug(F101," ebqflg","",ebqflg);
  2309.     debug(F101," bctr  ","",  bctr);
  2310.     debug(F101," rptq  ","",  rptq);
  2311.     debug(F101," rptflg","",rptflg);
  2312.     debug(F101," lscapu","",lscapu);
  2313.     debug(F101," atcapu","",atcapu);
  2314.     debug(F101," lpcapu","",lpcapu);
  2315.     debug(F101," swcapu","",swcapu);
  2316.     debug(F101," wslotn","", wslotn);
  2317.     debug(F101," whatru","", whatru);
  2318. }
  2319. /*  R D E B U -- Debugging display of rpar() values  */
  2320.  
  2321. VOID
  2322. rdebu(d,len) CHAR *d; int len; {
  2323.     debug(F111,"rpar: data",d,len);
  2324.     debug(F101," rpsiz ","", xunchar(d[0]));
  2325.     debug(F101," rtimo ","", rtimo);
  2326.     debug(F101," mypadn","",mypadn);
  2327.     debug(F101," mypadc","",mypadc);
  2328.     debug(F101," eol   ","",   eol);
  2329.     debug(F101," ctlq  ","",  ctlq);
  2330.     debug(F101," sq    ","",    sq);
  2331.     debug(F101," ebq   ","",   ebq);
  2332.     debug(F101," ebqflg","",ebqflg);
  2333.     debug(F101," bctr  ","",  bctr);
  2334.     debug(F101," rptq  ","",  d[8]);
  2335.     debug(F101," rptflg","",rptflg);
  2336.     debug(F101," capas ","", capas);
  2337.     debug(F101," bits  ","",d[capas]);
  2338.     debug(F101," lscapu","",lscapu);
  2339.     debug(F101," atcapu","",atcapu);
  2340.     debug(F101," lpcapu","",lpcapu);
  2341.     debug(F101," swcapu","",swcapu);
  2342.     debug(F101," wslotr","", wslotr);
  2343.     debug(F101," rpsiz(extended)","",rpsiz);
  2344. }
  2345.  
  2346. #ifdef COMMENT
  2347. /*  C H K E R R  --  Decide whether to exit upon a protocol error  */
  2348.  
  2349. VOID
  2350. chkerr() {
  2351.     if (backgrd && !server) fatal("Protocol error");
  2352. }
  2353. #endif /* COMMENT */
  2354. #endif /* NOXFER */
  2355.  
  2356. /*  F A T A L  --  Fatal error message */
  2357.  
  2358. VOID
  2359. fatal(msg) char *msg; {
  2360.     extern int initflg;
  2361.     static int initing = 0;
  2362.     if (!msg) msg = "";
  2363.     debug(F111,"fatal",msg,initflg);
  2364.  
  2365.     if (!initflg) {            /* If called from prescan */
  2366.     if (initing)            /* or called from sysinit() */
  2367.           exit(253);
  2368.     initing = 1;
  2369.     sysinit();
  2370.     }
  2371.  
  2372.     debug(F111,"fatal",msg,xitsta);
  2373.     tlog(F110,"Fatal:",msg,0L);
  2374. #ifdef VMS
  2375.     if (strncmp(msg,"%CKERMIT",8))
  2376.       conol("%CKERMIT-E-FATAL, ");
  2377.     conoll(msg);
  2378. #else /* !VMS */
  2379.     conoll(msg);
  2380. #endif /* VMS */
  2381. #ifdef OS2
  2382. #ifndef NOXFER
  2383.     if (xfrbel) {
  2384.         bleep(BP_FAIL);
  2385.         sleep(1);
  2386.         bleep(BP_FAIL);
  2387.     }
  2388. #endif /* NOXFER */
  2389.  
  2390. #endif /* OS2 */
  2391.     doexit(BAD_EXIT,xitsta | 1);        /* Exit indicating failure */
  2392. }
  2393.  
  2394. #ifndef NOXFER
  2395. /*  B L D L E N  --  Make length-encoded copy of string  */
  2396.  
  2397. char *
  2398. bldlen(str,dest) char *str, *dest; {
  2399.     int len;
  2400.     len = (int)strlen(str);
  2401.     if (len > 94)
  2402.       *dest = SP;
  2403.     else
  2404.       *dest = (char) tochar(len);
  2405.     strcpy(dest+1,str);            /* Checked below in setgen() */
  2406.     return(dest+len+1);
  2407. }
  2408.  
  2409.  
  2410. /*  S E T G E N  --  Construct a generic command  */
  2411. /*
  2412.   Call with Generic command character followed by three string arguments.
  2413.   Trailing strings are allowed to be empty ("").  Each string except the last
  2414.   non-empty string must be less than 95 characters long.  The final nonempty
  2415.   string is allowed to be longer.
  2416. */
  2417. CHAR
  2418. #ifdef CK_ANSIC
  2419. setgen(char type, char * arg1, char * arg2, char * arg3)
  2420. #else
  2421. setgen(type,arg1,arg2,arg3) char type, *arg1, *arg2, *arg3;
  2422. #endif /* CK_ANSIC */
  2423. /* setgen */ {
  2424.     char *upstr, *cp;
  2425. #ifdef DYNAMIC
  2426.     if (!cmdstr)
  2427.       if (!(cmdstr = malloc(MAXSP + 1)))
  2428.         fatal("setgen: can't allocate memory");
  2429. #endif /* DYNAMIC */
  2430.  
  2431.     cp = cmdstr;
  2432.     *cp++ = type;
  2433.     *cp = NUL;
  2434.     if (!arg1) arg1 = "";
  2435.     if (!arg2) arg2 = "";
  2436.     if (!arg3) arg3 = "";
  2437.     if (((int)strlen(arg1)+(int)strlen(arg2)+(int)strlen(arg3)+4) < MAXSP) {
  2438.     if (*arg1 != NUL) {
  2439.         upstr = bldlen(arg1,cp);
  2440.         if (*arg2 != NUL) {
  2441.         upstr = bldlen(arg2,upstr);
  2442.         if (*arg3 != NUL) bldlen(arg3,upstr);
  2443.         }
  2444.     }
  2445.     cmarg = cmdstr;
  2446.     debug(F110,"setgen",cmarg,0);
  2447.     return('g');
  2448.     }
  2449.     return('E');
  2450. }
  2451. #endif /* NOXFER */
  2452.  
  2453. #ifndef NOMSEND
  2454. static char *mgbufp = NULL;
  2455.  
  2456. /*  F N P A R S E  --  */
  2457.  
  2458. /*
  2459.   Argument is a character string containing one or more filespecs.
  2460.   This function breaks the string apart into an array of pointers, one
  2461.   to each filespec, and returns the number of filespecs.  Used by server
  2462.   when it receives a GET command to allow it to process multiple file
  2463.   specifications in one transaction.  Sets cmlist to point to a list of
  2464.   file pointers, exactly as if they were command line arguments.
  2465.  
  2466.   This version of fnparse treats spaces as filename separators.  If your
  2467.   operating system allows spaces in filenames, you'll need a different
  2468.   separator.
  2469.  
  2470.   This version of fnparse mallocs a string buffer to contain the names.  It
  2471.   cannot assume that the string that is pointed to by the argument is safe.
  2472. */
  2473. int
  2474. fnparse(string) char *string; {
  2475.     char *p, *s, *q;
  2476.     int r = 0, x;                       /* Return code */
  2477. #ifdef RECURSIVE
  2478.     debug(F111,"fnparse",string,recursive);
  2479. #endif /* RECURSIVE */
  2480.  
  2481.     if (mgbufp) free(mgbufp);           /* Free this from last time. */
  2482.     mgbufp = malloc((int)strlen(string)+2);
  2483.     if (!mgbufp) {
  2484.         debug(F100,"fnparse malloc error","",0);
  2485.         return(0);
  2486.     }
  2487. #ifndef NOICP
  2488. #ifndef NOSPL
  2489.     ckstrncpy(fspec,string,fspeclen);   /* Make copy for \v(filespec) */
  2490. #endif /* NOSPL */
  2491. #endif /* NOICP */
  2492.     s = string;                         /* Input string */
  2493.     p = q = mgbufp;                     /* Point to the copy */
  2494.     r = 0;                              /* Initialize our return code */
  2495.     while (*s == SP || *s == HT)        /* Skip leading spaces and tabs */
  2496.       s++;
  2497.     for (x = strlen(s);                 /* Strip trailing spaces */
  2498.          (x > 1) && (s[x-1] == SP || s[x-1] == HT);
  2499.          x--)
  2500.       s[x-1] = NUL;
  2501.     while (1) {                         /* Loop through rest of string */
  2502.         if (*s == CMDQ) {               /* Backslash (quote character)? */
  2503.             if ((x = xxesc(&s)) > -1) { /* Go interpret it. */
  2504.                 *q++ = (char) x;        /* Numeric backslash code, ok */
  2505.             } else {                    /* Just let it quote next char */
  2506.                 s++;                    /* get past the backslash */
  2507.                 *q++ = *s++;            /* deposit next char */
  2508.             }
  2509.             continue;
  2510.         } else if (*s == SP || *s == NUL) { /* Unquoted space or NUL? */
  2511.             *q++ = NUL;                 /* End of output filename. */
  2512.             msfiles[r] = p;             /* Add this filename to the list */
  2513.             debug(F111,"fnparse",msfiles[r],r);
  2514.             r++;                        /* Count it */
  2515.             if (*s == NUL) break;       /* End of string? */
  2516.             while (*s == SP) s++;       /* Skip repeated spaces */
  2517.             p = q;                      /* Start of next name */
  2518.             continue;
  2519.         } else *q++ = *s;               /* Otherwise copy the character */
  2520.         s++;                            /* Next input character */
  2521.     }
  2522.     debug(F101,"fnparse r","",r);
  2523.     msfiles[r] = "";                    /* Put empty string at end of list */
  2524.     cmlist = msfiles;
  2525.     return(r);
  2526. }
  2527. #endif /* NOMSEND */
  2528.  
  2529. char *                                  /* dbchr() for DEBUG SESSION */
  2530. dbchr(c) int c; {
  2531.     static char s[8];
  2532.     char *cp = s;
  2533.  
  2534.     c &= 0xff;
  2535.     if (c & 0x80) {                     /* 8th bit on */
  2536.         *cp++ = '~';
  2537.         c &= 0x7f;
  2538.     }
  2539.     if (c < SP) {                       /* Control character */
  2540.         *cp++ = '^';
  2541.         *cp++ = (char) ctl(c);
  2542.     } else if (c == DEL) {
  2543.         *cp++ = '^';
  2544.         *cp++ = '?';
  2545.     } else {                            /* Printing character */
  2546.         *cp++ = (char) c;
  2547.     }
  2548.     *cp = '\0';                         /* Terminate string */
  2549.     cp = s;                             /* Return pointer to it */
  2550.     return(cp);
  2551. }
  2552.  
  2553. /*  C K H O S T  --  Get name of local host (where C-Kermit is running)  */
  2554.  
  2555. /*
  2556.   Call with pointer to buffer to put hostname in, and length of buffer.
  2557.   Copies hostname into buffer on success, puts null string in buffer on
  2558.   failure.
  2559. */
  2560. #ifdef BSD44
  2561. #define BSD4
  2562. #undef ATTSV
  2563. #endif /* BSD44 */
  2564.  
  2565. #ifdef SVORPOSIX
  2566. #ifndef BSD44
  2567. #ifndef apollo
  2568. #include <sys/utsname.h>
  2569. #endif /* apollo */
  2570. #endif /* BSD44 */
  2571. #else
  2572. #ifdef BELLV10
  2573. #include <utsname.h>
  2574. #endif /* BELLV10 */
  2575. #endif /* SVORPOSIX*/
  2576.  
  2577. #ifdef CKSYSLOG
  2578. extern char uidbuf[], * clienthost;
  2579. #endif /* CKSYSLOG */
  2580.  
  2581. VOID
  2582. ckhost(vvbuf,vvlen) char * vvbuf; int vvlen; {
  2583.  
  2584. #ifndef NOPUSH
  2585.     extern int nopush;
  2586. #ifndef NOSERVER
  2587.     extern int en_hos;
  2588. #endif /* NOSERVER */
  2589. #endif /* NOPUSH */
  2590.  
  2591. #ifdef pdp11
  2592.     *vvbuf = NUL;
  2593. #else  /* Everything else - rest of this routine */
  2594.  
  2595.     char *g;
  2596.     int havefull = 0;
  2597. #ifdef VMS
  2598.     int x;
  2599. #endif /* VMS */
  2600.  
  2601. #ifdef SVORPOSIX
  2602. #ifndef BSD44
  2603. #ifndef _386BSD
  2604. #ifndef APOLLOSR10
  2605.     struct utsname hname;
  2606. #endif /* APOLLOSR10 */
  2607. #endif /* _386BSD */
  2608. #endif /* BSD44 */
  2609. #endif /* SVORPOSIX */
  2610. #ifdef datageneral
  2611.     int ac0 = (char *) vvbuf, ac1 = -1, ac2 = 0;
  2612. #endif /* datageneral */
  2613.  
  2614. #ifndef NOPUSH
  2615.     if (getenv("CK_NOPUSH")) {          /* No shell access allowed */
  2616.         nopush = 1;                     /* on this host... */
  2617. #ifndef NOSERVER
  2618.         en_hos = 0;
  2619. #endif /* NOSERVER */
  2620.     }
  2621. #endif /* NOPUSH */
  2622.  
  2623.     *vvbuf = NUL;                       /* How let's get our host name ... */
  2624.  
  2625. #ifndef BELLV10                         /* Does not have gethostname() */
  2626. #ifndef OXOS
  2627. #ifdef SVORPOSIX
  2628. #ifdef APOLLOSR10
  2629.     ckstrncpy(vvbuf,"Apollo",vvlen);
  2630. #else
  2631. #ifdef BSD44
  2632.     if (gethostname(vvbuf,vvlen) < 0)
  2633.       *vvbuf = NUL;
  2634. #else
  2635. #ifdef _386BSD
  2636.     if (gethostname(vvbuf,vvlen) < 0) *vvbuf = NUL;
  2637. #else
  2638. #ifdef QNX
  2639. #ifdef TCPSOCKET
  2640.     if (gethostname(vvbuf,vvlen) < 0) *vvbuf = NUL;
  2641. #else
  2642.     if (uname(&hname) > -1) ckstrncpy(vvbuf,hname.nodename,vvlen);
  2643. #endif /* TCPSOCKET */
  2644. #else /* SVORPOSIX but not _386BSD or BSD44 */
  2645. #ifdef __ia64__
  2646.     if (uname(&hname) > -1) ckstrncpy(vvbuf,hname.nodename,vvlen);
  2647. #else
  2648.     if (uname(&hname) > -1) {
  2649.     char * p;
  2650.     p = hname.nodename;
  2651. #ifdef TCPSOCKET
  2652. #ifndef NOCKGETFQHOST
  2653.     if (!ckstrchr(p,'.'))
  2654.       p = (char *)ckgetfqhostname(p);
  2655. #endif /* NOCKGETFQHOST */
  2656. #endif /* TCPSOCKET */
  2657.     if (!p) p = "";
  2658.     if (!*p) p = "(unknown)";
  2659.     ckstrncpy(vvbuf,p,vvlen);
  2660.     }
  2661. #endif /* __ia64__ */
  2662. #endif /* QNX */
  2663. #endif /* _386BSD */
  2664. #endif /* BSD44 */
  2665. #endif /* APOLLOSR10 */
  2666. #else /* !SVORPOSIX */
  2667. #ifdef BSD4
  2668.     if (gethostname(vvbuf,vvlen) < 0) *vvbuf = NUL;
  2669. #else /* !BSD4 */
  2670. #ifdef VMS
  2671.     g = getenv("SYS$NODE");
  2672.     if (g) ckstrncpy(vvbuf,g,vvlen);
  2673.     x = (int)strlen(vvbuf);
  2674.     if (x > 1 && vvbuf[x-1] == ':' && vvbuf[x-2] == ':') vvbuf[x-2] = NUL;
  2675. #else
  2676. #ifdef datageneral
  2677.     if (sys($HNAME,&ac0,&ac1,&ac2) == 0) /* successful */
  2678.         vvlen = ac2 + 1;                /* enh - have to add one */
  2679. #else
  2680. #ifdef OS2                              /* OS/2 */
  2681.     g = os2_gethostname();
  2682.     if (g) ckstrncpy(vvbuf,g,vvlen);
  2683. #else /* OS2 */
  2684. #ifdef OSK
  2685. #ifdef TCPSOCKET
  2686.         if (gethostname(vvbuf, vvlen) < 0) *vvbuf = NUL;
  2687. #endif /* TCPSOCKET */
  2688. #endif /* OSK */
  2689. #endif /* OS2 */
  2690. #endif /* datageneral */
  2691. #endif /* VMS */
  2692. #endif /* BSD4 */
  2693. #endif /* SVORPOSIX */
  2694. #else /* OXOS */
  2695.     /* If TCP/IP is not installed, gethostname() fails, use uname() */
  2696.     if (gethostname(vvbuf,vvlen) < 0) {
  2697.         if (uname(&hname) > -1)
  2698.             ckstrncpy(vvbuf,hname.nodename,vvlen);
  2699.         else
  2700.             *vvbuf = NUL;
  2701.     }
  2702. #endif /* OXOS */
  2703. #endif /* BELLV10 */
  2704.     if (*vvbuf == NUL) {                /* If it's still empty */
  2705.         g = getenv("HOST");             /* try this */
  2706.         if (g) ckstrncpy(vvbuf,g,vvlen);
  2707.     }
  2708.     vvbuf[vvlen-1] = NUL;               /* Make sure result is terminated. */
  2709. #endif /* pdp11 */
  2710. }
  2711. #ifdef BSD44
  2712. #undef BSD4
  2713. #define ATTSV
  2714. #endif /* BSD44 */
  2715.  
  2716. /*
  2717.   A S K M O R E  --  Poor person's "more".
  2718.   Returns 0 if no more, 1 if more wanted.
  2719. */
  2720. int
  2721. askmore() {
  2722.     char c;
  2723.     int rv, cx;
  2724. #ifdef IKSD
  2725.     extern int timelimit;
  2726. #endif /* IKSD */
  2727. #ifdef IKSDCONF
  2728.     extern int iksdcf;
  2729. #endif /* IKSDCONF */
  2730. #ifdef CK_APC
  2731.     extern int apcstatus, apcactive;
  2732. #endif /* CK_APC */
  2733.  
  2734. #ifdef NOICP
  2735.     return(1);
  2736. #else
  2737.     if (!xaskmore)
  2738.       return(1);
  2739. #ifdef IKSDCONF
  2740.     if (inserver && !iksdcf)
  2741.       return(1);
  2742. #endif /* IKSDCONF */
  2743. #ifdef CK_APC
  2744.     if (apcactive == APC_LOCAL ||
  2745.         (apcactive == APC_REMOTE && (apcstatus & APC_NOINP)))
  2746.         return(1);
  2747. #endif /* CK_APC */
  2748. #ifdef VMS
  2749.     if (batch)
  2750.       return(1);
  2751. #else
  2752. #ifdef UNIX
  2753.     if (backgrd)
  2754.       return(1);
  2755. #endif /* UNIX */
  2756. #endif /* VMS */
  2757.  
  2758. #ifndef VMS
  2759.     concb((char)escape);                /* Force CBREAK mode. */
  2760. #endif /* VMS */
  2761.  
  2762.     rv = -1;
  2763.     while (rv < 0) {
  2764. #ifndef OS2
  2765.         printf("more? ");
  2766. #ifdef UNIX
  2767. #ifdef NOSETBUF
  2768.         fflush(stdout);
  2769. #endif /* NOSETBUF */
  2770. #endif /* UNIX */
  2771. #else
  2772.         printf("more? ");
  2773.         fflush(stdout);
  2774. #endif /* OS2 */
  2775.  
  2776. #ifdef IKSD
  2777.         if (inserver) {
  2778.             cx = cmdgetc(timelimit);
  2779.             if (cx < -1 && timelimit) {
  2780.                 printf("\n?IKS idle timeout - Goodbye.\n");
  2781.                 doexit(GOOD_EXIT,0);
  2782.             } else if (cx == -1) {    /* Connection lost */
  2783.                 doexit(BAD_EXIT,0);
  2784.             }
  2785.             c = (char) cx;
  2786.         } else {
  2787. #endif /* IKSD */
  2788. #ifdef VMS
  2789.         conbin((char)escape);    /* Protect against Ctrl-Z */
  2790.         cx = coninc(0);
  2791.         concb((char)escape);
  2792. #else
  2793.         cx = cmdgetc(0);
  2794. #endif /* VMS */
  2795.         debug(F101,"askmore cmdgetc","",cx);
  2796.         if (cx == EOF) {
  2797.         debug(F100,"askmore EOF","",0);
  2798. #ifdef VMS
  2799.         c = '\032';
  2800. #else
  2801.         c = 'n';
  2802. #endif /* VMS */
  2803.         } else {
  2804.         c = (char)cx;
  2805.         }
  2806.         debug(F101,"askmore c","",c);
  2807.  
  2808. #ifdef IKSD
  2809.     }
  2810. #endif /* IKSD */
  2811.         switch (c) {
  2812.           /* Yes */
  2813.       case 'p': case 'P': case 'g': case 'G': /* Proceed or Go */
  2814.         xaskmore = 0;
  2815.         /* fall thru on purpose */
  2816.  
  2817.           case SP: case 'y': case 'Y': case 012:  case 015:
  2818. #ifdef OSK
  2819.             write(1, "\015      \015", sizeof "\015      \015" - 1);
  2820. #else
  2821.             printf("\015      \015");
  2822. #endif /* OSK */
  2823.             rv = 1;
  2824.             break;
  2825.           /* No */
  2826.           case 'n': case 'N': case 'q': case 'Q':
  2827. #ifdef OSK
  2828.             printf("\n");
  2829. #else
  2830.             printf("\015\012");
  2831. #endif /* OSK */
  2832.             rv = 0;
  2833.             break;
  2834.       case '\003':
  2835.       case '\004':
  2836.       case '\032':
  2837. #ifdef OSK
  2838.         printf("^%c...\n", (c + 0100));
  2839. #else
  2840.         printf("^%c...\015\012", (c + 0100));
  2841. #endif /* OSK */
  2842.         rv = 0;
  2843.         break;
  2844.           /* Invalid answer */
  2845.           default:
  2846.             debug(F111,"askmore","invalid answer",c);
  2847.             printf("Y or space-bar for yes, N for no, G to show the rest\n");
  2848.             continue;
  2849.         }
  2850. #ifdef OS2
  2851.         printf("\r                                                   \r");
  2852.         fflush(stdout);
  2853. #endif /* OS2 */
  2854.     }
  2855.     return(rv);
  2856. #endif /* NOICP */
  2857. }
  2858.  
  2859. /*  T R A P  --  Terminal interrupt handler */
  2860.  
  2861. SIGTYP
  2862. #ifdef CK_ANSIC
  2863. trap(int sig)
  2864. #else
  2865. trap(sig) int sig;
  2866. #endif /* CK_ANSIC */
  2867. /* trap */ {
  2868.     extern int b_save, f_save;
  2869. #ifndef NOICP
  2870.     extern int timelimit;
  2871. #endif /* NOICP */
  2872. #ifdef OS2
  2873.     extern unsigned long startflags;
  2874. #ifndef NOSETKEY
  2875.     extern int os2gks;
  2876. #endif /* NOSETKEY */
  2877.     int i;
  2878. #endif /* OS2 */
  2879. #ifndef NOSPL
  2880.     extern int i_active, instatus;
  2881. #endif /* NOSPL */
  2882. #ifdef VMS
  2883.     int i; FILE *f;
  2884. #endif /* VMS */
  2885.     extern int zchkod, zchkid;
  2886. #ifndef NOSPL
  2887.     extern int unkmacro;
  2888. #endif /* NOSPL */
  2889.  
  2890.     debok = 1;
  2891. #ifdef NTSIG
  2892.     connoi();
  2893. #endif /* NTSIG */
  2894. #ifdef __EMX__
  2895.     signal(SIGINT, SIG_ACK);
  2896. #endif
  2897. #ifdef GEMDOS
  2898. /* GEM is not reentrant, no i/o from interrupt level */
  2899.     cklongjmp(cmjbuf,1);                /* Jump back to parser now! */
  2900. #endif /* GEMDOS */
  2901.  
  2902. #ifdef DEBUG
  2903.     if (deblog) {
  2904.     if (sig == SIGINT)
  2905.       debug(F101,"trap caught SIGINT","",sig);
  2906.     else
  2907.       debug(F101,"trap caught signal","",sig);
  2908.     }
  2909. #endif /* DEBUG */
  2910.  
  2911. #ifdef OS2
  2912.     if ( sig == SIGBREAK && (startflags & 128) ) {
  2913.         debug(F101,"trap ignoring SIGBREAK","",sig);
  2914.         return;
  2915.     }
  2916. #endif /* OS2 */
  2917.  
  2918. #ifndef NOICP
  2919.     timelimit = 0;                      /* In case timed ASK interrupted */
  2920. #ifndef NOSPL
  2921.     unkmacro = 0;            /* Or ON_UNKNOWN_MACRO interrupted.. */
  2922. #endif /* NOSPL */
  2923. #endif /* NOICP */
  2924.     zchkod = 0;                         /* Or file expansion interrupted... */
  2925.     zchkid = 0;
  2926.     interrupted = 1;
  2927.  
  2928.     if (what & W_CONNECT) {        /* Are we in CONNECT mode? */
  2929. /*
  2930.   The HP workstation Reset key sends some kind of ueber-SIGINT that can not
  2931.   be SIG_IGNored, so we wind up here somehow (even though this is *not* the
  2932.   current SIGINT handler).  Just return.
  2933. */
  2934.         debug(F101,"trap: SIGINT caught during CONNECT","",sig);
  2935.         SIGRETURN;
  2936.     }
  2937. #ifndef NOSPL
  2938.     if (i_active) {                     /* INPUT command was active? */
  2939.         i_active = 0;                   /* Not any more... */
  2940.         instatus = INP_UI;              /* INPUT status = User Interrupted */
  2941.     }
  2942. #endif /* NOSPL */
  2943.  
  2944. #ifndef NOXFER
  2945.     ftreset();                          /* Restore global protocol settings */
  2946.     binary = b_save;                    /* Then restore these */
  2947.     fncnv  = f_save;
  2948.     bye_active = 0;
  2949.     diractive = 0;
  2950.     cdactive = 0;
  2951. #endif /* NOXFER */
  2952.     zclose(ZIFILE);                     /* If we were transferring a file, */
  2953.     zclose(ZOFILE);                     /* close it. */
  2954. #ifndef NOICP
  2955.     cmdsquo(cmd_quoting);               /* If command quoting was turned off */
  2956. #ifdef CKLEARN
  2957.     {
  2958.     extern FILE * learnfp;
  2959.     extern int learning;
  2960.     if (learnfp) {
  2961.         fclose(learnfp);
  2962.         learnfp = NULL;
  2963.         learning = 0;
  2964.     }
  2965.     }
  2966. #endif /* CKLEARN */
  2967. #endif /* NOICP */
  2968. #ifdef CK_APC
  2969.     delmac("_apc_commands",1);
  2970.     apcactive = APC_INACTIVE;
  2971. #endif /* CK_APC */
  2972.  
  2973. #ifdef VMS
  2974. /*
  2975.   Fix terminal.
  2976. */
  2977.     if (ft_win) {                       /* If curses window open */
  2978.         debug(F100,"^C trap() curses","",0);
  2979.         xxscreen(SCR_CW,0,0L,"");       /* Close it */
  2980.         conres();                       /* Restore terminal */
  2981.         i = printf("^C...");            /* Echo ^C to standard output */
  2982.     } else {
  2983.         conres();
  2984.         i = printf("^C...\n");          /* Echo ^C to standard output */
  2985.     }
  2986.     if (i < 1 && ferror(stdout)) {      /* If there was an error */
  2987.         debug(F100,"^C trap() error","",0);
  2988.         fclose(stdout);                 /* close standard output */
  2989.         f = fopen(dftty, "w");          /* open the controlling terminal */
  2990.         if (f) stdout = f;              /* and make it standard output */
  2991.         printf("^C...\n");              /* and echo the ^C again. */
  2992.     }
  2993. #else                                   /* Not VMS */
  2994. #ifdef STRATUS
  2995.     conres();                           /* Set console back to normal mode */
  2996. #endif /* STRATUS */
  2997. #ifndef NOXFER
  2998.     if (ft_win) {                       /* If curses window open, */
  2999.         debug(F100,"^C trap() curses","",0);
  3000.         xxscreen(SCR_CW,0,0L,"");    /* close it. */
  3001.         printf("^C...");                /* Echo ^C to standard output */
  3002.     } else {
  3003. #endif /* NOXFER */
  3004.         printf("^C...\n");
  3005. #ifndef NOXFER
  3006.     }
  3007. #endif /* NOXFER */
  3008. #endif /* VMS */
  3009. #ifdef datageneral
  3010.     connoi_mt();                        /* Kill asynch task that listens to */
  3011.     ttimoff();
  3012.     conres();                           /* the keyboard */
  3013. #endif /* datageneral */
  3014.  
  3015. #ifndef NOCCTRAP
  3016. /*  This is stupid -- every version should have ttimoff()...  */
  3017. #ifdef UNIX
  3018.     ttimoff();                          /* Turn off any timer interrupts */
  3019. #else
  3020. #ifdef OSK
  3021.     ttimoff();                          /* Turn off any timer interrupts */
  3022. #else
  3023. #ifdef STRATUS
  3024.     ttimoff();                          /* Turn off any timer interrupts */
  3025. #else
  3026. #ifdef OS2
  3027. #ifndef NOSETKEY
  3028.     os2gks = 1;                         /* Turn back on keycode mapping  */
  3029. #endif /* NOSETKEY */
  3030. #ifndef NOLOCAL
  3031.     for (i = 0; i < VNUM; i++)
  3032.       VscrnResetPopup(i);
  3033. #endif /* NOLOCAL */
  3034. #ifdef TCPSOCKET
  3035. #ifdef NT
  3036.     /* WSAIsBlocking() returns FALSE in Win95 during a blocking accept call */
  3037.     if ( WSASafeToCancel /* && WSAIsBlocking() */ ) {
  3038.         WSACancelBlockingCall();
  3039.     }
  3040. #endif /* NT */
  3041. #endif /* TCPSOCKET */
  3042. #ifdef CK_NETBIOS
  3043.     NCBCancelOutstanding();
  3044. #endif /* CK_NETBIOS */
  3045.     ttimoff();                          /* Turn off any timer interrupts */
  3046. #else
  3047. #ifdef VMS
  3048.     ttimoff();                          /* Turn off any timer interrupts */
  3049. #endif /* VMS */
  3050. #endif /* OS2 */
  3051. #endif /* STRATUS */
  3052. #endif /* OSK */
  3053. #endif /* UNIX */
  3054.  
  3055. #ifdef OSK
  3056.     sigmask(-1);
  3057. /*
  3058.   We are in an intercept routine but do not perform a F$RTE (done implicitly
  3059.   by rts).  We have to decrement the sigmask as F$RTE does.  Warning: longjump
  3060.   only restores the cpu registers, NOT the fpu registers.  So don't use fpu at
  3061.   all or at least don't use common fpu (double or float) register variables.
  3062. */
  3063. #endif /* OSK */
  3064.  
  3065. #ifdef NTSIG
  3066.     PostCtrlCSem();
  3067. #else /* NTSIG */
  3068.     debug(F100,"trap about to longjmp","",0);
  3069. #ifdef NT
  3070.     cklongjmp(ckjaddr(cmjbuf),1);
  3071. #else /* NT */
  3072.     cklongjmp(cmjbuf,1);
  3073. #endif /* NT */
  3074. #endif /* NTSIG */
  3075. #else /* NOCCTRAP */
  3076. /* No Ctrl-C trap, just exit. */
  3077. #ifdef CK_CURSES                        /* Curses support? */
  3078.     xxscreen(SCR_CW,0,0L,"");           /* Close curses window */
  3079. #endif /* CK_CURSES */
  3080.     doexit(BAD_EXIT,what);              /* Exit poorly */
  3081. #endif /* NOCCTRAP */
  3082.     SIGRETURN;
  3083. }
  3084.  
  3085.  
  3086. /*  C K _ T I M E  -- Returns pointer to current time. */
  3087.  
  3088. char *
  3089. ck_time() {
  3090.     static char tbuf[10];
  3091.     char *p;
  3092.     int x;
  3093.  
  3094.     ztime(&p);                          /* "Thu Feb  8 12:00:00 1990" */
  3095.     if (!p)                             /* like asctime()! */
  3096.       return("");
  3097.     if (*p) {
  3098.         for (x = 11; x < 19; x++)       /* copy hh:mm:ss */
  3099.           tbuf[x - 11] = p[x];          /* to tbuf */
  3100.         tbuf[8] = NUL;                  /* terminate */
  3101.     }
  3102.     return(tbuf);                       /* and return it */
  3103. }
  3104.  
  3105. /*  C C _ C L E A N  --  Cleanup after terminal interrupt handler */
  3106.  
  3107. #ifdef GEMDOS
  3108. int
  3109. cc_clean() {
  3110.     zclose(ZIFILE);                     /* If we were transferring a file, */
  3111.     zclose(ZOFILE);                     /* close it. */
  3112.     printf("^C...\n");                  /* Not VMS, no problem... */
  3113. }
  3114. #endif /* GEMDOS */
  3115.  
  3116.  
  3117. /*  S T P T R A P -- Handle SIGTSTP (suspend) signals */
  3118.  
  3119. SIGTYP
  3120. #ifdef CK_ANSIC
  3121. stptrap(int sig)
  3122. #else
  3123. stptrap(sig) int sig;
  3124. #endif /* CK_ANSIC */
  3125. /* stptrap */ {
  3126.  
  3127. #ifndef NOJC
  3128.     int x; extern int cmflgs;
  3129.     debug(F101,"stptrap() caught signal","",sig);
  3130.     if (!xsuspend) {
  3131.         printf("\r\nsuspend disabled\r\n");
  3132. #ifndef NOICP
  3133.         if (what & W_COMMAND) {        /* If we were parsing commands */
  3134.             prompt(xxstring);           /* reissue the prompt and partial */
  3135.             if (!cmflgs)                /* command (if any) */
  3136.               printf("%s",cmdbuf);
  3137.         }
  3138. #endif /* NOICP */
  3139.     } else {
  3140.         conres();                       /* Reset the console */
  3141. #ifndef OS2
  3142.         /* Flush pending output first, in case we are continued */
  3143.         /* in the background, which could make us block */
  3144.         fflush(stdout);
  3145.  
  3146.         x = psuspend(xsuspend);        /* Try to suspend. */
  3147.         if (x < 0)
  3148. #endif /* OS2 */
  3149.           printf("Job control not supported\r\n");
  3150.         conint(trap,stptrap);           /* Rearm the trap. */
  3151.         debug(F100,"stptrap back from suspend","",0);
  3152.         switch (what) {
  3153.           case W_CONNECT:               /* If suspended during CONNECT? */
  3154.             conbin((char)escape);       /* put console back in binary mode */
  3155.             debug(F100,"stptrap W_CONNECT","",0);
  3156.             break;
  3157. #ifndef NOICP
  3158.           case W_COMMAND:               /* Suspended in command mode */
  3159.             debug(F101,"stptrap W_COMMAND pflag","",pflag);
  3160.             concb((char)escape);        /* Put back CBREAK tty mode */
  3161.             if (pflag) {                /* If command parsing was */
  3162.                 prompt(xxstring);       /* reissue the prompt and partial */
  3163.                 if (!cmflgs)            /* command (if any) */
  3164.                   printf("%s",cmdbuf);
  3165.             }
  3166.             break;
  3167. #endif /* NOICP */
  3168.           default:                      /* All other cases... */
  3169.             debug(F100,"stptrap default","",0);
  3170.             concb((char)escape);        /* Put it back in CBREAK mode */
  3171.             break;
  3172.         }
  3173.     }
  3174. #endif /* NOJC */
  3175.     SIGRETURN;
  3176. }
  3177.  
  3178. #ifdef TLOG
  3179. #define TBUFL 300
  3180.  
  3181. /*  T L O G  --  Log a record in the transaction file  */
  3182. /*
  3183.  Call with a format and 3 arguments: two strings and a number:
  3184.    f     - Format, a bit string in range 0-7, bit x is on, arg #x is printed.
  3185.    s1,s2 - String arguments 0 and 1.
  3186.    n     - Long, argument 2.
  3187. */
  3188. VOID
  3189. #ifdef CK_ANSIC
  3190. dotlog(int f, char *s1, char *s2, CK_OFF_T n)
  3191. #else
  3192. dotlog(f,s1,s2,n) int f; CK_OFF_T n; char *s1, *s2;
  3193. #endif /* CK_ANSIC */
  3194. /* dotlog */ {
  3195.     static char s[TBUFL];
  3196.     extern int tlogfmt;
  3197.     char *sp = s; int x;
  3198.     if (!s1) s1 = "";
  3199.     if (!s2) s2 = "";
  3200.  
  3201.     if (!tralog) return;                /* If no transaction log, don't */
  3202.     if (tlogfmt != 1) return;
  3203.     switch (f) {
  3204.       case F000:                        /* 0 (special) "s1 n s2"  */
  3205.         if ((int)strlen(s1) + (int)strlen(s2) + 15 > TBUFL)
  3206.           sprintf(sp,"?T-Log string too long");
  3207.         else
  3208.       sprintf(sp,"%s %s %s",s1,ckfstoa(n),s2);
  3209.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3210.         break;
  3211.       case F001:                        /* 1, " n" */
  3212.         sprintf(sp," %s",ckfstoa(n));
  3213.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3214.         break;
  3215.       case F010:                        /* 2, "[s2]" */
  3216.         x = (int)strlen(s2);
  3217.         if (s2[x] == '\n') s2[x] = '\0';
  3218.         if (x + 6 > TBUFL)
  3219.           sprintf(sp,"?String too long");
  3220.         else sprintf(sp,"[%s]",s2);
  3221.         if (zsoutl(ZTFILE,"") < 0) tralog = 0;
  3222.         break;
  3223.       case F011:                        /* 3, "[s2] n" */
  3224.         x = (int)strlen(s2);
  3225.         if (s2[x] == '\n') s2[x] = '\0';
  3226.         if (x + 6 > TBUFL)
  3227.           sprintf(sp,"?String too long");
  3228.         else sprintf(sp,"[%s] %s",s2,ckfstoa(n));
  3229.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3230.         break;
  3231.       case F100:                        /* 4, "s1" */
  3232.         if (zsoutl(ZTFILE,s1) < 0) tralog = 0;
  3233.         break;
  3234.       case F101:                        /* 5, "s1: n" */
  3235.         if ((int)strlen(s1) + 15 > TBUFL)
  3236.           sprintf(sp,"?String too long");
  3237.         else sprintf(sp,"%s: %s",s1,ckfstoa(n));
  3238.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3239.         break;
  3240.       case F110:                        /* 6, "s1 s2" */
  3241.         x = (int)strlen(s2);
  3242.         if (s2[x] == '\n') s2[x] = '\0';
  3243.         if ((int)strlen(s1) + x + 4 > TBUFL)
  3244.           sprintf(sp,"?String too long");
  3245.         else
  3246.       sprintf(sp,"%s%s%s",s1,((*s2 == ':') ? "" : " "),s2);
  3247.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3248.         break;
  3249.       case F111:                        /* 7, "s1 s2: n" */
  3250.         x = (int)strlen(s2);
  3251.         if (s2[x] == '\n') s2[x] = '\0';
  3252.         if ((int)strlen(s1) + x + 15 > TBUFL)
  3253.           sprintf(sp,"?String too long");
  3254.         else
  3255.       sprintf(sp,"%s%s%s: %s",s1,((*s2 == ':') ? "" : " "),s2,ckfstoa(n));
  3256.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3257.         break;
  3258.       default:
  3259.         sprintf(sp,"?Invalid format for tlog() - %d",f);
  3260.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3261.     }
  3262. }
  3263.  
  3264. /*
  3265.   D O X L O G
  3266.  
  3267.   This is the transaction-log writer for BRIEF format.
  3268.   The idea is produce one record (line) per file.  Each record
  3269.   has the following delimited fields:
  3270.     Date (yyyymmdd)
  3271.     Time (hh:mm:ss)
  3272.     Action: SEND or RECV
  3273.     File name
  3274.     File size
  3275.     Transfer mode (text, binary, image, labeled, etc).
  3276.     Status: OK or FAILED
  3277.     Free-form comments in doublequotes
  3278.   The default separator is comma.
  3279.   If a field contains the separator, it is enclosed in doublequotes.
  3280. */
  3281. VOID
  3282. #ifdef CK_ANSIC
  3283. doxlog(int x, char * fn, CK_OFF_T fs, int fm, int status, char * msg)
  3284. #else
  3285. doxlog(x, fn, fs, fm, status, msg)
  3286.     int x; char * fn; CK_OFF_T fs; int fm; int status; char * msg;
  3287. #endif /* CK_ANSIC */
  3288. /* doxlog */ {
  3289.     extern int tlogsep;
  3290.     char sep[2];
  3291.     char buf[CKMAXPATH+256], * bufp;
  3292.     char tmpbuf[32];
  3293.     char * s, * p;
  3294.     int len, left, ftp = 0, k;
  3295.  
  3296.     if (!tralog) return;                /* If no transaction log, don't */
  3297.  
  3298.     if (!fn) fn = "";                   /* Protect against null pointers */
  3299.     if (!msg) msg = "";
  3300.     if (x & W_FTP)
  3301.       ftp++;
  3302.  
  3303.     sep[0] = (char) tlogsep;
  3304.     sep[1] = NUL;
  3305.     if (!sep[0]) sep[0] = ',';
  3306.  
  3307.     bufp = buf;
  3308.     left = sizeof(buf);
  3309.     debug(F101,"XXX doxlog left 1","",left);
  3310.  
  3311.     p = zzndate();                      /* Date */
  3312.     ckmakmsg(buf, left, p ? p : "00000000", sep, NULL, NULL);
  3313.     bufp += 9;
  3314.     left -= 9;
  3315.     debug(F111,"XXX doxlog left 2",buf,left);
  3316.  
  3317.     ztime(&p);
  3318.     ckstrncpy(bufp,p+11,left);
  3319.     bufp += 8;
  3320.     left -= 8;
  3321.     debug(F111,"XXX doxlog left 3",buf,left);
  3322.  
  3323.     if (ftp) {
  3324.     if (!(x & (W_SEND|W_RECV)))
  3325.       return;
  3326.     s =  (x & W_SEND) ? "PUT" : "GET";
  3327.     k = 3;
  3328.     } else {
  3329.     s =  (x & W_SEND) ? "SEND" : "RECV";
  3330.     k = 4;
  3331.     }
  3332.     ckmakmsg(bufp,left,sep,s,sep,NULL);
  3333.     bufp += k + 2;
  3334.     left -= (k + 2);
  3335.     debug(F111,"XXX doxlog left 4",buf,left);
  3336.  
  3337.     s = "";
  3338.     if (ckstrchr(fn,sep[0]))        /* Filename */
  3339.       s = "\"";
  3340.     ckmakmsg(bufp,left,s,fn,s,sep);
  3341.     sprintf(tmpbuf,"%s",ckfstoa(fs));           /* Size */
  3342.     ckstrncat(buf,tmpbuf,CKMAXPATH);
  3343.     ckstrncat(buf,sep,CKMAXPATH);
  3344.     debug(F110,"doxlog 4",buf,0);
  3345.  
  3346. #ifdef NOICP
  3347.     /* Transfer mode */
  3348.     ckstrncpy(tmpbuf, (binary ? "binary" : "text"), TMPBUFSIZ);
  3349. #else
  3350.     ckstrncpy(tmpbuf,gfmode(fm,0),TMPBUFSIZ);
  3351. #endif /* NOICP */
  3352.     if (ckstrchr(tmpbuf,sep[0])) {      /* Might contain spaces */
  3353.         ckstrncat(buf,"\"",CKMAXPATH);
  3354.         ckstrncat(buf,tmpbuf,CKMAXPATH);
  3355.         ckstrncat(buf,"\"",CKMAXPATH);
  3356.     } else
  3357.       ckstrncat(buf,tmpbuf,CKMAXPATH);
  3358.     ckstrncat(buf,sep,CKMAXPATH);
  3359.     debug(F110,"doxlog 5",buf,0);
  3360.  
  3361.     ckstrncat(buf, status ? "FAILED" : "OK",CKMAXPATH);
  3362.     len = strlen(buf);
  3363.     left = CKMAXPATH+256 - len;
  3364.     if (left < 2) fatal("doxlog buffer overlow");
  3365.  
  3366.     debug(F111,"XXX doxlog left 5",buf,left);
  3367.  
  3368.     debug(F110,"doxlog buf 1", buf, len);
  3369.     s = buf + len;
  3370.     if (status == 0 && left > 32) {
  3371.         long cps;
  3372.  
  3373. #ifdef GFTIMER
  3374.     debug(F101,"DOXLOG fpxfsecs","",(long)(fpxfsecs * 1000));
  3375.  
  3376.         cps = (long)((CKFLOAT) fs / fpxfsecs);
  3377.         sprintf(s,"%s\"%0.3fsec %ldcps\"",sep,fpxfsecs,cps);
  3378. #else
  3379.         cps = fs / xfsecs;
  3380.         sprintf(s,"%s\"%ldsec %ldcps\"",sep,xfsecs,cps);
  3381. #endif /* GFTIMER */
  3382.     } else if ((int)strlen(msg) + 4 < left) {
  3383.         sprintf(s,"%s\"%s\"",sep,msg);
  3384.     }
  3385.     debug(F111,"XXX doxlog left 5",buf,left);
  3386.  
  3387.     debug(F110,"doxlog 5",buf,0);
  3388.     x = zsoutl(ZTFILE,buf);
  3389.     debug(F101,"doxlog zsoutl","",x);
  3390.     if (x < 0) tralog = 0;
  3391. }
  3392. #endif /* TLOG */
  3393.  
  3394. #ifndef MAC
  3395. /*
  3396.   The rest of this file is for all implementations but the Macintosh.
  3397. */
  3398.  
  3399. #ifdef CK_CURSES
  3400. static int repaint = 0;                 /* Transfer display needs repainting */
  3401. #endif /* CK_CURSES */
  3402.  
  3403. #ifndef NOXFER
  3404. /*  C H K I N T  --  Check for console interrupts  */
  3405.  
  3406. /*
  3407.   Used during file transfer in local mode only:
  3408.   . If user has not touched the keyboard, returns 0 with no side effects.
  3409.   . If user typed S or A (etc, see below) prints status message and returns 0.
  3410.   . If user typed X or F (etc, see below) returns 0 with cxseen set to 1.
  3411.   . If user typed Z or B (etc, see below) returns 0 with czseen set to 1.
  3412.   . If user typed E or C (etc, see below) returns -1.
  3413. */
  3414. int
  3415. chkint() {
  3416.     int ch, cn, ofd; long zz;
  3417.     if (!xfrint)
  3418.       return(0);
  3419.     if ((!local) || (quiet)) return(0); /* Only do this if local & not quiet */
  3420. #ifdef datageneral
  3421.     if (con_reads_mt)                   /* if conint_mt task is active */
  3422.       if (conint_avl) {                 /* and there's an interrupt pending */
  3423.           cn = 1;                       /* process it */
  3424.           ch = conint_ch;
  3425.           conint_avl = 0;               /* turn off flag so conint_mt can */
  3426.       } else                            /* proceed */
  3427.         return(0);
  3428.     else                                /* if conint_mt not active */
  3429.       if ((ch = coninc(2)) < 0)         /* try to get char manually */
  3430.         return(0);                      /* I/O error, or no data */
  3431.       else                              /* if successful, set cn so we */
  3432.         cn = 1;                         /* know we got one */
  3433.     debug(F101,"chkint got keyboard character",ch,cn);
  3434. #else /* !datageneral */
  3435. #ifdef NTSIG
  3436.     {
  3437.         extern int TlsIndex;
  3438.         struct _threadinfo * threadinfo;
  3439.         threadinfo = (struct _threadinfo *) TlsGetValue(TlsIndex);
  3440.         if (threadinfo) {
  3441.             if (!WaitSem(threadinfo->DieSem,0))
  3442.               return -1;                /* Cancel Immediately */
  3443.         }
  3444.     }
  3445. #endif /* NTSIG */
  3446.     cn = conchk();                      /* Any input waiting? */
  3447.     debug(F101,"conchk","",cn);
  3448.     if (cn < 1) return(0);
  3449.     ch = coninc(5) ;
  3450.     debug(F101,"coninc","",ch);
  3451.     if (ch < 0) return(0);
  3452. #endif /* datageneral */
  3453.  
  3454.     ch &= 0177;
  3455.     switch (ch) {
  3456.       case 'A': case 'a': case 0001:    /* Status report */
  3457.       case 'S': case 's':
  3458.         if (fdispla != XYFD_R && fdispla != XYFD_S && fdispla != XYFD_N)
  3459.           return(0);                    /* Only for serial, simple or none */
  3460.         ofd = fdispla;                  /* [MF] Save file display type */
  3461.         if (fdispla == XYFD_N)
  3462.           fdispla = XYFD_R;             /* [MF] Pretend serial if no display */
  3463.         xxscreen(SCR_TN,0,0l,"Status report:");
  3464.         xxscreen(SCR_TN,0,0l," file type: ");
  3465.         if (binary) {
  3466.             switch(binary) {
  3467.               case XYFT_L: xxscreen(SCR_TZ,0,0l,"labeled"); break;
  3468.               case XYFT_I: xxscreen(SCR_TZ,0,0l,"image"); break;
  3469.               case XYFT_U: xxscreen(SCR_TZ,0,0l,"binary undefined"); break;
  3470.               default:
  3471.               case XYFT_B: xxscreen(SCR_TZ,0,0l,"binary"); break;
  3472.             }
  3473.         } else {
  3474. #ifdef NOCSETS
  3475.             xxscreen(SCR_TZ,0,0l,"text");
  3476. #else
  3477.             xxscreen(SCR_TU,0,0l,"text, ");
  3478.             if (tcharset == TC_TRANSP || xfrxla == 0) {
  3479.                 xxscreen(SCR_TZ,0,0l,"transparent");
  3480.             } else {
  3481.                 if (what & W_SEND) {
  3482.                     xxscreen(SCR_TZ,0,0l,tcsinfo[tcharset].keyword);
  3483.                     xxscreen(SCR_TU,0,0l," => ");
  3484.                     xxscreen(SCR_TZ,0,0l,fcsinfo[fcharset].keyword);
  3485.                 } else {
  3486.                     xxscreen(SCR_TZ,0,0l,fcsinfo[fcharset].keyword);
  3487.                     xxscreen(SCR_TU,0,0l," => ");
  3488.                     xxscreen(SCR_TZ,0,0l,tcsinfo[tcharset].keyword);
  3489.                 }
  3490.             }
  3491. #endif /* NOCSETS */
  3492.         }
  3493.         xxscreen(SCR_QE,0,filcnt," file number");
  3494.         if (fsize) xxscreen(SCR_QE,0,fsize," size");
  3495.         xxscreen(SCR_QE,0,ffc," characters so far");
  3496.         if (fsize > 0L) {
  3497. #ifdef CK_RESEND
  3498.             zz = what & W_SEND ? sendstart : what & W_RECV ? rs_len : 0;
  3499.             zz = ( (ffc + zz) * 100L ) / fsize;
  3500. #else
  3501.             zz = ( ffc * 100L ) / fsize;
  3502. #endif /* CK_RESEND */
  3503.             xxscreen(SCR_QE,0,zz,      " percent done");
  3504.         }
  3505.         if (bctu == 4) {                /* Block check */
  3506.             xxscreen(SCR_TU,0,0L," block check: ");
  3507.             xxscreen(SCR_TZ,0,0L,"blank-free-2");
  3508.         } else xxscreen(SCR_QE,0,(long)bctu,  " block check");
  3509.         xxscreen(SCR_QE,0,(long)rptflg," compression");
  3510.         xxscreen(SCR_QE,0,(long)ebqflg," 8th-bit prefixing");
  3511.         xxscreen(SCR_QE,0,(long)lscapu," locking shifts");
  3512.         if (!network)
  3513.           xxscreen(SCR_QE,0, speed, " speed");
  3514.         if (what & W_SEND)
  3515.  
  3516.           xxscreen(SCR_QE,0,spsiz, " packet length");
  3517.         else if (what & W_RECV || what & W_REMO)
  3518.           xxscreen(SCR_QE,0,urpsiz," packet length");
  3519.         xxscreen(SCR_QE,0,wslots,  " window slots");
  3520.         fdispla = ofd; /* [MF] Restore file display type */
  3521.         return(0);
  3522.  
  3523.       case 'B': case 'b': case 0002:    /* Cancel batch */
  3524.       case 'Z': case 'z': case 0032:
  3525.         czseen = 1;
  3526.         interrupted = 1;
  3527.         xxscreen(SCR_ST,ST_MSG,0l,
  3528.                  (((what & W_RECV) && (wslots > 1)) ?
  3529.                   "Canceling batch, wait... " :
  3530.                   "Canceling batch... ")
  3531.                  );
  3532.         return(0);
  3533.  
  3534.       case 'F': case 'f': case 0006:    /* Cancel file */
  3535.       case 'X': case 'x': case 0030:
  3536.         cxseen = 1;
  3537.         interrupted = 1;
  3538.         xxscreen(SCR_ST,ST_MSG,0l,
  3539.                  (((what & W_RECV) && (wslots > 1)) ?
  3540.                   "Canceling file, wait... " :
  3541.                   "Canceling file... ")
  3542.                  );
  3543.         return(0);
  3544.  
  3545.       case 'R': case 'r': case 0022:    /* Resend packet */
  3546.       case 0015: case 0012:
  3547. #ifdef STREAMING
  3548.         if (streaming)
  3549.           return(0);
  3550. #endif /* STREAMING */
  3551.         xxscreen(SCR_ST,ST_MSG,0l,"Resending packet... ");
  3552.         numerrs++;
  3553.         resend(winlo);
  3554.         return(0);
  3555.  
  3556. #ifdef datageneral
  3557.       case '\03':                       /* We're not trapping ^C's with */
  3558.         trap(0);                        /* signals, so we check here    */
  3559. #endif /* datageneral */
  3560.  
  3561.       case 'C': case 'c':               /* Ctrl-C */
  3562. #ifndef datageneral
  3563.       case '\03':
  3564. #endif /* datageneral */
  3565.  
  3566.       case 'E': case 'e':               /* Send error packet */
  3567.       case 0005:
  3568.         interrupted = 1;
  3569.         return(-1);
  3570.  
  3571. #ifdef CK_CURSES
  3572.       case 0014:                        /* Ctrl-L to refresh screen */
  3573.       case 'L': case 'l':               /* Also accept L (upper, lower) */
  3574.       case 0027:                        /* Ctrl-W synonym for VMS & Ingres */
  3575.         repaint = 1;
  3576.         return(0);
  3577. #endif /* CK_CURSES */
  3578.  
  3579.       case 'T':
  3580.       case 't':                /* Turn on debug-log timestamps */
  3581. #ifdef DEBUG
  3582.     {
  3583.         extern int debtim;
  3584.         if (ch == 'T') {
  3585.         debtim = 1;
  3586.         xxscreen(SCR_ST,ST_MSG,0l,
  3587.              "Debug timestamps On... ");
  3588.         } else {
  3589.         debtim = 1;
  3590.         xxscreen(SCR_ST,ST_MSG,0l,
  3591.              "Debug timestamps Off... ");
  3592.         }
  3593.     }
  3594. #endif /* DEBUG */
  3595.     return(0);
  3596.  
  3597.       case 'D':
  3598. #ifdef DEBUG
  3599.     if (!deblog) {
  3600.         debopn("debug.log",0);
  3601.         if (deblog) {
  3602.         xxscreen(SCR_ST,ST_MSG,0l,"debug.log open... ");
  3603.         } else {
  3604.         xxscreen(SCR_ST,ST_MSG,0l,"debug.log open FAILED... ");
  3605.         }
  3606.     } else {
  3607.         xxscreen(SCR_ST,ST_MSG,0l,"Debug log On... ");
  3608.     }
  3609.     if (deblog)
  3610.       debok = 1;
  3611. #endif /* DEBUG */
  3612.     return(0);
  3613.  
  3614.       case 'd':                /* Turn off debugging */
  3615. #ifdef DEBUG
  3616.     if (deblog)
  3617.       xxscreen(SCR_ST,ST_MSG,0l,"Debug log Off... ");
  3618.     debok = 0;
  3619. #endif /* DEBUG */
  3620.     return(0);
  3621.  
  3622.       default:                          /* Anything else, print message */
  3623.         intmsg(1L);
  3624.         return(0);
  3625.     }
  3626. }
  3627.  
  3628. /*  I N T M S G  --  Issue message about terminal interrupts  */
  3629.  
  3630. VOID
  3631. #ifdef CK_ANSIC
  3632. intmsg(long n)
  3633. #else
  3634. intmsg(n) long n;
  3635. #endif /* CK_ANSIC */
  3636. /* intmsg */ {
  3637. #ifdef CK_NEED_SIG
  3638.     char buf[80];
  3639. #endif /* CK_NEED_SIG */
  3640.  
  3641.     if (!displa || quiet)               /* Not if we're being quiet */
  3642.       return;
  3643.     if (server && (!srvdis || n > -1L)) /* Special for server */
  3644.       return;
  3645. #ifdef CK_NEED_SIG
  3646.     buf[0] = NUL;                       /* Keep compilers happy */
  3647. #endif /* CK_NEED_SIG */
  3648. #ifndef OXOS
  3649. #ifdef SVORPOSIX
  3650.     conchk();                           /* Clear out pending escape-signals */
  3651. #endif /* SVORPOSIX */
  3652. #endif /* ! OXOS */
  3653. #ifdef VMS
  3654.     conres();                           /* So Ctrl-C will work */
  3655. #endif /* VMS */
  3656.     if ((!server && n == 1L) || (server && n < 0L)) {
  3657.  
  3658. #ifdef CK_NEED_SIG
  3659.         if (xfrint) {
  3660.         ckmakmsg(buf,
  3661.              80,
  3662.              "Type escape character (",
  3663.              dbchr(escape),
  3664.              ") followed by:",
  3665.              NULL
  3666.              );
  3667.             xxscreen(SCR_TN,0,0l,buf);
  3668.         }
  3669. #endif /* CK_NEED_SIG */
  3670.  
  3671.         if (xfrint) {
  3672.             if (protocol == PROTO_K) {
  3673.  xxscreen(SCR_TN,0,0l,"X to cancel file,  CR to resend current packet");
  3674.  xxscreen(SCR_TN,0,0l,"Z to cancel group, A for status report");
  3675.  xxscreen(SCR_TN,0,0l,"E to send Error packet, Ctrl-C to quit immediately: ");
  3676.             } else {
  3677.                 xxscreen(SCR_TN,0,0l,"Ctrl-C to cancel file transfer: ");
  3678.             }
  3679.         } else {
  3680.             xxscreen(SCR_TN,0,0l,"Transfer interruption disabled. ");
  3681.         }
  3682.     }
  3683.     else xxscreen(SCR_TU,0,0l," ");
  3684. }
  3685.  
  3686. #ifndef NODISPLAY
  3687. static int newdpy = 0;                  /* New display flag */
  3688. static char fbuf[80];                   /* Filename buffer */
  3689. static char abuf[80];                   /* As-name buffer */
  3690. static char a2buf[80];                  /* Second As-name buffer */
  3691. static CK_OFF_T oldffc = 0L;
  3692. static CK_OFF_T dots = 0L;
  3693. static int hpos = 0;
  3694.  
  3695. static VOID                             /* Initialize Serial or CRT display */
  3696. dpyinit() {
  3697.     int m = 0, n = 0;
  3698.     char * s = "";
  3699.  
  3700.     newdpy = 0;                         /*  Don't do this again */
  3701.     oldffc = (CK_OFF_T)0;        /*  Reset this */
  3702.     dots = (CK_OFF_T)0;            /*  and this.. */
  3703.     oldcps = cps = 0L;
  3704.  
  3705.     conoll("");                /* New line */
  3706.     if (what & W_SEND) s = "Sending: ";    /* Action */
  3707.     else if (what & W_RECV) s = "Receiving: ";
  3708.     n = (int)strlen(s) + (int)strlen(fbuf);
  3709.     conol(fbuf);
  3710.     m = (int)strlen(abuf) + 4;
  3711.     if (n + m > cmd_cols) {
  3712.         conoll("");
  3713.         n = 0;
  3714.     } else
  3715.       n += m;
  3716.     if (*abuf) {
  3717.         conol(" => ");
  3718.         conol(abuf);
  3719.     }
  3720.     m = (int)strlen(a2buf) + 4;
  3721.     if (n + m > cmd_cols) {
  3722.         conoll("");
  3723.         n = 0;
  3724.     } else
  3725.       n += m;
  3726.     if (*a2buf) {
  3727.         conol(" => ");
  3728.         conol(a2buf);
  3729.     }
  3730.     *fbuf = NUL; *abuf = NUL; *a2buf = NUL;
  3731.     conoll("");
  3732.     if (fsize > (CK_OFF_T)-1) {        /* Size */
  3733.         sprintf(fbuf,"Size: %s, Type: ",ckfstoa(fsize)); /* SAFE (80) */
  3734.         conol(fbuf); *fbuf = NUL;
  3735.     } else conol("Size: unknown, Type: ");
  3736.     if (binary) {            /* Type */
  3737.         switch(binary) {
  3738.               case XYFT_L: conol("labeled"); break;
  3739.               case XYFT_I: conol("image"); break;
  3740.               case XYFT_U: conol("binary undefined"); break;
  3741.               default:
  3742.               case XYFT_B: conol("binary"); break;
  3743.         }
  3744.     } else {
  3745. #ifdef NOCSETS
  3746.         conol("text");
  3747. #else
  3748.         conol("text, ");
  3749.         if (tcharset == TC_TRANSP || xfrxla == 0) {
  3750.             conol("transparent");
  3751.         } else {
  3752.             if (what & W_SEND) {
  3753.                 conol(fcsinfo[fcharset].keyword);
  3754.                 conol(" => ");
  3755.                 conol(tcsinfo[tcharset].keyword);
  3756.             } else {
  3757.                 conol(tcsinfo[tcharset].keyword);
  3758.                 conol(" => ");
  3759.                 conol(fcsinfo[fcharset].keyword);
  3760.             }
  3761.         }
  3762. #endif /* NOCSETS */
  3763.     }
  3764. #ifdef STREAMING
  3765.     if (streaming)
  3766.       conol(", STREAMING");
  3767. #endif /* STREAMING */
  3768.     conoll("");
  3769.  
  3770.     if (fdispla == XYFD_S) {            /* CRT field headings */
  3771. /*
  3772.   Define CK_CPS to show current transfer rate.
  3773.   Leave it undefined to show estimated time remaining.
  3774.   Estimated-time-remaining code from Andy Fyfe, not tested on
  3775.   pathological cases.
  3776. */
  3777. #define CK_CPS
  3778.  
  3779. #ifdef CK_CPS
  3780.         conoll("    File   Percent       Packet");
  3781.         conoll("    Bytes  Done     CPS  Length");
  3782. #else
  3783.         conoll("    File   Percent  Secs Packet");
  3784.         conoll("    Bytes  Done     Left Length");
  3785. #endif /* CK_CPS */
  3786.         newdpy = 0;
  3787.     }
  3788.     hpos = 0;
  3789. }
  3790.  
  3791. /*
  3792.   showpkt(c)
  3793.   c = completion code: 0 means transfer in progress, nonzero means it's done.
  3794.   Show the file transfer progress counter and perhaps verbose packet type.
  3795. */
  3796. VOID
  3797. #ifdef CK_ANSIC
  3798. showpkt(char c)
  3799. #else
  3800. showpkt(c) char c;
  3801. #endif /* CK_ANSIC */
  3802. /* showpkt */ {
  3803.  
  3804. #ifndef GFTIMER
  3805.     long et;                            /* Elapsed time, entire batch  */
  3806. #endif /* GFTIMER */
  3807.     CK_OFF_T howfar;            /* How far into file */
  3808.     long pd;                            /* Percent done, this file     */
  3809.     long tp;                            /* Transfer rate, entire batch */
  3810.     long ps;                            /* Packet size, current packet */
  3811.     CK_OFF_T mytfc;            /* Local copy of byte counter  */
  3812.  
  3813. #ifdef GFTIMER
  3814.     CKFLOAT tnow;
  3815. #endif /* GFTIMER */
  3816.  
  3817.     if (newdpy)                         /* Put up filenames, etc, */
  3818.       dpyinit();                        /* if they're not there already. */
  3819.  
  3820.     howfar = ffc;                       /* How far */
  3821. /*
  3822.   Calculate CPS rate even if not displaying on screen for use in file
  3823.   transfer statistics.
  3824. */
  3825. #ifdef GFTIMER
  3826.     tnow = gftimer();                   /* Time since we started */
  3827.     ps = (what & W_RECV) ? rpktl : spktl; /* Packet size */
  3828. #ifdef CK_RESEND
  3829.     if (what & W_SEND)            /* In case we didn't start at */
  3830.       howfar += sendstart;              /*  the beginning... */
  3831.     else if (what & W_RECV)
  3832.       howfar += rs_len;
  3833. #endif /* CK_RESEND */
  3834.     pd = -1;                            /* Percent done. */
  3835.     if (c == NUL) {                     /* Still going, figure % done */
  3836.         if (!fsize) return;        /* Empty file, don't bother */
  3837.         pd = (fsize > 99) ? (howfar / (fsize / (CK_OFF_T)100)) : 0;
  3838.         if (pd > 100) pd = 100;         /* Expansion */
  3839.     }
  3840.     if (c != NUL)
  3841.       if (!cxseen && !discard && !czseen)
  3842.         pd = 100;                       /* File complete, so 100%. */
  3843.  
  3844.     mytfc = (pd < 100) ? tfc + ffc : tfc;    /* CPS */
  3845.     tp = (long)((tnow > 0.0) ? (CKFLOAT) mytfc / tnow : 0);
  3846.     if (c && (tp == 0))
  3847.       tp = ffc;
  3848.  
  3849.     cps = tp;                           /* Set global variable */
  3850.     if (cps > peakcps &&                /* Peak transfer rate */
  3851.          ((what & W_SEND && spackets > wslots + 4) ||
  3852.       (!(what & W_SEND) && spackets > 10))) {
  3853.         peakcps = cps;
  3854.     }
  3855.  
  3856. #else  /* Not GFTIMER */
  3857.  
  3858.     et = gtimer();                      /* Elapsed time  */
  3859.     ps = (what & W_RECV) ? rpktl : spktl; /* Packet length */
  3860. #ifdef CK_RESEND
  3861.     if (what & W_SEND)            /* And if we didn't start at */
  3862.       howfar += sendstart;              /*  the beginning... */
  3863.     else if (what & W_RECV)
  3864.       howfar += rs_len;
  3865. #endif /* CK_RESEND */
  3866.     pd = -1;                            /* Percent done. */
  3867.     if (c == NUL) {                     /* Still going, figure % done */
  3868.         if (fsize == 0L) return;        /* Empty file, don't bother */
  3869.         pd = (fsize > 99) ? (howfar / (fsize / (CK_OFF_T)100)) : 0;
  3870.         if (pd > 100) pd = 100;         /* Expansion */
  3871.     }
  3872.     if (c != NUL)
  3873.       if (!cxseen && !discard && !czseen)
  3874.         pd = 100;                       /* File complete, so 100%. */
  3875.  
  3876.  
  3877. #ifndef CK_CPS
  3878. /*
  3879.   fsecs = time (from gtimer) that this file started (set in sfile()).
  3880.   Rate so far is ffc / (et - fsecs),  estimated time for remaining bytes
  3881.   is (fsize - ffc) / (ffc / (et - fsecs)).
  3882. */
  3883.     tp = (howfar > 0) ? (fsize - howfar) * (et - fsecs) / howfar : 0;
  3884. #endif /* CK_CPS */
  3885.  
  3886. #ifdef CK_CPS
  3887.     mytfc = (pd < 100) ? tfc + ffc : tfc;
  3888.     tp = (et > 0) ? mytfc / et : 0;    /* Transfer rate */
  3889.     if (c && (tp == 0))            /* Watch out for subsecond times */
  3890.         tp = ffc;
  3891.  
  3892.     cps = tp;                /* Set global variable */
  3893.     if (cps > peakcps &&                /* Peak transfer rate */
  3894.          ((what & W_SEND && spackets > wslots + 4) ||
  3895.       (!(what & W_SEND) && spackets > 10))) {
  3896.         peakcps = cps;
  3897.     }
  3898. #endif /* CK_CPS */
  3899.  
  3900. #endif /* GFTIMER */
  3901.  
  3902.     if (fdispla == XYFD_S) {            /* CRT display */
  3903.         char buffer[128];
  3904.     /* These sprintfs should be safe until we have 32-digit numbers */
  3905.  
  3906.         if (pd > -1L)
  3907.           sprintf(buffer, "%c%9s%5ld%%%8ld%8ld ", CR,ckfstoa(howfar),pd,tp,ps);
  3908.         else
  3909.           sprintf(buffer, "%c%9s      %8ld%8ld ", CR,ckfstoa(howfar),tp,ps);
  3910.         conol(buffer);
  3911.         hpos = 31;
  3912.     } else if (fdispla == XYFD_R) {     /* SERIAL */
  3913.         long i, k;
  3914.         if (howfar - oldffc < 1024)     /* Update display every 1K */
  3915.           return;
  3916.         oldffc = howfar;                /* Time for new display */
  3917.         k = (howfar / 1024L) - dots;    /* How many K so far */
  3918.         for (i = 0L; i < k; i++) {
  3919.             if (hpos++ > (cmd_cols - 3)) { /* Time to wrap? */
  3920.                 conoll("");
  3921.                 hpos = 0;
  3922.             }
  3923.             conoc('.');                 /* Print a dot for this K */
  3924.             dots++;                     /* Count it */
  3925.         }
  3926.     }
  3927. }
  3928.  
  3929.  
  3930. /*  C K S C R E E N  --  Screen display function  */
  3931.  
  3932. /*
  3933.   ckscreen(f,c,n,s)
  3934.     f - argument descriptor
  3935.     c - a character or small integer
  3936.     n - a long integer
  3937.     s - a string.
  3938.  
  3939.   and global fdispla = SET FILE DISPLAY value:
  3940.  
  3941.     XYFD_N = NONE
  3942.     XYFD_R = SERIAL:     Dots, etc, works on any terminal, even hardcopy.
  3943.     XYFD_S = CRT:        Works on any CRT, writes over current line.
  3944.     XYFD_C = FULLSCREEN: Requires terminal-dependent screen control.
  3945.     XYFD_B = BRIEF:      Like SERIAL but only filename & completion status.
  3946.     XYFD_G = GUI;        Windows GUI, same behavior as FULLSCREEN
  3947. */
  3948. VOID
  3949. #ifdef CK_ANSIC
  3950. ckscreen(int f, char c,CK_OFF_T n,char *s)
  3951. #else
  3952. ckscreen(f,c,n,s) int f; char c; CK_OFF_T n; char *s;
  3953. #endif /* CK_ANSIC */
  3954. /* screen */ {
  3955.     char buf[80];
  3956.     int len;                            /* Length of string */
  3957. #ifdef UNIX
  3958. #ifndef NOJC
  3959.     int obg;
  3960. _PROTOTYP( VOID conbgt, (int) );
  3961. #endif /* NOJC */
  3962. #endif /* UNIX */
  3963.     int ftp = 0;
  3964.  
  3965.     ftp = (what & W_FTP) ? 1 : 0;    /* FTP or Kermit? */
  3966.  
  3967.     if (!local && !ftp)            /* In remote mode - don't do this */
  3968.       return;
  3969.  
  3970.     if (!s) s = "";
  3971.  
  3972.     if (!fxd_inited)                    /* Initialize if necessary */
  3973.       fxdinit(fdispla);
  3974.  
  3975. #ifdef UNIX
  3976. #ifndef NOJC
  3977.     obg = backgrd;                      /* Previous background status */
  3978.     conbgt(1);                          /* See if running in background */
  3979.     if (!backgrd && obg) {              /* Just came into foreground? */
  3980.         concb((char)escape);            /* Put console back in CBREAK mode */
  3981.         setint();                       /* Restore interrupts */
  3982.     }
  3983. #endif /* NOJC */
  3984. #endif /* UNIX */
  3985.  
  3986.     if ((f != SCR_WM) && (f != SCR_EM)) /* Always update warnings & errors */
  3987.       if (!displa ||
  3988.           (backgrd && bgset) ||
  3989.           fdispla == XYFD_N ||
  3990.           (server && !srvdis)
  3991.           )
  3992.         return;
  3993.  
  3994. #ifdef VMS
  3995.     if (f == SCR_FN)                    /* VMS - shorten the name */
  3996.       s = zrelname(s,zgtdir());
  3997. #endif /* VMS */
  3998.  
  3999.     if (dest == DEST_S)                 /* SET DESTINATION SCREEN */
  4000.       return;                           /*  would interfere... */
  4001.  
  4002. #ifdef KUI
  4003.     if (fdispla == XYFD_G) {            /* If gui display selected */
  4004.         screeng(f,c,n,s);               /* call the gui version */
  4005.         return;
  4006.     }
  4007. #endif /* KUI */
  4008. #ifdef CK_CURSES
  4009.     if (fdispla == XYFD_C) {            /* If fullscreen display selected */
  4010.         screenc(f,c,n,s);               /* call the fullscreen version */
  4011.         return;
  4012.     }
  4013. #endif /* CK_CURSES */
  4014.  
  4015.     len = (int)strlen(s);               /* Length of string */
  4016.  
  4017.     switch (f) {                        /* Handle our function code */
  4018.       case SCR_FN:                      /* Filename */
  4019.         if (fdispla == XYFD_B) {
  4020. #ifdef NEWFTP
  4021.         if (ftp)
  4022.           printf(" %s %s", what & W_SEND ? "PUT" : "GET", s);
  4023.         else
  4024. #endif /* NEWFTP */
  4025.           printf(" %s %s", what & W_SEND ? "SEND" : "RECV", s);
  4026. #ifdef UNIX
  4027.             fflush(stdout);
  4028. #endif /* UNIX */
  4029.             return;
  4030.         }
  4031. #ifdef MAC
  4032.         conoll(""); conol(s); conoc(SP); hpos = len + 1;
  4033. #else
  4034.         ckstrncpy(fbuf,s,80);
  4035.         abuf[0] = a2buf[0] = NUL;
  4036.         newdpy = 1;                     /* New file so refresh display */
  4037. #endif /* MAC */
  4038.         return;
  4039.  
  4040.       case SCR_AN:                      /* As-name */
  4041.         if (fdispla == XYFD_B) {
  4042. #ifdef COMMENT
  4043.             printf("(as %s) ",s);
  4044. #endif /* COMMENT */
  4045.             return;
  4046.         }
  4047. #ifdef MAC
  4048.         if (hpos + len > 75) { conoll(""); hpos = 0; }
  4049.         conol("=> "); conol(s);
  4050.         if ((hpos += (len + 3)) > 78) { conoll(""); hpos = 0; }
  4051. #else
  4052.         if (abuf[0]) {
  4053.             ckstrncpy(a2buf,s,80);
  4054.         } else {
  4055.             ckstrncpy(abuf,s,80);
  4056.         }
  4057. #endif /* MAC */
  4058.         return;
  4059.  
  4060.       case SCR_FS:                      /* File-size */
  4061.         if (fdispla == XYFD_B) {
  4062.             printf(" (%s) (%s byte%s)",
  4063. #ifdef NOICP
  4064.                    (binary ? "binary" : "text")
  4065. #else
  4066.                    gfmode(binary,0)
  4067. #endif /* NOICP */
  4068.                    , ckfstoa(n), n == 1 ? "" : "s");
  4069. #ifdef UNIX
  4070.             fflush(stdout);
  4071. #endif /* UNIX */
  4072.             return;
  4073.         }
  4074. #ifdef MAC
  4075.         sprintf(buf,", Size: %s",ckfstoa(n));  conoll(buf);  hpos = 0;
  4076. #endif /* MAC */
  4077.         return;
  4078.  
  4079.       case SCR_XD:                      /* X-packet data */
  4080.         if (fdispla == XYFD_B)
  4081.           return;
  4082. #ifdef MAC
  4083.         conoll(""); conoll(s); hpos = 0;
  4084. #else
  4085.         ckstrncpy(fbuf,s,80);
  4086.         abuf[0] = a2buf[0] = NUL;
  4087. #endif /* MAC */
  4088.         return;
  4089.  
  4090.       case SCR_ST:                      /* File status */
  4091.         switch (c) {
  4092.           case ST_OK:                   /* Transferred OK */
  4093.             showpkt('Z');               /* Update numbers one last time */
  4094.             if (fdispla == XYFD_B) {
  4095. #ifdef GFTIMER
  4096.                 printf(": OK (%0.3f sec, %ld cps)\n",fpxfsecs,
  4097.                        (long)((CKFLOAT)ffc / fpxfsecs));
  4098. #else
  4099.                 printf(": OK (%d sec, %ld cps)\n",xfsecs,ffc/xfsecs);
  4100. #endif /* GFTIMER */
  4101.                 return;
  4102.             }
  4103.             if ((hpos += 5) > 78) conoll(""); /* Wrap screen line. */
  4104.             conoll(" [OK]"); hpos = 0;  /* Print OK message. */
  4105.             if (fdispla == XYFD_S) {    /* We didn't show Z packet when */
  4106.                 conoc('Z');             /* it came, so show it now. */
  4107.                 hpos = 1;
  4108.             }
  4109.             return;
  4110.  
  4111.           case ST_DISC:                 /*  Discarded */
  4112.             if (fdispla == XYFD_B) {
  4113.                 printf(": DISCARDED\n");
  4114.                 return;
  4115.             }
  4116.             if ((hpos += 12) > 78) conoll("");
  4117.             conoll(" [discarded]"); hpos = 0;
  4118.             return;
  4119.  
  4120.           case ST_INT:                  /*  Interrupted */
  4121.             if (fdispla == XYFD_B) {
  4122.                 printf(": INTERRUPTED\n");
  4123.                 return;
  4124.             }
  4125.             if ((hpos += 14) > 78) conoll("");
  4126.             conoll(" [interrupted]"); hpos = 0;
  4127.             return;
  4128.  
  4129.       case ST_SIM:
  4130.             if (fdispla == XYFD_B) {
  4131.         if (n == SKP_XNX)
  4132.           printf(": WOULD BE TRANSFERRED (New file)\n");
  4133.         else if (n == SKP_XUP)
  4134.           printf(": WOULD BE TRANSFERRED (Remote file older)\n");
  4135.         else if (n == SKP_SIM)
  4136.           printf(": WOULD BE TRANSFERRED\n");
  4137.         else if (n > 0 && n < nskreason)
  4138.           printf(": SKIPPED (%s)\n",skreason[n]);
  4139.         else
  4140.           printf(": SKIPPED\n");
  4141.                 return;
  4142.             } else if (fdispla == XYFD_S) {
  4143.                 if (fdispla == XYFD_S && fbuf[0]) { /* CRT display */
  4144.                     conoll("");         /* New line */
  4145.                     if (what & W_SEND) conol("Would Send: "); /* Action */
  4146.                     else if (what & W_RECV) conol("Would Receive: ");
  4147.                     conol(fbuf);
  4148.                     if (*abuf) conol(" => "); conol(abuf); /* Names */
  4149.                     if (*a2buf) conol(" => "); conol(a2buf); /* Names */
  4150.                     *fbuf = NUL; *abuf = NUL; *a2buf = NUL;
  4151.                 }
  4152.                 conoll(" [simulated]");
  4153.                 return;
  4154.             }
  4155.             if ((hpos += 10) > 78) conoll("");
  4156.             conol(" [simulated]"); hpos = 0;
  4157.             return;
  4158.  
  4159.           case ST_SKIP:                 /*  Skipped */
  4160.             if (fdispla == XYFD_B) {
  4161.         if (n == SKP_XNX)
  4162.           printf(": WOULD BE TRANSFERRED (New file)\n");
  4163.         else if (n == SKP_XUP)
  4164.           printf(": WOULD BE TRANSFERRED (Remote file older)\n");
  4165.         else if (n == SKP_SIM)
  4166.           printf(": WOULD BE TRANSFERRED\n");
  4167.         else if (n > 0 && n < nskreason)
  4168.           printf(": SKIPPED (%s)\n",skreason[n]);
  4169.         else
  4170.           printf(": SKIPPED\n");
  4171.                 return;
  4172.             } else if (fdispla == XYFD_S) {
  4173.                 if (fdispla == XYFD_S && fbuf[0]) { /* CRT display */
  4174.                     conoll("");         /* New line */
  4175.                     if (what & W_SEND) conol("Sending: "); /* Action */
  4176.                     else if (what & W_RECV) conol("Receiving: ");
  4177.                     conol(fbuf);
  4178.                     if (*abuf) conol(" => "); conol(abuf); /* Names */
  4179.                     if (*a2buf) conol(" => "); conol(a2buf); /* Names */
  4180.                     *fbuf = NUL; *abuf = NUL; *a2buf = NUL;
  4181.                 }
  4182.                 conoll(" [skipped]");
  4183.                 return;
  4184.             }
  4185.             if ((hpos += 10) > 78) conoll("");
  4186.         conol(" "); conol(fbuf);
  4187.             conoll(" [skipped]"); hpos = 0;
  4188.             return;
  4189.  
  4190.           case ST_ERR:                  /* Error */
  4191.             if (fdispla == XYFD_B) {
  4192.                 printf(": ERROR: %s\n",s);
  4193.                 return;
  4194.             }
  4195.             conoll("");
  4196.             conol("Error: "); conoll(s); hpos = 0;
  4197.             return;
  4198.  
  4199.           case ST_MSG:                  /* Message */
  4200. #ifdef NEWFTP
  4201.             if (fdispla == XYFD_B) {
  4202.                 if (ftp && ftp_deb)
  4203.           printf(": MESSAGE: %s\n",s);
  4204.                 return;
  4205.             }
  4206. #endif /* NEWFTP */
  4207.             conoll("");
  4208.             conol("Message: ");
  4209.             conoll(s);
  4210.             hpos = 0;
  4211.             return;
  4212.  
  4213.           case ST_REFU:                 /* Refused */
  4214.             if (fdispla == XYFD_B) {
  4215.                 printf(": REFUSED\n");
  4216.                 return;
  4217.             } else if (fdispla == XYFD_S) {
  4218.                 if (fdispla == XYFD_S && fbuf[0]) { /* CRT display */
  4219.                     conoll("");         /* New line */
  4220.                     if (what & W_SEND) conol("Sending: "); /* Action */
  4221.                     else if (what & W_RECV) conol("Receiving: ");
  4222.                     conol(fbuf);
  4223.                     if (*abuf) conol(" => "); conol(abuf);      /* Names */
  4224.                     if (*a2buf) conol(" => "); conol(a2buf);    /* Names */
  4225.                     *fbuf = NUL; *abuf = NUL; *a2buf = NUL;
  4226.                     conoll("");
  4227.                 }
  4228.                 conol("Refused: "); conoll(s);
  4229.                 return;
  4230.             }
  4231.             conoll("");
  4232.             conol("Refused: "); conoll(s); hpos = 0;
  4233.             return;
  4234.  
  4235.           case ST_INC:                  /* Incomplete */
  4236.             if (fdispla == XYFD_B) {
  4237.                 printf(": INCOMPLETE\n");
  4238.                 return;
  4239.             }
  4240.             if ((hpos += 12) > 78) conoll("");
  4241.             conoll(" [incomplete]"); hpos = 0;
  4242.             return;
  4243.  
  4244.           default:
  4245.             conoll("*** screen() called with bad status ***");
  4246.             hpos = 0;
  4247.             return;
  4248.         }
  4249.  
  4250. #ifdef MAC
  4251.       case SCR_PN:                      /* Packet number */
  4252.         if (fdispla == XYFD_B) {
  4253.             return;
  4254.         }
  4255.     ckmakmsg(buf,80,s,": ",ckltoa(n),NULL);
  4256.         conol(buf); hpos += (int)strlen(buf); return;
  4257. #endif /* MAC */
  4258.  
  4259.       case SCR_PT:                      /* Packet type or pseudotype */
  4260.         if (fdispla == XYFD_B)
  4261.           return;
  4262.         if (c == 'Y') return;           /* Don't bother with ACKs */
  4263.         if (c == 'D') {                 /* In data transfer phase, */
  4264.             showpkt(NUL);               /* show progress. */
  4265.             return;
  4266.         }
  4267. #ifndef AMIGA
  4268.         if (hpos++ > 77) {              /* If near right margin, */
  4269.             conoll("");                 /* Start new line */
  4270.             hpos = 0;                   /* and reset counter. */
  4271.         }
  4272. #endif /* AMIGA */
  4273.         if (c == 'Z' && fdispla == XYFD_S)
  4274.           return;
  4275.         else
  4276.           conoc(c);                     /* Display the packet type. */
  4277. #ifdef AMIGA
  4278.         if (c == 'G') conoll("");       /* New line after G packets */
  4279. #endif /* AMIGA */
  4280.         return;
  4281.  
  4282.       case SCR_TC:                      /* Transaction complete */
  4283.         if (xfrbel) bleep(BP_NOTE);
  4284.         if (fdispla == XYFD_B) {        /* Brief display... */
  4285.             if (filcnt > 1) {
  4286.                 long fx;
  4287.                 fx = filcnt - filrej;
  4288.                 printf(" SUMMARY: %ld file%s", fx, ((fx == 1) ? "" : "s"));
  4289.                 printf(", %s byte%s", ckfstoa(tfc), ((tfc == 1) ? "" : "s"));
  4290. #ifdef GFTIMER
  4291.                 printf(", %0.3f sec, %ld cps", fptsecs, tfcps);
  4292. #else
  4293.                 printf(", %ld sec, %ld cps", tsecs, tfcps);
  4294. #endif /* GFTIMER */
  4295.                 printf(".\n");
  4296.             }
  4297.         } else {
  4298.             conoll("");
  4299.         }
  4300. #ifdef UNIX
  4301.         fflush(stdout);
  4302. #endif /* UNIX */
  4303.         return;
  4304.  
  4305.       case SCR_EM:                      /* Error message */
  4306.         if (fdispla == XYFD_B) {
  4307.             printf(" ERROR: %s\n",s);
  4308.             return;
  4309.         }
  4310.         conoll(""); conoc('?'); conoll(s); hpos = 0; return;
  4311.  
  4312.       case SCR_WM:                      /* Warning message */
  4313.         if (fdispla == XYFD_B) {
  4314.             printf(" WARNING: %s\n",s);
  4315.             return;
  4316.         }
  4317.         conoll(""); conoll(s); hpos = 0; return;
  4318.  
  4319.       case SCR_MS:                      /* Message from other Kermit */
  4320.         if (fdispla == XYFD_B) {
  4321.             printf(" MESSAGE: %s\n",s);
  4322.             return;
  4323.         }
  4324.         conoll(""); conoll(s); hpos = 0; return;
  4325.  
  4326.       case SCR_TU:                      /* Undelimited text */
  4327.         if (fdispla == XYFD_B)
  4328.           return;
  4329.         if ((hpos += len) > 77) { conoll(""); hpos = len; }
  4330.         conol(s); return;
  4331.  
  4332.       case SCR_TN:                      /* Text delimited at beginning */
  4333.         if (fdispla == XYFD_B)
  4334.           return;
  4335.         conoll(""); conol(s); hpos = len; return;
  4336.  
  4337.       case SCR_TZ:                      /* Text delimited at end */
  4338.         if (fdispla == XYFD_B)
  4339.           return;
  4340.         if ((hpos += len) > 77) { conoll(""); hpos = len; }
  4341.         conoll(s); return;
  4342.  
  4343.       case SCR_QE:                      /* Quantity equals */
  4344.         if (fdispla == XYFD_B)
  4345.           return;
  4346.     ckmakmsg(buf,80,s,": ",ckltoa(n),NULL);
  4347.         conoll(buf); hpos = 0; return;
  4348.  
  4349.       case SCR_CW:                      /* Close fullscreen window */
  4350.         return;                         /* No window to close */
  4351.  
  4352.       case SCR_CD:
  4353.         return;
  4354.  
  4355.       default:
  4356.         conoll("*** screen() called with bad object ***");
  4357.         hpos = 0;
  4358.         return;
  4359.     }
  4360. }
  4361. #endif /* NODISPLAY */
  4362.  
  4363. /*  E R M S G  --  Nonfatal error message  */
  4364.  
  4365. /* Should be used only for printing the message text from an Error packet. */
  4366.  
  4367. VOID
  4368. ermsg(msg) char *msg; {                 /* Print error message */
  4369.     debug(F110,"ermsg",msg,0);
  4370.     if (local)
  4371.       xxscreen(SCR_EM,0,0L,msg);
  4372.     tlog(F110,"Protocol Error:",msg,0L);
  4373. }
  4374. #endif /* NOXFER */
  4375.  
  4376. VOID
  4377. setseslog(x) int x; {
  4378.     seslog = x;
  4379. #ifdef KUI
  4380.     KuiSetProperty(KUI_TERM_CAPTURE,x,0);
  4381. #endif /* KUI */
  4382. }
  4383.  
  4384. VOID
  4385. doclean(fc) int fc; {                   /* General cleanup */
  4386. #ifdef OS2ORUNIX
  4387.     extern int ttyfd;
  4388. #endif /* OS2ORUNIX */
  4389.     extern int  keep;
  4390.     extern int exithangup;
  4391. #ifndef NOXFER
  4392.     extern char filnam[];
  4393. #endif /* NOXFER */
  4394. #ifndef NOICP
  4395.     int x;
  4396.  
  4397.     if (fc > 0)
  4398.       dostop();                 /* Stop all command files and end macros */
  4399. #endif /* NOICP */
  4400.  
  4401. #ifndef NOXFER
  4402.     if (pktlog) {
  4403.         *pktfil = '\0';
  4404.         pktlog = 0;
  4405.         zclose(ZPFILE);
  4406.     }
  4407. #endif /* NOXFER */
  4408.     if (seslog) {
  4409.         *sesfil = '\0';
  4410.         setseslog(0);
  4411.         zclose(ZSFILE);
  4412.     }
  4413. #ifdef TLOG
  4414.     if (tralog) {
  4415.         tlog(F100,"Transaction Log Closed","",0L);
  4416.         *trafil = '\0';
  4417.         tralog = 0;
  4418.         zclose(ZTFILE);
  4419.     }
  4420. #endif /* TLOG */
  4421.  
  4422.     debug(F100,"doclean calling dologend","",0);
  4423.     dologend();                         /* End current log record if any */
  4424. #ifdef COMMENT
  4425.     if (dialog) {                       /* If connection log open */
  4426.     dialog = 0;
  4427.         *diafil = '\0';                 /* close it. */
  4428.         zclose(ZDIFIL);
  4429.     }
  4430. #endif /* COMMENT */
  4431.  
  4432. #ifndef NOICP
  4433. #ifndef NOSPL
  4434.     zclose(ZRFILE);                     /* READ and WRITE files, if any. */
  4435.     zclose(ZWFILE);
  4436. #ifndef NOXFER
  4437.     zclose(ZIFILE);                     /* And other files too */
  4438.     x = chkfn(ZOFILE);            /* Download in progress? */
  4439.     debug(F111,"doclean chkfn ZOFILE",filnam,x);
  4440.     debug(F111,"doclean keep","",keep);
  4441.     zclose(ZOFILE);            /* Close output file */
  4442.     if (x > 0 && !keep) {        /* If it was being downloaded */
  4443.     if (filnam[0])
  4444.       x = zdelet(filnam);        /* Delete if INCOMPLETE = DISCARD */
  4445.     debug(F111,"doclean download filename",filnam,x);
  4446.     }
  4447. #endif /* NOXFER */
  4448.     zclose(ZSYSFN);
  4449.     zclose(ZMFILE);
  4450.  
  4451.     if (fc < 1) {                       /* RESETing, not EXITing */
  4452. #ifdef DEBUG
  4453.         if (deblog) {                   /* Close the debug log. */
  4454.             *debfil = '\0';
  4455.             deblog = 0;
  4456.             zclose(ZDFILE);
  4457.         }
  4458. #endif /* DEBUG */
  4459.         return;
  4460.     }
  4461. #endif /* NOSPL */
  4462. #endif /* NOICP */
  4463.  
  4464. #ifndef NOLOCAL
  4465.     debug(F101,"doclean exithangup","",exithangup);
  4466.     if (local && exithangup) {        /* Close communication connection */
  4467.         extern int haslock;
  4468.     int x;
  4469.     
  4470.     x = ttchk();
  4471.     debug(F101,"doclean ttchk()","",x);
  4472. #ifdef OS2ORUNIX
  4473.     debug(F101,"doclean ttyfd","",ttyfd);
  4474. #endif /* OS2ORUNIX */
  4475.         if (x >= 0
  4476. #ifdef OS2
  4477.             || ttyfd != -1
  4478. #else
  4479. #ifdef UNIX
  4480.             || haslock                  /* Make sure we get lockfile! */
  4481.             || (!network && ttyfd > -1)
  4482. #endif /* UNIX */
  4483. #endif /* OS2 */
  4484.             ) {
  4485.             extern int wasclosed, whyclosed;
  4486.         debug(F100,"doclean hanging up and closing","",0);
  4487.             if (msgflg) {
  4488. #ifdef UNIX
  4489.                 fflush(stdout);
  4490. #endif /* UNIX */
  4491.                 printf("Closing %s...",ttname);
  4492.             }
  4493. #ifndef NODIAL
  4494.             mdmhup();                   /* Hangup the modem??? */
  4495. #endif /* NODIAL */
  4496.             ttclos(0);                  /* Close external line, if any */
  4497.             if (msgflg) {
  4498.                 printf("OK\n");
  4499. #ifdef UNIX
  4500.                 fflush(stdout);
  4501. #endif /* UNIX */
  4502.             }
  4503.             if (wasclosed) {
  4504.                 whyclosed = WC_CLOS;
  4505. #ifndef NOSPL
  4506.                 if (nmac) {             /* Any macros defined? */
  4507.                     int k;              /* Yes */
  4508.                     k = mlook(mactab,"on_close",nmac);  /* Look this up */
  4509.                     if (k >= 0) {                       /* If found, */
  4510.                         wasclosed = 0;
  4511.                         /* printf("ON_CLOSE DOCLEAN\n"); */
  4512.                         *(mactab[k].kwd) = NUL;         /* See comment below */
  4513.                         if (dodo(k,ckitoa(whyclosed),0) > -1) /* set it up, */
  4514.                           parser(1);                    /* and execute it */
  4515.                     }
  4516.                 }
  4517. #endif /* NOSPL */
  4518.                 wasclosed = 0;
  4519.             }
  4520.         }
  4521.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty */
  4522.         local = dfloc;                  /* And default remote/local status */
  4523.     }
  4524. #ifdef DEBUG
  4525.     else if (local) debug(F100,"doclean hangup/close skipped","",0);
  4526. #endif /* DEBUG */
  4527. #endif /* NOLOCAL */
  4528.  
  4529. #ifdef NEWFTP
  4530.     ftpbye();                /* If FTP connection open, close it */
  4531. #endif /* NEWFTP */
  4532.  
  4533. #ifdef IKSD
  4534.     if (inserver)
  4535.       ttclos(0);            /* If IKSD, close socket */
  4536. #endif /* IKSD */
  4537.  
  4538. #ifndef NOSPL
  4539. /*
  4540.   If a macro named "on_exit" is defined, execute it.  Also remove it from the
  4541.   macro table, in case its definition includes an EXIT or QUIT command, which
  4542.   would cause much recursion and would prevent the program from ever actually
  4543.   EXITing.
  4544. */
  4545.     if (nmac) {                         /* Any macros defined? */
  4546.         int k;                          /* Yes */
  4547.         char * cmd = "on_exit";         /* MSVC 2.x compiler error */
  4548.         k = mlook(mactab,cmd,nmac);     /* Look up "on_exit" */
  4549.         if (k >= 0) {                   /* If found, */
  4550. #ifdef COMMENT
  4551.         /* This makes a mess if ON_EXIT itself executes macros */
  4552.             *(mactab[k].kwd) = NUL;     /* poke its name from the table, */
  4553. #else
  4554.         /* Replace the keyword with something that doesn't wreck the */
  4555.         /* order of the keyword table */
  4556.         ckstrncpy(mactab[k].kwd,"on_exxx",8);
  4557. #endif /* COMMENT */
  4558.             if (dodo(k,"",0) > -1)      /* set it up, */
  4559.               parser(1);                /* and execute it */
  4560.         }
  4561.     }
  4562. #endif /* NOSPL */
  4563. /*
  4564.   Put console terminal back to normal.  This is done here because the
  4565.   ON_EXIT macro calls the parser, which meddles with console terminal modes.
  4566. */
  4567.     conres();                           /* Restore console terminal. */
  4568.  
  4569. #ifdef COMMENT
  4570. /* Should be no need for this, and maybe it's screwing things up? */
  4571.     connoi();                           /* Turn off console interrupt traps */
  4572. #endif /* COMMENT */
  4573.  
  4574.     /* Delete the Startup File if we are supposed to. */
  4575. #ifndef NOICP
  4576.     {
  4577.         extern int DeleteStartupFile;
  4578.         debug(F111,"doclean DeleteStartupFile",cmdfil,DeleteStartupFile);
  4579.         if (DeleteStartupFile) {
  4580.             int rc = zdelet(cmdfil);
  4581.             debug(F111,"doclean zdelet",cmdfil,rc);
  4582.         }
  4583.     }
  4584. #endif /* NOICP */
  4585.     syscleanup();                       /* System-dependent cleanup, last */
  4586. }
  4587.  
  4588. /*  D O E X I T  --  Exit from the program.  */
  4589.  
  4590. /*
  4591.   First arg is general, system-independent symbol: GOOD_EXIT or BAD_EXIT.
  4592.   If second arg is -1, take 1st arg literally.
  4593.   If second arg is not -1, work it into the exit code.
  4594. */
  4595. VOID
  4596. doexit(exitstat,code) int exitstat, code; {
  4597.     extern int x_logged, quitting;
  4598. #ifdef OS2
  4599.     extern int display_demo;
  4600.     extern int SysInited;
  4601. #endif /* OS2 */
  4602. #ifdef CK_KERBEROS
  4603. #ifdef KRB4
  4604.     extern int krb4_autodel;
  4605. #endif /* KRB4 */
  4606. #ifdef KRB5
  4607.     extern int krb5_autodel;
  4608. #endif /* KRB5 */
  4609. #endif /* CK_KERBEROS */
  4610.  
  4611. #ifdef VMS
  4612.     char envstr[64];
  4613.     static $DESCRIPTOR(symnam,"CKERMIT_STATUS");
  4614.     static struct dsc$descriptor_s symval;
  4615. #endif /* VMS */
  4616.     int i;
  4617.  
  4618. #ifdef DEBUG
  4619. #ifdef USE_LUCACHE
  4620.     extern long lucalls, luhits, xxhits, luloop;
  4621.     extern int lusize;
  4622. #endif /* USE_LUCACHE */
  4623. #ifndef NOSPL
  4624.     extern int cmdstats[];
  4625. #endif /* NOSPL */
  4626.  
  4627.     quitting++;
  4628.  
  4629. #ifdef OS2
  4630.     if ( !SysInited ) {
  4631.         static int initing = 0;
  4632.         if ( initing )
  4633.       exit(253);
  4634.         initing = 1;
  4635.         sysinit();
  4636.     }
  4637. #endif /* OS2 */
  4638.  
  4639.     if (deblog) {
  4640. #ifdef USE_LUCACHE
  4641.     debug(F101,"lookup cache size","",lusize);
  4642.     debug(F101,"lookup calls ....","",lucalls);
  4643.     debug(F101,"lookup cache hits","",luhits);
  4644.     debug(F101,"lookup start hits","",xxhits);
  4645.     debug(F101,"lookup loop iterations","",luloop);
  4646. #endif /* USE_LUCACHE */
  4647. #ifndef NOSPL
  4648.     for (i = 0; i < 256; i++) {
  4649.         if (cmdstats[i])
  4650.           debug(F111,"CMSTATS",ckitoa(i),cmdstats[i]);
  4651.     }
  4652. #endif /* NOSPL */
  4653.     debug(F101,"doexit exitstat","",exitstat);
  4654.     debug(F101,"doexit code","",code);
  4655.     debug(F101,"doexit xitsta","",xitsta);
  4656.     }
  4657. #endif /* DEBUG */
  4658.  
  4659. #ifdef CK_KERBEROS
  4660.     /* If we are automatically destroying Kerberos credentials on Exit */
  4661.     /* do it now. */
  4662. #ifdef KRB4
  4663.     if (krb4_autodel == KRB_DEL_EX) {
  4664.         extern struct krb_op_data krb_op;
  4665.         krb_op.version = 4;
  4666.         krb_op.cache = NULL;
  4667.         ck_krb4_destroy(&krb_op);
  4668.     }
  4669. #endif /* KRB4 */
  4670. #ifdef KRB5
  4671.     if (krb5_autodel == KRB_DEL_EX) {
  4672.         extern struct krb_op_data krb_op;
  4673.         extern char * krb5_d_cc;
  4674.         krb_op.version = 5;
  4675.         krb_op.cache = krb5_d_cc;
  4676.         ck_krb5_destroy(&krb_op);
  4677.     }
  4678. #endif /* KRB5 */
  4679. #endif /* CK_KERBEROS */
  4680.  
  4681. #ifndef NOLOCAL
  4682. #ifdef OS2
  4683.     if (SysInited)
  4684.     {
  4685. #ifdef DCMDBUF
  4686.         extern struct cmdptr *cmdstk;
  4687. #else
  4688.         extern struct cmdptr cmdstk[];
  4689. #endif /* DCMDBUF */
  4690.         extern int tt_status[];
  4691.         extern int vmode;
  4692.  
  4693.         /* If there is a demo screen to be displayed, display it */
  4694.         if (display_demo) {
  4695.             demoscrn(VCMD);
  4696.             display_demo = 0;
  4697.         }
  4698. #ifndef KUI
  4699.         /* This is going to be hideous.  If we have a status line */
  4700.         /* in the command window turn it off before we exit.      */
  4701.  
  4702.         if ( tt_status[VCMD] && vmode == VCMD ) {
  4703.             domac("_clear_statusline","set command statusline off",
  4704.                    cmdstk[cmdlvl].ccflgs);
  4705.             delmac("_clear_statusline",1);
  4706.             RequestScreenMutex(-1);
  4707.             VscrnIsDirty(vmode);
  4708.             ReleaseScreenMutex();
  4709.             while ( IsVscrnDirty(vmode) )
  4710.                 msleep(200);
  4711.             RequestScreenMutex(-1);
  4712.             ReleaseScreenMutex();
  4713.         }
  4714. #endif /* KUI */
  4715.         DialerSend(OPT_KERMIT_EXIT,exitstat);
  4716. #ifndef KUI
  4717.         debug(F100,"doexit about to msleep","",0);
  4718.  
  4719.         if ( isWin95() )
  4720.             msleep(250);
  4721. #endif /* KUI */
  4722.     }
  4723. #endif /* OS2 */
  4724. #endif /* NOLOCAL */
  4725.  
  4726. #ifdef IKSD
  4727. #ifdef CK_LOGIN
  4728.     if (inserver && x_logged) {
  4729. #ifndef NOSPL
  4730. /*
  4731.   If a macro named "on_logout" is defined, execute it.  Also remove it from the
  4732.   macro table, in case its definition includes an EXIT or QUIT command, which
  4733.   would cause much recursion and would prevent the program from ever actually
  4734.   EXITing.
  4735. */
  4736.     if (nmac) {            /* Any macros defined? */
  4737.         int k;            /* Yes */
  4738.         char * cmd = "on_logout";    /* MSVC 2.x compiler error */
  4739.         k = mlook(mactab,cmd,nmac);    /* Look up "on_logout" */
  4740.         if (k >= 0) {        /* If found, */
  4741.         *(mactab[k].kwd) = NUL;    /* poke its name from the table, */
  4742.         if (dodo(k,"",0) > -1)    /* set it up, */
  4743.           parser(1);        /* and execute it */
  4744.         }
  4745.     }
  4746. #endif /* NOSPL */
  4747.     zvlogout();
  4748.     }
  4749. #endif /* CK_LOGIN */
  4750. #endif /* IKSD */
  4751.  
  4752.     debug(F100,"doexit about to doclean","",0);
  4753.     doclean(1);                         /* Clean up most things */
  4754.  
  4755. #ifdef VMS
  4756.     if (code == -1)
  4757.       code = 0;                         /* Since we set two different items */
  4758.     sprintf(envstr,"%d", exitstat | code); /* SAFE */
  4759.     symval.dsc$w_length = (int)strlen(envstr);
  4760.     symval.dsc$a_pointer = envstr;
  4761.     symval.dsc$b_class = DSC$K_CLASS_S;
  4762.     symval.dsc$b_dtype = DSC$K_DTYPE_T;
  4763.     i = 2;                              /* Store in global table */
  4764. #ifdef COMMENT                          /* Martin Zinser */
  4765.     LIB$SET_SYMBOL(&symnam, &symval, &i);
  4766. #else
  4767.     lib$set_symbol(&symnam, &symval, &i);
  4768. #endif /* COMMENT */
  4769.     if (exitstat == BAD_EXIT)
  4770.       exitstat = SS$_ABORT | STS$M_INHIB_MSG;
  4771.     if (exitstat == GOOD_EXIT)
  4772.       exitstat = SS$_NORMAL | STS$M_INHIB_MSG;
  4773. #else /* Not VMS */
  4774.     if (code != -1)                     /* Take 1st arg literally */
  4775.       exitstat |= code;
  4776. #endif /* VMS */
  4777.  
  4778. #ifdef IKSD
  4779. #ifdef IKSDB
  4780.     debug(F101,"doexit ikdbopen","",ikdbopen);
  4781.     if (ikdbopen && dbfp) {             /* If IKSD database open */
  4782.         int x;
  4783.         x = freeslot(mydbslot);         /* Free our slot... */
  4784.         debug(F101,"doexit freeslot","",x);
  4785.         fclose(dbfp);                   /* and close it. */
  4786.     }
  4787. #endif /* IKSDB */
  4788. #endif /* IKSD */
  4789.  
  4790. /* We have put this off till the very last moment... */
  4791.  
  4792. #ifdef DEBUG
  4793.     if (deblog) {                       /* Close the debug log. */
  4794.         debug(F101,"C-Kermit EXIT status","",exitstat);
  4795.         *debfil = '\0';
  4796.         deblog = 0;
  4797.         zclose(ZDFILE);
  4798.     }
  4799. #endif /* DEBUG */
  4800.  
  4801. #ifdef OS2
  4802.     _exit(exitstat);            /* Exit from C-Kermit (no matter what) */
  4803. #else /* OS2 */
  4804.     exit(exitstat);                     /* Exit from C-Kermit */
  4805. #endif /* OS2 */
  4806. }
  4807.  
  4808. VOID
  4809. bgchk() {                               /* Check background status */
  4810.     if (bgset < 0) {                    /* They didn't type SET BACKGROUND */
  4811. #ifdef VMS                              /* Set prompt flag based on */
  4812.         pflag = !batch;                 /* what we detected at startup. */
  4813. #else
  4814.         pflag = !backgrd;
  4815. #endif /* VMS */
  4816.     } else {                            /* Otherwise SET BACKGROUND value */
  4817.         pflag = (bgset == 0 ? 1 : 0);
  4818.     }
  4819.  
  4820. #ifndef NOICP
  4821.     /* Message flag on only if at top level, pflag is on, and QUIET is OFF */
  4822.     if (!xcmdsrc)
  4823.       msgflg = (pflag == 0) ? 0 : !quiet;
  4824.     else msgflg = 0;
  4825. #else
  4826.     msgflg = 0;
  4827. #endif /* NOICP */
  4828. }
  4829.  
  4830. /* Set console interrupts */
  4831.  
  4832. VOID
  4833. setint() {                              /* According to SET COMMAND INTERRUP */
  4834.     int x = 0;
  4835.     if (cmdint)  x |= 1;
  4836.     if (xsuspend) x |= 2;
  4837.     debug(F101,"setint","",x);
  4838.  
  4839.     switch (x) {                        /* Set the desired combination */
  4840.       case 0: connoi(); break;          /* No interrupts */
  4841.       case 1: conint(trap,SIG_IGN); break;
  4842.       case 2: conint(SIG_IGN,stptrap); break;
  4843.       case 3: conint(trap,stptrap); break;
  4844.     }
  4845.     bgchk();                            /* Check background status */
  4846. }
  4847.  
  4848. #ifdef DEBUG
  4849. /*  D E B U G  --  Enter a record in the debugging log  */
  4850.  
  4851. /*
  4852.  Call with a format, two strings, and a number:
  4853.    f  - Format, a bit string in range 0-7.
  4854.         If bit x is on, then argument number x is printed.
  4855.    s1 - String, argument number 1.  If selected, printed as is.
  4856.    s2 - String, argument number 2.  If selected, printed in brackets.
  4857.    n  - Long int, argument 3.  If selected, printed preceded by equals sign.
  4858.  
  4859.    f=0 is special: print s1,s2, and interpret n as a char.
  4860.  
  4861.    f=F011 (3) is also special; in this case s2 is interpeted as a counted
  4862.    string that might contain NULs.  n is the length.  If n is negative, this
  4863.    means the string has been truncated and ".." should be printed after the
  4864.    first n bytes.  NUL and LF bytes are printed as "<NUL>" and "<LF>".
  4865.  
  4866.    Globals:
  4867.      deblog: nonzero if debug log open.
  4868.      debok:  nonzero if ok to write entries.
  4869. */
  4870. /*
  4871.   WARNING: Don't change DEBUFL without changing sprintf() formats below,
  4872.   accordingly.
  4873. */
  4874. #define DBUFL 4000
  4875. /*
  4876.   WARNING: This routine is not thread-safe, especially when Kermit is
  4877.   executing on multiple CPUs -- as different threads write to the same
  4878.   static buffer, the debug statements are all interleaved.  To be fixed
  4879.   later...
  4880. */
  4881. static char *dbptr = (char *)0;
  4882.  
  4883. int
  4884. #ifdef CK_ANSIC
  4885. dodebug(int f, char *s1, char *s2, CK_OFF_T n)
  4886. #else
  4887. dodebug(f,s1,s2,n) int f; char *s1, *s2; CK_OFF_T n;
  4888. #endif /* CK_ANSIC */
  4889. /* dodebug */ {
  4890.     char *sp;
  4891.     int len1, len2;
  4892.     extern int debtim;
  4893. #ifdef OS2
  4894.     extern int SysInited;
  4895. #endif /* OS2 */
  4896.  
  4897.     if (!deblog || !debok)
  4898.       return(0);
  4899.  
  4900. #ifdef COMMENT
  4901.     /* expensive... */
  4902.     if (!chkfn(ZDFILE))            /* Debug log not open, don't. */
  4903.       return(0);
  4904. #endif /* COMMENT */
  4905.     if (!dbptr) {                       /* Allocate memory buffer */
  4906.         dbptr = malloc(DBUFL+4);        /* This only happens once */
  4907.         if (!dbptr) {
  4908.             zclose(ZDFILE);
  4909.             return(0);
  4910.         }
  4911.     }
  4912. /*
  4913.   This prevents infinite recursion in case we accidentally put a debug()
  4914.   call in this routine, or call another routine that contains debug() calls.
  4915.   From this point on, all returns from this return must be via goto xdebug,
  4916.   which sets deblog back to 1.
  4917. */
  4918. #ifdef OS2
  4919.     if (SysInited) {
  4920.     if (RequestDebugMutex(30000))
  4921.         goto xdebug;
  4922.     }
  4923. #else /* OS2 */
  4924.     deblog = 0;                         /* Prevent infinite recursion */
  4925. #endif /* OS2 */
  4926.  
  4927.     if (debtim) {                       /* Timestamp */
  4928.         char *tb, tsbuf[48];
  4929.         ztime(&tb);
  4930.         ckstrncpy(tsbuf,tb,32);
  4931.         if (ztmsec > -1L) {
  4932.         sprintf(tsbuf+19,".%03ld ",ztmsec); /* SAFE */
  4933.     } else {
  4934.         tsbuf[19] = ':';
  4935.         tsbuf[20] = SP;
  4936.         tsbuf[21] = NUL;
  4937.     }
  4938.         zsout(ZDFILE,tsbuf+11);
  4939.     }
  4940.     if (!s1) s1="(NULL)";
  4941.     if (!s2) s2="(NULL)";
  4942.  
  4943.     len1 = strlen(s1);
  4944.     len2 = strlen(s2);
  4945.  
  4946. #ifdef COMMENT
  4947. /*
  4948.   This should work, but it doesn't.
  4949.   So instead we'll cope with overflow via sprintf formats.
  4950.   N.B.: UNFORTUNATELY, this means we have to put constants in the
  4951.   sprintf formats.
  4952. */
  4953.     if (f != F011 && (!f || (f & 6))) { /* String argument(s) included? */
  4954.         x = (int) strlen(s1) + (int) strlen(s2) + 18;
  4955.         if (x > dbufl) {                /* Longer than buffer? */
  4956.             if (dbptr)                  /* Yes, free previous buffer */
  4957.               free(dbptr);
  4958.             dbptr = (char *) malloc(x + 2); /* Allocate a new one */
  4959.             if (!dbptr) {
  4960.                 zsoutl(ZDFILE,"DEBUG: Memory allocation failure");
  4961.                 deblog = 0;
  4962.                 zclose(ZDFILE);
  4963.                 goto xdebug;
  4964.             } else {
  4965.                 dbufl = x;
  4966.                 sprintf(dbptr,"DEBUG: Buffer expanded to %d\n", x + 18);
  4967.                 zsoutl(ZDFILE,dbptr);
  4968.             }
  4969.         }
  4970.     }
  4971. #endif /* COMMENT */
  4972.  
  4973. #ifdef COMMENT
  4974. /* The aforementioned sprintf() formats were like this: */
  4975.         if (n > 31 && n < 127)
  4976.           sprintf(sp,"%.100s%.2000s:%c\n",s1,s2,(CHAR) n);
  4977.         else if (n < 32 || n == 127)
  4978.           sprintf(sp,"%.100s%.2000s:^%c\n",s1,s2,(CHAR) ((n+64) & 0x7F));
  4979.         else if (n > 127 && n < 160)
  4980.           sprintf(sp,"%.100s%.2000s:~^%c\n",s1,s2,(CHAR)((n-64) & 0x7F));
  4981.         else if (n > 159 && n < 256)
  4982.           sprintf(sp,"%.100s%.2000s:~%c\n",s1,s2,(CHAR) (n & 0x7F));
  4983.         else sprintf(sp,"%.100s%.2000s:%ld\n",s1,s2,n);
  4984. /*
  4985.   But, naturally, it turns out these are not portable either, so now
  4986.   we do the stupidest possible thing.
  4987. */
  4988. #endif /* COMMENT */
  4989.  
  4990. #ifdef BIGBUFOK
  4991. /* Need to accept longer strings when debugging authenticated connections */
  4992.     if (f == F010) {
  4993.         if (len2 + 2 >= DBUFL) s2 = "(string too long)";
  4994.     } else if (f != F011 && f != F100) {
  4995.         if (len1 > 100) s1 = "(string too long)";
  4996.         if (len2 + 101 >= DBUFL) s2 = "(string too long)";
  4997.     }
  4998. #else
  4999.     if (f != F011) {
  5000.         if (len1 > 100) s1 = "(string too long)";
  5001.         if (len2 + 101 >= DBUFL) s2 = "(string too long)";
  5002.     }
  5003. #endif /* BIGBUFOK */
  5004.  
  5005.     sp = dbptr;
  5006.  
  5007.     switch (f) {                /* Write log record according to format. */
  5008.       case F000:                /* 0 = print both strings, and n as a char. */
  5009.         if (len2 > 0) {
  5010.             if ((n > 31 && n < 127) || (n > 159 && n < 256))
  5011.               sprintf(sp,"%s[%s]=%c\n",s1,s2,(CHAR) n);
  5012.             else if (n < 32 || n == 127)
  5013.               sprintf(sp,"%s[%s]=^%c\n",s1,s2,(CHAR) ((n+64) & 0x7F));
  5014.             else if (n > 127 && n < 160)
  5015.               sprintf(sp,"%s[%s]=~^%c\n",s1,s2,(CHAR)((n-64) & 0x7F));
  5016.             else sprintf(sp,"%s[%s]=0x%lX\n",s1,s2,(long)n);
  5017.         } else {
  5018.             if ((n > 31 && n < 127) || (n > 159 && n < 256))
  5019.               sprintf(sp,"%s=%c\n",s1,(CHAR) n);
  5020.             else if (n < 32 || n == 127)
  5021.               sprintf(sp,"%s=^%c\n",s1,(CHAR) ((n+64) & 0x7F));
  5022.             else if (n > 127 && n < 160)
  5023.               sprintf(sp,"%s=~^%c\n",s1,(CHAR)((n-64) & 0x7F));
  5024.             else sprintf(sp,"%s=0x%lX\n",s1,(long)n);
  5025.         }
  5026.         if (zsout(ZDFILE,dbptr) < 0) {
  5027.             deblog = 0;
  5028.             zclose(ZDFILE);
  5029.         }
  5030. #ifdef CKSYSLOG
  5031.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5032.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5033.         }
  5034. #endif /* CKSYSLOG */
  5035.         break;
  5036.  
  5037.       case F001:                        /* 1, "=n" */
  5038. #ifdef COMMENT
  5039.         /* This was never used */
  5040.         sprintf(sp,"=%s\n",ckfstoa(n));
  5041. #else
  5042.         /* Like F111, but shows number n in hex */
  5043.     ckmakxmsg(sp,DBUFL,
  5044.           s1,
  5045.           (*s1 ? ":" : ""),
  5046.           s2,
  5047.           (*s2 ? ":" : ""),
  5048.           ckltox(n),
  5049.           "\n",
  5050.           NULL,NULL,NULL,NULL,NULL,NULL
  5051.           );
  5052. #endif /* COMMENT */
  5053.         if (zsout(ZDFILE,dbptr) < 0) {
  5054.             deblog = 0;
  5055.             zclose(ZDFILE);
  5056.         }
  5057. #ifdef CKSYSLOG
  5058.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5059.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5060.         }
  5061. #endif /* CKSYSLOG */
  5062.         break;
  5063.  
  5064. /*
  5065.   This one was never used so (October 2000) we now use it like F011,
  5066.   except in this case we treat s2 as NUL terminated.
  5067. */
  5068.       case F010:
  5069.     n = -debxlen;
  5070. /*
  5071.   This one treats n as the length of the string s2, which may contain NULs.
  5072.   It's good for logging NUL-bearing data in the debug log.
  5073. */
  5074.       case F011: {
  5075.       int i, j, contd = 0;
  5076.       char * p = s2, *pbuf = NULL;    /* p = source pointer */
  5077.       int m;            /* pbuf = destination pointer */
  5078.  
  5079.       if (f == F011) {
  5080.           if (n < 0) {        /* n = size of source */
  5081.           n = 0 - n;        /* Negative means to add "..." */
  5082.           contd = 1;
  5083.           }
  5084.       } else {
  5085.           int x, flag = 0;
  5086.           x = strlen(s2);
  5087.           if (n < 0) {
  5088.           flag = 1;
  5089.           n = 0 - n;
  5090.           }
  5091.           if (x < n)
  5092.         n = x;
  5093.       }
  5094.       if (n == 0)            /* 0 means do nothing */
  5095.         goto xdebug;
  5096.       m = DBUFL - 8;        /* Get size for interpreted part */
  5097.       if (n > m)            /* Ensure requested size not too big */
  5098.         n = m;
  5099.       pbuf = dbptr;            /* Construction pointer */
  5100.       i = 0;
  5101.       pbuf[i++] = '[';        /* Interpret the string into it */
  5102.       for (j = 0; j < n && i < m-4; p++,j++) { /* char by char... */
  5103.           if (*p == LF) {
  5104.           if (i >= m-4)
  5105.             break;
  5106.           pbuf[i++] = '<';
  5107.           pbuf[i++] = 'L';
  5108.           pbuf[i++] = 'F';
  5109.           pbuf[i++] = '>';
  5110.           continue;
  5111.           } else if (*p == CR) {
  5112.           if (i >= m-4)
  5113.             break;
  5114.           pbuf[i++] = '<';
  5115.           pbuf[i++] = 'C';
  5116.           pbuf[i++] = 'R';
  5117.           pbuf[i++] = '>';
  5118.           continue;
  5119.           } else if (*p == HT) {
  5120.           if (i >= m-5)
  5121.             break;
  5122.           pbuf[i++] = '<';
  5123.           pbuf[i++] = 'T';
  5124.           pbuf[i++] = 'A';
  5125.           pbuf[i++] = 'B';
  5126.           pbuf[i++] = '>';
  5127.           continue;
  5128.           } else if (*p) {
  5129.           pbuf[i++] = *p;
  5130.           continue;
  5131.           } else {
  5132.           if (i >= m-5)
  5133.             break;
  5134.           pbuf[i++] = '<';
  5135.           pbuf[i++] = 'N';
  5136.           pbuf[i++] = 'U';
  5137.           pbuf[i++] = 'L';
  5138.           pbuf[i++] = '>';
  5139.           continue;
  5140.           }
  5141.       }
  5142.       if (i < m-2 && (*p || contd)) {
  5143.           pbuf[i++] = '.';
  5144.           pbuf[i++] = '.';
  5145.       }
  5146.       pbuf[i++] = ']';
  5147.       pbuf[i] = NUL;
  5148.       if (zsout(ZDFILE,s1) < 0) {
  5149.           deblog = 0;
  5150.           zclose(ZDFILE);
  5151.       }
  5152.       if (zsoutl(ZDFILE,pbuf) < 0) {
  5153.           deblog = 0;
  5154.           zclose(ZDFILE);
  5155.       }
  5156. #ifdef CKSYSLOG
  5157.       if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5158.           cksyslog(SYSLG_DB,1,"debug",s1,pbuf);
  5159.       }
  5160. #endif /* CKSYSLOG */
  5161.         }
  5162.         break;
  5163.  
  5164.       case F100:                        /* 4, "s1" */
  5165.         if (zsoutl(ZDFILE,s1) < 0) {
  5166.             deblog = 0;
  5167.             zclose(ZDFILE);
  5168.         }
  5169. #ifdef CKSYSLOG
  5170.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5171.             cksyslog(SYSLG_DB,1,"debug",s1,NULL);
  5172.         }
  5173. #endif /* CKSYSLOG */
  5174.         break;
  5175.       case F101:                        /* 5, "s1=n" */
  5176.         sprintf(sp,"%s=%s\n",s1,ckfstoa(n));
  5177.         if (zsout(ZDFILE,dbptr) < 0) {
  5178.             deblog = 0;
  5179.             zclose(ZDFILE);
  5180.         }
  5181. #ifdef CKSYSLOG
  5182.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5183.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5184.         }
  5185. #endif /* CKSYSLOG */
  5186.         break;
  5187.       case F110:                        /* 6, "s1[s2]" */
  5188.         sprintf(sp,"%s[%s]\n",s1,s2);
  5189.         if (zsout(ZDFILE,dbptr) < 0) {
  5190.             deblog = 0;
  5191.             zclose(ZDFILE);
  5192.         }
  5193. #ifdef CKSYSLOG
  5194.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5195.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5196.         }
  5197. #endif /* CKSYSLOG */
  5198.         break;
  5199.       case F111:                        /* 7, "s1[s2]=n" */
  5200.         sprintf(sp,"%s[%s]=%s\n",s1,s2,ckfstoa(n));
  5201.         if (zsout(ZDFILE,dbptr) < 0) {
  5202.             deblog = 0;
  5203.             zclose(ZDFILE);
  5204.         }
  5205. #ifdef CKSYSLOG
  5206.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5207.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5208.         }
  5209. #endif /* CKSYSLOG */
  5210.         break;
  5211.       default:
  5212.         sprintf(sp,"\n?Invalid format for debug() - %d\n",f);
  5213.         if (zsout(ZDFILE,dbptr) < 0) {
  5214.             deblog = 0;
  5215.             zclose(ZDFILE);
  5216.         }
  5217. #ifdef CKSYSLOG
  5218.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5219.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5220.         }
  5221. #endif /* CKSYSLOG */
  5222.         break;
  5223.     }
  5224.   xdebug:                               /* Common exit point */
  5225. #ifdef OS2
  5226.     if (SysInited)
  5227.     ReleaseDebugMutex();
  5228. #else /* OS2 */
  5229.     deblog = 1;                         /* Restore this */
  5230. #endif /* OS2 */
  5231.     return(0);
  5232. }
  5233.  
  5234. int
  5235. #ifdef CK_ANSIC
  5236. dohexdump(CHAR *msg, CHAR *st, int cnt)
  5237. #else
  5238. dohexdump(msg,st,cnt) CHAR *msg; CHAR *st; int cnt;
  5239. #endif /* CK_ANSIC */
  5240. /* dohexdump */ {
  5241.     int i = 0, j = 0, k = 0;
  5242.     char tmp[8];
  5243. #ifdef OS2
  5244.     extern int SysInited;
  5245. #endif /* OS2 */
  5246.  
  5247.     if (!deblog) return(0);        /* If no debug log, don't. */
  5248.     if (!dbptr) {                       /* Allocate memory buffer */
  5249.         dbptr = malloc(DBUFL+1);        /* This only happens once */
  5250.         if (!dbptr) {
  5251.             deblog = 0;
  5252.             zclose(ZDFILE);
  5253.             return(0);
  5254.         }
  5255.     }
  5256.  
  5257. #ifdef OS2
  5258.     if (SysInited) {
  5259.     if (RequestDebugMutex(30000))
  5260.         goto xdebug;
  5261.     }
  5262. #else /* OS2 */
  5263.     deblog = 0;                         /* Prevent infinite recursion */
  5264. #endif /* OS2 */
  5265.  
  5266.     if (msg != NULL) {
  5267.     ckmakxmsg(dbptr,
  5268.           DBUFL,
  5269.           "HEXDUMP: ",
  5270.           (char *)msg,
  5271.           " (",
  5272.           ckitoa(cnt),
  5273.           " bytes)\n",
  5274.           NULL,NULL,NULL,NULL,NULL,NULL,NULL
  5275.          );
  5276.         if (zsout(ZDFILE,dbptr) < 0) {
  5277.             deblog = 0;
  5278.             zclose(ZDFILE);
  5279.         goto xdebug;
  5280.         }
  5281.     } else {
  5282.     ckmakmsg(dbptr,
  5283.          DBUFL,
  5284.          "HEXDUMP: (",
  5285.          ckitoa(cnt),
  5286.          " bytes)\n",
  5287.          NULL
  5288.          );
  5289.         zsout(ZDFILE,dbptr);
  5290.         if (zsout(ZDFILE,dbptr) < 0) {
  5291.             deblog = 0;
  5292.             zclose(ZDFILE);
  5293.         goto xdebug;
  5294.         }
  5295.     }
  5296.     for (i = 0; i < cnt; i++) {
  5297.         dbptr[0] = '\0';
  5298.         for (j = 0 ; (j < 16); j++) {
  5299.             if ((i + j) < cnt)
  5300.           sprintf(tmp,
  5301.               "%s%02x ",
  5302.               (j == 8 ? "| " : ""),
  5303.               (CHAR) st[i + j]
  5304.               );
  5305.             else
  5306.           sprintf(tmp,
  5307.               "%s   ",
  5308.               (j == 8 ? "| " : "")
  5309.               );
  5310.             ckstrncat(dbptr,tmp,DBUFL+1);
  5311.         }
  5312.         ckstrncat(dbptr," ",DBUFL+1);
  5313.         for (k = 0; (k < 16) && ((i + k) < cnt); k++) {
  5314.             sprintf(tmp,
  5315.                     "%s%c",
  5316.                     (k == 8 ? " " : ""),
  5317.                     isprint(st[i + k]) ? st[i + k] : '.'
  5318.                     );
  5319.             ckstrncat(dbptr,tmp,DBUFL+1);
  5320.         }
  5321.         ckstrncat(dbptr,"\n",DBUFL+1);
  5322.         i += j - 1;
  5323.         if (zsout(ZDFILE,dbptr) < 0) {
  5324.             deblog = 0;
  5325.             zclose(ZDFILE);
  5326.         goto xdebug;
  5327.         }
  5328.     } /* end for */
  5329.  
  5330.  
  5331.   xdebug:
  5332. #ifdef OS2
  5333.     if (SysInited)
  5334.       ReleaseDebugMutex();
  5335. #else /* OS2 */
  5336.     deblog = 1;
  5337. #endif /* OS2 */
  5338.     return(0);
  5339. }
  5340. #endif /* DEBUG */
  5341.  
  5342. /*  Session Log... */
  5343.  
  5344. extern int slogts;            /* Session Log timestamps */
  5345. int tsstate = 0;
  5346.  
  5347. VOID
  5348. #ifdef OS2
  5349. logchar(unsigned short c)
  5350. #else /* OS2 */
  5351. #ifdef CK_ANSIC
  5352. logchar(char c)
  5353. #else
  5354. logchar(c) char c;
  5355. #endif /* CK_ANSIC */
  5356. #endif /* OS2 */
  5357. /* logchar */ {                         /* Log character c to session log */
  5358.     int oktolog = 0;
  5359. #ifndef NOLOCAL
  5360.     if (!seslog)
  5361.       return;
  5362.  
  5363.     if ((sessft != XYFT_T) ||
  5364.     (c != '\0' &&
  5365. #ifdef UNIX
  5366.      c != '\r' &&
  5367. #else
  5368. #ifdef datageneral
  5369.      c != '\r' &&
  5370. #else
  5371. #ifdef STRATUS
  5372.      c != '\r' &&
  5373. #else
  5374. #ifdef AMIGA
  5375.      c != '\r' &&
  5376. #else
  5377. #ifdef GEMDOS
  5378.      c != '\r' &&
  5379. #endif /* GEMDOS */
  5380. #endif /* AMIGA */
  5381. #endif /* STRATUS */
  5382. #endif /* datageneral */
  5383. #endif /* UNIX */
  5384. #ifdef OSK
  5385.      c != '\n' &&
  5386. #else
  5387. #ifdef MAC
  5388.      c != '\n' &&
  5389. #endif /* MAC */
  5390. #endif /* OSK */
  5391.      c != XON &&
  5392.      c != XOFF))
  5393.       oktolog = 1;
  5394.     if (!oktolog)
  5395.       return;
  5396.     if (slogts) {            /* Log is timestamped */
  5397.     if (tsstate == 0) {        /* State = between-lines */
  5398.         char * p;            /* zstime() pointer */
  5399.         char ts[48];        /* timestamp buffer */
  5400.         ztime(&p);            /* Get asctime() string */
  5401.         ckstrncpy(ts,p,32);        /* Make safe copy */
  5402.         if (ztmsec > -1L) {        /* Add msecs if we have them */
  5403.         sprintf(&ts[19],".%03ld: ",ztmsec); /* SAFE */
  5404.         } else {
  5405.         ts[19] = ':';
  5406.         ts[20] = SP;
  5407.         ts[21] = NUL;
  5408.         }
  5409.         if (zsout(ZSFILE,&ts[11]) < 0)
  5410.           goto xlogchar;
  5411.         if (c != '\n')        /* If this is not eol */
  5412.           tsstate = 1;        /* go to in-a-line state. */
  5413.     } else if (c == '\n') {        /* In a line */
  5414.         tsstate = 0;        /* If eol go to between-lines state. */
  5415.     }
  5416.     }
  5417.     if (zchout(ZSFILE,(CHAR)(c & 0xFF)) < 0) /* Log the character */
  5418.       goto xlogchar;
  5419.     return;
  5420.  
  5421.   xlogchar:
  5422.     conoll("");
  5423.     conoll("ERROR WRITING SESSION LOG, LOG CLOSED!");
  5424.     setseslog(0);
  5425.     zclose(ZSFILE);
  5426. #endif /* NOLOCAL */
  5427. }
  5428.  
  5429. VOID
  5430. logstr(s, len) char * s; int len; {     /* Log string to session log */
  5431. #ifndef NOLOCAL
  5432.     int n = 0;
  5433.     if (!s)
  5434.       return;
  5435.     while (seslog && (n < len))
  5436.       logchar(s[n++]);
  5437. #endif /* NOLOCAL */
  5438. }
  5439.  
  5440. #ifdef CK_CURSES
  5441. int
  5442. ck_repaint() {
  5443.     repaint = 1;
  5444.     return(0);
  5445. }
  5446.  
  5447. #ifdef STRATUS
  5448. /* VOS has curses but no tgetent() */
  5449. int
  5450. tgetent(s1, s2) char * s1, * s2; {
  5451.     return(1);
  5452. }
  5453. #endif /* STRATUS */
  5454.  
  5455. #ifdef VMS
  5456. #ifdef __DECC
  5457. _PROTOTYP(int tgetent,(char *, char *));
  5458. #endif /* __DECC */
  5459. #endif /* VMS */
  5460.  
  5461. /*
  5462.   There are three different ways to do fullscreen on VMS.
  5463.   1. Use the real curses library, VAXCCURSE.
  5464.   2. Use do-it-yourself code.
  5465.   3. Use the Screen Manager, SMG$.
  5466.  
  5467.   Method 1 doesn't work quite right; you can't call endwin(), so once you've
  5468.   started curses mode, you can never leave.
  5469.  
  5470.   Method 2 doesn't optimize the screen, and so much more time is spent in
  5471.   screen writes.  This actually causes file transfers to fail because the
  5472.   tty device input buffer can be overrun while the screen is being updated,
  5473.   especially on a slow MicroVAX that has small typeahead buffers.
  5474.  
  5475.   In the following #ifdef block, #define one of them and #undef the other 2.
  5476.  
  5477.   So now let's try method 3...
  5478. */
  5479. #ifdef VMS
  5480. #define CK_SMG                          /* Screen Manager */
  5481. #undef MYCURSES                         /* Do-it-yourself */
  5482. #undef VMSCURSE                         /* VAXCCURSE library */
  5483. #endif /* VMS */
  5484. /*
  5485.   But just before New Years, 2000, the SMG library seemed to break on
  5486.   both VMS systems we have here (an Alpha with VMS 7.1 and a VAX with 5.5).
  5487.   So back to MYCURSES, which works fine.
  5488. */
  5489. #ifdef VMS
  5490. #undef CK_SMG
  5491. #define MYCURSES
  5492. #endif /* VMS */
  5493.  
  5494. #ifdef MYCURSES
  5495. #define stdscr 0
  5496. #ifdef CK_WREFRESH
  5497. #undef CK_WREFRESH
  5498. #endif /* CK_WREFRESH */
  5499. #endif /* MYCURSES */
  5500.  
  5501. /*  S C R E E N C  --  Screen display function, uses curses  */
  5502.  
  5503. /* Idea for curses display contributed by Chris Pratt of APV Baker, UK */
  5504.  
  5505. /* Avoid conficts with curses.h */
  5506.  
  5507. #ifdef QNX
  5508. /* Same as ckcasc.h, but in a different radix... */
  5509. #ifdef ESC
  5510. #undef ESC
  5511. #endif /* ESC */
  5512. #endif /* QNX */
  5513.  
  5514. #ifndef MYCURSES
  5515. #undef VOID                             /* This was defined in ckcdeb.h */
  5516. #endif /* MYCURSES */
  5517.  
  5518. #undef BS                               /* These were defined in ckcasc.h */
  5519. #undef CR
  5520. #undef NL
  5521. #undef SO
  5522. #undef US
  5523. #undef SP                               /* Used in ncurses */
  5524. #define CHR_SP 32                       /* Use this instead */
  5525.  
  5526. #ifdef VMS                              /* VMS fullscreen display */
  5527. #ifdef MYCURSES                         /* Do-it-yourself method */
  5528. extern int isvt52;                      /* From CKVTIO.C */
  5529. #define printw printf
  5530. #else
  5531. #ifdef VMSCURSE                         /* VMS curses library VAXCCURSE */
  5532. #include <curses.h>
  5533. /* Note: Screen manager doesn't need a header file */
  5534. #endif /* VMSCURSE */
  5535. #endif /* MYCURSES */
  5536. #else                                   /* Not VMS */
  5537. #ifdef MYCURSES                         /* Do-it-yourself method */
  5538. #define isvt52 0                        /* Used by OS/2, VT-100/ANSI always */
  5539. #ifdef CKXPRINTF
  5540. #define printw ckxprintf
  5541. #else /* CKXPRINTF */
  5542. #ifdef KUI
  5543. #define printw Vscrnprintw
  5544. #else /* KUI */
  5545. #define printw printf
  5546. #endif /* KUI */
  5547. #endif /* CKXPRINTF */
  5548. #else                                   /* Use real curses */
  5549. #ifdef CK_NCURSES                       /* or ncurses... */
  5550. #ifdef CKXPRINTF                        /* Our printf macro conflicts with */
  5551. #undef printf                           /* use of "printf" in ncurses.h */
  5552. #endif /* CKXPRINTF */
  5553. #include <ncurses.h>
  5554. #ifdef CKXPRINTF
  5555. #define printf ckxprintf
  5556. #endif /* CKXPRINTF */
  5557. #else  /* Not ncurses */
  5558. #ifdef CKXPRINTF                        /* Our printf macro conflicts with */
  5559. #undef printf                           /* use of "printf" in curses.h */
  5560. #endif /* CKXPRINTF */
  5561. #ifdef M_XENIX                /* SCO XENIX... */
  5562. #ifdef M_TERMCAP
  5563. #undef M_TERMCAP
  5564. #endif /* M_TERMCAP */
  5565. #ifndef M_TERMINFO
  5566. #define M_TERMINFO
  5567. #endif /* M_TERMINFO */
  5568. #endif /* M_XENIX */
  5569. #ifdef RTAIX
  5570. #undef NLS                /* Avoid 'redeclaration of free'. */
  5571. #endif /* RTAIX */
  5572. #include <curses.h>
  5573. #ifdef CKXPRINTF
  5574. #define printf ckxprintf
  5575. #endif /* CKXPRINTF */
  5576. #endif /* CK_NCURSES */
  5577. #endif /* MYCURSES */
  5578. #endif /* VMS */
  5579.  
  5580. #endif /* CK_CURSES */
  5581.  
  5582. /*  F X D I N I T  --  File Xfer Display Initialization  */
  5583.  
  5584. #ifdef CK_CURSES
  5585. #ifndef MYCURSES
  5586. #ifndef CK_SMG
  5587. static
  5588. #ifdef CK_ANSIC
  5589. /* Can't use VOID because of curses.h */
  5590. void
  5591. ck_termset(int);
  5592. #else
  5593. ck_termset();
  5594. #endif /* CK_ANSIC */
  5595. #endif /* CK_SMG */
  5596. #endif /* MYCURSES */
  5597. #endif /* CK_CURSES */
  5598.  
  5599. #ifdef NOTERMCAP
  5600. static int notermcap = 1;
  5601. #else
  5602. static int notermcap = 0;
  5603. #endif /* NOTERMCAP */
  5604.  
  5605. #ifndef NODISPLAY
  5606. #ifdef OSK
  5607. VOID
  5608. #else
  5609. #ifdef CK_ANSIC
  5610. void
  5611. #endif /* CKANSIC */
  5612. #endif /* OSK */
  5613. fxdinit(xdispla) int xdispla; {
  5614. #ifndef COHERENT
  5615. #ifndef OS2
  5616. #ifndef STRATUS
  5617.     char *s;
  5618.     int x, dummy;
  5619.  
  5620.     debug(F101,"fxdinit xdispla","",xdispla);
  5621.     debug(F101,"fxdinit fxd_inited","",fxd_inited);
  5622.  
  5623. #ifdef IKSD
  5624. #ifndef NOXFER
  5625.     /* No curses for IKSD */
  5626.     if (inserver) {
  5627.         fdispla = XYFD_N;
  5628.         return;
  5629.     }
  5630.     if (fxd_inited)                     /* Only do this once */
  5631.       return;
  5632. #endif /* NOXFER */
  5633. #endif /* IKSD */
  5634.  
  5635.     if (xdispla == XYFD_R || xdispla == XYFD_S || xdispla == XYFD_B) {
  5636.     if (xfrmsg) {
  5637.         printf("%s\n",xfrmsg);
  5638.         makestr(&xfrmsg,NULL);
  5639.     }
  5640.     }
  5641.  
  5642. #ifdef CK_CURSES
  5643. #ifdef VMS
  5644.     /* Force BRIEF in Batch logs */
  5645.     if (batch && (xdispla == XYFD_C || xdispla == XYFD_S))
  5646.       xdispla = XYFD_B;
  5647. #else
  5648.     if (xdispla == XYFD_C || xdispla == 9999) {
  5649.  
  5650. #ifdef DYNAMIC
  5651.         if (!trmbuf) {
  5652. /*
  5653.   Allocate tgetent() buffer.  Make it big -- some termcaps can be huge;
  5654.   tgetent() merrily writes past the end of the buffer, causing core dumps
  5655.   or worse.
  5656. */
  5657.             trmbuf = (char *)malloc(TRMBUFL);
  5658.             if (!trmbuf) {
  5659.                 notermcap = 1;
  5660.                 debug(F101,"fxdinit malloc trmbuf","FAILED",TRMBUFL);
  5661.                 fdispla = XYFD_S;
  5662.                 return;
  5663.             }
  5664. #ifdef COMMENT
  5665.             debug(F111,"fxdinit malloc trmbuf","OK",TRMBUFL);
  5666.             debug(F001,"fxdinit trmbuf","",trmbuf);
  5667.             memset(trmbuf,'\0',(size_t)TRMBUFL);
  5668.             debug(F100,"fxdinit memset OK","",0);
  5669. #endif /* COMMENT */
  5670.         }
  5671. #endif /* DYNAMIC */
  5672.  
  5673.         debug(F100,"fxdinit before getenv(TERM)","",0);
  5674.         s = getenv("TERM");
  5675.         debug(F110,"fxdinit after getenv(TERM)",s,0);
  5676.         if (!s) s = "";
  5677.         if (*s) {
  5678.             debug(F110,"fxdinit before tgetent()",s,0);
  5679.             x = tgetent(trmbuf,s);
  5680.             debug(F111,"fxdinit tgetent",s,x);
  5681.         } else {
  5682.             x = 0;
  5683.             notermcap = 1;
  5684.             debug(F110,"fxdinit TERM null - no tgetent",s,0);
  5685.         }
  5686.         if (x < 1 && !quiet && !backgrd
  5687. #ifdef VMS
  5688.             && !batch
  5689. #endif /* VMS */
  5690.             ) {
  5691.             printf("Warning: terminal type unknown: \"%s\"\n",s);
  5692. #ifdef COMMENT
  5693.         /* Confusing - nobody knows what this means */
  5694.             printf("SCREEN command will use ANSI sequences.\n");
  5695. #endif /* COMMENT */
  5696.             if (local)
  5697.               printf("Fullscreen file transfer display disabled.\n");
  5698.             fdispla = XYFD_S;
  5699.         }
  5700. #ifndef MYCURSES
  5701. #ifndef CK_SMG
  5702.         ck_termset(x);
  5703. #endif /* CK_SMG */
  5704. #endif /* MYCURSES */
  5705.         fxd_inited = 1;
  5706.     }
  5707. #endif /* CK_CURSES */
  5708. #endif /* VMS */
  5709. #endif /* STRATUS */
  5710. #endif /* OS2 */
  5711. #endif /* COHERENT */
  5712. }
  5713. #endif /* NODISPLAY */
  5714.  
  5715. #ifdef CK_CURSES
  5716. #ifdef CK_SMG
  5717. /*
  5718.   Long section for Screen Manager starts here...
  5719.   By William Bader.
  5720. */
  5721. #include "ckvvms.h"
  5722. #ifdef OLD_VMS
  5723. #include <smgdef.h>                     /* use this on VAX C 2.4 */
  5724. /* #include <smgmsg.h> */
  5725. #else
  5726. #include <smg$routines.h>               /* Martin Zinser */
  5727. #endif /* OLD_VMS */
  5728.  
  5729. extern unsigned int vms_status;     /* Used for system service return status */
  5730.  
  5731. static long smg_pasteboard_id = -1;     /* pasteboard identifier */
  5732. static long smg_display_id = -1;        /* display identifier */
  5733. static int smg_open = 0;                /* flag if smg current open */
  5734. static int smg_inited = 0;              /* flag if smg initialized */
  5735.  
  5736. #ifdef COMMENT
  5737. #define clrtoeol()      SMG$ERASE_LINE(&smg_display_id, 0, 0)
  5738.  
  5739. #define clear()         SMG$ERASE_DISPLAY(&smg_display_id, 0, 0, 0, 0)
  5740.  
  5741. #define touchwin(scr)   SMG$REPAINT_SCREEN(&smg_pasteboard_id)
  5742.  
  5743. #else  /* Not COMMENT */
  5744.  
  5745. #define clrtoeol()      smg$erase_line(&smg_display_id, 0, 0)
  5746.  
  5747. #define clear()         smg$erase_display(&smg_display_id, 0, 0, 0, 0)
  5748.  
  5749. #define touchwin(scr)   smg$repaint_screen(&smg_pasteboard_id)
  5750. #endif /* COMMENT */
  5751.  
  5752. #define clearok(curscr,ok)              /* Let wrefresh() do the work */
  5753.  
  5754. #define wrefresh(cursrc) touchwin(scr)
  5755.  
  5756. static void
  5757. move(row, col) int row, col; {
  5758.     /* Change from 0-based for curses to 1-based for SMG */
  5759.     if (!smg_open)
  5760.       return;
  5761.     ++row; ++col;
  5762.     debug(F111,"VMS smg move",ckitoa(row),col);
  5763. #ifdef COMMENT                          /* Martin Zinser */
  5764.     CHECK_ERR("move: smg$set_cursor_abs",
  5765.               SMG$SET_CURSOR_ABS(&smg_display_id, &row, &col));
  5766. #else
  5767.     CHECK_ERR("move: smg$set_cursor_abs",
  5768.               smg$set_cursor_abs(&smg_display_id, &row, &col));
  5769. #endif /* COMMENT */
  5770.     debug(F101,"VMS smg move vms_status","",vms_status);
  5771. }
  5772.  
  5773. #ifdef VMS_V40
  5774. #define OLD_VMS
  5775. #endif /* VMS_V40 */
  5776. #ifdef VMS_V42
  5777. #define OLD_VMS
  5778. #endif /* VMS_V42 */
  5779. #ifdef VMS_V44
  5780. #define OLD_VMS
  5781. #endif /* VMS_V44 */
  5782.  
  5783. static int
  5784. initscr() {
  5785.     int rows = 24, cols = 80;
  5786.     int row = 1, col = 1;
  5787.  
  5788.     debug(F101,"VMS initscr smg_pasteboard_id A","",smg_pasteboard_id);
  5789.  
  5790.     if (smg_pasteboard_id == -1) { /* Open the screen */
  5791. #ifdef OLD_VMS                     /* Note: Routine calls lowercased 9/96 */
  5792.         CHECK_ERR("initscr: smg$create_pasteboard",
  5793.                   smg$create_pasteboard(&smg_pasteboard_id, 0, 0, 0, 0));
  5794. #else
  5795.         /* For VMS V5, not tested */
  5796.         CHECK_ERR("initscr: smg$create_pasteboard",
  5797.                   smg$create_pasteboard(&smg_pasteboard_id, 0, 0, 0, 0, 0));
  5798. #endif /* OLD_VMS */
  5799.     }
  5800.     debug(F101,"VMS initscr smg_pasteboard_id B","",smg_pasteboard_id);
  5801.     if (smg_pasteboard_id == -1) {
  5802.     printf("?Error initializing fullscreen display\n");
  5803.     fdispla = XYFD_S;
  5804.     dpyinit();
  5805.     return(0);
  5806.     }
  5807.     debug(F101,"VMS initscr smg_display_id","",smg_display_id);
  5808.     if (smg_display_id == -1) {         /* Create a display window */
  5809.  
  5810. #ifdef COMMENT                          /* Martin Zinser */
  5811.         CHECK_ERR("initscr: smg$create_virtual_display",
  5812.                   SMG$CREATE_VIRTUAL_DISPLAY(&rows, &cols, &smg_display_id,
  5813.                                              0, 0, 0));
  5814.  
  5815.         /* Connect the display window to the screen */
  5816.         CHECK_ERR("initscr: smg$paste_virtual_display",
  5817.                   SMG$PASTE_VIRTUAL_DISPLAY(&smg_display_id,&smg_pasteboard_id,
  5818.                                             &row,&col));
  5819. #else
  5820.         CHECK_ERR("initscr: smg$create_virtual_display",
  5821.                   smg$create_virtual_display(&rows, &cols, &smg_display_id,
  5822.                                              0, 0, 0));
  5823.  
  5824.         /* Connect the display window to the screen */
  5825.         CHECK_ERR("initscr: smg$paste_virtual_display",
  5826.                   smg$paste_virtual_display(&smg_display_id,&smg_pasteboard_id,
  5827.                                             &row,&col));
  5828. #endif /* COMMENT */
  5829.     }
  5830.     debug(F101,"VMS initscr smg_open A","",smg_open);
  5831.     if (!smg_open) {                    /* Start a batch update */
  5832.         smg_open = 1;
  5833. #ifdef COMMENT
  5834.         CHECK_ERR("initscr: smg$begin_pasteboard_update",
  5835.                   SMG$BEGIN_PASTEBOARD_UPDATE(&smg_pasteboard_id));
  5836. #else
  5837.         CHECK_ERR("initscr: smg$begin_pasteboard_update",
  5838.                   smg$begin_pasteboard_update(&smg_pasteboard_id));
  5839. #endif /* COMMENT */
  5840.     debug(F101,"VMS initscr smg$begin_pasteboard_update","",vms_status);
  5841.     }
  5842.     debug(F101,"VMS initscr smg_open B","",smg_open);
  5843.     smg_inited = 1;
  5844.     return(1);
  5845. }
  5846.  
  5847. static void
  5848. refresh() {
  5849.     debug(F101,"refresh smg_pasteboard_id","",smg_pasteboard_id);
  5850.  
  5851.     if (smg_open == 0 || smg_pasteboard_id == -1)
  5852.       return;
  5853.  
  5854. #ifdef COMMENT                          /* Martin Zinser */
  5855.     CHECK_ERR("refresh: smg$end_pasteboard_update",
  5856.               SMG$END_PASTEBOARD_UPDATE(&smg_pasteboard_id));
  5857.     CHECK_ERR("refresh: smg$begin_pasteboard_update",
  5858.               SMG$BEGIN_PASTEBOARD_UPDATE(&smg_pasteboard_id));
  5859. #else
  5860.     CHECK_ERR("refresh: smg$end_pasteboard_update",
  5861.               smg$end_pasteboard_update(&smg_pasteboard_id));
  5862.     CHECK_ERR("refresh: smg$begin_pasteboard_update",
  5863.               smg$begin_pasteboard_update(&smg_pasteboard_id));
  5864. #endif /* COMMENT */
  5865. }
  5866.  
  5867. static void
  5868. endwin() {
  5869.     if (!smg_open)
  5870.       return;
  5871.  
  5872.     smg_open = 0;
  5873.  
  5874. #ifdef COMMENT
  5875.     CHECK_ERR("endwin: smg$end_pasteboard_update",
  5876.               SMG$END_PASTEBOARD_UPDATE(&smg_pasteboard_id));
  5877. #else
  5878.     CHECK_ERR("endwin: smg$end_pasteboard_update",
  5879.               smg$end_pasteboard_update(&smg_pasteboard_id));
  5880. #endif /* COMMENT */
  5881.  
  5882.     move(22, 0);
  5883.  
  5884. #ifdef COMMENT
  5885. /*
  5886.   These calls clear the screen.
  5887.   (convert routine calls to lowercase - Martin Zinser)
  5888. */
  5889.     CHECK_ERR("endwin: smg$delete_virtual_display",
  5890.               SMG$DELETE_VIRTUAL_DISPLAY(&smg_display_id));
  5891.     smg_display_id = -1;
  5892.  
  5893.     CHECK_ERR("endwin: smg$delete_pasteboard",
  5894.               SMG$DELETE_PASTEBOARD(&smg_pasteboard_id, 0));
  5895.     smg_pasteboard_id = -1;
  5896. #endif /* COMMENT */
  5897. }
  5898.  
  5899. #ifdef COMMENT
  5900. /* DECC 6.2 screams bloody murder about printw ("not enough args") */
  5901. /* but adding the following prototype only makes it holler louder. */
  5902. #ifdef __DECC
  5903. /* "varargs" prototype for printw */
  5904. _PROTOTYP(static int printw,(char *, ...));
  5905. #endif /* __DECC */
  5906. #endif /* COMMENT */
  5907.  
  5908. #ifdef __DECC
  5909. #include <stdarg.h>
  5910. _PROTOTYP(static void printw,(char *, ...));
  5911. static void
  5912. printw(char *str,...) {
  5913.     char buf[255];
  5914.     va_list ap;
  5915.     $DESCRIPTOR(text_dsc, 0);
  5916.     text_dsc.dsc$a_pointer=buf;
  5917.     if (!smg_open)
  5918.       return;
  5919.     va_start(ap,str);
  5920.     text_dsc.dsc$w_length = vsprintf(buf, str, ap);
  5921.     va_end(ap);
  5922.     CHECK_ERR("printw: smg$put_chars",
  5923.               smg$put_chars(&smg_display_id, &text_dsc, 0, 0, 0, 0, 0));
  5924. }
  5925. #else
  5926. static void
  5927. printw(str, a1, a2, a3, a4, a5, a6, a7, a8)
  5928.     char *str;
  5929.     long a1, a2, a3, a4, a5, a6, a7, a8;
  5930. /* printw */ {
  5931.     char buf[255];
  5932.     $DESCRIPTOR(text_dsc, 0);
  5933.     if (!smg_open)
  5934.       return;
  5935.     text_dsc.dsc$a_pointer=buf;
  5936.     text_dsc.dsc$w_length = sprintf(buf, str, a1, a2, a3, a4, a5, a6, a7, a8);
  5937.     CHECK_ERR("printw: smg$put_chars",
  5938.               smg$put_chars(&smg_display_id, &text_dsc, 0, 0, 0, 0, 0));
  5939. }
  5940. #endif /* __DECC */
  5941.  
  5942. #define CK_CURPOS
  5943. int
  5944. ck_curpos(row, col) {
  5945.     debug(F111,"VMS smg ck_curpos",ckitoa(row),col);
  5946.     if (!smg_inited || !smg_open) {
  5947.         initscr();
  5948.     }
  5949.     debug(F101,"VMS smg curpos smg_open","",smg_open);
  5950.     if (!smg_open)
  5951.       return(0);
  5952.     debug(F111,"VMS smg ck_curpos",ckitoa(row-1),col-1);
  5953.     move(row - 1, col - 1);             /* SMG is 0-based */
  5954.     refresh();
  5955.     /* endwin(); */
  5956.     return(0);
  5957. }
  5958.  
  5959. int
  5960. ck_cls() {
  5961.     debug(F101,"VMS smg ck_cls smg_inited","",smg_inited);
  5962.     if (!smg_inited || !smg_open) {
  5963.         initscr();
  5964.     }
  5965.     debug(F101,"VMS smg ck_cls smg_open","",smg_open);
  5966.     if (!smg_open)
  5967.       return(0);
  5968.     clear();
  5969.     refresh();
  5970.     /* endwin(); */
  5971.     return(0);
  5972. }
  5973.  
  5974. int
  5975. ck_cleol() {
  5976.     debug(F101,"VMS smg ck_cleol smg_inited","",smg_inited);
  5977.     if (!smg_inited || !smg_open) {
  5978.         initscr();
  5979.     }
  5980.     debug(F101,"VMS smg ck_cleol smg_open","",smg_open);
  5981.     if (!smg_open)
  5982.       return(0);
  5983.     clrtoeol();
  5984.     refresh();
  5985.     /* endwin(); */
  5986.     return(0);
  5987. }
  5988. #endif /* CK_SMG */
  5989.  
  5990. #ifdef MYCURSES
  5991. /*
  5992.   Do-it-yourself curses implementation for VMS, OS/2 and other ANSI/VT-100's.
  5993.   Supports only the VT52 and VT1xx (and later VT2xx/3xx/4xx) terminals.
  5994.   By Terry Kennedy, St Peters College.
  5995.  
  5996.   First, some stuff we can just ignore:
  5997. */
  5998.  
  5999. static int
  6000. touchwin(x) int x; {
  6001.     return(0);
  6002. }
  6003. static int
  6004. initscr() {
  6005.     return(0);
  6006. }
  6007. static int
  6008. refresh() {
  6009.     return(0);
  6010. }
  6011. static int
  6012. endwin() {
  6013.     return(0);
  6014. }
  6015.  
  6016. /*
  6017.  * Now, some stuff we need to do:
  6018.  */
  6019.  
  6020. _PROTOTYP( int move, (int, int) );
  6021. #ifndef OS2
  6022. int
  6023. move(row, col) int row, col; {
  6024.     if (isvt52)
  6025.       printf("\033Y%c%c", row + 037, col + 037);
  6026.     else
  6027.       printf("\033[%d;%dH", row + 1, col + 1);
  6028.     return(0);
  6029. }
  6030.  
  6031. int
  6032. clear() {
  6033.     move(0,0);
  6034.     if (isvt52)
  6035.       printf("\033J");
  6036.     else
  6037.       printf("\033[J");
  6038.     return(0);
  6039. }
  6040.  
  6041. int
  6042. clrtoeol() {
  6043.     if (isvt52)
  6044.       printf("\033K");
  6045.     else
  6046.       printf("\033[K");
  6047.     return(0);
  6048. }
  6049.  
  6050. #define CK_CURPOS
  6051. int
  6052. ck_cls() {
  6053.     return(clear());
  6054. }
  6055.  
  6056. int
  6057. ck_cleol() {
  6058.     return(clrtoeol());
  6059. }
  6060.  
  6061. int
  6062. ck_curpos(row, col) int row, col; {
  6063.     move(row, col);
  6064.     return(0);
  6065. }
  6066.  
  6067. #else /* OS2 */
  6068. /* Windows NT and Windows 95 do not provide ANSI emulation */
  6069. /* Therefore we might as well not use it for OS/2 either   */
  6070.  
  6071. int
  6072. move(row, col) int row, col; {
  6073. #ifndef ONETERMUPD
  6074.     SetCurPos(row, col);
  6075. #endif /* ONETERMUPD */
  6076.     lgotoxy( VCMD, col+1, row+1);
  6077.     VscrnIsDirty(VCMD);
  6078.     return(0);
  6079. }
  6080.  
  6081. int
  6082. clear() {
  6083.     viocell cell;
  6084.     move(0,0);
  6085. #ifdef ONETERMUPD
  6086.     if (VscrnGetBufferSize(VCMD) > 0) {
  6087.         VscrnScroll(VCMD, UPWARD, 0,
  6088.                     VscrnGetHeight(VCMD)-(1),
  6089.                     VscrnGetHeight(VCMD)-(0), TRUE, CHR_SP);
  6090.         cleartermscreen(VCMD);
  6091.     }
  6092. #else
  6093.     cell.c = ' ';
  6094.     cell.a = colorcmd;
  6095.     WrtNCell(cell, cmd_rows * cmd_cols, 0, 0);
  6096. #endif /* ONETERMUPD */
  6097.     return(0);
  6098. }
  6099.  
  6100. int
  6101. clrtoeol() {
  6102.     USHORT row, col;
  6103.     viocell cell;
  6104.  
  6105.     cell.c = ' ';
  6106.     cell.a = colorcmd;
  6107. #ifndef ONETERMUPD
  6108.     GetCurPos(&row, &col );
  6109.     WrtNCell(cell, cmd_cols - col -1, row, col);
  6110. #endif /* ONETERMUPD */
  6111.     clrtoeoln(VCMD,CHR_SP);
  6112.     return(0);
  6113. }
  6114.  
  6115. #define CK_CURPOS
  6116. int
  6117. ck_curpos(row, col) int row, col; {
  6118.     move(row, col);
  6119.     return(0);
  6120. }
  6121.  
  6122. int
  6123. ck_cls() {
  6124.     return(clear());
  6125. }
  6126.  
  6127. int
  6128. ck_cleol() {
  6129.     return(clrtoeol());
  6130. }
  6131.  
  6132. #endif /* OS2 */
  6133. #endif /* MYCURSES */
  6134.  
  6135. #ifndef NOTERMCAP
  6136. #ifndef CK_CURPOS
  6137. #define CK_CURPOS
  6138.  
  6139. /* Termcap/Terminfo section */
  6140.  
  6141. static char cur_cls[32] = { NUL, NUL };
  6142. static char cur_cleol[32] = { NUL, NUL };
  6143. static char cur_cm[64] = { NUL, NUL };
  6144. static char tgsbuf[128] = { NUL, NUL };
  6145.  
  6146. static
  6147. #ifdef CK_ANSIC
  6148. void
  6149. #endif /* CK_ANSIC */
  6150. ck_termset(x) int x; {
  6151.     cur_cls[0] = NUL;
  6152.     cur_cleol[0] = NUL;
  6153.     cur_cm[0] = NUL;
  6154. #ifdef tgetent
  6155.     debug(F100,"tgetent is a macro","",0);
  6156. #endif /* tgetent */
  6157. #ifdef tgetstr
  6158.     debug(F100,"tgetstr is a macro","",0);
  6159. #endif /* tgetstr */
  6160. #ifdef tputs
  6161.     debug(F100,"tputs is a macro","",0);
  6162. #endif /* tputs */
  6163. #ifdef tgoto
  6164.     debug(F100,"tgoto is a macro","",0);
  6165. #endif /* tgoto */
  6166. #ifdef NOTERMCAP
  6167.     /* tgetstr() gets a segmentation fault on OSF/1 */
  6168.     debug(F100,"ck_termset NOTERMCAP","",0);
  6169. #else
  6170.     if (notermcap) {
  6171.         debug(F100,"ck_termset notermcap","",0);
  6172.         return;
  6173.     }
  6174.     debug(F101,"ck_termset x","",x);
  6175.     if (x > 0) {
  6176.         char * bp;
  6177.         bp = tgsbuf;
  6178.         *bp = NUL;
  6179.         debug(F110,"ck_termset calling tgetstr","cl",0);
  6180.         if (tgetstr("cl", &bp)) {       /* Get clear-screen code */
  6181.             debug(F110,"ck_termset tgetstr cl",tgsbuf,"");
  6182.             if ((int)strlen(tgsbuf) < 32)
  6183.               ckstrncpy(cur_cls,tgsbuf,32);
  6184.         } else
  6185.           return;
  6186.         bp = tgsbuf;
  6187.         if (tgetstr("ce", &bp)) {       /* Get clear-to-end-of-line code */
  6188.             debug(F110,"ck_termset tgetstr ce",tgsbuf,"");
  6189.             if ((int)strlen(tgsbuf) < 32)
  6190.               ckstrncpy(cur_cleol,tgsbuf,32);
  6191.         } else
  6192.           return;
  6193.         bp = tgsbuf;
  6194.         if (tgetstr("cm", &bp)) {       /* Get cursor-movement code */
  6195.             debug(F110,"ck_termset tgetstr cm",tgsbuf,"");
  6196.             if ((int)strlen(tgsbuf) < 64)
  6197.               ckstrncpy(cur_cm,tgsbuf,64);
  6198.         } else
  6199.           return;
  6200.     }
  6201. #endif /* NOTERMCAP */
  6202. }
  6203.  
  6204. #ifndef TPUTSFNTYPE
  6205. #ifdef TPUTSISVOID
  6206. #define TPUTSFNTYPE void
  6207. #else
  6208. #define TPUTSFNTYPE int
  6209. #endif /* TPUTSISVOID */
  6210. #endif /* TPUTSFNTYPE */
  6211.  
  6212. #ifndef TPUTSARGTYPE
  6213. #ifdef HPUX9
  6214. #define TPUTSARGTYPE char
  6215. #else
  6216. #ifdef HPUX10
  6217. #define TPUTSARGTYPE char
  6218. #else
  6219. #define TPUTSARGTYPE int
  6220. #endif /* HPUX10 */
  6221. #endif /* HPUX9 */
  6222. #endif /* TPUTSARGTYPE */
  6223.  
  6224. static TPUTSFNTYPE
  6225. #ifdef CK_ANSIC
  6226. ck_outc(TPUTSARGTYPE x)
  6227. #else
  6228. ck_outc(x) TPUTSARGTYPE x;
  6229. #endif /* CK_ANSIC */
  6230. {                                       /* To satisfy tputs() arg3 prototype */
  6231.     int rc;
  6232.     char c;
  6233.     c = (char) x;
  6234.     rc = (inserver) ? ttoc(c) : conoc(c);
  6235. #ifndef TPUTSISVOID
  6236.     return(rc);
  6237. #endif /* TPUTSISVOID */
  6238. }
  6239.  
  6240. int
  6241. ck_curpos(row, col) int row, col; {
  6242. #ifdef CK_ANSIC
  6243.     TPUTSFNTYPE (*fn)(TPUTSARGTYPE);
  6244. #else
  6245.     TPUTSFNTYPE (*fn)();
  6246. #endif /* CK_ANSIC */
  6247.     if (!fxd_inited)
  6248.       fxdinit(9999);
  6249.     if (!cur_cm[0]) {                   /* We don't have escape sequences */
  6250. #ifdef COMMENT
  6251.         return(-1);                     /* Do nothing */
  6252. #else
  6253.         /* Both C-Kermit's SCREEN command and ANSI/VT100 are 1-based */
  6254.         printf("\033[%d;%dH", row, col); /* Or default to ANSI */
  6255. #endif /* COMMENT */
  6256.     } else {
  6257.         fn = ck_outc;
  6258.         /* termcap/terminfo is 0-based */
  6259.         tputs(
  6260. #ifdef TPUTSARG1CONST
  6261.               (const char *)
  6262. #endif /* TPUTSARG1CONST */
  6263.               tgoto(cur_cm,col-1,row-1),1,fn);
  6264.     }
  6265.     return(0);
  6266. }
  6267.  
  6268. int
  6269. ck_cls() {
  6270. #ifdef CK_ANSIC
  6271.     TPUTSFNTYPE (*fn)(TPUTSARGTYPE);
  6272. #else
  6273.     TPUTSFNTYPE (*fn)();
  6274. #endif /* CK_ANSIC */
  6275.     if (!fxd_inited)
  6276.       fxdinit(9999);
  6277.     if (!cur_cls[0]) {                  /* If we don't have escape sequences */
  6278. #ifdef COMMENT
  6279.         return(-1);                     /* Do nothing */
  6280. #else
  6281.         printf("\033[;H\033[2J");       /* Or default to ANSI */
  6282. #endif /* COMMENT */
  6283.     } else {
  6284.         fn = ck_outc;
  6285.         debug(F111,"ck_cls 2",cur_cls,fxd_inited);
  6286.         tputs(cur_cls,cmd_rows,fn);
  6287.     }
  6288.     return(0);
  6289. }
  6290.  
  6291. int
  6292. ck_cleol() {
  6293. #ifdef CK_ANSIC
  6294.     TPUTSFNTYPE (*fn)(TPUTSARGTYPE);
  6295. #else
  6296.     TPUTSFNTYPE (*fn)();
  6297. #endif /* CK_ANSIC */
  6298.     if (!fxd_inited)
  6299.       fxdinit(9999);
  6300.     if (!cur_cleol[0]) {                /* If we don't have escape sequences */
  6301. #ifdef COMMENT
  6302.         return(-1);                     /* Do nothing */
  6303. #else
  6304.         printf("\033[K");               /* Or use ANSI */
  6305. #endif /* COMMENT */
  6306.     } else {
  6307.         fn = ck_outc;
  6308.         tputs(cur_cleol,1,fn);
  6309.     }
  6310.     return(0);
  6311. }
  6312. #endif /* CK_CURPOS */
  6313. #else
  6314. static void
  6315. ck_termset(x) int x; {
  6316.     if (x) return;
  6317. }
  6318. #endif /* NOTERMCAP */
  6319.  
  6320. #ifndef CK_CURPOS
  6321. #define CK_CURPOS
  6322. int
  6323. ck_cls() {
  6324.     printf("\033[;H\033[2J");
  6325.     return(0);
  6326. }
  6327.  
  6328. int
  6329. ck_cleol() {
  6330.     printf("\033[K");
  6331.     return(0);
  6332. }
  6333.  
  6334. int
  6335. ck_curpos(row, col) int row, col; {
  6336.     printf("\033[%d;%dH", row, col);
  6337.     return(0);
  6338. }
  6339. #endif /* CK_CURPOS */
  6340.  
  6341.  
  6342. #ifndef NOXFER
  6343. static int cinit = 0;                   /* Flag for curses init'd */
  6344. static int cendw = 0;                   /* endwin() was called */
  6345.  
  6346. static
  6347. #ifdef CK_ANSIC                         /* Because VOID used by curses.h */
  6348. void
  6349. #else
  6350. #ifdef MYCURSES
  6351. VOID
  6352. #else
  6353. int
  6354. #endif /* MYCURSES */
  6355. #endif /* CK_ANSIC */
  6356. #ifdef CK_ANSIC                         /* Update % transfered and % bar */
  6357. updpct(long old, long new)
  6358. #else /* CK_ANSIC */
  6359. updpct(old, new) long old, new;
  6360. #endif /* CK_ANSIC */
  6361. /* updpct */ {
  6362. #ifdef COMMENT
  6363.     int m, n;
  6364.     move(CW_PCD,22);
  6365.     printw("%ld", new);
  6366. #ifdef KUI
  6367. #ifndef K95G
  6368.     KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_PCD, (long) new);
  6369. #endif /* K95G */
  6370. #endif /* KUI */
  6371. #ifdef CK_PCT_BAR
  6372.     if (thermometer) {
  6373.         if (old > new) {
  6374.             old = 0;
  6375.             move(CW_PCD, 26);
  6376.             clrtoeol();
  6377.         }
  6378.         m = old/2;
  6379.         move(CW_PCD, 26 + m);
  6380.         n = new / 2 - m;
  6381. #ifndef OS2
  6382.         while (n > 0) {
  6383.             if ((m + 1) % 5 == 0)
  6384.               printw("*");
  6385.             else
  6386.               printw("=");
  6387.             m++;
  6388.             n--;
  6389.         }
  6390.         if (new % 2 != 0) printw("-");
  6391.         /* move(CW_PCD, 22+53); */
  6392. #else /* OS2 */
  6393.         while (n > 0) {
  6394.             printw("%c", '\333');
  6395.             m++; n--;
  6396.         }
  6397.         if (new % 2 != 0)
  6398.           printw("%c", '\261');
  6399. #endif /* OS2 */
  6400.     }
  6401. #endif /* CK_PCT_BAR */
  6402.     /* clrtoeol(); */
  6403. #else  /* !COMMENT */
  6404. #ifdef OS2
  6405. #define CHAR1   '\333'          /* OS2 - CP437 */
  6406. #define CHAR2   '\261'
  6407. #else
  6408. #define CHAR1   '/'             /* Default */
  6409. #define CHAR2   '-'
  6410. #endif /* OS2 */
  6411.     debug(F101,"updpct old","",old);
  6412.     debug(F101,"updpct new","",new);
  6413.     move(CW_PCD,22);
  6414.     printw("%-3ld", new); /*  (was)   printw("%ld", new);  */
  6415. #ifdef KUI
  6416. #ifndef K95G
  6417.     KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PCD, (long) new );
  6418. #endif /* K95G */
  6419. #endif /* KUI */
  6420. #ifdef CK_PCT_BAR
  6421.     if (thermometer) {
  6422.         int m, n;
  6423.  
  6424.         if (old > new) {
  6425.             old = 0 ;
  6426.             move(CW_PCD, 26);
  6427.             clrtoeol();
  6428.         }
  6429.         if (new <= 100L) {
  6430.             m = old / 2;
  6431.             n = new / 2 - m;
  6432.             move(CW_PCD, 26+m);
  6433.             while (n-- > 0)
  6434.               printw("%c", CHAR1);
  6435.             if (new % 2 != 0)
  6436.               printw("%c", CHAR2);
  6437.         }
  6438.     }
  6439. #endif /* CK_PCT_BAR */
  6440. #endif /* COMMENT */
  6441. }
  6442.  
  6443. static long old_tr = -1L;               /* Time remaining previously */
  6444.  
  6445. static long
  6446. #ifdef CK_ANSIC
  6447. shoetl(long old_tr, long cps, long fsiz, long howfar)
  6448. #else
  6449. shoetl(old_tr, cps, fsiz, howfar) long old_tr, cps, fsiz, howfar;
  6450. #endif /* CK_ANSIC */
  6451. /* shoetl */ {                          /* Estimated time left in transfer */
  6452.     long tr;                            /* Time remaining, seconds */
  6453.  
  6454. #ifdef GFTIMER
  6455.     if (fsiz > 0L && cps > 0L)
  6456.       tr = (long)((CKFLOAT)(fsiz - howfar) / (CKFLOAT)cps);
  6457.     else
  6458.       tr = -1L;
  6459. #else
  6460.     tr = (fsiz > 0L && cps > 0L) ?
  6461.       ((fsiz - howfar) / cps) :
  6462.         -1L;
  6463. #endif /* GFTIMER */
  6464.     move(CW_TR,22);
  6465.     if (tr > -1L) {
  6466.         if (tr != old_tr) {
  6467.             printw("%s",hhmmss(tr));
  6468. #ifdef KUI
  6469. #ifndef K95G
  6470.             KuiSetProperty(KUI_FILE_TRANSFER, (long)CW_TR, (long)hhmmss(tr));
  6471. #endif /* K95G */
  6472. #endif /* KUI */
  6473.             clrtoeol();
  6474.         }
  6475.     } else {
  6476.         printw("(unknown)");
  6477. #ifdef KUI
  6478. #ifndef K95G
  6479.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_TR, (long) "(unknown)" );
  6480. #endif /* K95G */
  6481. #endif /* KUI */
  6482.         clrtoeol();
  6483.     }
  6484.     return(tr);
  6485. }
  6486.  
  6487. static long
  6488. #ifdef CK_ANSIC
  6489. shocps(int pct, long fsiz, long howfar)
  6490. #else
  6491. shocps(pct, fsiz, howfar) int pct; long fsiz, howfar;
  6492. #endif /* CK_ANSIC */
  6493. /* shocps */ {
  6494. #ifdef CPS_WEIGHTED
  6495.     static long oldffc = 0L;
  6496. #endif /* CPS_WEIGHTED */
  6497. #ifdef GFTIMER
  6498.     CKFLOAT secs, xx;
  6499. #else
  6500.     long secs, xx;
  6501. #endif /* GFTIMER */
  6502.  
  6503. #ifdef GFTIMER
  6504.     xx = (gtv >= 0.0) ? gtv : 0.0;      /* Floating-point version */
  6505.     gtv = gftimer();
  6506.     if ((gtv - oldgtv) < (CKFLOAT) 1.0) /* Only do this once per second */
  6507.       return(oldcps);
  6508.     oldgtv = xx;
  6509. #else
  6510.     xx = (gtv >= 0) ? gtv : 0;          /* Whole-number version */
  6511.     gtv = gtimer();
  6512.     if ((gtv - oldgtv) < 1)
  6513.       return(oldcps);
  6514.     oldgtv = xx;
  6515. #endif /* GFTIMER */
  6516.  
  6517. #ifdef CPS_WEIGHTED
  6518.     /* debug(F100,"SHOCPS: WEIGHTED","",0); */
  6519.     if (gtv != oldgtv) {                /* The first packet is ignored */
  6520.         if (ffc < oldffc)
  6521.           oldffc = ffc;
  6522.         oldcps = cps;
  6523.         if (oldcps && oldgtv >
  6524. #ifdef GFTIMER
  6525.             1.0
  6526. #else
  6527.             1
  6528. #endif /* GFTIMER */
  6529.             ) {                         /* The first second is ignored */
  6530. /*
  6531.   This version of shocps() produces a weighted average that some
  6532.   people like, but most people find it disconcerting and bombard us
  6533.   with questions and complaints about why the CPS figure fluctuates so
  6534.   wildly.  So now you only get the weighted average if you build the
  6535.   program yourself with CPS_WEIGHTED defined.
  6536. */
  6537. #ifndef CPS_VINCE
  6538. #ifdef GFTIMER
  6539.             cps = (long)((((CKFLOAT)oldcps * 3.0) +
  6540.                    (CKFLOAT)(ffc - oldffc) / (gtv-oldgtv) ) / 4.0);
  6541. #else
  6542.             cps = ( (oldcps * 3) + (ffc - oldffc) / (gtv-oldgtv) ) / 4;
  6543. #endif /* GFTIMER */
  6544. #else
  6545. /* And an alternate weighting scheme from Vincent Fatica... */
  6546.             cps = (3 *
  6547.              ((1+pct/300)*oldffc/oldgtv+(1-pct/100)*(ffc-oldffc)/(gtv-oldgtv)))
  6548.               / 4;
  6549. #endif /* CPS_VINCE */
  6550.         } else {
  6551.             /* No weighted average since there is nothing to weigh */
  6552. #ifdef GFTIMER
  6553.             cps = (long)(gtv != 0.0 ?
  6554.               (CKFLOAT)(ffc - oldffc) / (gtv - oldgtv) :
  6555.                 (ffc - oldffc)) ;
  6556. #else
  6557.             cps = gtv ? (ffc - oldffc) / (gtv - oldgtv) : (ffc - oldffc) ;
  6558. #endif /* GFTIMER */
  6559.         }
  6560. #ifdef COMMENT
  6561. #ifdef DEBUG
  6562.         if (deblog) {
  6563.             debug(F101,"SHOCPS: pct   ","",pct);
  6564.             debug(F101,"SHOCPS: gtv   ","",gtv);
  6565.             debug(F101,"SHOCPS: oldgtv","",oldgtv);
  6566.             debug(F101,"SHOCPS: dgtv  ","",(long)(gtv-oldgtv));
  6567.             debug(F101,"SHOCPS: ffc   ","",ffc);
  6568.             debug(F101,"SHOCPS: oldffc","",oldffc);
  6569.             debug(F101,"SHOCPS: dffc  ","",ffc-oldffc);
  6570.             debug(F101,"SHOCPS: cps   ","",cps);
  6571.         }
  6572. #endif /* DEBUG */
  6573. #endif /* COMMENT */
  6574.         move(CW_CP,22);
  6575.         printw("%ld", cps);
  6576. #ifdef KUI
  6577. #ifndef K95G
  6578.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, (long) cps );
  6579. #endif /* K95G */
  6580. #endif /* KUI */
  6581.         clrtoeol();
  6582.         oldffc = ffc;
  6583.     }
  6584. #else /* !CPS_WEIGHTED */
  6585. #ifdef COMMENT
  6586. #ifdef DEBUG
  6587.     if (deblog) {
  6588.     debug(F100,"SHOCPS: NOT WEIGHTED","",0);
  6589.         debug(F101,"SHOCPS: pct    ","",pct);
  6590.         debug(F101,"SHOCPS: gtv    ","",gtv);
  6591.         debug(F101,"SHOCPS: oldgtv ","",oldgtv);
  6592.         debug(F101,"SHOCPS: dgtv   ","",(long)gtv - (long)oldgtv);
  6593.         debug(F101,"SHOCPS: ffc    ","",ffc);
  6594.         debug(F101,"SHOCPS: oldffc ","",oldffc);
  6595.         debug(F101,"SHOCPS: dffc   ","",ffc-oldffc);
  6596.         debug(F101,"SHOCPS: cps    ","",cps);
  6597.         debug(F101,"SHOCPS: filcnt ","",filcnt);
  6598. #ifdef GFTIMER
  6599.         debug(F101,"SHOCPS: fpfsecs","",fpfsecs);
  6600. #endif /* GFTIMER */
  6601.     }
  6602.     debug(F101,"shocps gtv","",gtv);
  6603. #endif /* DEBUG */
  6604. #ifdef GFTIMER
  6605. #endif /* COMMENT */
  6606.     /* debug(F101,"shocps fpfsecs","",fpfsecs); */
  6607.     secs = gtv - fpfsecs;
  6608.     /* debug(F101,"shocps secs","",(long)secs); */
  6609.     if (secs > 0.0) {
  6610.         cps = (long)((CKFLOAT) ffc / secs);
  6611.         /* debug(F101,"shocps cps","",cps); */
  6612.         move(CW_CP,22);
  6613. #ifdef KUI
  6614. #ifndef K95G
  6615.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, (long) cps );
  6616. #endif /* K95G */
  6617. #endif /* KUI */
  6618.         printw("%ld", cps);
  6619.         clrtoeol();
  6620.     }
  6621. #else  /* Not GFTIMER */
  6622.     if ((secs = gtv - fsecs) > 0) {
  6623.         cps = (secs < 1L) ? ffc : ffc / secs;
  6624.         move(CW_CP,22);
  6625. #ifdef KUI
  6626. #ifndef K95G
  6627.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, (long) cps );
  6628. #endif /* K95G */
  6629. #endif /* KUI */
  6630.         printw("%ld", cps);
  6631.         clrtoeol();
  6632.     }
  6633. #endif /* GFTIMER */
  6634. #endif /* CPS_WEIGHTED */
  6635.  
  6636.     if (cps > peakcps &&                /* Peak transfer rate */
  6637.         ((what & W_SEND && spackets > wslots + 4) ||
  6638.      (!(what & W_SEND) && spackets > 10))) {
  6639.         peakcps = cps;
  6640.     }
  6641.     old_tr = shoetl(old_tr, cps, fsiz, howfar);
  6642.     return(cps);
  6643. }
  6644.  
  6645. static
  6646. #ifdef CK_ANSIC                         /* Because VOID used by curses.h */
  6647. void
  6648. #else
  6649. #ifdef MYCURSES
  6650. VOID
  6651. #else
  6652. int
  6653. #endif /* MYCURSES */
  6654. #endif /* CK_ANSIC */
  6655. scrft() {                               /* Display file type */
  6656.     char xferstr[256];
  6657.     xferstr[0] = NUL;
  6658.     if (binary) {
  6659.         switch(binary) {
  6660.           case XYFT_L:
  6661.             ckstrncpy(xferstr,"LABELED",256);
  6662.             break;
  6663.           case XYFT_I:
  6664.             ckstrncpy(xferstr,"IMAGE",256);
  6665.             break;
  6666.           case XYFT_U:
  6667.             ckstrncpy(xferstr,"BINARY UNDEFINED",256);
  6668.             break;
  6669.       case XYFT_M:
  6670.             ckstrncpy(xferstr,"MACBINARY",256);
  6671.             break;
  6672.       case XYFT_X:
  6673.             ckstrncpy(xferstr,"TENEX",256);
  6674.             break;
  6675.           default:
  6676.           case XYFT_B:
  6677.             ckstrncpy(xferstr,"BINARY",256);
  6678.             break;
  6679.         }
  6680. #ifdef CK_RESEND
  6681.         if (what & W_SEND && sendstart > 0L) {
  6682.             if (sendmode == SM_PSEND) {
  6683.                 ckstrncat(xferstr, " / partial", 256);
  6684.             } else if (sendmode == SM_RESEND) {
  6685.                 ckstrncat(xferstr, " / resend", 256);
  6686.             }
  6687.         } else if (what & W_RECV && rs_len > 0L) {
  6688.             ckstrncat(xferstr, " / resend", 256);
  6689.         }
  6690. #endif /* CK_RESEND */
  6691.     } else {
  6692.  
  6693. #ifndef NOCSETS
  6694.         ckstrncpy(xferstr,"TEXT",256);
  6695. #ifdef NEWFTP
  6696. #ifndef NOUNICODE
  6697.     if (what & W_FTP) {
  6698.         if (ftp_csx < 0)
  6699.           ckstrncat(xferstr," (no translation)", 256);
  6700.         else
  6701.           ckmakxmsg(&xferstr[4],252,
  6702.                " (",
  6703.                fcsinfo[(what & W_SEND) ? ftp_csl : ftp_csx].keyword,
  6704.                " => ",
  6705.                fcsinfo[(what & W_SEND) ? ftp_csx : ftp_csl].keyword,
  6706.                ")",
  6707.                NULL,NULL,NULL,NULL,NULL,NULL,NULL
  6708.                );
  6709.     } else
  6710. #endif /* NOUNICODE */
  6711. #endif /* NEWFTP */
  6712.       if (tcharset == TC_TRANSP) {
  6713.             ckstrncat(xferstr, " (no translation)", 256);
  6714.         } else {
  6715.             if (what & W_SEND) {
  6716.                 sprintf( &xferstr[strlen(xferstr)], /* safe */
  6717.                         " (%s => %s)",
  6718.                         fcsinfo[fcharset].keyword, /* built-in keywords */
  6719.                         tcsinfo[tcharset].keyword  /* lengths are controlled */
  6720.             );
  6721.             } else {
  6722.                 sprintf( &xferstr[strlen(xferstr)], /* safe */
  6723.                         " (%s => %s)",
  6724.                         tcsinfo[tcharset].keyword, /* built-in keywords */
  6725.                         fcsinfo[fcharset].keyword); /* lengths controlled */
  6726.             }
  6727.         }
  6728. #endif /* NOCSETS */
  6729.     }
  6730.     move(CW_TYP,22);
  6731.     printw("%s", xferstr);
  6732.     clrtoeol();
  6733. #ifdef KUI
  6734. #ifndef K95G
  6735.     KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_TYP, (long) xferstr );
  6736. #endif /* K95G */
  6737. #endif /* KUI */
  6738.     return;
  6739. }
  6740.  
  6741. #ifdef CK_NEWTERM
  6742. static FILE *ck_stdout = NULL;
  6743. static int ck_fd = -1;
  6744. #endif /* CK_NEWTERM */
  6745.  
  6746. static long pct = 0L, oldpct = 0L, oldrtt = -1L;
  6747. static int oldtyp = 0, oldwin = -1, oldtry = -1, oldlen = -1, oldtim = -1;
  6748.  
  6749. #ifdef NETCONN
  6750. static char *netname[] = {
  6751.     "none",                /* 00 */
  6752.     "TCP/IP",                /* 01 TCP (Sockets) */
  6753.     "TCP/IP",                /* 02 TCP (Streams) */
  6754.     "X.25",                /* 03 SunLink X.24  */
  6755.     "DECnet",                /* 04 DECnet  */
  6756.     "VAX PSI",                /* 05 VAX PSI */
  6757.     "Named Pipes",            /* 06 LAN Manager Named Pipe */
  6758.     "X.25",                /* 07 Stratus VOS X.25 */
  6759.     "NetBIOS",                /* 08 IBM NETBIOS */
  6760.     "SuperLAT",                /* 07 Meridian SuperLAT */
  6761.     "File",                /* 10 File */
  6762.     "Command",                /* 11 Subprocess (pipe) */
  6763.     "DLL",                /* 12 DLL does i/o */
  6764.     "X.25",                /* 13 IBM AIXLink X.25 */
  6765.     "X.25",                /* 14 HP-UX X.25 */
  6766.     "PTY",                /* 15 Pseudoterminal */
  6767.     "SSH",                /* 16 SSH */
  6768.     "<ERROR>",                /* 17 In case new types are added */
  6769.     "<ERROR>",                /* 18 but nobody remembers to update */
  6770.     "<ERROR>",                /* 19 this table ... */
  6771.     NULL                /* 20 */
  6772. };
  6773. static int nnetname = (sizeof(netname) / sizeof(char *));
  6774.  
  6775. #endif /* NETCONN */
  6776.  
  6777. #ifdef CK_ANSIC
  6778. void
  6779. screenc(int f, char c,CK_OFF_T n,char *s)
  6780. #else
  6781. #ifdef MYCURSES
  6782. VOID
  6783. #else
  6784. int
  6785. #endif /* MYCURSES */
  6786. screenc(f,c,n,s)
  6787. int f;          /* argument descriptor */
  6788. char c;         /* a character or small integer */
  6789. CK_OFF_T n;     /* a long integer */
  6790. char *s;        /* a string */
  6791. #endif /* CK_ANSIC */
  6792. /* screenc() */ {
  6793. #ifdef CK_SSL
  6794.     extern int tls_active_flag, ssl_active_flag;
  6795. #endif /* CK_SSL */
  6796. #ifdef RLOGCODE
  6797.     extern int ttnproto;
  6798. #endif /* RLOGCODE */
  6799.     static int q = 0;
  6800.     static long fcnt = 0L;        /* Number of files transferred */
  6801.     static CK_OFF_T fsiz = (CK_OFF_T)-1; /* Copy of file size */
  6802.     static CK_OFF_T fbyt = 0L; /* Total file bytes of all files transferred */
  6803.     static CK_OFF_T howfar = 0L; /* How much of current file has been xfer'd */
  6804.     static int  pctlbl = 0L;  /* Percent done vs Bytes so far */
  6805.     long cps = 0L;
  6806.  
  6807.     int net = 0;
  6808.     int xnet = 0;
  6809.     int ftp = 0;
  6810.     int len;                            /* Length of string */
  6811.     int errors = 0;                     /* Error counter */
  6812.     int x;                              /* Worker */
  6813.  
  6814.     debug(F101,"screenc cinit","",cinit);
  6815.     debug(F101,"screenc cendw","",cendw);
  6816.  
  6817.     if (!s) s = "";                     /* Always do this. */
  6818.  
  6819.     ftp = (what & W_FTP) ? 1 : 0;    /* FTP or Kermit */
  6820.     net = network || ftp;
  6821.     xnet = ftp ? 1 : nettype;        /* NET_TCPB == 1 */
  6822.  
  6823.     if (cinit == 0 || cendw > 0) {      /* Handle borderline cases... */
  6824.         if (f == SCR_CW) {              /* Close window, but it's not open */
  6825.             ft_win = 0;
  6826.             return;
  6827.         }
  6828.         debug(F111,"screenc A",s,f);
  6829.         if (f == SCR_EM ||
  6830.            (f == SCR_PT && c == 'E')) { /* Fatal error before window open */
  6831.             conoll(""); conoc('?'); conoll(s); return; /* Regular display */
  6832.         }
  6833.     }
  6834.     if (cinit == 0) {                   /* Only call initscr() once */
  6835.     char * s;
  6836.     /* Check these now -- if they are defined but not numeric */
  6837.     /* they can crash curses */
  6838.     s = getenv("LINES");
  6839.     if (s) if (!rdigits(s)) {
  6840.         printf("?LINES variable not numeric: \"%s\".\n",s);
  6841.         printf("(Fullscreen display disabled)\n");
  6842.         fdispla = XYFD_S;
  6843.         return;
  6844.     }
  6845.     s = getenv("COLUMNS");
  6846.     if (s) if (!rdigits(s)) {
  6847.         printf("?COLUMNS variable not numeric: \"%s\".\n",s);
  6848.         printf("(Fullscreen display disabled)\n");
  6849.         fdispla = XYFD_S;
  6850.         return;
  6851.     }
  6852.         cendw = 1;                      /* New window needs repainting */
  6853. #ifdef COMMENT
  6854.         if (!initscr()) {               /* Oops, can't initialize window? */
  6855. /*
  6856.   In fact, this doesn't happen.  "man curses" says initscr() halts the
  6857.   entire program if it fails, which is true on the systems where I've
  6858.   tested it.  It will fail if your terminal type is not known to it.
  6859.   That's why SET FILE DISPLAY FULLSCREEN calls tgetent() to make sure the
  6860.   terminal type is known before allowing a curses display.
  6861. */
  6862.             fprintf(stderr,"CURSES INITSCR ERROR\r\n");
  6863.             fdispla = XYFD_S;           /* Fall back to CRT display */
  6864.             return;
  6865.         } else {
  6866.             cinit++;                    /* Window initialized ok */
  6867.             debug(F100,"CURSES INITSCR OK","",0);
  6868.         }
  6869. #else                                   /* Save some memory. */
  6870. #ifdef CK_NEWTERM
  6871.         /* (From Andy Fyfe <andy@vlsi.cs.caltech.edu>)
  6872.            System V curses seems to reserve the right to alter the buffering
  6873.            on the output FILE* without restoring it.  Fortunately System V
  6874.            curses provides newterm(), an alternative to initscr(), that
  6875.            allows us to specify explicitly the terminal type and input and
  6876.            output FILE pointers.  Thus we duplicate stdout, and let curses
  6877.            have the copy.  The original remains unaltered.  Unfortunately,
  6878.            newterm() seems to be particular to System V.
  6879.         */
  6880.         s = getenv("TERM");
  6881.         if (ck_fd < 0) {
  6882.             ck_fd = dup(fileno(stdout));
  6883.             ck_stdout = (ck_fd >= 0) ? (FILE *)fdopen(ck_fd, "w") : NULL;
  6884.         }
  6885.         debug(F100,"screenc newterm...","",0);
  6886.  
  6887. /* NOTE: It might be necessary to do this with stdin too! */
  6888. /* This would have been the case in FreeBSD 4.1 but they fixed the */
  6889. /* problem by restoring the buffering of stdin before the final release. */
  6890. /* (But T.E. Dickey says stdin is not buffered?) */
  6891.  
  6892.         if (ck_stdout == NULL || newterm(s, ck_stdout, stdin) == 0) {
  6893.             fprintf(stderr,
  6894.               "Fullscreen display not supported for terminal type: %s\r\n",s);
  6895.             fdispla = XYFD_S;           /* Use CRT instead */
  6896.             return;
  6897.         }
  6898.         debug(F100,"screenc newterm ok","",0);
  6899. #else
  6900.         debug(F100,"screen calling initscr","",0);
  6901.         initscr();                      /* Initialize curses. */
  6902.         debug(F100,"screen initscr ok","",0);
  6903. #endif /* CK_NEWTERM */
  6904.         cinit++;                        /* Remember curses was initialized. */
  6905. #endif /* COMMENT */
  6906.     }
  6907.     ft_win = 1;                         /* Window is open */
  6908.     if (repaint) {
  6909. #ifdef CK_WREFRESH
  6910. /*
  6911.   This totally repaints the screen, just what we want, but we can only
  6912.   do this with real curses, and then only if clearok() and wrefresh() are
  6913.   provided in the curses library.
  6914. */
  6915. #ifdef OS2
  6916.         RestoreCmdMode();
  6917. #else
  6918. #ifdef QNX
  6919. #ifndef QNX16
  6920.         clearok(stdscr, 1);             /* QNX doesn't have curscr */
  6921. #endif /* QNX16 */
  6922.         wrefresh(stdscr);
  6923. #else
  6924.         wrefresh(curscr);
  6925. #endif /* QNX */
  6926. #endif /* OS2 */
  6927. #else  /* No CK_WREFRESH */
  6928. /*
  6929.   Kermit's do-it-yourself method, works with all types of fullscreen
  6930.   support, but does not repaint all the fields.  For example, the filename
  6931.   is lost, because it arrives at a certain time and never comes again, and
  6932.   Kermit presently does not save it anywhere.  Making this method work for
  6933.   all fields would be a rather major recoding task, duplicating what curses
  6934.   already does, and would add a lot of complexity and storage space.
  6935. */
  6936.         cendw = 1;
  6937. #endif /* CK_WREFRESH */
  6938.         repaint = 0;
  6939.     }
  6940.     if (cendw) {                        /* endwin() was called previously */
  6941. #ifdef VMS
  6942.         initscr();                      /* (or should have been!) */
  6943.         clear();
  6944.         touchwin(stdscr);
  6945.         refresh();
  6946. #else
  6947. #ifdef QNX
  6948. /*
  6949.   In QNX, if we don't call initscr() here we core dump.
  6950.   I don't have any QNX curses documentation, but other curses manuals
  6951.   say that initscr() should be called only once per application, and
  6952.   experience shows that on other systems, calling initscr() here generally
  6953.   results in a core dump.
  6954. */
  6955.         debug(F100,"screenc re-calling initscr QNX","",0);
  6956.         initscr();
  6957.         clear();
  6958.         refresh();
  6959. #ifdef COMMENT
  6960. /*
  6961.   But even so, second and subsequent curses displays are messed up.
  6962.   Calling touchwin, refresh, etc, doesn't make any difference.
  6963. */
  6964.         debug(F100,"screenc calling touchwin QNX","",0);
  6965.         touchwin(stdscr);
  6966.         debug(F100,"screenc calling refresh QNX","",0);
  6967.         refresh();
  6968. #endif /* COMMENT */
  6969.  
  6970. #else /* All others... */
  6971.         debug(F100,"screenc calling clear","",0);
  6972.         clear();
  6973.         debug(F100,"screenc clear ok","",0);
  6974. #endif /* QNX */
  6975. #endif /* VMS */
  6976.         debug(F100,"screenc setup ok","",0);
  6977.         debug(F100,"screenc doing first move","",0);
  6978.         move(CW_BAN,0);                 /* Display the banner */
  6979.         debug(F110,"screenc myhost",myhost,0);
  6980. #ifdef TCPSOCKET
  6981.         debug(F110,"screenc myipaddr",myipaddr,0);
  6982. #endif /* TCPSOCKET */
  6983. #ifdef HPUX1010
  6984.         debug(F100,"screenc calling first printw...","",0);
  6985. /* Right here is where HP-UX 10.10 libxcurse.1 Rev 76.20 hangs... */
  6986. #endif /* HPUX1010 */
  6987.         if (myhost[0]) {
  6988. #ifdef TCPSOCKET
  6989.             if (!myipaddr[0]
  6990. #ifdef OS2
  6991.                  /* We need to perform this test because on non-TCP/IP */
  6992.                  /* systems the call to getlocalipaddr() results in a  */
  6993.                  /* DNS Lookup which takes several minutes to time out */
  6994.                  && net &&
  6995.                  (xnet == NET_TCPA || xnet == NET_TCPB
  6996. #ifdef SSHBUILTIN
  6997.                   || xnet == NET_SSH
  6998. #endif /* SSHBUILTIN */
  6999.                   )
  7000. #endif /* OS2 */
  7001.                  )
  7002.               getlocalipaddr();
  7003.             if (myipaddr[0] && strcmp((char *)myhost,(char *)myipaddr))
  7004.               printw("%s, %s [%s]",versio,(char *)myhost,(char *)myipaddr);
  7005.             else
  7006. #endif /* TCPSOCKET */
  7007.               printw("%s, %s",versio,(char *)myhost);
  7008.         } else {
  7009.             printw("%s",versio);
  7010.         }
  7011. #ifdef HPUX1010
  7012.         debug(F100,"screenc first printw returns","",0);
  7013. #endif /* HPUX1010 */
  7014.         move(CW_DIR,3);
  7015.         printw("Current Directory: %s",zgtdir());
  7016. #ifdef KUI
  7017. #ifndef K95G
  7018.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_DIR, (long) zgtdir() );
  7019. #endif /* K95G */
  7020. #endif /* KUI */
  7021.         if (net) {
  7022.             move(CW_LIN,8);
  7023.             printw("Network Host: %s",
  7024. #ifdef NEWFTP
  7025.            ftp ? (ftp_host ? ftp_host : "(unknown)") :
  7026. #endif /* NEWFTP */
  7027.            ttname
  7028.            );
  7029.         } else {
  7030.             move(CW_LIN,0);
  7031.             printw("Communication Device: %s",ttname);
  7032.         }
  7033. #ifdef KUI
  7034. #ifndef K95G
  7035.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_LIN, (long) ttname );
  7036. #endif /* K95G */
  7037. #endif /* KUI */
  7038.  
  7039.         if (net) {
  7040.             move(CW_SPD,8);
  7041.             printw("Network Type: ");
  7042.         } else {
  7043.             move(CW_SPD,1);
  7044.             printw("Communication Speed: ");
  7045.         }
  7046.         move(CW_SPD,22);                /* Serial speed or network type */
  7047.         if (net) {
  7048. #ifdef NETCONN
  7049.         int secure = 0;
  7050.         char * xname;
  7051.         if (xnet > nnetname)
  7052.           xname = "[ERROR]";
  7053.         else
  7054.           xname = netname[xnet];
  7055. #ifdef NEWFTP
  7056.             if (ftp) {
  7057.         if (ftpissecure())
  7058.           secure = 1;
  7059.         } else
  7060. #endif /* NEWFTP */
  7061.           if (0
  7062. #ifdef SSHBUILTIN
  7063.                 || IS_SSH()
  7064. #endif /* SSHBUILTIN */
  7065. #ifdef CK_ENCRYPTION
  7066.                 || ck_tn_encrypting() && ck_tn_decrypting()
  7067. #endif /* CK_ENCRYPTION */
  7068. #ifdef CK_SSL
  7069.                 || tls_active_flag || ssl_active_flag
  7070. #endif /* CK_SSL */
  7071. #ifdef RLOGCODE
  7072. #ifdef CK_KERBEROS
  7073. #ifdef CK_ENCRYPTION
  7074.                 || ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN
  7075. #endif /* CK_ENCRYPTION */
  7076. #endif /* CK_KERBEROS */
  7077. #endif /* RLOGCODE */
  7078.                  ) {
  7079.         secure = 1;
  7080.         }
  7081.         if (secure) {
  7082. #ifdef KUI
  7083. #ifndef K95G
  7084.                 char buf[30];
  7085.                 sprintf(buf,"%s (SECURE)",xname);
  7086.                 KuiSetProperty(KUI_FILE_TRANSFER,
  7087.                                (long) CW_SPD,
  7088.                                (long) buf
  7089.                                );
  7090. #endif /* K95G */
  7091. #endif /* KUI */
  7092.                 printw("%s (SECURE)",xname);
  7093.             } else {
  7094.                 printw("%s",xname);
  7095. #ifdef KUI
  7096. #ifndef K95G
  7097.                 KuiSetProperty(KUI_FILE_TRANSFER,
  7098.                                (long) CW_SPD,
  7099.                                (long) xname
  7100.                                );
  7101. #endif /* K95G */
  7102. #endif /* KUI */
  7103.             }
  7104. #else
  7105.             printw("(network)");
  7106. #ifdef KUI
  7107. #ifndef K95G
  7108.             KuiSetProperty(KUI_FILE_TRANSFER,
  7109.                            (long) CW_SPD,
  7110.                            (long) "(network)"
  7111.                            );
  7112. #endif /* K95G */
  7113. #endif /* KUI */
  7114. #endif /* NETCONN */
  7115.         } else {
  7116.             if (speed < 0L)
  7117.               speed = ttgspd();
  7118.             if (speed > 0L) {
  7119.                 if (speed == 8880) {
  7120.                     printw("75/1200");
  7121. #ifdef KUI
  7122. #ifndef K95G
  7123.                     KuiSetProperty(KUI_FILE_TRANSFER,
  7124.                                    (long) CW_SPD,
  7125.                                    (long) "75/1200"
  7126.                                    );
  7127. #endif /* K95G */
  7128. #endif /* KUI */
  7129.                 } else {
  7130.                     char speedbuf[64] ;
  7131.                     sprintf(speedbuf, "%ld", speed);
  7132.                     printw("%s",speedbuf);
  7133. #ifdef KUI
  7134. #ifndef K95G
  7135.                     KuiSetProperty(KUI_FILE_TRANSFER,
  7136.                                    (long) CW_SPD,
  7137.                                    (long) speedbuf
  7138.                                    );
  7139. #endif /* K95G */
  7140. #endif /* KUI */
  7141.                 }
  7142.             } else {
  7143.                 printw("unknown");
  7144. #ifdef KUI
  7145. #ifndef K95G
  7146.                 KuiSetProperty(KUI_FILE_TRANSFER,
  7147.                                (long) CW_SPD,
  7148.                                (long) "(unknown)"
  7149.                                );
  7150. #endif /* K95G */
  7151. #endif /* KUI */
  7152.             }
  7153.         }
  7154.         move(CW_PAR,14);
  7155.         printw("Parity: %s",ftp ? "none" : parnam((char)parity));
  7156. #ifdef KUI
  7157. #ifndef K95G
  7158.         KuiSetProperty(KUI_FILE_TRANSFER,
  7159.                        (long) CW_PAR,
  7160.                        (long) parnam((char)parity)
  7161.                        );
  7162. #endif /* K95G */
  7163. #endif /* KUI */
  7164. #ifdef CK_TIMERS
  7165.         if (/* rttflg && */ protocol == PROTO_K) {
  7166.             move(CW_TMO, 9); printw("RTT/Timeout:"); }
  7167. #endif /* CK_TIMERS */
  7168.         move(CW_TYP,11); printw("File Type:");
  7169.         move(CW_SIZ,11); printw("File Size:");
  7170.         move(CW_PCD, 8);
  7171.         clrtoeol();
  7172.         pctlbl = (what & W_SEND);
  7173.         printw("%s:", pctlbl ? "Percent Done" : "Bytes So Far");
  7174.  
  7175. #ifdef XYZ_INTERNAL
  7176.         move(CW_BAR, 1);
  7177.         printw("%10s Protocol:", ftp ? "FTP" : ptab[protocol].p_name);
  7178. #endif /* XYZ_INTERNAL */
  7179. #ifdef CK_PCT_BAR
  7180.         if (thermometer) {
  7181.             oldpct = pct = 0;
  7182.             move(CW_BAR,22);
  7183.             printw("    ...10...20...30...40...50...60...70...80...90..100");
  7184.             move(CW_BAR,22+56);
  7185.         }
  7186. #endif /* CK_PCT_BAR */
  7187.         move(CW_TR,  1); printw("Estimated Time Left:");
  7188.         move(CW_CP,  2); printw("Transfer Rate, CPS:");
  7189.         move(CW_WS,  8); printw("Window Slots:%s",
  7190.                                 ((protocol == PROTO_K) && !ftp) ?
  7191.                                 "" : " N/A"
  7192.                                 );
  7193.         move(CW_PT,  9); printw("Packet Type:");
  7194.         if (ftp || protocol != PROTO_K) {
  7195.         move(CW_PT,22);
  7196.             printw("%s", "N/A");
  7197.             move(CW_PC,  11); printw("I/O Count:");
  7198.             move(CW_PL,  10); printw("I/O Length:");
  7199.         } else {
  7200.             move(CW_PC,  8); printw("Packet Count:");
  7201.             move(CW_PL,  7); printw("Packet Length:");
  7202.         }
  7203. #ifndef COMMENT
  7204.         move(CW_PR,  9); printw("Error Count:");
  7205. #else
  7206.         move(CW_PR,  2); printw("Packet Retry Count:");
  7207. #endif
  7208. #ifdef COMMENT
  7209.         move(CW_PB,  2); printw("Packet Block Check:");
  7210. #endif /* COMMENT */
  7211.         move(CW_ERR,10); printw("Last Error:");
  7212.         move(CW_MSG, 8); printw("Last Message:");
  7213.     if (xfrmsg) {
  7214.         move(CW_MSG, 22); printw("%s",xfrmsg);
  7215.         makestr(&xfrmsg,NULL);
  7216.     }
  7217.         move(CW_INT, 0);
  7218.         if (!xfrint) {
  7219.             printw("(Transfer interruption is disabled)");
  7220.         } else {
  7221. #ifdef CK_NEED_SIG
  7222.             printw(
  7223. "<%s>X to cancel file, <%s>Z to cancel group, <%s><CR> to resend last packet",
  7224.                    dbchr(escape), dbchr(escape), dbchr(escape)
  7225.                    );
  7226.             move(CW_INT + 1, 0);
  7227.             printw(
  7228. "<%s>E to send Error packet, ^C to quit immediately, <%s>L to refresh screen.",
  7229.                    dbchr(escape), dbchr(escape)
  7230.                    );
  7231. #else /* !CK_NEED_SIG */
  7232.             move(CW_INT, 0);
  7233. #ifdef OS2
  7234.             if (protocol == PROTO_K) {
  7235.                 printw(
  7236. "X to cancel file, Z to cancel group, <Enter> to resend last packet,"
  7237.                        );
  7238.             }
  7239. #else /* !OS2 */
  7240. #ifdef VMS                              /* In VMS avoid bottom line */
  7241.             printw(
  7242. "X: Cancel this file; E: Cancel transfer; ^C: Quit now; ^W: Refresh screen."
  7243.                    );
  7244. #else
  7245.             printw(
  7246. "X to cancel file, Z to cancel group, <CR> to resend last packet,"
  7247.                    );
  7248. #endif /* VMS */
  7249. #endif /* OS2 */
  7250.  
  7251. #ifndef VMS
  7252.             move(CW_INT + 1, 0);
  7253.             if (protocol == PROTO_K) {
  7254.                 printw(
  7255. "E to send Error packet, ^C to quit immediately, ^L to refresh screen."
  7256.                        );
  7257.             } else {
  7258.                 printw("^C to cancel file transfer.");
  7259.             }
  7260. #endif /* VMS */
  7261. #endif /* CK_NEED_SIG */
  7262.         }
  7263.         refresh();
  7264.         cendw = 0;
  7265.     }
  7266.     debug(F101,"SCREENC switch","",f);
  7267.     debug(F000,"SCREENC c","",c);
  7268.     debug(F101,"SCREENC n","",n);
  7269.  
  7270.     len = strlen(s);                    /* Length of argument string */
  7271.     switch (f) {                        /* Handle our function code */
  7272.       case SCR_FN:                      /* Filename */
  7273.         oldpct = pct = 0L;              /* Reset percents */
  7274. #ifdef GFTIMER
  7275.         gtv = (CKFLOAT) -1.0;
  7276.         /* oldgtv = (CKFLOAT) -1.0; */
  7277. #else
  7278.         gtv = -1L;
  7279.         /* oldgtv = -1L; */
  7280. #endif /* GFTIMER */
  7281.         oldwin = -1;
  7282.         fsiz = (CK_OFF_T)-1;        /* Invalidate previous file size */
  7283.         move(CW_PCD,22);                /* Erase percent done from last time */
  7284. #ifdef KUI
  7285. #ifndef K95G
  7286.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PCD, (long) 0 );
  7287.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_FFC, (long) 0 );
  7288. #endif /* K95G */
  7289. #endif /* KUI */
  7290.         clrtoeol();
  7291.         move(CW_SIZ,22);                /* Erase file size from last time */
  7292. #ifdef KUI
  7293. #ifndef K95G
  7294.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_SIZ, (long) 0 );
  7295. #endif /* K95G */
  7296. #endif /* KUI */
  7297.         clrtoeol();
  7298.         move(CW_ERR,22);                /* And last error message */
  7299. #ifdef KUI
  7300. #ifndef K95G
  7301.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) "" );
  7302. #endif /* K95G */
  7303. #endif /* KUI */
  7304.         clrtoeol();
  7305. #ifdef COMMENT
  7306. #ifdef STREAMING
  7307.         if (protocol == PROTO_K && streamok) {
  7308.             move(CW_BAR, 1);
  7309. #ifdef XYZ_INTERNAL
  7310.             printw("   Kermit STREAMING:");
  7311. #else
  7312.             printw("          STREAMING:");
  7313. #endif /* XYZ_INTERNAL */
  7314.         }
  7315. #endif /* STREAMING */
  7316. #endif /* COMMENT */
  7317.  
  7318.         if (what & W_SEND) {        /* If we're sending... */
  7319. #ifdef NEWFTP
  7320.         if (what & W_FTP) {        /* FTP */
  7321.                 move(CW_NAM,13);
  7322.                 printw("FTP PUT:");
  7323.         } else
  7324. #endif /* NEWFTP */
  7325. #ifdef CK_RESEND
  7326.             switch (sendmode) {        /* Kermit */
  7327.               case SM_RESEND:
  7328.                 move(CW_NAM,11);
  7329.                 printw("RESENDING:");
  7330.                 break;
  7331.               default:
  7332.                 move(CW_NAM,13);
  7333.                 printw("SENDING:");
  7334.                 break;
  7335.             }
  7336. #else
  7337.             move(CW_NAM,13);
  7338.             printw("SENDING:");
  7339. #endif /* CK_RESEND */
  7340.  
  7341.         } else if (what & W_RECV) {    /* If we're receiving... */
  7342. #ifdef NEWFTP
  7343.         if (what & W_FTP) {        /* FTP */
  7344.                 move(CW_NAM,13);
  7345.                 printw("FTP GET:");
  7346.         } else {
  7347. #endif /* NEWFTP */
  7348.         move(CW_NAM,11);
  7349.         printw("RECEIVING:");
  7350. #ifdef NEWFTP
  7351.         }
  7352.         } else if (what == (W_FTP|W_FT_DELE)) {
  7353.         move(CW_NAM,10);
  7354.         printw("FTP DELETE:");
  7355. #endif /* NEWFTP */
  7356.         } else {                        /* If we don't know... */
  7357.             move(CW_NAM,11);            /* (should never see this) */
  7358.             printw("File Name:");
  7359.         }
  7360.         move(CW_NAM,22);                /* Display the filename */
  7361.         if (len > 57) {
  7362.             printw("%.55s..",s);
  7363.             len = 57;
  7364.         } else printw("%s",s);
  7365. #ifdef KUI
  7366. #ifndef K95G
  7367.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  7368. #endif /* K95G */
  7369. #endif /* KUI */
  7370.         q = len;                        /* Remember name length for later */
  7371.         clrtoeol();
  7372.         scrft();                        /* Display file type (can change) */
  7373.         refresh();
  7374. #ifdef OS2
  7375.         SaveCmdMode(0, 0);
  7376. #endif /* OS2 */
  7377.         return;
  7378.  
  7379.       case SCR_AN:                      /* File as-name */
  7380.         if (q + len + 4 < 58) {         /* Will fit */
  7381.             move(CW_NAM, 22 + q);
  7382.             printw(" => %s",s);
  7383. #ifdef KUI
  7384. #ifndef K95G
  7385.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  7386. #endif /* K95G */
  7387. #endif /* KUI */
  7388.         } else {                        /* Too long */
  7389.             move(CW_NAM, 22);           /* Overwrite previous name */
  7390.             q = 0;
  7391.             if (len + 4 > 57) {                                 /* wg15 */
  7392.                 printw(" => %.51s..",s);                        /* wg15 */
  7393.                 len = 53;                                       /* wg15 */
  7394.             } else printw(" => %s",s);                          /* wg15 */
  7395. #ifdef KUI
  7396. #ifndef K95G
  7397.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s  );
  7398. #endif /* K95G */
  7399. #endif /* KUI */
  7400.         }
  7401.         q += len + 4;                   /* Remember horizontal position */
  7402.         clrtoeol();
  7403.         refresh();
  7404. #ifdef OS2
  7405.         SaveCmdMode(0, 0);
  7406. #endif /* OS2 */
  7407.         return;
  7408.  
  7409.       case SCR_FS:                      /* File size */
  7410.         fsiz = n;
  7411.         move(CW_SIZ,22);
  7412.         if (fsiz > (CK_OFF_T)-1) {
  7413. #ifdef KUI
  7414. #ifndef K95G
  7415.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_SIZ, (long) n );
  7416. #endif /* K95G */
  7417. #endif /* KUI */
  7418.             printw("%s",ckfstoa(n));
  7419.         }
  7420.     if (fsiz == -2L) {
  7421.         printw("POSSIBLY EXCEEDS LOCAL FILE SIZE LIMIT");
  7422.     }
  7423.         clrtoeol();
  7424. #ifdef COMMENT
  7425.         move(CW_PCD, 8);
  7426.         if (fsiz > (CK_OFF_T)-1) {    /* Put up percent label */
  7427.             pctlbl = 1;
  7428.         clrtoeol();
  7429.             printw("Percent Done:");
  7430.         }
  7431. #else
  7432.     move(CW_PCD, 8);
  7433.     clrtoeol();
  7434.         if (fsiz > (CK_OFF_T)-1) {    /* Put up percent label */
  7435.             pctlbl = 1;
  7436.             printw("Percent Done:");
  7437.         } else {
  7438.             pctlbl = 0;
  7439.             printw("Bytes So Far:");
  7440.     }
  7441. #endif /* COMMENT */
  7442.         clrtoeol();
  7443.         scrft();                        /* File type */
  7444.         refresh();
  7445. #ifdef OS2
  7446.         SaveCmdMode(0, 0);
  7447. #endif /* OS2 */
  7448.         return;
  7449.  
  7450.       case SCR_PT:                      /* Packet type or pseudotype */
  7451.         if (spackets < 5) {
  7452.             extern int sysindex;
  7453.             extern struct sysdata sysidlist[];
  7454.             /* Things that won't change after the 4th packet */
  7455.             move(CW_PAR,22);
  7456.             printw("%s",parnam((char)parity));
  7457. #ifdef KUI
  7458. #ifndef K95G
  7459.             KuiSetProperty( KUI_FILE_TRANSFER,
  7460.                            (long) CW_PAR,
  7461.                            (long) parnam((char)parity)
  7462.                            );
  7463. #endif /* K95G */
  7464. #endif /* KUI */
  7465.             clrtoeol();
  7466. #ifdef COMMENT
  7467.             move(CW_PB, 22);            /* Block check on this packet */
  7468.             if (bctu == 4)
  7469.               printw("B");
  7470.             else
  7471.               printw("%d",bctu);
  7472.             clrtoeol();
  7473. #endif /* COMMENT */
  7474.             if (
  7475. #ifdef NEWFTP
  7476.         (ftp && (spackets == 1 || rpackets == 1)) ||
  7477. #endif /* NEWFTP */
  7478.         spackets == 4
  7479.         ) {
  7480.                 move(CW_LIN,8);
  7481.                 if (
  7482. #ifdef NEWFTP
  7483.             ftp ||
  7484. #endif /* NEWFTP */
  7485.             ((protocol == PROTO_K) && (sysindex > -1))
  7486.             ) {
  7487.                     if (net) {
  7488.                         move(CW_LIN,8);
  7489.                         printw("Network Host: %s (%s)",
  7490. #ifdef NEWFTP
  7491.                    ftp ? (ftp_host ? ftp_host : "") :
  7492. #endif /* NEWFTP */
  7493.                    ttname,
  7494. #ifdef NEWFTP
  7495.                    ftp ? ftp_srvtyp :
  7496. #endif /* NEWFTP */
  7497.                    sysidlist[sysindex].sid_name
  7498.                    );
  7499.                     } else {
  7500.                         move(CW_LIN,0);
  7501.                         printw("Communication Device: %s (remote host is %s)",
  7502.                              ttname,
  7503.                              sysidlist[sysindex].sid_name
  7504.                              );
  7505.                     }
  7506.                     clrtoeol();
  7507.                 }
  7508.             }
  7509.         }
  7510. #ifdef CK_TIMERS
  7511.         if (/* rttflg && */ protocol == PROTO_K) {
  7512.             long xx;
  7513.             if (
  7514. #ifdef STREAMING
  7515.                 streaming && oldwin != -2
  7516. #else
  7517.                 0
  7518. #endif /* STREAMING */
  7519.                 ) {
  7520.                 move(CW_TMO, 22);
  7521.                 printw("00 / 00");
  7522.                 clrtoeol();
  7523.             } else {
  7524.                 xx = (rttdelay + 500) / 1000;
  7525.                 if (xx != oldrtt || rcvtimo != oldtim) {
  7526.                     move(CW_TMO, 22);
  7527.                     printw("%02ld / %02d", xx, rcvtimo);
  7528.                     oldrtt = xx;
  7529.                     oldtim = rcvtimo;
  7530.                     clrtoeol();
  7531.                 }
  7532.             }
  7533.         }
  7534. #endif /* CK_TIMERS */
  7535.  
  7536.         x = (what & W_RECV) ?          /* Packet length */
  7537.           rpktl+(protocol==PROTO_K?1:0) :
  7538.             spktl;
  7539.         if (x != oldlen) {              /* But only if it changed. */
  7540.             move(CW_PL, 22);
  7541.             printw("%d",x);
  7542. #ifdef KUI
  7543. #ifndef K95G
  7544.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PL, (long) x );
  7545. #endif /* K95G */
  7546. #endif /* KUI */
  7547.             clrtoeol();
  7548.             oldlen = x;
  7549.         }
  7550.         move(CW_PC, 22);                /* Packet count (always). */
  7551.  
  7552.         printw("%d", (what & W_RECV) ? rpackets : spackets);
  7553. #ifdef KUI
  7554. #ifndef K95G
  7555.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PC, (long) spackets );
  7556. #endif /* K95G */
  7557. #endif /* KUI */
  7558.         clrtoeol();
  7559.  
  7560.         if (protocol == PROTO_K && !ftp) { /* Window slots */
  7561.             char ws[16];
  7562.             int flag;
  7563.             flag = 0;
  7564. #ifdef STREAMING
  7565.             if (streaming) {
  7566.                 if (oldwin != -2) {
  7567.                     sprintf(ws,"STREAMING");
  7568.                     flag = 1;
  7569.                     oldwin = -2;
  7570.                 }
  7571.             } else
  7572. #endif /* STREAMING */
  7573.               if (wcur != oldwin) {
  7574.                   sprintf(ws, "%d of %d", wcur < 1 ? 1 : wcur, wslotn);
  7575.                   flag = 1;
  7576.                   oldwin = wcur;
  7577.               }
  7578.             if (flag) {
  7579.                 move(CW_WS, 22);
  7580.                 printw("%s", ws);
  7581.                 clrtoeol();
  7582. #ifdef KUI
  7583. #ifndef K95G
  7584.                 KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_WS, (long) ws );
  7585. #endif /* K95G */
  7586. #endif /* KUI */
  7587.             }
  7588.         }
  7589.         errors = retrans + crunched + timeouts;
  7590.         if (errors != oldtry) {         /* Retry count, if changed */
  7591.             move(CW_PR, 22);
  7592.             printw("%d",errors);
  7593. #ifdef KUI
  7594. #ifndef K95G
  7595.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PR, (long) errors );
  7596. #endif /* K95G */
  7597. #endif /* KUI */
  7598.             clrtoeol();
  7599.             oldtry = errors;
  7600.         }
  7601.     /* Sender's packet type */
  7602.         if (!ftp && (c != oldtyp && c != 'Y' && c != 'N')) {
  7603.             char type[2];
  7604.             sprintf(type, "%c",c);
  7605.             move(CW_PT,22);
  7606.             printw("%s", type);
  7607. #ifdef KUI
  7608. #ifndef K95G
  7609.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PT, (long) type );
  7610. #endif /* K95G */
  7611. #endif /* KUI */
  7612.             clrtoeol();
  7613.             oldtyp = c;
  7614.         }
  7615.         switch (c) {                    /* Now handle specific packet types */
  7616.           case 'S':                     /* Beginning of transfer */
  7617.             fcnt = fbyt = 0L;           /* Clear counters */
  7618. #ifdef GFTIMER
  7619.             gtv = -1.0;
  7620. #else /* GFTIMER */
  7621.             gtv = -1L;                  /* And old/new things... */
  7622. #endif /* GFTIMER */
  7623.             oldpct = pct = 0L;
  7624.             break;
  7625.  
  7626.           case 'Z':                     /* or EOF */
  7627.             debug(F101,"screenc SCR_PT Z pktnum","",n);
  7628.             debug(F101,"screenc SCR_PT Z oldpct","",oldpct);
  7629.             debug(F101,"screenc SCR_PT Z pct","",pct);
  7630.           case 'D':                     /* Data packet */
  7631.             if (fsiz > 0L) {            /* Show percent done if known */
  7632.                 oldpct = pct;           /* Remember previous percent */
  7633.                 howfar = ffc;
  7634. #ifdef CK_RESEND
  7635.                 if (what & W_SEND)    /* Account for PSEND or RESEND */
  7636.                   howfar += sendstart;
  7637.                 else if (what & W_RECV)
  7638.                   howfar += rs_len;
  7639. #endif /* CK_RESEND */
  7640.                 /* Percent done, to be displayed... */
  7641.                 if (c == 'Z') {
  7642.                     if (!discard && !cxseen && !czseen) pct = 100L;
  7643.                 } else
  7644.                   pct = (fsiz > 99L) ? (howfar / (fsiz / 100L)) : 0L;
  7645.                 if (pct > 100L ||       /* Allow for expansion and */
  7646.                    (oldpct == 99L && pct < 0L)) /* other boundary conditions */
  7647.                   pct = 100L;
  7648.                 if (pct != oldpct)      /* Only do this 100 times per file */
  7649.                   updpct(oldpct, pct);
  7650.             } else {
  7651.                 move(CW_PCD,22);
  7652.                 printw("%s", ckfstoa(ffc));
  7653.             }
  7654. #ifdef KUI
  7655. #ifndef K95G
  7656.             KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) howfar);
  7657. #endif /* K95G */
  7658. #endif /* KUI */
  7659.             cps = shocps((int) pct, fsiz, howfar);
  7660.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  7661.             break;
  7662.  
  7663.           case '%':                     /* Timeouts, retransmissions */
  7664.             cps = shocps((int) pct, fsiz, howfar);
  7665.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  7666.  
  7667.             errors = retrans + crunched + timeouts;
  7668.             if (errors != oldtry) {     /* Error count, if changed */
  7669.                 move(CW_PR, 22);
  7670.                 printw("%d",errors);
  7671.                 clrtoeol();
  7672. #ifdef KUI
  7673. #ifndef K95G
  7674.                 KuiSetProperty(KUI_FILE_TRANSFER,
  7675.                                (long) CW_PR, (long) errors
  7676.                                );
  7677. #endif /* K95G */
  7678. #endif /* KUI */
  7679.                 }
  7680.                 oldtry = errors;
  7681.                 if (s) if (*s) {
  7682.                     move(CW_ERR,22);
  7683.                     printw("%s",s);
  7684.                     clrtoeol();
  7685. #ifdef KUI
  7686. #ifndef K95G
  7687.                     KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_ERR, (long) s);
  7688. #endif /* K95G */
  7689. #endif /* KUI */
  7690.             }
  7691.             break;
  7692.  
  7693.           case 'E':                     /* Error packet */
  7694. #ifdef COMMENT
  7695.             move(CW_ERR,22);            /* Print its data field */
  7696.             if (*s) {
  7697.                 printw("%s",s);
  7698. #ifdef KUI
  7699. #ifndef K95G
  7700.                 KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  7701. #endif /* K95G */
  7702. #endif /* KUI */
  7703.             }
  7704.             clrtoeol();
  7705. #endif /* COMMENT */
  7706.             fcnt = fbyt = 0L;           /* So no bytes for this file */
  7707.             break;
  7708.           case 'Q':                     /* Crunched packet */
  7709.             cps = shocps((int) pct, fsiz, howfar);
  7710.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  7711.             move(CW_ERR,22);
  7712.             printw("Damaged Packet");
  7713. #ifdef KUI
  7714. #ifndef K95G
  7715.             KuiSetProperty(KUI_FILE_TRANSFER,
  7716.                            (long) CW_ERR,
  7717.                            (long) "Damaged Packet"
  7718.                            );
  7719. #endif /* K95G */
  7720. #endif /* KUI */
  7721.             clrtoeol();
  7722.             break;
  7723.           case 'q':                     /* Ctrl-C or connection lost */
  7724.             move(CW_MSG,22);
  7725.         clrtoeol();
  7726.             if (!s) s = "";
  7727.             printw(*s ? s : "User interruption or connection lost");
  7728. #ifdef KUI
  7729. #ifndef K95G
  7730.             KuiSetProperty(KUI_FILE_TRANSFER,
  7731.                            (long) CW_MSG,
  7732.                            (long) s
  7733.                            );
  7734. #endif /* K95G */
  7735. #endif /* KUI */
  7736.             break;
  7737.           case 'T':                     /* Timeout */
  7738.             cps = shocps((int) pct, fsiz, howfar);
  7739.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  7740.             move(CW_ERR,22);
  7741.             printw("Timeout %d sec",rcvtimo);
  7742. #ifdef KUI
  7743. #ifndef K95G
  7744.             KuiSetProperty(KUI_FILE_TRANSFER,
  7745.                            (long) CW_ERR,
  7746.                            (long) "Timeout"
  7747.                            );
  7748. #endif /* K95G */
  7749. #endif /* KUI */
  7750.             clrtoeol();
  7751.             errors = retrans + crunched + timeouts;
  7752.             if (errors != oldtry) {     /* Error count, if changed */
  7753.                 move(CW_PR, 22);
  7754.                 printw("%d",errors);
  7755. #ifdef KUI
  7756. #ifndef K95G
  7757.                 KuiSetProperty(KUI_FILE_TRANSFER,
  7758.                                (long) CW_PR, (long) errors
  7759.                                );
  7760. #endif /* K95G */
  7761. #endif /* KUI */
  7762.                 clrtoeol();
  7763.                 oldtry = errors;
  7764.             }
  7765.             break;
  7766.           default:                      /* Others, do nothing */
  7767.             break;
  7768.         }
  7769.         refresh();
  7770. #ifdef OS2
  7771.         SaveCmdMode(0, 0);
  7772. #endif /* OS2 */
  7773.         return;
  7774.  
  7775.       case SCR_ST:                      /* File transfer status */
  7776.         debug(F101,"screenc SCR_ST c","",c);
  7777.         debug(F101,"screenc SCR_ST success","",success);
  7778.         debug(F101,"screenc SCR_ST cxseen","",cxseen);
  7779. #ifdef COMMENT
  7780.         move(CW_PCD,22);                /* Update percent done */
  7781.         if (c == ST_OK) {               /* OK, print 100 % */
  7782.             if (pctlbl)
  7783.               updpct(oldpct,100);
  7784.             else
  7785.               printw("%s", ckfstoa(ffc));
  7786. #ifdef KUI
  7787. #ifndef K95G
  7788.             KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  7789. #endif /* K95G */
  7790. #endif /* KUI */
  7791.             pct = 100;
  7792.             oldpct = 0;
  7793.         } else if (fsiz > 0L)           /* Not OK, update final percent */
  7794. /*
  7795.   The else part writes all over the screen -- howfar and/or fsiz have
  7796.   been reset as a consequence of the not-OKness of the transfer.
  7797. */
  7798.           if (pctlbl)
  7799.             updpct(oldpct, (howfar * 100L) / fsiz);
  7800.         clrtoeol();
  7801. #else
  7802.         if (c == ST_OK) {               /* OK, print 100 % */
  7803.             move(CW_PCD,22);            /* Update percent done */
  7804.             if (pctlbl) {
  7805.         if (oldpct == 0)    /* Switching from "bytes so far" */
  7806.           clrtoeol();        /* to "percent done"... */
  7807.         updpct(oldpct,100);
  7808.         } else
  7809.               printw("%s", ckfstoa(ffc));
  7810. #ifdef KUI
  7811. #ifndef K95G
  7812.             KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  7813. #endif /* K95G */
  7814. #endif /* KUI */
  7815. #ifdef COMMENT
  7816.             pct = 100;
  7817.             oldpct = 0;
  7818. #endif /* COMMENT */
  7819.             clrtoeol();
  7820.         }
  7821. #endif /* COMMENT */
  7822.  
  7823. #ifdef COMMENT
  7824. /* No, leave it there so they can read it */
  7825.         move(CW_MSG,22);                /* Remove any previous message */
  7826. #ifdef KUI
  7827. #ifndef K95G
  7828.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_MSG, (long) "" );
  7829. #endif /* K95G */
  7830. #endif /* KUI */
  7831.         clrtoeol(); refresh();
  7832. #endif /* COMMENT */
  7833.  
  7834.         move(CW_TR, 22);
  7835. #ifdef KUI
  7836. #ifndef K95G
  7837.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_TR, (long) "" );
  7838. #endif /* K95G */
  7839. #endif /* KUI */
  7840.         clrtoeol(); refresh();
  7841.  
  7842.         switch (c) {                    /* Print new status message */
  7843.           case ST_OK:                   /* Transfer OK */
  7844.             fcnt++;                     /* Count this file */
  7845.         if (what == (W_FTP|W_FT_DELE)) {
  7846.         move(CW_MSG,22);
  7847.         clrtoeol();
  7848.         printw("Delete OK");
  7849.         } else {
  7850.         fbyt += ffc;
  7851.         move(CW_MSG,22);
  7852.         clrtoeol();
  7853.         printw("Transfer OK");
  7854.         }
  7855. #ifdef KUI
  7856. #ifndef K95G
  7857.             KuiSetProperty(KUI_FILE_TRANSFER,
  7858.                            (long) CW_MSG,
  7859.                            (long) "Transfer OK"
  7860.                            );
  7861. #endif /* K95G */
  7862. #endif /* KUI */
  7863.             clrtoeol(); refresh();
  7864.             return;
  7865.  
  7866.           case ST_DISC:                 /* Discarded */
  7867.             move(CW_ERR,22);
  7868.             printw("File discarded");
  7869. #ifdef KUI
  7870. #ifndef K95G
  7871.             KuiSetProperty(KUI_FILE_TRANSFER,
  7872.                            (long) CW_ERR,
  7873.                            (long) "File discarded"
  7874.                            );
  7875. #endif /* K95G */
  7876. #endif /* KUI */
  7877. #ifdef COMMENT
  7878.             pct = oldpct = 0;
  7879. #endif /* COMMENT */
  7880.             clrtoeol(); refresh();
  7881.             return;
  7882.  
  7883.           case ST_INT:                  /* Interrupted */
  7884.             move(CW_ERR,22);
  7885.             printw("Transfer interrupted");
  7886. #ifdef KUI
  7887. #ifndef K95G
  7888.             KuiSetProperty(KUI_FILE_TRANSFER,
  7889.                            (long) CW_ERR,
  7890.                            (long) "Transfer interrupted"
  7891.                            );
  7892. #endif /* K95G */
  7893. #endif /* KUI */
  7894. #ifdef COMMENT
  7895.             pct = oldpct = 0;
  7896. #endif /* COMMENT */
  7897.             clrtoeol(); refresh();
  7898.             return;
  7899.  
  7900.           case ST_SKIP:                 /* Skipped */
  7901.             move(CW_ERR,22);
  7902.         if (n > 0 && n < nskreason)
  7903.           printw("File skipped (%s)",skreason[n]);
  7904.         else
  7905.           printw("File skipped");
  7906. #ifdef KUI
  7907. #ifndef K95G
  7908.             KuiSetProperty(KUI_FILE_TRANSFER,
  7909.                            (long) CW_ERR,
  7910.                            (long) "File skipped"
  7911.                            );
  7912. #endif /* K95G */
  7913. #endif /* KUI */
  7914. #ifdef COMMENT
  7915.             pct = oldpct = 0;
  7916. #endif /* COMMENT */
  7917.             clrtoeol(); refresh();
  7918.             return;
  7919.  
  7920.           case ST_ERR:                  /* Error message */
  7921.             move(CW_ERR,22);
  7922.             if (!s) s = (char *)epktmsg;
  7923.             printw("%s",s);
  7924. #ifdef KUI
  7925. #ifndef K95G
  7926.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  7927. #endif /* K95G */
  7928. #endif /* KUI */
  7929. #ifdef COMMENT
  7930.             pct = oldpct = 0;
  7931. #endif /* COMMENT */
  7932.             clrtoeol(); refresh();
  7933.             return;
  7934.  
  7935.           case ST_REFU:                 /* Refused */
  7936.             move(CW_ERR,22);
  7937.             if (*s) {
  7938.                 char errbuf[64] ;
  7939.                 sprintf( errbuf, "Refused, %s", s ) ;
  7940.                 printw("%s", errbuf);
  7941. #ifdef KUI
  7942. #ifndef K95G
  7943.                 KuiSetProperty(KUI_FILE_TRANSFER,(long) CW_ERR,(long) errbuf);
  7944. #endif /* K95G */
  7945. #endif /* KUI */
  7946.             } else {
  7947.                 printw("Refused");
  7948. #ifdef KUI
  7949. #ifndef K95G
  7950.                 KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_ERR,(long)"Refused");
  7951. #endif /* K95G */
  7952. #endif /* KUI */
  7953.             }
  7954. #ifdef COMMENT
  7955.             pct = oldpct = 0;
  7956. #endif /* COMMENT */
  7957.             clrtoeol(); refresh();
  7958.             return;
  7959.  
  7960.           case ST_INC:
  7961.             move(CW_ERR,22);
  7962.             printw("Incomplete");
  7963. #ifdef KUI
  7964. #ifndef K95G
  7965.             KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_ERR,(long)"Incomplete");
  7966. #endif /* K95G */
  7967. #endif /* KUI */
  7968. #ifdef COMMENT
  7969.             pct = oldpct = 0;
  7970. #endif /* COMMENT */
  7971.             clrtoeol(); refresh();
  7972.             return;
  7973.  
  7974.           case ST_MSG:
  7975.             move(CW_MSG,22);
  7976.             printw("%s",s);
  7977. #ifdef KUI
  7978. #ifndef K95G
  7979.             KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_MSG,(long)s);
  7980. #endif /* K95G */
  7981. #endif /* KUI */
  7982.             clrtoeol(); refresh();
  7983.             return;
  7984.  
  7985.           default:                      /* Bad call */
  7986.             move(CW_ERR,22);
  7987.             printw("*** screen() called with bad status ***");
  7988. #ifdef KUI
  7989. #ifndef K95G
  7990.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR,
  7991.                        (long) "*** screen() called with bad status ***" );
  7992. #endif /* K95G */
  7993. #endif /* KUI */
  7994.             clrtoeol(); refresh(); return;
  7995.         }
  7996.  
  7997.       case SCR_TC: {                    /* Transaction complete */
  7998.           char msgbuf[128];
  7999.           move(CW_CP,22);               /* Overall transfer rate */
  8000. #ifdef KUI
  8001. #ifndef K95G
  8002.           KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, tfcps);
  8003. #endif /* K95G */
  8004. #endif /* KUI */
  8005.           printw("%s", ckfstoa(tfcps));
  8006.           clrtoeol();
  8007.           if (success) {
  8008.               move(CW_MSG,22);          /* Print statistics in message line */
  8009.               clrtoeol();
  8010.           }
  8011.           if (success) {
  8012.               sprintf(msgbuf,
  8013.                       "SUCCESS.  Files: %ld, Bytes: %s, %ld CPS",
  8014.                       filcnt - filrej,
  8015.                       ckfstoa(fbyt),
  8016.                       tfcps
  8017.                       );
  8018.               printw("%s", msgbuf);
  8019. #ifdef KUI
  8020. #ifndef K95G
  8021.               KuiSetProperty(KUI_FILE_TRANSFER,
  8022.                              (long) CW_MSG,
  8023.                              (long) msgbuf
  8024.                              );
  8025. #endif /* K95G */
  8026. #endif /* KUI */
  8027.               clrtoeol();
  8028.  
  8029.           }
  8030.           move(CW_TR, 1);
  8031.           printw("       Elapsed Time: %s",hhmmss((long)
  8032. #ifdef GFTIMER
  8033.                                                   (fptsecs + 0.5)
  8034. #else
  8035.                                                   tsecs
  8036. #endif /* GFTIMER */
  8037.                                                    ));
  8038. #ifdef KUI
  8039. #ifndef K95G
  8040.           KuiSetProperty(KUI_FILE_TRANSFER,
  8041.                          (long) CW_TR,
  8042.                          (long) hhmmss((long)
  8043. #ifdef GFTIMER
  8044.                                        (fptsecs + 0.5)
  8045. #else
  8046.                                        tsecs
  8047. #endif /* GFTIMER */
  8048.                                        ));
  8049. #endif /* K95G */
  8050. #endif /* KUI */
  8051.           clrtoeol();
  8052.           move(23,0); clrtoeol();       /* Clear instructions lines */
  8053.           move(22,0); clrtoeol();       /* to make room for prompt. */
  8054.           refresh();
  8055.  
  8056. #ifdef GFTIMER
  8057.           oldgtv = (CKFLOAT) -1.0;
  8058. #else
  8059.           oldgtv = -1L;
  8060. #endif /* GFTIMER */
  8061.  
  8062. #ifndef VMSCURSE
  8063.       debug(F100,"screenc endwin A","",0);
  8064.           endwin();
  8065. #ifdef COMMENT
  8066. /*
  8067.   Why and when was this call to conres() added?  It makes no sense,
  8068.   and it breaks echoing on Solaris 8.
  8069. */
  8070. #ifdef SOLARIS
  8071.           conres();
  8072. #endif /* SOLARIS */
  8073. #endif /* COMMENT */
  8074. #endif /* VMSCURSE */
  8075.  
  8076. #ifdef COMMENT
  8077.           pct = 100; oldpct = 0;        /* Reset these for next time. */
  8078. #endif /* COMMENT */
  8079.           oldtyp = 0; oldrtt = -1L; oldtry = -1; oldlen = -1;
  8080.           oldtim = -1;
  8081.           cendw = 1;
  8082.           if (xfrbel) bleep(BP_NOTE);   /* Close window, then beep. */
  8083. #ifdef UNIX
  8084.           fflush(stdout);
  8085. #endif /* UNIX */
  8086.           ft_win = 0;                   /* Window closed. */
  8087.           return;
  8088.       }
  8089.       case SCR_EM:                      /* Error packet (fatal) */
  8090.         move (CW_ERR,22);
  8091.         printw("FAILURE: %s",s);
  8092. #ifdef KUI
  8093. #ifndef K95G
  8094.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  8095. #endif /* K95G */
  8096. #endif /* KUI */
  8097.         if (xfrbel) bleep(BP_FAIL);
  8098. #ifdef COMMENT
  8099.         pct = oldpct = 0;
  8100. #endif /* COMMENT */
  8101.         clrtoeol(); refresh(); return;
  8102.  
  8103.       case SCR_QE:                      /* Quantity equals */
  8104.       case SCR_TU:                      /* Undelimited text */
  8105.       case SCR_TN:                      /* Text delimited at start */
  8106.       case SCR_TZ:                      /* Text delimited at end */
  8107.         return;                         /* (ignored in fullscreen display) */
  8108.  
  8109.       case SCR_MS:            /* Message from Kermit partner */
  8110.         move(CW_MSG,22);
  8111.     printw("%s",s);
  8112.         clrtoeol(); refresh(); return;
  8113.  
  8114.       case SCR_XD:                      /* X-packet data */
  8115.         pct = oldpct = 0;
  8116.         move(CW_NAM,22);
  8117.         printw("%s",s);
  8118. #ifdef KUI
  8119. #ifndef K95G
  8120.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  8121. #endif /* K95G */
  8122. #endif /* KUI */
  8123.         clrtoeol(); refresh(); return;
  8124.  
  8125.       case SCR_CW:                      /* Close Window */
  8126.         clrtoeol(); move(23,0); clrtoeol(); move(22,0); clrtoeol();
  8127.         refresh();
  8128. #ifdef COMMENT
  8129.         pct = 100; oldpct = 0;          /* Reset these for next time. */
  8130. #endif /* COMMENT */
  8131.         oldtyp = 0; oldrtt = -1L; oldtry = -1; oldlen = -1;
  8132.         oldtim = -1;
  8133.  
  8134. #ifndef VMSCURSE
  8135.     debug(F100,"screenc endwin B","",0);
  8136.         endwin();
  8137. #endif /* VMSCURSE */
  8138.         ft_win = 0;                     /* Flag that window is closed. */
  8139.         cendw = 1; return;
  8140.  
  8141.       case SCR_CD:                      /* Display current directory */
  8142.         move(CW_DIR,22);
  8143.          printw("%s", s);
  8144. #ifdef KUI
  8145. #ifndef K95G
  8146.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_DIR, (long) s );
  8147. #endif /* K95G */
  8148. #endif /* KUI */
  8149.         clrtoeol();
  8150.         refresh();
  8151. #ifdef OS2
  8152.         SaveCmdMode(0, 0);
  8153. #endif /* OS2 */
  8154.         return;
  8155.  
  8156.       default:                          /* Bad call */
  8157.         move (CW_ERR,22);
  8158. #ifdef KUI
  8159. #ifndef K95G
  8160.         KuiSetProperty(KUI_FILE_TRANSFER,
  8161.                        (long) CW_ERR,
  8162.                        (long) "*** screen() called with bad function code ***"
  8163.                        );
  8164. #endif /* K95G */
  8165. #endif /* KUI */
  8166.         printw("*** screen() called with bad function code ***");
  8167.         clrtoeol(); refresh(); return;
  8168.     }
  8169. }
  8170. #endif /* CK_CURSES */
  8171.  
  8172. #ifdef KUI
  8173. #ifdef CK_ANSIC
  8174. void
  8175. screeng(int f, char c,long n,char *s)
  8176. #else
  8177. VOID
  8178. screeng(f,c,n,s)
  8179. int f;          /* argument descriptor */
  8180. char c;         /* a character or small integer */
  8181. long n;         /* a long integer */
  8182. char *s;        /* a string */
  8183. #endif /* CK_ANSIC */
  8184. /* screeng() */ {
  8185. #ifdef CK_SSL
  8186.     extern int tls_active_flag, ssl_active_flag;
  8187. #endif /* CK_SSL */
  8188. #ifdef RLOGCODE
  8189.     extern int ttnproto;
  8190. #endif /* RLOGCODE */
  8191.     static int q = 0;
  8192.     static CK_OFF_T fsiz = (CK_OFF_T)-1; /* Copy of file size */
  8193.     static long fcnt = 0L;    /* Number of files transferred */
  8194.     static long fbyt = 0L;    /* Total file bytes of all files transferred */
  8195.     static CK_OFF_T howfar = (CK_OFF_T)0; /* How much of file xfer'd so far */
  8196.     static int  pctlbl = 0L;  /* Percent done vs Bytes so far */
  8197.     long cps = 0L;
  8198.  
  8199.     int net = 0;
  8200.     int xnet = 0;
  8201.     int ftp = 0;
  8202.     int len;                            /* Length of string */
  8203.     int errors = 0;                     /* Error counter */
  8204.     int x;                              /* Worker */
  8205.  
  8206.     debug(F101,"screeng cinit","",cinit);
  8207.     debug(F101,"screeng cendw","",cendw);
  8208.  
  8209.     if (!s) s = "";                     /* Always do this. */
  8210.  
  8211.     ftp = (what & W_FTP) ? 1 : 0;    /* FTP or Kermit */
  8212.     net = network || ftp;
  8213.     xnet = ftp ? 1 : nettype;        /* NET_TCPB == 1 */
  8214.  
  8215.     if (cinit == 0 || cendw > 0) {      /* Handle borderline cases... */
  8216.         if (f == SCR_CW) {              /* Close window, but it's not open */
  8217.             ft_win = 0;
  8218.             return;
  8219.         }
  8220.         debug(F111,"screeng A",s,f);
  8221.         if (f == SCR_EM ||
  8222.            (f == SCR_PT && c == 'E')) { /* Fatal error before window open */
  8223.             conoll(""); conoc('?'); conoll(s); return; /* Regular display */
  8224.         }
  8225.     }
  8226.     if (cinit == 0) {                   /* Only call initscr() once */
  8227.     /* Check these now -- if they are defined but not numeric */
  8228.     /* they can crash curses */
  8229.         cendw = 1;                      /* New window needs repainting */
  8230.         debug(F100,"screeng calling initscr","",0);
  8231.         initscr();                      /* Initialize curses. */
  8232.         debug(F100,"screeng initscr ok","",0);
  8233.         cinit++;                        /* Remember curses was initialized. */
  8234.     }
  8235.     ft_win = 1;                         /* Window is open */
  8236.     if (repaint) {
  8237. #ifdef CK_WREFRESH
  8238. /*
  8239.   This totally repaints the screen, just what we want, but we can only
  8240.   do this with real curses, and then only if clearok() and wrefresh() are
  8241.   provided in the curses library.
  8242. */
  8243.         RestoreCmdMode();
  8244. #else  /* No CK_WREFRESH */
  8245. /*
  8246.   Kermit's do-it-yourself method, works with all types of fullscreen
  8247.   support, but does not repaint all the fields.  For example, the filename
  8248.   is lost, because it arrives at a certain time and never comes again, and
  8249.   Kermit presently does not save it anywhere.  Making this method work for
  8250.   all fields would be a rather major recoding task, duplicating what curses
  8251.   already does, and would add a lot of complexity and storage space.
  8252. */
  8253.         cendw = 1;
  8254. #endif /* CK_WREFRESH */
  8255.         repaint = 0;
  8256.     }
  8257.     if (cendw) {                        /* endwin() was called previously */
  8258.         debug(F100,"screeng setup ok","",0);
  8259.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_DIR, (long) zgtdir() );
  8260.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_LIN,
  8261.                         (long) (
  8262. #ifdef NEWFTP
  8263.                                 ftp ? (ftp_host ? ftp_host : "(unknown)") :
  8264. #endif /* NEWFTP */
  8265.                                 ttname) );
  8266.  
  8267.         if (net) {
  8268. #ifdef NETCONN
  8269.         int secure = 0;
  8270.         char * xname;
  8271.         if (xnet > nnetname)
  8272.           xname = "[ERROR]";
  8273.         else
  8274.           xname = netname[xnet];
  8275. #ifdef NEWFTP
  8276.             if (ftp) {
  8277.         if (ftpissecure())
  8278.           secure = 1;
  8279.         } else
  8280. #endif /* NEWFTP */
  8281.           if (0
  8282. #ifdef SSHBUILTIN
  8283.                 || IS_SSH()
  8284. #endif /* SSHBUILTIN */
  8285. #ifdef CK_ENCRYPTION
  8286.                 || ck_tn_encrypting() && ck_tn_decrypting()
  8287. #endif /* CK_ENCRYPTION */
  8288. #ifdef CK_SSL
  8289.                 || tls_active_flag || ssl_active_flag
  8290. #endif /* CK_SSL */
  8291. #ifdef RLOGCODE
  8292. #ifdef CK_KERBEROS
  8293. #ifdef CK_ENCRYPTION
  8294.                 || ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN
  8295. #endif /* CK_ENCRYPTION */
  8296. #endif /* CK_KERBEROS */
  8297. #endif /* RLOGCODE */
  8298.                  ) {
  8299.         secure = 1;
  8300.         }
  8301.         if (secure) {
  8302.                 char buf[30];
  8303.                 sprintf(buf,"%s (SECURE)",xname);
  8304.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8305.                                (long) CW_SPD,
  8306.                                (long) buf
  8307.                                );
  8308.             } else {
  8309.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8310.                                (long) CW_SPD,
  8311.                                (long) xname
  8312.                                );
  8313.             }
  8314. #else
  8315.             KuiSetProperty(KUI_FILE_TRANSFER,
  8316.                            (long) CW_SPD,
  8317.                            (long) "(network)"
  8318.                            );
  8319. #endif /* NETCONN */
  8320.         } else {
  8321.             if (speed < 0L)
  8322.               speed = ttgspd();
  8323.             if (speed > 0L) {
  8324.                 if (speed == 8880) {
  8325.                     KuiSetProperty(KUI_FILE_TRANSFER,
  8326.                                    (long) CW_SPD,
  8327.                                    (long) "75/1200"
  8328.                                    );
  8329.                 } else {
  8330.                     char speedbuf[64] ;
  8331.                     sprintf(speedbuf, "%ld", speed);
  8332.                     KuiSetProperty(KUI_FILE_TRANSFER,
  8333.                                    (long) CW_SPD,
  8334.                                    (long) speedbuf
  8335.                                    );
  8336.                 }
  8337.             } else {
  8338.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8339.                                (long) CW_SPD,
  8340.                                (long) "(unknown)"
  8341.                                );
  8342.             }
  8343.         }
  8344.         KuiSetProperty(KUI_FILE_TRANSFER,
  8345.                        (long) CW_PAR,
  8346.                        (long) parnam((char)parity)
  8347.                        );
  8348.         pctlbl = (what & W_SEND);
  8349.         cendw = 0;
  8350.     }
  8351.     debug(F101,"SCREENC switch","",f);
  8352.     debug(F000,"SCREENC c","",c);
  8353.     debug(F101,"SCREENC n","",n);
  8354.  
  8355.     len = strlen(s);                    /* Length of argument string */
  8356.     switch (f) {                        /* Handle our function code */
  8357.       case SCR_FN:                      /* Filename */
  8358.         oldpct = pct = 0L;              /* Reset percents */
  8359. #ifdef GFTIMER
  8360.         gtv = (CKFLOAT) -1.0;
  8361.         /* oldgtv = (CKFLOAT) -1.0; */
  8362. #else
  8363.         gtv = -1L;
  8364.         /* oldgtv = -1L; */
  8365. #endif /* GFTIMER */
  8366.         oldwin = -1;
  8367.         fsiz = (CK_OFF_T)-1L;        /* Invalidate previous file size */
  8368.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PCD, (long) 0 );
  8369.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_FFC, (long) 0 );
  8370.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_SIZ, (long) 0 );
  8371.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) "" );
  8372.  
  8373.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  8374.         q = len;                        /* Remember name length for later */
  8375.         scrft();                        /* Display file type (can change) */
  8376. #ifdef OS2
  8377.         SaveCmdMode(0, 0);
  8378. #endif /* OS2 */
  8379.         return;
  8380.  
  8381.       case SCR_AN:                      /* File as-name */
  8382.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  8383. #ifdef OS2
  8384.         SaveCmdMode(0, 0);
  8385. #endif /* OS2 */
  8386.         return;
  8387.  
  8388.       case SCR_FS:                      /* File size */
  8389.         fsiz = n;
  8390.         if (fsiz > (CK_OFF_T)-1) {
  8391.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_SIZ, (long) n );
  8392.         }
  8393.         if (fsiz > (CK_OFF_T)-1) {    /* Put up percent label */
  8394.             pctlbl = 1;
  8395.         } else {
  8396.             pctlbl = 0;
  8397.     }
  8398.         scrft();                        /* File type */
  8399. #ifdef OS2
  8400.         SaveCmdMode(0, 0);
  8401. #endif /* OS2 */
  8402.         return;
  8403.  
  8404.       case SCR_PT:                      /* Packet type or pseudotype */
  8405.         if (spackets < 5) {
  8406.             extern int sysindex;
  8407.             extern struct sysdata sysidlist[];
  8408.             /* Things that won't change after the 4th packet */
  8409.             KuiSetProperty( KUI_FILE_TRANSFER,
  8410.                            (long) CW_PAR,
  8411.                            (long) parnam((char)parity)
  8412.                            );
  8413.             if (
  8414. #ifdef NEWFTP
  8415.         (ftp && (spackets == 1 || rpackets == 1)) ||
  8416. #endif /* NEWFTP */
  8417.         spackets == 4
  8418.         ) {
  8419.                 if (
  8420. #ifdef NEWFTP
  8421.             ftp ||
  8422. #endif /* NEWFTP */
  8423.             ((protocol == PROTO_K) && (sysindex > -1))
  8424.             ) {
  8425.                     char msgbuf[128];
  8426.                     if (net) {
  8427.                         sprintf(msgbuf,"Network Host: %s (%s)",
  8428. #ifdef NEWFTP
  8429.                    ftp ? (ftp_host ? ftp_host : "") :
  8430. #endif /* NEWFTP */
  8431.                    ttname,
  8432. #ifdef NEWFTP
  8433.                    ftp ? ftp_srvtyp :
  8434. #endif /* NEWFTP */
  8435.                    sysidlist[sysindex].sid_name
  8436.                    );
  8437.                     } else {
  8438.                         sprintf(msgbuf,
  8439.                 "Communication Device: %s (remote host is %s)",
  8440.                 ttname,
  8441.                 sysidlist[sysindex].sid_name
  8442.                 );
  8443.                     }
  8444.                     KuiSetProperty( KUI_FILE_TRANSFER,
  8445.                     (long) CW_LIN,
  8446.                     (long) msgbuf
  8447.                     );
  8448.                 }
  8449.             }
  8450.         }
  8451. #ifdef CK_TIMERS
  8452.         if (/* rttflg && */ protocol == PROTO_K) {
  8453.             long xx;
  8454.             if (
  8455. #ifdef STREAMING
  8456.                 streaming && oldwin != -2
  8457. #else
  8458.                 0
  8459. #endif /* STREAMING */
  8460.                 ) {
  8461.                 char msgbuf[64];
  8462.                 sprintf(msgbuf,"00 / 00");
  8463.                 KuiSetProperty( KUI_FILE_TRANSFER,
  8464.                 (long) CW_TMO,
  8465.                 (long) msgbuf
  8466.                 );
  8467.             } else {
  8468.                 xx = (rttdelay + 500) / 1000;
  8469.                 if (xx != oldrtt || rcvtimo != oldtim) {
  8470.                     char msgbuf[64];
  8471.                     sprintf(msgbuf,"%02ld / %02d", xx, rcvtimo);
  8472.                     KuiSetProperty( KUI_FILE_TRANSFER,
  8473.                     (long) CW_TMO,
  8474.                     (long) msgbuf
  8475.                     );
  8476.                     oldrtt = xx;
  8477.                     oldtim = rcvtimo;
  8478.                     clrtoeol();
  8479.                 }
  8480.             }
  8481.         }
  8482. #endif /* CK_TIMERS */
  8483.  
  8484.         x = (what & W_RECV) ?          /* Packet length */
  8485.           rpktl+(protocol==PROTO_K?1:0) :
  8486.             spktl;
  8487.         if (x != oldlen) {              /* But only if it changed. */
  8488.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PL, (long) x );
  8489.             oldlen = x;
  8490.         }
  8491.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PC, (long) spackets );
  8492.  
  8493.         if (protocol == PROTO_K && !ftp) { /* Window slots */
  8494.             char ws[16];
  8495.             int flag;
  8496.             flag = 0;
  8497. #ifdef STREAMING
  8498.             if (streaming) {
  8499.                 if (oldwin != -2) {
  8500.                     sprintf(ws,"STREAMING");
  8501.                     flag = 1;
  8502.                     oldwin = -2;
  8503.                 }
  8504.             } else
  8505. #endif /* STREAMING */
  8506.               if (wcur != oldwin) {
  8507.                   sprintf(ws, "%d of %d", wcur < 1 ? 1 : wcur, wslotn);
  8508.                   flag = 1;
  8509.                   oldwin = wcur;
  8510.               }
  8511.             if (flag) {
  8512.                 KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_WS, (long) ws );
  8513.             }
  8514.         }
  8515.         errors = retrans + crunched + timeouts;
  8516.         if (errors != oldtry) {         /* Retry count, if changed */
  8517.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PR, (long) errors );
  8518.             oldtry = errors;
  8519.         }
  8520.     /* Sender's packet type */
  8521.         if (!ftp && (c != oldtyp && c != 'Y' && c != 'N')) {
  8522.             char type[2];
  8523.             sprintf(type, "%c",c);
  8524.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PT, (long) type );
  8525.             oldtyp = c;
  8526.         }
  8527.         switch (c) {                    /* Now handle specific packet types */
  8528.           case 'S':                     /* Beginning of transfer */
  8529.             fcnt = fbyt = 0L;           /* Clear counters */
  8530. #ifdef GFTIMER
  8531.             gtv = -1.0;
  8532. #else /* GFTIMER */
  8533.             gtv = -1L;                  /* And old/new things... */
  8534. #endif /* GFTIMER */
  8535.             oldpct = pct = 0L;
  8536.             break;
  8537.  
  8538.           case 'Z':                     /* or EOF */
  8539.             debug(F101,"screeng SCR_PT Z pktnum","",n);
  8540.             debug(F101,"screeng SCR_PT Z oldpct","",oldpct);
  8541.             debug(F101,"screeng SCR_PT Z pct","",pct);
  8542.           case 'D':                     /* Data packet */
  8543.             if (fsiz > 0L) {            /* Show percent done if known */
  8544.                 oldpct = pct;           /* Remember previous percent */
  8545.                 howfar = ffc;
  8546. #ifdef CK_RESEND
  8547.                 if (what & W_SEND)    /* Account for PSEND or RESEND */
  8548.                   howfar += sendstart;
  8549.                 else if (what & W_RECV)
  8550.                   howfar += rs_len;
  8551. #endif /* CK_RESEND */
  8552.                 /* Percent done, to be displayed... */
  8553.                 if (c == 'Z') {
  8554.                     if (!discard && !cxseen && !czseen) pct = 100L;
  8555.                 } else
  8556.                   pct = (fsiz > 99L) ? (howfar / (fsiz / 100L)) : 0L;
  8557.                 if (pct > 100L ||       /* Allow for expansion and */
  8558.                    (oldpct == 99L && pct < 0L)) /* other boundary conditions */
  8559.                   pct = 100L;
  8560.                 if (pct != oldpct)      /* Only do this 100 times per file */
  8561.                   updpct(oldpct, pct);
  8562.             } else {
  8563.                 KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  8564.             }
  8565.             KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) howfar);
  8566.             cps = shocps((int) pct, fsiz, howfar);
  8567.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  8568.             break;
  8569.  
  8570.           case '%':                     /* Timeouts, retransmissions */
  8571.             cps = shocps((int) pct, fsiz, howfar);
  8572.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  8573.  
  8574.             errors = retrans + crunched + timeouts;
  8575.             if (errors != oldtry) {     /* Error count, if changed */
  8576.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8577.                                (long) CW_PR,
  8578.                    (long) errors
  8579.                                );
  8580.                 }
  8581.                 oldtry = errors;
  8582.                 if (s) if (*s) {
  8583.                     KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_ERR, (long) s);
  8584.             }
  8585.             break;
  8586.  
  8587.           case 'E':                     /* Error packet */
  8588.             if (*s) {
  8589.                 KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  8590.             }
  8591.             fcnt = fbyt = 0L;           /* So no bytes for this file */
  8592.             break;
  8593.           case 'Q':                     /* Crunched packet */
  8594.             cps = shocps((int) pct, fsiz, howfar);
  8595.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  8596.             KuiSetProperty(KUI_FILE_TRANSFER,
  8597.                            (long) CW_ERR,
  8598.                            (long) "Damaged Packet"
  8599.                            );
  8600.             break;
  8601.           case 'q':                     /* Ctrl-C or connection lost */
  8602.             if (!s) s = "";
  8603.             if (!*s) s = "User interruption or connection lost";
  8604.             KuiSetProperty(KUI_FILE_TRANSFER,
  8605.                            (long) CW_MSG,
  8606.                            (long) s
  8607.                            );
  8608.             break;
  8609.           case 'T':                     /* Timeout */
  8610.             cps = shocps((int) pct, fsiz, howfar);
  8611.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  8612.             KuiSetProperty(KUI_FILE_TRANSFER,
  8613.                            (long) CW_ERR,
  8614.                            (long) "Timeout"
  8615.                            );
  8616.             errors = retrans + crunched + timeouts;
  8617.             if (errors != oldtry) {     /* Error count, if changed */
  8618.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8619.                                (long) CW_PR, (long) errors
  8620.                                );
  8621.                 oldtry = errors;
  8622.             }
  8623.             break;
  8624.           default:                      /* Others, do nothing */
  8625.             break;
  8626.         }
  8627. #ifdef OS2
  8628.         SaveCmdMode(0, 0);
  8629. #endif /* OS2 */
  8630.         return;
  8631.  
  8632.       case SCR_ST:                      /* File transfer status */
  8633.         debug(F101,"screeng SCR_ST c","",c);
  8634.         debug(F101,"screeng SCR_ST success","",success);
  8635.         debug(F101,"screeng SCR_ST cxseen","",cxseen);
  8636. #ifdef COMMENT
  8637.         if (c == ST_OK) {               /* OK, print 100 % */
  8638.             if (pctlbl)
  8639.               updpct(oldpct,100);
  8640.             else
  8641.                 KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  8642.             pct = 100;
  8643.             oldpct = 0;
  8644.         } else if (fsiz > 0L)           /* Not OK, update final percent */
  8645. /*
  8646.   The else part writes all over the screen -- howfar and/or fsiz have
  8647.   been reset as a consequence of the not-OKness of the transfer.
  8648. */
  8649.           if (pctlbl)
  8650.             updpct(oldpct, (howfar * 100L) / fsiz);
  8651. #else
  8652.         if (c == ST_OK) {               /* OK, print 100 % */
  8653.             if (pctlbl) {
  8654.         updpct(oldpct,100);
  8655.         } else
  8656.                 KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  8657. #ifdef COMMENT
  8658.             pct = 100;
  8659.             oldpct = 0;
  8660. #endif /* COMMENT */
  8661.         }
  8662. #endif /* COMMENT */
  8663.  
  8664.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_TR, (long) "" );
  8665.  
  8666.         switch (c) {                    /* Print new status message */
  8667.           case ST_OK:                   /* Transfer OK */
  8668.             fcnt++;                     /* Count this file */
  8669.         if (what == (W_FTP|W_FT_DELE)) {
  8670.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8671.                                 (long) CW_MSG,
  8672.                                 (long) "Delete OK"
  8673.                                 );
  8674.         } else {
  8675.         fbyt += ffc;
  8676.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8677.                                 (long) CW_MSG,
  8678.                                 (long) "Transfer OK"
  8679.                                 );
  8680.         }
  8681.             return;
  8682.  
  8683.           case ST_DISC:                 /* Discarded */
  8684.             KuiSetProperty(KUI_FILE_TRANSFER,
  8685.                            (long) CW_ERR,
  8686.                            (long) "File discarded"
  8687.                            );
  8688. #ifdef COMMENT
  8689.             pct = oldpct = 0;
  8690. #endif /* COMMENT */
  8691.             return;
  8692.  
  8693.           case ST_INT:                  /* Interrupted */
  8694.             KuiSetProperty(KUI_FILE_TRANSFER,
  8695.                            (long) CW_ERR,
  8696.                            (long) "Transfer interrupted"
  8697.                            );
  8698. #ifdef COMMENT
  8699.             pct = oldpct = 0;
  8700. #endif /* COMMENT */
  8701.             return;
  8702.  
  8703.         case ST_SKIP: {                /* Skipped */
  8704.             char errbuf[64] ;
  8705.         if (n > 0 && n < nskreason)
  8706.                 sprintf( errbuf, "File skipped, (%s)", skreason[n] ) ;
  8707.         else
  8708.                 sprintf( errbuf, "File skipped" ) ;
  8709.             KuiSetProperty(KUI_FILE_TRANSFER,
  8710.                            (long) CW_ERR,
  8711.                            (long) errbuf
  8712.                            );
  8713. #ifdef COMMENT
  8714.             pct = oldpct = 0;
  8715. #endif /* COMMENT */
  8716.             return;
  8717.         }
  8718.           case ST_ERR:                  /* Error message */
  8719.             if (!s) s = (char *)epktmsg;
  8720.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  8721. #ifdef COMMENT
  8722.             pct = oldpct = 0;
  8723. #endif /* COMMENT */
  8724.             return;
  8725.  
  8726.           case ST_REFU:                 /* Refused */
  8727.             if (*s) {
  8728.                 char errbuf[64] ;
  8729.                 sprintf( errbuf, "Refused, %s", s ) ;
  8730.                 KuiSetProperty(KUI_FILE_TRANSFER,(long) CW_ERR,(long) errbuf);
  8731.             } else {
  8732.                 KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_ERR,(long)"Refused");
  8733.             }
  8734. #ifdef COMMENT
  8735.             pct = oldpct = 0;
  8736. #endif /* COMMENT */
  8737.             return;
  8738.  
  8739.           case ST_INC:
  8740.             KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_ERR,(long)"Incomplete");
  8741. #ifdef COMMENT
  8742.             pct = oldpct = 0;
  8743. #endif /* COMMENT */
  8744.             return;
  8745.  
  8746.           case ST_MSG:
  8747.             KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_MSG,(long)s);
  8748.             return;
  8749.  
  8750.           default:                      /* Bad call */
  8751.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR,
  8752.                        (long) "*** screen() called with bad status ***" );
  8753.             return;
  8754.         }
  8755.  
  8756.       case SCR_TC: {                    /* Transaction complete */
  8757.           char msgbuf[128];
  8758.           KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, tfcps);
  8759.           if (success) {
  8760.               sprintf(msgbuf,
  8761.                       "SUCCESS.  Files: %s, Bytes: %ld, %ld CPS",
  8762.                       filcnt - filrej,
  8763.                       ckfstoa(fbyt),
  8764.                       tfcps
  8765.                       );
  8766.               KuiSetProperty(KUI_FILE_TRANSFER,
  8767.                              (long) CW_MSG,
  8768.                              (long) msgbuf
  8769.                              );
  8770.           }
  8771.           KuiSetProperty(KUI_FILE_TRANSFER,
  8772.                          (long) CW_TR,
  8773.                          (long) hhmmss((long)
  8774. #ifdef GFTIMER
  8775.                                        (fptsecs + 0.5)
  8776. #else
  8777.                                        tsecs
  8778. #endif /* GFTIMER */
  8779.                                        ));
  8780.  
  8781. #ifdef GFTIMER
  8782.           oldgtv = (CKFLOAT) -1.0;
  8783. #else
  8784.           oldgtv = -1L;
  8785. #endif /* GFTIMER */
  8786.  
  8787. #ifdef COMMENT
  8788.           pct = 100; oldpct = 0;        /* Reset these for next time. */
  8789. #endif /* COMMENT */
  8790.           oldtyp = 0; oldrtt = -1L; oldtry = -1; oldlen = -1;
  8791.           oldtim = -1;
  8792.           cendw = 1;
  8793.           if (xfrbel) bleep(BP_NOTE);   /* Close window, then beep. */
  8794.           ft_win = 0;                   /* Window closed. */
  8795.           return;
  8796.       }
  8797.       case SCR_EM:                      /* Error packet (fatal) */
  8798.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  8799.         if (xfrbel) bleep(BP_FAIL);
  8800. #ifdef COMMENT
  8801.         pct = oldpct = 0;
  8802. #endif /* COMMENT */
  8803.         return;
  8804.  
  8805.       case SCR_QE:                      /* Quantity equals */
  8806.       case SCR_TU:                      /* Undelimited text */
  8807.       case SCR_TN:                      /* Text delimited at start */
  8808.       case SCR_TZ:                      /* Text delimited at end */
  8809.         return;                         /* (ignored in fullscreen display) */
  8810.  
  8811.       case SCR_XD:                      /* X-packet data */
  8812.         pct = oldpct = 0;
  8813.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  8814.         return;
  8815.  
  8816.       case SCR_CW:                      /* Close Window */
  8817. #ifdef COMMENT
  8818.         pct = 100; oldpct = 0;          /* Reset these for next time. */
  8819. #endif /* COMMENT */
  8820.         oldtyp = 0; oldrtt = -1L; oldtry = -1; oldlen = -1;
  8821.         oldtim = -1;
  8822.  
  8823.         ft_win = 0;                     /* Flag that window is closed. */
  8824.         cendw = 1; return;
  8825.  
  8826.       case SCR_CD:                      /* Display current directory */
  8827.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_DIR, (long) s );
  8828. #ifdef OS2
  8829.         SaveCmdMode(0, 0);
  8830. #endif /* OS2 */
  8831.         return;
  8832.  
  8833.       default:                          /* Bad call */
  8834.         KuiSetProperty(KUI_FILE_TRANSFER,
  8835.                        (long) CW_ERR,
  8836.                        (long) "*** screen() called with bad function code ***"
  8837.                        );
  8838.         return;
  8839.     }
  8840. }
  8841. #endif /* KUI */
  8842. #endif /* MAC */
  8843.  
  8844. #endif /* NOXFER */
  8845.  
  8846. #ifndef CK_CURPOS
  8847. /* Dummies for when cursor control is not supported */
  8848. int
  8849. ck_curpos(row, col) {
  8850.     return(-1);
  8851. }
  8852.  
  8853. int
  8854. ck_cls() {
  8855.     return(-1);
  8856. }
  8857.  
  8858. int
  8859. ck_cleol() {
  8860.     return(-1);
  8861. }
  8862. #endif /* CK_CURPOS */
  8863.  
  8864. #ifndef NOIKSD
  8865. #ifdef IKSDB
  8866.  
  8867. struct iksdbfld dbfld[] = {
  8868.    /* Offset    Length    Type   */
  8869.     { DB_FLAGS, dB_FLAGS, DBT_HEX },    /*  0 db_FLAGS Flags */
  8870.     { DB_ATYPE, dB_ATYPE, DBT_HEX },    /*  1 db_ATYPE Auth type */
  8871.     { DB_AMODE, dB_AMODE, DBT_HEX },    /*  3 db_AMODE Auth mode */
  8872.     { DB_STATE, dB_STATE, DBT_HEX },    /*  2 db_STATE State */
  8873.     { DB_MYPID, dB_MYPID, DBT_HEX },    /*  5 db_MYPID PID */
  8874.     { DB_SADDR, dB_SADDR, DBT_HEX },    /*  4 db_SADDR Server address */
  8875.     { DB_CADDR, dB_CADDR, DBT_HEX },    /*  6 db_CADDR Client address */
  8876.     { DB_START, dB_START, DBT_DAT },    /*  7 db_START Session start */
  8877.     { DB_LASTU, dB_LASTU, DBT_DAT },    /*  8 db_LASTU Last update */
  8878.     { DB_ULEN,  dB_ULEN,  DBT_HEX },    /*  9 db_ULEN  Username length */
  8879.     { DB_DLEN,  dB_DLEN,  DBT_HEX },    /* 10 db_DLEN  Directory name length */
  8880.     { DB_ILEN,  dB_ILEN,  DBT_HEX },    /* 11 db_ILEN  Info length */
  8881.     { DB_PAD1,  dB_PAD1,  DBT_UND },    /* 12 db_PAD1  (Reserved) */
  8882.     { DB_USER,  dB_USER,  DBT_STR },    /* 13 db_USER  Username */
  8883.     { DB_DIR,   dB_DIR,   DBT_STR },    /* 14 db_DIR   Current Directory */
  8884.     { DB_INFO,  dB_INFO,  DBT_STR }     /* 15 db_INFO  State-specific info */
  8885. };
  8886.  
  8887. static char lcknam[CKMAXPATH+1];        /* Lockfile pathname */
  8888. static char tmplck[CKMAXPATH+1];        /* Temporary lockfile name */
  8889.  
  8890. static char * updmode =                 /* Update mode for fopen() */
  8891. #ifdef OS2
  8892.   "r+b"
  8893. #else
  8894. #ifdef VMS
  8895.   "r+b"
  8896. #else
  8897.   "r+"
  8898. #endif /* VMS */
  8899. #endif /* OS2 */
  8900.   ;
  8901.  
  8902. /*  D B I N I T  --  Initialize the IKSD database...  */
  8903.  
  8904. int
  8905. dbinit() {
  8906.     extern int dbinited;
  8907.     int x = 0;
  8908.     debug(F110,"dbinit dbdir 1",dbdir,0);
  8909.     debug(F110,"dbinit dbfile 1",dbfile,0);
  8910.     if (dbinited)
  8911.       return(0);
  8912. #ifdef OS2
  8913.     if (!dbdir) {
  8914. #ifdef NT
  8915.         char * p = NULL;
  8916.         if (!isWin95()) {
  8917.             p = getenv("SystemRoot");
  8918.         } else {
  8919.             p = getenv("winbootdir");
  8920.             if (!p)  p = getenv("windir");
  8921.         }
  8922.         if (!p) p = "C:/";
  8923.         dbdir = malloc(strlen(p)+2);
  8924.         strcpy(dbdir,p);        /* safe */
  8925.         p = dbdir;
  8926.         while (*p) {
  8927.             if (*p == '\\')
  8928.               *p = '/';
  8929.             p++;
  8930.         }
  8931.         if (*(p-1) != '/' ) {
  8932.             *p++ = '/';
  8933.             *p = '\0';
  8934.         }
  8935. #else /* NT */
  8936.         makestr(&dbdir,"C:/");
  8937. #endif /* NT */
  8938.     }
  8939. #else /* OS2 */
  8940.     if (!dbdir)
  8941.       makestr(&dbdir,IK_DBASEDIR);
  8942. #endif /* OS2 */
  8943.  
  8944.     if (!dbfile) {
  8945.         char * s = "";
  8946.         x = strlen(dbdir);
  8947.         if (dbdir[x-1] != '/') {
  8948.             s = "/";
  8949.             x++;
  8950.         }
  8951.         x += (int)strlen(IK_DBASEFIL);
  8952.         dbfile = (char *)malloc(x+1);
  8953.         sprintf(dbfile,"%s%s%s",dbdir,s,IK_DBASEFIL);
  8954.     }
  8955.     debug(F110,"dbinit dbdir 2",dbdir,0);
  8956.     debug(F110,"dbinit dbfile 2",dbfile,0);
  8957.     mypid = getpid();                   /* Get my pid */
  8958.     debug(F101,"dbinit mypid","",mypid);
  8959.  
  8960.     if (!myhexip[0]) {                  /* Set my hex IP address */
  8961. #ifdef TCPSOCKET
  8962.         extern unsigned long myxipaddr;
  8963.         if (getlocalipaddr() > -1) {
  8964.             myip = myxipaddr;
  8965.             sprintf(myhexip,"%08lx",myip); /* (Needs fixing for IPv6) */
  8966.         } else
  8967. #endif /* TCPSOCKET */
  8968.           ckstrncpy(myhexip,"00000000",9);
  8969.     }
  8970.     debug(F111,"dbinit myip",myhexip,myip);
  8971.     if (!peerhexip[0]) {                /* Get peer's  hex IP address */
  8972. #ifdef TCPSOCKET
  8973.         extern unsigned long peerxipaddr;
  8974.         if (ckgetpeer()) {
  8975.             peerip = peerxipaddr;
  8976.             sprintf(peerhexip,"%08lx",peerip); /* (Needs fixing for IPv6) */
  8977.             debug(F111,"dbinit peerip",peerhexip,peerip);
  8978.         } else {
  8979.             debug(F101,"dbinit ckgetpeer failure","",errno);
  8980.             ckstrncpy(peerhexip,"00000000",9);
  8981.         }
  8982. #else
  8983.         ckstrncpy(peerhexip,"00000000",9);
  8984. #endif /* TCPSOCKET */
  8985.     }
  8986.     debug(F111,"dbinit peerip",peerhexip,peerip);
  8987.     debug(F101,"dbinit dbenabled","",dbenabled);
  8988.     if (dbenabled && inserver) {
  8989.         mydbslot = getslot();
  8990.         debug(F111,"dbinit getslot",ckitoa(ikdbopen),x);
  8991.         if (ikdbopen) dbinited = 1;
  8992.     }
  8993.     return(0);
  8994. }
  8995.  
  8996. /*  U P D S L O T  --  Update slot n  */
  8997.  
  8998. /*
  8999.   Opens the database if necessary, seeks to slot n, writes current record
  9000.   and adds current time to last-update field.  n is the record sequence number
  9001.   (0, 1, 2, ...), not the seek pointer.   Returns -1 on failure, 0 on success.
  9002. */
  9003. int
  9004. updslot(n) int n; {                     /* Update our slot */
  9005.     int rc = 0;
  9006.     CK_OFF_T position;
  9007.  
  9008.     debug(F111,"updslot","ikdbopen",ikdbopen);
  9009.     if (!ikdbopen)                      /* Not if not ok */
  9010.       return(0);
  9011.     if (!dbfp) {                        /* Open database if not open */
  9012.         dbfp = fopen(dbfile,updmode);   /* In update no-truncate mode */
  9013.         if (!dbfp) {
  9014.             debug(F110,"updslot fopen failed",dbfile,0);
  9015.             ikdbopen = 0;
  9016.             return(-1);
  9017.         }
  9018.     }
  9019.     /* debug(F111,"updslot dbfile",dbfile,dbfp); */
  9020.     position = n * DB_RECL;
  9021.     if (CKFSEEK(dbfp,position,0) < 0) {    /* Seek to desired slot */
  9022.         debug(F111,"updslot fseek failed",dbfile,mydbseek);
  9023.         ikdbopen = 0;
  9024.         rc = -1;
  9025.     } else {
  9026.         /* Update the update time */
  9027.         strncpy(&dbrec[dbfld[db_LASTU].off],
  9028.                 ckdate(),
  9029.                 dbfld[db_LASTU].len
  9030.                 );
  9031.         if (fwrite(dbrec,1,DB_RECL,dbfp) < DB_RECL) { /* Write the record */
  9032.             debug(F110,"updslot fwrite failed",dbfile,0);
  9033.             ikdbopen = 0;
  9034.             rc = -1;
  9035.         } else {                        /* Flush the write */
  9036.             fflush(dbfp);
  9037.         }
  9038.     }
  9039.     return(rc);
  9040. }
  9041.  
  9042. /*  I N I T S L O T --  Initialize slot n with my info  */
  9043.  
  9044. int
  9045. initslot(n) int n; {                    /* Initialize slot */
  9046.     int k;
  9047. #ifdef TCPSOCKET
  9048.     extern unsigned long peerxipaddr;
  9049. #endif /* TCPSOCKET */
  9050.  
  9051.     debug(F101,"initslot","",n);
  9052.  
  9053. #ifdef USE_MEMCPY
  9054.     memset(dbrec,32,DB_RECL);
  9055. #else
  9056.     for (k = 0; k < DB_RECL; k++)
  9057.       dbrec[k] = '\040';
  9058. #endif /* USE_MEMCPY */
  9059.  
  9060.     myflags = DBF_INUSE;                /* Set in-use flag */
  9061.     mystate = W_NOTHING;
  9062.     myatype = 0L;
  9063.     myamode = 0L;
  9064.  
  9065.     k = dbfld[db_FLAGS].len;            /* Length of flags field */
  9066.     strncpy(&dbrec[dbfld[db_FLAGS].off],ulongtohex(myflags,k),k);
  9067.  
  9068.     k = dbfld[db_ATYPE].len;
  9069.     strncpy(&dbrec[dbfld[db_ATYPE].off],ulongtohex(myatype,k),k);
  9070.  
  9071.     k = dbfld[db_AMODE].len;
  9072.     strncpy(&dbrec[dbfld[db_AMODE].off],ulongtohex(myamode,k),k);
  9073.  
  9074.     k = dbfld[db_STATE].len;
  9075.     strncpy(&dbrec[dbfld[db_STATE].off],ulongtohex(mystate,k),k);
  9076.  
  9077.     k = dbfld[db_SADDR].len;
  9078.     strncpy(&dbrec[dbfld[db_SADDR].off],ulongtohex(myip,k),k);
  9079.  
  9080. #ifdef TCPSOCKET
  9081.     ckgetpeer();
  9082.     k = dbfld[db_CADDR].len;
  9083.     strncpy(&dbrec[dbfld[db_CADDR].off],ulongtohex(peerxipaddr,k),k);
  9084. #else
  9085.     k = dbfld[db_CADDR].len;
  9086.     strncpy(&dbrec[dbfld[db_CADDR].off],ulongtohex(0L,k),k);
  9087. #endif /* TCPSOCKET */
  9088.  
  9089.     k = dbfld[db_MYPID].len;
  9090.     strncpy(&dbrec[dbfld[db_MYPID].off],ulongtohex(mypid,k),k);
  9091.  
  9092.     k = dbfld[db_START].len;
  9093.     strncpy(&dbrec[dbfld[db_START].off],ckdate(),k);
  9094.  
  9095.     k = dbfld[db_ULEN].len;
  9096.     strncpy(&dbrec[dbfld[db_ULEN].off],"0000",4);
  9097.  
  9098.     k = dbfld[db_DLEN].len;
  9099.     strncpy(&dbrec[dbfld[db_DLEN].off],"0000",4);
  9100.  
  9101.     k = dbfld[db_ILEN].len;
  9102.     strncpy(&dbrec[dbfld[db_ILEN].off],"0000",4);
  9103.  
  9104.     strncpy(&dbrec[dbfld[db_INFO].off],"INIT",4);
  9105.     return(updslot(n));
  9106. }
  9107.  
  9108. int
  9109. slotstate(x,s1,s2,s3) int x; char *s1, *s2, *s3; {
  9110.     int k, l1, l2, l3, z;
  9111.     mystate = x;
  9112.     debug(F101,"slotstate ikdbopen","",ikdbopen);
  9113.     if (!ikdbopen)
  9114.       return(-1);
  9115.     if (!s1) s1 = "";
  9116.     l1 = strlen(s1);
  9117.     if (!s2) s2 = "";
  9118.     l2 = strlen(s2);
  9119.     if (!s3) s3 = "";
  9120.     l3 = strlen(s3);
  9121.     strncpy(&dbrec[DB_STATE],ulongtohex(mystate,4),4);
  9122.     k = dbfld[db_ILEN].len;
  9123.     z = l1 + l2 + l3 + 2;
  9124.     if (z > dB_INFO)
  9125.       z = dB_INFO;
  9126.     strncpy(&dbrec[DB_ILEN],ulongtohex((unsigned long)z,k),k);
  9127.     k = dbfld[db_INFO].len;
  9128.     z = dbfld[db_INFO].off;
  9129.     if (l1 <= k) {
  9130.         lset(&dbrec[z],s1,l1+1,32);
  9131.         z += l1+1;
  9132.         k -= l1+1;
  9133.         if (l2 <= k) {
  9134.             lset(&dbrec[z],s2,l2+1,32);
  9135.             z += l2+1;
  9136.             k -= l2+1;
  9137.             if (l3 <= k)
  9138.               lset(&dbrec[z],s3,k,32);
  9139.         }
  9140.     }
  9141. #ifdef DEBUG
  9142.     if (deblog) {
  9143.         char buf[128];
  9144.         int i;
  9145.         strncpy(buf,&dbrec[DB_INFO],127);
  9146.         buf[127] = NUL;
  9147.         for (i = 126; i > 0 && buf[i] == 32; i--) buf[i] = 0;
  9148.         debug(F111,"slotstate",buf,mystate);
  9149.     }
  9150. #endif /* DEBUG */
  9151.     z = updslot(mydbslot);
  9152.     debug(F101,"slotstate updslot","",z);
  9153.     return(z);
  9154. }
  9155.  
  9156. int
  9157. slotdir(s1,s2) char * s1, * s2; {       /* Update current directory */
  9158.     int k, len1, len2;
  9159.     if (!ikdbopen)
  9160.       return(-1);
  9161.     if (!s1) s1 = "";
  9162.     if (!s2) s2 = "";
  9163.     len1 = strlen(s1);
  9164.     len2 = strlen(s2);
  9165.     k = dbfld[db_DLEN].len;
  9166.     strncpy(&dbrec[DB_DLEN],ulongtohex((unsigned long)(len1+len2),k),k);
  9167.     k = dbfld[db_DIR].len;
  9168.     if (len1 > 0) {
  9169.         lset(&dbrec[dbfld[db_DIR].off],s1,len1,32);
  9170.         lset(&dbrec[dbfld[db_DIR].off+len1],s2,k-len1,32);
  9171.     } else {
  9172.         lset(&dbrec[dbfld[db_DIR].off],s2,k,32);
  9173.     }
  9174.     return(updslot(mydbslot));
  9175. }
  9176.  
  9177. /*  F R E E S L O T  --  Free slot n  */
  9178.  
  9179. int
  9180. freeslot(n) int n; {
  9181.     int k;
  9182.     if (!ikdbopen)
  9183.       return(0);
  9184.     dbflags = 0L;
  9185.     if (n == mydbslot) {
  9186.         dbflags = myflags & ~DBF_INUSE;
  9187.         dbflags &= ~DBF_LOGGED;
  9188.     }
  9189.     k = dbfld[db_FLAGS].len;
  9190.     strncpy(&dbrec[dbfld[db_FLAGS].off],ulongtohex(dbflags,k),k);
  9191.     return(updslot(n));
  9192. }
  9193.  
  9194. /*  G E T S L O T  --  Find a free database slot; returns slot number  */
  9195.  
  9196. int
  9197. getslot() {                             /* Find a free slot for us */
  9198.     FILE * rfp = NULL;                  /* Returns slot number (0, 1, ...) */
  9199.     char idstring[64];                  /* PID string buffer (decimal) */
  9200.     char pidbuf[64], * s;
  9201.     int j, k, n, x, rc = -1;
  9202.     int lockfd, tries, haveslot = 0;
  9203.     long lockpid;
  9204.     CK_OFF_T i;
  9205.     /* char ipbuf[17]; */
  9206.  
  9207.     if (!myhexip[0])                    /* Set my hex IP address if not set */
  9208.       ckstrncpy((char *)myhexip,"7F000001",33);
  9209.     sprintf(idstring,"%08lx:%010ld\n",myip,mypid);
  9210.     debug(F110,"getslot idstring", idstring, 0);
  9211.  
  9212.     /* Make temporary lockfile name IP.PID (hex.hex) */
  9213.     /* This should fit in 14 chars -- huge PIDs are usually not possible */
  9214.     /* on 14-char filename systems. */
  9215.  
  9216.     sprintf(tmplck,"%s%08lx.%lx",dbdir,myip,mypid);
  9217.     debug(F110,"getslot tempfile",tmplck,0);
  9218.  
  9219.     /* Make a temporary file */
  9220.  
  9221.     lockfd = creat(tmplck, 0600);
  9222.     if (lockfd < 0) {
  9223.         debug(F111,"getslock temp lockfile create failure", tmplck, errno);
  9224.         return(-1);
  9225.     }
  9226.     /* Write my (decimal) PID into the temp file */
  9227.  
  9228.     write(lockfd,idstring,(int)strlen(idstring));
  9229.     if (close(lockfd) < 0) {            /* Close lockfile */
  9230.         debug(F101,"getslot error closing temp lockfile", "", errno);
  9231.         return(-1);
  9232.     }
  9233.     sprintf(lcknam,"%s%s",dbdir,IK_LOCKFILE); /* Build lockfile name */
  9234.     debug(F110,"getslot lockfile",lcknam,0);
  9235.  
  9236.     rfp = fopen(lcknam,"r");            /* See if lockfile exists */
  9237.     if (rfp) {                          /* If so... */
  9238.         rset(pidbuf,"",64,0);
  9239.         x = fread(pidbuf,1,63,rfp);     /* Read ID string from it */
  9240.         fclose(rfp);                    /* and close it quickly */
  9241.         debug(F110,"getslot lock exists",pidbuf,0);
  9242.         if (x > 0) {                    /* If we have a PID, check it */
  9243.             char * s = pidbuf;
  9244.             while (*s) {
  9245.                 if (islower(*s)) *s = toupper(*s);
  9246.                 if (*s == ':') {
  9247.                     *s = NUL;
  9248.                     debug(F110,"getslot lock IP",pidbuf,0);
  9249.                     debug(F110,"gteslot my   IP",myhexip,0);
  9250.                     if (!strcmp(pidbuf,myhexip)) { /* Same IP address? */
  9251.                         lockpid = atol(s+1); /* Yes, now get PID */
  9252.                         debug(F101,"getslot lockpid","",lockpid);
  9253.  
  9254.                         /* Check if PID lockpid on this computer is alive */
  9255.                         x = zchkpid(lockpid);
  9256.                         if (!x) {
  9257.                             debug(F100,"getslot PID stale,removing lock","",0);
  9258.                             unlink(lcknam);
  9259.                         }
  9260.                         break;
  9261.                     }
  9262.                 }
  9263.                 s++;
  9264.             }
  9265.         } else {
  9266.             debug(F111,"getslot lockfile open failure",lcknam,errno);
  9267.         }
  9268.     }
  9269.     /* Try IK_LCKTRIES (16) times to rename temp file to lockfile */
  9270.  
  9271.     for (tries = IK_LCKTRIES; tries > 0; tries--) {
  9272.         if (zrename(tmplck,lcknam) == 0)
  9273.           break;
  9274.         debug(F101,"getslot database locked by pid", "", dbpid);
  9275.         sleep(IK_LCKSLEEP);
  9276.     }
  9277.     if (tries < 1) {                    /* Couldn't */
  9278.         debug(F110,"getslot create lock failure",lcknam,0);
  9279.         return(-1);
  9280.     }
  9281.     /* Have lock, open database */
  9282.  
  9283.     debug(F110,"getslot has lock",lcknam,0); /* Have lock */
  9284.  
  9285.     if (!dbfile)
  9286.       return(-1);
  9287.  
  9288.     /* If database doesn't exist, create it. */
  9289.  
  9290.     debug(F110,"getslot dbfile",dbfile,0);
  9291.     if (zchki(dbfile) < 0) {
  9292.         debug(F110,"getslot creating new database",dbfile,0);
  9293.         x = creat(dbfile,0660);
  9294.         if (x < 0) {
  9295.             debug(F111,"getslot creat() failed", dbfile, errno);
  9296.             goto xslot;
  9297.         }
  9298.         close(x);
  9299.     }
  9300.     dbfp = fopen(dbfile,updmode);       /* Open it in update mode */
  9301.     if (!dbfp) {
  9302.         debug(F111,"getslot fopen failed",dbfile,errno);
  9303.         goto xslot;
  9304.     }
  9305.     /* Now find a free (or new) slot... */
  9306.  
  9307.     dblastused = 0L;                    /* Seek pointer to last record inuse */
  9308.     mydbseek = 0L;                      /* Seek pointer for my record */
  9309.  
  9310.     /* Quickly read the whole database; n = record counter, i = seek pointer */
  9311.  
  9312.     for (n = 0, i = 0; !feof(dbfp); i += DB_RECL, n++) {
  9313.         x = fread(dbrec,1,DB_RECL,dbfp); /* Read a record */
  9314.         if (x < 1)                      /* EOF not caught by feof() */
  9315.           break;
  9316. #ifndef NOFTRUNCATE
  9317.         if (x != DB_RECL) {             /* Watch out for trailing junk */
  9318.             debug(F101,"getslot bad size","",x);  /* (Shouldn't happen...) */
  9319. #ifdef COHERENT
  9320.             chsize(fileno(dbfp),i);
  9321. #else
  9322.             ftruncate(fileno(dbfp),(CK_OFF_T)i);
  9323. #endif /* COHERENT */
  9324.             x = 0;
  9325.             CKFSEEK(dbfp,i,0);
  9326.             break;
  9327.         }
  9328. #endif /* NOFTRUNCATE */
  9329.         debug(F101,"getslot record","",n);
  9330.         k = dbfld[db_FLAGS].off;
  9331.         j = dbfld[db_FLAGS].len;
  9332.         dbflags = hextoulong(&dbrec[k],j);
  9333.         debug(F001,"getslot dbflags","",dbflags);
  9334.         k = dbfld[db_MYPID].off;
  9335.         j = dbfld[db_MYPID].len;
  9336.         dbpid  = hextoulong(&dbrec[k],j);
  9337.         debug(F001,"getslot dbpid","",dbpid);
  9338.         k = dbfld[db_SADDR].off;
  9339.         j = dbfld[db_SADDR].len;
  9340.         dbip = hextoulong(&dbrec[k],j);
  9341.         debug(F001,"getslot dbip","",dbip);
  9342.  
  9343.         if (dbflags & DBF_INUSE) {      /* Remember last slot in use */
  9344.             x = 0;                      /* Make sure it's REALLY in use */
  9345.             if (dbpid == mypid && dbip == myip) { /* Check for PID == my PID */
  9346.                 x = 1;
  9347.                 debug(F101,"getslot record pid","",dbpid);
  9348.             } else {                    /* Or for stale PID */
  9349.                 x = zchkpid(dbpid);
  9350.                 debug(F101,"getslot zchkpid()","",x);
  9351.             }
  9352.             if (!x) {                   /* Bogus record */
  9353.                 x = freeslot(n);
  9354.                 debug(F101,"getslot stale record pid: freeslot()","",x);
  9355.                 if (x > -1 && !haveslot)
  9356.                   dbflags = 0;
  9357.             } else {                    /* It's really in use */
  9358.                 dblastused = i;
  9359.             }
  9360.         }
  9361.         if (!haveslot) {                /* If I don't have a slot yet */
  9362.             if (!(dbflags & DBF_INUSE)) {       /* Claim this one */
  9363.                 debug(F101,"getslot free slot", "", n);
  9364.                 haveslot = 1;
  9365.                 mydbseek = i;
  9366.                 mydbslot = n;           /* But keep going... */
  9367.             }
  9368.         }
  9369.     }
  9370.     /* Come here with i == seek pointer to first record after eof */
  9371.  
  9372.     if (!haveslot) {                    /* Found no free slot so add to end */
  9373.         debug(F101,"getslot new slot","",n);
  9374.         haveslot = 1;
  9375.         mydbseek = i;
  9376.         mydbslot = n;
  9377.     }
  9378.     ikdbopen = 1;                       /* OK to make database entries */
  9379.     debug(F101,"getslot records","",n);
  9380.     debug(F101,"getslot dblastused","",dblastused);
  9381.     debug(F101,"getslot i","",i);
  9382.  
  9383.     /* Trim stale records from end */
  9384.  
  9385. #ifndef NOFTRUNCATE
  9386.     if (i > dblastused+DB_RECL) {
  9387.         debug(F101,"getslot truncating at","",dblastused+DB_RECL);
  9388. #ifdef COHERENT
  9389.         x = chsize(fileno(dbfp),dblastused+DB_RECL);
  9390. #else
  9391.         x = ftruncate(fileno(dbfp),(CK_OFF_T)(dblastused+DB_RECL));
  9392. #endif /* COHERENT */
  9393.         if (x < 0)                      /* (Not fatal) */
  9394.           debug(F101,"getslot ftruncate failed", "", errno);
  9395.     }
  9396. #endif /* NOFTRUNCATE */
  9397.  
  9398.     /* Initialize my record */
  9399.  
  9400.     if (initslot(mydbslot) < 0) {
  9401.         debug(F101,"getslot initslot() error","",n);
  9402.         ikdbopen = 0;
  9403.         goto xslot;
  9404.     }
  9405.     debug(F101,"getslot OK","",mydbslot);
  9406.     rc = mydbslot;                      /* OK return code */
  9407.  
  9408.   xslot:                                /* Unlock the database and return */
  9409.     if (unlink(lcknam) < 0) {
  9410.         debug(F111,"getslot lockfile removal failed",lcknam,errno);
  9411.         rc = -1;
  9412.     }
  9413.     return(rc);
  9414. }
  9415. #endif /* IKSDB */
  9416. #endif /* NOIKSD */
  9417.