home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckv206.zip / ckuusx.c < prev    next >
C/C++ Source or Header  |  2002-10-31  |  281KB  |  9,277 lines

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