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