home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku201.zip / ckuusx.c < prev    next >
C/C++ Source or Header  |  2002-02-01  |  255KB  |  8,546 lines

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