home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku209.zip / ckuusx.c < prev    next >
C/C++ Source or Header  |  2003-03-26  |  281KB  |  9,298 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, 2003,
  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, xsuspend, 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.     extern unsigned long startflags;
  2779. #ifndef NOSETKEY
  2780.     extern int os2gks;
  2781. #endif /* NOSETKEY */
  2782.     int i;
  2783. #endif /* OS2 */
  2784. #ifndef NOSPL
  2785.     extern int i_active, instatus;
  2786. #endif /* NOSPL */
  2787. #ifdef VMS
  2788.     int i; FILE *f;
  2789. #endif /* VMS */
  2790.     extern int zchkod, zchkid;
  2791. #ifndef NOSPL
  2792.     extern int unkmacro;
  2793. #endif /* NOSPL */
  2794.  
  2795.     debok = 1;
  2796. #ifdef NTSIG
  2797.     connoi();
  2798. #endif /* NTSIG */
  2799. #ifdef __EMX__
  2800.     signal(SIGINT, SIG_ACK);
  2801. #endif
  2802. #ifdef GEMDOS
  2803. /* GEM is not reentrant, no i/o from interrupt level */
  2804.     cklongjmp(cmjbuf,1);                /* Jump back to parser now! */
  2805. #endif /* GEMDOS */
  2806.  
  2807. #ifdef DEBUG
  2808.     if (deblog) {
  2809.     if (sig == SIGINT)
  2810.       debug(F101,"trap caught SIGINT","",sig);
  2811.     else
  2812.       debug(F101,"trap caught signal","",sig);
  2813.     }
  2814. #endif /* DEBUG */
  2815.  
  2816. #ifdef OS2
  2817.     if ( sig == SIGBREAK && (startflags & 128) ) {
  2818.         debug(F101,"trap ignoring SIGBREAK","",sig);
  2819.         return;
  2820.     }
  2821. #endif /* OS2 */
  2822.  
  2823. #ifndef NOICP
  2824.     timelimit = 0;                      /* In case timed ASK interrupted */
  2825. #ifndef NOSPL
  2826.     unkmacro = 0;            /* Or ON_UNKNOWN_MACRO interrupted.. */
  2827. #endif /* NOSPL */
  2828. #endif /* NOICP */
  2829.     zchkod = 0;                         /* Or file expansion interrupted... */
  2830.     zchkid = 0;
  2831.     interrupted = 1;
  2832.  
  2833.     if (what & W_CONNECT) {        /* Are we in CONNECT mode? */
  2834. /*
  2835.   The HP workstation Reset key sends some kind of ueber-SIGINT that can not
  2836.   be SIG_IGNored, so we wind up here somehow (even though this is *not* the
  2837.   current SIGINT handler).  Just return.
  2838. */
  2839.         debug(F101,"trap: SIGINT caught during CONNECT","",sig);
  2840.         SIGRETURN;
  2841.     }
  2842. #ifndef NOSPL
  2843.     if (i_active) {                     /* INPUT command was active? */
  2844.         i_active = 0;                   /* Not any more... */
  2845.         instatus = INP_UI;              /* INPUT status = User Interrupted */
  2846.     }
  2847. #endif /* NOSPL */
  2848.  
  2849. #ifndef NOXFER
  2850.     ftreset();                          /* Restore global protocol settings */
  2851.     binary = b_save;                    /* Then restore these */
  2852.     fncnv  = f_save;
  2853.     bye_active = 0;
  2854.     diractive = 0;
  2855.     cdactive = 0;
  2856. #endif /* NOXFER */
  2857.     zclose(ZIFILE);                     /* If we were transferring a file, */
  2858.     zclose(ZOFILE);                     /* close it. */
  2859. #ifndef NOICP
  2860.     cmdsquo(cmd_quoting);               /* If command quoting was turned off */
  2861. #ifdef CKLEARN
  2862.     {
  2863.     extern FILE * learnfp;
  2864.     extern int learning;
  2865.     if (learnfp) {
  2866.         fclose(learnfp);
  2867.         learnfp = NULL;
  2868.         learning = 0;
  2869.     }
  2870.     }
  2871. #endif /* CKLEARN */
  2872. #endif /* NOICP */
  2873. #ifdef CK_APC
  2874.     delmac("_apc_commands",1);
  2875.     apcactive = APC_INACTIVE;
  2876. #endif /* CK_APC */
  2877.  
  2878. #ifdef VMS
  2879. /*
  2880.   Fix terminal.
  2881. */
  2882.     if (ft_win) {                       /* If curses window open */
  2883.         debug(F100,"^C trap() curses","",0);
  2884.         xxscreen(SCR_CW,0,0L,"");       /* Close it */
  2885.         conres();                       /* Restore terminal */
  2886.         i = printf("^C...");            /* Echo ^C to standard output */
  2887.     } else {
  2888.         conres();
  2889.         i = printf("^C...\n");          /* Echo ^C to standard output */
  2890.     }
  2891.     if (i < 1 && ferror(stdout)) {      /* If there was an error */
  2892.         debug(F100,"^C trap() error","",0);
  2893.         fclose(stdout);                 /* close standard output */
  2894.         f = fopen(dftty, "w");          /* open the controlling terminal */
  2895.         if (f) stdout = f;              /* and make it standard output */
  2896.         printf("^C...\n");              /* and echo the ^C again. */
  2897.     }
  2898. #else                                   /* Not VMS */
  2899. #ifdef STRATUS
  2900.     conres();                           /* Set console back to normal mode */
  2901. #endif /* STRATUS */
  2902. #ifndef NOXFER
  2903.     if (ft_win) {                       /* If curses window open, */
  2904.         debug(F100,"^C trap() curses","",0);
  2905.         xxscreen(SCR_CW,0,0L,"");    /* close it. */
  2906.         printf("^C...");                /* Echo ^C to standard output */
  2907.     } else {
  2908. #endif /* NOXFER */
  2909.         printf("^C...\n");
  2910. #ifndef NOXFER
  2911.     }
  2912. #endif /* NOXFER */
  2913. #endif /* VMS */
  2914. #ifdef datageneral
  2915.     connoi_mt();                        /* Kill asynch task that listens to */
  2916.     ttimoff();
  2917.     conres();                           /* the keyboard */
  2918. #endif /* datageneral */
  2919.  
  2920. #ifndef NOCCTRAP
  2921. /*  This is stupid -- every version should have ttimoff()...  */
  2922. #ifdef UNIX
  2923.     ttimoff();                          /* Turn off any timer interrupts */
  2924. #else
  2925. #ifdef OSK
  2926.     ttimoff();                          /* Turn off any timer interrupts */
  2927. #else
  2928. #ifdef STRATUS
  2929.     ttimoff();                          /* Turn off any timer interrupts */
  2930. #else
  2931. #ifdef OS2
  2932. #ifndef NOSETKEY
  2933.     os2gks = 1;                         /* Turn back on keycode mapping  */
  2934. #endif /* NOSETKEY */
  2935. #ifndef NOLOCAL
  2936.     for (i = 0; i < VNUM; i++)
  2937.       VscrnResetPopup(i);
  2938. #endif /* NOLOCAL */
  2939. #ifdef TCPSOCKET
  2940. #ifdef NT
  2941.     /* WSAIsBlocking() returns FALSE in Win95 during a blocking accept call */
  2942.     if ( WSASafeToCancel /* && WSAIsBlocking() */ ) {
  2943.         WSACancelBlockingCall();
  2944.     }
  2945. #endif /* NT */
  2946. #endif /* TCPSOCKET */
  2947. #ifdef CK_NETBIOS
  2948.     NCBCancelOutstanding();
  2949. #endif /* CK_NETBIOS */
  2950.     ttimoff();                          /* Turn off any timer interrupts */
  2951. #else
  2952. #ifdef VMS
  2953.     ttimoff();                          /* Turn off any timer interrupts */
  2954. #endif /* VMS */
  2955. #endif /* OS2 */
  2956. #endif /* STRATUS */
  2957. #endif /* OSK */
  2958. #endif /* UNIX */
  2959.  
  2960. #ifdef OSK
  2961.     sigmask(-1);
  2962. /*
  2963.   We are in an intercept routine but do not perform a F$RTE (done implicitly
  2964.   by rts).  We have to decrement the sigmask as F$RTE does.  Warning: longjump
  2965.   only restores the cpu registers, NOT the fpu registers.  So don't use fpu at
  2966.   all or at least don't use common fpu (double or float) register variables.
  2967. */
  2968. #endif /* OSK */
  2969.  
  2970. #ifdef NTSIG
  2971.     PostCtrlCSem();
  2972. #else /* NTSIG */
  2973.     debug(F100,"trap about to longjmp","",0);
  2974. #ifdef NT
  2975.     cklongjmp(ckjaddr(cmjbuf),1);
  2976. #else /* NT */
  2977.     cklongjmp(cmjbuf,1);
  2978. #endif /* NT */
  2979. #endif /* NTSIG */
  2980. #else /* NOCCTRAP */
  2981. /* No Ctrl-C trap, just exit. */
  2982. #ifdef CK_CURSES                        /* Curses support? */
  2983.     xxscreen(SCR_CW,0,0L,"");           /* Close curses window */
  2984. #endif /* CK_CURSES */
  2985.     doexit(BAD_EXIT,what);              /* Exit poorly */
  2986. #endif /* NOCCTRAP */
  2987.     SIGRETURN;
  2988. }
  2989.  
  2990.  
  2991. /*  C K _ T I M E  -- Returns pointer to current time. */
  2992.  
  2993. char *
  2994. ck_time() {
  2995.     static char tbuf[10];
  2996.     char *p;
  2997.     int x;
  2998.  
  2999.     ztime(&p);                          /* "Thu Feb  8 12:00:00 1990" */
  3000.     if (!p)                             /* like asctime()! */
  3001.       return("");
  3002.     if (*p) {
  3003.         for (x = 11; x < 19; x++)       /* copy hh:mm:ss */
  3004.           tbuf[x - 11] = p[x];          /* to tbuf */
  3005.         tbuf[8] = NUL;                  /* terminate */
  3006.     }
  3007.     return(tbuf);                       /* and return it */
  3008. }
  3009.  
  3010. /*  C C _ C L E A N  --  Cleanup after terminal interrupt handler */
  3011.  
  3012. #ifdef GEMDOS
  3013. int
  3014. cc_clean() {
  3015.     zclose(ZIFILE);                     /* If we were transferring a file, */
  3016.     zclose(ZOFILE);                     /* close it. */
  3017.     printf("^C...\n");                  /* Not VMS, no problem... */
  3018. }
  3019. #endif /* GEMDOS */
  3020.  
  3021.  
  3022. /*  S T P T R A P -- Handle SIGTSTP (suspend) signals */
  3023.  
  3024. SIGTYP
  3025. #ifdef CK_ANSIC
  3026. stptrap(int sig)
  3027. #else
  3028. stptrap(sig) int sig;
  3029. #endif /* CK_ANSIC */
  3030. /* stptrap */ {
  3031.  
  3032. #ifndef NOJC
  3033.     int x; extern int cmflgs;
  3034.     debug(F101,"stptrap() caught signal","",sig);
  3035.     if (!xsuspend) {
  3036.         printf("\r\nsuspend disabled\r\n");
  3037. #ifndef NOICP
  3038.         if (what & W_COMMAND) {        /* If we were parsing commands */
  3039.             prompt(xxstring);           /* reissue the prompt and partial */
  3040.             if (!cmflgs)                /* command (if any) */
  3041.               printf("%s",cmdbuf);
  3042.         }
  3043. #endif /* NOICP */
  3044.     } else {
  3045.         conres();                       /* Reset the console */
  3046. #ifndef OS2
  3047.         /* Flush pending output first, in case we are continued */
  3048.         /* in the background, which could make us block */
  3049.         fflush(stdout);
  3050.  
  3051.         x = psuspend(xsuspend);        /* Try to suspend. */
  3052.         if (x < 0)
  3053. #endif /* OS2 */
  3054.           printf("Job control not supported\r\n");
  3055.         conint(trap,stptrap);           /* Rearm the trap. */
  3056.         debug(F100,"stptrap back from suspend","",0);
  3057.         switch (what) {
  3058.           case W_CONNECT:               /* If suspended during CONNECT? */
  3059.             conbin((char)escape);       /* put console back in binary mode */
  3060.             debug(F100,"stptrap W_CONNECT","",0);
  3061.             break;
  3062. #ifndef NOICP
  3063.           case W_COMMAND:               /* Suspended in command mode */
  3064.             debug(F101,"stptrap W_COMMAND pflag","",pflag);
  3065.             concb((char)escape);        /* Put back CBREAK tty mode */
  3066.             if (pflag) {                /* If command parsing was */
  3067.                 prompt(xxstring);       /* reissue the prompt and partial */
  3068.                 if (!cmflgs)            /* command (if any) */
  3069.                   printf("%s",cmdbuf);
  3070.             }
  3071.             break;
  3072. #endif /* NOICP */
  3073.           default:                      /* All other cases... */
  3074.             debug(F100,"stptrap default","",0);
  3075.             concb((char)escape);        /* Put it back in CBREAK mode */
  3076.             break;
  3077.         }
  3078.     }
  3079. #endif /* NOJC */
  3080.     SIGRETURN;
  3081. }
  3082.  
  3083. #ifdef TLOG
  3084. #define TBUFL 300
  3085.  
  3086. /*  T L O G  --  Log a record in the transaction file  */
  3087. /*
  3088.  Call with a format and 3 arguments: two strings and a number:
  3089.    f     - Format, a bit string in range 0-7, bit x is on, arg #x is printed.
  3090.    s1,s2 - String arguments 0 and 1.
  3091.    n     - Long, argument 2.
  3092. */
  3093. VOID
  3094. #ifdef CK_ANSIC
  3095. dotlog(int f, char *s1, char *s2, long n)
  3096. #else
  3097. dotlog(f,s1,s2,n) int f; long n; char *s1, *s2;
  3098. #endif /* CK_ANSIC */
  3099. /* dotlog */ {
  3100.     static char s[TBUFL];
  3101.     extern int tlogfmt;
  3102.     char *sp = s; int x;
  3103.     if (!s1) s1 = "";
  3104.     if (!s2) s2 = "";
  3105.  
  3106.     if (!tralog) return;                /* If no transaction log, don't */
  3107.     if (tlogfmt != 1) return;
  3108.     switch (f) {
  3109.       case F000:                        /* 0 (special) "s1 n s2"  */
  3110.         if ((int)strlen(s1) + (int)strlen(s2) + 15 > TBUFL)
  3111.           sprintf(sp,"?T-Log string too long");
  3112.         else
  3113.       sprintf(sp,"%s %ld %s",s1,n,s2);
  3114.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3115.         break;
  3116.       case F001:                        /* 1, " n" */
  3117.         sprintf(sp," %ld",n);
  3118.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3119.         break;
  3120.       case F010:                        /* 2, "[s2]" */
  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]",s2);
  3126.         if (zsoutl(ZTFILE,"") < 0) tralog = 0;
  3127.         break;
  3128.       case F011:                        /* 3, "[s2] n" */
  3129.         x = (int)strlen(s2);
  3130.         if (s2[x] == '\n') s2[x] = '\0';
  3131.         if (x + 6 > TBUFL)
  3132.           sprintf(sp,"?String too long");
  3133.         else sprintf(sp,"[%s] %ld",s2,n);
  3134.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3135.         break;
  3136.       case F100:                        /* 4, "s1" */
  3137.         if (zsoutl(ZTFILE,s1) < 0) tralog = 0;
  3138.         break;
  3139.       case F101:                        /* 5, "s1: n" */
  3140.         if ((int)strlen(s1) + 15 > TBUFL)
  3141.           sprintf(sp,"?String too long");
  3142.         else sprintf(sp,"%s: %ld",s1,n);
  3143.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3144.         break;
  3145.       case F110:                        /* 6, "s1 s2" */
  3146.         x = (int)strlen(s2);
  3147.         if (s2[x] == '\n') s2[x] = '\0';
  3148.         if ((int)strlen(s1) + x + 4 > TBUFL)
  3149.           sprintf(sp,"?String too long");
  3150.         else
  3151.       sprintf(sp,"%s%s%s",s1,((*s2 == ':') ? "" : " "),s2);
  3152.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3153.         break;
  3154.       case F111:                        /* 7, "s1 s2: n" */
  3155.         x = (int)strlen(s2);
  3156.         if (s2[x] == '\n') s2[x] = '\0';
  3157.         if ((int)strlen(s1) + x + 15 > TBUFL)
  3158.           sprintf(sp,"?String too long");
  3159.         else
  3160.       sprintf(sp,"%s%s%s: %ld",s1,((*s2 == ':') ? "" : " "),s2,n);
  3161.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3162.         break;
  3163.       default:
  3164.         sprintf(sp,"?Invalid format for tlog() - %ld",n);
  3165.         if (zsoutl(ZTFILE,s) < 0) tralog = 0;
  3166.     }
  3167. }
  3168.  
  3169. /*
  3170.   D O X L O G
  3171.  
  3172.   This is the transaction-log writer for BRIEF format.
  3173.   The idea is produce one record (line) per file.  Each record
  3174.   has the following delimited fields:
  3175.     Date (yyyymmdd)
  3176.     Time (hh:mm:ss)
  3177.     Action: SEND or RECV
  3178.     File name
  3179.     File size
  3180.     Transfer mode (text, binary, image, labeled, etc).
  3181.     Status: OK or FAILED
  3182.     Free-form comments in doublequotes
  3183.   The default separator is comma.
  3184.   If a field contains the separator, it is enclosed in doublequotes.
  3185. */
  3186. VOID
  3187. #ifdef CK_ANSIC
  3188. doxlog(int x, char * fn, long fs, int fm, int status, char * msg)
  3189. #else
  3190. doxlog(x, fn, fs, fm, status, msg)
  3191.     int x; char * fn; long fs; int fm; int status; char * msg;
  3192. #endif /* CK_ANSIC */
  3193. /* doxlog */ {
  3194.     extern int tlogsep;
  3195.     char sep[2];
  3196.     char buf[CKMAXPATH+256], * bufp;
  3197.     char tmpbuf[32];
  3198.     char * s, * p;
  3199.     int len, left, ftp = 0, k;
  3200.  
  3201.     if (!tralog) return;                /* If no transaction log, don't */
  3202.  
  3203.     if (!fn) fn = "";                   /* Protect against null pointers */
  3204.     if (!msg) msg = "";
  3205.     if (x & W_FTP)
  3206.       ftp++;
  3207.  
  3208.     sep[0] = (char) tlogsep;
  3209.     sep[1] = NUL;
  3210.     if (!sep[0]) sep[0] = ',';
  3211.  
  3212.     bufp = buf;
  3213.     left = sizeof(buf);
  3214.     debug(F101,"XXX doxlog left 1","",left);
  3215.  
  3216.     p = zzndate();                      /* Date */
  3217.     ckmakmsg(buf, left, p ? p : "00000000", sep, NULL, NULL);
  3218.     bufp += 9;
  3219.     left -= 9;
  3220.     debug(F111,"XXX doxlog left 2",buf,left);
  3221.  
  3222.     ztime(&p);
  3223.     ckstrncpy(bufp,p+11,left);
  3224.     bufp += 8;
  3225.     left -= 8;
  3226.     debug(F111,"XXX doxlog left 3",buf,left);
  3227.  
  3228.     if (ftp) {
  3229.     if (!(x & (W_SEND|W_RECV)))
  3230.       return;
  3231.     s =  (x & W_SEND) ? "PUT" : "GET";
  3232.     k = 3;
  3233.     } else {
  3234.     s =  (x & W_SEND) ? "SEND" : "RECV";
  3235.     k = 4;
  3236.     }
  3237.     ckmakmsg(bufp,left,sep,s,sep,NULL);
  3238.     bufp += k + 2;
  3239.     left -= (k + 2);
  3240.     debug(F111,"XXX doxlog left 4",buf,left);
  3241.  
  3242.     s = "";
  3243.     if (ckstrchr(fn,sep[0]))        /* Filename */
  3244.       s = "\"";
  3245.     ckmakmsg(bufp,left,s,fn,s,sep);
  3246.     sprintf(tmpbuf,"%ld",fs);           /* Size */
  3247.     ckstrncat(buf,tmpbuf,CKMAXPATH);
  3248.     ckstrncat(buf,sep,CKMAXPATH);
  3249.     debug(F110,"doxlog 4",buf,0);
  3250.  
  3251. #ifdef NOICP
  3252.     /* Transfer mode */
  3253.     ckstrncpy(tmpbuf, (binary ? "binary" : "text"), TMPBUFSIZ);
  3254. #else
  3255.     ckstrncpy(tmpbuf,gfmode(fm,0),TMPBUFSIZ);
  3256. #endif /* NOICP */
  3257.     if (ckstrchr(tmpbuf,sep[0])) {      /* Might contain spaces */
  3258.         ckstrncat(buf,"\"",CKMAXPATH);
  3259.         ckstrncat(buf,tmpbuf,CKMAXPATH);
  3260.         ckstrncat(buf,"\"",CKMAXPATH);
  3261.     } else
  3262.       ckstrncat(buf,tmpbuf,CKMAXPATH);
  3263.     ckstrncat(buf,sep,CKMAXPATH);
  3264.     debug(F110,"doxlog 5",buf,0);
  3265.  
  3266.     ckstrncat(buf, status ? "FAILED" : "OK",CKMAXPATH);
  3267.     len = strlen(buf);
  3268.     left = CKMAXPATH+256 - len;
  3269.     if (left < 2) fatal("doxlog buffer overlow");
  3270.  
  3271.     debug(F111,"XXX doxlog left 5",buf,left);
  3272.  
  3273.     debug(F110,"doxlog buf 1", buf, len);
  3274.     s = buf + len;
  3275.     if (status == 0 && left > 32) {
  3276.         long cps;
  3277.  
  3278. #ifdef GFTIMER
  3279.     debug(F101,"DOXLOG fpxfsecs","",(long)(fpxfsecs * 1000));
  3280.  
  3281.         cps = (long)((CKFLOAT) fs / fpxfsecs);
  3282.         sprintf(s,"%s\"%0.3fsec %ldcps\"",sep,fpxfsecs,cps);
  3283. #else
  3284.         cps = fs / xfsecs;
  3285.         sprintf(s,"%s\"%ldsec %ldcps\"",sep,xfsecs,cps);
  3286. #endif /* GFTIMER */
  3287.     } else if ((int)strlen(msg) + 4 < left) {
  3288.         sprintf(s,"%s\"%s\"",sep,msg);
  3289.     }
  3290.     debug(F111,"XXX doxlog left 5",buf,left);
  3291.  
  3292.     debug(F110,"doxlog 5",buf,0);
  3293.     x = zsoutl(ZTFILE,buf);
  3294.     debug(F101,"doxlog zsoutl","",x);
  3295.     if (x < 0) tralog = 0;
  3296. }
  3297. #endif /* TLOG */
  3298.  
  3299. #ifndef MAC
  3300. /*
  3301.   The rest of this file is for all implementations but the Macintosh.
  3302. */
  3303.  
  3304. #ifdef CK_CURSES
  3305. static int repaint = 0;                 /* Transfer display needs repainting */
  3306. #endif /* CK_CURSES */
  3307.  
  3308. #ifndef NOXFER
  3309. /*  C H K I N T  --  Check for console interrupts  */
  3310.  
  3311. /*
  3312.   Used during file transfer in local mode only:
  3313.   . If user has not touched the keyboard, returns 0 with no side effects.
  3314.   . If user typed S or A (etc, see below) prints status message and returns 0.
  3315.   . If user typed X or F (etc, see below) returns 0 with cxseen set to 1.
  3316.   . If user typed Z or B (etc, see below) returns 0 with czseen set to 1.
  3317.   . If user typed E or C (etc, see below) returns -1.
  3318. */
  3319. int
  3320. chkint() {
  3321.     int ch, cn, ofd; long zz;
  3322.     if (!xfrint)
  3323.       return(0);
  3324.     if ((!local) || (quiet)) return(0); /* Only do this if local & not quiet */
  3325. #ifdef datageneral
  3326.     if (con_reads_mt)                   /* if conint_mt task is active */
  3327.       if (conint_avl) {                 /* and there's an interrupt pending */
  3328.           cn = 1;                       /* process it */
  3329.           ch = conint_ch;
  3330.           conint_avl = 0;               /* turn off flag so conint_mt can */
  3331.       } else                            /* proceed */
  3332.         return(0);
  3333.     else                                /* if conint_mt not active */
  3334.       if ((ch = coninc(2)) < 0)         /* try to get char manually */
  3335.         return(0);                      /* I/O error, or no data */
  3336.       else                              /* if successful, set cn so we */
  3337.         cn = 1;                         /* know we got one */
  3338.     debug(F101,"chkint got keyboard character",ch,cn);
  3339. #else /* !datageneral */
  3340. #ifdef NTSIG
  3341.     {
  3342.         extern int TlsIndex;
  3343.         struct _threadinfo * threadinfo;
  3344.         threadinfo = (struct _threadinfo *) TlsGetValue(TlsIndex);
  3345.         if (threadinfo) {
  3346.             if (!WaitSem(threadinfo->DieSem,0))
  3347.               return -1;                /* Cancel Immediately */
  3348.         }
  3349.     }
  3350. #endif /* NTSIG */
  3351.     cn = conchk();                      /* Any input waiting? */
  3352.     debug(F101,"conchk","",cn);
  3353.     if (cn < 1) return(0);
  3354.     ch = coninc(5) ;
  3355.     debug(F101,"coninc","",ch);
  3356.     if (ch < 0) return(0);
  3357. #endif /* datageneral */
  3358.  
  3359.     ch &= 0177;
  3360.     switch (ch) {
  3361.       case 'A': case 'a': case 0001:    /* Status report */
  3362.       case 'S': case 's':
  3363.         if (fdispla != XYFD_R && fdispla != XYFD_S && fdispla != XYFD_N)
  3364.           return(0);                    /* Only for serial, simple or none */
  3365.         ofd = fdispla;                  /* [MF] Save file display type */
  3366.         if (fdispla == XYFD_N)
  3367.           fdispla = XYFD_R;             /* [MF] Pretend serial if no display */
  3368.         xxscreen(SCR_TN,0,0l,"Status report:");
  3369.         xxscreen(SCR_TN,0,0l," file type: ");
  3370.         if (binary) {
  3371.             switch(binary) {
  3372.               case XYFT_L: xxscreen(SCR_TZ,0,0l,"labeled"); break;
  3373.               case XYFT_I: xxscreen(SCR_TZ,0,0l,"image"); break;
  3374.               case XYFT_U: xxscreen(SCR_TZ,0,0l,"binary undefined"); break;
  3375.               default:
  3376.               case XYFT_B: xxscreen(SCR_TZ,0,0l,"binary"); break;
  3377.             }
  3378.         } else {
  3379. #ifdef NOCSETS
  3380.             xxscreen(SCR_TZ,0,0l,"text");
  3381. #else
  3382.             xxscreen(SCR_TU,0,0l,"text, ");
  3383.             if (tcharset == TC_TRANSP || xfrxla == 0) {
  3384.                 xxscreen(SCR_TZ,0,0l,"transparent");
  3385.             } else {
  3386.                 if (what & W_SEND) {
  3387.                     xxscreen(SCR_TZ,0,0l,tcsinfo[tcharset].keyword);
  3388.                     xxscreen(SCR_TU,0,0l," => ");
  3389.                     xxscreen(SCR_TZ,0,0l,fcsinfo[fcharset].keyword);
  3390.                 } else {
  3391.                     xxscreen(SCR_TZ,0,0l,fcsinfo[fcharset].keyword);
  3392.                     xxscreen(SCR_TU,0,0l," => ");
  3393.                     xxscreen(SCR_TZ,0,0l,tcsinfo[tcharset].keyword);
  3394.                 }
  3395.             }
  3396. #endif /* NOCSETS */
  3397.         }
  3398.         xxscreen(SCR_QE,0,filcnt," file number");
  3399.         if (fsize) xxscreen(SCR_QE,0,fsize," size");
  3400.         xxscreen(SCR_QE,0,ffc," characters so far");
  3401.         if (fsize > 0L) {
  3402. #ifdef CK_RESEND
  3403.             zz = what & W_SEND ? sendstart : what & W_RECV ? rs_len : 0;
  3404.             zz = ( (ffc + zz) * 100L ) / fsize;
  3405. #else
  3406.             zz = ( ffc * 100L ) / fsize;
  3407. #endif /* CK_RESEND */
  3408.             xxscreen(SCR_QE,0,zz,      " percent done");
  3409.         }
  3410.         if (bctu == 4) {                /* Block check */
  3411.             xxscreen(SCR_TU,0,0L," block check: ");
  3412.             xxscreen(SCR_TZ,0,0L,"blank-free-2");
  3413.         } else xxscreen(SCR_QE,0,(long)bctu,  " block check");
  3414.         xxscreen(SCR_QE,0,(long)rptflg," compression");
  3415.         xxscreen(SCR_QE,0,(long)ebqflg," 8th-bit prefixing");
  3416.         xxscreen(SCR_QE,0,(long)lscapu," locking shifts");
  3417.         if (!network)
  3418.           xxscreen(SCR_QE,0, speed, " speed");
  3419.         if (what & W_SEND)
  3420.  
  3421.           xxscreen(SCR_QE,0,(long)spsiz, " packet length");
  3422.         else if (what & W_RECV || what & W_REMO)
  3423.           xxscreen(SCR_QE,0,(long)urpsiz," packet length");
  3424.         xxscreen(SCR_QE,0,(long)wslots,  " window slots");
  3425.         fdispla = ofd; /* [MF] Restore file display type */
  3426.         return(0);
  3427.  
  3428.       case 'B': case 'b': case 0002:    /* Cancel batch */
  3429.       case 'Z': case 'z': case 0032:
  3430.         czseen = 1;
  3431.         interrupted = 1;
  3432.         xxscreen(SCR_ST,ST_MSG,0l,
  3433.                  (((what & W_RECV) && (wslots > 1)) ?
  3434.                   "Canceling batch, wait... " :
  3435.                   "Canceling batch... ")
  3436.                  );
  3437.         return(0);
  3438.  
  3439.       case 'F': case 'f': case 0006:    /* Cancel file */
  3440.       case 'X': case 'x': case 0030:
  3441.         cxseen = 1;
  3442.         interrupted = 1;
  3443.         xxscreen(SCR_ST,ST_MSG,0l,
  3444.                  (((what & W_RECV) && (wslots > 1)) ?
  3445.                   "Canceling file, wait... " :
  3446.                   "Canceling file... ")
  3447.                  );
  3448.         return(0);
  3449.  
  3450.       case 'R': case 'r': case 0022:    /* Resend packet */
  3451.       case 0015: case 0012:
  3452. #ifdef STREAMING
  3453.         if (streaming)
  3454.           return(0);
  3455. #endif /* STREAMING */
  3456.         xxscreen(SCR_ST,ST_MSG,0l,"Resending packet... ");
  3457.         numerrs++;
  3458.         resend(winlo);
  3459.         return(0);
  3460.  
  3461. #ifdef datageneral
  3462.       case '\03':                       /* We're not trapping ^C's with */
  3463.         trap(0);                        /* signals, so we check here    */
  3464. #endif /* datageneral */
  3465.  
  3466.       case 'C': case 'c':               /* Ctrl-C */
  3467. #ifndef datageneral
  3468.       case '\03':
  3469. #endif /* datageneral */
  3470.  
  3471.       case 'E': case 'e':               /* Send error packet */
  3472.       case 0005:
  3473.         interrupted = 1;
  3474.         return(-1);
  3475.  
  3476. #ifdef CK_CURSES
  3477.       case 0014:                        /* Ctrl-L to refresh screen */
  3478.       case 'L': case 'l':               /* Also accept L (upper, lower) */
  3479.       case 0027:                        /* Ctrl-W synonym for VMS & Ingres */
  3480.         repaint = 1;
  3481.         return(0);
  3482. #endif /* CK_CURSES */
  3483.  
  3484.       case 'T':
  3485.       case 't':                /* Turn on debug-log timestamps */
  3486. #ifdef DEBUG
  3487.     {
  3488.         extern int debtim;
  3489.         if (ch == 'T') {
  3490.         debtim = 1;
  3491.         xxscreen(SCR_ST,ST_MSG,0l,
  3492.              "Debug timestamps On... ");
  3493.         } else {
  3494.         debtim = 1;
  3495.         xxscreen(SCR_ST,ST_MSG,0l,
  3496.              "Debug timestamps Off... ");
  3497.         }
  3498.     }
  3499. #endif /* DEBUG */
  3500.     return(0);
  3501.  
  3502.       case 'D':
  3503. #ifdef DEBUG
  3504.     if (!deblog) {
  3505.         debopn("debug.log",0);
  3506.         if (deblog) {
  3507.         xxscreen(SCR_ST,ST_MSG,0l,"debug.log open... ");
  3508.         } else {
  3509.         xxscreen(SCR_ST,ST_MSG,0l,"debug.log open FAILED... ");
  3510.         }
  3511.     } else {
  3512.         xxscreen(SCR_ST,ST_MSG,0l,"Debug log On... ");
  3513.     }
  3514.     if (deblog)
  3515.       debok = 1;
  3516. #endif /* DEBUG */
  3517.     return(0);
  3518.  
  3519.       case 'd':                /* Turn off debugging */
  3520. #ifdef DEBUG
  3521.     if (deblog)
  3522.       xxscreen(SCR_ST,ST_MSG,0l,"Debug log Off... ");
  3523.     debok = 0;
  3524. #endif /* DEBUG */
  3525.     return(0);
  3526.  
  3527.       default:                          /* Anything else, print message */
  3528.         intmsg(1L);
  3529.         return(0);
  3530.     }
  3531. }
  3532.  
  3533. /*  I N T M S G  --  Issue message about terminal interrupts  */
  3534.  
  3535. VOID
  3536. #ifdef CK_ANSIC
  3537. intmsg(long n)
  3538. #else
  3539. intmsg(n) long n;
  3540. #endif /* CK_ANSIC */
  3541. /* intmsg */ {
  3542. #ifdef CK_NEED_SIG
  3543.     char buf[80];
  3544. #endif /* CK_NEED_SIG */
  3545.  
  3546.     if (!displa || quiet)               /* Not if we're being quiet */
  3547.       return;
  3548.     if (server && (!srvdis || n > -1L)) /* Special for server */
  3549.       return;
  3550. #ifdef CK_NEED_SIG
  3551.     buf[0] = NUL;                       /* Keep compilers happy */
  3552. #endif /* CK_NEED_SIG */
  3553. #ifndef OXOS
  3554. #ifdef SVORPOSIX
  3555.     conchk();                           /* Clear out pending escape-signals */
  3556. #endif /* SVORPOSIX */
  3557. #endif /* ! OXOS */
  3558. #ifdef VMS
  3559.     conres();                           /* So Ctrl-C will work */
  3560. #endif /* VMS */
  3561.     if ((!server && n == 1L) || (server && n < 0L)) {
  3562.  
  3563. #ifdef CK_NEED_SIG
  3564.         if (xfrint) {
  3565.         ckmakmsg(buf,
  3566.              80,
  3567.              "Type escape character (",
  3568.              dbchr(escape),
  3569.              ") followed by:",
  3570.              NULL
  3571.              );
  3572.             xxscreen(SCR_TN,0,0l,buf);
  3573.         }
  3574. #endif /* CK_NEED_SIG */
  3575.  
  3576.         if (xfrint) {
  3577.             if (protocol == PROTO_K) {
  3578.  xxscreen(SCR_TN,0,0l,"X to cancel file,  CR to resend current packet");
  3579.  xxscreen(SCR_TN,0,0l,"Z to cancel group, A for status report");
  3580.  xxscreen(SCR_TN,0,0l,"E to send Error packet, Ctrl-C to quit immediately: ");
  3581.             } else {
  3582.                 xxscreen(SCR_TN,0,0l,"Ctrl-C to cancel file transfer: ");
  3583.             }
  3584.         } else {
  3585.             xxscreen(SCR_TN,0,0l,"Transfer interruption disabled. ");
  3586.         }
  3587.     }
  3588.     else xxscreen(SCR_TU,0,0l," ");
  3589. }
  3590.  
  3591. #ifndef NODISPLAY
  3592. static int newdpy = 0;                  /* New display flag */
  3593. static char fbuf[80];                   /* Filename buffer */
  3594. static char abuf[80];                   /* As-name buffer */
  3595. static char a2buf[80];                  /* Second As-name buffer */
  3596. static long oldffc = 0L;
  3597. static long dots = 0L;
  3598. static int hpos = 0;
  3599.  
  3600. static VOID                             /* Initialize Serial or CRT display */
  3601. dpyinit() {
  3602.     int m = 0, n = 0;
  3603.     char * s = "";
  3604.  
  3605.     newdpy = 0;                         /*  Don't do this again */
  3606.     oldffc = 0L;                        /*  Reset this */
  3607.     dots = 0L;                          /*  and this.. */
  3608.     oldcps = cps = 0L;
  3609.  
  3610.     conoll("");                /* New line */
  3611.     if (what & W_SEND) s = "Sending: ";    /* Action */
  3612.     else if (what & W_RECV) s = "Receiving: ";
  3613.     n = (int)strlen(s) + (int)strlen(fbuf);
  3614.     conol(fbuf);
  3615.     m = (int)strlen(abuf) + 4;
  3616.     if (n + m > cmd_cols) {
  3617.         conoll("");
  3618.         n = 0;
  3619.     } else
  3620.       n += m;
  3621.     if (*abuf) {
  3622.         conol(" => ");
  3623.         conol(abuf);
  3624.     }
  3625.     m = (int)strlen(a2buf) + 4;
  3626.     if (n + m > cmd_cols) {
  3627.         conoll("");
  3628.         n = 0;
  3629.     } else
  3630.       n += m;
  3631.     if (*a2buf) {
  3632.         conol(" => ");
  3633.         conol(a2buf);
  3634.     }
  3635.     *fbuf = NUL; *abuf = NUL; *a2buf = NUL;
  3636.     conoll("");
  3637.     if (fsize > -1L) {            /* Size */
  3638.         sprintf(fbuf,"Size: %ld, Type: ",fsize); /* SAFE (80) */
  3639.         conol(fbuf); *fbuf = NUL;
  3640.     } else conol("Size: unknown, Type: ");
  3641.     if (binary) {            /* Type */
  3642.         switch(binary) {
  3643.               case XYFT_L: conol("labeled"); break;
  3644.               case XYFT_I: conol("image"); break;
  3645.               case XYFT_U: conol("binary undefined"); break;
  3646.               default:
  3647.               case XYFT_B: conol("binary"); break;
  3648.         }
  3649.     } else {
  3650. #ifdef NOCSETS
  3651.         conol("text");
  3652. #else
  3653.         conol("text, ");
  3654.         if (tcharset == TC_TRANSP || xfrxla == 0) {
  3655.             conol("transparent");
  3656.         } else {
  3657.             if (what & W_SEND) {
  3658.                 conol(fcsinfo[fcharset].keyword);
  3659.                 conol(" => ");
  3660.                 conol(tcsinfo[tcharset].keyword);
  3661.             } else {
  3662.                 conol(tcsinfo[tcharset].keyword);
  3663.                 conol(" => ");
  3664.                 conol(fcsinfo[fcharset].keyword);
  3665.             }
  3666.         }
  3667. #endif /* NOCSETS */
  3668.     }
  3669. #ifdef STREAMING
  3670.     if (streaming)
  3671.       conol(", STREAMING");
  3672. #endif /* STREAMING */
  3673.     conoll("");
  3674.  
  3675.     if (fdispla == XYFD_S) {            /* CRT field headings */
  3676. /*
  3677.   Define CK_CPS to show current transfer rate.
  3678.   Leave it undefined to show estimated time remaining.
  3679.   Estimated-time-remaining code from Andy Fyfe, not tested on
  3680.   pathological cases.
  3681. */
  3682. #define CK_CPS
  3683.  
  3684. #ifdef CK_CPS
  3685.         conoll("    File   Percent       Packet");
  3686.         conoll("    Bytes  Done     CPS  Length");
  3687. #else
  3688.         conoll("    File   Percent  Secs Packet");
  3689.         conoll("    Bytes  Done     Left Length");
  3690. #endif /* CK_CPS */
  3691.         newdpy = 0;
  3692.     }
  3693.     hpos = 0;
  3694. }
  3695.  
  3696. /*
  3697.   showpkt(c)
  3698.   c = completion code: 0 means transfer in progress, nonzero means it's done.
  3699.   Show the file transfer progress counter and perhaps verbose packet type.
  3700. */
  3701. VOID
  3702. #ifdef CK_ANSIC
  3703. showpkt(char c)
  3704. #else
  3705. showpkt(c) char c;
  3706. #endif /* CK_ANSIC */
  3707. /* showpkt */ {
  3708.  
  3709. #ifndef GFTIMER
  3710.     long et;                            /* Elapsed time, entire batch  */
  3711. #endif /* GFTIMER */
  3712.     long howfar;                        /* How far into file */
  3713.     long pd;                            /* Percent done, this file     */
  3714.     long tp;                            /* Transfer rate, entire batch */
  3715.     long ps;                            /* Packet size, current packet */
  3716.     long mytfc;                         /* Local copy of byte counter  */
  3717.  
  3718. #ifdef GFTIMER
  3719.     CKFLOAT tnow;
  3720. #endif /* GFTIMER */
  3721.  
  3722.     if (newdpy)                         /* Put up filenames, etc, */
  3723.       dpyinit();                        /* if they're not there already. */
  3724.  
  3725.     howfar = ffc;                       /* How far */
  3726. /*
  3727.   Calculate CPS rate even if not displaying on screen for use in file
  3728.   transfer statistics.
  3729. */
  3730. #ifdef GFTIMER
  3731.     tnow = gftimer();                   /* Time since we started */
  3732.     ps = (what & W_RECV) ? rpktl : spktl; /* Packet size */
  3733. #ifdef CK_RESEND
  3734.     if (what & W_SEND)            /* In case we didn't start at */
  3735.       howfar += sendstart;              /*  the beginning... */
  3736.     else if (what & W_RECV)
  3737.       howfar += rs_len;
  3738. #endif /* CK_RESEND */
  3739.     pd = -1;                            /* Percent done. */
  3740.     if (c == NUL) {                     /* Still going, figure % done */
  3741.         if (fsize == 0L) return;        /* Empty file, don't bother */
  3742.         pd = (fsize > 99L) ? (howfar / (fsize / 100L)) : 0L;
  3743.         if (pd > 100) pd = 100;         /* Expansion */
  3744.     }
  3745.     if (c != NUL)
  3746.       if (!cxseen && !discard && !czseen)
  3747.         pd = 100;                       /* File complete, so 100%. */
  3748.  
  3749.     mytfc = (pd < 100) ? tfc + ffc : tfc;    /* CPS */
  3750.     tp = (long)((tnow > 0.0) ? (CKFLOAT) mytfc / tnow : 0);
  3751.     if (c && (tp == 0))
  3752.       tp = ffc;
  3753.  
  3754.     cps = tp;                           /* Set global variable */
  3755.     if (cps > peakcps &&                /* Peak transfer rate */
  3756.          ((what & W_SEND && spackets > wslots + 4) ||
  3757.       (!(what & W_SEND) && spackets > 10))) {
  3758.         peakcps = cps;
  3759.     }
  3760.  
  3761. #else  /* Not GFTIMER */
  3762.  
  3763.     et = gtimer();                      /* Elapsed time  */
  3764.     ps = (what & W_RECV) ? rpktl : spktl; /* Packet length */
  3765. #ifdef CK_RESEND
  3766.     if (what & W_SEND)            /* And if we didn't start at */
  3767.       howfar += sendstart;              /*  the beginning... */
  3768.     else if (what & W_RECV)
  3769.       howfar += rs_len;
  3770. #endif /* CK_RESEND */
  3771.     pd = -1;                            /* Percent done. */
  3772.     if (c == NUL) {                     /* Still going, figure % done */
  3773.         if (fsize == 0L) return;        /* Empty file, don't bother */
  3774.         pd = (fsize > 99L) ? (howfar / (fsize / 100L)) : 0L;
  3775.         if (pd > 100) pd = 100;         /* Expansion */
  3776.     }
  3777.     if (c != NUL)
  3778.       if (!cxseen && !discard && !czseen)
  3779.         pd = 100;                       /* File complete, so 100%. */
  3780.  
  3781.  
  3782. #ifndef CK_CPS
  3783. /*
  3784.   fsecs = time (from gtimer) that this file started (set in sfile()).
  3785.   Rate so far is ffc / (et - fsecs),  estimated time for remaining bytes
  3786.   is (fsize - ffc) / (ffc / (et - fsecs)).
  3787. */
  3788.     tp = (howfar > 0L) ? (fsize - howfar) * (et - fsecs) / howfar : 0L;
  3789. #endif /* CK_CPS */
  3790.  
  3791. #ifdef CK_CPS
  3792.     mytfc = (pd < 100) ? tfc + ffc : tfc;
  3793.     tp = (et > 0) ? mytfc / et : 0;    /* Transfer rate */
  3794.     if (c && (tp == 0))            /* Watch out for subsecond times */
  3795.         tp = ffc;
  3796.  
  3797.     cps = tp;                /* Set global variable */
  3798.     if (cps > peakcps &&                /* Peak transfer rate */
  3799.          ((what & W_SEND && spackets > wslots + 4) ||
  3800.       (!(what & W_SEND) && spackets > 10))) {
  3801.         peakcps = cps;
  3802.     }
  3803. #endif /* CK_CPS */
  3804.  
  3805. #endif /* GFTIMER */
  3806.  
  3807.     if (fdispla == XYFD_S) {            /* CRT display */
  3808.         char buffer[128];
  3809.     /* These sprintfs should be safe until we have 32-digit numbers */
  3810.  
  3811.         if (pd > -1L)
  3812.           sprintf(buffer, "%c%9ld%5ld%%%8ld%8ld ", CR, howfar, pd, tp, ps);
  3813.         else
  3814.           sprintf(buffer, "%c%9ld      %8ld%8ld ", CR, howfar, tp, ps);
  3815.         conol(buffer);
  3816.         hpos = 31;
  3817.     } else if (fdispla == XYFD_R) {     /* SERIAL */
  3818.         long i, k;
  3819.         if (howfar - oldffc < 1024)     /* Update display every 1K */
  3820.           return;
  3821.         oldffc = howfar;                /* Time for new display */
  3822.         k = (howfar / 1024L) - dots;    /* How many K so far */
  3823.         for (i = 0L; i < k; i++) {
  3824.             if (hpos++ > (cmd_cols - 3)) { /* Time to wrap? */
  3825.                 conoll("");
  3826.                 hpos = 0;
  3827.             }
  3828.             conoc('.');                 /* Print a dot for this K */
  3829.             dots++;                     /* Count it */
  3830.         }
  3831.     }
  3832. }
  3833.  
  3834.  
  3835. /*  C K S C R E E N  --  Screen display function  */
  3836.  
  3837. /*
  3838.   ckscreen(f,c,n,s)
  3839.     f - argument descriptor
  3840.     c - a character or small integer
  3841.     n - a long integer
  3842.     s - a string.
  3843.  
  3844.   and global fdispla = SET FILE DISPLAY value:
  3845.  
  3846.     XYFD_N = NONE
  3847.     XYFD_R = SERIAL:     Dots, etc, works on any terminal, even hardcopy.
  3848.     XYFD_S = CRT:        Works on any CRT, writes over current line.
  3849.     XYFD_C = FULLSCREEN: Requires terminal-dependent screen control.
  3850.     XYFD_B = BRIEF:      Like SERIAL but only filename & completion status.
  3851.     XYFD_G = GUI;        Windows GUI, same behavior as FULLSCREEN
  3852. */
  3853. VOID
  3854. #ifdef CK_ANSIC
  3855. ckscreen(int f, char c,long n,char *s)
  3856. #else
  3857. ckscreen(f,c,n,s) int f; char c; long n; char *s;
  3858. #endif /* CK_ANSIC */
  3859. /* screen */ {
  3860.     char buf[80];
  3861.     int len;                            /* Length of string */
  3862. #ifdef UNIX
  3863. #ifndef NOJC
  3864.     int obg;
  3865. _PROTOTYP( VOID conbgt, (int) );
  3866. #endif /* NOJC */
  3867. #endif /* UNIX */
  3868.     int ftp = 0;
  3869.  
  3870.     ftp = (what & W_FTP) ? 1 : 0;    /* FTP or Kermit? */
  3871.  
  3872.     if (!local && !ftp)            /* In remote mode - don't do this */
  3873.       return;
  3874.  
  3875.     if (!s) s = "";
  3876.  
  3877.     if (!fxd_inited)                    /* Initialize if necessary */
  3878.       fxdinit(fdispla);
  3879.  
  3880. #ifdef UNIX
  3881. #ifndef NOJC
  3882.     obg = backgrd;                      /* Previous background status */
  3883.     conbgt(1);                          /* See if running in background */
  3884.     if (!backgrd && obg) {              /* Just came into foreground? */
  3885.         concb((char)escape);            /* Put console back in CBREAK mode */
  3886.         setint();                       /* Restore interrupts */
  3887.     }
  3888. #endif /* NOJC */
  3889. #endif /* UNIX */
  3890.  
  3891.     if ((f != SCR_WM) && (f != SCR_EM)) /* Always update warnings & errors */
  3892.       if (!displa ||
  3893.           (backgrd && bgset) ||
  3894.           fdispla == XYFD_N ||
  3895.           (server && !srvdis)
  3896.           )
  3897.         return;
  3898.  
  3899. #ifdef VMS
  3900.     if (f == SCR_FN)                    /* VMS - shorten the name */
  3901.       s = zrelname(s,zgtdir());
  3902. #endif /* VMS */
  3903.  
  3904.     if (dest == DEST_S)                 /* SET DESTINATION SCREEN */
  3905.       return;                           /*  would interfere... */
  3906.  
  3907. #ifdef KUI
  3908.     if (fdispla == XYFD_G) {            /* If gui display selected */
  3909.         screeng(f,c,n,s);               /* call the gui version */
  3910.         return;
  3911.     }
  3912. #endif /* KUI */
  3913. #ifdef CK_CURSES
  3914.     if (fdispla == XYFD_C) {            /* If fullscreen display selected */
  3915.         screenc(f,c,n,s);               /* call the fullscreen version */
  3916.         return;
  3917.     }
  3918. #endif /* CK_CURSES */
  3919.  
  3920.     len = (int)strlen(s);               /* Length of string */
  3921.  
  3922.     switch (f) {                        /* Handle our function code */
  3923.       case SCR_FN:                      /* Filename */
  3924.         if (fdispla == XYFD_B) {
  3925. #ifdef NEWFTP
  3926.         if (ftp)
  3927.           printf(" %s %s", what & W_SEND ? "PUT" : "GET", s);
  3928.         else
  3929. #endif /* NEWFTP */
  3930.           printf(" %s %s", what & W_SEND ? "SEND" : "RECV", s);
  3931. #ifdef UNIX
  3932.             fflush(stdout);
  3933. #endif /* UNIX */
  3934.             return;
  3935.         }
  3936. #ifdef MAC
  3937.         conoll(""); conol(s); conoc(SP); hpos = len + 1;
  3938. #else
  3939.         ckstrncpy(fbuf,s,80);
  3940.         abuf[0] = a2buf[0] = NUL;
  3941.         newdpy = 1;                     /* New file so refresh display */
  3942. #endif /* MAC */
  3943.         return;
  3944.  
  3945.       case SCR_AN:                      /* As-name */
  3946.         if (fdispla == XYFD_B) {
  3947. #ifdef COMMENT
  3948.             printf("(as %s) ",s);
  3949. #endif /* COMMENT */
  3950.             return;
  3951.         }
  3952. #ifdef MAC
  3953.         if (hpos + len > 75) { conoll(""); hpos = 0; }
  3954.         conol("=> "); conol(s);
  3955.         if ((hpos += (len + 3)) > 78) { conoll(""); hpos = 0; }
  3956. #else
  3957.         if (abuf[0]) {
  3958.             ckstrncpy(a2buf,s,80);
  3959.         } else {
  3960.             ckstrncpy(abuf,s,80);
  3961.         }
  3962. #endif /* MAC */
  3963.         return;
  3964.  
  3965.       case SCR_FS:                      /* File-size */
  3966.         if (fdispla == XYFD_B) {
  3967.             printf(" (%s) (%ld byte%s)",
  3968. #ifdef NOICP
  3969.                    (binary ? "binary" : "text")
  3970. #else
  3971.                    gfmode(binary,0)
  3972. #endif /* NOICP */
  3973.                    , n, n == 1L ? "" : "s");
  3974. #ifdef UNIX
  3975.             fflush(stdout);
  3976. #endif /* UNIX */
  3977.             return;
  3978.         }
  3979. #ifdef MAC
  3980.         sprintf(buf,", Size: %ld",n);  conoll(buf);  hpos = 0;
  3981. #endif /* MAC */
  3982.         return;
  3983.  
  3984.       case SCR_XD:                      /* X-packet data */
  3985.         if (fdispla == XYFD_B)
  3986.           return;
  3987. #ifdef MAC
  3988.         conoll(""); conoll(s); hpos = 0;
  3989. #else
  3990.         ckstrncpy(fbuf,s,80);
  3991.         abuf[0] = a2buf[0] = NUL;
  3992. #endif /* MAC */
  3993.         return;
  3994.  
  3995.       case SCR_ST:                      /* File status */
  3996.         switch (c) {
  3997.           case ST_OK:                   /* Transferred OK */
  3998.             showpkt('Z');               /* Update numbers one last time */
  3999.             if (fdispla == XYFD_B) {
  4000. #ifdef GFTIMER
  4001.                 printf(": OK (%0.3f sec, %ld cps)\n",fpxfsecs,
  4002.                        (long)((CKFLOAT)ffc / fpxfsecs));
  4003. #else
  4004.                 printf(": OK (%d sec, %ld cps)\n",xfsecs,ffc/xfsecs);
  4005. #endif /* GFTIMER */
  4006.                 return;
  4007.             }
  4008.             if ((hpos += 5) > 78) conoll(""); /* Wrap screen line. */
  4009.             conoll(" [OK]"); hpos = 0;  /* Print OK message. */
  4010.             if (fdispla == XYFD_S) {    /* We didn't show Z packet when */
  4011.                 conoc('Z');             /* it came, so show it now. */
  4012.                 hpos = 1;
  4013.             }
  4014.             return;
  4015.  
  4016.           case ST_DISC:                 /*  Discarded */
  4017.             if (fdispla == XYFD_B) {
  4018.                 printf(": DISCARDED\n");
  4019.                 return;
  4020.             }
  4021.             if ((hpos += 12) > 78) conoll("");
  4022.             conoll(" [discarded]"); hpos = 0;
  4023.             return;
  4024.  
  4025.           case ST_INT:                  /*  Interrupted */
  4026.             if (fdispla == XYFD_B) {
  4027.                 printf(": INTERRUPTED\n");
  4028.                 return;
  4029.             }
  4030.             if ((hpos += 14) > 78) conoll("");
  4031.             conoll(" [interrupted]"); hpos = 0;
  4032.             return;
  4033.  
  4034.       case ST_SIM:
  4035.             if (fdispla == XYFD_B) {
  4036.         if (n == SKP_XNX)
  4037.           printf(": WOULD BE TRANSFERRED (New file)\n");
  4038.         else if (n == SKP_XUP)
  4039.           printf(": WOULD BE TRANSFERRED (Remote file older)\n");
  4040.         else if (n == SKP_SIM)
  4041.           printf(": WOULD BE TRANSFERRED\n");
  4042.         else if (n > 0 && n < nskreason)
  4043.           printf(": SKIPPED (%s)\n",skreason[n]);
  4044.         else
  4045.           printf(": SKIPPED\n");
  4046.                 return;
  4047.             } else if (fdispla == XYFD_S) {
  4048.                 if (fdispla == XYFD_S && fbuf[0]) { /* CRT display */
  4049.                     conoll("");         /* New line */
  4050.                     if (what & W_SEND) conol("Would Send: "); /* Action */
  4051.                     else if (what & W_RECV) conol("Would Receive: ");
  4052.                     conol(fbuf);
  4053.                     if (*abuf) conol(" => "); conol(abuf); /* Names */
  4054.                     if (*a2buf) conol(" => "); conol(a2buf); /* Names */
  4055.                     *fbuf = NUL; *abuf = NUL; *a2buf = NUL;
  4056.                 }
  4057.                 conoll(" [simulated]");
  4058.                 return;
  4059.             }
  4060.             if ((hpos += 10) > 78) conoll("");
  4061.             conol(" [simulated]"); hpos = 0;
  4062.             return;
  4063.  
  4064.           case ST_SKIP:                 /*  Skipped */
  4065.             if (fdispla == XYFD_B) {
  4066.         if (n == SKP_XNX)
  4067.           printf(": WOULD BE TRANSFERRED (New file)\n");
  4068.         else if (n == SKP_XUP)
  4069.           printf(": WOULD BE TRANSFERRED (Remote file older)\n");
  4070.         else if (n == SKP_SIM)
  4071.           printf(": WOULD BE TRANSFERRED\n");
  4072.         else if (n > 0 && n < nskreason)
  4073.           printf(": SKIPPED (%s)\n",skreason[n]);
  4074.         else
  4075.           printf(": SKIPPED\n");
  4076.                 return;
  4077.             } else if (fdispla == XYFD_S) {
  4078.                 if (fdispla == XYFD_S && fbuf[0]) { /* CRT display */
  4079.                     conoll("");         /* New line */
  4080.                     if (what & W_SEND) conol("Sending: "); /* Action */
  4081.                     else if (what & W_RECV) conol("Receiving: ");
  4082.                     conol(fbuf);
  4083.                     if (*abuf) conol(" => "); conol(abuf); /* Names */
  4084.                     if (*a2buf) conol(" => "); conol(a2buf); /* Names */
  4085.                     *fbuf = NUL; *abuf = NUL; *a2buf = NUL;
  4086.                 }
  4087.                 conoll(" [skipped]");
  4088.                 return;
  4089.             }
  4090.             if ((hpos += 10) > 78) conoll("");
  4091.         conol(" "); conol(fbuf);
  4092.             conoll(" [skipped]"); hpos = 0;
  4093.             return;
  4094.  
  4095.           case ST_ERR:                  /* Error */
  4096.             if (fdispla == XYFD_B) {
  4097.                 printf(": ERROR: %s\n",s);
  4098.                 return;
  4099.             }
  4100.             conoll("");
  4101.             conol("Error: "); conoll(s); hpos = 0;
  4102.             return;
  4103.  
  4104.           case ST_MSG:                  /* Message */
  4105. #ifdef NEWFTP
  4106.             if (fdispla == XYFD_B) {
  4107.                 if (ftp && ftp_deb)
  4108.           printf(": MESSAGE: %s\n",s);
  4109.                 return;
  4110.             }
  4111. #endif /* NEWFTP */
  4112.             conoll("");
  4113.             conol("Message: ");
  4114.             conoll(s);
  4115.             hpos = 0;
  4116.             return;
  4117.  
  4118.           case ST_REFU:                 /* Refused */
  4119.             if (fdispla == XYFD_B) {
  4120.                 printf(": REFUSED\n");
  4121.                 return;
  4122.             } else if (fdispla == XYFD_S) {
  4123.                 if (fdispla == XYFD_S && fbuf[0]) { /* CRT display */
  4124.                     conoll("");         /* New line */
  4125.                     if (what & W_SEND) conol("Sending: "); /* Action */
  4126.                     else if (what & W_RECV) conol("Receiving: ");
  4127.                     conol(fbuf);
  4128.                     if (*abuf) conol(" => "); conol(abuf);      /* Names */
  4129.                     if (*a2buf) conol(" => "); conol(a2buf);    /* Names */
  4130.                     *fbuf = NUL; *abuf = NUL; *a2buf = NUL;
  4131.                     conoll("");
  4132.                 }
  4133.                 conol("Refused: "); conoll(s);
  4134.                 return;
  4135.             }
  4136.             conoll("");
  4137.             conol("Refused: "); conoll(s); hpos = 0;
  4138.             return;
  4139.  
  4140.           case ST_INC:                  /* Incomplete */
  4141.             if (fdispla == XYFD_B) {
  4142.                 printf(": INCOMPLETE\n");
  4143.                 return;
  4144.             }
  4145.             if ((hpos += 12) > 78) conoll("");
  4146.             conoll(" [incomplete]"); hpos = 0;
  4147.             return;
  4148.  
  4149.           default:
  4150.             conoll("*** screen() called with bad status ***");
  4151.             hpos = 0;
  4152.             return;
  4153.         }
  4154.  
  4155. #ifdef MAC
  4156.       case SCR_PN:                      /* Packet number */
  4157.         if (fdispla == XYFD_B) {
  4158.             return;
  4159.         }
  4160.     ckmakmsg(buf,80,s,": ",ckltoa(n),NULL);
  4161.         conol(buf); hpos += (int)strlen(buf); return;
  4162. #endif /* MAC */
  4163.  
  4164.       case SCR_PT:                      /* Packet type or pseudotype */
  4165.         if (fdispla == XYFD_B)
  4166.           return;
  4167.         if (c == 'Y') return;           /* Don't bother with ACKs */
  4168.         if (c == 'D') {                 /* In data transfer phase, */
  4169.             showpkt(NUL);               /* show progress. */
  4170.             return;
  4171.         }
  4172. #ifndef AMIGA
  4173.         if (hpos++ > 77) {              /* If near right margin, */
  4174.             conoll("");                 /* Start new line */
  4175.             hpos = 0;                   /* and reset counter. */
  4176.         }
  4177. #endif /* AMIGA */
  4178.         if (c == 'Z' && fdispla == XYFD_S)
  4179.           return;
  4180.         else
  4181.           conoc(c);                     /* Display the packet type. */
  4182. #ifdef AMIGA
  4183.         if (c == 'G') conoll("");       /* New line after G packets */
  4184. #endif /* AMIGA */
  4185.         return;
  4186.  
  4187.       case SCR_TC:                      /* Transaction complete */
  4188.         if (xfrbel) bleep(BP_NOTE);
  4189.         if (fdispla == XYFD_B) {        /* Brief display... */
  4190.             if (filcnt > 1) {
  4191.                 long fx;
  4192.                 fx = filcnt - filrej;
  4193.                 printf(" SUMMARY: %ld file%s", fx, ((fx == 1L) ? "" : "s"));
  4194.                 printf(", %ld byte%s", tfc, ((tfc == 1L) ? "" : "s"));
  4195. #ifdef GFTIMER
  4196.                 printf(", %0.3f sec, %ld cps", fptsecs, tfcps);
  4197. #else
  4198.                 printf(", %ld sec, %ld cps", tsecs, tfcps);
  4199. #endif /* GFTIMER */
  4200.                 printf(".\n");
  4201.             }
  4202.         } else {
  4203.             conoll("");
  4204.         }
  4205. #ifdef UNIX
  4206.         fflush(stdout);
  4207. #endif /* UNIX */
  4208.         return;
  4209.  
  4210.       case SCR_EM:                      /* Error message */
  4211.         if (fdispla == XYFD_B) {
  4212.             printf(" ERROR: %s\n",s);
  4213.             return;
  4214.         }
  4215.         conoll(""); conoc('?'); conoll(s); hpos = 0; return;
  4216.  
  4217.       case SCR_WM:                      /* Warning message */
  4218.         if (fdispla == XYFD_B) {
  4219.             printf(" WARNING: %s\n",s);
  4220.             return;
  4221.         }
  4222.         conoll(""); conoll(s); hpos = 0; return;
  4223.  
  4224.       case SCR_TU:                      /* Undelimited text */
  4225.         if (fdispla == XYFD_B)
  4226.           return;
  4227.         if ((hpos += len) > 77) { conoll(""); hpos = len; }
  4228.         conol(s); return;
  4229.  
  4230.       case SCR_TN:                      /* Text delimited at beginning */
  4231.         if (fdispla == XYFD_B)
  4232.           return;
  4233.         conoll(""); conol(s); hpos = len; return;
  4234.  
  4235.       case SCR_TZ:                      /* Text delimited at end */
  4236.         if (fdispla == XYFD_B)
  4237.           return;
  4238.         if ((hpos += len) > 77) { conoll(""); hpos = len; }
  4239.         conoll(s); return;
  4240.  
  4241.       case SCR_QE:                      /* Quantity equals */
  4242.         if (fdispla == XYFD_B)
  4243.           return;
  4244.     ckmakmsg(buf,80,s,": ",ckltoa(n),NULL);
  4245.         conoll(buf); hpos = 0; return;
  4246.  
  4247.       case SCR_CW:                      /* Close fullscreen window */
  4248.         return;                         /* No window to close */
  4249.  
  4250.       case SCR_CD:
  4251.         return;
  4252.  
  4253.       default:
  4254.         conoll("*** screen() called with bad object ***");
  4255.         hpos = 0;
  4256.         return;
  4257.     }
  4258. }
  4259. #endif /* NODISPLAY */
  4260.  
  4261. /*  E R M S G  --  Nonfatal error message  */
  4262.  
  4263. /* Should be used only for printing the message text from an Error packet. */
  4264.  
  4265. VOID
  4266. ermsg(msg) char *msg; {                 /* Print error message */
  4267.     debug(F110,"ermsg",msg,0);
  4268.     if (local)
  4269.       xxscreen(SCR_EM,0,0L,msg);
  4270.     tlog(F110,"Protocol Error:",msg,0L);
  4271. }
  4272. #endif /* NOXFER */
  4273.  
  4274. VOID
  4275. setseslog(x) int x; {
  4276.     seslog = x;
  4277. #ifdef KUI
  4278.     KuiSetProperty(KUI_TERM_CAPTURE,x,0);
  4279. #endif /* KUI */
  4280. }
  4281.  
  4282. VOID
  4283. doclean(fc) int fc; {                   /* General cleanup */
  4284. #ifdef OS2ORUNIX
  4285.     extern int ttyfd;
  4286. #endif /* OS2ORUNIX */
  4287.     extern int  keep;
  4288.     extern int exithangup;
  4289. #ifndef NOXFER
  4290.     extern char filnam[];
  4291. #endif /* NOXFER */
  4292. #ifndef NOICP
  4293.     int x;
  4294.  
  4295.     if (fc > 0)
  4296.       dostop();                 /* Stop all command files and end macros */
  4297. #endif /* NOICP */
  4298.  
  4299. #ifndef NOXFER
  4300.     if (pktlog) {
  4301.         *pktfil = '\0';
  4302.         pktlog = 0;
  4303.         zclose(ZPFILE);
  4304.     }
  4305. #endif /* NOXFER */
  4306.     if (seslog) {
  4307.         *sesfil = '\0';
  4308.         setseslog(0);
  4309.         zclose(ZSFILE);
  4310.     }
  4311. #ifdef TLOG
  4312.     if (tralog) {
  4313.         tlog(F100,"Transaction Log Closed","",0L);
  4314.         *trafil = '\0';
  4315.         tralog = 0;
  4316.         zclose(ZTFILE);
  4317.     }
  4318. #endif /* TLOG */
  4319.  
  4320.     debug(F100,"doclean calling dologend","",0);
  4321.     dologend();                         /* End current log record if any */
  4322. #ifdef COMMENT
  4323.     if (dialog) {                       /* If connection log open */
  4324.     dialog = 0;
  4325.         *diafil = '\0';                 /* close it. */
  4326.         zclose(ZDIFIL);
  4327.     }
  4328. #endif /* COMMENT */
  4329.  
  4330. #ifndef NOICP
  4331. #ifndef NOSPL
  4332.     zclose(ZRFILE);                     /* READ and WRITE files, if any. */
  4333.     zclose(ZWFILE);
  4334. #ifndef NOXFER
  4335.     zclose(ZIFILE);                     /* And other files too */
  4336.     x = chkfn(ZOFILE);            /* Download in progress? */
  4337.     debug(F111,"doclean chkfn ZOFILE",filnam,x);
  4338.     debug(F111,"doclean keep","",keep);
  4339.     zclose(ZOFILE);            /* Close output file */
  4340.     if (x > 0 && !keep) {        /* If it was being downloaded */
  4341.     if (filnam[0])
  4342.       x = zdelet(filnam);        /* Delete if INCOMPLETE = DISCARD */
  4343.     debug(F111,"doclean download filename",filnam,x);
  4344.     }
  4345. #endif /* NOXFER */
  4346.     zclose(ZSYSFN);
  4347.     zclose(ZMFILE);
  4348.  
  4349.     if (fc < 1) {                       /* RESETing, not EXITing */
  4350. #ifdef DEBUG
  4351.         if (deblog) {                   /* Close the debug log. */
  4352.             *debfil = '\0';
  4353.             deblog = 0;
  4354.             zclose(ZDFILE);
  4355.         }
  4356. #endif /* DEBUG */
  4357.         return;
  4358.     }
  4359. #endif /* NOSPL */
  4360. #endif /* NOICP */
  4361.  
  4362. #ifndef NOLOCAL
  4363.     debug(F101,"doclean exithangup","",exithangup);
  4364.     if (local && exithangup) {        /* Close communication connection */
  4365.         extern int haslock;
  4366.     int x;
  4367.     
  4368.     x = ttchk();
  4369.     debug(F101,"doclean ttchk()","",x);
  4370. #ifdef OS2ORUNIX
  4371.     debug(F101,"doclean ttyfd","",ttyfd);
  4372. #endif /* OS2ORUNIX */
  4373.         if (x >= 0
  4374. #ifdef OS2
  4375.             || ttyfd != -1
  4376. #else
  4377. #ifdef UNIX
  4378.             || haslock                  /* Make sure we get lockfile! */
  4379.             || (!network && ttyfd > -1)
  4380. #endif /* UNIX */
  4381. #endif /* OS2 */
  4382.             ) {
  4383.             extern int wasclosed, whyclosed;
  4384.         debug(F100,"doclean hanging up and closing","",0);
  4385.             if (msgflg) {
  4386. #ifdef UNIX
  4387.                 fflush(stdout);
  4388. #endif /* UNIX */
  4389.                 printf("Closing %s...",ttname);
  4390.             }
  4391. #ifndef NODIAL
  4392.             mdmhup();                   /* Hangup the modem??? */
  4393. #endif /* NODIAL */
  4394.             ttclos(0);                  /* Close external line, if any */
  4395.             if (msgflg) {
  4396.                 printf("OK\n");
  4397. #ifdef UNIX
  4398.                 fflush(stdout);
  4399. #endif /* UNIX */
  4400.             }
  4401.             if (wasclosed) {
  4402.                 whyclosed = WC_CLOS;
  4403. #ifndef NOSPL
  4404.                 if (nmac) {             /* Any macros defined? */
  4405.                     int k;              /* Yes */
  4406.                     k = mlook(mactab,"on_close",nmac);  /* Look this up */
  4407.                     if (k >= 0) {                       /* If found, */
  4408.                         wasclosed = 0;
  4409.                         /* printf("ON_CLOSE DOCLEAN\n"); */
  4410.                         *(mactab[k].kwd) = NUL;         /* See comment below */
  4411.                         if (dodo(k,ckitoa(whyclosed),0) > -1) /* set it up, */
  4412.                           parser(1);                    /* and execute it */
  4413.                     }
  4414.                 }
  4415. #endif /* NOSPL */
  4416.                 wasclosed = 0;
  4417.             }
  4418.         }
  4419.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty */
  4420.         local = dfloc;                  /* And default remote/local status */
  4421.     }
  4422. #ifdef DEBUG
  4423.     else if (local) debug(F100,"doclean hangup/close skipped","",0);
  4424. #endif /* DEBUG */
  4425. #endif /* NOLOCAL */
  4426.  
  4427. #ifdef NEWFTP
  4428.     ftpbye();                /* If FTP connection open, close it */
  4429. #endif /* NEWFTP */
  4430.  
  4431. #ifdef IKSD
  4432.     if (inserver)
  4433.       ttclos(0);            /* If IKSD, close socket */
  4434. #endif /* IKSD */
  4435.  
  4436. #ifndef NOSPL
  4437. /*
  4438.   If a macro named "on_exit" is defined, execute it.  Also remove it from the
  4439.   macro table, in case its definition includes an EXIT or QUIT command, which
  4440.   would cause much recursion and would prevent the program from ever actually
  4441.   EXITing.
  4442. */
  4443.     if (nmac) {                         /* Any macros defined? */
  4444.         int k;                          /* Yes */
  4445.         char * cmd = "on_exit";         /* MSVC 2.x compiler error */
  4446.         k = mlook(mactab,cmd,nmac);     /* Look up "on_exit" */
  4447.         if (k >= 0) {                   /* If found, */
  4448. #ifdef COMMENT
  4449.         /* This makes a mess if ON_EXIT itself executes macros */
  4450.             *(mactab[k].kwd) = NUL;     /* poke its name from the table, */
  4451. #else
  4452.         /* Replace the keyword with something that doesn't wreck the */
  4453.         /* order of the keyword table */
  4454.         ckstrncpy(mactab[k].kwd,"on_exxx",8);
  4455. #endif /* COMMENT */
  4456.             if (dodo(k,"",0) > -1)      /* set it up, */
  4457.               parser(1);                /* and execute it */
  4458.         }
  4459.     }
  4460. #endif /* NOSPL */
  4461. /*
  4462.   Put console terminal back to normal.  This is done here because the
  4463.   ON_EXIT macro calls the parser, which meddles with console terminal modes.
  4464. */
  4465.     conres();                           /* Restore console terminal. */
  4466.  
  4467. #ifdef COMMENT
  4468. /* Should be no need for this, and maybe it's screwing things up? */
  4469.     connoi();                           /* Turn off console interrupt traps */
  4470. #endif /* COMMENT */
  4471.  
  4472.     /* Delete the Startup File if we are supposed to. */
  4473. #ifndef NOICP
  4474.     {
  4475.         extern int DeleteStartupFile;
  4476.         debug(F111,"doclean DeleteStartupFile",cmdfil,DeleteStartupFile);
  4477.         if (DeleteStartupFile) {
  4478.             int rc = zdelet(cmdfil);
  4479.             debug(F111,"doclean zdelet",cmdfil,rc);
  4480.         }
  4481.     }
  4482. #endif /* NOICP */
  4483.     syscleanup();                       /* System-dependent cleanup, last */
  4484. }
  4485.  
  4486. /*  D O E X I T  --  Exit from the program.  */
  4487.  
  4488. /*
  4489.   First arg is general, system-independent symbol: GOOD_EXIT or BAD_EXIT.
  4490.   If second arg is -1, take 1st arg literally.
  4491.   If second arg is not -1, work it into the exit code.
  4492. */
  4493. VOID
  4494. doexit(exitstat,code) int exitstat, code; {
  4495.     extern int x_logged, quitting;
  4496. #ifdef OS2
  4497.     extern int display_demo;
  4498.     extern int SysInited;
  4499. #endif /* OS2 */
  4500. #ifdef CK_KERBEROS
  4501. #ifdef KRB4
  4502.     extern int krb4_autodel;
  4503. #endif /* KRB4 */
  4504. #ifdef KRB5
  4505.     extern int krb5_autodel;
  4506. #endif /* KRB5 */
  4507. #endif /* CK_KERBEROS */
  4508.  
  4509. #ifdef VMS
  4510.     char envstr[64];
  4511.     static $DESCRIPTOR(symnam,"CKERMIT_STATUS");
  4512.     static struct dsc$descriptor_s symval;
  4513. #endif /* VMS */
  4514.     int i;
  4515.  
  4516. #ifdef DEBUG
  4517. #ifdef USE_LUCACHE
  4518.     extern long lucalls, luhits, xxhits, luloop;
  4519.     extern int lusize;
  4520. #endif /* USE_LUCACHE */
  4521. #ifndef NOSPL
  4522.     extern int cmdstats[];
  4523. #endif /* NOSPL */
  4524.  
  4525.     quitting++;
  4526.  
  4527. #ifdef OS2
  4528.     if ( !SysInited )
  4529.         sysinit();
  4530. #endif /* OS2 */
  4531.  
  4532.     if (deblog) {
  4533. #ifdef USE_LUCACHE
  4534.     debug(F101,"lookup cache size","",lusize);
  4535.     debug(F101,"lookup calls ....","",lucalls);
  4536.     debug(F101,"lookup cache hits","",luhits);
  4537.     debug(F101,"lookup start hits","",xxhits);
  4538.     debug(F101,"lookup loop iterations","",luloop);
  4539. #endif /* USE_LUCACHE */
  4540. #ifndef NOSPL
  4541.     for (i = 0; i < 256; i++) {
  4542.         if (cmdstats[i])
  4543.           debug(F111,"CMSTATS",ckitoa(i),cmdstats[i]);
  4544.     }
  4545. #endif /* NOSPL */
  4546.     debug(F101,"doexit exitstat","",exitstat);
  4547.     debug(F101,"doexit code","",code);
  4548.     debug(F101,"doexit xitsta","",xitsta);
  4549.     }
  4550. #endif /* DEBUG */
  4551.  
  4552. #ifdef CK_KERBEROS
  4553.     /* If we are automatically destroying Kerberos credentials on Exit */
  4554.     /* do it now. */
  4555. #ifdef KRB4
  4556.     if (krb4_autodel == KRB_DEL_EX) {
  4557.         extern struct krb_op_data krb_op;
  4558.         krb_op.version = 4;
  4559.         krb_op.cache = NULL;
  4560.         ck_krb4_destroy(&krb_op);
  4561.     }
  4562. #endif /* KRB4 */
  4563. #ifdef KRB5
  4564.     if (krb5_autodel == KRB_DEL_EX) {
  4565.         extern struct krb_op_data krb_op;
  4566.         extern char * krb5_d_cc;
  4567.         krb_op.version = 5;
  4568.         krb_op.cache = krb5_d_cc;
  4569.         ck_krb5_destroy(&krb_op);
  4570.     }
  4571. #endif /* KRB5 */
  4572. #endif /* CK_KERBEROS */
  4573.  
  4574. #ifndef NOLOCAL
  4575. #ifdef OS2
  4576.     if (SysInited)
  4577.     {
  4578. #ifdef DCMDBUF
  4579.         extern struct cmdptr *cmdstk;
  4580. #else
  4581.         extern struct cmdptr cmdstk[];
  4582. #endif /* DCMDBUF */
  4583.         extern int tt_status[];
  4584.         extern int vmode;
  4585.  
  4586.         /* If there is a demo screen to be displayed, display it */
  4587.         if (display_demo) {
  4588.             demoscrn(VCMD);
  4589.             display_demo = 0;
  4590.         }
  4591. #ifndef KUI
  4592.         /* This is going to be hideous.  If we have a status line */
  4593.         /* in the command window turn it off before we exit.      */
  4594.  
  4595.         if ( tt_status[VCMD] && vmode == VCMD ) {
  4596.             domac("_clear_statusline","set command statusline off",
  4597.                    cmdstk[cmdlvl].ccflgs);
  4598.             delmac("_clear_statusline",1);
  4599.             RequestScreenMutex(-1);
  4600.             VscrnIsDirty(vmode);
  4601.             ReleaseScreenMutex();
  4602.             while ( IsVscrnDirty(vmode) )
  4603.                 msleep(200);
  4604.             RequestScreenMutex(-1);
  4605.             ReleaseScreenMutex();
  4606.         }
  4607. #endif /* KUI */
  4608.         DialerSend(OPT_KERMIT_EXIT,exitstat);
  4609. #ifndef KUI
  4610.         debug(F100,"doexit about to msleep","",0);
  4611.  
  4612.         if ( isWin95() )
  4613.             msleep(250);
  4614. #endif /* KUI */
  4615.     }
  4616. #endif /* OS2 */
  4617. #endif /* NOLOCAL */
  4618.  
  4619. #ifdef IKSD
  4620. #ifdef CK_LOGIN
  4621.     if (inserver && x_logged) {
  4622. #ifndef NOSPL
  4623. /*
  4624.   If a macro named "on_logout" is defined, execute it.  Also remove it from the
  4625.   macro table, in case its definition includes an EXIT or QUIT command, which
  4626.   would cause much recursion and would prevent the program from ever actually
  4627.   EXITing.
  4628. */
  4629.     if (nmac) {            /* Any macros defined? */
  4630.         int k;            /* Yes */
  4631.         char * cmd = "on_logout";    /* MSVC 2.x compiler error */
  4632.         k = mlook(mactab,cmd,nmac);    /* Look up "on_logout" */
  4633.         if (k >= 0) {        /* If found, */
  4634.         *(mactab[k].kwd) = NUL;    /* poke its name from the table, */
  4635.         if (dodo(k,"",0) > -1)    /* set it up, */
  4636.           parser(1);        /* and execute it */
  4637.         }
  4638.     }
  4639. #endif /* NOSPL */
  4640.     zvlogout();
  4641.     }
  4642. #endif /* CK_LOGIN */
  4643. #endif /* IKSD */
  4644.  
  4645.     debug(F100,"doexit about to doclean","",0);
  4646.     doclean(1);                         /* Clean up most things */
  4647.  
  4648. #ifdef VMS
  4649.     if (code == -1)
  4650.       code = 0;                         /* Since we set two different items */
  4651.     sprintf(envstr,"%d", exitstat | code); /* SAFE */
  4652.     symval.dsc$w_length = (int)strlen(envstr);
  4653.     symval.dsc$a_pointer = envstr;
  4654.     symval.dsc$b_class = DSC$K_CLASS_S;
  4655.     symval.dsc$b_dtype = DSC$K_DTYPE_T;
  4656.     i = 2;                              /* Store in global table */
  4657. #ifdef COMMENT                          /* Martin Zinser */
  4658.     LIB$SET_SYMBOL(&symnam, &symval, &i);
  4659. #else
  4660.     lib$set_symbol(&symnam, &symval, &i);
  4661. #endif /* COMMENT */
  4662.     if (exitstat == BAD_EXIT)
  4663.       exitstat = SS$_ABORT | STS$M_INHIB_MSG;
  4664.     if (exitstat == GOOD_EXIT)
  4665.       exitstat = SS$_NORMAL | STS$M_INHIB_MSG;
  4666. #else /* Not VMS */
  4667.     if (code != -1)                     /* Take 1st arg literally */
  4668.       exitstat |= code;
  4669. #endif /* VMS */
  4670.  
  4671. #ifdef IKSD
  4672. #ifdef IKSDB
  4673.     debug(F101,"doexit ikdbopen","",ikdbopen);
  4674.     if (ikdbopen && dbfp) {             /* If IKSD database open */
  4675.         int x;
  4676.         x = freeslot(mydbslot);         /* Free our slot... */
  4677.         debug(F101,"doexit freeslot","",x);
  4678.         fclose(dbfp);                   /* and close it. */
  4679.     }
  4680. #endif /* IKSDB */
  4681. #endif /* IKSD */
  4682.  
  4683. /* We have put this off till the very last moment... */
  4684.  
  4685. #ifdef DEBUG
  4686.     if (deblog) {                       /* Close the debug log. */
  4687.         debug(F101,"C-Kermit EXIT status","",exitstat);
  4688.         *debfil = '\0';
  4689.         deblog = 0;
  4690.         zclose(ZDFILE);
  4691.     }
  4692. #endif /* DEBUG */
  4693.  
  4694. #ifdef OS2
  4695.     _exit(exitstat);            /* Exit from C-Kermit (no matter what) */
  4696. #else /* OS2 */
  4697.     exit(exitstat);                     /* Exit from C-Kermit */
  4698. #endif /* OS2 */
  4699. }
  4700.  
  4701. VOID
  4702. bgchk() {                               /* Check background status */
  4703.     if (bgset < 0) {                    /* They didn't type SET BACKGROUND */
  4704. #ifdef VMS                              /* Set prompt flag based on */
  4705.         pflag = !batch;                 /* what we detected at startup. */
  4706. #else
  4707.         pflag = !backgrd;
  4708. #endif /* VMS */
  4709.     } else {                            /* Otherwise SET BACKGROUND value */
  4710.         pflag = (bgset == 0 ? 1 : 0);
  4711.     }
  4712.  
  4713. #ifndef NOICP
  4714.     /* Message flag on only if at top level, pflag is on, and QUIET is OFF */
  4715.     if (!xcmdsrc)
  4716.       msgflg = (pflag == 0) ? 0 : !quiet;
  4717.     else msgflg = 0;
  4718. #else
  4719.     msgflg = 0;
  4720. #endif /* NOICP */
  4721. }
  4722.  
  4723. /* Set console interrupts */
  4724.  
  4725. VOID
  4726. setint() {                              /* According to SET COMMAND INTERRUP */
  4727.     int x = 0;
  4728.     if (cmdint)  x |= 1;
  4729.     if (xsuspend) x |= 2;
  4730.     debug(F101,"setint","",x);
  4731.  
  4732.     switch (x) {                        /* Set the desired combination */
  4733.       case 0: connoi(); break;          /* No interrupts */
  4734.       case 1: conint(trap,SIG_IGN); break;
  4735.       case 2: conint(SIG_IGN,stptrap); break;
  4736.       case 3: conint(trap,stptrap); break;
  4737.     }
  4738.     bgchk();                            /* Check background status */
  4739. }
  4740.  
  4741. #ifdef DEBUG
  4742. /*  D E B U G  --  Enter a record in the debugging log  */
  4743.  
  4744. /*
  4745.  Call with a format, two strings, and a number:
  4746.    f  - Format, a bit string in range 0-7.
  4747.         If bit x is on, then argument number x is printed.
  4748.    s1 - String, argument number 1.  If selected, printed as is.
  4749.    s2 - String, argument number 2.  If selected, printed in brackets.
  4750.    n  - Long int, argument 3.  If selected, printed preceded by equals sign.
  4751.  
  4752.    f=0 is special: print s1,s2, and interpret n as a char.
  4753.  
  4754.    f=F011 (3) is also special; in this case s2 is interpeted as a counted
  4755.    string that might contain NULs.  n is the length.  If n is negative, this
  4756.    means the string has been truncated and ".." should be printed after the
  4757.    first n bytes.  NUL and LF bytes are printed as "<NUL>" and "<LF>".
  4758.  
  4759.    Globals:
  4760.      deblog: nonzero if debug log open.
  4761.      debok:  nonzero if ok to write entries.
  4762. */
  4763. /*
  4764.   WARNING: Don't change DEBUFL without changing sprintf() formats below,
  4765.   accordingly.
  4766. */
  4767. #define DBUFL 4000
  4768. /*
  4769.   WARNING: This routine is not thread-safe, especially when Kermit is
  4770.   executing on multiple CPUs -- as different threads write to the same
  4771.   static buffer, the debug statements are all interleaved.  To be fixed
  4772.   later...
  4773. */
  4774. static char *dbptr = (char *)0;
  4775.  
  4776. int
  4777. #ifdef CK_ANSIC
  4778. dodebug(int f, char *s1, char *s2, long n)
  4779. #else
  4780. dodebug(f,s1,s2,n) int f; char *s1, *s2; long n;
  4781. #endif /* CK_ANSIC */
  4782. /* dodebug */ {
  4783.     char *sp;
  4784.     int len1, len2;
  4785.     extern int debtim;
  4786. #ifdef OS2
  4787.     extern int SysInited;
  4788. #endif /* OS2 */
  4789.  
  4790.     if (!deblog || !debok)
  4791.       return(0);
  4792.  
  4793. #ifdef COMMENT
  4794.     /* expensive... */
  4795.     if (!chkfn(ZDFILE))            /* Debug log not open, don't. */
  4796.       return(0);
  4797. #endif /* COMMENT */
  4798.     if (!dbptr) {                       /* Allocate memory buffer */
  4799.         dbptr = malloc(DBUFL+4);        /* This only happens once */
  4800.         if (!dbptr) {
  4801.             zclose(ZDFILE);
  4802.             return(0);
  4803.         }
  4804.     }
  4805. /*
  4806.   This prevents infinite recursion in case we accidentally put a debug()
  4807.   call in this routine, or call another routine that contains debug() calls.
  4808.   From this point on, all returns from this return must be via goto xdebug,
  4809.   which sets deblog back to 1.
  4810. */
  4811. #ifdef OS2
  4812.     if (SysInited) {
  4813.     if (RequestDebugMutex(30000))
  4814.         goto xdebug;
  4815.     }
  4816. #else /* OS2 */
  4817.     deblog = 0;                         /* Prevent infinite recursion */
  4818. #endif /* OS2 */
  4819.  
  4820.     if (debtim) {                       /* Timestamp */
  4821.         char *tb, tsbuf[48];
  4822.         ztime(&tb);
  4823.         ckstrncpy(tsbuf,tb,32);
  4824.         if (ztmsec > -1L) {
  4825.         sprintf(tsbuf+19,".%03ld ",ztmsec); /* SAFE */
  4826.     } else {
  4827.         tsbuf[19] = ':';
  4828.         tsbuf[20] = SP;
  4829.         tsbuf[21] = NUL;
  4830.     }
  4831.         zsout(ZDFILE,tsbuf+11);
  4832.     }
  4833.     if (!s1) s1="(NULL)";
  4834.     if (!s2) s2="(NULL)";
  4835.  
  4836.     len1 = strlen(s1);
  4837.     len2 = strlen(s2);
  4838.  
  4839. #ifdef COMMENT
  4840. /*
  4841.   This should work, but it doesn't.
  4842.   So instead we'll cope with overflow via sprintf formats.
  4843.   N.B.: UNFORTUNATELY, this means we have to put constants in the
  4844.   sprintf formats.
  4845. */
  4846.     if (f != F011 && (!f || (f & 6))) { /* String argument(s) included? */
  4847.         x = (int) strlen(s1) + (int) strlen(s2) + 18;
  4848.         if (x > dbufl) {                /* Longer than buffer? */
  4849.             if (dbptr)                  /* Yes, free previous buffer */
  4850.               free(dbptr);
  4851.             dbptr = (char *) malloc(x + 2); /* Allocate a new one */
  4852.             if (!dbptr) {
  4853.                 zsoutl(ZDFILE,"DEBUG: Memory allocation failure");
  4854.                 deblog = 0;
  4855.                 zclose(ZDFILE);
  4856.                 goto xdebug;
  4857.             } else {
  4858.                 dbufl = x;
  4859.                 sprintf(dbptr,"DEBUG: Buffer expanded to %d\n", x + 18);
  4860.                 zsoutl(ZDFILE,dbptr);
  4861.             }
  4862.         }
  4863.     }
  4864. #endif /* COMMENT */
  4865.  
  4866. #ifdef COMMENT
  4867. /* The aforementioned sprintf() formats were like this: */
  4868.         if (n > 31 && n < 127)
  4869.           sprintf(sp,"%.100s%.2000s:%c\n",s1,s2,(CHAR) n);
  4870.         else if (n < 32 || n == 127)
  4871.           sprintf(sp,"%.100s%.2000s:^%c\n",s1,s2,(CHAR) ((n+64) & 0x7F));
  4872.         else if (n > 127 && n < 160)
  4873.           sprintf(sp,"%.100s%.2000s:~^%c\n",s1,s2,(CHAR)((n-64) & 0x7F));
  4874.         else if (n > 159 && n < 256)
  4875.           sprintf(sp,"%.100s%.2000s:~%c\n",s1,s2,(CHAR) (n & 0x7F));
  4876.         else sprintf(sp,"%.100s%.2000s:%ld\n",s1,s2,n);
  4877. /*
  4878.   But, naturally, it turns out these are not portable either, so now
  4879.   we do the stupidest possible thing.
  4880. */
  4881. #endif /* COMMENT */
  4882.  
  4883. #ifdef BIGBUFOK
  4884. /* Need to accept longer strings when debugging authenticated connections */
  4885.     if (f == F010) {
  4886.         if (len2 + 2 >= DBUFL) s2 = "(string too long)";
  4887.     } else if (f != F011 && f != F100) {
  4888.         if (len1 > 100) s1 = "(string too long)";
  4889.         if (len2 + 101 >= DBUFL) s2 = "(string too long)";
  4890.     }
  4891. #else
  4892.     if (f != F011) {
  4893.         if (len1 > 100) s1 = "(string too long)";
  4894.         if (len2 + 101 >= DBUFL) s2 = "(string too long)";
  4895.     }
  4896. #endif /* BIGBUFOK */
  4897.  
  4898.     sp = dbptr;
  4899.  
  4900.     switch (f) {                /* Write log record according to format. */
  4901.       case F000:                /* 0 = print both strings, and n as a char. */
  4902.         if (len2 > 0) {
  4903.             if ((n > 31 && n < 127) || (n > 159 && n < 256))
  4904.               sprintf(sp,"%s[%s]=%c\n",s1,s2,(CHAR) n);
  4905.             else if (n < 32 || n == 127)
  4906.               sprintf(sp,"%s[%s]=^%c\n",s1,s2,(CHAR) ((n+64) & 0x7F));
  4907.             else if (n > 127 && n < 160)
  4908.               sprintf(sp,"%s[%s]=~^%c\n",s1,s2,(CHAR)((n-64) & 0x7F));
  4909.             else sprintf(sp,"%s[%s]=0x%lX\n",s1,s2,n);
  4910.         } else {
  4911.             if ((n > 31 && n < 127) || (n > 159 && n < 256))
  4912.               sprintf(sp,"%s=%c\n",s1,(CHAR) n);
  4913.             else if (n < 32 || n == 127)
  4914.               sprintf(sp,"%s=^%c\n",s1,(CHAR) ((n+64) & 0x7F));
  4915.             else if (n > 127 && n < 160)
  4916.               sprintf(sp,"%s=~^%c\n",s1,(CHAR)((n-64) & 0x7F));
  4917.             else sprintf(sp,"%s=0x%lX\n",s1,n);
  4918.         }
  4919.         if (zsout(ZDFILE,dbptr) < 0) {
  4920.             deblog = 0;
  4921.             zclose(ZDFILE);
  4922.         }
  4923. #ifdef CKSYSLOG
  4924.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  4925.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  4926.         }
  4927. #endif /* CKSYSLOG */
  4928.         break;
  4929.  
  4930.       case F001:                        /* 1, "=n" */
  4931. #ifdef COMMENT
  4932.         /* This was never used */
  4933.         sprintf(sp,"=%ld\n",n);
  4934. #else
  4935.         /* Like F111, but shows number n in hex */
  4936.     ckmakxmsg(sp,DBUFL,
  4937.           s1,
  4938.           (*s1 ? ":" : ""),
  4939.           s2,
  4940.           (*s2 ? ":" : ""),
  4941.           ckltox(n),
  4942.           "\n",
  4943.           NULL,NULL,NULL,NULL,NULL,NULL
  4944.           );
  4945. #endif /* COMMENT */
  4946.         if (zsout(ZDFILE,dbptr) < 0) {
  4947.             deblog = 0;
  4948.             zclose(ZDFILE);
  4949.         }
  4950. #ifdef CKSYSLOG
  4951.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  4952.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  4953.         }
  4954. #endif /* CKSYSLOG */
  4955.         break;
  4956.  
  4957. /*
  4958.   This one was never used so (October 2000) we now use it like F011,
  4959.   except in this case we treat s2 as NUL terminated.
  4960. */
  4961.       case F010:
  4962.     n = -debxlen;
  4963. /*
  4964.   This one treats n as the length of the string s2, which may contain NULs.
  4965.   It's good for logging NUL-bearing data in the debug log.
  4966. */
  4967.       case F011: {
  4968.       int i, j, contd = 0;
  4969.       char * p = s2, *pbuf = NULL;    /* p = source pointer */
  4970.       int m;            /* pbuf = destination pointer */
  4971.  
  4972.       if (f == F011) {
  4973.           if (n < 0) {        /* n = size of source */
  4974.           n = 0 - n;        /* Negative means to add "..." */
  4975.           contd = 1;
  4976.           }
  4977.       } else {
  4978.           int x, flag = 0;
  4979.           x = strlen(s2);
  4980.           if (n < 0) {
  4981.           flag = 1;
  4982.           n = 0 - n;
  4983.           }
  4984.           if (x < n)
  4985.         n = x;
  4986.       }
  4987.       if (n == 0)            /* 0 means do nothing */
  4988.         goto xdebug;
  4989.       m = DBUFL - 8;        /* Get size for interpreted part */
  4990.       if (n > m)            /* Ensure requested size not too big */
  4991.         n = m;
  4992.       pbuf = dbptr;            /* Construction pointer */
  4993.       i = 0;
  4994.       pbuf[i++] = '[';        /* Interpret the string into it */
  4995.       for (j = 0; j < n && i < m-4; p++,j++) { /* char by char... */
  4996.           if (*p == LF) {
  4997.           if (i >= m-4)
  4998.             break;
  4999.           pbuf[i++] = '<';
  5000.           pbuf[i++] = 'L';
  5001.           pbuf[i++] = 'F';
  5002.           pbuf[i++] = '>';
  5003.           continue;
  5004.           } else if (*p == CR) {
  5005.           if (i >= m-4)
  5006.             break;
  5007.           pbuf[i++] = '<';
  5008.           pbuf[i++] = 'C';
  5009.           pbuf[i++] = 'R';
  5010.           pbuf[i++] = '>';
  5011.           continue;
  5012.           } else if (*p == HT) {
  5013.           if (i >= m-5)
  5014.             break;
  5015.           pbuf[i++] = '<';
  5016.           pbuf[i++] = 'T';
  5017.           pbuf[i++] = 'A';
  5018.           pbuf[i++] = 'B';
  5019.           pbuf[i++] = '>';
  5020.           continue;
  5021.           } else if (*p) {
  5022.           pbuf[i++] = *p;
  5023.           continue;
  5024.           } else {
  5025.           if (i >= m-5)
  5026.             break;
  5027.           pbuf[i++] = '<';
  5028.           pbuf[i++] = 'N';
  5029.           pbuf[i++] = 'U';
  5030.           pbuf[i++] = 'L';
  5031.           pbuf[i++] = '>';
  5032.           continue;
  5033.           }
  5034.       }
  5035.       if (i < m-2 && (*p || contd)) {
  5036.           pbuf[i++] = '.';
  5037.           pbuf[i++] = '.';
  5038.       }
  5039.       pbuf[i++] = ']';
  5040.       pbuf[i] = NUL;
  5041.       if (zsout(ZDFILE,s1) < 0) {
  5042.           deblog = 0;
  5043.           zclose(ZDFILE);
  5044.       }
  5045.       if (zsoutl(ZDFILE,pbuf) < 0) {
  5046.           deblog = 0;
  5047.           zclose(ZDFILE);
  5048.       }
  5049. #ifdef CKSYSLOG
  5050.       if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5051.           cksyslog(SYSLG_DB,1,"debug",s1,pbuf);
  5052.       }
  5053. #endif /* CKSYSLOG */
  5054.         }
  5055.         break;
  5056.  
  5057.       case F100:                        /* 4, "s1" */
  5058.         if (zsoutl(ZDFILE,s1) < 0) {
  5059.             deblog = 0;
  5060.             zclose(ZDFILE);
  5061.         }
  5062. #ifdef CKSYSLOG
  5063.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5064.             cksyslog(SYSLG_DB,1,"debug",s1,NULL);
  5065.         }
  5066. #endif /* CKSYSLOG */
  5067.         break;
  5068.       case F101:                        /* 5, "s1=n" */
  5069.         sprintf(sp,"%s=%ld\n",s1,n);
  5070.         if (zsout(ZDFILE,dbptr) < 0) {
  5071.             deblog = 0;
  5072.             zclose(ZDFILE);
  5073.         }
  5074. #ifdef CKSYSLOG
  5075.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5076.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5077.         }
  5078. #endif /* CKSYSLOG */
  5079.         break;
  5080.       case F110:                        /* 6, "s1[s2]" */
  5081.         sprintf(sp,"%s[%s]\n",s1,s2);
  5082.         if (zsout(ZDFILE,dbptr) < 0) {
  5083.             deblog = 0;
  5084.             zclose(ZDFILE);
  5085.         }
  5086. #ifdef CKSYSLOG
  5087.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5088.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5089.         }
  5090. #endif /* CKSYSLOG */
  5091.         break;
  5092.       case F111:                        /* 7, "s1[s2]=n" */
  5093.         sprintf(sp,"%s[%s]=%ld\n",s1,s2,n);
  5094.         if (zsout(ZDFILE,dbptr) < 0) {
  5095.             deblog = 0;
  5096.             zclose(ZDFILE);
  5097.         }
  5098. #ifdef CKSYSLOG
  5099.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5100.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5101.         }
  5102. #endif /* CKSYSLOG */
  5103.         break;
  5104.       default:
  5105.         sprintf(sp,"\n?Invalid format for debug() - %d\n",f);
  5106.         if (zsout(ZDFILE,dbptr) < 0) {
  5107.             deblog = 0;
  5108.             zclose(ZDFILE);
  5109.         }
  5110. #ifdef CKSYSLOG
  5111.         if (ckxsyslog >= SYSLG_DB && ckxlogging) {
  5112.             cksyslog(SYSLG_DB,1,"debug",dbptr,NULL);
  5113.         }
  5114. #endif /* CKSYSLOG */
  5115.         break;
  5116.     }
  5117.   xdebug:                               /* Common exit point */
  5118. #ifdef OS2
  5119.     if (SysInited)
  5120.     ReleaseDebugMutex();
  5121. #else /* OS2 */
  5122.     deblog = 1;                         /* Restore this */
  5123. #endif /* OS2 */
  5124.     return(0);
  5125. }
  5126.  
  5127. int
  5128. #ifdef CK_ANSIC
  5129. dohexdump(CHAR *msg, CHAR *st, int cnt)
  5130. #else
  5131. dohexdump(msg,st,cnt) CHAR *msg; CHAR *st; int cnt;
  5132. #endif /* CK_ANSIC */
  5133. /* dohexdump */ {
  5134.     int i = 0, j = 0, k = 0;
  5135.     char tmp[8];
  5136. #ifdef OS2
  5137.     extern int SysInited;
  5138. #endif /* OS2 */
  5139.  
  5140.     if (!deblog) return(0);        /* If no debug log, don't. */
  5141.     if (!dbptr) {                       /* Allocate memory buffer */
  5142.         dbptr = malloc(DBUFL+1);        /* This only happens once */
  5143.         if (!dbptr) {
  5144.             deblog = 0;
  5145.             zclose(ZDFILE);
  5146.             return(0);
  5147.         }
  5148.     }
  5149.  
  5150. #ifdef OS2
  5151.     if (SysInited) {
  5152.     if (RequestDebugMutex(30000))
  5153.         goto xdebug;
  5154.     }
  5155. #else /* OS2 */
  5156.     deblog = 0;                         /* Prevent infinite recursion */
  5157. #endif /* OS2 */
  5158.  
  5159.     if (msg != NULL) {
  5160.     ckmakxmsg(dbptr,
  5161.           DBUFL,
  5162.           "HEXDUMP: ",
  5163.           (char *)msg,
  5164.           " (",
  5165.           ckitoa(cnt),
  5166.           " bytes)\n",
  5167.           NULL,NULL,NULL,NULL,NULL,NULL,NULL
  5168.          );
  5169.         if (zsout(ZDFILE,dbptr) < 0) {
  5170.             deblog = 0;
  5171.             zclose(ZDFILE);
  5172.         goto xdebug;
  5173.         }
  5174.     } else {
  5175.     ckmakmsg(dbptr,
  5176.          DBUFL,
  5177.          "HEXDUMP: (",
  5178.          ckitoa(cnt),
  5179.          " bytes)\n",
  5180.          NULL
  5181.          );
  5182.         zsout(ZDFILE,dbptr);
  5183.         if (zsout(ZDFILE,dbptr) < 0) {
  5184.             deblog = 0;
  5185.             zclose(ZDFILE);
  5186.         goto xdebug;
  5187.         }
  5188.     }
  5189.     for (i = 0; i < cnt; i++) {
  5190.         dbptr[0] = '\0';
  5191.         for (j = 0 ; (j < 16); j++) {
  5192.             if ((i + j) < cnt)
  5193.           sprintf(tmp,
  5194.               "%s%02x ",
  5195.               (j == 8 ? "| " : ""),
  5196.               (CHAR) st[i + j]
  5197.               );
  5198.             else
  5199.           sprintf(tmp,
  5200.               "%s   ",
  5201.               (j == 8 ? "| " : "")
  5202.               );
  5203.             ckstrncat(dbptr,tmp,DBUFL+1);
  5204.         }
  5205.         ckstrncat(dbptr," ",DBUFL+1);
  5206.         for (k = 0; (k < 16) && ((i + k) < cnt); k++) {
  5207.             sprintf(tmp,
  5208.                     "%s%c",
  5209.                     (k == 8 ? " " : ""),
  5210.                     isprint(st[i + k]) ? st[i + k] : '.'
  5211.                     );
  5212.             ckstrncat(dbptr,tmp,DBUFL+1);
  5213.         }
  5214.         ckstrncat(dbptr,"\n",DBUFL+1);
  5215.         i += j - 1;
  5216.         if (zsout(ZDFILE,dbptr) < 0) {
  5217.             deblog = 0;
  5218.             zclose(ZDFILE);
  5219.         goto xdebug;
  5220.         }
  5221.     } /* end for */
  5222.  
  5223.  
  5224.   xdebug:
  5225. #ifdef OS2
  5226.     if (SysInited)
  5227.       ReleaseDebugMutex();
  5228. #else /* OS2 */
  5229.     deblog = 1;
  5230. #endif /* OS2 */
  5231.     return(0);
  5232. }
  5233. #endif /* DEBUG */
  5234.  
  5235. /*  Session Log... */
  5236.  
  5237. extern int slogts;            /* Session Log timestamps */
  5238. int tsstate = 0;
  5239.  
  5240. VOID
  5241. #ifdef OS2
  5242. logchar(unsigned short c)
  5243. #else /* OS2 */
  5244. #ifdef CK_ANSIC
  5245. logchar(char c)
  5246. #else
  5247. logchar(c) char c;
  5248. #endif /* CK_ANSIC */
  5249. #endif /* OS2 */
  5250. /* logchar */ {                         /* Log character c to session log */
  5251.     int oktolog = 0;
  5252. #ifndef NOLOCAL
  5253.     if (!seslog)
  5254.       return;
  5255.  
  5256.     if ((sessft != XYFT_T) ||
  5257.     (c != '\0' &&
  5258. #ifdef UNIX
  5259.      c != '\r' &&
  5260. #else
  5261. #ifdef datageneral
  5262.      c != '\r' &&
  5263. #else
  5264. #ifdef STRATUS
  5265.      c != '\r' &&
  5266. #else
  5267. #ifdef AMIGA
  5268.      c != '\r' &&
  5269. #else
  5270. #ifdef GEMDOS
  5271.      c != '\r' &&
  5272. #endif /* GEMDOS */
  5273. #endif /* AMIGA */
  5274. #endif /* STRATUS */
  5275. #endif /* datageneral */
  5276. #endif /* UNIX */
  5277. #ifdef OSK
  5278.      c != '\n' &&
  5279. #else
  5280. #ifdef MAC
  5281.      c != '\n' &&
  5282. #endif /* MAC */
  5283. #endif /* OSK */
  5284.      c != XON &&
  5285.      c != XOFF))
  5286.       oktolog = 1;
  5287.     if (!oktolog)
  5288.       return;
  5289.     if (slogts) {            /* Log is timestamped */
  5290.     if (tsstate == 0) {        /* State = between-lines */
  5291.         char * p;            /* zstime() pointer */
  5292.         char ts[48];        /* timestamp buffer */
  5293.         ztime(&p);            /* Get asctime() string */
  5294.         ckstrncpy(ts,p,32);        /* Make safe copy */
  5295.         if (ztmsec > -1L) {        /* Add msecs if we have them */
  5296.         sprintf(&ts[19],".%03ld: ",ztmsec); /* SAFE */
  5297.         } else {
  5298.         ts[19] = ':';
  5299.         ts[20] = SP;
  5300.         ts[21] = NUL;
  5301.         }
  5302.         if (zsout(ZSFILE,&ts[11]) < 0)
  5303.           goto xlogchar;
  5304.         if (c != '\n')        /* If this is not eol */
  5305.           tsstate = 1;        /* go to in-a-line state. */
  5306.     } else if (c == '\n') {        /* In a line */
  5307.         tsstate = 0;        /* If eol go to between-lines state. */
  5308.     }
  5309.     }
  5310.     if (zchout(ZSFILE,(CHAR)(c & 0xFF)) < 0) /* Log the character */
  5311.       goto xlogchar;
  5312.     return;
  5313.  
  5314.   xlogchar:
  5315.     conoll("");
  5316.     conoll("ERROR WRITING SESSION LOG, LOG CLOSED!");
  5317.     setseslog(0);
  5318.     zclose(ZSFILE);
  5319. #endif /* NOLOCAL */
  5320. }
  5321.  
  5322. VOID
  5323. logstr(s, len) char * s; int len; {     /* Log string to session log */
  5324. #ifndef NOLOCAL
  5325.     int n = 0;
  5326.     if (!s)
  5327.       return;
  5328.     while (seslog && (n < len))
  5329.       logchar(s[n++]);
  5330. #endif /* NOLOCAL */
  5331. }
  5332.  
  5333. #ifdef CK_CURSES
  5334. int
  5335. ck_repaint() {
  5336.     repaint = 1;
  5337.     return(0);
  5338. }
  5339.  
  5340. #ifdef STRATUS
  5341. /* VOS has curses but no tgetent() */
  5342. int
  5343. tgetent(s1, s2) char * s1, * s2; {
  5344.     return(1);
  5345. }
  5346. #endif /* STRATUS */
  5347.  
  5348. #ifdef VMS
  5349. #ifdef __DECC
  5350. _PROTOTYP(int tgetent,(char *, char *));
  5351. #endif /* __DECC */
  5352. #endif /* VMS */
  5353.  
  5354. /*
  5355.   There are three different ways to do fullscreen on VMS.
  5356.   1. Use the real curses library, VAXCCURSE.
  5357.   2. Use do-it-yourself code.
  5358.   3. Use the Screen Manager, SMG$.
  5359.  
  5360.   Method 1 doesn't work quite right; you can't call endwin(), so once you've
  5361.   started curses mode, you can never leave.
  5362.  
  5363.   Method 2 doesn't optimize the screen, and so much more time is spent in
  5364.   screen writes.  This actually causes file transfers to fail because the
  5365.   tty device input buffer can be overrun while the screen is being updated,
  5366.   especially on a slow MicroVAX that has small typeahead buffers.
  5367.  
  5368.   In the following #ifdef block, #define one of them and #undef the other 2.
  5369.  
  5370.   So now let's try method 3...
  5371. */
  5372. #ifdef VMS
  5373. #define CK_SMG                          /* Screen Manager */
  5374. #undef MYCURSES                         /* Do-it-yourself */
  5375. #undef VMSCURSE                         /* VAXCCURSE library */
  5376. #endif /* VMS */
  5377. /*
  5378.   But just before New Years, 2000, the SMG library seemed to break on
  5379.   both VMS systems we have here (an Alpha with VMS 7.1 and a VAX with 5.5).
  5380.   So back to MYCURSES, which works fine.
  5381. */
  5382. #ifdef VMS
  5383. #undef CK_SMG
  5384. #define MYCURSES
  5385. #endif /* VMS */
  5386.  
  5387. #ifdef MYCURSES
  5388. #define stdscr 0
  5389. #ifdef CK_WREFRESH
  5390. #undef CK_WREFRESH
  5391. #endif /* CK_WREFRESH */
  5392. #endif /* MYCURSES */
  5393.  
  5394. /*  S C R E E N C  --  Screen display function, uses curses  */
  5395.  
  5396. /* Idea for curses display contributed by Chris Pratt of APV Baker, UK */
  5397.  
  5398. /* Avoid conficts with curses.h */
  5399.  
  5400. #ifdef QNX
  5401. /* Same as ckcasc.h, but in a different radix... */
  5402. #ifdef ESC
  5403. #undef ESC
  5404. #endif /* ESC */
  5405. #endif /* QNX */
  5406.  
  5407. #ifndef MYCURSES
  5408. #undef VOID                             /* This was defined in ckcdeb.h */
  5409. #endif /* MYCURSES */
  5410.  
  5411. #undef BS                               /* These were defined in ckcasc.h */
  5412. #undef CR
  5413. #undef NL
  5414. #undef SO
  5415. #undef US
  5416. #undef SP                               /* Used in ncurses */
  5417. #define CHR_SP 32                       /* Use this instead */
  5418.  
  5419. #ifdef VMS                              /* VMS fullscreen display */
  5420. #ifdef MYCURSES                         /* Do-it-yourself method */
  5421. extern int isvt52;                      /* From CKVTIO.C */
  5422. #define printw printf
  5423. #else
  5424. #ifdef VMSCURSE                         /* VMS curses library VAXCCURSE */
  5425. #include <curses.h>
  5426. /* Note: Screen manager doesn't need a header file */
  5427. #endif /* VMSCURSE */
  5428. #endif /* MYCURSES */
  5429. #else                                   /* Not VMS */
  5430. #ifdef MYCURSES                         /* Do-it-yourself method */
  5431. #define isvt52 0                        /* Used by OS/2, VT-100/ANSI always */
  5432. #ifdef CKXPRINTF
  5433. #define printw ckxprintf
  5434. #else /* CKXPRINTF */
  5435. #ifdef KUI
  5436. #define printw Vscrnprintw
  5437. #else /* KUI */
  5438. #define printw printf
  5439. #endif /* KUI */
  5440. #endif /* CKXPRINTF */
  5441. #else                                   /* Use real curses */
  5442. #ifdef CK_NCURSES                       /* or ncurses... */
  5443. #ifdef CKXPRINTF                        /* Our printf macro conflicts with */
  5444. #undef printf                           /* use of "printf" in ncurses.h */
  5445. #endif /* CKXPRINTF */
  5446. #include <ncurses.h>
  5447. #ifdef CKXPRINTF
  5448. #define printf ckxprintf
  5449. #endif /* CKXPRINTF */
  5450. #else  /* Not ncurses */
  5451. #ifdef CKXPRINTF                        /* Our printf macro conflicts with */
  5452. #undef printf                           /* use of "printf" in curses.h */
  5453. #endif /* CKXPRINTF */
  5454. #ifdef M_XENIX                /* SCO XENIX... */
  5455. #ifdef M_TERMCAP
  5456. #undef M_TERMCAP
  5457. #endif /* M_TERMCAP */
  5458. #ifndef M_TERMINFO
  5459. #define M_TERMINFO
  5460. #endif /* M_TERMINFO */
  5461. #endif /* M_XENIX */
  5462. #ifdef RTAIX
  5463. #undef NLS                /* Avoid 'redeclaration of free'. */
  5464. #endif /* RTAIX */
  5465. #include <curses.h>
  5466. #ifdef CKXPRINTF
  5467. #define printf ckxprintf
  5468. #endif /* CKXPRINTF */
  5469. #endif /* CK_NCURSES */
  5470. #endif /* MYCURSES */
  5471. #endif /* VMS */
  5472.  
  5473. #endif /* CK_CURSES */
  5474.  
  5475. /*  F X D I N I T  --  File Xfer Display Initialization  */
  5476.  
  5477. #ifdef CK_CURSES
  5478. #ifndef MYCURSES
  5479. #ifndef CK_SMG
  5480. static
  5481. #ifdef CK_ANSIC
  5482. /* Can't use VOID because of curses.h */
  5483. void
  5484. ck_termset(int);
  5485. #else
  5486. ck_termset();
  5487. #endif /* CK_ANSIC */
  5488. #endif /* CK_SMG */
  5489. #endif /* MYCURSES */
  5490. #endif /* CK_CURSES */
  5491.  
  5492. #ifdef NOTERMCAP
  5493. static int notermcap = 1;
  5494. #else
  5495. static int notermcap = 0;
  5496. #endif /* NOTERMCAP */
  5497.  
  5498. #ifndef NODISPLAY
  5499. #ifdef OSK
  5500. VOID
  5501. #else
  5502. #ifdef CK_ANSIC
  5503. void
  5504. #endif /* CKANSIC */
  5505. #endif /* OSK */
  5506. fxdinit(xdispla) int xdispla; {
  5507. #ifndef COHERENT
  5508. #ifndef OS2
  5509. #ifndef STRATUS
  5510.     char *s;
  5511.     int x, dummy;
  5512.  
  5513.     debug(F101,"fxdinit xdispla","",xdispla);
  5514.     debug(F101,"fxdinit fxd_inited","",fxd_inited);
  5515.  
  5516. #ifdef IKSD
  5517. #ifndef NOXFER
  5518.     /* No curses for IKSD */
  5519.     if (inserver) {
  5520.         fdispla = XYFD_N;
  5521.         return;
  5522.     }
  5523.     if (fxd_inited)                     /* Only do this once */
  5524.       return;
  5525. #endif /* NOXFER */
  5526. #endif /* IKSD */
  5527.  
  5528.     if (xdispla == XYFD_R || xdispla == XYFD_S || xdispla == XYFD_B) {
  5529.     if (xfrmsg) {
  5530.         printf("%s\n",xfrmsg);
  5531.         makestr(&xfrmsg,NULL);
  5532.     }
  5533.     }
  5534.  
  5535. #ifdef CK_CURSES
  5536. #ifdef VMS
  5537.     /* Force BRIEF in Batch logs */
  5538.     if (batch && (xdispla == XYFD_C || xdispla == XYFD_S))
  5539.       xdispla = XYFD_B;
  5540. #else
  5541.     if (xdispla == XYFD_C || xdispla == 9999) {
  5542.  
  5543. #ifdef DYNAMIC
  5544.         if (!trmbuf) {
  5545. /*
  5546.   Allocate tgetent() buffer.  Make it big -- some termcaps can be huge;
  5547.   tgetent() merrily writes past the end of the buffer, causing core dumps
  5548.   or worse.
  5549. */
  5550.             trmbuf = (char *)malloc(TRMBUFL);
  5551.             if (!trmbuf) {
  5552.                 notermcap = 1;
  5553.                 debug(F101,"fxdinit malloc trmbuf","FAILED",TRMBUFL);
  5554.                 fdispla = XYFD_S;
  5555.                 return;
  5556.             }
  5557.             debug(F111,"fxdinit malloc trmbuf","OK",TRMBUFL);
  5558.             debug(F001,"fxdinit trmbuf","",trmbuf);
  5559. #ifdef COMMENT
  5560.             memset(trmbuf,'\0',(size_t)TRMBUFL);
  5561.             debug(F100,"fxdinit memset OK","",0);
  5562. #endif /* COMMENT */
  5563.         }
  5564. #endif /* DYNAMIC */
  5565.  
  5566.         debug(F100,"fxdinit before getenv(TERM)","",0);
  5567.         s = getenv("TERM");
  5568.         debug(F110,"fxdinit after getenv(TERM)",s,0);
  5569.         if (!s) s = "";
  5570.         if (*s) {
  5571.             debug(F110,"fxdinit before tgetent()",s,0);
  5572.             x = tgetent(trmbuf,s);
  5573.             debug(F111,"fxdinit tgetent",s,x);
  5574.         } else {
  5575.             x = 0;
  5576.             notermcap = 1;
  5577.             debug(F110,"fxdinit TERM null - no tgetent",s,0);
  5578.         }
  5579.         if (x < 1 && !quiet && !backgrd
  5580. #ifdef VMS
  5581.             && !batch
  5582. #endif /* VMS */
  5583.             ) {
  5584.             printf("Warning: terminal type unknown: \"%s\"\n",s);
  5585.             printf("SCREEN command will use ANSI sequences.\n");
  5586.             if (local)
  5587.               printf("Fullscreen file transfer display disabled.\n");
  5588.             fdispla = XYFD_S;
  5589.         }
  5590. #ifndef MYCURSES
  5591. #ifndef CK_SMG
  5592.         ck_termset(x);
  5593. #endif /* CK_SMG */
  5594. #endif /* MYCURSES */
  5595.         fxd_inited = 1;
  5596.     }
  5597. #endif /* CK_CURSES */
  5598. #endif /* VMS */
  5599. #endif /* STRATUS */
  5600. #endif /* OS2 */
  5601. #endif /* COHERENT */
  5602. }
  5603. #endif /* NODISPLAY */
  5604.  
  5605. #ifdef CK_CURSES
  5606. #ifdef CK_SMG
  5607. /*
  5608.   Long section for Screen Manager starts here...
  5609.   By William Bader.
  5610. */
  5611. #include "ckvvms.h"
  5612. #ifdef OLD_VMS
  5613. #include <smgdef.h>                     /* use this on VAX C 2.4 */
  5614. /* #include <smgmsg.h> */
  5615. #else
  5616. #include <smg$routines.h>               /* Martin Zinser */
  5617. #endif /* OLD_VMS */
  5618.  
  5619. extern unsigned int vms_status;     /* Used for system service return status */
  5620.  
  5621. static long smg_pasteboard_id = -1;     /* pasteboard identifier */
  5622. static long smg_display_id = -1;        /* display identifier */
  5623. static int smg_open = 0;                /* flag if smg current open */
  5624. static int smg_inited = 0;              /* flag if smg initialized */
  5625.  
  5626. #ifdef COMMENT
  5627. #define clrtoeol()      SMG$ERASE_LINE(&smg_display_id, 0, 0)
  5628.  
  5629. #define clear()         SMG$ERASE_DISPLAY(&smg_display_id, 0, 0, 0, 0)
  5630.  
  5631. #define touchwin(scr)   SMG$REPAINT_SCREEN(&smg_pasteboard_id)
  5632.  
  5633. #else  /* Not COMMENT */
  5634.  
  5635. #define clrtoeol()      smg$erase_line(&smg_display_id, 0, 0)
  5636.  
  5637. #define clear()         smg$erase_display(&smg_display_id, 0, 0, 0, 0)
  5638.  
  5639. #define touchwin(scr)   smg$repaint_screen(&smg_pasteboard_id)
  5640. #endif /* COMMENT */
  5641.  
  5642. #define clearok(curscr,ok)              /* Let wrefresh() do the work */
  5643.  
  5644. #define wrefresh(cursrc) touchwin(scr)
  5645.  
  5646. static void
  5647. move(row, col) int row, col; {
  5648.     /* Change from 0-based for curses to 1-based for SMG */
  5649.     if (!smg_open)
  5650.       return;
  5651.     ++row; ++col;
  5652.     debug(F111,"VMS smg move",ckitoa(row),col);
  5653. #ifdef COMMENT                          /* Martin Zinser */
  5654.     CHECK_ERR("move: smg$set_cursor_abs",
  5655.               SMG$SET_CURSOR_ABS(&smg_display_id, &row, &col));
  5656. #else
  5657.     CHECK_ERR("move: smg$set_cursor_abs",
  5658.               smg$set_cursor_abs(&smg_display_id, &row, &col));
  5659. #endif /* COMMENT */
  5660.     debug(F101,"VMS smg move vms_status","",vms_status);
  5661. }
  5662.  
  5663. #ifdef VMS_V40
  5664. #define OLD_VMS
  5665. #endif /* VMS_V40 */
  5666. #ifdef VMS_V42
  5667. #define OLD_VMS
  5668. #endif /* VMS_V42 */
  5669. #ifdef VMS_V44
  5670. #define OLD_VMS
  5671. #endif /* VMS_V44 */
  5672.  
  5673. static int
  5674. initscr() {
  5675.     int rows = 24, cols = 80;
  5676.     int row = 1, col = 1;
  5677.  
  5678.     debug(F101,"VMS initscr smg_pasteboard_id A","",smg_pasteboard_id);
  5679.  
  5680.     if (smg_pasteboard_id == -1) { /* Open the screen */
  5681. #ifdef OLD_VMS                     /* Note: Routine calls lowercased 9/96 */
  5682.         CHECK_ERR("initscr: smg$create_pasteboard",
  5683.                   smg$create_pasteboard(&smg_pasteboard_id, 0, 0, 0, 0));
  5684. #else
  5685.         /* For VMS V5, not tested */
  5686.         CHECK_ERR("initscr: smg$create_pasteboard",
  5687.                   smg$create_pasteboard(&smg_pasteboard_id, 0, 0, 0, 0, 0));
  5688. #endif /* OLD_VMS */
  5689.     }
  5690.     debug(F101,"VMS initscr smg_pasteboard_id B","",smg_pasteboard_id);
  5691.     if (smg_pasteboard_id == -1) {
  5692.     printf("?Error initializing fullscreen display\n");
  5693.     fdispla = XYFD_S;
  5694.     dpyinit();
  5695.     return(0);
  5696.     }
  5697.     debug(F101,"VMS initscr smg_display_id","",smg_display_id);
  5698.     if (smg_display_id == -1) {         /* Create a display window */
  5699.  
  5700. #ifdef COMMENT                          /* Martin Zinser */
  5701.         CHECK_ERR("initscr: smg$create_virtual_display",
  5702.                   SMG$CREATE_VIRTUAL_DISPLAY(&rows, &cols, &smg_display_id,
  5703.                                              0, 0, 0));
  5704.  
  5705.         /* Connect the display window to the screen */
  5706.         CHECK_ERR("initscr: smg$paste_virtual_display",
  5707.                   SMG$PASTE_VIRTUAL_DISPLAY(&smg_display_id,&smg_pasteboard_id,
  5708.                                             &row,&col));
  5709. #else
  5710.         CHECK_ERR("initscr: smg$create_virtual_display",
  5711.                   smg$create_virtual_display(&rows, &cols, &smg_display_id,
  5712.                                              0, 0, 0));
  5713.  
  5714.         /* Connect the display window to the screen */
  5715.         CHECK_ERR("initscr: smg$paste_virtual_display",
  5716.                   smg$paste_virtual_display(&smg_display_id,&smg_pasteboard_id,
  5717.                                             &row,&col));
  5718. #endif /* COMMENT */
  5719.     }
  5720.     debug(F101,"VMS initscr smg_open A","",smg_open);
  5721.     if (!smg_open) {                    /* Start a batch update */
  5722.         smg_open = 1;
  5723. #ifdef COMMENT
  5724.         CHECK_ERR("initscr: smg$begin_pasteboard_update",
  5725.                   SMG$BEGIN_PASTEBOARD_UPDATE(&smg_pasteboard_id));
  5726. #else
  5727.         CHECK_ERR("initscr: smg$begin_pasteboard_update",
  5728.                   smg$begin_pasteboard_update(&smg_pasteboard_id));
  5729. #endif /* COMMENT */
  5730.     debug(F101,"VMS initscr smg$begin_pasteboard_update","",vms_status);
  5731.     }
  5732.     debug(F101,"VMS initscr smg_open B","",smg_open);
  5733.     smg_inited = 1;
  5734.     return(1);
  5735. }
  5736.  
  5737. static void
  5738. refresh() {
  5739.     debug(F101,"refresh smg_pasteboard_id","",smg_pasteboard_id);
  5740.  
  5741.     if (smg_open == 0 || smg_pasteboard_id == -1)
  5742.       return;
  5743.  
  5744. #ifdef COMMENT                          /* Martin Zinser */
  5745.     CHECK_ERR("refresh: smg$end_pasteboard_update",
  5746.               SMG$END_PASTEBOARD_UPDATE(&smg_pasteboard_id));
  5747.     CHECK_ERR("refresh: smg$begin_pasteboard_update",
  5748.               SMG$BEGIN_PASTEBOARD_UPDATE(&smg_pasteboard_id));
  5749. #else
  5750.     CHECK_ERR("refresh: smg$end_pasteboard_update",
  5751.               smg$end_pasteboard_update(&smg_pasteboard_id));
  5752.     CHECK_ERR("refresh: smg$begin_pasteboard_update",
  5753.               smg$begin_pasteboard_update(&smg_pasteboard_id));
  5754. #endif /* COMMENT */
  5755. }
  5756.  
  5757. static void
  5758. endwin() {
  5759.     if (!smg_open)
  5760.       return;
  5761.  
  5762.     smg_open = 0;
  5763.  
  5764. #ifdef COMMENT
  5765.     CHECK_ERR("endwin: smg$end_pasteboard_update",
  5766.               SMG$END_PASTEBOARD_UPDATE(&smg_pasteboard_id));
  5767. #else
  5768.     CHECK_ERR("endwin: smg$end_pasteboard_update",
  5769.               smg$end_pasteboard_update(&smg_pasteboard_id));
  5770. #endif /* COMMENT */
  5771.  
  5772.     move(22, 0);
  5773.  
  5774. #ifdef COMMENT
  5775. /*
  5776.   These calls clear the screen.
  5777.   (convert routine calls to lowercase - Martin Zinser)
  5778. */
  5779.     CHECK_ERR("endwin: smg$delete_virtual_display",
  5780.               SMG$DELETE_VIRTUAL_DISPLAY(&smg_display_id));
  5781.     smg_display_id = -1;
  5782.  
  5783.     CHECK_ERR("endwin: smg$delete_pasteboard",
  5784.               SMG$DELETE_PASTEBOARD(&smg_pasteboard_id, 0));
  5785.     smg_pasteboard_id = -1;
  5786. #endif /* COMMENT */
  5787. }
  5788.  
  5789. #ifdef COMMENT
  5790. /* DECC 6.2 screams bloody murder about printw ("not enough args") */
  5791. /* but adding the following prototype only makes it holler louder. */
  5792. #ifdef __DECC
  5793. /* "varargs" prototype for printw */
  5794. _PROTOTYP(static int printw,(char *, ...));
  5795. #endif /* __DECC */
  5796. #endif /* COMMENT */
  5797.  
  5798. #ifdef __DECC
  5799. #include <stdarg.h>
  5800. _PROTOTYP(static void printw,(char *, ...));
  5801. static void
  5802. printw(char *str,...) {
  5803.     char buf[255];
  5804.     va_list ap;
  5805.     $DESCRIPTOR(text_dsc, 0);
  5806.     text_dsc.dsc$a_pointer=buf;
  5807.     if (!smg_open)
  5808.       return;
  5809.     va_start(ap,str);
  5810.     text_dsc.dsc$w_length = vsprintf(buf, str, ap);
  5811.     va_end(ap);
  5812.     CHECK_ERR("printw: smg$put_chars",
  5813.               smg$put_chars(&smg_display_id, &text_dsc, 0, 0, 0, 0, 0));
  5814. }
  5815. #else
  5816. static void
  5817. printw(str, a1, a2, a3, a4, a5, a6, a7, a8)
  5818.     char *str;
  5819.     long a1, a2, a3, a4, a5, a6, a7, a8;
  5820. /* printw */ {
  5821.     char buf[255];
  5822.     $DESCRIPTOR(text_dsc, 0);
  5823.     if (!smg_open)
  5824.       return;
  5825.     text_dsc.dsc$a_pointer=buf;
  5826.     text_dsc.dsc$w_length = sprintf(buf, str, a1, a2, a3, a4, a5, a6, a7, a8);
  5827.     CHECK_ERR("printw: smg$put_chars",
  5828.               smg$put_chars(&smg_display_id, &text_dsc, 0, 0, 0, 0, 0));
  5829. }
  5830. #endif /* __DECC */
  5831.  
  5832. #define CK_CURPOS
  5833. int
  5834. ck_curpos(row, col) {
  5835.     debug(F111,"VMS smg ck_curpos",ckitoa(row),col);
  5836.     if (!smg_inited || !smg_open) {
  5837.         initscr();
  5838.     }
  5839.     debug(F101,"VMS smg curpos smg_open","",smg_open);
  5840.     if (!smg_open)
  5841.       return(0);
  5842.     debug(F111,"VMS smg ck_curpos",ckitoa(row-1),col-1);
  5843.     move(row - 1, col - 1);             /* SMG is 0-based */
  5844.     refresh();
  5845.     /* endwin(); */
  5846.     return(0);
  5847. }
  5848.  
  5849. int
  5850. ck_cls() {
  5851.     debug(F101,"VMS smg ck_cls smg_inited","",smg_inited);
  5852.     if (!smg_inited || !smg_open) {
  5853.         initscr();
  5854.     }
  5855.     debug(F101,"VMS smg ck_cls smg_open","",smg_open);
  5856.     if (!smg_open)
  5857.       return(0);
  5858.     clear();
  5859.     refresh();
  5860.     /* endwin(); */
  5861.     return(0);
  5862. }
  5863.  
  5864. int
  5865. ck_cleol() {
  5866.     debug(F101,"VMS smg ck_cleol smg_inited","",smg_inited);
  5867.     if (!smg_inited || !smg_open) {
  5868.         initscr();
  5869.     }
  5870.     debug(F101,"VMS smg ck_cleol smg_open","",smg_open);
  5871.     if (!smg_open)
  5872.       return(0);
  5873.     clrtoeol();
  5874.     refresh();
  5875.     /* endwin(); */
  5876.     return(0);
  5877. }
  5878. #endif /* CK_SMG */
  5879.  
  5880. #ifdef MYCURSES
  5881. /*
  5882.   Do-it-yourself curses implementation for VMS, OS/2 and other ANSI/VT-100's.
  5883.   Supports only the VT52 and VT1xx (and later VT2xx/3xx/4xx) terminals.
  5884.   By Terry Kennedy, St Peters College.
  5885.  
  5886.   First, some stuff we can just ignore:
  5887. */
  5888.  
  5889. static int
  5890. touchwin(x) int x; {
  5891.     return(0);
  5892. }
  5893. static int
  5894. initscr() {
  5895.     return(0);
  5896. }
  5897. static int
  5898. refresh() {
  5899.     return(0);
  5900. }
  5901. static int
  5902. endwin() {
  5903.     return(0);
  5904. }
  5905.  
  5906. /*
  5907.  * Now, some stuff we need to do:
  5908.  */
  5909.  
  5910. _PROTOTYP( int move, (int, int) );
  5911. #ifndef OS2
  5912. int
  5913. move(row, col) int row, col; {
  5914.     if (isvt52)
  5915.       printf("\033Y%c%c", row + 037, col + 037);
  5916.     else
  5917.       printf("\033[%d;%dH", row + 1, col + 1);
  5918.     return(0);
  5919. }
  5920.  
  5921. int
  5922. clear() {
  5923.     move(0,0);
  5924.     if (isvt52)
  5925.       printf("\033J");
  5926.     else
  5927.       printf("\033[J");
  5928.     return(0);
  5929. }
  5930.  
  5931. int
  5932. clrtoeol() {
  5933.     if (isvt52)
  5934.       printf("\033K");
  5935.     else
  5936.       printf("\033[K");
  5937.     return(0);
  5938. }
  5939.  
  5940. #define CK_CURPOS
  5941. int
  5942. ck_cls() {
  5943.     return(clear());
  5944. }
  5945.  
  5946. int
  5947. ck_cleol() {
  5948.     return(clrtoeol());
  5949. }
  5950.  
  5951. int
  5952. ck_curpos(row, col) int row, col; {
  5953.     move(row, col);
  5954.     return(0);
  5955. }
  5956.  
  5957. #else /* OS2 */
  5958. /* Windows NT and Windows 95 do not provide ANSI emulation */
  5959. /* Therefore we might as well not use it for OS/2 either   */
  5960.  
  5961. int
  5962. move(row, col) int row, col; {
  5963. #ifndef ONETERMUPD
  5964.     SetCurPos(row, col);
  5965. #endif /* ONETERMUPD */
  5966.     lgotoxy( VCMD, col+1, row+1);
  5967.     VscrnIsDirty(VCMD);
  5968.     return(0);
  5969. }
  5970.  
  5971. int
  5972. clear() {
  5973.     viocell cell;
  5974.     move(0,0);
  5975. #ifdef ONETERMUPD
  5976.     if (VscrnGetBufferSize(VCMD) > 0) {
  5977.         VscrnScroll(VCMD, UPWARD, 0,
  5978.                     VscrnGetHeight(VCMD)-(1),
  5979.                     VscrnGetHeight(VCMD)-(0), TRUE, CHR_SP);
  5980.         cleartermscreen(VCMD);
  5981.     }
  5982. #else
  5983.     cell.c = ' ';
  5984.     cell.a = colorcmd;
  5985.     WrtNCell(cell, cmd_rows * cmd_cols, 0, 0);
  5986. #endif /* ONETERMUPD */
  5987.     return(0);
  5988. }
  5989.  
  5990. int
  5991. clrtoeol() {
  5992.     USHORT row, col;
  5993.     viocell cell;
  5994.  
  5995.     cell.c = ' ';
  5996.     cell.a = colorcmd;
  5997. #ifndef ONETERMUPD
  5998.     GetCurPos(&row, &col );
  5999.     WrtNCell(cell, cmd_cols - col -1, row, col);
  6000. #endif /* ONETERMUPD */
  6001.     clrtoeoln(VCMD,CHR_SP);
  6002.     return(0);
  6003. }
  6004.  
  6005. #define CK_CURPOS
  6006. int
  6007. ck_curpos(row, col) int row, col; {
  6008.     move(row, col);
  6009.     return(0);
  6010. }
  6011.  
  6012. int
  6013. ck_cls() {
  6014.     return(clear());
  6015. }
  6016.  
  6017. int
  6018. ck_cleol() {
  6019.     return(clrtoeol());
  6020. }
  6021.  
  6022. #endif /* OS2 */
  6023. #endif /* MYCURSES */
  6024.  
  6025. #ifndef NOTERMCAP
  6026. #ifndef CK_CURPOS
  6027. #define CK_CURPOS
  6028.  
  6029. /* Termcap/Terminfo section */
  6030.  
  6031. static char cur_cls[32] = { NUL, NUL };
  6032. static char cur_cleol[32] = { NUL, NUL };
  6033. static char cur_cm[64] = { NUL, NUL };
  6034. static char tgsbuf[128] = { NUL, NUL };
  6035.  
  6036. static
  6037. #ifdef CK_ANSIC
  6038. void
  6039. #endif /* CK_ANSIC */
  6040. ck_termset(x) int x; {
  6041.     cur_cls[0] = NUL;
  6042.     cur_cleol[0] = NUL;
  6043.     cur_cm[0] = NUL;
  6044. #ifdef tgetent
  6045.     debug(F100,"tgetent is a macro","",0);
  6046. #endif /* tgetent */
  6047. #ifdef tgetstr
  6048.     debug(F100,"tgetstr is a macro","",0);
  6049. #endif /* tgetstr */
  6050. #ifdef tputs
  6051.     debug(F100,"tputs is a macro","",0);
  6052. #endif /* tputs */
  6053. #ifdef tgoto
  6054.     debug(F100,"tgoto is a macro","",0);
  6055. #endif /* tgoto */
  6056. #ifdef NOTERMCAP
  6057.     /* tgetstr() gets a segmentation fault on OSF/1 */
  6058.     debug(F100,"ck_termset NOTERMCAP","",0);
  6059. #else
  6060.     if (notermcap) {
  6061.         debug(F100,"ck_termset notermcap","",0);
  6062.         return;
  6063.     }
  6064.     debug(F101,"ck_termset x","",x);
  6065.     if (x > 0) {
  6066.         char * bp;
  6067.         bp = tgsbuf;
  6068.         *bp = NUL;
  6069.         debug(F110,"ck_termset calling tgetstr","cl",0);
  6070.         if (tgetstr("cl", &bp)) {       /* Get clear-screen code */
  6071.             debug(F110,"ck_termset tgetstr cl",tgsbuf,"");
  6072.             if ((int)strlen(tgsbuf) < 32)
  6073.               ckstrncpy(cur_cls,tgsbuf,32);
  6074.         } else
  6075.           return;
  6076.         bp = tgsbuf;
  6077.         if (tgetstr("ce", &bp)) {       /* Get clear-to-end-of-line code */
  6078.             debug(F110,"ck_termset tgetstr ce",tgsbuf,"");
  6079.             if ((int)strlen(tgsbuf) < 32)
  6080.               ckstrncpy(cur_cleol,tgsbuf,32);
  6081.         } else
  6082.           return;
  6083.         bp = tgsbuf;
  6084.         if (tgetstr("cm", &bp)) {       /* Get cursor-movement code */
  6085.             debug(F110,"ck_termset tgetstr cm",tgsbuf,"");
  6086.             if ((int)strlen(tgsbuf) < 64)
  6087.               ckstrncpy(cur_cm,tgsbuf,64);
  6088.         } else
  6089.           return;
  6090.     }
  6091. #endif /* NOTERMCAP */
  6092. }
  6093.  
  6094. #ifndef TPUTSFNTYPE
  6095. #ifdef TPUTSISVOID
  6096. #define TPUTSFNTYPE void
  6097. #else
  6098. #define TPUTSFNTYPE int
  6099. #endif /* TPUTSISVOID */
  6100. #endif /* TPUTSFNTYPE */
  6101.  
  6102. #ifndef TPUTSARGTYPE
  6103. #ifdef HPUX9
  6104. #define TPUTSARGTYPE char
  6105. #else
  6106. #ifdef HPUX10
  6107. #define TPUTSARGTYPE char
  6108. #else
  6109. #define TPUTSARGTYPE int
  6110. #endif /* HPUX10 */
  6111. #endif /* HPUX9 */
  6112. #endif /* TPUTSARGTYPE */
  6113.  
  6114. static TPUTSFNTYPE
  6115. #ifdef CK_ANSIC
  6116. ck_outc(TPUTSARGTYPE x)
  6117. #else
  6118. ck_outc(x) TPUTSARGTYPE x;
  6119. #endif /* CK_ANSIC */
  6120. {                                       /* To satisfy tputs() arg3 prototype */
  6121.     int rc;
  6122.     char c;
  6123.     c = (char) x;
  6124.     rc = (inserver) ? ttoc(c) : conoc(c);
  6125. #ifndef TPUTSISVOID
  6126.     return(rc);
  6127. #endif /* TPUTSISVOID */
  6128. }
  6129.  
  6130. int
  6131. ck_curpos(row, col) {
  6132. #ifdef CK_ANSIC
  6133.     TPUTSFNTYPE (*fn)(TPUTSARGTYPE);
  6134. #else
  6135.     TPUTSFNTYPE (*fn)();
  6136. #endif /* CK_ANSIC */
  6137.     if (!fxd_inited)
  6138.       fxdinit(9999);
  6139.     if (!cur_cm[0]) {                   /* We don't have escape sequences */
  6140. #ifdef COMMENT
  6141.         return(-1);                     /* Do nothing */
  6142. #else
  6143.         /* Both C-Kermit's SCREEN command and ANSI/VT100 are 1-based */
  6144.         printf("\033[%d;%dH", row, col); /* Or default to ANSI */
  6145. #endif /* COMMENT */
  6146.     } else {
  6147.         fn = ck_outc;
  6148.         /* termcap/terminfo is 0-based */
  6149.         tputs(
  6150. #ifdef TPUTSARG1CONST
  6151.               (const char *)
  6152. #endif /* TPUTSARG1CONST */
  6153.               tgoto(cur_cm,col-1,row-1),1,fn);
  6154.     }
  6155.     return(0);
  6156. }
  6157.  
  6158. int
  6159. ck_cls() {
  6160. #ifdef CK_ANSIC
  6161.     TPUTSFNTYPE (*fn)(TPUTSARGTYPE);
  6162. #else
  6163.     TPUTSFNTYPE (*fn)();
  6164. #endif /* CK_ANSIC */
  6165.     if (!fxd_inited)
  6166.       fxdinit(9999);
  6167.     if (!cur_cls[0]) {                  /* If we don't have escape sequences */
  6168. #ifdef COMMENT
  6169.         return(-1);                     /* Do nothing */
  6170. #else
  6171.         printf("\033[;H\033[2J");       /* Or default to ANSI */
  6172. #endif /* COMMENT */
  6173.     } else {
  6174.         fn = ck_outc;
  6175.         debug(F111,"ck_cls 2",cur_cls,fxd_inited);
  6176.         tputs(cur_cls,cmd_rows,fn);
  6177.     }
  6178.     return(0);
  6179. }
  6180.  
  6181. int
  6182. ck_cleol() {
  6183. #ifdef CK_ANSIC
  6184.     TPUTSFNTYPE (*fn)(TPUTSARGTYPE);
  6185. #else
  6186.     TPUTSFNTYPE (*fn)();
  6187. #endif /* CK_ANSIC */
  6188.     if (!fxd_inited)
  6189.       fxdinit(9999);
  6190.     if (!cur_cleol[0]) {                /* If we don't have escape sequences */
  6191. #ifdef COMMENT
  6192.         return(-1);                     /* Do nothing */
  6193. #else
  6194.         printf("\033[K");               /* Or use ANSI */
  6195. #endif /* COMMENT */
  6196.     } else {
  6197.         fn = ck_outc;
  6198.         tputs(cur_cleol,1,fn);
  6199.     }
  6200.     return(0);
  6201. }
  6202. #endif /* CK_CURPOS */
  6203. #else
  6204. static void
  6205. ck_termset(x) int x; {
  6206.     if (x) return;
  6207. }
  6208. #endif /* NOTERMCAP */
  6209.  
  6210. #ifndef CK_CURPOS
  6211. #define CK_CURPOS
  6212. int
  6213. ck_cls() {
  6214.     printf("\033[;H\033[2J");
  6215.     return(0);
  6216. }
  6217.  
  6218. int
  6219. ck_cleol() {
  6220.     printf("\033[K");
  6221.     return(0);
  6222. }
  6223.  
  6224. int
  6225. ck_curpos(row, col) int row, col; {
  6226.     printf("\033[%d;%dH", row, col);
  6227.     return(0);
  6228. }
  6229. #endif /* CK_CURPOS */
  6230.  
  6231.  
  6232. #ifndef NOXFER
  6233. static int cinit = 0;                   /* Flag for curses init'd */
  6234. static int cendw = 0;                   /* endwin() was called */
  6235.  
  6236. static
  6237. #ifdef CK_ANSIC                         /* Because VOID used by curses.h */
  6238. void
  6239. #else
  6240. #ifdef MYCURSES
  6241. VOID
  6242. #else
  6243. int
  6244. #endif /* MYCURSES */
  6245. #endif /* CK_ANSIC */
  6246. #ifdef CK_ANSIC                         /* Update % transfered and % bar */
  6247. updpct(long old, long new)
  6248. #else /* CK_ANSIC */
  6249. updpct(old, new) long old, new;
  6250. #endif /* CK_ANSIC */
  6251. /* updpct */ {
  6252. #ifdef COMMENT
  6253.     int m, n;
  6254.     move(CW_PCD,22);
  6255.     printw("%ld", new);
  6256. #ifdef KUI
  6257. #ifndef K95G
  6258.     KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_PCD, (long) new);
  6259. #endif /* K95G */
  6260. #endif /* KUI */
  6261. #ifdef CK_PCT_BAR
  6262.     if (thermometer) {
  6263.         if (old > new) {
  6264.             old = 0;
  6265.             move(CW_PCD, 26);
  6266.             clrtoeol();
  6267.         }
  6268.         m = old/2;
  6269.         move(CW_PCD, 26 + m);
  6270.         n = new / 2 - m;
  6271. #ifndef OS2
  6272.         while (n > 0) {
  6273.             if ((m + 1) % 5 == 0)
  6274.               printw("*");
  6275.             else
  6276.               printw("=");
  6277.             m++;
  6278.             n--;
  6279.         }
  6280.         if (new % 2 != 0) printw("-");
  6281.         /* move(CW_PCD, 22+53); */
  6282. #else /* OS2 */
  6283.         while (n > 0) {
  6284.             printw("%c", '\333');
  6285.             m++; n--;
  6286.         }
  6287.         if (new % 2 != 0)
  6288.           printw("%c", '\261');
  6289. #endif /* OS2 */
  6290.     }
  6291. #endif /* CK_PCT_BAR */
  6292.     /* clrtoeol(); */
  6293. #else  /* !COMMENT */
  6294. #ifdef OS2
  6295. #define CHAR1   '\333'          /* OS2 - CP437 */
  6296. #define CHAR2   '\261'
  6297. #else
  6298. #define CHAR1   '/'             /* Default */
  6299. #define CHAR2   '-'
  6300. #endif /* OS2 */
  6301.     debug(F101,"updpct old","",old);
  6302.     debug(F101,"updpct new","",new);
  6303.     move(CW_PCD,22);
  6304.     printw("%-3ld", new); /*  (was)   printw("%ld", new);  */
  6305. #ifdef KUI
  6306. #ifndef K95G
  6307.     KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PCD, (long) new );
  6308. #endif /* K95G */
  6309. #endif /* KUI */
  6310. #ifdef CK_PCT_BAR
  6311.     if (thermometer) {
  6312.         int m, n;
  6313.  
  6314.         if (old > new) {
  6315.             old = 0 ;
  6316.             move(CW_PCD, 26);
  6317.             clrtoeol();
  6318.         }
  6319.         if (new <= 100L) {
  6320.             m = old / 2;
  6321.             n = new / 2 - m;
  6322.             move(CW_PCD, 26+m);
  6323.             while (n-- > 0)
  6324.               printw("%c", CHAR1);
  6325.             if (new % 2 != 0)
  6326.               printw("%c", CHAR2);
  6327.         }
  6328.     }
  6329. #endif /* CK_PCT_BAR */
  6330. #endif /* COMMENT */
  6331. }
  6332.  
  6333. static long old_tr = -1L;               /* Time remaining previously */
  6334.  
  6335. static long
  6336. #ifdef CK_ANSIC
  6337. shoetl(long old_tr, long cps, long fsiz, long howfar)
  6338. #else
  6339. shoetl(old_tr, cps, fsiz, howfar) long old_tr, cps, fsiz, howfar;
  6340. #endif /* CK_ANSIC */
  6341. /* shoetl */ {                          /* Estimated time left in transfer */
  6342.     long tr;                            /* Time remaining, seconds */
  6343.  
  6344. #ifdef GFTIMER
  6345.     if (fsiz > 0L && cps > 0L)
  6346.       tr = (long)((CKFLOAT)(fsiz - howfar) / (CKFLOAT)cps);
  6347.     else
  6348.       tr = -1L;
  6349. #else
  6350.     tr = (fsiz > 0L && cps > 0L) ?
  6351.       ((fsiz - howfar) / cps) :
  6352.         -1L;
  6353. #endif /* GFTIMER */
  6354.     move(CW_TR,22);
  6355.     if (tr > -1L) {
  6356.         if (tr != old_tr) {
  6357.             printw("%s",hhmmss(tr));
  6358. #ifdef KUI
  6359. #ifndef K95G
  6360.             KuiSetProperty(KUI_FILE_TRANSFER, (long)CW_TR, (long)hhmmss(tr));
  6361. #endif /* K95G */
  6362. #endif /* KUI */
  6363.             clrtoeol();
  6364.         }
  6365.     } else {
  6366.         printw("(unknown)");
  6367. #ifdef KUI
  6368. #ifndef K95G
  6369.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_TR, (long) "(unknown)" );
  6370. #endif /* K95G */
  6371. #endif /* KUI */
  6372.         clrtoeol();
  6373.     }
  6374.     return(tr);
  6375. }
  6376.  
  6377. static long
  6378. #ifdef CK_ANSIC
  6379. shocps(int pct, long fsiz, long howfar)
  6380. #else
  6381. shocps(pct, fsiz, howfar) int pct; long fsiz, howfar;
  6382. #endif /* CK_ANSIC */
  6383. /* shocps */ {
  6384. #ifdef CPS_WEIGHTED
  6385.     static long oldffc = 0L;
  6386. #endif /* CPS_WEIGHTED */
  6387. #ifdef GFTIMER
  6388.     CKFLOAT secs, xx;
  6389. #else
  6390.     long secs, xx;
  6391. #endif /* GFTIMER */
  6392.  
  6393. #ifdef GFTIMER
  6394.     xx = (gtv >= 0.0) ? gtv : 0.0;      /* Floating-point version */
  6395.     gtv = gftimer();
  6396.     if ((gtv - oldgtv) < (CKFLOAT) 1.0) /* Only do this once per second */
  6397.       return(oldcps);
  6398.     oldgtv = xx;
  6399. #else
  6400.     xx = (gtv >= 0) ? gtv : 0;          /* Whole-number version */
  6401.     gtv = gtimer();
  6402.     if ((gtv - oldgtv) < 1)
  6403.       return(oldcps);
  6404.     oldgtv = xx;
  6405. #endif /* GFTIMER */
  6406.  
  6407. #ifdef CPS_WEIGHTED
  6408.     /* debug(F100,"SHOCPS: WEIGHTED","",0); */
  6409.     if (gtv != oldgtv) {                /* The first packet is ignored */
  6410.         if (ffc < oldffc)
  6411.           oldffc = ffc;
  6412.         oldcps = cps;
  6413.         if (oldcps && oldgtv >
  6414. #ifdef GFTIMER
  6415.             1.0
  6416. #else
  6417.             1
  6418. #endif /* GFTIMER */
  6419.             ) {                         /* The first second is ignored */
  6420. /*
  6421.   This version of shocps() produces a weighted average that some
  6422.   people like, but most people find it disconcerting and bombard us
  6423.   with questions and complaints about why the CPS figure fluctuates so
  6424.   wildly.  So now you only get the weighted average if you build the
  6425.   program yourself with CPS_WEIGHTED defined.
  6426. */
  6427. #ifndef CPS_VINCE
  6428. #ifdef GFTIMER
  6429.             cps = (long)((((CKFLOAT)oldcps * 3.0) +
  6430.                    (CKFLOAT)(ffc - oldffc) / (gtv-oldgtv) ) / 4.0);
  6431. #else
  6432.             cps = ( (oldcps * 3) + (ffc - oldffc) / (gtv-oldgtv) ) / 4;
  6433. #endif /* GFTIMER */
  6434. #else
  6435. /* And an alternate weighting scheme from Vincent Fatica... */
  6436.             cps = (3 *
  6437.              ((1+pct/300)*oldffc/oldgtv+(1-pct/100)*(ffc-oldffc)/(gtv-oldgtv)))
  6438.               / 4;
  6439. #endif /* CPS_VINCE */
  6440.         } else {
  6441.             /* No weighted average since there is nothing to weigh */
  6442. #ifdef GFTIMER
  6443.             cps = (long)(gtv != 0.0 ?
  6444.               (CKFLOAT)(ffc - oldffc) / (gtv - oldgtv) :
  6445.                 (ffc - oldffc)) ;
  6446. #else
  6447.             cps = gtv ? (ffc - oldffc) / (gtv - oldgtv) : (ffc - oldffc) ;
  6448. #endif /* GFTIMER */
  6449.         }
  6450. #ifdef COMMENT
  6451. #ifdef DEBUG
  6452.         if (deblog) {
  6453.             debug(F101,"SHOCPS: pct   ","",pct);
  6454.             debug(F101,"SHOCPS: gtv   ","",gtv);
  6455.             debug(F101,"SHOCPS: oldgtv","",oldgtv);
  6456.             debug(F101,"SHOCPS: dgtv  ","",(long)(gtv-oldgtv));
  6457.             debug(F101,"SHOCPS: ffc   ","",ffc);
  6458.             debug(F101,"SHOCPS: oldffc","",oldffc);
  6459.             debug(F101,"SHOCPS: dffc  ","",ffc-oldffc);
  6460.             debug(F101,"SHOCPS: cps   ","",cps);
  6461.         }
  6462. #endif /* DEBUG */
  6463. #endif /* COMMENT */
  6464.         move(CW_CP,22);
  6465.         printw("%ld", cps);
  6466. #ifdef KUI
  6467. #ifndef K95G
  6468.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, (long) cps );
  6469. #endif /* K95G */
  6470. #endif /* KUI */
  6471.         clrtoeol();
  6472.         oldffc = ffc;
  6473.     }
  6474. #else /* !CPS_WEIGHTED */
  6475. #ifdef COMMENT
  6476. #ifdef DEBUG
  6477.     if (deblog) {
  6478.     debug(F100,"SHOCPS: NOT WEIGHTED","",0);
  6479.         debug(F101,"SHOCPS: pct    ","",pct);
  6480.         debug(F101,"SHOCPS: gtv    ","",gtv);
  6481.         debug(F101,"SHOCPS: oldgtv ","",oldgtv);
  6482.         debug(F101,"SHOCPS: dgtv   ","",(long)gtv - (long)oldgtv);
  6483.         debug(F101,"SHOCPS: ffc    ","",ffc);
  6484.         debug(F101,"SHOCPS: oldffc ","",oldffc);
  6485.         debug(F101,"SHOCPS: dffc   ","",ffc-oldffc);
  6486.         debug(F101,"SHOCPS: cps    ","",cps);
  6487.         debug(F101,"SHOCPS: filcnt ","",filcnt);
  6488. #ifdef GFTIMER
  6489.         debug(F101,"SHOCPS: fpfsecs","",fpfsecs);
  6490. #endif /* GFTIMER */
  6491.     }
  6492.     debug(F101,"shocps gtv","",gtv);
  6493. #endif /* DEBUG */
  6494. #ifdef GFTIMER
  6495. #endif /* COMMENT */
  6496.     /* debug(F101,"shocps fpfsecs","",fpfsecs); */
  6497.     secs = gtv - fpfsecs;
  6498.     /* debug(F101,"shocps secs","",(long)secs); */
  6499.     if (secs > 0.0) {
  6500.         cps = (long)((CKFLOAT) ffc / secs);
  6501.         /* debug(F101,"shocps cps","",cps); */
  6502.         move(CW_CP,22);
  6503. #ifdef KUI
  6504. #ifndef K95G
  6505.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, (long) cps );
  6506. #endif /* K95G */
  6507. #endif /* KUI */
  6508.         printw("%ld", cps);
  6509.         clrtoeol();
  6510.     }
  6511. #else  /* Not GFTIMER */
  6512.     if ((secs = gtv - fsecs) > 0) {
  6513.         cps = (secs < 1L) ? ffc : ffc / secs;
  6514.         move(CW_CP,22);
  6515. #ifdef KUI
  6516. #ifndef K95G
  6517.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, (long) cps );
  6518. #endif /* K95G */
  6519. #endif /* KUI */
  6520.         printw("%ld", cps);
  6521.         clrtoeol();
  6522.     }
  6523. #endif /* GFTIMER */
  6524. #endif /* CPS_WEIGHTED */
  6525.  
  6526.     if (cps > peakcps &&                /* Peak transfer rate */
  6527.         ((what & W_SEND && spackets > wslots + 4) ||
  6528.      (!(what & W_SEND) && spackets > 10))) {
  6529.         peakcps = cps;
  6530.     }
  6531.     old_tr = shoetl(old_tr, cps, fsiz, howfar);
  6532.     return(cps);
  6533. }
  6534.  
  6535. static
  6536. #ifdef CK_ANSIC                         /* Because VOID used by curses.h */
  6537. void
  6538. #else
  6539. #ifdef MYCURSES
  6540. VOID
  6541. #else
  6542. int
  6543. #endif /* MYCURSES */
  6544. #endif /* CK_ANSIC */
  6545. scrft() {                               /* Display file type */
  6546.     char xferstr[256];
  6547.     xferstr[0] = NUL;
  6548.     if (binary) {
  6549.         switch(binary) {
  6550.           case XYFT_L:
  6551.             ckstrncpy(xferstr,"LABELED",256);
  6552.             break;
  6553.           case XYFT_I:
  6554.             ckstrncpy(xferstr,"IMAGE",256);
  6555.             break;
  6556.           case XYFT_U:
  6557.             ckstrncpy(xferstr,"BINARY UNDEFINED",256);
  6558.             break;
  6559.       case XYFT_M:
  6560.             ckstrncpy(xferstr,"MACBINARY",256);
  6561.             break;
  6562.       case XYFT_X:
  6563.             ckstrncpy(xferstr,"TENEX",256);
  6564.             break;
  6565.           default:
  6566.           case XYFT_B:
  6567.             ckstrncpy(xferstr,"BINARY",256);
  6568.             break;
  6569.         }
  6570. #ifdef CK_RESEND
  6571.         if (what & W_SEND && sendstart > 0L) {
  6572.             if (sendmode == SM_PSEND) {
  6573.                 ckstrncat(xferstr, " / partial", 256);
  6574.             } else if (sendmode == SM_RESEND) {
  6575.                 ckstrncat(xferstr, " / resend", 256);
  6576.             }
  6577.         } else if (what & W_RECV && rs_len > 0L) {
  6578.             ckstrncat(xferstr, " / resend", 256);
  6579.         }
  6580. #endif /* CK_RESEND */
  6581.     } else {
  6582.  
  6583. #ifndef NOCSETS
  6584.         ckstrncpy(xferstr,"TEXT",256);
  6585. #ifdef NEWFTP
  6586. #ifndef NOUNICODE
  6587.     if (what & W_FTP) {
  6588.         if (ftp_csx < 0)
  6589.           ckstrncat(xferstr," (no translation)", 256);
  6590.         else
  6591.           ckmakxmsg(&xferstr[4],252,
  6592.                " (",
  6593.                fcsinfo[(what & W_SEND) ? ftp_csl : ftp_csx].keyword,
  6594.                " => ",
  6595.                fcsinfo[(what & W_SEND) ? ftp_csx : ftp_csl].keyword,
  6596.                ")",
  6597.                NULL,NULL,NULL,NULL,NULL,NULL,NULL
  6598.                );
  6599.     } else
  6600. #endif /* NOUNICODE */
  6601. #endif /* NEWFTP */
  6602.       if (tcharset == TC_TRANSP) {
  6603.             ckstrncat(xferstr, " (no translation)", 256);
  6604.         } else {
  6605.             if (what & W_SEND) {
  6606.                 sprintf( &xferstr[strlen(xferstr)], /* safe */
  6607.                         " (%s => %s)",
  6608.                         fcsinfo[fcharset].keyword, /* built-in keywords */
  6609.                         tcsinfo[tcharset].keyword  /* lengths are controlled */
  6610.             );
  6611.             } else {
  6612.                 sprintf( &xferstr[strlen(xferstr)], /* safe */
  6613.                         " (%s => %s)",
  6614.                         tcsinfo[tcharset].keyword, /* built-in keywords */
  6615.                         fcsinfo[fcharset].keyword); /* lengths controlled */
  6616.             }
  6617.         }
  6618. #endif /* NOCSETS */
  6619.     }
  6620.     move(CW_TYP,22);
  6621.     printw("%s", xferstr);
  6622.     clrtoeol();
  6623. #ifdef KUI
  6624. #ifndef K95G
  6625.     KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_TYP, (long) xferstr );
  6626. #endif /* K95G */
  6627. #endif /* KUI */
  6628.     return;
  6629. }
  6630.  
  6631. #ifdef CK_NEWTERM
  6632. static FILE *ck_stdout = NULL;
  6633. static int ck_fd = -1;
  6634. #endif /* CK_NEWTERM */
  6635.  
  6636. static long pct = 0L, oldpct = 0L, oldrtt = -1L;
  6637. static int oldtyp = 0, oldwin = -1, oldtry = -1, oldlen = -1, oldtim = -1;
  6638.  
  6639. #ifdef NETCONN
  6640. static char *netname[] = {
  6641.     "none",                /* 00 */
  6642.     "TCP/IP",                /* 01 TCP (Sockets) */
  6643.     "TCP/IP",                /* 02 TCP (Streams) */
  6644.     "X.25",                /* 03 SunLink X.24  */
  6645.     "DECnet",                /* 04 DECnet  */
  6646.     "VAX PSI",                /* 05 VAX PSI */
  6647.     "Named Pipes",            /* 06 LAN Manager Named Pipe */
  6648.     "X.25",                /* 07 Stratus VOS X.25 */
  6649.     "NetBIOS",                /* 08 IBM NETBIOS */
  6650.     "SuperLAT",                /* 07 Meridian SuperLAT */
  6651.     "File",                /* 10 File */
  6652.     "Command",                /* 11 Subprocess (pipe) */
  6653.     "DLL",                /* 12 DLL does i/o */
  6654.     "X.25",                /* 13 IBM AIXLink X.25 */
  6655.     "X.25",                /* 14 HP-UX X.25 */
  6656.     "PTY",                /* 15 Pseudoterminal */
  6657.     "SSH",                /* 16 SSH */
  6658.     "<ERROR>",                /* 17 In case new types are added */
  6659.     "<ERROR>",                /* 18 but nobody remembers to update */
  6660.     "<ERROR>",                /* 19 this table ... */
  6661.     NULL                /* 20 */
  6662. };
  6663. static int nnetname = (sizeof(netname) / sizeof(char *));
  6664.  
  6665. #endif /* NETCONN */
  6666.  
  6667. #ifdef CK_ANSIC
  6668. void
  6669. screenc(int f, char c,long n,char *s)
  6670. #else
  6671. #ifdef MYCURSES
  6672. VOID
  6673. #else
  6674. int
  6675. #endif /* MYCURSES */
  6676. screenc(f,c,n,s)
  6677. int f;          /* argument descriptor */
  6678. char c;         /* a character or small integer */
  6679. long n;         /* a long integer */
  6680. char *s;        /* a string */
  6681. #endif /* CK_ANSIC */
  6682. /* screenc() */ {
  6683. #ifdef CK_SSL
  6684.     extern int tls_active_flag, ssl_active_flag;
  6685. #endif /* CK_SSL */
  6686. #ifdef RLOGCODE
  6687.     extern int ttnproto;
  6688. #endif /* RLOGCODE */
  6689.     static int q = 0;
  6690.     static long fsiz = -1L;   /* Copy of file size */
  6691.     static long fcnt = 0L;    /* Number of files transferred */
  6692.     static long fbyt = 0L;    /* Total file bytes of all files transferred */
  6693.     static long howfar = 0L;  /* How much of current file has been xfer'd. */
  6694.     static int  pctlbl = 0L;  /* Percent done vs Bytes so far */
  6695.     long cps = 0L;
  6696.  
  6697.     int net = 0;
  6698.     int xnet = 0;
  6699.     int ftp = 0;
  6700.     int len;                            /* Length of string */
  6701.     int errors = 0;                     /* Error counter */
  6702.     int x;                              /* Worker */
  6703.  
  6704.     debug(F101,"screenc cinit","",cinit);
  6705.     debug(F101,"screenc cendw","",cendw);
  6706.  
  6707.     if (!s) s = "";                     /* Always do this. */
  6708.  
  6709.     ftp = (what & W_FTP) ? 1 : 0;    /* FTP or Kermit */
  6710.     net = network || ftp;
  6711.     xnet = ftp ? 1 : nettype;        /* NET_TCPB == 1 */
  6712.  
  6713.     if (cinit == 0 || cendw > 0) {      /* Handle borderline cases... */
  6714.         if (f == SCR_CW) {              /* Close window, but it's not open */
  6715.             ft_win = 0;
  6716.             return;
  6717.         }
  6718.         debug(F111,"screenc A",s,f);
  6719.         if (f == SCR_EM ||
  6720.            (f == SCR_PT && c == 'E')) { /* Fatal error before window open */
  6721.             conoll(""); conoc('?'); conoll(s); return; /* Regular display */
  6722.         }
  6723.     }
  6724.     if (cinit == 0) {                   /* Only call initscr() once */
  6725.     char * s;
  6726.     /* Check these now -- if they are defined but not numeric */
  6727.     /* they can crash curses */
  6728.     s = getenv("LINES");
  6729.     if (s) if (!rdigits(s)) {
  6730.         printf("?LINES variable not numeric: \"%s\".\n",s);
  6731.         printf("(Fullscreen display disabled)\n");
  6732.         fdispla = XYFD_S;
  6733.         return;
  6734.     }
  6735.     s = getenv("COLUMNS");
  6736.     if (s) if (!rdigits(s)) {
  6737.         printf("?COLUMNS variable not numeric: \"%s\".\n",s);
  6738.         printf("(Fullscreen display disabled)\n");
  6739.         fdispla = XYFD_S;
  6740.         return;
  6741.     }
  6742.         cendw = 1;                      /* New window needs repainting */
  6743. #ifdef COMMENT
  6744.         if (!initscr()) {               /* Oops, can't initialize window? */
  6745. /*
  6746.   In fact, this doesn't happen.  "man curses" says initscr() halts the
  6747.   entire program if it fails, which is true on the systems where I've
  6748.   tested it.  It will fail if your terminal type is not known to it.
  6749.   That's why SET FILE DISPLAY FULLSCREEN calls tgetent() to make sure the
  6750.   terminal type is known before allowing a curses display.
  6751. */
  6752.             fprintf(stderr,"CURSES INITSCR ERROR\r\n");
  6753.             fdispla = XYFD_S;           /* Fall back to CRT display */
  6754.             return;
  6755.         } else {
  6756.             cinit++;                    /* Window initialized ok */
  6757.             debug(F100,"CURSES INITSCR OK","",0);
  6758.         }
  6759. #else                                   /* Save some memory. */
  6760. #ifdef CK_NEWTERM
  6761.         /* (From Andy Fyfe <andy@vlsi.cs.caltech.edu>)
  6762.            System V curses seems to reserve the right to alter the buffering
  6763.            on the output FILE* without restoring it.  Fortunately System V
  6764.            curses provides newterm(), an alternative to initscr(), that
  6765.            allows us to specify explicitly the terminal type and input and
  6766.            output FILE pointers.  Thus we duplicate stdout, and let curses
  6767.            have the copy.  The original remains unaltered.  Unfortunately,
  6768.            newterm() seems to be particular to System V.
  6769.         */
  6770.         s = getenv("TERM");
  6771.         if (ck_fd < 0) {
  6772.             ck_fd = dup(fileno(stdout));
  6773.             ck_stdout = (ck_fd >= 0) ? (FILE *)fdopen(ck_fd, "w") : NULL;
  6774.         }
  6775.         debug(F100,"screenc newterm...","",0);
  6776.  
  6777. /* NOTE: It might be necessary to do this with stdin too! */
  6778. /* This would have been the case in FreeBSD 4.1 but they fixed the */
  6779. /* problem by restoring the buffering of stdin before the final release. */
  6780. /* (But T.E. Dickey says stdin is not buffered?) */
  6781.  
  6782.         if (ck_stdout == NULL || newterm(s, ck_stdout, stdin) == 0) {
  6783.             fprintf(stderr,
  6784.               "Fullscreen display not supported for terminal type: %s\r\n",s);
  6785.             fdispla = XYFD_S;           /* Use CRT instead */
  6786.             return;
  6787.         }
  6788.         debug(F100,"screenc newterm ok","",0);
  6789. #else
  6790.         debug(F100,"screen calling initscr","",0);
  6791.         initscr();                      /* Initialize curses. */
  6792.         debug(F100,"screen initscr ok","",0);
  6793. #endif /* CK_NEWTERM */
  6794.         cinit++;                        /* Remember curses was initialized. */
  6795. #endif /* COMMENT */
  6796.     }
  6797.     ft_win = 1;                         /* Window is open */
  6798.     if (repaint) {
  6799. #ifdef CK_WREFRESH
  6800. /*
  6801.   This totally repaints the screen, just what we want, but we can only
  6802.   do this with real curses, and then only if clearok() and wrefresh() are
  6803.   provided in the curses library.
  6804. */
  6805. #ifdef OS2
  6806.         RestoreCmdMode();
  6807. #else
  6808. #ifdef QNX
  6809. #ifndef QNX16
  6810.         clearok(stdscr, 1);             /* QNX doesn't have curscr */
  6811. #endif /* QNX16 */
  6812.         wrefresh(stdscr);
  6813. #else
  6814.         wrefresh(curscr);
  6815. #endif /* QNX */
  6816. #endif /* OS2 */
  6817. #else  /* No CK_WREFRESH */
  6818. /*
  6819.   Kermit's do-it-yourself method, works with all types of fullscreen
  6820.   support, but does not repaint all the fields.  For example, the filename
  6821.   is lost, because it arrives at a certain time and never comes again, and
  6822.   Kermit presently does not save it anywhere.  Making this method work for
  6823.   all fields would be a rather major recoding task, duplicating what curses
  6824.   already does, and would add a lot of complexity and storage space.
  6825. */
  6826.         cendw = 1;
  6827. #endif /* CK_WREFRESH */
  6828.         repaint = 0;
  6829.     }
  6830.     if (cendw) {                        /* endwin() was called previously */
  6831. #ifdef VMS
  6832.         initscr();                      /* (or should have been!) */
  6833.         clear();
  6834.         touchwin(stdscr);
  6835.         refresh();
  6836. #else
  6837. #ifdef QNX
  6838. /*
  6839.   In QNX, if we don't call initscr() here we core dump.
  6840.   I don't have any QNX curses documentation, but other curses manuals
  6841.   say that initscr() should be called only once per application, and
  6842.   experience shows that on other systems, calling initscr() here generally
  6843.   results in a core dump.
  6844. */
  6845.         debug(F100,"screenc re-calling initscr QNX","",0);
  6846.         initscr();
  6847.         clear();
  6848.         refresh();
  6849. #ifdef COMMENT
  6850. /*
  6851.   But even so, second and subsequent curses displays are messed up.
  6852.   Calling touchwin, refresh, etc, doesn't make any difference.
  6853. */
  6854.         debug(F100,"screenc calling touchwin QNX","",0);
  6855.         touchwin(stdscr);
  6856.         debug(F100,"screenc calling refresh QNX","",0);
  6857.         refresh();
  6858. #endif /* COMMENT */
  6859.  
  6860. #else /* All others... */
  6861.         debug(F100,"screenc calling clear","",0);
  6862.         clear();
  6863.         debug(F100,"screenc clear ok","",0);
  6864. #endif /* QNX */
  6865. #endif /* VMS */
  6866.         debug(F100,"screenc setup ok","",0);
  6867.         debug(F100,"screenc doing first move","",0);
  6868.         move(CW_BAN,0);                 /* Display the banner */
  6869.         debug(F110,"screenc myhost",myhost,0);
  6870. #ifdef TCPSOCKET
  6871.         debug(F110,"screenc myipaddr",myipaddr,0);
  6872. #endif /* TCPSOCKET */
  6873. #ifdef HPUX1010
  6874.         debug(F100,"screenc calling first printw...","",0);
  6875. /* Right here is where HP-UX 10.10 libxcurse.1 Rev 76.20 hangs... */
  6876. #endif /* HPUX1010 */
  6877.         if (myhost[0]) {
  6878. #ifdef TCPSOCKET
  6879.             if (!myipaddr[0]
  6880. #ifdef OS2
  6881.                  /* We need to perform this test because on non-TCP/IP */
  6882.                  /* systems the call to getlocalipaddr() results in a  */
  6883.                  /* DNS Lookup which takes several minutes to time out */
  6884.                  && net &&
  6885.                  (xnet == NET_TCPA || xnet == NET_TCPB
  6886. #ifdef SSHBUILTIN
  6887.                   || xnet == NET_SSH
  6888. #endif /* SSHBUILTIN */
  6889.                   )
  6890. #endif /* OS2 */
  6891.                  )
  6892.               getlocalipaddr();
  6893.             if (myipaddr[0] && strcmp((char *)myhost,(char *)myipaddr))
  6894.               printw("%s, %s [%s]",versio,(char *)myhost,(char *)myipaddr);
  6895.             else
  6896. #endif /* TCPSOCKET */
  6897.               printw("%s, %s",versio,(char *)myhost);
  6898.         } else {
  6899.             printw("%s",versio);
  6900.         }
  6901. #ifdef HPUX1010
  6902.         debug(F100,"screenc first printw returns","",0);
  6903. #endif /* HPUX1010 */
  6904.         move(CW_DIR,3);
  6905.         printw("Current Directory: %s",zgtdir());
  6906. #ifdef KUI
  6907. #ifndef K95G
  6908.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_DIR, (long) zgtdir() );
  6909. #endif /* K95G */
  6910. #endif /* KUI */
  6911.         if (net) {
  6912.             move(CW_LIN,8);
  6913.             printw("Network Host: %s",
  6914. #ifdef NEWFTP
  6915.            ftp ? (ftp_host ? ftp_host : "(unknown)") :
  6916. #endif /* NEWFTP */
  6917.            ttname
  6918.            );
  6919.         } else {
  6920.             move(CW_LIN,0);
  6921.             printw("Communication Device: %s",ttname);
  6922.         }
  6923. #ifdef KUI
  6924. #ifndef K95G
  6925.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_LIN, (long) ttname );
  6926. #endif /* K95G */
  6927. #endif /* KUI */
  6928.  
  6929.         if (net) {
  6930.             move(CW_SPD,8);
  6931.             printw("Network Type: ");
  6932.         } else {
  6933.             move(CW_SPD,1);
  6934.             printw("Communication Speed: ");
  6935.         }
  6936.         move(CW_SPD,22);                /* Serial speed or network type */
  6937.         if (net) {
  6938. #ifdef NETCONN
  6939.         int secure = 0;
  6940.         char * xname;
  6941.         if (xnet > nnetname)
  6942.           xname = "[ERROR]";
  6943.         else
  6944.           xname = netname[xnet];
  6945. #ifdef NEWFTP
  6946.             if (ftp) {
  6947.         if (ftpissecure())
  6948.           secure = 1;
  6949.         } else
  6950. #endif /* NEWFTP */
  6951.           if (0
  6952. #ifdef SSHBUILTIN
  6953.                 || IS_SSH()
  6954. #endif /* SSHBUILTIN */
  6955. #ifdef CK_ENCRYPTION
  6956.                 || ck_tn_encrypting() && ck_tn_decrypting()
  6957. #endif /* CK_ENCRYPTION */
  6958. #ifdef CK_SSL
  6959.                 || tls_active_flag || ssl_active_flag
  6960. #endif /* CK_SSL */
  6961. #ifdef RLOGCODE
  6962. #ifdef CK_KERBEROS
  6963. #ifdef CK_ENCRYPTION
  6964.                 || ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN
  6965. #endif /* CK_ENCRYPTION */
  6966. #endif /* CK_KERBEROS */
  6967. #endif /* RLOGCODE */
  6968.                  ) {
  6969.         secure = 1;
  6970.         }
  6971.         if (secure) {
  6972. #ifdef KUI
  6973. #ifndef K95G
  6974.                 char buf[30];
  6975.                 sprintf(buf,"%s (SECURE)",xname);
  6976.                 KuiSetProperty(KUI_FILE_TRANSFER,
  6977.                                (long) CW_SPD,
  6978.                                (long) buf
  6979.                                );
  6980. #endif /* K95G */
  6981. #endif /* KUI */
  6982.                 printw("%s (SECURE)",xname);
  6983.             } else {
  6984.                 printw("%s",xname);
  6985. #ifdef KUI
  6986. #ifndef K95G
  6987.                 KuiSetProperty(KUI_FILE_TRANSFER,
  6988.                                (long) CW_SPD,
  6989.                                (long) xname
  6990.                                );
  6991. #endif /* K95G */
  6992. #endif /* KUI */
  6993.             }
  6994. #else
  6995.             printw("(network)");
  6996. #ifdef KUI
  6997. #ifndef K95G
  6998.             KuiSetProperty(KUI_FILE_TRANSFER,
  6999.                            (long) CW_SPD,
  7000.                            (long) "(network)"
  7001.                            );
  7002. #endif /* K95G */
  7003. #endif /* KUI */
  7004. #endif /* NETCONN */
  7005.         } else {
  7006.             if (speed < 0L)
  7007.               speed = ttgspd();
  7008.             if (speed > 0L) {
  7009.                 if (speed == 8880) {
  7010.                     printw("75/1200");
  7011. #ifdef KUI
  7012. #ifndef K95G
  7013.                     KuiSetProperty(KUI_FILE_TRANSFER,
  7014.                                    (long) CW_SPD,
  7015.                                    (long) "75/1200"
  7016.                                    );
  7017. #endif /* K95G */
  7018. #endif /* KUI */
  7019.                 } else {
  7020.                     char speedbuf[64] ;
  7021.                     sprintf(speedbuf, "%ld", speed);
  7022.                     printw("%s",speedbuf);
  7023. #ifdef KUI
  7024. #ifndef K95G
  7025.                     KuiSetProperty(KUI_FILE_TRANSFER,
  7026.                                    (long) CW_SPD,
  7027.                                    (long) speedbuf
  7028.                                    );
  7029. #endif /* K95G */
  7030. #endif /* KUI */
  7031.                 }
  7032.             } else {
  7033.                 printw("unknown");
  7034. #ifdef KUI
  7035. #ifndef K95G
  7036.                 KuiSetProperty(KUI_FILE_TRANSFER,
  7037.                                (long) CW_SPD,
  7038.                                (long) "(unknown)"
  7039.                                );
  7040. #endif /* K95G */
  7041. #endif /* KUI */
  7042.             }
  7043.         }
  7044.         move(CW_PAR,14);
  7045.         printw("Parity: %s",ftp ? "none" : parnam((char)parity));
  7046. #ifdef KUI
  7047. #ifndef K95G
  7048.         KuiSetProperty(KUI_FILE_TRANSFER,
  7049.                        (long) CW_PAR,
  7050.                        (long) parnam((char)parity)
  7051.                        );
  7052. #endif /* K95G */
  7053. #endif /* KUI */
  7054. #ifdef CK_TIMERS
  7055.         if (/* rttflg && */ protocol == PROTO_K) {
  7056.             move(CW_TMO, 9); printw("RTT/Timeout:"); }
  7057. #endif /* CK_TIMERS */
  7058.         move(CW_TYP,11); printw("File Type:");
  7059.         move(CW_SIZ,11); printw("File Size:");
  7060.         move(CW_PCD, 8);
  7061.         clrtoeol();
  7062.         pctlbl = (what & W_SEND);
  7063.         printw("%s:", pctlbl ? "Percent Done" : "Bytes So Far");
  7064.  
  7065. #ifdef XYZ_INTERNAL
  7066.         move(CW_BAR, 1);
  7067.         printw("%10s Protocol:", ftp ? "FTP" : ptab[protocol].p_name);
  7068. #endif /* XYZ_INTERNAL */
  7069. #ifdef CK_PCT_BAR
  7070.         if (thermometer) {
  7071.             oldpct = pct = 0;
  7072.             move(CW_BAR,22);
  7073.             printw("    ...10...20...30...40...50...60...70...80...90..100");
  7074.             move(CW_BAR,22+56);
  7075.         }
  7076. #endif /* CK_PCT_BAR */
  7077.         move(CW_TR,  1); printw("Estimated Time Left:");
  7078.         move(CW_CP,  2); printw("Transfer Rate, CPS:");
  7079.         move(CW_WS,  8); printw("Window Slots:%s",
  7080.                                 ((protocol == PROTO_K) && !ftp) ?
  7081.                                 "" : " N/A"
  7082.                                 );
  7083.         move(CW_PT,  9); printw("Packet Type:");
  7084.         if (ftp || protocol != PROTO_K) {
  7085.         move(CW_PT,22);
  7086.             printw("%s", "N/A");
  7087.             move(CW_PC,  11); printw("I/O Count:");
  7088.             move(CW_PL,  10); printw("I/O Length:");
  7089.         } else {
  7090.             move(CW_PC,  8); printw("Packet Count:");
  7091.             move(CW_PL,  7); printw("Packet Length:");
  7092.         }
  7093. #ifndef COMMENT
  7094.         move(CW_PR,  9); printw("Error Count:");
  7095. #else
  7096.         move(CW_PR,  2); printw("Packet Retry Count:");
  7097. #endif
  7098. #ifdef COMMENT
  7099.         move(CW_PB,  2); printw("Packet Block Check:");
  7100. #endif /* COMMENT */
  7101.         move(CW_ERR,10); printw("Last Error:");
  7102.         move(CW_MSG, 8); printw("Last Message:");
  7103.     if (xfrmsg) {
  7104.         move(CW_MSG, 22); printw("%s",xfrmsg);
  7105.         makestr(&xfrmsg,NULL);
  7106.     }
  7107.         move(CW_INT, 0);
  7108.         if (!xfrint) {
  7109.             printw("(Transfer interruption is disabled)");
  7110.         } else {
  7111. #ifdef CK_NEED_SIG
  7112.             printw(
  7113. "<%s>X to cancel file, <%s>Z to cancel group, <%s><CR> to resend last packet",
  7114.                    dbchr(escape), dbchr(escape), dbchr(escape)
  7115.                    );
  7116.             move(CW_INT + 1, 0);
  7117.             printw(
  7118. "<%s>E to send Error packet, ^C to quit immediately, <%s>L to refresh screen.",
  7119.                    dbchr(escape), dbchr(escape)
  7120.                    );
  7121. #else /* !CK_NEED_SIG */
  7122.             move(CW_INT, 0);
  7123. #ifdef OS2
  7124.             if (protocol == PROTO_K) {
  7125.                 printw(
  7126. "X to cancel file, Z to cancel group, <Enter> to resend last packet,"
  7127.                        );
  7128.             }
  7129. #else /* !OS2 */
  7130. #ifdef VMS                              /* In VMS avoid bottom line */
  7131.             printw(
  7132. "X: Cancel this file; E: Cancel transfer; ^C: Quit now; ^W: Refresh screen."
  7133.                    );
  7134. #else
  7135.             printw(
  7136. "X to cancel file, Z to cancel group, <CR> to resend last packet,"
  7137.                    );
  7138. #endif /* VMS */
  7139. #endif /* OS2 */
  7140.  
  7141. #ifndef VMS
  7142.             move(CW_INT + 1, 0);
  7143.             if (protocol == PROTO_K) {
  7144.                 printw(
  7145. "E to send Error packet, ^C to quit immediately, ^L to refresh screen."
  7146.                        );
  7147.             } else {
  7148.                 printw("^C to cancel file transfer.");
  7149.             }
  7150. #endif /* VMS */
  7151. #endif /* CK_NEED_SIG */
  7152.         }
  7153.         refresh();
  7154.         cendw = 0;
  7155.     }
  7156.     debug(F101,"SCREENC switch","",f);
  7157.     debug(F000,"SCREENC c","",c);
  7158.     debug(F101,"SCREENC n","",n);
  7159.  
  7160.     len = strlen(s);                    /* Length of argument string */
  7161.     switch (f) {                        /* Handle our function code */
  7162.       case SCR_FN:                      /* Filename */
  7163.         oldpct = pct = 0L;              /* Reset percents */
  7164. #ifdef GFTIMER
  7165.         gtv = (CKFLOAT) -1.0;
  7166.         /* oldgtv = (CKFLOAT) -1.0; */
  7167. #else
  7168.         gtv = -1L;
  7169.         /* oldgtv = -1L; */
  7170. #endif /* GFTIMER */
  7171.         oldwin = -1;
  7172.         fsiz = -1L;                     /* Invalidate previous file size */
  7173.         move(CW_PCD,22);                /* Erase percent done from last time */
  7174. #ifdef KUI
  7175. #ifndef K95G
  7176.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PCD, (long) 0 );
  7177.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_FFC, (long) 0 );
  7178. #endif /* K95G */
  7179. #endif /* KUI */
  7180.         clrtoeol();
  7181.         move(CW_SIZ,22);                /* Erase file size from last time */
  7182. #ifdef KUI
  7183. #ifndef K95G
  7184.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_SIZ, (long) 0 );
  7185. #endif /* K95G */
  7186. #endif /* KUI */
  7187.         clrtoeol();
  7188.         move(CW_ERR,22);                /* And last error message */
  7189. #ifdef KUI
  7190. #ifndef K95G
  7191.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) "" );
  7192. #endif /* K95G */
  7193. #endif /* KUI */
  7194.         clrtoeol();
  7195. #ifdef COMMENT
  7196. #ifdef STREAMING
  7197.         if (protocol == PROTO_K && streamok) {
  7198.             move(CW_BAR, 1);
  7199. #ifdef XYZ_INTERNAL
  7200.             printw("   Kermit STREAMING:");
  7201. #else
  7202.             printw("          STREAMING:");
  7203. #endif /* XYZ_INTERNAL */
  7204.         }
  7205. #endif /* STREAMING */
  7206. #endif /* COMMENT */
  7207.  
  7208.         if (what & W_SEND) {        /* If we're sending... */
  7209. #ifdef NEWFTP
  7210.         if (what & W_FTP) {        /* FTP */
  7211.                 move(CW_NAM,13);
  7212.                 printw("FTP PUT:");
  7213.         } else
  7214. #endif /* NEWFTP */
  7215. #ifdef CK_RESEND
  7216.             switch (sendmode) {        /* Kermit */
  7217.               case SM_RESEND:
  7218.                 move(CW_NAM,11);
  7219.                 printw("RESENDING:");
  7220.                 break;
  7221.               default:
  7222.                 move(CW_NAM,13);
  7223.                 printw("SENDING:");
  7224.                 break;
  7225.             }
  7226. #else
  7227.             move(CW_NAM,13);
  7228.             printw("SENDING:");
  7229. #endif /* CK_RESEND */
  7230.  
  7231.         } else if (what & W_RECV) {    /* If we're receiving... */
  7232. #ifdef NEWFTP
  7233.         if (what & W_FTP) {        /* FTP */
  7234.                 move(CW_NAM,13);
  7235.                 printw("FTP GET:");
  7236.         } else {
  7237. #endif /* NEWFTP */
  7238.         move(CW_NAM,11);
  7239.         printw("RECEIVING:");
  7240. #ifdef NEWFTP
  7241.         }
  7242.         } else if (what == (W_FTP|W_FT_DELE)) {
  7243.         move(CW_NAM,10);
  7244.         printw("FTP DELETE:");
  7245. #endif /* NEWFTP */
  7246.         } else {                        /* If we don't know... */
  7247.             move(CW_NAM,11);            /* (should never see this) */
  7248.             printw("File Name:");
  7249.         }
  7250.         move(CW_NAM,22);                /* Display the filename */
  7251.         if (len > 57) {
  7252.             printw("%.55s..",s);
  7253.             len = 57;
  7254.         } else printw("%s",s);
  7255. #ifdef KUI
  7256. #ifndef K95G
  7257.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  7258. #endif /* K95G */
  7259. #endif /* KUI */
  7260.         q = len;                        /* Remember name length for later */
  7261.         clrtoeol();
  7262.         scrft();                        /* Display file type (can change) */
  7263.         refresh();
  7264. #ifdef OS2
  7265.         SaveCmdMode(0, 0);
  7266. #endif /* OS2 */
  7267.         return;
  7268.  
  7269.       case SCR_AN:                      /* File as-name */
  7270.         if (q + len + 4 < 58) {         /* Will fit */
  7271.             move(CW_NAM, 22 + q);
  7272.             printw(" => %s",s);
  7273. #ifdef KUI
  7274. #ifndef K95G
  7275.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  7276. #endif /* K95G */
  7277. #endif /* KUI */
  7278.         } else {                        /* Too long */
  7279.             move(CW_NAM, 22);           /* Overwrite previous name */
  7280.             q = 0;
  7281.             if (len + 4 > 57) {                                 /* wg15 */
  7282.                 printw(" => %.51s..",s);                        /* wg15 */
  7283.                 len = 53;                                       /* wg15 */
  7284.             } else printw(" => %s",s);                          /* wg15 */
  7285. #ifdef KUI
  7286. #ifndef K95G
  7287.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s  );
  7288. #endif /* K95G */
  7289. #endif /* KUI */
  7290.         }
  7291.         q += len + 4;                   /* Remember horizontal position */
  7292.         clrtoeol();
  7293.         refresh();
  7294. #ifdef OS2
  7295.         SaveCmdMode(0, 0);
  7296. #endif /* OS2 */
  7297.         return;
  7298.  
  7299.       case SCR_FS:                      /* File size */
  7300.         fsiz = n;
  7301.         move(CW_SIZ,22);
  7302.         if (fsiz > -1L) {
  7303. #ifdef KUI
  7304. #ifndef K95G
  7305.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_SIZ, (long) n );
  7306. #endif /* K95G */
  7307. #endif /* KUI */
  7308.             printw("%ld",n);
  7309.         }
  7310.         clrtoeol();
  7311. #ifdef COMMENT
  7312.         move(CW_PCD, 8);
  7313.         if (fsiz > -1L) {               /* Put up percent label */
  7314.             pctlbl = 1;
  7315.         clrtoeol();
  7316.             printw("Percent Done:");
  7317.         }
  7318. #else
  7319.     move(CW_PCD, 8);
  7320.     clrtoeol();
  7321.         if (fsiz > -1L) {               /* Put up percent label */
  7322.             pctlbl = 1;
  7323.             printw("Percent Done:");
  7324.         } else {
  7325.             pctlbl = 0;
  7326.             printw("Bytes So Far:");
  7327.     }
  7328. #endif /* COMMENT */
  7329.         clrtoeol();
  7330.         scrft();                        /* File type */
  7331.         refresh();
  7332. #ifdef OS2
  7333.         SaveCmdMode(0, 0);
  7334. #endif /* OS2 */
  7335.         return;
  7336.  
  7337.       case SCR_PT:                      /* Packet type or pseudotype */
  7338.         if (spackets < 5) {
  7339.             extern int sysindex;
  7340.             extern struct sysdata sysidlist[];
  7341.             /* Things that won't change after the 4th packet */
  7342.             move(CW_PAR,22);
  7343.             printw("%s",parnam((char)parity));
  7344. #ifdef KUI
  7345. #ifndef K95G
  7346.             KuiSetProperty( KUI_FILE_TRANSFER,
  7347.                            (long) CW_PAR,
  7348.                            (long) parnam((char)parity)
  7349.                            );
  7350. #endif /* K95G */
  7351. #endif /* KUI */
  7352.             clrtoeol();
  7353. #ifdef COMMENT
  7354.             move(CW_PB, 22);            /* Block check on this packet */
  7355.             if (bctu == 4)
  7356.               printw("B");
  7357.             else
  7358.               printw("%d",bctu);
  7359.             clrtoeol();
  7360. #endif /* COMMENT */
  7361.             if (
  7362. #ifdef NEWFTP
  7363.         (ftp && (spackets == 1 || rpackets == 1)) ||
  7364. #endif /* NEWFTP */
  7365.         spackets == 4
  7366.         ) {
  7367.                 move(CW_LIN,8);
  7368.                 if (
  7369. #ifdef NEWFTP
  7370.             ftp ||
  7371. #endif /* NEWFTP */
  7372.             ((protocol == PROTO_K) && (sysindex > -1))
  7373.             ) {
  7374.                     if (net) {
  7375.                         move(CW_LIN,8);
  7376.                         printw("Network Host: %s (%s)",
  7377. #ifdef NEWFTP
  7378.                    ftp ? (ftp_host ? ftp_host : "") :
  7379. #endif /* NEWFTP */
  7380.                    ttname,
  7381. #ifdef NEWFTP
  7382.                    ftp ? ftp_srvtyp :
  7383. #endif /* NEWFTP */
  7384.                    sysidlist[sysindex].sid_name
  7385.                    );
  7386.                     } else {
  7387.                         move(CW_LIN,0);
  7388.                         printw("Communication Device: %s (remote host is %s)",
  7389.                              ttname,
  7390.                              sysidlist[sysindex].sid_name
  7391.                              );
  7392.                     }
  7393.                     clrtoeol();
  7394.                 }
  7395.             }
  7396.         }
  7397. #ifdef CK_TIMERS
  7398.         if (/* rttflg && */ protocol == PROTO_K) {
  7399.             long xx;
  7400.             if (
  7401. #ifdef STREAMING
  7402.                 streaming && oldwin != -2
  7403. #else
  7404.                 0
  7405. #endif /* STREAMING */
  7406.                 ) {
  7407.                 move(CW_TMO, 22);
  7408.                 printw("00 / 00");
  7409.                 clrtoeol();
  7410.             } else {
  7411.                 xx = (rttdelay + 500) / 1000;
  7412.                 if (xx != oldrtt || rcvtimo != oldtim) {
  7413.                     move(CW_TMO, 22);
  7414.                     printw("%02ld / %02d", xx, rcvtimo);
  7415.                     oldrtt = xx;
  7416.                     oldtim = rcvtimo;
  7417.                     clrtoeol();
  7418.                 }
  7419.             }
  7420.         }
  7421. #endif /* CK_TIMERS */
  7422.  
  7423.         x = (what & W_RECV) ?          /* Packet length */
  7424.           rpktl+(protocol==PROTO_K?1:0) :
  7425.             spktl;
  7426.         if (x != oldlen) {              /* But only if it changed. */
  7427.             move(CW_PL, 22);
  7428.             printw("%d",x);
  7429. #ifdef KUI
  7430. #ifndef K95G
  7431.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PL, (long) x );
  7432. #endif /* K95G */
  7433. #endif /* KUI */
  7434.             clrtoeol();
  7435.             oldlen = x;
  7436.         }
  7437.         move(CW_PC, 22);                /* Packet count (always). */
  7438.  
  7439.         printw("%d", (what & W_RECV) ? rpackets : spackets);
  7440. #ifdef KUI
  7441. #ifndef K95G
  7442.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PC, (long) spackets );
  7443. #endif /* K95G */
  7444. #endif /* KUI */
  7445.         clrtoeol();
  7446.  
  7447.         if (protocol == PROTO_K && !ftp) { /* Window slots */
  7448.             char ws[16];
  7449.             int flag;
  7450.             flag = 0;
  7451. #ifdef STREAMING
  7452.             if (streaming) {
  7453.                 if (oldwin != -2) {
  7454.                     sprintf(ws,"STREAMING");
  7455.                     flag = 1;
  7456.                     oldwin = -2;
  7457.                 }
  7458.             } else
  7459. #endif /* STREAMING */
  7460.               if (wcur != oldwin) {
  7461.                   sprintf(ws, "%d of %d", wcur < 1 ? 1 : wcur, wslotn);
  7462.                   flag = 1;
  7463.                   oldwin = wcur;
  7464.               }
  7465.             if (flag) {
  7466.                 move(CW_WS, 22);
  7467.                 printw("%s", ws);
  7468.                 clrtoeol();
  7469. #ifdef KUI
  7470. #ifndef K95G
  7471.                 KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_WS, (long) ws );
  7472. #endif /* K95G */
  7473. #endif /* KUI */
  7474.             }
  7475.         }
  7476.         errors = retrans + crunched + timeouts;
  7477.         if (errors != oldtry) {         /* Retry count, if changed */
  7478.             move(CW_PR, 22);
  7479.             printw("%d",errors);
  7480. #ifdef KUI
  7481. #ifndef K95G
  7482.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PR, (long) errors );
  7483. #endif /* K95G */
  7484. #endif /* KUI */
  7485.             clrtoeol();
  7486.             oldtry = errors;
  7487.         }
  7488.     /* Sender's packet type */
  7489.         if (!ftp && (c != oldtyp && c != 'Y' && c != 'N')) {
  7490.             char type[2];
  7491.             sprintf(type, "%c",c);
  7492.             move(CW_PT,22);
  7493.             printw("%s", type);
  7494. #ifdef KUI
  7495. #ifndef K95G
  7496.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PT, (long) type );
  7497. #endif /* K95G */
  7498. #endif /* KUI */
  7499.             clrtoeol();
  7500.             oldtyp = c;
  7501.         }
  7502.         switch (c) {                    /* Now handle specific packet types */
  7503.           case 'S':                     /* Beginning of transfer */
  7504.             fcnt = fbyt = 0L;           /* Clear counters */
  7505. #ifdef GFTIMER
  7506.             gtv = -1.0;
  7507. #else /* GFTIMER */
  7508.             gtv = -1L;                  /* And old/new things... */
  7509. #endif /* GFTIMER */
  7510.             oldpct = pct = 0L;
  7511.             break;
  7512.  
  7513.           case 'Z':                     /* or EOF */
  7514.             debug(F101,"screenc SCR_PT Z pktnum","",n);
  7515.             debug(F101,"screenc SCR_PT Z oldpct","",oldpct);
  7516.             debug(F101,"screenc SCR_PT Z pct","",pct);
  7517.           case 'D':                     /* Data packet */
  7518.             if (fsiz > 0L) {            /* Show percent done if known */
  7519.                 oldpct = pct;           /* Remember previous percent */
  7520.                 howfar = ffc;
  7521. #ifdef CK_RESEND
  7522.                 if (what & W_SEND)    /* Account for PSEND or RESEND */
  7523.                   howfar += sendstart;
  7524.                 else if (what & W_RECV)
  7525.                   howfar += rs_len;
  7526. #endif /* CK_RESEND */
  7527.                 /* Percent done, to be displayed... */
  7528.                 if (c == 'Z') {
  7529.                     if (!discard && !cxseen && !czseen) pct = 100L;
  7530.                 } else
  7531.                   pct = (fsiz > 99L) ? (howfar / (fsiz / 100L)) : 0L;
  7532.                 if (pct > 100L ||       /* Allow for expansion and */
  7533.                    (oldpct == 99L && pct < 0L)) /* other boundary conditions */
  7534.                   pct = 100L;
  7535.                 if (pct != oldpct)      /* Only do this 100 times per file */
  7536.                   updpct(oldpct, pct);
  7537.             } else {
  7538.                 move(CW_PCD,22);
  7539.                 printw("%ld", ffc);
  7540.             }
  7541. #ifdef KUI
  7542. #ifndef K95G
  7543.             KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) howfar);
  7544. #endif /* K95G */
  7545. #endif /* KUI */
  7546.             cps = shocps((int) pct, fsiz, howfar);
  7547.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  7548.             break;
  7549.  
  7550.           case '%':                     /* Timeouts, retransmissions */
  7551.             cps = shocps((int) pct, fsiz, howfar);
  7552.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  7553.  
  7554.             errors = retrans + crunched + timeouts;
  7555.             if (errors != oldtry) {     /* Error count, if changed */
  7556.                 move(CW_PR, 22);
  7557.                 printw("%d",errors);
  7558.                 clrtoeol();
  7559. #ifdef KUI
  7560. #ifndef K95G
  7561.                 KuiSetProperty(KUI_FILE_TRANSFER,
  7562.                                (long) CW_PR, (long) errors
  7563.                                );
  7564. #endif /* K95G */
  7565. #endif /* KUI */
  7566.                 }
  7567.                 oldtry = errors;
  7568.                 if (s) if (*s) {
  7569.                     move(CW_ERR,22);
  7570.                     printw("%s",s);
  7571.                     clrtoeol();
  7572. #ifdef KUI
  7573. #ifndef K95G
  7574.                     KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_ERR, (long) s);
  7575. #endif /* K95G */
  7576. #endif /* KUI */
  7577.             }
  7578.             break;
  7579.  
  7580.           case 'E':                     /* Error packet */
  7581. #ifdef COMMENT
  7582.             move(CW_ERR,22);            /* Print its data field */
  7583.             if (*s) {
  7584.                 printw("%s",s);
  7585. #ifdef KUI
  7586. #ifndef K95G
  7587.                 KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  7588. #endif /* K95G */
  7589. #endif /* KUI */
  7590.             }
  7591.             clrtoeol();
  7592. #endif /* COMMENT */
  7593.             fcnt = fbyt = 0L;           /* So no bytes for this file */
  7594.             break;
  7595.           case 'Q':                     /* Crunched packet */
  7596.             cps = shocps((int) pct, fsiz, howfar);
  7597.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  7598.             move(CW_ERR,22);
  7599.             printw("Damaged Packet");
  7600. #ifdef KUI
  7601. #ifndef K95G
  7602.             KuiSetProperty(KUI_FILE_TRANSFER,
  7603.                            (long) CW_ERR,
  7604.                            (long) "Damaged Packet"
  7605.                            );
  7606. #endif /* K95G */
  7607. #endif /* KUI */
  7608.             clrtoeol();
  7609.             break;
  7610.           case 'q':                     /* Ctrl-C or connection lost */
  7611.             move(CW_MSG,22);
  7612.         clrtoeol();
  7613.             if (!s) s = "";
  7614.             printw(*s ? s : "User interruption or connection lost");
  7615. #ifdef KUI
  7616. #ifndef K95G
  7617.             KuiSetProperty(KUI_FILE_TRANSFER,
  7618.                            (long) CW_MSG,
  7619.                            (long) s
  7620.                            );
  7621. #endif /* K95G */
  7622. #endif /* KUI */
  7623.             break;
  7624.           case 'T':                     /* Timeout */
  7625.             cps = shocps((int) pct, fsiz, howfar);
  7626.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  7627.             move(CW_ERR,22);
  7628.             printw("Timeout %d sec",rcvtimo);
  7629. #ifdef KUI
  7630. #ifndef K95G
  7631.             KuiSetProperty(KUI_FILE_TRANSFER,
  7632.                            (long) CW_ERR,
  7633.                            (long) "Timeout"
  7634.                            );
  7635. #endif /* K95G */
  7636. #endif /* KUI */
  7637.             clrtoeol();
  7638.             errors = retrans + crunched + timeouts;
  7639.             if (errors != oldtry) {     /* Error count, if changed */
  7640.                 move(CW_PR, 22);
  7641.                 printw("%d",errors);
  7642. #ifdef KUI
  7643. #ifndef K95G
  7644.                 KuiSetProperty(KUI_FILE_TRANSFER,
  7645.                                (long) CW_PR, (long) errors
  7646.                                );
  7647. #endif /* K95G */
  7648. #endif /* KUI */
  7649.                 clrtoeol();
  7650.                 oldtry = errors;
  7651.             }
  7652.             break;
  7653.           default:                      /* Others, do nothing */
  7654.             break;
  7655.         }
  7656.         refresh();
  7657. #ifdef OS2
  7658.         SaveCmdMode(0, 0);
  7659. #endif /* OS2 */
  7660.         return;
  7661.  
  7662.       case SCR_ST:                      /* File transfer status */
  7663.         debug(F101,"screenc SCR_ST c","",c);
  7664.         debug(F101,"screenc SCR_ST success","",success);
  7665.         debug(F101,"screenc SCR_ST cxseen","",cxseen);
  7666. #ifdef COMMENT
  7667.         move(CW_PCD,22);                /* Update percent done */
  7668.         if (c == ST_OK) {               /* OK, print 100 % */
  7669.             if (pctlbl)
  7670.               updpct(oldpct,100);
  7671.             else
  7672.               printw("%ld", ffc);
  7673. #ifdef KUI
  7674. #ifndef K95G
  7675.             KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  7676. #endif /* K95G */
  7677. #endif /* KUI */
  7678.             pct = 100;
  7679.             oldpct = 0;
  7680.         } else if (fsiz > 0L)           /* Not OK, update final percent */
  7681. /*
  7682.   The else part writes all over the screen -- howfar and/or fsiz have
  7683.   been reset as a consequence of the not-OKness of the transfer.
  7684. */
  7685.           if (pctlbl)
  7686.             updpct(oldpct, (howfar * 100L) / fsiz);
  7687.         clrtoeol();
  7688. #else
  7689.         if (c == ST_OK) {               /* OK, print 100 % */
  7690.             move(CW_PCD,22);            /* Update percent done */
  7691.             if (pctlbl) {
  7692.         if (oldpct == 0)    /* Switching from "bytes so far" */
  7693.           clrtoeol();        /* to "percent done"... */
  7694.         updpct(oldpct,100);
  7695.         } else
  7696.               printw("%ld", ffc);
  7697. #ifdef KUI
  7698. #ifndef K95G
  7699.             KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  7700. #endif /* K95G */
  7701. #endif /* KUI */
  7702. #ifdef COMMENT
  7703.             pct = 100;
  7704.             oldpct = 0;
  7705. #endif /* COMMENT */
  7706.             clrtoeol();
  7707.         }
  7708. #endif /* COMMENT */
  7709.  
  7710. #ifdef COMMENT
  7711. /* No, leave it there so they can read it */
  7712.         move(CW_MSG,22);                /* Remove any previous message */
  7713. #ifdef KUI
  7714. #ifndef K95G
  7715.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_MSG, (long) "" );
  7716. #endif /* K95G */
  7717. #endif /* KUI */
  7718.         clrtoeol(); refresh();
  7719. #endif /* COMMENT */
  7720.  
  7721.         move(CW_TR, 22);
  7722. #ifdef KUI
  7723. #ifndef K95G
  7724.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_TR, (long) "" );
  7725. #endif /* K95G */
  7726. #endif /* KUI */
  7727.         clrtoeol(); refresh();
  7728.  
  7729.         switch (c) {                    /* Print new status message */
  7730.           case ST_OK:                   /* Transfer OK */
  7731.             fcnt++;                     /* Count this file */
  7732.         if (what == (W_FTP|W_FT_DELE)) {
  7733.         move(CW_MSG,22);
  7734.         clrtoeol();
  7735.         printw("Delete OK");
  7736.         } else {
  7737.         fbyt += ffc;
  7738.         move(CW_MSG,22);
  7739.         clrtoeol();
  7740.         printw("Transfer OK");
  7741.         }
  7742. #ifdef KUI
  7743. #ifndef K95G
  7744.             KuiSetProperty(KUI_FILE_TRANSFER,
  7745.                            (long) CW_MSG,
  7746.                            (long) "Transfer OK"
  7747.                            );
  7748. #endif /* K95G */
  7749. #endif /* KUI */
  7750.             clrtoeol(); refresh();
  7751.             return;
  7752.  
  7753.           case ST_DISC:                 /* Discarded */
  7754.             move(CW_ERR,22);
  7755.             printw("File discarded");
  7756. #ifdef KUI
  7757. #ifndef K95G
  7758.             KuiSetProperty(KUI_FILE_TRANSFER,
  7759.                            (long) CW_ERR,
  7760.                            (long) "File discarded"
  7761.                            );
  7762. #endif /* K95G */
  7763. #endif /* KUI */
  7764. #ifdef COMMENT
  7765.             pct = oldpct = 0;
  7766. #endif /* COMMENT */
  7767.             clrtoeol(); refresh();
  7768.             return;
  7769.  
  7770.           case ST_INT:                  /* Interrupted */
  7771.             move(CW_ERR,22);
  7772.             printw("Transfer interrupted");
  7773. #ifdef KUI
  7774. #ifndef K95G
  7775.             KuiSetProperty(KUI_FILE_TRANSFER,
  7776.                            (long) CW_ERR,
  7777.                            (long) "Transfer interrupted"
  7778.                            );
  7779. #endif /* K95G */
  7780. #endif /* KUI */
  7781. #ifdef COMMENT
  7782.             pct = oldpct = 0;
  7783. #endif /* COMMENT */
  7784.             clrtoeol(); refresh();
  7785.             return;
  7786.  
  7787.           case ST_SKIP:                 /* Skipped */
  7788.             move(CW_ERR,22);
  7789.         if (n > 0 && n < nskreason)
  7790.           printw("File skipped (%s)",skreason[n]);
  7791.         else
  7792.           printw("File skipped");
  7793. #ifdef KUI
  7794. #ifndef K95G
  7795.             KuiSetProperty(KUI_FILE_TRANSFER,
  7796.                            (long) CW_ERR,
  7797.                            (long) "File skipped"
  7798.                            );
  7799. #endif /* K95G */
  7800. #endif /* KUI */
  7801. #ifdef COMMENT
  7802.             pct = oldpct = 0;
  7803. #endif /* COMMENT */
  7804.             clrtoeol(); refresh();
  7805.             return;
  7806.  
  7807.           case ST_ERR:                  /* Error message */
  7808.             move(CW_ERR,22);
  7809.             if (!s) s = (char *)epktmsg;
  7810.             printw("%s",s);
  7811. #ifdef KUI
  7812. #ifndef K95G
  7813.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  7814. #endif /* K95G */
  7815. #endif /* KUI */
  7816. #ifdef COMMENT
  7817.             pct = oldpct = 0;
  7818. #endif /* COMMENT */
  7819.             clrtoeol(); refresh();
  7820.             return;
  7821.  
  7822.           case ST_REFU:                 /* Refused */
  7823.             move(CW_ERR,22);
  7824.             if (*s) {
  7825.                 char errbuf[64] ;
  7826.                 sprintf( errbuf, "Refused, %s", s ) ;
  7827.                 printw("%s", errbuf);
  7828. #ifdef KUI
  7829. #ifndef K95G
  7830.                 KuiSetProperty(KUI_FILE_TRANSFER,(long) CW_ERR,(long) errbuf);
  7831. #endif /* K95G */
  7832. #endif /* KUI */
  7833.             } else {
  7834.                 printw("Refused");
  7835. #ifdef KUI
  7836. #ifndef K95G
  7837.                 KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_ERR,(long)"Refused");
  7838. #endif /* K95G */
  7839. #endif /* KUI */
  7840.             }
  7841. #ifdef COMMENT
  7842.             pct = oldpct = 0;
  7843. #endif /* COMMENT */
  7844.             clrtoeol(); refresh();
  7845.             return;
  7846.  
  7847.           case ST_INC:
  7848.             move(CW_ERR,22);
  7849.             printw("Incomplete");
  7850. #ifdef KUI
  7851. #ifndef K95G
  7852.             KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_ERR,(long)"Incomplete");
  7853. #endif /* K95G */
  7854. #endif /* KUI */
  7855. #ifdef COMMENT
  7856.             pct = oldpct = 0;
  7857. #endif /* COMMENT */
  7858.             clrtoeol(); refresh();
  7859.             return;
  7860.  
  7861.           case ST_MSG:
  7862.             move(CW_MSG,22);
  7863.             printw("%s",s);
  7864. #ifdef KUI
  7865. #ifndef K95G
  7866.             KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_MSG,(long)s);
  7867. #endif /* K95G */
  7868. #endif /* KUI */
  7869.             clrtoeol(); refresh();
  7870.             return;
  7871.  
  7872.           default:                      /* Bad call */
  7873.             move(CW_ERR,22);
  7874.             printw("*** screen() called with bad status ***");
  7875. #ifdef KUI
  7876. #ifndef K95G
  7877.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR,
  7878.                        (long) "*** screen() called with bad status ***" );
  7879. #endif /* K95G */
  7880. #endif /* KUI */
  7881.             clrtoeol(); refresh(); return;
  7882.         }
  7883.  
  7884.       case SCR_TC: {                    /* Transaction complete */
  7885.           char msgbuf[128];
  7886.           move(CW_CP,22);               /* Overall transfer rate */
  7887. #ifdef KUI
  7888. #ifndef K95G
  7889.           KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, tfcps);
  7890. #endif /* K95G */
  7891. #endif /* KUI */
  7892.           printw("%ld", tfcps);
  7893.           clrtoeol();
  7894.           if (success) {
  7895.               move(CW_MSG,22);          /* Print statistics in message line */
  7896.               clrtoeol();
  7897.           }
  7898.           if (success) {
  7899.               sprintf(msgbuf,
  7900.                       "SUCCESS.  Files: %ld, Bytes: %ld, %ld CPS",
  7901.                       filcnt - filrej,
  7902.                       fbyt,
  7903.                       tfcps
  7904.                       );
  7905.               printw("%s", msgbuf);
  7906. #ifdef KUI
  7907. #ifndef K95G
  7908.               KuiSetProperty(KUI_FILE_TRANSFER,
  7909.                              (long) CW_MSG,
  7910.                              (long) msgbuf
  7911.                              );
  7912. #endif /* K95G */
  7913. #endif /* KUI */
  7914.               clrtoeol();
  7915.  
  7916.           }
  7917.           move(CW_TR, 1);
  7918.           printw("       Elapsed Time: %s",hhmmss((long)
  7919. #ifdef GFTIMER
  7920.                                                   (fptsecs + 0.5)
  7921. #else
  7922.                                                   tsecs
  7923. #endif /* GFTIMER */
  7924.                                                    ));
  7925. #ifdef KUI
  7926. #ifndef K95G
  7927.           KuiSetProperty(KUI_FILE_TRANSFER,
  7928.                          (long) CW_TR,
  7929.                          (long) hhmmss((long)
  7930. #ifdef GFTIMER
  7931.                                        (fptsecs + 0.5)
  7932. #else
  7933.                                        tsecs
  7934. #endif /* GFTIMER */
  7935.                                        ));
  7936. #endif /* K95G */
  7937. #endif /* KUI */
  7938.           clrtoeol();
  7939.           move(23,0); clrtoeol();       /* Clear instructions lines */
  7940.           move(22,0); clrtoeol();       /* to make room for prompt. */
  7941.           refresh();
  7942.  
  7943. #ifdef GFTIMER
  7944.           oldgtv = (CKFLOAT) -1.0;
  7945. #else
  7946.           oldgtv = -1L;
  7947. #endif /* GFTIMER */
  7948.  
  7949. #ifndef VMSCURSE
  7950.       debug(F100,"screenc endwin A","",0);
  7951.           endwin();
  7952. #ifdef COMMENT
  7953. /*
  7954.   Why and when was this call to conres() added?  It makes no sense,
  7955.   and it breaks echoing on Solaris 8.
  7956. */
  7957. #ifdef SOLARIS
  7958.           conres();
  7959. #endif /* SOLARIS */
  7960. #endif /* COMMENT */
  7961. #endif /* VMSCURSE */
  7962.  
  7963. #ifdef COMMENT
  7964.           pct = 100; oldpct = 0;        /* Reset these for next time. */
  7965. #endif /* COMMENT */
  7966.           oldtyp = 0; oldrtt = -1L; oldtry = -1; oldlen = -1;
  7967.           oldtim = -1;
  7968.           cendw = 1;
  7969.           if (xfrbel) bleep(BP_NOTE);   /* Close window, then beep. */
  7970. #ifdef UNIX
  7971.           fflush(stdout);
  7972. #endif /* UNIX */
  7973.           ft_win = 0;                   /* Window closed. */
  7974.           return;
  7975.       }
  7976.       case SCR_EM:                      /* Error packet (fatal) */
  7977.         move (CW_ERR,22);
  7978.         printw("FAILURE: %s",s);
  7979. #ifdef KUI
  7980. #ifndef K95G
  7981.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  7982. #endif /* K95G */
  7983. #endif /* KUI */
  7984.         if (xfrbel) bleep(BP_FAIL);
  7985. #ifdef COMMENT
  7986.         pct = oldpct = 0;
  7987. #endif /* COMMENT */
  7988.         clrtoeol(); refresh(); return;
  7989.  
  7990.       case SCR_QE:                      /* Quantity equals */
  7991.       case SCR_TU:                      /* Undelimited text */
  7992.       case SCR_TN:                      /* Text delimited at start */
  7993.       case SCR_TZ:                      /* Text delimited at end */
  7994.         return;                         /* (ignored in fullscreen display) */
  7995.  
  7996.       case SCR_XD:                      /* X-packet data */
  7997.         pct = oldpct = 0;
  7998.         move(CW_NAM,22);
  7999.         printw("%s",s);
  8000. #ifdef KUI
  8001. #ifndef K95G
  8002.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  8003. #endif /* K95G */
  8004. #endif /* KUI */
  8005.         clrtoeol(); refresh(); return;
  8006.  
  8007.       case SCR_CW:                      /* Close Window */
  8008.         clrtoeol(); move(23,0); clrtoeol(); move(22,0); clrtoeol();
  8009.         refresh();
  8010. #ifdef COMMENT
  8011.         pct = 100; oldpct = 0;          /* Reset these for next time. */
  8012. #endif /* COMMENT */
  8013.         oldtyp = 0; oldrtt = -1L; oldtry = -1; oldlen = -1;
  8014.         oldtim = -1;
  8015.  
  8016. #ifndef VMSCURSE
  8017.     debug(F100,"screenc endwin B","",0);
  8018.         endwin();
  8019. #endif /* VMSCURSE */
  8020.         ft_win = 0;                     /* Flag that window is closed. */
  8021.         cendw = 1; return;
  8022.  
  8023.       case SCR_CD:                      /* Display current directory */
  8024.         move(CW_DIR,22);
  8025.          printw("%s", s);
  8026. #ifdef KUI
  8027. #ifndef K95G
  8028.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_DIR, (long) s );
  8029. #endif /* K95G */
  8030. #endif /* KUI */
  8031.         clrtoeol();
  8032.         refresh();
  8033. #ifdef OS2
  8034.         SaveCmdMode(0, 0);
  8035. #endif /* OS2 */
  8036.         return;
  8037.  
  8038.       default:                          /* Bad call */
  8039.         move (CW_ERR,22);
  8040. #ifdef KUI
  8041. #ifndef K95G
  8042.         KuiSetProperty(KUI_FILE_TRANSFER,
  8043.                        (long) CW_ERR,
  8044.                        (long) "*** screen() called with bad function code ***"
  8045.                        );
  8046. #endif /* K95G */
  8047. #endif /* KUI */
  8048.         printw("*** screen() called with bad function code ***");
  8049.         clrtoeol(); refresh(); return;
  8050.     }
  8051. }
  8052. #endif /* CK_CURSES */
  8053.  
  8054. #ifdef KUI
  8055. #ifdef CK_ANSIC
  8056. void
  8057. screeng(int f, char c,long n,char *s)
  8058. #else
  8059. VOID
  8060. screeng(f,c,n,s)
  8061. int f;          /* argument descriptor */
  8062. char c;         /* a character or small integer */
  8063. long n;         /* a long integer */
  8064. char *s;        /* a string */
  8065. #endif /* CK_ANSIC */
  8066. /* screeng() */ {
  8067. #ifdef CK_SSL
  8068.     extern int tls_active_flag, ssl_active_flag;
  8069. #endif /* CK_SSL */
  8070. #ifdef RLOGCODE
  8071.     extern int ttnproto;
  8072. #endif /* RLOGCODE */
  8073.     static int q = 0;
  8074.     static long fsiz = -1L;   /* Copy of file size */
  8075.     static long fcnt = 0L;    /* Number of files transferred */
  8076.     static long fbyt = 0L;    /* Total file bytes of all files transferred */
  8077.     static long howfar = 0L;  /* How much of current file has been xfer'd. */
  8078.     static int  pctlbl = 0L;  /* Percent done vs Bytes so far */
  8079.     long cps = 0L;
  8080.  
  8081.     int net = 0;
  8082.     int xnet = 0;
  8083.     int ftp = 0;
  8084.     int len;                            /* Length of string */
  8085.     int errors = 0;                     /* Error counter */
  8086.     int x;                              /* Worker */
  8087.  
  8088.     debug(F101,"screeng cinit","",cinit);
  8089.     debug(F101,"screeng cendw","",cendw);
  8090.  
  8091.     if (!s) s = "";                     /* Always do this. */
  8092.  
  8093.     ftp = (what & W_FTP) ? 1 : 0;    /* FTP or Kermit */
  8094.     net = network || ftp;
  8095.     xnet = ftp ? 1 : nettype;        /* NET_TCPB == 1 */
  8096.  
  8097.     if (cinit == 0 || cendw > 0) {      /* Handle borderline cases... */
  8098.         if (f == SCR_CW) {              /* Close window, but it's not open */
  8099.             ft_win = 0;
  8100.             return;
  8101.         }
  8102.         debug(F111,"screeng A",s,f);
  8103.         if (f == SCR_EM ||
  8104.            (f == SCR_PT && c == 'E')) { /* Fatal error before window open */
  8105.             conoll(""); conoc('?'); conoll(s); return; /* Regular display */
  8106.         }
  8107.     }
  8108.     if (cinit == 0) {                   /* Only call initscr() once */
  8109.     /* Check these now -- if they are defined but not numeric */
  8110.     /* they can crash curses */
  8111.         cendw = 1;                      /* New window needs repainting */
  8112.         debug(F100,"screeng calling initscr","",0);
  8113.         initscr();                      /* Initialize curses. */
  8114.         debug(F100,"screeng initscr ok","",0);
  8115.         cinit++;                        /* Remember curses was initialized. */
  8116.     }
  8117.     ft_win = 1;                         /* Window is open */
  8118.     if (repaint) {
  8119. #ifdef CK_WREFRESH
  8120. /*
  8121.   This totally repaints the screen, just what we want, but we can only
  8122.   do this with real curses, and then only if clearok() and wrefresh() are
  8123.   provided in the curses library.
  8124. */
  8125.         RestoreCmdMode();
  8126. #else  /* No CK_WREFRESH */
  8127. /*
  8128.   Kermit's do-it-yourself method, works with all types of fullscreen
  8129.   support, but does not repaint all the fields.  For example, the filename
  8130.   is lost, because it arrives at a certain time and never comes again, and
  8131.   Kermit presently does not save it anywhere.  Making this method work for
  8132.   all fields would be a rather major recoding task, duplicating what curses
  8133.   already does, and would add a lot of complexity and storage space.
  8134. */
  8135.         cendw = 1;
  8136. #endif /* CK_WREFRESH */
  8137.         repaint = 0;
  8138.     }
  8139.     if (cendw) {                        /* endwin() was called previously */
  8140.         debug(F100,"screeng setup ok","",0);
  8141.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_DIR, (long) zgtdir() );
  8142.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_LIN,
  8143.                         (long) (
  8144. #ifdef NEWFTP
  8145.                                 ftp ? (ftp_host ? ftp_host : "(unknown)") :
  8146. #endif /* NEWFTP */
  8147.                                 ttname) );
  8148.  
  8149.         if (net) {
  8150. #ifdef NETCONN
  8151.         int secure = 0;
  8152.         char * xname;
  8153.         if (xnet > nnetname)
  8154.           xname = "[ERROR]";
  8155.         else
  8156.           xname = netname[xnet];
  8157. #ifdef NEWFTP
  8158.             if (ftp) {
  8159.         if (ftpissecure())
  8160.           secure = 1;
  8161.         } else
  8162. #endif /* NEWFTP */
  8163.           if (0
  8164. #ifdef SSHBUILTIN
  8165.                 || IS_SSH()
  8166. #endif /* SSHBUILTIN */
  8167. #ifdef CK_ENCRYPTION
  8168.                 || ck_tn_encrypting() && ck_tn_decrypting()
  8169. #endif /* CK_ENCRYPTION */
  8170. #ifdef CK_SSL
  8171.                 || tls_active_flag || ssl_active_flag
  8172. #endif /* CK_SSL */
  8173. #ifdef RLOGCODE
  8174. #ifdef CK_KERBEROS
  8175. #ifdef CK_ENCRYPTION
  8176.                 || ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN
  8177. #endif /* CK_ENCRYPTION */
  8178. #endif /* CK_KERBEROS */
  8179. #endif /* RLOGCODE */
  8180.                  ) {
  8181.         secure = 1;
  8182.         }
  8183.         if (secure) {
  8184.                 char buf[30];
  8185.                 sprintf(buf,"%s (SECURE)",xname);
  8186.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8187.                                (long) CW_SPD,
  8188.                                (long) buf
  8189.                                );
  8190.             } else {
  8191.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8192.                                (long) CW_SPD,
  8193.                                (long) xname
  8194.                                );
  8195.             }
  8196. #else
  8197.             KuiSetProperty(KUI_FILE_TRANSFER,
  8198.                            (long) CW_SPD,
  8199.                            (long) "(network)"
  8200.                            );
  8201. #endif /* NETCONN */
  8202.         } else {
  8203.             if (speed < 0L)
  8204.               speed = ttgspd();
  8205.             if (speed > 0L) {
  8206.                 if (speed == 8880) {
  8207.                     KuiSetProperty(KUI_FILE_TRANSFER,
  8208.                                    (long) CW_SPD,
  8209.                                    (long) "75/1200"
  8210.                                    );
  8211.                 } else {
  8212.                     char speedbuf[64] ;
  8213.                     sprintf(speedbuf, "%ld", speed);
  8214.                     KuiSetProperty(KUI_FILE_TRANSFER,
  8215.                                    (long) CW_SPD,
  8216.                                    (long) speedbuf
  8217.                                    );
  8218.                 }
  8219.             } else {
  8220.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8221.                                (long) CW_SPD,
  8222.                                (long) "(unknown)"
  8223.                                );
  8224.             }
  8225.         }
  8226.         KuiSetProperty(KUI_FILE_TRANSFER,
  8227.                        (long) CW_PAR,
  8228.                        (long) parnam((char)parity)
  8229.                        );
  8230.         pctlbl = (what & W_SEND);
  8231.         cendw = 0;
  8232.     }
  8233.     debug(F101,"SCREENC switch","",f);
  8234.     debug(F000,"SCREENC c","",c);
  8235.     debug(F101,"SCREENC n","",n);
  8236.  
  8237.     len = strlen(s);                    /* Length of argument string */
  8238.     switch (f) {                        /* Handle our function code */
  8239.       case SCR_FN:                      /* Filename */
  8240.         oldpct = pct = 0L;              /* Reset percents */
  8241. #ifdef GFTIMER
  8242.         gtv = (CKFLOAT) -1.0;
  8243.         /* oldgtv = (CKFLOAT) -1.0; */
  8244. #else
  8245.         gtv = -1L;
  8246.         /* oldgtv = -1L; */
  8247. #endif /* GFTIMER */
  8248.         oldwin = -1;
  8249.         fsiz = -1L;                     /* Invalidate previous file size */
  8250.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PCD, (long) 0 );
  8251.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_FFC, (long) 0 );
  8252.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_SIZ, (long) 0 );
  8253.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) "" );
  8254.  
  8255.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  8256.         q = len;                        /* Remember name length for later */
  8257.         scrft();                        /* Display file type (can change) */
  8258. #ifdef OS2
  8259.         SaveCmdMode(0, 0);
  8260. #endif /* OS2 */
  8261.         return;
  8262.  
  8263.       case SCR_AN:                      /* File as-name */
  8264.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  8265. #ifdef OS2
  8266.         SaveCmdMode(0, 0);
  8267. #endif /* OS2 */
  8268.         return;
  8269.  
  8270.       case SCR_FS:                      /* File size */
  8271.         fsiz = n;
  8272.         if (fsiz > -1L) {
  8273.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_SIZ, (long) n );
  8274.         }
  8275.         if (fsiz > -1L) {               /* Put up percent label */
  8276.             pctlbl = 1;
  8277.         } else {
  8278.             pctlbl = 0;
  8279.     }
  8280.         scrft();                        /* File type */
  8281. #ifdef OS2
  8282.         SaveCmdMode(0, 0);
  8283. #endif /* OS2 */
  8284.         return;
  8285.  
  8286.       case SCR_PT:                      /* Packet type or pseudotype */
  8287.         if (spackets < 5) {
  8288.             extern int sysindex;
  8289.             extern struct sysdata sysidlist[];
  8290.             /* Things that won't change after the 4th packet */
  8291.             KuiSetProperty( KUI_FILE_TRANSFER,
  8292.                            (long) CW_PAR,
  8293.                            (long) parnam((char)parity)
  8294.                            );
  8295.             if (
  8296. #ifdef NEWFTP
  8297.         (ftp && (spackets == 1 || rpackets == 1)) ||
  8298. #endif /* NEWFTP */
  8299.         spackets == 4
  8300.         ) {
  8301.                 if (
  8302. #ifdef NEWFTP
  8303.             ftp ||
  8304. #endif /* NEWFTP */
  8305.             ((protocol == PROTO_K) && (sysindex > -1))
  8306.             ) {
  8307.                     char msgbuf[128];
  8308.                     if (net) {
  8309.                         sprintf(msgbuf,"Network Host: %s (%s)",
  8310. #ifdef NEWFTP
  8311.                    ftp ? (ftp_host ? ftp_host : "") :
  8312. #endif /* NEWFTP */
  8313.                    ttname,
  8314. #ifdef NEWFTP
  8315.                    ftp ? ftp_srvtyp :
  8316. #endif /* NEWFTP */
  8317.                    sysidlist[sysindex].sid_name
  8318.                    );
  8319.                     } else {
  8320.                         sprintf(msgbuf,
  8321.                 "Communication Device: %s (remote host is %s)",
  8322.                 ttname,
  8323.                 sysidlist[sysindex].sid_name
  8324.                 );
  8325.                     }
  8326.                     KuiSetProperty( KUI_FILE_TRANSFER,
  8327.                     (long) CW_LIN,
  8328.                     (long) msgbuf
  8329.                     );
  8330.                 }
  8331.             }
  8332.         }
  8333. #ifdef CK_TIMERS
  8334.         if (/* rttflg && */ protocol == PROTO_K) {
  8335.             long xx;
  8336.             if (
  8337. #ifdef STREAMING
  8338.                 streaming && oldwin != -2
  8339. #else
  8340.                 0
  8341. #endif /* STREAMING */
  8342.                 ) {
  8343.                 char msgbuf[64];
  8344.                 sprintf(msgbuf,"00 / 00");
  8345.                 KuiSetProperty( KUI_FILE_TRANSFER,
  8346.                 (long) CW_TMO,
  8347.                 (long) msgbuf
  8348.                 );
  8349.             } else {
  8350.                 xx = (rttdelay + 500) / 1000;
  8351.                 if (xx != oldrtt || rcvtimo != oldtim) {
  8352.                     char msgbuf[64];
  8353.                     sprintf(msgbuf,"%02ld / %02d", xx, rcvtimo);
  8354.                     KuiSetProperty( KUI_FILE_TRANSFER,
  8355.                     (long) CW_TMO,
  8356.                     (long) msgbuf
  8357.                     );
  8358.                     oldrtt = xx;
  8359.                     oldtim = rcvtimo;
  8360.                     clrtoeol();
  8361.                 }
  8362.             }
  8363.         }
  8364. #endif /* CK_TIMERS */
  8365.  
  8366.         x = (what & W_RECV) ?          /* Packet length */
  8367.           rpktl+(protocol==PROTO_K?1:0) :
  8368.             spktl;
  8369.         if (x != oldlen) {              /* But only if it changed. */
  8370.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PL, (long) x );
  8371.             oldlen = x;
  8372.         }
  8373.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PC, (long) spackets );
  8374.  
  8375.         if (protocol == PROTO_K && !ftp) { /* Window slots */
  8376.             char ws[16];
  8377.             int flag;
  8378.             flag = 0;
  8379. #ifdef STREAMING
  8380.             if (streaming) {
  8381.                 if (oldwin != -2) {
  8382.                     sprintf(ws,"STREAMING");
  8383.                     flag = 1;
  8384.                     oldwin = -2;
  8385.                 }
  8386.             } else
  8387. #endif /* STREAMING */
  8388.               if (wcur != oldwin) {
  8389.                   sprintf(ws, "%d of %d", wcur < 1 ? 1 : wcur, wslotn);
  8390.                   flag = 1;
  8391.                   oldwin = wcur;
  8392.               }
  8393.             if (flag) {
  8394.                 KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_WS, (long) ws );
  8395.             }
  8396.         }
  8397.         errors = retrans + crunched + timeouts;
  8398.         if (errors != oldtry) {         /* Retry count, if changed */
  8399.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PR, (long) errors );
  8400.             oldtry = errors;
  8401.         }
  8402.     /* Sender's packet type */
  8403.         if (!ftp && (c != oldtyp && c != 'Y' && c != 'N')) {
  8404.             char type[2];
  8405.             sprintf(type, "%c",c);
  8406.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_PT, (long) type );
  8407.             oldtyp = c;
  8408.         }
  8409.         switch (c) {                    /* Now handle specific packet types */
  8410.           case 'S':                     /* Beginning of transfer */
  8411.             fcnt = fbyt = 0L;           /* Clear counters */
  8412. #ifdef GFTIMER
  8413.             gtv = -1.0;
  8414. #else /* GFTIMER */
  8415.             gtv = -1L;                  /* And old/new things... */
  8416. #endif /* GFTIMER */
  8417.             oldpct = pct = 0L;
  8418.             break;
  8419.  
  8420.           case 'Z':                     /* or EOF */
  8421.             debug(F101,"screeng SCR_PT Z pktnum","",n);
  8422.             debug(F101,"screeng SCR_PT Z oldpct","",oldpct);
  8423.             debug(F101,"screeng SCR_PT Z pct","",pct);
  8424.           case 'D':                     /* Data packet */
  8425.             if (fsiz > 0L) {            /* Show percent done if known */
  8426.                 oldpct = pct;           /* Remember previous percent */
  8427.                 howfar = ffc;
  8428. #ifdef CK_RESEND
  8429.                 if (what & W_SEND)    /* Account for PSEND or RESEND */
  8430.                   howfar += sendstart;
  8431.                 else if (what & W_RECV)
  8432.                   howfar += rs_len;
  8433. #endif /* CK_RESEND */
  8434.                 /* Percent done, to be displayed... */
  8435.                 if (c == 'Z') {
  8436.                     if (!discard && !cxseen && !czseen) pct = 100L;
  8437.                 } else
  8438.                   pct = (fsiz > 99L) ? (howfar / (fsiz / 100L)) : 0L;
  8439.                 if (pct > 100L ||       /* Allow for expansion and */
  8440.                    (oldpct == 99L && pct < 0L)) /* other boundary conditions */
  8441.                   pct = 100L;
  8442.                 if (pct != oldpct)      /* Only do this 100 times per file */
  8443.                   updpct(oldpct, pct);
  8444.             } else {
  8445.                 KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  8446.             }
  8447.             KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) howfar);
  8448.             cps = shocps((int) pct, fsiz, howfar);
  8449.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  8450.             break;
  8451.  
  8452.           case '%':                     /* Timeouts, retransmissions */
  8453.             cps = shocps((int) pct, fsiz, howfar);
  8454.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  8455.  
  8456.             errors = retrans + crunched + timeouts;
  8457.             if (errors != oldtry) {     /* Error count, if changed */
  8458.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8459.                                (long) CW_PR,
  8460.                    (long) errors
  8461.                                );
  8462.                 }
  8463.                 oldtry = errors;
  8464.                 if (s) if (*s) {
  8465.                     KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_ERR, (long) s);
  8466.             }
  8467.             break;
  8468.  
  8469.           case 'E':                     /* Error packet */
  8470.             if (*s) {
  8471.                 KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  8472.             }
  8473.             fcnt = fbyt = 0L;           /* So no bytes for this file */
  8474.             break;
  8475.           case 'Q':                     /* Crunched packet */
  8476.             cps = shocps((int) pct, fsiz, howfar);
  8477.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  8478.             KuiSetProperty(KUI_FILE_TRANSFER,
  8479.                            (long) CW_ERR,
  8480.                            (long) "Damaged Packet"
  8481.                            );
  8482.             break;
  8483.           case 'q':                     /* Ctrl-C or connection lost */
  8484.             if (!s) s = "";
  8485.             if (!*s) s = "User interruption or connection lost";
  8486.             KuiSetProperty(KUI_FILE_TRANSFER,
  8487.                            (long) CW_MSG,
  8488.                            (long) s
  8489.                            );
  8490.             break;
  8491.           case 'T':                     /* Timeout */
  8492.             cps = shocps((int) pct, fsiz, howfar);
  8493.             /* old_tr = shoetl(old_tr, cps, fsiz, howfar); */
  8494.             KuiSetProperty(KUI_FILE_TRANSFER,
  8495.                            (long) CW_ERR,
  8496.                            (long) "Timeout"
  8497.                            );
  8498.             errors = retrans + crunched + timeouts;
  8499.             if (errors != oldtry) {     /* Error count, if changed */
  8500.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8501.                                (long) CW_PR, (long) errors
  8502.                                );
  8503.                 oldtry = errors;
  8504.             }
  8505.             break;
  8506.           default:                      /* Others, do nothing */
  8507.             break;
  8508.         }
  8509. #ifdef OS2
  8510.         SaveCmdMode(0, 0);
  8511. #endif /* OS2 */
  8512.         return;
  8513.  
  8514.       case SCR_ST:                      /* File transfer status */
  8515.         debug(F101,"screeng SCR_ST c","",c);
  8516.         debug(F101,"screeng SCR_ST success","",success);
  8517.         debug(F101,"screeng SCR_ST cxseen","",cxseen);
  8518. #ifdef COMMENT
  8519.         if (c == ST_OK) {               /* OK, print 100 % */
  8520.             if (pctlbl)
  8521.               updpct(oldpct,100);
  8522.             else
  8523.                 KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  8524.             pct = 100;
  8525.             oldpct = 0;
  8526.         } else if (fsiz > 0L)           /* Not OK, update final percent */
  8527. /*
  8528.   The else part writes all over the screen -- howfar and/or fsiz have
  8529.   been reset as a consequence of the not-OKness of the transfer.
  8530. */
  8531.           if (pctlbl)
  8532.             updpct(oldpct, (howfar * 100L) / fsiz);
  8533. #else
  8534.         if (c == ST_OK) {               /* OK, print 100 % */
  8535.             if (pctlbl) {
  8536.         updpct(oldpct,100);
  8537.         } else
  8538.                 KuiSetProperty(KUI_FILE_TRANSFER, (long) CW_FFC, (long) ffc);
  8539. #ifdef COMMENT
  8540.             pct = 100;
  8541.             oldpct = 0;
  8542. #endif /* COMMENT */
  8543.         }
  8544. #endif /* COMMENT */
  8545.  
  8546.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_TR, (long) "" );
  8547.  
  8548.         switch (c) {                    /* Print new status message */
  8549.           case ST_OK:                   /* Transfer OK */
  8550.             fcnt++;                     /* Count this file */
  8551.         if (what == (W_FTP|W_FT_DELE)) {
  8552.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8553.                                 (long) CW_MSG,
  8554.                                 (long) "Delete OK"
  8555.                                 );
  8556.         } else {
  8557.         fbyt += ffc;
  8558.                 KuiSetProperty(KUI_FILE_TRANSFER,
  8559.                                 (long) CW_MSG,
  8560.                                 (long) "Transfer OK"
  8561.                                 );
  8562.         }
  8563.             return;
  8564.  
  8565.           case ST_DISC:                 /* Discarded */
  8566.             KuiSetProperty(KUI_FILE_TRANSFER,
  8567.                            (long) CW_ERR,
  8568.                            (long) "File discarded"
  8569.                            );
  8570. #ifdef COMMENT
  8571.             pct = oldpct = 0;
  8572. #endif /* COMMENT */
  8573.             return;
  8574.  
  8575.           case ST_INT:                  /* Interrupted */
  8576.             KuiSetProperty(KUI_FILE_TRANSFER,
  8577.                            (long) CW_ERR,
  8578.                            (long) "Transfer interrupted"
  8579.                            );
  8580. #ifdef COMMENT
  8581.             pct = oldpct = 0;
  8582. #endif /* COMMENT */
  8583.             return;
  8584.  
  8585.         case ST_SKIP: {                /* Skipped */
  8586.             char errbuf[64] ;
  8587.         if (n > 0 && n < nskreason)
  8588.                 sprintf( errbuf, "File skipped, (%s)", skreason[n] ) ;
  8589.         else
  8590.                 sprintf( errbuf, "File skipped" ) ;
  8591.             KuiSetProperty(KUI_FILE_TRANSFER,
  8592.                            (long) CW_ERR,
  8593.                            (long) errbuf
  8594.                            );
  8595. #ifdef COMMENT
  8596.             pct = oldpct = 0;
  8597. #endif /* COMMENT */
  8598.             return;
  8599.         }
  8600.           case ST_ERR:                  /* Error message */
  8601.             if (!s) s = (char *)epktmsg;
  8602.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  8603. #ifdef COMMENT
  8604.             pct = oldpct = 0;
  8605. #endif /* COMMENT */
  8606.             return;
  8607.  
  8608.           case ST_REFU:                 /* Refused */
  8609.             if (*s) {
  8610.                 char errbuf[64] ;
  8611.                 sprintf( errbuf, "Refused, %s", s ) ;
  8612.                 KuiSetProperty(KUI_FILE_TRANSFER,(long) CW_ERR,(long) errbuf);
  8613.             } else {
  8614.                 KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_ERR,(long)"Refused");
  8615.             }
  8616. #ifdef COMMENT
  8617.             pct = oldpct = 0;
  8618. #endif /* COMMENT */
  8619.             return;
  8620.  
  8621.           case ST_INC:
  8622.             KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_ERR,(long)"Incomplete");
  8623. #ifdef COMMENT
  8624.             pct = oldpct = 0;
  8625. #endif /* COMMENT */
  8626.             return;
  8627.  
  8628.           case ST_MSG:
  8629.             KuiSetProperty(KUI_FILE_TRANSFER,(long)CW_MSG,(long)s);
  8630.             return;
  8631.  
  8632.           default:                      /* Bad call */
  8633.             KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR,
  8634.                        (long) "*** screen() called with bad status ***" );
  8635.             return;
  8636.         }
  8637.  
  8638.       case SCR_TC: {                    /* Transaction complete */
  8639.           char msgbuf[128];
  8640.           KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_CP, tfcps);
  8641.           if (success) {
  8642.               sprintf(msgbuf,
  8643.                       "SUCCESS.  Files: %ld, Bytes: %ld, %ld CPS",
  8644.                       filcnt - filrej,
  8645.                       fbyt,
  8646.                       tfcps
  8647.                       );
  8648.               KuiSetProperty(KUI_FILE_TRANSFER,
  8649.                              (long) CW_MSG,
  8650.                              (long) msgbuf
  8651.                              );
  8652.           }
  8653.           KuiSetProperty(KUI_FILE_TRANSFER,
  8654.                          (long) CW_TR,
  8655.                          (long) hhmmss((long)
  8656. #ifdef GFTIMER
  8657.                                        (fptsecs + 0.5)
  8658. #else
  8659.                                        tsecs
  8660. #endif /* GFTIMER */
  8661.                                        ));
  8662.  
  8663. #ifdef GFTIMER
  8664.           oldgtv = (CKFLOAT) -1.0;
  8665. #else
  8666.           oldgtv = -1L;
  8667. #endif /* GFTIMER */
  8668.  
  8669. #ifdef COMMENT
  8670.           pct = 100; oldpct = 0;        /* Reset these for next time. */
  8671. #endif /* COMMENT */
  8672.           oldtyp = 0; oldrtt = -1L; oldtry = -1; oldlen = -1;
  8673.           oldtim = -1;
  8674.           cendw = 1;
  8675.           if (xfrbel) bleep(BP_NOTE);   /* Close window, then beep. */
  8676.           ft_win = 0;                   /* Window closed. */
  8677.           return;
  8678.       }
  8679.       case SCR_EM:                      /* Error packet (fatal) */
  8680.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_ERR, (long) s );
  8681.         if (xfrbel) bleep(BP_FAIL);
  8682. #ifdef COMMENT
  8683.         pct = oldpct = 0;
  8684. #endif /* COMMENT */
  8685.         return;
  8686.  
  8687.       case SCR_QE:                      /* Quantity equals */
  8688.       case SCR_TU:                      /* Undelimited text */
  8689.       case SCR_TN:                      /* Text delimited at start */
  8690.       case SCR_TZ:                      /* Text delimited at end */
  8691.         return;                         /* (ignored in fullscreen display) */
  8692.  
  8693.       case SCR_XD:                      /* X-packet data */
  8694.         pct = oldpct = 0;
  8695.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_NAM, (long) s );
  8696.         return;
  8697.  
  8698.       case SCR_CW:                      /* Close Window */
  8699. #ifdef COMMENT
  8700.         pct = 100; oldpct = 0;          /* Reset these for next time. */
  8701. #endif /* COMMENT */
  8702.         oldtyp = 0; oldrtt = -1L; oldtry = -1; oldlen = -1;
  8703.         oldtim = -1;
  8704.  
  8705.         ft_win = 0;                     /* Flag that window is closed. */
  8706.         cendw = 1; return;
  8707.  
  8708.       case SCR_CD:                      /* Display current directory */
  8709.         KuiSetProperty( KUI_FILE_TRANSFER, (long) CW_DIR, (long) s );
  8710. #ifdef OS2
  8711.         SaveCmdMode(0, 0);
  8712. #endif /* OS2 */
  8713.         return;
  8714.  
  8715.       default:                          /* Bad call */
  8716.         KuiSetProperty(KUI_FILE_TRANSFER,
  8717.                        (long) CW_ERR,
  8718.                        (long) "*** screen() called with bad function code ***"
  8719.                        );
  8720.         return;
  8721.     }
  8722. }
  8723. #endif /* KUI */
  8724. #endif /* MAC */
  8725.  
  8726. #endif /* NOXFER */
  8727.  
  8728. #ifndef CK_CURPOS
  8729. /* Dummies for when cursor control is not supported */
  8730. int
  8731. ck_curpos(row, col) {
  8732.     return(-1);
  8733. }
  8734.  
  8735. int
  8736. ck_cls() {
  8737.     return(-1);
  8738. }
  8739.  
  8740. int
  8741. ck_cleol() {
  8742.     return(-1);
  8743. }
  8744. #endif /* CK_CURPOS */
  8745.  
  8746. #ifndef NOIKSD
  8747. #ifdef IKSDB
  8748.  
  8749. struct iksdbfld dbfld[] = {
  8750.    /* Offset    Length    Type   */
  8751.     { DB_FLAGS, dB_FLAGS, DBT_HEX },    /*  0 db_FLAGS Flags */
  8752.     { DB_ATYPE, dB_ATYPE, DBT_HEX },    /*  1 db_ATYPE Auth type */
  8753.     { DB_AMODE, dB_AMODE, DBT_HEX },    /*  3 db_AMODE Auth mode */
  8754.     { DB_STATE, dB_STATE, DBT_HEX },    /*  2 db_STATE State */
  8755.     { DB_MYPID, dB_MYPID, DBT_HEX },    /*  5 db_MYPID PID */
  8756.     { DB_SADDR, dB_SADDR, DBT_HEX },    /*  4 db_SADDR Server address */
  8757.     { DB_CADDR, dB_CADDR, DBT_HEX },    /*  6 db_CADDR Client address */
  8758.     { DB_START, dB_START, DBT_DAT },    /*  7 db_START Session start */
  8759.     { DB_LASTU, dB_LASTU, DBT_DAT },    /*  8 db_LASTU Last update */
  8760.     { DB_ULEN,  dB_ULEN,  DBT_HEX },    /*  9 db_ULEN  Username length */
  8761.     { DB_DLEN,  dB_DLEN,  DBT_HEX },    /* 10 db_DLEN  Directory name length */
  8762.     { DB_ILEN,  dB_ILEN,  DBT_HEX },    /* 11 db_ILEN  Info length */
  8763.     { DB_PAD1,  dB_PAD1,  DBT_UND },    /* 12 db_PAD1  (Reserved) */
  8764.     { DB_USER,  dB_USER,  DBT_STR },    /* 13 db_USER  Username */
  8765.     { DB_DIR,   dB_DIR,   DBT_STR },    /* 14 db_DIR   Current Directory */
  8766.     { DB_INFO,  dB_INFO,  DBT_STR }     /* 15 db_INFO  State-specific info */
  8767. };
  8768.  
  8769. static char lcknam[CKMAXPATH+1];        /* Lockfile pathname */
  8770. static char tmplck[CKMAXPATH+1];        /* Temporary lockfile name */
  8771.  
  8772. static char * updmode =                 /* Update mode for fopen() */
  8773. #ifdef OS2
  8774.   "r+b"
  8775. #else
  8776. #ifdef VMS
  8777.   "r+b"
  8778. #else
  8779.   "r+"
  8780. #endif /* VMS */
  8781. #endif /* OS2 */
  8782.   ;
  8783.  
  8784. /*  D B I N I T  --  Initialize the IKSD database...  */
  8785.  
  8786. int
  8787. dbinit() {
  8788.     extern int dbinited;
  8789.     int x = 0;
  8790.     debug(F110,"dbinit dbdir 1",dbdir,0);
  8791.     debug(F110,"dbinit dbfile 1",dbfile,0);
  8792.     if (dbinited)
  8793.       return(0);
  8794. #ifdef OS2
  8795.     if (!dbdir) {
  8796. #ifdef NT
  8797.         char * p = NULL;
  8798.         if (!isWin95()) {
  8799.             p = getenv("SystemRoot");
  8800.         } else {
  8801.             p = getenv("winbootdir");
  8802.             if (!p)  p = getenv("windir");
  8803.         }
  8804.         if (!p) p = "C:/";
  8805.         dbdir = malloc(strlen(p)+2);
  8806.         strcpy(dbdir,p);        /* safe */
  8807.         p = dbdir;
  8808.         while (*p) {
  8809.             if (*p == '\\')
  8810.               *p = '/';
  8811.             p++;
  8812.         }
  8813.         if (*(p-1) != '/' ) {
  8814.             *p++ = '/';
  8815.             *p = '\0';
  8816.         }
  8817. #else /* NT */
  8818.         makestr(&dbdir,"C:/");
  8819. #endif /* NT */
  8820.     }
  8821. #else /* OS2 */
  8822.     if (!dbdir)
  8823.       makestr(&dbdir,IK_DBASEDIR);
  8824. #endif /* OS2 */
  8825.  
  8826.     if (!dbfile) {
  8827.         char * s = "";
  8828.         x = strlen(dbdir);
  8829.         if (dbdir[x-1] != '/') {
  8830.             s = "/";
  8831.             x++;
  8832.         }
  8833.         x += (int)strlen(IK_DBASEFIL);
  8834.         dbfile = (char *)malloc(x+1);
  8835.         sprintf(dbfile,"%s%s%s",dbdir,s,IK_DBASEFIL);
  8836.     }
  8837.     debug(F110,"dbinit dbdir 2",dbdir,0);
  8838.     debug(F110,"dbinit dbfile 2",dbfile,0);
  8839.     mypid = getpid();                   /* Get my pid */
  8840.     debug(F101,"dbinit mypid","",mypid);
  8841.  
  8842.     if (!myhexip[0]) {                  /* Set my hex IP address */
  8843. #ifdef TCPSOCKET
  8844.         extern unsigned long myxipaddr;
  8845.         if (getlocalipaddr() > -1) {
  8846.             myip = myxipaddr;
  8847.             sprintf(myhexip,"%08lx",myip); /* (Needs fixing for IPv6) */
  8848.         } else
  8849. #endif /* TCPSOCKET */
  8850.           ckstrncpy(myhexip,"00000000",9);
  8851.     }
  8852.     debug(F111,"dbinit myip",myhexip,myip);
  8853.     if (!peerhexip[0]) {                /* Get peer's  hex IP address */
  8854. #ifdef TCPSOCKET
  8855.         extern unsigned long peerxipaddr;
  8856.         if (ckgetpeer()) {
  8857.             peerip = peerxipaddr;
  8858.             sprintf(peerhexip,"%08lx",peerip); /* (Needs fixing for IPv6) */
  8859.             debug(F111,"dbinit peerip",peerhexip,peerip);
  8860.         } else {
  8861.             debug(F101,"dbinit ckgetpeer failure","",errno);
  8862.             ckstrncpy(peerhexip,"00000000",9);
  8863.         }
  8864. #else
  8865.         ckstrncpy(peerhexip,"00000000",9);
  8866. #endif /* TCPSOCKET */
  8867.     }
  8868.     debug(F111,"dbinit peerip",peerhexip,peerip);
  8869.     debug(F101,"dbinit dbenabled","",dbenabled);
  8870.     if (dbenabled && inserver) {
  8871.         mydbslot = getslot();
  8872.         debug(F111,"dbinit getslot",ckitoa(ikdbopen),x);
  8873.         if (ikdbopen) dbinited = 1;
  8874.     }
  8875.     return(0);
  8876. }
  8877.  
  8878. /*  U P D S L O T  --  Update slot n  */
  8879.  
  8880. /*
  8881.   Opens the database if necessary, seeks to slot n, writes current record
  8882.   and adds current time to last-update field.  n is the record sequence number
  8883.   (0, 1, 2, ...), not the seek pointer.   Returns -1 on failure, 0 on success.
  8884. */
  8885. int
  8886. updslot(n) int n; {                     /* Update our slot */
  8887.     int rc = 0;
  8888.     long position;
  8889.  
  8890.     debug(F111,"updslot","ikdbopen",ikdbopen);
  8891.     if (!ikdbopen)                      /* Not if not ok */
  8892.       return(0);
  8893.     if (!dbfp) {                        /* Open database if not open */
  8894.         dbfp = fopen(dbfile,updmode);   /* In update no-truncate mode */
  8895.         if (!dbfp) {
  8896.             debug(F110,"updslot fopen failed",dbfile,0);
  8897.             ikdbopen = 0;
  8898.             return(-1);
  8899.         }
  8900.     }
  8901.     debug(F111,"updslot dbfile",dbfile,dbfp);
  8902.     position = n * DB_RECL;
  8903.     if (fseek(dbfp,position,0) < 0) {   /* Seek to desired slot */
  8904.         debug(F111,"updslot fseek failed",dbfile,mydbseek);
  8905.         ikdbopen = 0;
  8906.         rc = -1;
  8907.     } else {
  8908.         /* Update the update time */
  8909.         strncpy(&dbrec[dbfld[db_LASTU].off],
  8910.                 ckdate(),
  8911.                 dbfld[db_LASTU].len
  8912.                 );
  8913.         if (fwrite(dbrec,1,DB_RECL,dbfp) < DB_RECL) { /* Write the record */
  8914.             debug(F110,"updslot fwrite failed",dbfile,0);
  8915.             ikdbopen = 0;
  8916.             rc = -1;
  8917.         } else {                        /* Flush the write */
  8918.             fflush(dbfp);
  8919.         }
  8920.     }
  8921.     return(rc);
  8922. }
  8923.  
  8924. /*  I N I T S L O T --  Initialize slot n with my info  */
  8925.  
  8926. int
  8927. initslot(n) int n; {                    /* Initialize slot */
  8928.     int k;
  8929. #ifdef TCPSOCKET
  8930.     extern unsigned long peerxipaddr;
  8931. #endif /* TCPSOCKET */
  8932.  
  8933.     debug(F101,"initslot","",n);
  8934.  
  8935. #ifdef USE_MEMCPY
  8936.     memset(dbrec,32,DB_RECL);
  8937. #else
  8938.     for (k = 0; k < DB_RECL; k++)
  8939.       dbrec[k] = '\040';
  8940. #endif /* USE_MEMCPY */
  8941.  
  8942.     myflags = DBF_INUSE;                /* Set in-use flag */
  8943.     mystate = W_NOTHING;
  8944.     myatype = 0L;
  8945.     myamode = 0L;
  8946.  
  8947.     k = dbfld[db_FLAGS].len;            /* Length of flags field */
  8948.     strncpy(&dbrec[dbfld[db_FLAGS].off],ulongtohex(myflags,k),k);
  8949.  
  8950.     k = dbfld[db_ATYPE].len;
  8951.     strncpy(&dbrec[dbfld[db_ATYPE].off],ulongtohex(myatype,k),k);
  8952.  
  8953.     k = dbfld[db_AMODE].len;
  8954.     strncpy(&dbrec[dbfld[db_AMODE].off],ulongtohex(myamode,k),k);
  8955.  
  8956.     k = dbfld[db_STATE].len;
  8957.     strncpy(&dbrec[dbfld[db_STATE].off],ulongtohex(mystate,k),k);
  8958.  
  8959.     k = dbfld[db_SADDR].len;
  8960.     strncpy(&dbrec[dbfld[db_SADDR].off],ulongtohex(myip,k),k);
  8961.  
  8962. #ifdef TCPSOCKET
  8963.     ckgetpeer();
  8964.     k = dbfld[db_CADDR].len;
  8965.     strncpy(&dbrec[dbfld[db_CADDR].off],ulongtohex(peerxipaddr,k),k);
  8966. #else
  8967.     k = dbfld[db_CADDR].len;
  8968.     strncpy(&dbrec[dbfld[db_CADDR].off],ulongtohex(0L,k),k);
  8969. #endif /* TCPSOCKET */
  8970.  
  8971.     k = dbfld[db_MYPID].len;
  8972.     strncpy(&dbrec[dbfld[db_MYPID].off],ulongtohex(mypid,k),k);
  8973.  
  8974.     k = dbfld[db_START].len;
  8975.     strncpy(&dbrec[dbfld[db_START].off],ckdate(),k);
  8976.  
  8977.     k = dbfld[db_ULEN].len;
  8978.     strncpy(&dbrec[dbfld[db_ULEN].off],"0000",4);
  8979.  
  8980.     k = dbfld[db_DLEN].len;
  8981.     strncpy(&dbrec[dbfld[db_DLEN].off],"0000",4);
  8982.  
  8983.     k = dbfld[db_ILEN].len;
  8984.     strncpy(&dbrec[dbfld[db_ILEN].off],"0000",4);
  8985.  
  8986.     strncpy(&dbrec[dbfld[db_INFO].off],"INIT",4);
  8987.     return(updslot(n));
  8988. }
  8989.  
  8990. int
  8991. slotstate(x,s1,s2,s3) int x; char *s1, *s2, *s3; {
  8992.     int k, l1, l2, l3, z;
  8993.     mystate = x;
  8994.     debug(F101,"slotstate ikdbopen","",ikdbopen);
  8995.     if (!ikdbopen)
  8996.       return(-1);
  8997.     if (!s1) s1 = "";
  8998.     l1 = strlen(s1);
  8999.     if (!s2) s2 = "";
  9000.     l2 = strlen(s2);
  9001.     if (!s3) s3 = "";
  9002.     l3 = strlen(s3);
  9003.     strncpy(&dbrec[DB_STATE],ulongtohex(mystate,4),4);
  9004.     k = dbfld[db_ILEN].len;
  9005.     z = l1 + l2 + l3 + 2;
  9006.     if (z > dB_INFO)
  9007.       z = dB_INFO;
  9008.     strncpy(&dbrec[DB_ILEN],ulongtohex((unsigned long)z,k),k);
  9009.     k = dbfld[db_INFO].len;
  9010.     z = dbfld[db_INFO].off;
  9011.     if (l1 <= k) {
  9012.         lset(&dbrec[z],s1,l1+1,32);
  9013.         z += l1+1;
  9014.         k -= l1+1;
  9015.         if (l2 <= k) {
  9016.             lset(&dbrec[z],s2,l2+1,32);
  9017.             z += l2+1;
  9018.             k -= l2+1;
  9019.             if (l3 <= k)
  9020.               lset(&dbrec[z],s3,k,32);
  9021.         }
  9022.     }
  9023. #ifdef DEBUG
  9024.     if (deblog) {
  9025.         char buf[128];
  9026.         int i;
  9027.         strncpy(buf,&dbrec[DB_INFO],127);
  9028.         buf[127] = NUL;
  9029.         for (i = 126; i > 0 && buf[i] == 32; i--) buf[i] = 0;
  9030.         debug(F111,"slotstate",buf,mystate);
  9031.     }
  9032. #endif /* DEBUG */
  9033.     z = updslot(mydbslot);
  9034.     debug(F101,"slotstate updslot","",z);
  9035.     return(z);
  9036. }
  9037.  
  9038. int
  9039. slotdir(s1,s2) char * s1, * s2; {       /* Update current directory */
  9040.     int k, len1, len2;
  9041.     if (!ikdbopen)
  9042.       return(-1);
  9043.     if (!s1) s1 = "";
  9044.     if (!s2) s2 = "";
  9045.     len1 = strlen(s1);
  9046.     len2 = strlen(s2);
  9047.     k = dbfld[db_DLEN].len;
  9048.     strncpy(&dbrec[DB_DLEN],ulongtohex((unsigned long)(len1+len2),k),k);
  9049.     k = dbfld[db_DIR].len;
  9050.     if (len1 > 0) {
  9051.         lset(&dbrec[dbfld[db_DIR].off],s1,len1,32);
  9052.         lset(&dbrec[dbfld[db_DIR].off+len1],s2,k-len1,32);
  9053.     } else {
  9054.         lset(&dbrec[dbfld[db_DIR].off],s2,k,32);
  9055.     }
  9056.     return(updslot(mydbslot));
  9057. }
  9058.  
  9059. /*  F R E E S L O T  --  Free slot n  */
  9060.  
  9061. int
  9062. freeslot(n) int n; {
  9063.     int k;
  9064.     if (!ikdbopen)
  9065.       return(0);
  9066.     dbflags = 0L;
  9067.     if (n == mydbslot) {
  9068.         dbflags = myflags & ~DBF_INUSE;
  9069.         dbflags &= ~DBF_LOGGED;
  9070.     }
  9071.     k = dbfld[db_FLAGS].len;
  9072.     strncpy(&dbrec[dbfld[db_FLAGS].off],ulongtohex(dbflags,k),k);
  9073.     return(updslot(n));
  9074. }
  9075.  
  9076. /*  G E T S L O T  --  Find a free database slot; returns slot number  */
  9077.  
  9078. int
  9079. getslot() {                             /* Find a free slot for us */
  9080.     FILE * rfp = NULL;                  /* Returns slot number (0, 1, ...) */
  9081.     char idstring[64];                  /* PID string buffer (decimal) */
  9082.     char pidbuf[64], * s;
  9083.     int j, k, n, x, rc = -1;
  9084.     int lockfd, tries, haveslot = 0;
  9085.     long lockpid, i;
  9086.     /* char ipbuf[17]; */
  9087.  
  9088.     if (!myhexip[0])                    /* Set my hex IP address if not set */
  9089.       ckstrncpy((char *)myhexip,"7F000001",33);
  9090.     sprintf(idstring,"%08lx:%010ld\n",myip,mypid);
  9091.     debug(F110,"getslot idstring", idstring, 0);
  9092.  
  9093.     /* Make temporary lockfile name IP.PID (hex.hex) */
  9094.     /* This should fit in 14 chars -- huge PIDs are usually not possible */
  9095.     /* on 14-char filename systems. */
  9096.  
  9097.     sprintf(tmplck,"%s%08lx.%lx",dbdir,myip,mypid);
  9098.     debug(F110,"getslot tempfile",tmplck,0);
  9099.  
  9100.     /* Make a temporary file */
  9101.  
  9102.     lockfd = creat(tmplck, 0600);
  9103.     if (lockfd < 0) {
  9104.         debug(F111,"getslock temp lockfile create failure", tmplck, errno);
  9105.         return(-1);
  9106.     }
  9107.     /* Write my (decimal) PID into the temp file */
  9108.  
  9109.     write(lockfd,idstring,(int)strlen(idstring));
  9110.     if (close(lockfd) < 0) {            /* Close lockfile */
  9111.         debug(F101,"getslot error closing temp lockfile", "", errno);
  9112.         return(-1);
  9113.     }
  9114.     sprintf(lcknam,"%s%s",dbdir,IK_LOCKFILE); /* Build lockfile name */
  9115.     debug(F110,"getslot lockfile",lcknam,0);
  9116.  
  9117.     rfp = fopen(lcknam,"r");            /* See if lockfile exists */
  9118.     if (rfp) {                          /* If so... */
  9119.         rset(pidbuf,"",64,0);
  9120.         x = fread(pidbuf,1,63,rfp);     /* Read ID string from it */
  9121.         fclose(rfp);                    /* and close it quickly */
  9122.         debug(F110,"getslot lock exists",pidbuf,0);
  9123.         if (x > 0) {                    /* If we have a PID, check it */
  9124.             char * s = pidbuf;
  9125.             while (*s) {
  9126.                 if (islower(*s)) *s = toupper(*s);
  9127.                 if (*s == ':') {
  9128.                     *s = NUL;
  9129.                     debug(F110,"getslot lock IP",pidbuf,0);
  9130.                     debug(F110,"gteslot my   IP",myhexip,0);
  9131.                     if (!strcmp(pidbuf,myhexip)) { /* Same IP address? */
  9132.                         lockpid = atol(s+1); /* Yes, now get PID */
  9133.                         debug(F101,"getslot lockpid","",lockpid);
  9134.  
  9135.                         /* Check if PID lockpid on this computer is alive */
  9136.                         x = zchkpid(lockpid);
  9137.                         if (!x) {
  9138.                             debug(F100,"getslot PID stale,removing lock","",0);
  9139.                             unlink(lcknam);
  9140.                         }
  9141.                         break;
  9142.                     }
  9143.                 }
  9144.                 s++;
  9145.             }
  9146.         } else {
  9147.             debug(F111,"getslot lockfile open failure",lcknam,errno);
  9148.         }
  9149.     }
  9150.     /* Try IK_LCKTRIES (16) times to rename temp file to lockfile */
  9151.  
  9152.     for (tries = IK_LCKTRIES; tries > 0; tries--) {
  9153.         if (zrename(tmplck,lcknam) == 0)
  9154.           break;
  9155.         debug(F101,"getslot database locked by pid", "", dbpid);
  9156.         sleep(IK_LCKSLEEP);
  9157.     }
  9158.     if (tries < 1) {                    /* Couldn't */
  9159.         debug(F110,"getslot create lock failure",lcknam,0);
  9160.         return(-1);
  9161.     }
  9162.     /* Have lock, open database */
  9163.  
  9164.     debug(F110,"getslot has lock",lcknam,0); /* Have lock */
  9165.  
  9166.     if (!dbfile)
  9167.       return(-1);
  9168.  
  9169.     /* If database doesn't exist, create it. */
  9170.  
  9171.     debug(F110,"getslot dbfile",dbfile,0);
  9172.     if (zchki(dbfile) < 0) {
  9173.         debug(F110,"getslot creating new database",dbfile,0);
  9174.         x = creat(dbfile,0660);
  9175.         if (x < 0) {
  9176.             debug(F111,"getslot creat() failed", dbfile, errno);
  9177.             goto xslot;
  9178.         }
  9179.         close(x);
  9180.     }
  9181.     dbfp = fopen(dbfile,updmode);       /* Open it in update mode */
  9182.     if (!dbfp) {
  9183.         debug(F111,"getslot fopen failed",dbfile,errno);
  9184.         goto xslot;
  9185.     }
  9186.     /* Now find a free (or new) slot... */
  9187.  
  9188.     dblastused = 0L;                    /* Seek pointer to last record inuse */
  9189.     mydbseek = 0L;                      /* Seek pointer for my record */
  9190.  
  9191.     /* Quickly read the whole database; n = record counter, i = seek pointer */
  9192.  
  9193.     for (n = 0, i = 0; !feof(dbfp); i += DB_RECL, n++) {
  9194.         x = fread(dbrec,1,DB_RECL,dbfp); /* Read a record */
  9195.         if (x < 1)                      /* EOF not caught by feof() */
  9196.           break;
  9197. #ifndef NOFTRUNCATE
  9198.         if (x != DB_RECL) {             /* Watch out for trailing junk */
  9199.             debug(F101,"getslot bad size","",x);  /* (Shouldn't happen...) */
  9200. #ifdef COHERENT
  9201.             chsize(fileno(dbfp),i);
  9202. #else
  9203.             ftruncate(fileno(dbfp),i);
  9204. #endif /* COHERENT */
  9205.             x = 0;
  9206.             fseek(dbfp,i,0);
  9207.             break;
  9208.         }
  9209. #endif /* NOFTRUNCATE */
  9210.         debug(F101,"getslot record","",n);
  9211.         k = dbfld[db_FLAGS].off;
  9212.         j = dbfld[db_FLAGS].len;
  9213.         dbflags = hextoulong(&dbrec[k],j);
  9214.         debug(F001,"getslot dbflags","",dbflags);
  9215.         k = dbfld[db_MYPID].off;
  9216.         j = dbfld[db_MYPID].len;
  9217.         dbpid  = hextoulong(&dbrec[k],j);
  9218.         debug(F001,"getslot dbpid","",dbpid);
  9219.         k = dbfld[db_SADDR].off;
  9220.         j = dbfld[db_SADDR].len;
  9221.         dbip = hextoulong(&dbrec[k],j);
  9222.         debug(F001,"getslot dbip","",dbip);
  9223.  
  9224.         if (dbflags & DBF_INUSE) {      /* Remember last slot in use */
  9225.             x = 0;                      /* Make sure it's REALLY in use */
  9226.             if (dbpid == mypid && dbip == myip) { /* Check for PID == my PID */
  9227.                 x = 1;
  9228.                 debug(F101,"getslot record pid","",dbpid);
  9229.             } else {                    /* Or for stale PID */
  9230.                 x = zchkpid(dbpid);
  9231.                 debug(F101,"getslot zchkpid()","",x);
  9232.             }
  9233.             if (!x) {                   /* Bogus record */
  9234.                 x = freeslot(n);
  9235.                 debug(F101,"getslot stale record pid: freeslot()","",x);
  9236.                 if (x > -1 && !haveslot)
  9237.                   dbflags = 0;
  9238.             } else {                    /* It's really in use */
  9239.                 dblastused = i;
  9240.             }
  9241.         }
  9242.         if (!haveslot) {                /* If I don't have a slot yet */
  9243.             if (!(dbflags & DBF_INUSE)) {       /* Claim this one */
  9244.                 debug(F101,"getslot free slot", "", n);
  9245.                 haveslot = 1;
  9246.                 mydbseek = i;
  9247.                 mydbslot = n;           /* But keep going... */
  9248.             }
  9249.         }
  9250.     }
  9251.     /* Come here with i == seek pointer to first record after eof */
  9252.  
  9253.     if (!haveslot) {                    /* Found no free slot so add to end */
  9254.         debug(F101,"getslot new slot","",n);
  9255.         haveslot = 1;
  9256.         mydbseek = i;
  9257.         mydbslot = n;
  9258.     }
  9259.     ikdbopen = 1;                       /* OK to make database entries */
  9260.     debug(F101,"getslot records","",n);
  9261.     debug(F101,"getslot dblastused","",dblastused);
  9262.     debug(F101,"getslot i","",i);
  9263.  
  9264.     /* Trim stale records from end */
  9265.  
  9266. #ifndef NOFTRUNCATE
  9267.     if (i > dblastused+DB_RECL) {
  9268.         debug(F101,"getslot truncating at","",dblastused+DB_RECL);
  9269. #ifdef COHERENT
  9270.         x = chsize(fileno(dbfp),dblastused+DB_RECL);
  9271. #else
  9272.         x = ftruncate(fileno(dbfp),dblastused+DB_RECL);
  9273. #endif /* COHERENT */
  9274.         if (x < 0)                      /* (Not fatal) */
  9275.           debug(F101,"getslot ftruncate failed", "", errno);
  9276.     }
  9277. #endif /* NOFTRUNCATE */
  9278.  
  9279.     /* Initialize my record */
  9280.  
  9281.     if (initslot(mydbslot) < 0) {
  9282.         debug(F101,"getslot initslot() error","",n);
  9283.         ikdbopen = 0;
  9284.         goto xslot;
  9285.     }
  9286.     debug(F101,"getslot OK","",mydbslot);
  9287.     rc = mydbslot;                      /* OK return code */
  9288.  
  9289.   xslot:                                /* Unlock the database and return */
  9290.     if (unlink(lcknam) < 0) {
  9291.         debug(F111,"getslot lockfile removal failed",lcknam,errno);
  9292.         rc = -1;
  9293.     }
  9294.     return(rc);
  9295. }
  9296. #endif /* IKSDB */
  9297. #endif /* NOIKSD */
  9298.