home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sources / misc / 3952 < prev    next >
Encoding:
Text File  |  1992-09-14  |  57.2 KB  |  2,184 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  4. Subject:  v32i060:  ecu - ECU Asynchronous Communications v3.20, Part25/40
  5. Message-ID: <1992Sep14.144645.22082@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: dea35ee9e7428239289a82ce4ef4e57e
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. References: <csm-v32i036=ecu.141245@sparky.IMD.Sterling.COM>
  11. Date: Mon, 14 Sep 1992 14:46:45 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 2169
  14.  
  15. Submitted-by: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  16. Posting-number: Volume 32, Issue 60
  17. Archive-name: ecu/part25
  18. Environment: SCO,XENIX,ISC,SUNOS,SYSVR4,HDB,Curses
  19. Supersedes: ecu: Volume 21, Issue 53-89
  20.  
  21. ---- Cut Here and feed the following to sh ----
  22. #!/bin/sh
  23. # this is ecu320.25 (part 25 of ecu320)
  24. # do not concatenate these parts, unpack them in order with /bin/sh
  25. # file z/zcommon.c continued
  26. #
  27. if test ! -r _shar_seq_.tmp; then
  28.     echo 'Please unpack part 1 first!'
  29.     exit 1
  30. fi
  31. (read Scheck
  32.  if test "$Scheck" != 25; then
  33.     echo Please unpack part "$Scheck" next!
  34.     exit 1
  35.  else
  36.     exit 0
  37.  fi
  38. ) < _shar_seq_.tmp || exit 1
  39. if test ! -f _shar_wnt_.tmp; then
  40.     echo 'x - still skipping z/zcommon.c'
  41. else
  42. echo 'x - continuing file z/zcommon.c'
  43. sed 's/^X//' << 'SHAR_EOF' >> 'z/zcommon.c' &&
  44. X/*:05-11-1992-16:43-wht@gyro-fix WORKING_SELECT nap once and for all */
  45. X/*:05-08-1992-02:42-wht@n4hgf-select-based Nap was buggy */
  46. X/*:08-30-1991-20:09-wht@n4hgf2-sun Nap was not returning a value */
  47. X/*:08-30-1991-02:34-jdeitch@jadpc.cts.com-fix no hzmsec */
  48. X/*:08-21-1991-06:23-wht@n4hgf-sun porting */
  49. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  50. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  51. X
  52. X#include <stdio.h>
  53. X#include <errno.h>
  54. X#include <signal.h>
  55. X#include <setjmp.h>
  56. X#include <ctype.h>
  57. X#include "../ecu_types.h"
  58. X#include <sys/param.h>
  59. X#include "../ecu_pwd.h"
  60. X#include "zmodem.h"
  61. X
  62. X#if defined(sun) || defined(SVR4)
  63. X# include <sys/time.h>
  64. X#endif
  65. X
  66. Xextern unsigned char vmin_count;
  67. Xextern int Zmodem;
  68. Xextern unsigned Baudrate;
  69. Xextern int Twostop;        /* Use two stop bits */
  70. X
  71. X#if defined(LLITOUT)
  72. Xlong Locmode;        /* Saved "local mode" for 4.x BSD "new driver" */
  73. Xlong Locbit = LLITOUT;    /* Bit SUPPOSED to disable output translations */
  74. X#endif
  75. X
  76. Xint sigint = 0;            /* dummy for nap.c */
  77. X
  78. Xstruct 
  79. X{
  80. X    unsigned baudr;
  81. X    int speedcode;
  82. X} speeds[] = 
  83. X{
  84. X    110,    B110,
  85. X    300,    B300,
  86. X    600,    B600,
  87. X    1200,    B1200,
  88. X    2400,    B2400,
  89. X    4800,    B4800,
  90. X    9600,    B9600,
  91. X    19200,    EXTA,
  92. X    38400,    EXTB,
  93. X    0,
  94. X};
  95. X
  96. X/* crctab calculated by Mark G. Mendel,Network Systems Corporation */
  97. Xunsigned short crctab[256] = 
  98. X{
  99. X    0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
  100. X    0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
  101. X    0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
  102. X    0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
  103. X    0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
  104. X    0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
  105. X    0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
  106. X    0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
  107. X    0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
  108. X    0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
  109. X    0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
  110. X    0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
  111. X    0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
  112. X    0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
  113. X    0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
  114. X    0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
  115. X    0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
  116. X    0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
  117. X    0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
  118. X    0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
  119. X    0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
  120. X    0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
  121. X    0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
  122. X    0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
  123. X    0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
  124. X    0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
  125. X    0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
  126. X    0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
  127. X    0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
  128. X    0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
  129. X    0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
  130. X    0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
  131. X};
  132. X
  133. X#if defined(WANT_UPDCRC_HERE)    /* wht -- moved to zmodem.h */
  134. X/*
  135. X * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
  136. X *  NOTE: First srgument must be in range 0 to 255.
  137. X *        Second argument is referenced twice.
  138. X * 
  139. X * Programmers may incorporate any or all code into their programs,
  140. X * giving proper credit within the source. Publication of the 
  141. X * source routines is permitted so long as proper credit is given 
  142. X * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
  143. X * Omen Technology.
  144. X */
  145. X
  146. X#define updcrc(cp,crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
  147. X#endif
  148. X
  149. X/*
  150. X  First,the polynomial itself and its table of feedback terms.  The
  151. X  polynomial is:
  152. X
  153. X  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
  154. X
  155. X  Note that we take it "backwards" and put the highest-order term in the
  156. X  lowest-order bit.  The X^32 term is "implied"; the LSB is the X^31
  157. X  term,etc.  The X^0 term (usually shown as "+1") results in the MSB being
  158. X  1.  Note that the usual hardware shift register implementation,which is
  159. X  what we're using (we're merely optimizing it by doing eight-bit chunks at
  160. X  a time) shifts bits into the lowest-order term.  In our
  161. X  implementation,that means shifting towards the right.  Why do we do it
  162. X  this way?  Because the calculated CRC must be transmitted in order from
  163. X  highest-order term to lowest-order term.  UARTs transmit characters in
  164. X  order from LSB to MSB.  By storing the CRC this way, we hand it to the
  165. X  UART in the order low-byte to high-byte; the UART sends each low-bit to
  166. X  hight-bit; and the result is transmission bit by bit from highest- to
  167. X  lowest-order term without requiring any bit shuffling on our part.
  168. X  Reception works similarly.
  169. X
  170. X  The feedback terms table consists of 256 32-bit entries.  Notes:   
  171. X
  172. X     The macro for using the table is UPDC32 is located in zmodem.h
  173. X                                                                     
  174. X     It might not be obvious,but the feedback terms simply represent the
  175. X     results of eight shift/xor opera- tions for all combinations of data
  176. X     and CRC register values.
  177. X                                                                     
  178. X     The values must be right-shifted by eight bits by the "UPDC32" logic;
  179. X     the shift must be unsigned (bring in zeroes).  On some hardware you
  180. X     could probably optimize the shift in assembler by using byte-swap
  181. X     instructions.
  182. X*/
  183. X
  184. Xlong cr3tab[] =        /* CRC polynomial 0xedb88320 */
  185. X{
  186. X    0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535,0x9e6495a3,
  187. X    0x0edb8832,0x79dcb8a4,0xe0d5e91e,0x97d2d988,0x09b64c2b,0x7eb17cbd,0xe7b82d07,0x90bf1d91,
  188. X    0x1db71064,0x6ab020f2,0xf3b97148,0x84be41de,0x1adad47d,0x6ddde4eb,0xf4d4b551,0x83d385c7,
  189. X    0x136c9856,0x646ba8c0,0xfd62f97a,0x8a65c9ec,0x14015c4f,0x63066cd9,0xfa0f3d63,0x8d080df5,
  190. X    0x3b6e20c8,0x4c69105e,0xd56041e4,0xa2677172,0x3c03e4d1,0x4b04d447,0xd20d85fd,0xa50ab56b,
  191. X    0x35b5a8fa,0x42b2986c,0xdbbbc9d6,0xacbcf940,0x32d86ce3,0x45df5c75,0xdcd60dcf,0xabd13d59,
  192. X    0x26d930ac,0x51de003a,0xc8d75180,0xbfd06116,0x21b4f4b5,0x56b3c423,0xcfba9599,0xb8bda50f,
  193. X    0x2802b89e,0x5f058808,0xc60cd9b2,0xb10be924,0x2f6f7c87,0x58684c11,0xc1611dab,0xb6662d3d,
  194. X    0x76dc4190,0x01db7106,0x98d220bc,0xefd5102a,0x71b18589,0x06b6b51f,0x9fbfe4a5,0xe8b8d433,
  195. X    0x7807c9a2,0x0f00f934,0x9609a88e,0xe10e9818,0x7f6a0dbb,0x086d3d2d,0x91646c97,0xe6635c01,
  196. X    0x6b6b51f4,0x1c6c6162,0x856530d8,0xf262004e,0x6c0695ed,0x1b01a57b,0x8208f4c1,0xf50fc457,
  197. X    0x65b0d9c6,0x12b7e950,0x8bbeb8ea,0xfcb9887c,0x62dd1ddf,0x15da2d49,0x8cd37cf3,0xfbd44c65,
  198. X    0x4db26158,0x3ab551ce,0xa3bc0074,0xd4bb30e2,0x4adfa541,0x3dd895d7,0xa4d1c46d,0xd3d6f4fb,
  199. X    0x4369e96a,0x346ed9fc,0xad678846,0xda60b8d0,0x44042d73,0x33031de5,0xaa0a4c5f,0xdd0d7cc9,
  200. X    0x5005713c,0x270241aa,0xbe0b1010,0xc90c2086,0x5768b525,0x206f85b3,0xb966d409,0xce61e49f,
  201. X    0x5edef90e,0x29d9c998,0xb0d09822,0xc7d7a8b4,0x59b33d17,0x2eb40d81,0xb7bd5c3b,0xc0ba6cad,
  202. X    0xedb88320,0x9abfb3b6,0x03b6e20c,0x74b1d29a,0xead54739,0x9dd277af,0x04db2615,0x73dc1683,
  203. X    0xe3630b12,0x94643b84,0x0d6d6a3e,0x7a6a5aa8,0xe40ecf0b,0x9309ff9d,0x0a00ae27,0x7d079eb1,
  204. X    0xf00f9344,0x8708a3d2,0x1e01f268,0x6906c2fe,0xf762575d,0x806567cb,0x196c3671,0x6e6b06e7,
  205. X    0xfed41b76,0x89d32be0,0x10da7a5a,0x67dd4acc,0xf9b9df6f,0x8ebeeff9,0x17b7be43,0x60b08ed5,
  206. X    0xd6d6a3e8,0xa1d1937e,0x38d8c2c4,0x4fdff252,0xd1bb67f1,0xa6bc5767,0x3fb506dd,0x48b2364b,
  207. X    0xd80d2bda,0xaf0a1b4c,0x36034af6,0x41047a60,0xdf60efc3,0xa867df55,0x316e8eef,0x4669be79,
  208. X    0xcb61b38c,0xbc66831a,0x256fd2a0,0x5268e236,0xcc0c7795,0xbb0b4703,0x220216b9,0x5505262f,
  209. X    0xc5ba3bbe,0xb2bd0b28,0x2bb45a92,0x5cb36a04,0xc2d7ffa7,0xb5d0cf31,0x2cd99e8b,0x5bdeae1d,
  210. X    0x9b64c2b0,0xec63f226,0x756aa39c,0x026d930a,0x9c0906a9,0xeb0e363f,0x72076785,0x05005713,
  211. X    0x95bf4a82,0xe2b87a14,0x7bb12bae,0x0cb61b38,0x92d28e9b,0xe5d5be0d,0x7cdcefb7,0x0bdbdf21,
  212. X    0x86d3d2d4,0xf1d4e242,0x68ddb3f8,0x1fda836e,0x81be16cd,0xf6b9265b,0x6fb077e1,0x18b74777,
  213. X    0x88085ae6,0xff0f6a70,0x66063bca,0x11010b5c,0x8f659eff,0xf862ae69,0x616bffd3,0x166ccf45,
  214. X    0xa00ae278,0xd70dd2ee,0x4e048354,0x3903b3c2,0xa7672661,0xd06016f7,0x4969474d,0x3e6e77db,
  215. X    0xaed16a4a,0xd9d65adc,0x40df0b66,0x37d83bf0,0xa9bcae53,0xdebb9ec5,0x47b2cf7f,0x30b5ffe9,
  216. X    0xbdbdf21c,0xcabac28a,0x53b39330,0x24b4a3a6,0xbad03605,0xcdd70693,0x54de5729,0x23d967bf,
  217. X    0xb3667a2e,0xc4614ab8,0x5d681b02,0x2a6f2b94,0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d
  218. X};
  219. X
  220. X#if defined(FIONREAD)
  221. X/*
  222. X *  Return non 0 iff something to read from io descriptor f
  223. X */
  224. Xint
  225. Xrdchk(f)
  226. Xint f;
  227. X{
  228. X    int lf = 0;
  229. X
  230. X    ioctl(f,FIONREAD,&lf);
  231. X    return(!!lf);
  232. X}
  233. X#endif
  234. X
  235. Xunsigned short
  236. Xgetspeed(code)
  237. Xint code;
  238. X{
  239. X    register n;
  240. X
  241. X    for(n=0; speeds[n].baudr; ++n)
  242. X        if(speeds[n].speedcode == code)
  243. X            return(speeds[n].baudr);
  244. X    return(38400);    /* Assume fifo if ioctl failed */
  245. X}
  246. X
  247. X
  248. X
  249. X#if defined(ICANON)
  250. Xstruct termio oldtty,tty;
  251. X#else
  252. Xstruct sgttyb oldtty,tty;
  253. Xstruct tchars oldtch,tch;
  254. X#endif
  255. X
  256. Xextern int iofd;        /* File descriptor for ioctls & reads */
  257. X
  258. X/*
  259. X * mode(n)
  260. X *  3: save old tty stat, set raw mode with flow control
  261. X *  2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
  262. X *  1: save old tty stat, set raw mode 
  263. X *  0: restore original tty mode
  264. X */
  265. Xmode(new_mode)
  266. Xint new_mode;
  267. X{
  268. X    static did0 = FALSE;
  269. X    report_mode(new_mode);
  270. X    switch(new_mode)
  271. X    {
  272. X    case 2:        /* Un-raw mode used by sz,sb when -g detected */
  273. X        if(!did0)
  274. X            (void) ioctl(iofd,TCGETA,&oldtty);
  275. X        tty = oldtty;
  276. X        tty.c_iflag &= ~(IXON | IXOFF | IXANY);
  277. X
  278. X#if defined(RTSFLOW)
  279. X        if(tty.c_cflag & (RTSFLOW | CTSFLOW))
  280. X            tty.c_iflag = BRKINT;
  281. X        else
  282. X            tty.c_iflag = BRKINT|IXON;
  283. X#else
  284. X        tty.c_iflag = BRKINT|IXON;
  285. X#endif
  286. X
  287. X        tty.c_oflag = 0;    /* Transparent output */
  288. X
  289. X        tty.c_cflag &= ~PARENB;    /* Disable parity */
  290. X        tty.c_cflag |= CS8;    /* Set character size = 8 */
  291. X        if(Twostop)
  292. X            tty.c_cflag |= CSTOPB;    /* Set two stop bits */
  293. X
  294. X
  295. X#if defined(READCHECK)
  296. X        tty.c_lflag = Zmodem ? 0 : ISIG;
  297. X        tty.c_cc[VINTR] = Zmodem ? -1:030;    /* Interrupt char */
  298. X#else
  299. X        tty.c_lflag = ISIG;
  300. X        tty.c_cc[VINTR] = Zmodem ? 03:030;    /* Interrupt char */
  301. X#endif
  302. X        tty.c_cc[VQUIT] = -1;            /* Quit char */
  303. X#if defined(NFGVMIN)
  304. X        tty.c_cc[VMIN] = 1;
  305. X#else
  306. X        tty.c_cc[VMIN] = 3;     /* This many chars satisfies reads */
  307. X#endif
  308. X        tty.c_cc[VTIME] = 1;    /* or in this many tenths of seconds */
  309. X
  310. X        (void) ioctl(iofd,TCSETAW,&tty);
  311. X        did0 = TRUE;
  312. X        return(OK);
  313. X    case 1:
  314. X    case 3:
  315. X        if(!did0)
  316. X            (void) ioctl(iofd,TCGETA,&oldtty);
  317. X        tty = oldtty;
  318. X        tty.c_iflag &= ~(IXON | IXOFF | IXANY);
  319. X
  320. X#if defined(RTSFLOW)
  321. X        tty.c_iflag = new_mode == 3 ? (IGNBRK | RTSFLOW) : IGNBRK;
  322. X#else
  323. X        tty.c_iflag = new_mode == 3 ? (IGNBRK | IXOFF) : IGNBRK;
  324. X#endif
  325. X
  326. X        /* No echo,crlf mapping,INTR,QUIT,delays,no erase/kill */
  327. X        tty.c_lflag &= ~(ECHO | ICANON | ISIG);
  328. X
  329. X        tty.c_oflag = 0;    /* Transparent output */
  330. X
  331. X        tty.c_cflag &= ~PARENB;    /* Same baud rate,disable parity */
  332. X        tty.c_cflag |= CS8;    /* Set character size = 8 */
  333. X        if(Twostop)
  334. X            tty.c_cflag |= CSTOPB;    /* Set two stop bits */
  335. X#if defined(NFGVMIN)
  336. X        tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */
  337. X#else
  338. X        tty.c_cc[VMIN] = vmin_count; /* This many chars satisfies reads */
  339. X#endif
  340. X        tty.c_cc[VTIME] = 1;    /* or in this many tenths of seconds */
  341. X        (void) ioctl(iofd,TCSETAW,&tty);
  342. X        did0 = TRUE;
  343. X        Baudrate = getspeed(tty.c_cflag & CBAUD);
  344. X        report_comm_baud_rate(Baudrate);
  345. X        return(OK);
  346. X    case 0:
  347. X        if(!did0)
  348. X            return(ERROR);
  349. X        (void) ioctl(iofd,TCSBRK,1);    /* Wait for output to drain */
  350. X        (void) ioctl(iofd,TCFLSH,1);    /* Flush input queue */
  351. X        (void) ioctl(iofd,TCSETAW,&oldtty);    /* Restore modes */
  352. X        (void) ioctl(iofd,TCXONC,1);    /* Restart output */
  353. X        return(OK);
  354. X    default:
  355. X        return(ERROR);
  356. X    }
  357. X}
  358. X
  359. X/*+-------------------------------------------------------------------------
  360. X    sendbrk()
  361. X--------------------------------------------------------------------------*/
  362. Xsendbrk()
  363. X{
  364. X    ioctl(iofd,TCSBRK,0);
  365. X}    /* end of sendbrk */
  366. X
  367. X/*+-------------------------------------------------------------------------
  368. X    get_curr_dir(currdir,currdir_max)
  369. X--------------------------------------------------------------------------*/
  370. Xvoid
  371. Xget_curr_dir(currdir,currdir_max)
  372. Xchar *currdir;
  373. Xint currdir_max;
  374. X{
  375. X    getcwd(currdir,currdir_max);
  376. X}    /* end of get_curr_dir */
  377. X
  378. X/*+-------------------------------------------------------------------------
  379. X    zmputs(str) - send a string to the modem
  380. X
  381. Xprocessing for \336 (sleep 1 sec) and \335 (break signal)
  382. X--------------------------------------------------------------------------*/
  383. Xzmputs(str)
  384. Xregister char *str;
  385. X{
  386. Xregister char strch;
  387. X
  388. X    while(strch = *str++)
  389. X    {
  390. X        switch(strch)
  391. X        {
  392. X        case '\336':
  393. X            sleep(1);
  394. X            continue;
  395. X        case '\335':
  396. X            sendbrk();
  397. X            continue;
  398. X        default:
  399. X            sendline(strch);
  400. X        }
  401. X    }
  402. X}    /* end of zmputs */
  403. X
  404. X/*+-----------------------------------------------------------------------
  405. X    get_home_dir(home_dir):  leave plenty of room for result!
  406. X------------------------------------------------------------------------*/
  407. Xget_home_dir(home_dir)
  408. Xchar *home_dir;
  409. X{
  410. Xchar *cptr;
  411. Xstatic char home_directory[256] = "";
  412. Xstruct passwd *pwent;
  413. Xstruct passwd *getpwuid();
  414. Xchar *getenv();
  415. X
  416. X    if(home_directory[0])
  417. X    {
  418. X        strcpy(home_dir,home_directory);
  419. X        return(0);
  420. X    }
  421. X
  422. X    if(cptr = getenv("HOME"))            /* x286 seems to blow up ... */
  423. X    {                                    /* ... in pwent code ... hmmm */
  424. X        strcpy(home_directory,cptr);
  425. X        strcpy(home_dir,cptr);
  426. X        return(0);
  427. X    }
  428. X
  429. X    if(!(pwent = getpwuid(getuid())))
  430. X    {
  431. X        perror("cannot get pwent for you!!");
  432. X        exit(1);
  433. X    }
  434. X    strcpy(home_directory,pwent->pw_dir);
  435. X    strcpy(home_dir,pwent->pw_dir);
  436. X    endpwent();
  437. X    return(0);
  438. X
  439. X}    /* end of get_home_dir */
  440. X
  441. X/* end of zcommon.c */
  442. X/* vi: set tabstop=4 shiftwidth=4: */
  443. SHAR_EOF
  444. echo 'File z/zcommon.c is complete' &&
  445. chmod 0644 z/zcommon.c ||
  446. echo 'restore of z/zcommon.c failed'
  447. Wc_c="`wc -c < 'z/zcommon.c'`"
  448. test 14276 -eq "$Wc_c" ||
  449.     echo 'z/zcommon.c: original size 14276, current size' "$Wc_c"
  450. rm -f _shar_wnt_.tmp
  451. fi
  452. # ============= z/zcurses.c ==============
  453. if test -f 'z/zcurses.c' -a X"$1" != X"-c"; then
  454.     echo 'x - skipping z/zcurses.c (File already exists)'
  455.     rm -f _shar_wnt_.tmp
  456. else
  457. > _shar_wnt_.tmp
  458. echo 'x - extracting z/zcurses.c (Text)'
  459. sed 's/^X//' << 'SHAR_EOF' > 'z/zcurses.c' &&
  460. X/*+-------------------------------------------------------------------------
  461. X    zcurses.c -- ecu file transfer program curses interface
  462. X
  463. X  000000000011111111112222222222333333333344444444445555555550
  464. X  012345678901234567890123456789012345678901234567890123456789
  465. X00.-[ prog+rev ]-- <dir> ------------------------------------.
  466. X01|  ZMODEM_6____  _40_____________________________________  |
  467. X02|  File ### of ###: _38__________________________________  |
  468. X03|  File position:  _8______ length: _8______  -rwxrwxrwx   |
  469. X04|  _55____________________________________________________ | transaction
  470. X05|  _55____________________________________________________ | last rx/tx hdr
  471. X06|  Comm I/O: rx _8______  tx _8______ bytes                |
  472. X07|  Baud rate: _5___ BINARY blklen: _____ comm mode: RAW-g  |
  473. X08|  Time:    started: __:__:__ this file: __:__:__ window:  |
  474. X09|  __:__:__ elapsed: __:__:__            __:__:__ ________ |
  475. X10|  Errors: this file: _3_ total: _4__ files skipped: _3_   |
  476. X11|  _55____________________________________________________ |  err str
  477. X12|  _55____________________________________________________ |  comment str
  478. X13|  _55____________________________________________________ |  remote info
  479. X14`----------------------------------------------------------'
  480. X
  481. X14|  FE ___ OE ___ rcvd ________ xmtd ________ RTS _ CTS _      FASI
  482. X15|  flow xmtr CTS ____ XOFF ____ rcvr RTS ____ XOFF ____
  483. X16|  queues: xmtr _____ of _____  rcvr _____ of _____
  484. X
  485. X14|  Output queue depth  ______  RTS _  CTS _                   sun
  486. X15|  Input queue depth   ______  Input queue avail ______ 
  487. X
  488. X
  489. X  Defined functions:
  490. X    clear_area(w,row,col,len)
  491. X    clear_area_char(w,row,col,len,fillchar)
  492. X    determine_output_mode()
  493. X    dumbtty_newline()
  494. X    get_elapsed_time(elapsed_secs)
  495. X    get_tod(type,tod)
  496. X    mode_map(file_mode,mode_str)
  497. X    report_comm_baud_rate(baud_rate)
  498. X    report_error_count()
  499. X    report_file_byte_io(count)
  500. X    report_file_close(skipped)
  501. X    report_file_open_length(length)
  502. X    report_file_open_mode(file_mode)
  503. X    report_file_open_tod()
  504. X    report_file_rcv_started(filename,length,last_mod_time,file_mode)
  505. X    report_file_send_open(filename,filestat)
  506. X    report_file_xfer_rate(text,count,final)
  507. X    report_init(title)
  508. X    report_last_rxhdr(rptstr,error_flag)
  509. X    report_last_txhdr(rptstr,error_flag)
  510. X    report_mode(comm_mode)
  511. X    report_protocol_crc_type(str)
  512. X    report_protocol_type(str)
  513. X    report_rx_ind(status)
  514. X    report_rx_tx_count()
  515. X    report_rxblklen(blklen)
  516. X    report_rxpos(pos)
  517. X    report_str(rptstr,error_flag)
  518. X    report_top_line(topstr)
  519. X    report_transaction(str)
  520. X    report_transfer_progress(filepos,initfpos)
  521. X    report_tx_ind(status)
  522. X    report_txblklen(blklen)
  523. X    report_txpos(pos)
  524. X    report_uninit(sig)
  525. X    report_window()
  526. X    report_xfer_mode(str)
  527. X    vanilla_ruling()
  528. X
  529. X------------------------------------------------------------------------*/
  530. X/*+:EDITS:*/
  531. X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  532. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  533. X/*:02-09-1992-16:08-root@n4hgf-ruling characters only on  SCO (tcap curses) */
  534. X/*:01-05-1992-17:27-wht@n4hgf-properly display progress for resumed transfers */
  535. X/*:09-02-1991-01:12-wht@n4hgf2-show sun driver information */
  536. X/*:08-28-1991-14:08-wht@n4hgf2-SVR4 cleanup by aega84!lh */
  537. X/*:08-23-1991-18:33-wht@n4hgf2-disable force no curses for tty vs. line speed */
  538. X/*:08-21-1991-06:23-wht@n4hgf-sun porting */
  539. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  540. X/*:06-15-1991-05:47-root@n4hgf-report per-file xfer rate */
  541. X/*:05-25-1991-14:51-wht@n4hgf-FAS/i display */
  542. X/*:04-24-1991-01:22-wht@n4hgf-handle dumbtty and single file xfer >= 1 hour */
  543. X/*:02-03-1991-17:27-wht@n4hgf-show elapsed time during no curses xfer */
  544. X/*:01-04-1991-15:54-wht@n4hgf-dumbtty per-file xfer rate was wrong */
  545. X/*:12-18-1990-21:26-wht@n4hgf-better output control */
  546. X/*:12-04-1990-04:07-wht@n4hgf-handle slow terminal using faster line */
  547. X/*:12-04-1990-03:04-wht@n4hgf-choose ruling chars based on multiscreen or not */
  548. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  549. X/*:08-14-1990-20:41-wht@n4hgf-ecu3.00-flush old edit history */
  550. X
  551. X#include "../ecucurses.h"
  552. X#include "../ecu_types.h"
  553. X#include "../ecu_stat.h"
  554. X#include <ctype.h>
  555. X#include <signal.h>
  556. X#include <time.h>
  557. X#include <sys/timeb.h>
  558. X
  559. X#if defined(M_SYSV)
  560. X#   include <sys/machdep.h>
  561. X#else
  562. X#if defined(ISC) || defined(SVR4)
  563. X#  include <sys/at_ansi.h>
  564. X#  include <sys/kd.h>
  565. X#endif
  566. X#endif
  567. X
  568. X#if defined(FASI)
  569. X#  include <local/fas.h>
  570. X#endif    /* FASI */
  571. X
  572. X#include "../pc_scr.h"
  573. X
  574. X#ifdef USE_PROTOS
  575. X# include "protos.h"
  576. X#endif
  577. X
  578. Xlong time();
  579. Xvoid report_error_count();
  580. Xextern char *tzname[];
  581. Xstruct tm *localtime();
  582. X
  583. Xunsigned char sTL = at_TL;
  584. Xunsigned char sTR = at_TR;
  585. Xunsigned char sBL = at_BL;
  586. Xunsigned char sBR = at_BR;
  587. Xunsigned char sLT = at_LT;
  588. Xunsigned char sRT = at_RT;
  589. Xunsigned char sVR = at_VR;
  590. Xunsigned char sHR = at_HR;
  591. X
  592. X#if defined(FASI)
  593. X#define WIN_LINES    18
  594. X#else
  595. X#if defined(sun)
  596. X#define WIN_LINES    17
  597. X#else
  598. X#define WIN_LINES    15
  599. X#endif    /* sun */
  600. X#endif    /* FASI */
  601. X
  602. X#define WIN_COLS    60
  603. X#define WIN_TOPY    2
  604. X#define WIN_LEFTX    8
  605. X
  606. Xextern char curr_dir[];
  607. Xextern char *bottom_label;
  608. Xextern int Filcnt;
  609. Xextern int ecusz_flag;    /* ecusz == 1, ecurz == 0 */
  610. Xextern int force_dumbtty;
  611. Xextern int skip_count;
  612. Xextern int npats;
  613. Xextern int iofd;
  614. Xextern long rxpos;
  615. Xextern int log_packets;
  616. Xextern long Txpos;
  617. Xextern long Rxpos;
  618. Xextern long initial_filepos;
  619. X
  620. XWINDOW    *win;
  621. Xint (*original_sigint_handler)();
  622. Xint (*original_sigquit_handler)();
  623. Xint (*original_sigterm_handler)();
  624. Xint report_init_complete;
  625. Xint report_verbosity;
  626. Xint dumbtty;
  627. Xint dumbtty_pos;
  628. Xint this_file_errors;
  629. Xlong this_file_xfer_count;
  630. Xint total_errors;
  631. Xint show_window;
  632. Xlong current_seconds;
  633. Xlong start_seconds;
  634. Xlong this_file_start_seconds;
  635. Xlong elapsed_seconds;
  636. Xunsigned long total_data_bytes_xfered;
  637. Xunsigned int zcurses_baud_rate;
  638. Xchar s128[128];
  639. X
  640. X#if defined(FASI)
  641. Xstruct fas_info fip_start;
  642. X#endif /* FASI */
  643. X
  644. X
  645. Xchar *win_template[] =
  646. X{
  647. X/*00000000001111111111222222222233333333334444444444555555555 */
  648. X/*01234567890123456789012345678901234567890123456789012345678 */
  649. X/*.----------------------------------------------------------. */
  650. X  "                                                          ",    /* 1 */
  651. X  "  File ### of ###: _____________________________________  ",    /* 2 */
  652. X  "  File position:  ________ length: ________               ",    /* 3 */
  653. X  "                                                          ",    /* 4 */
  654. X  "  tx: ______________________  rx: ______________________  ",    /* 5 */
  655. X  "  Comm I/O: rx ________  tx ________ bytes                ",    /* 6 */
  656. X  "  Baud rate: _____ ______ blklen: _____ comm mode: ______ ",    /* 7 */
  657. X  "  Time:    started: __:__:__ this file: __:__:__          ", /* 8 */
  658. X  "  __:__:__ elapsed: __:__:__            __:__:__          ", /* 9 */
  659. X  "  Errors: this file: ___ total: ____ files skipped: ___   ", /* 10 */
  660. X  "                                                          ",    /* 11 */
  661. X  "                                                          ",    /* 12 */
  662. X  "                                                          ",    /* 13 */
  663. X#if defined(FASI)
  664. X  "  FE ___ OE ___ rcvd ________ xmtd ________ RTS _ CTS _   ",
  665. X  "  flow xmtr CTS ____ XOFF ____ rcvr RTS ____ XOFF ____    ",
  666. X  "  queues: xmtr _____ of _____  rcvr _____ of _____        ",
  667. X#endif    /* FASI */
  668. X#if defined(sun)
  669. X  "  Output queue depth  ______  RTS _  CTS _                ",
  670. X  "  Input queue depth   ______  Input queue avail ______    ",
  671. X#endif
  672. X/*`----------------------------------------------------------' */
  673. X(char *)0
  674. X};
  675. X
  676. X/*+-------------------------------------------------------------------------
  677. X    vanilla_ruling() - use ordinary ruling characters
  678. X--------------------------------------------------------------------------*/
  679. Xvoid
  680. Xvanilla_ruling()
  681. X{
  682. X    sTL = vanilla_TL;
  683. X    sTR = vanilla_TR;
  684. X    sBL = vanilla_BL;
  685. X    sBR = vanilla_BR;
  686. X    sLT = vanilla_LT;
  687. X    sRT = vanilla_RT;
  688. X    sVR = vanilla_VR;
  689. X    sHR = vanilla_HR;
  690. X
  691. X}    /* end of vanilla_ruling */
  692. X
  693. X/*+-----------------------------------------------------------------------
  694. X    char *get_elapsed_time(elapsed_secs)
  695. X    hh:mm:ss returned
  696. X  static string address is returned
  697. X------------------------------------------------------------------------*/
  698. Xchar *
  699. Xget_elapsed_time(elapsed_secs)
  700. Xlong elapsed_secs;
  701. X{
  702. X    static char elapsed_time_str[10];
  703. X    long hh,mm,ss;
  704. X
  705. X    hh = elapsed_secs / 3600;
  706. X    elapsed_secs -= hh * 3600;
  707. X    mm = elapsed_secs / 60L;
  708. X    elapsed_secs -= mm * 60L;
  709. X    ss = elapsed_secs;
  710. X
  711. X    sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss);
  712. X    return(elapsed_time_str);
  713. X}    /* end of get_elapsed_time */
  714. X
  715. X/*+-----------------------------------------------------------------------
  716. X    char *get_tod(type,tod)
  717. X
  718. X  time of day types:
  719. X    0        hh:mm
  720. X    1        hh:mm:ss
  721. X    2        mm-dd-yyyy hh:mm
  722. X
  723. X  static string address is returned
  724. X  if tod != (char *)0, time is returned there too
  725. X------------------------------------------------------------------------*/
  726. Xchar *
  727. Xget_tod(type,tod)
  728. Xint type;
  729. Xchar *tod;
  730. X{
  731. X    static char tod_str[32];
  732. X    long cur_time = time((long *)0);
  733. X    struct tm *lt = localtime(&cur_time);
  734. X
  735. X    switch(type)
  736. X    {
  737. X        case 0:
  738. X            sprintf(tod_str,"%02d:%02d",lt->tm_hour,lt->tm_min);
  739. X            break;
  740. X
  741. X        default:
  742. X        case 1:
  743. X            sprintf(tod_str,"%02d:%02d:%02d",
  744. X                lt->tm_hour,lt->tm_min,lt->tm_sec);
  745. X            break;
  746. X
  747. X        case 2:
  748. X            sprintf(tod_str,"%02d-%02d-%04d %02d:%02d",
  749. X                lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
  750. X                lt->tm_hour,lt->tm_min);
  751. X            break;
  752. X    }
  753. X
  754. X    if(tod != (char *)0)
  755. X        strcpy(tod,tod_str);
  756. X
  757. X    return(tod_str);
  758. X}    /* end of get_tod */
  759. X
  760. X/*+-----------------------------------------------------------------------
  761. X    mode_map(file_mode,mode_str)    build drwxrwxrwx string
  762. X------------------------------------------------------------------------*/
  763. Xchar *
  764. Xmode_map(file_mode,mode_str)
  765. Xunsigned short file_mode;
  766. Xchar *mode_str;
  767. X{
  768. Xregister unsigned ftype = file_mode & S_IFMT;
  769. Xregister char *rtn;
  770. Xstatic char result[12];
  771. X
  772. X    rtn = (mode_str == (char *)0) ? result : mode_str;
  773. X
  774. X    /*               drwxrwxrwx */
  775. X    /*               0123456789 */
  776. X    strcpy(rtn,"----------");
  777. X
  778. X    switch(ftype)
  779. X    {
  780. X        case S_IFIFO:    *rtn = 'p'; break; /* FIFO (named pipe) */
  781. X        case S_IFDIR:    *rtn = 'd'; break; /* directory */
  782. X        case S_IFCHR:    *rtn = 'c'; break; /* character special */
  783. X        case S_IFBLK:    *rtn = 'b'; break; /* block special */
  784. X        case S_IFREG:    *rtn = '-'; break; /* regular */
  785. X
  786. X#if defined(S_IFLNK)
  787. X        case S_IFLNK:    *rtn = 'l'; break; /* symbolic link */
  788. X#endif
  789. X#if defined(S_IFSOCK)
  790. X        case S_IFSOCK:    *rtn = 's'; break; /* socket */
  791. X#endif
  792. X
  793. X#if defined(S_IFNAM)
  794. X        case S_IFNAM:                        /* name space entry */
  795. X#if defined(S_IFNAM)
  796. X            if(file_mode & S_INSEM)                /* semaphore */
  797. X            {
  798. X                *rtn = 's';
  799. X                break;
  800. X            }
  801. X#endif
  802. X#if defined(S_INSHD)
  803. X            if(file_mode & S_INSHD)                /* shared memory */
  804. X            {
  805. X                *rtn = 'm';
  806. X                break;
  807. X            }
  808. X            break;
  809. X#endif
  810. X#endif
  811. X
  812. X        default:        *rtn = '?'; break;    /* ??? */
  813. X    }
  814. X
  815. X    if(file_mode & 000400) *(rtn + 1) = 'r';
  816. X    if(file_mode & 000200) *(rtn + 2) = 'w';
  817. X    if(file_mode & 000100) *(rtn + 3) = 'x';
  818. X    if(file_mode & 004000) *(rtn + 3) = 's';
  819. X    if(file_mode & 000040) *(rtn + 4) = 'r';
  820. X    if(file_mode & 000020) *(rtn + 5) = 'w';
  821. X    if(file_mode & 000010) *(rtn + 6) = 'x';
  822. X    if(file_mode & 002000) *(rtn + 6) = 's';
  823. X    if(file_mode & 000004) *(rtn + 7) = 'r';
  824. X    if(file_mode & 000002) *(rtn + 8) = 'w';
  825. X    if(file_mode & 000001) *(rtn + 9) = 'x';
  826. X    if(file_mode & 001000) *(rtn + 9) = 't';
  827. X
  828. X    return(rtn);
  829. X
  830. X}    /* end of mode_map */
  831. X
  832. X/*+-------------------------------------------------------------------------
  833. X    dumbtty_newline()
  834. X--------------------------------------------------------------------------*/
  835. Xvoid
  836. Xdumbtty_newline()
  837. X{
  838. X    if(dumbtty_pos)
  839. X        printf("\r\n");
  840. X    dumbtty_pos = 0;
  841. X
  842. X}    /* end of dumbtty_newline */
  843. X
  844. X/*+-------------------------------------------------------------------------
  845. X    clear_area(w,row,col,len)
  846. X--------------------------------------------------------------------------*/
  847. Xclear_area(w,row,col,len)
  848. XWINDOW    *w;
  849. Xint row;
  850. Xint col;
  851. Xint len;
  852. X{
  853. X    if(dumbtty)
  854. X        return;
  855. X    wmove(w,row,col);
  856. X    while(len-- > 0)
  857. X        waddch(w,' ');
  858. X    wmove(w,row,col);
  859. X
  860. X}    /* end of clear_area */
  861. X
  862. X/*+-------------------------------------------------------------------------
  863. X    clear_area_char(w,row,col,len,fillchar)
  864. X--------------------------------------------------------------------------*/
  865. Xclear_area_char(w,row,col,len,fillchar)
  866. XWINDOW    *w;
  867. Xint row;
  868. Xint col;
  869. Xint len;
  870. Xchar fillchar;
  871. X{
  872. X    if(dumbtty)
  873. X        return;
  874. X    wmove(w,row,col);
  875. X    while(len-- > 0)
  876. X        waddch(w,fillchar);
  877. X    wmove(w,row,col);
  878. X
  879. X}    /* end of clear_area_char */
  880. X
  881. X/*+-------------------------------------------------------------------------
  882. X    report_top_line(topstr)
  883. X   top line: row 1 col 17 length 42
  884. X--------------------------------------------------------------------------*/
  885. Xvoid
  886. Xreport_top_line(topstr)
  887. Xchar *topstr;
  888. X{
  889. Xchar s42[42];
  890. X
  891. X    if(dumbtty)
  892. X    {
  893. X        dumbtty_newline();
  894. X        dumbtty_pos = printf("%s",topstr);
  895. X        fflush(stdout);
  896. X        return;
  897. X    }
  898. X
  899. X    clear_area(win,1,17,42);
  900. X    if(strlen(topstr) < 40)
  901. X        waddstr(win,topstr);
  902. X    else
  903. X    {
  904. X        strncpy(s42,topstr,40);
  905. X        s42[40] = 0;
  906. X        waddstr(win,s42);
  907. X    }
  908. X}    /* end of report_top_line */
  909. X
  910. X/*+-------------------------------------------------------------------------
  911. X    report_xfer_mode(modestr)  BINARY/ASCII
  912. X   protocol xfer type: row 7 col 20 length 6
  913. X--------------------------------------------------------------------------*/
  914. Xreport_xfer_mode(str)
  915. Xchar *str;
  916. X{
  917. Xchar s10[10];
  918. X
  919. X    if(dumbtty)
  920. X        return;
  921. X    if(strlen(str) > 6)
  922. X    {
  923. X        strncpy(s10,str,6);
  924. X        s10[7] = 0;
  925. X        str = s10;
  926. X    }
  927. X    clear_area(win,7,20,6);
  928. X    waddstr(win,str);
  929. X    wrefresh(win);
  930. X
  931. X}    /* end of report_xfer_mode */
  932. X
  933. X/*+-------------------------------------------------------------------------
  934. X    report_protocol_type(str)
  935. X
  936. X  protocol type:  row 1 col 3 length 6 string
  937. X--------------------------------------------------------------------------*/
  938. Xreport_protocol_type(str)
  939. Xregister char *str;
  940. X{
  941. Xchar s10[10];
  942. X
  943. X    if(dumbtty)
  944. X    {
  945. X        return;
  946. X    }
  947. X
  948. X    if(strlen(str) > 6)
  949. X    {
  950. X        strncpy(s10,str,6);
  951. X        s10[7] = 0;
  952. X        str = s10;
  953. X    }
  954. X    clear_area(win,1,3,6);
  955. X    waddstr(win,str);
  956. X    wrefresh(win);
  957. X
  958. X}    /* end of report_protocol_type */
  959. X
  960. X/*+-------------------------------------------------------------------------
  961. X    report_protocol_crc_type(str)
  962. X
  963. X  protocol crc type:  row 1 col 9 length 6
  964. X--------------------------------------------------------------------------*/
  965. Xreport_protocol_crc_type(str)
  966. Xregister char *str;
  967. X{
  968. Xchar s8[8];
  969. X
  970. X    if(dumbtty)
  971. X    {
  972. X        return;
  973. X    }
  974. X
  975. X    if(strlen(str) > 6)
  976. X    {
  977. X        strncpy(s8,str,6);
  978. X        s8[7] = 0;
  979. X        str = s8;
  980. X    }
  981. X    clear_area(win,1,9,6);
  982. X    waddstr(win,str);
  983. X    wrefresh(win);
  984. X
  985. X}    /* end of report_protocol_crc_type */
  986. X
  987. X/*+-------------------------------------------------------------------------
  988. X    report_uninit(sig)
  989. X--------------------------------------------------------------------------*/
  990. Xvoid
  991. Xreport_uninit(sig)
  992. Xint sig;        /* if -1, called by normal code, else kill() value */
  993. X{
  994. X    float rate = 0.0;
  995. X    float eff = 0.0;
  996. X
  997. X    if(report_init_complete)
  998. X    {
  999. X        current_seconds = time((long *)0);
  1000. X        elapsed_seconds = current_seconds - start_seconds;
  1001. X        if(elapsed_seconds && (zcurses_baud_rate > 50))
  1002. X        {
  1003. X            rate = (float)total_data_bytes_xfered /
  1004. X                (float)elapsed_seconds;
  1005. X            if(zcurses_baud_rate)
  1006. X                eff  = 100.0 * (rate / ((float)zcurses_baud_rate / 10.0));
  1007. X        }
  1008. X        if(rate > 0.01)
  1009. X        {
  1010. X            sprintf(s128,"XFERINFO transaction rate ~= %.0f ch/sec (%.0f%%)",
  1011. X                rate,(eff > 0.5) ? eff : 0.0);
  1012. X            if(log_packets)
  1013. X            {
  1014. X                write(log_packets,"info: ",6);
  1015. X                write(log_packets,s128,strlen(s128));
  1016. X                write(log_packets,"\n",1);
  1017. X            }
  1018. X            report_top_line(s128 + 9);
  1019. X#if defined(WHT)
  1020. X            ecu_log_event(getppid(),s128);
  1021. X#endif
  1022. X        }
  1023. X        if(dumbtty)
  1024. X            dumbtty_newline();
  1025. X        else
  1026. X        {
  1027. X            report_file_byte_io(0L);
  1028. X            report_rx_tx_count();
  1029. X            wmove(win,WIN_LINES - 1,WIN_COLS - 1);
  1030. X            wrefresh(win);
  1031. X            endwin();
  1032. X            fprintf(stderr,"\r\n\r\n\r\n");
  1033. X            fflush(stderr);
  1034. X        }
  1035. X        report_init_complete = 0;
  1036. X    }
  1037. X
  1038. X}    /* end of report_uninit */
  1039. X
  1040. X/*+-------------------------------------------------------------------------
  1041. X    determine_output_mode()
  1042. X--------------------------------------------------------------------------*/
  1043. Xint
  1044. Xdetermine_output_mode()
  1045. X{
  1046. X#if defined(CONS_GET)
  1047. X    int monitor_type;
  1048. X#endif
  1049. X    struct stat dn;
  1050. X    struct stat tty_stat;
  1051. X#ifdef NO_PTY_CURSES
  1052. X    struct stat pty_stat;
  1053. X#endif
  1054. X
  1055. X    if(force_dumbtty)
  1056. X    {
  1057. X        dumbtty = 1;
  1058. X        report_verbosity = 1;
  1059. X        report_init_complete = 1;
  1060. X        return(1);
  1061. X    }
  1062. X
  1063. X#ifndef M_SYSV    /* these are always set thus for non-SCO */
  1064. X    vanilla_ruling();
  1065. X#endif
  1066. X
  1067. X#if defined(CONS_GET)
  1068. X    if(ioctl(0,CONS_GET,&monitor_type) < 0)    /* not multiscreen */
  1069. X    {
  1070. X#endif
  1071. X
  1072. X#ifdef M_SYSV    /* SCO non AT console */
  1073. X        vanilla_ruling();
  1074. X#endif
  1075. X
  1076. X        /*
  1077. X         * if tty (console) is not character special, only report
  1078. X         * basic progress
  1079. X         */
  1080. X        memset((char *)&dn,0,sizeof(dn));
  1081. X        stat("/dev/null",&dn);
  1082. X        if(fstat(0,&tty_stat) ||
  1083. X            ((tty_stat.st_mode & S_IFMT) != S_IFCHR) ||
  1084. X            (dn.st_rdev == tty_stat.st_rdev))
  1085. X        {
  1086. X            dumbtty = 1;
  1087. X            report_verbosity = 0;
  1088. X            report_init_complete = 1;
  1089. X            return(1);
  1090. X        }
  1091. X
  1092. X#ifdef NO_PTY_CURSES
  1093. X        /*
  1094. X         * if pty (must be xterm), send clear screen and no curses
  1095. X         */
  1096. X        if(!stat("/dev/ttyp0",&pty_stat) &&
  1097. X            (pty_stat.st_rdev & 0xFF00) == (tty_stat.st_rdev & 0xFF00))
  1098. X        {
  1099. X        static char ff[] = "\033[H\0332J\r\n";
  1100. X            write(2,ff,strlen(ff));
  1101. X            dumbtty = 1;
  1102. X            report_verbosity = 1;
  1103. X            report_init_complete = 1;
  1104. X            return(1);
  1105. X        }
  1106. X#endif
  1107. X
  1108. X        /*
  1109. X         * if non-multiscreen tty baud rate not at least that
  1110. X         * of the attached line, use no curses, but do be a bit
  1111. X         * more verbose than if tty not char special
  1112. X         */
  1113. X#ifdef TTY_VS_LINE_SPEED_NO_CURSES
  1114. X        test_tty_and_line_baud();
  1115. X#endif
  1116. X
  1117. X#if defined(CONS_GET)
  1118. X    }
  1119. X#endif
  1120. X
  1121. X    return(dumbtty);
  1122. X
  1123. X}    /* end of determine_output_mode */
  1124. X
  1125. X/*+-------------------------------------------------------------------------
  1126. X    report_init(title)
  1127. X  "top line": row 1 col 11 len 21
  1128. X  file quan:  row 2 col 15 len  3
  1129. X              row 2 col 12 len  7 clear "of ###"
  1130. X  start time: row 8 col 21 len  8
  1131. X  "window:"   row 8 col 50 len  7
  1132. X--------------------------------------------------------------------------*/
  1133. Xvoid
  1134. Xreport_init(title)
  1135. Xchar *title;
  1136. X{
  1137. X    register int itmp;
  1138. X
  1139. X    if(report_init_complete)
  1140. X        return;
  1141. X
  1142. X    start_seconds = time((long *)0);
  1143. X    current_seconds = start_seconds;
  1144. X
  1145. X    if(dumbtty)
  1146. X        return;
  1147. X
  1148. X#if defined(FASI)
  1149. X        (void)ioctl(iofd,FASIC_SIP,&fip_start);
  1150. X#endif /* FASI */
  1151. X
  1152. X    if(!initscr())
  1153. X        exit(254);
  1154. X    if(!stdscr)
  1155. X        exit(254);
  1156. X    crmode();
  1157. X    noecho();
  1158. X    nonl();
  1159. X    clear();
  1160. X    report_init_complete = 1;
  1161. X    win = newwin(WIN_LINES,WIN_COLS,WIN_TOPY,WIN_LEFTX);
  1162. X    box(win,sVR,sHR);
  1163. X#ifndef SVR4
  1164. X    wmove(win,0,0); waddch(win,sTL);
  1165. X    wmove(win,win->_maxy - 1,0); waddch(win,sBL);
  1166. X    wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,sBR);
  1167. X    wmove(win,0,win->_maxx - 1); waddch(win,sTR);
  1168. X#endif
  1169. X    wmove(win,0,2);
  1170. X    wstandout(win);
  1171. X    waddch(win,'[');
  1172. X    waddch(win,' ');
  1173. X    strcpy(s128,title);
  1174. X    waddstr(win,s128);
  1175. X    waddch(win,' ');
  1176. X    waddch(win,']');
  1177. X    wstandend(win);
  1178. X#ifdef SVR4
  1179. X    whline(win, (unsigned long)(sHR & 0x00ff), 2);
  1180. X    wmove(win,0, 8 + strlen(title));
  1181. X#else
  1182. X    waddch(win,sHR);
  1183. X    waddch(win,sHR);
  1184. X#endif
  1185. X    waddch(win,' ');
  1186. X    itmp = WIN_COLS - 2 - 7 - strlen(title);
  1187. X    curr_dir[itmp] = 0;
  1188. X    waddstr(win,curr_dir);
  1189. X    waddch(win,' ');
  1190. X    if(bottom_label)
  1191. X    {
  1192. X        strncpy(s128,bottom_label,WIN_COLS - 6);
  1193. X        s128[WIN_COLS - 6] = 0;
  1194. X        wmove(win,WIN_LINES - 1,2);
  1195. X        waddch(win,' ');
  1196. X        waddstr(win,s128);
  1197. X        waddch(win,' ');
  1198. X    }
  1199. X
  1200. X    itmp = 0;
  1201. X    while(1)
  1202. X    {
  1203. X        if(win_template[itmp] == (char *)0)
  1204. X            break;
  1205. X        wmove(win,itmp + 1,1);
  1206. X        waddstr(win,win_template[itmp++]);
  1207. X    }
  1208. X    if(ecusz_flag)
  1209. X    {
  1210. X        clear_area(win,2,15,3);
  1211. X        sprintf(s128,"%-3d",npats);
  1212. X        waddstr(win,s128);
  1213. X#if defined(FORK_DEBUG)
  1214. X        sprintf(s128,"DEBUG ecusz pid %d",getpid());
  1215. X#endif
  1216. X    }
  1217. X    else    /* ecurz */
  1218. X    {
  1219. X        clear_area(win,2,11,8);    /* clear "of ###" */
  1220. X        waddstr(win,":");
  1221. X#if defined(FORK_DEBUG)
  1222. X        sprintf(s128,"DEBUG ecurz pid %d",getpid());
  1223. X#endif
  1224. X    }
  1225. X
  1226. X#if defined(FORK_DEBUG)
  1227. X    ecu_log_event(getppid(),s128);
  1228. X#endif
  1229. X
  1230. X    clear_area(win,1,11,21);
  1231. X    report_error_count();
  1232. X    clear_area(win,8,21,8);        /* starting time */
  1233. X    waddstr(win,get_tod(1,(char *)0));
  1234. X
  1235. X    if(show_window)
  1236. X    {
  1237. X        wmove(win,8,50);
  1238. X        waddstr(win,"window:");
  1239. X        wmove(win,9,50);
  1240. X        waddstr(win,"+0");
  1241. X    }
  1242. X
  1243. X    wrefresh(win);
  1244. X
  1245. X}    /* end of report_init */
  1246. X
  1247. X/*+-------------------------------------------------------------------------
  1248. X    report_rx_ind(status)
  1249. X--------------------------------------------------------------------------*/
  1250. Xvoid
  1251. Xreport_rx_ind(status)
  1252. Xint status;
  1253. X{
  1254. Xchar *cptr;
  1255. X
  1256. X    if(dumbtty)
  1257. X    {
  1258. X        if(report_verbosity && status)
  1259. X        {
  1260. X            printf("R");
  1261. X            if(++dumbtty_pos > 75)
  1262. X            {
  1263. X                dumbtty_newline();
  1264. X                current_seconds = time((long *)0);
  1265. X                elapsed_seconds = current_seconds - this_file_start_seconds;
  1266. X                cptr = get_elapsed_time(elapsed_seconds);
  1267. X                dumbtty_pos = printf("%s elapsed ",cptr +
  1268. X                    ((elapsed_seconds < 3600L) ? 3 : 0));
  1269. X            }
  1270. X            fflush(stdout);
  1271. X        }
  1272. X        return;
  1273. X    }
  1274. X    wmove(win,1,54);
  1275. X    waddch(win,(status) ? 'R' : ' ');
  1276. X    wmove(win,1,54);
  1277. X    wrefresh(win);
  1278. X}    /* end of report_rx_ind */
  1279. X
  1280. X/*+-------------------------------------------------------------------------
  1281. X    report_tx_ind(status)
  1282. X--------------------------------------------------------------------------*/
  1283. Xvoid
  1284. Xreport_tx_ind(status)
  1285. Xint status;
  1286. X{
  1287. Xchar *cptr;
  1288. X    if(dumbtty)
  1289. X    {
  1290. X        if(report_verbosity && status)
  1291. X        {
  1292. X            printf("T");
  1293. X            if(++dumbtty_pos > 75)
  1294. X            {
  1295. X                dumbtty_newline();
  1296. X                dumbtty_newline();
  1297. X                current_seconds = time((long *)0);
  1298. X                elapsed_seconds = current_seconds - this_file_start_seconds;
  1299. X                cptr = get_elapsed_time(elapsed_seconds);
  1300. X                dumbtty_pos = printf("%s elapsed ",cptr +
  1301. X                    ((elapsed_seconds < 3600L) ? 3 : 0));
  1302. X            }
  1303. X            fflush(stdout);
  1304. X        }
  1305. X        return;
  1306. X    }
  1307. X    wmove(win,1,56);
  1308. X    waddch(win,(status) ? 'T' : ' ');
  1309. X    wmove(win,1,56);
  1310. X    wrefresh(win);
  1311. X}    /* end of report_tx_ind */
  1312. X
  1313. X/*+-------------------------------------------------------------------------
  1314. X    report_window() - if enable, show open widow size
  1315. X--------------------------------------------------------------------------*/
  1316. Xvoid
  1317. Xreport_window()
  1318. X{
  1319. X    if(show_window && !dumbtty)
  1320. X    {
  1321. X    long ltmp;
  1322. X        wmove(win,9,50);
  1323. X        if((ltmp = (Txpos - Rxpos)) > 999999L)
  1324. X            waddstr(win,">+999999");
  1325. X        else if(ltmp < -999999L)
  1326. X            ;
  1327. X        else
  1328. X        {
  1329. X            sprintf(s128,"%+-8ld",ltmp);
  1330. X            waddstr(win,s128);
  1331. X            if(log_packets)
  1332. X            {
  1333. X                write(log_packets,"window: ",8);
  1334. X                write(log_packets,s128,strlen(s128));
  1335. X                write(log_packets,"\n",1);
  1336. X            }
  1337. X        }
  1338. X    }
  1339. X}    /* end of report_window */
  1340. X
  1341. X/*+-------------------------------------------------------------------------
  1342. X    report_rx_tx_count()
  1343. X
  1344. X  This function may be counted upon to perform wrefresh(win)
  1345. X
  1346. X  rx char count:          row  6 col 16 len 8 unsigned long
  1347. X  tx char count:          row  6 col 29 len 8 unsigned long
  1348. X  session elapsed time:   row  9 col 21 len 8
  1349. X  this file elapsed time: row  9 col 41 len 8
  1350. X  current tod:            row  9 col  3 len 8
  1351. X  window:                 row  9 col 50 len 8
  1352. X
  1353. XIf FASI,
  1354. X  FE:                     row 14 col  6 len 4
  1355. X  OE:                     row 14 col 13 len 4
  1356. X  rcvd count:             row 14 col 22 len 8 unsigned long
  1357. X  xmtd count:             row 14 col 36 len 8 unsigned long
  1358. X  RTS status:             row 14 col 48 len 1
  1359. X  CTS status:             row 14 col 55 len 1
  1360. X  xmtr CTS count:         row 15 col 18 len 4
  1361. X  xmtr XOFF count:        row 15 col 28 len 4
  1362. X  rcvr CTS count:         row 15 col 42 len 4
  1363. X  rcvr XOFF count:        row 15 col 52 len 4
  1364. X  xmtr queue depth        row 16 col 16 len 5
  1365. X  xmtr queue size         row 16 col 25 len 5 (one time)
  1366. X  rcvr queue depth        row 16 col 37 len 5
  1367. X  rcvr queue size         row 16 col 46 len 5 (one time)
  1368. X
  1369. XIf sun,
  1370. X  output queue depth      row 14 col 23 len 6
  1371. X  RTS status              row 14 col 35 len 1
  1372. X  CTS status              row 14 col 42 len 1
  1373. X  input queue depth       row 15 col 23 len 6
  1374. X  input queue avail       row 15 col 49 len 6
  1375. X--------------------------------------------------------------------------*/
  1376. Xreport_rx_tx_count()
  1377. X{
  1378. X    extern unsigned long rx_char_count;
  1379. X    extern unsigned long tx_char_count;
  1380. X#if defined(FASI)
  1381. X    unsigned long ltmp;
  1382. X    struct fas_info now;
  1383. X#endif    /* FASI */
  1384. X#if defined(sun)
  1385. Xuint output_queue;
  1386. Xuint input_avail;
  1387. Xuint input_size;
  1388. Xuint modem_lines;
  1389. X#endif
  1390. X
  1391. X    register char *cptr;
  1392. X
  1393. X    if(dumbtty)
  1394. X    {
  1395. X        return;
  1396. X    }
  1397. X
  1398. X    sprintf(s128,"%-8ld",rx_char_count);
  1399. X    wmove(win,6,16);
  1400. X    waddstr(win,s128);
  1401. X    sprintf(s128,"%-8ld",tx_char_count);
  1402. X    wmove(win,6,29);
  1403. X    waddstr(win,s128);
  1404. X
  1405. X    /* now time of day */
  1406. X    wmove(win,9,3);
  1407. X    cptr = get_tod(1,(char *)0);
  1408. X    waddstr(win,cptr);
  1409. X    current_seconds = time((long *)0);
  1410. X    elapsed_seconds = current_seconds - start_seconds;
  1411. X    cptr = get_elapsed_time(elapsed_seconds);
  1412. X    wmove(win,9,21);
  1413. X    waddstr(win,cptr);
  1414. X    if(this_file_start_seconds)
  1415. X        elapsed_seconds = current_seconds - this_file_start_seconds;
  1416. X    else
  1417. X        elapsed_seconds = 0;
  1418. X    cptr = get_elapsed_time(elapsed_seconds);
  1419. X    wmove(win,9,41);
  1420. X    waddstr(win,cptr);
  1421. X
  1422. X#if defined(FASI)
  1423. X    if(!ioctl(iofd,FASIC_SIP,&now))
  1424. X    {
  1425. X    static int statics = 0;    /* one time display flag */
  1426. X        if((ltmp = now.framing_errors - fip_start.framing_errors) > 999L)
  1427. X            ltmp = 999L;
  1428. X        sprintf(s128,"%-3lu",ltmp);
  1429. X        wmove(win,14,6);
  1430. X        waddstr(win,s128);
  1431. X
  1432. X        if((ltmp = now.overrun_errors - fip_start.overrun_errors) > 999L)
  1433. X            ltmp = 999L;
  1434. X        sprintf(s128,"%-3lu",ltmp);
  1435. X        wmove(win,14,13);
  1436. X        waddstr(win,s128);
  1437. X
  1438. X        ltmp = now.characters_received - fip_start.characters_received;
  1439. X        sprintf(s128,"%-8lu",ltmp);
  1440. X        wmove(win,14,22);
  1441. X        waddstr(win,s128);
  1442. X
  1443. X        ltmp = now.characters_transmitted - fip_start.characters_transmitted;
  1444. X        sprintf(s128,"%-8lu",ltmp);
  1445. X        wmove(win,14,36);
  1446. X        waddstr(win,s128);
  1447. X
  1448. X        wmove(win,14,49);
  1449. X        waddch(win,(now.mcr & MC_SET_RTS) ? 'T' : 'F');
  1450. X
  1451. X        wmove(win,14,55);
  1452. X        waddch(win,(now.msr & MS_CTS_PRESENT) ? 'T' : 'F');
  1453. X
  1454. X        ltmp = now.xmtr_hw_flow_count - fip_start.xmtr_hw_flow_count;
  1455. X        if(ltmp > 9999L)
  1456. X            ltmp = 9999L;
  1457. X        sprintf(s128,"%-4lu",ltmp);
  1458. X        wmove(win,15,17);
  1459. X        waddstr(win,s128);
  1460. X
  1461. X        ltmp = now.xmtr_sw_flow_count - fip_start.xmtr_sw_flow_count;
  1462. X        if(ltmp > 9999L)
  1463. X            ltmp = 9999L;
  1464. X        sprintf(s128,"%-4lu",ltmp);
  1465. X        wmove(win,15,27);
  1466. X        waddstr(win,s128);
  1467. X
  1468. X        ltmp = now.rcvr_hw_flow_count - fip_start.rcvr_hw_flow_count;
  1469. X        if(ltmp > 9999L)
  1470. X            ltmp = 9999L;
  1471. X        sprintf(s128,"%-4lu",ltmp);
  1472. X        wmove(win,15,41);
  1473. X        waddstr(win,s128);
  1474. X
  1475. X        ltmp = now.rcvr_sw_flow_count - fip_start.rcvr_sw_flow_count;
  1476. X        if(ltmp > 9999L)
  1477. X            ltmp = 9999L;
  1478. X        sprintf(s128,"%-4lu",ltmp);
  1479. X        wmove(win,15,51);
  1480. X        waddstr(win,s128);
  1481. X
  1482. X        if(now.xmit_ring_cnt > 99999)
  1483. X            now.xmit_ring_cnt = 99999;
  1484. X        sprintf(s128,"%-5u",now.xmit_ring_cnt);
  1485. X        wmove(win,16,16);
  1486. X        waddstr(win,s128);
  1487. X
  1488. X        if(now.recv_ring_cnt > 99999)
  1489. X            now.recv_ring_cnt = 99999;
  1490. X        sprintf(s128,"%-5u",now.recv_ring_cnt);
  1491. X        wmove(win,16,37);
  1492. X        waddstr(win,s128);
  1493. X
  1494. X        if(!statics)
  1495. X        {
  1496. X            statics = 1;
  1497. X            ltmp = XMIT_BUFF_SIZE;
  1498. X            if(ltmp > 99999)
  1499. X                ltmp = 99999;
  1500. X            sprintf(s128,"%-5lu",ltmp);
  1501. X            wmove(win,16,25);
  1502. X            waddstr(win,s128);
  1503. X
  1504. X            ltmp = RECV_BUFF_SIZE;
  1505. X            if(ltmp > 99999)
  1506. X                ltmp = 99999;
  1507. X            sprintf(s128,"%-5lu",ltmp);
  1508. X            wmove(win,16,46);
  1509. X            waddstr(win,s128);
  1510. X        }
  1511. X    }
  1512. X#endif    /* FASI */
  1513. X
  1514. X#if defined(sun)
  1515. X    output_queue = 0;
  1516. X    ioctl(iofd,TIOCOUTQ,(int *)&output_queue);
  1517. X    if(output_queue > 999999)
  1518. X        output_queue = 999999;
  1519. X    sprintf(s128,"%6u",output_queue);
  1520. X    wmove(win,14,23);
  1521. X    waddstr(win,s128);
  1522. X
  1523. X    modem_lines = 0;
  1524. X    ioctl(iofd,TIOCMGET,(int *)&modem_lines);
  1525. X    wmove(win,14,35);
  1526. X    waddch(win,(modem_lines & TIOCM_RTS) ? 'T' : 'F');
  1527. X    wmove(win,14,42);
  1528. X    waddch(win,(modem_lines & TIOCM_CTS) ? 'T' : 'F');
  1529. X
  1530. X    input_size = 0;
  1531. X    input_avail = 0;
  1532. X    ioctl(iofd,TIOCISPACE,(int *)&input_avail);
  1533. X    ioctl(iofd,TIOCISIZE,(int *)&input_size);
  1534. X    if(input_size > 999999)
  1535. X        input_size = 999999;
  1536. X    if(input_avail > 999999)
  1537. X        input_avail = 999999;
  1538. X    sprintf(s128,"%6u",input_size - input_avail);
  1539. X    wmove(win,15,23);
  1540. X    waddstr(win,s128);
  1541. X    sprintf(s128,"%6u",input_avail);
  1542. X    wmove(win,15,49);
  1543. X    waddstr(win,s128);
  1544. X#endif
  1545. X
  1546. X    report_window();
  1547. X
  1548. X    wrefresh(win);        /* calling procs expect this to occur always */
  1549. X
  1550. X}    /* end of report_rx_tx_count */
  1551. X
  1552. X/*+-------------------------------------------------------------------------
  1553. X    report_mode(comm_mode)
  1554. X
  1555. X comm mode row 7 col 52 length 6
  1556. X   3: save old tty stat, set raw mode with flow control
  1557. X   2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
  1558. X   1: save old tty stat, set raw mode 
  1559. X   0: restore original tty mode
  1560. X--------------------------------------------------------------------------*/
  1561. Xvoid
  1562. Xreport_mode(comm_mode)
  1563. Xint comm_mode;
  1564. X{
  1565. Xchar *cptr;
  1566. Xchar tmp[8];
  1567. X
  1568. X    if(dumbtty)
  1569. X    {
  1570. X        return;
  1571. X    }
  1572. X
  1573. X    clear_area(win,7,52,6);
  1574. X    switch(comm_mode)
  1575. X    {
  1576. X        case 0:
  1577. X            cptr = "NORMAL";
  1578. X            break;
  1579. X        case 1:
  1580. X            cptr = "RAW";
  1581. X            break;
  1582. X        case 2:
  1583. X            cptr = "RAW-g";
  1584. X            break;
  1585. X        case 3:
  1586. X            cptr = "RAW-f";
  1587. X            break;
  1588. X        default:
  1589. X            sprintf(tmp,"%5u",comm_mode);
  1590. X            cptr = tmp;
  1591. X    }
  1592. X    waddstr(win,cptr);
  1593. X    wrefresh(win);
  1594. X    if(log_packets)
  1595. X    {
  1596. X        write(log_packets,"comm_mode: ",6);
  1597. X        write(log_packets,cptr,strlen(cptr));
  1598. X        write(log_packets,"\n",1);
  1599. X    }
  1600. X
  1601. X}    /* end of report_mode */
  1602. X
  1603. X/*+-------------------------------------------------------------------------
  1604. X    report_rxblklen(blklen) 
  1605. Xrow 7 col 35 5 chars
  1606. X--------------------------------------------------------------------------*/
  1607. Xvoid
  1608. Xreport_rxblklen(blklen)
  1609. Xint blklen;
  1610. X{
  1611. X    char tmp[10];
  1612. X
  1613. X    if(dumbtty)
  1614. X    {
  1615. X        return;
  1616. X    }
  1617. X
  1618. X    sprintf(tmp,"%-5u",blklen);
  1619. X    clear_area(win,7,35,5);
  1620. X    waddstr(win,tmp);
  1621. X    wrefresh(win);
  1622. X}    /* end of report_rxblklen */
  1623. X
  1624. X/*+-------------------------------------------------------------------------
  1625. X    report_txblklen(blklen) 
  1626. Xrow 7 col 35 5 chars
  1627. X--------------------------------------------------------------------------*/
  1628. Xvoid
  1629. Xreport_txblklen(blklen)
  1630. Xint blklen;
  1631. X{
  1632. X    if(dumbtty)
  1633. X    {
  1634. X        return;
  1635. X    }
  1636. X
  1637. X    report_rxblklen(blklen);
  1638. X}    /* end of report_txblklen */
  1639. X
  1640. X/*+-------------------------------------------------------------------------
  1641. X    report_file_xfer_rate(text,count,final)
  1642. X--------------------------------------------------------------------------*/
  1643. Xvoid
  1644. Xreport_file_xfer_rate(text,count,final)
  1645. Xchar *text;
  1646. Xlong count;
  1647. Xint final;
  1648. X{
  1649. X    float rate = 0.0;
  1650. X    float efficiency = 0.0;
  1651. X    static long last_report = 0L;
  1652. X
  1653. X    current_seconds = time((long *)0);
  1654. X
  1655. X    if(!final && (current_seconds < (last_report + 5L)))
  1656. X        return;
  1657. X    last_report = current_seconds;
  1658. X
  1659. X    elapsed_seconds = current_seconds - this_file_start_seconds;
  1660. X
  1661. X    if(count && (elapsed_seconds > 0) && zcurses_baud_rate)
  1662. X    {
  1663. X        rate = (float)count / (float)elapsed_seconds;
  1664. X        efficiency  = 100.0 * (rate / ((float)zcurses_baud_rate / 10.0));
  1665. X    }
  1666. X
  1667. X    if(efficiency > 120.0)    /* interim hack for ecusz -r */
  1668. X        return;
  1669. X
  1670. X    if(rate > 0.01)
  1671. X    {
  1672. X        if(efficiency < 0.5)
  1673. X            sprintf(s128,"XFERINFO %s rate ~= %.0f ch/sec",text,rate);
  1674. X        else
  1675. X        {
  1676. X            sprintf(s128,"XFERINFO %s rate ~= %.0f ch/sec (%.0lf%%)",
  1677. X                text,rate,efficiency);
  1678. X        }
  1679. X        if(!dumbtty)
  1680. X            report_top_line(s128 + 9);
  1681. X#if defined(WHT)
  1682. X        if(final)
  1683. X            ecu_log_event(getppid(),s128);
  1684. X#endif
  1685. X    }
  1686. X
  1687. X}    /* end of report_file_xfer_rate */
  1688. X
  1689. X/*+-------------------------------------------------------------------------
  1690. X    report_transfer_progress(filepos,initfpos)
  1691. X--------------------------------------------------------------------------*/
  1692. Xvoid
  1693. Xreport_transfer_progress(filepos,initfpos)
  1694. Xlong filepos;
  1695. Xlong initfpos;
  1696. X{
  1697. Xchar refr;
  1698. X
  1699. X    if(dumbtty)
  1700. X        return;
  1701. X
  1702. X    if(rdchk(0))
  1703. X    {
  1704. X        read(0,&refr,1);
  1705. X        if(refr == 0x0C || refr == 0x012)    /* ^L or ^R */
  1706. X        {
  1707. X            touchwin(stdscr);
  1708. X            wrefresh(stdscr);
  1709. X            touchwin(win);
  1710. X            wrefresh(win);
  1711. X        }
  1712. X    }
  1713. X
  1714. X    if((filepos > 99999999L) || (filepos < 0L))
  1715. X        return;
  1716. X
  1717. X    sprintf(s128,"%-8lu",filepos);
  1718. X    wmove(win,3,19);
  1719. X    waddstr(win,s128);
  1720. X    report_file_xfer_rate("data",filepos - initfpos,0);
  1721. X    report_rx_tx_count();    /* which will do a refresh */
  1722. X
  1723. X}    /* end of report_transfer_progress */
  1724. X
  1725. X/*+-------------------------------------------------------------------------
  1726. X    report_rxpos(pos) - report received file progress
  1727. X--------------------------------------------------------------------------*/
  1728. Xvoid
  1729. Xreport_rxpos(pos)
  1730. Xlong pos;
  1731. X{
  1732. X
  1733. X    if(dumbtty)
  1734. X        return;
  1735. X    report_transfer_progress(pos,initial_filepos);
  1736. X
  1737. X}    /* end of report_rxpos */
  1738. X
  1739. X/*+-------------------------------------------------------------------------
  1740. X    report_txpos(pos) - report transmitted file progress
  1741. X--------------------------------------------------------------------------*/
  1742. Xvoid
  1743. Xreport_txpos(pos)
  1744. Xlong pos;
  1745. X{
  1746. X
  1747. X    if(dumbtty)
  1748. X        return;
  1749. X    report_transfer_progress(pos,initial_filepos);
  1750. X
  1751. X}    /* end of report_txpos */
  1752. X
  1753. X/*+-------------------------------------------------------------------------
  1754. X    report_error_count()
  1755. X
  1756. X  this file: row 10 col 22 len 3
  1757. X  total:     row 10 col 33 len 4
  1758. X  skipped:   row 10 col 53 len 3
  1759. X--------------------------------------------------------------------------*/
  1760. Xvoid
  1761. Xreport_error_count()
  1762. X{
  1763. X    char tmp[16];
  1764. X
  1765. X    if(dumbtty)
  1766. X    {
  1767. X        return;
  1768. X    }
  1769. X
  1770. X    wmove(win,10,22);
  1771. X    sprintf(tmp,"%-3d",this_file_errors);
  1772. X    if(this_file_errors)
  1773. X        wstandout(win);
  1774. X    waddstr(win,tmp);
  1775. X    if(this_file_errors)
  1776. X        wstandend(win);
  1777. X
  1778. X    wmove(win,10,33);
  1779. X    sprintf(tmp,"%-4d",total_errors);
  1780. X    if(total_errors)
  1781. X        wstandout(win);
  1782. X    waddstr(win,tmp);
  1783. X    if(total_errors)
  1784. X        wstandend(win);
  1785. X
  1786. X    wmove(win,10,53);
  1787. X    sprintf(tmp,"%-3d",skip_count);
  1788. X    waddstr(win,tmp);
  1789. X    wrefresh(win);
  1790. X
  1791. X}    /* end of report_error_count */
  1792. X
  1793. X/*+-------------------------------------------------------------------------
  1794. X    report_last_txhdr(rptstr,error_flag)
  1795. X    5,7,22
  1796. X--------------------------------------------------------------------------*/
  1797. Xvoid
  1798. Xreport_last_txhdr(rptstr,error_flag)
  1799. Xregister char *rptstr;
  1800. Xint error_flag;
  1801. X{
  1802. Xchar s24[24];
  1803. X
  1804. X    if(log_packets)
  1805. X    {
  1806. X        write(log_packets,"tx:   ",6);
  1807. X        write(log_packets,rptstr,strlen(rptstr));
  1808. X        write(log_packets,"\n",1);
  1809. X    }
  1810. X
  1811. X    if(dumbtty)
  1812. X    {
  1813. X        if(error_flag)
  1814. X        {
  1815. X            dumbtty_newline();
  1816. X            dumbtty_pos = printf("%s ",rptstr);
  1817. X            ++this_file_errors;
  1818. X            ++total_errors;
  1819. X        }
  1820. X        return;
  1821. X    }
  1822. X
  1823. X    if(strlen(rptstr) > 22)
  1824. X    {
  1825. X        strncpy(s24,rptstr,22);
  1826. X        s24[23] = 0;
  1827. X        rptstr = s24;
  1828. X    }
  1829. X    clear_area(win,5,7,22);
  1830. X    waddstr(win,rptstr);
  1831. X
  1832. X    if(error_flag)
  1833. X    {
  1834. X        ++this_file_errors;
  1835. X        ++total_errors;
  1836. X        report_error_count();
  1837. X    }
  1838. X#if 0
  1839. X    else
  1840. X        wrefresh(win);
  1841. X#endif
  1842. X
  1843. X}    /* end of report_last_txhdr */
  1844. X
  1845. X/*+-------------------------------------------------------------------------
  1846. X    report_last_rxhdr(rptstr,error_flag)
  1847. X    5,35,22
  1848. X--------------------------------------------------------------------------*/
  1849. Xvoid
  1850. Xreport_last_rxhdr(rptstr,error_flag)
  1851. Xregister char *rptstr;
  1852. Xint error_flag;
  1853. X{
  1854. Xchar s24[24];
  1855. Xextern int log_packets;
  1856. X
  1857. X    if(log_packets)
  1858. X    {
  1859. X        write(log_packets,"rx:   ",6);
  1860. X        write(log_packets,rptstr,strlen(rptstr));
  1861. X        write(log_packets,"\n",1);
  1862. X    }
  1863. X
  1864. X    if(dumbtty)
  1865. X    {
  1866. X        if(error_flag)
  1867. X        {
  1868. X            dumbtty_newline();
  1869. X            dumbtty_pos = printf("%s ",rptstr);
  1870. X            ++this_file_errors;
  1871. X            ++total_errors;
  1872. X        }
  1873. X        return;
  1874. X    }
  1875. X
  1876. X    if(strlen(rptstr) > 22)
  1877. X    {
  1878. X        strncpy(s24,rptstr,22);
  1879. X        s24[23] = 0;
  1880. X        rptstr = s24;
  1881. X    }
  1882. X    clear_area(win,5,35,22);
  1883. X    waddstr(win,rptstr);
  1884. X
  1885. X    report_window();
  1886. X    if(error_flag)
  1887. X    {
  1888. X        ++this_file_errors;
  1889. X        ++total_errors;
  1890. X        report_error_count();
  1891. X    }
  1892. X#if 0
  1893. X    else
  1894. X        wrefresh(win);
  1895. X#endif
  1896. X
  1897. X}    /* end of report_last_rxhdr */
  1898. X
  1899. X/*+-------------------------------------------------------------------------
  1900. X    report_str(rptstr,error_flag) row 11/12 col 3 len 55
  1901. X
  1902. X  error_flag == 0 for status/progress message
  1903. X             == 1 for bump error count, unless rptstr is null
  1904. X                  in which case, merely clear error string area
  1905. X             == 2 write string on bottom line (not an error)
  1906. X             == 3 write string on transaction line (not an error)
  1907. X             == -1 use error line but do not bump error count
  1908. X--------------------------------------------------------------------------*/
  1909. Xvoid
  1910. Xreport_str(rptstr,error_flag)
  1911. Xregister char *rptstr;
  1912. Xint error_flag;
  1913. X{
  1914. Xchar s60[60];
  1915. Xextern int log_packets;
  1916. X
  1917. X    if(log_packets)
  1918. X    {
  1919. X        sprintf(s60,"rpt %d:",error_flag);
  1920. X        write(log_packets,s60,strlen(s60));
  1921. X        write(log_packets,rptstr,strlen(rptstr));
  1922. X        write(log_packets,"\n",1);
  1923. X    }
  1924. X
  1925. X    if(dumbtty)
  1926. X    {
  1927. X        if(!strlen(rptstr))
  1928. X            return;
  1929. X        switch(error_flag)
  1930. X        {
  1931. X            case 0:
  1932. X                break;
  1933. X            case 1:
  1934. X                this_file_errors++;
  1935. X                total_errors++;
  1936. X            case -1:
  1937. X            case 2:
  1938. X            case 3:
  1939. X                dumbtty_newline();
  1940. X                dumbtty_pos = printf("%s ",rptstr);
  1941. X                fflush(stdout);
  1942. X        }
  1943. X        return;
  1944. X    }
  1945. X
  1946. X    if(strlen(rptstr) > 55)
  1947. X    {
  1948. X        strncpy(s60,rptstr,55);
  1949. X        s60[55] = 0;
  1950. X        rptstr = s60;
  1951. X    }
  1952. X
  1953. X    switch(error_flag)
  1954. X    {
  1955. X        case 0:
  1956. X            clear_area(win,12,3,55);
  1957. X            break;
  1958. X        case 1:
  1959. X            this_file_errors++;
  1960. X            total_errors++;
  1961. X            report_error_count();
  1962. X        case -1:
  1963. X            clear_area(win,11,3,55);
  1964. X            break;
  1965. X        case 2:
  1966. X            clear_area(win,13,3,55);
  1967. X            break;
  1968. X        case 3:
  1969. X            clear_area(win,4,3,55);
  1970. X            break;
  1971. X    }
  1972. X
  1973. X    waddstr(win,rptstr);
  1974. X    wrefresh(win);
  1975. X
  1976. X}    /* end of report_str */
  1977. X
  1978. X/*+-------------------------------------------------------------------------
  1979. X    report_transaction()
  1980. X--------------------------------------------------------------------------*/
  1981. Xvoid
  1982. Xreport_transaction(str)
  1983. Xchar *str;
  1984. X{
  1985. X    report_str(str,3);
  1986. X}    /* end of report_transaction */
  1987. X
  1988. X/*+-------------------------------------------------------------------------
  1989. X    report_file_open_tod() -- time of start of this file
  1990. X
  1991. X  this file open time: row 8 col 41 length 8
  1992. X--------------------------------------------------------------------------*/
  1993. Xvoid
  1994. Xreport_file_open_tod()
  1995. X{
  1996. X    if(dumbtty)
  1997. X        return;
  1998. X    clear_area(win,8,41,8);
  1999. X    waddstr(win,get_tod(1,(char *)0));
  2000. X    wrefresh(win);
  2001. X}    /* end of report_file_open_tod */
  2002. X
  2003. X/*+-------------------------------------------------------------------------
  2004. X    report_file_open_mode(file_mode)
  2005. X  mode map: row 4 col 46 len 10
  2006. X--------------------------------------------------------------------------*/
  2007. Xreport_file_open_mode(file_mode)
  2008. Xunsigned short file_mode;
  2009. X{
  2010. X    if(dumbtty)
  2011. X        return;
  2012. X    clear_area(win,3,46,10);
  2013. X    waddstr(win,mode_map(file_mode,(char *)0));
  2014. X    wrefresh(win);
  2015. X}    /* end of report_file_open_mode */
  2016. X
  2017. X/*+-------------------------------------------------------------------------
  2018. X    report_file_open_length(long_length)
  2019. X  length:   row 3 col 36 len  8
  2020. X--------------------------------------------------------------------------*/
  2021. Xreport_file_open_length(length)
  2022. Xlong length;
  2023. X{
  2024. X    if(dumbtty)
  2025. X        return;
  2026. X    clear_area(win,3,36,8);
  2027. X    if(length <= 0)
  2028. X        waddstr(win,"unknown");
  2029. X    else
  2030. X    {
  2031. X        sprintf(s128,"%-8lu",length);
  2032. X        waddstr(win,s128);
  2033. X    }
  2034. X    wrefresh(win);
  2035. X}    /* end of report_file_open_length */
  2036. X
  2037. X/*+-------------------------------------------------------------------------
  2038. X    report_file_send_open(filename,filestat)
  2039. X
  2040. X  filename: row 2 col 20 len 38
  2041. X  number:   row 2 col 8 len 3
  2042. X  length:   row 3 col 36 len  8
  2043. X  mode:     row 3 col 46 len 10
  2044. X  time of start of this file: row 4 col 47 length 8 hh:mm:ss
  2045. X--------------------------------------------------------------------------*/
  2046. Xvoid
  2047. Xreport_file_send_open(filename,filestat)
  2048. Xchar *filename;
  2049. Xstruct stat *filestat;
  2050. X{
  2051. Xchar s50[50];
  2052. Xregister char *cptr = filename;
  2053. X
  2054. X    if(log_packets)
  2055. X    {
  2056. X        write(log_packets,"file: ",6);
  2057. X        write(log_packets,filename,strlen(filename));
  2058. X        write(log_packets,"\n",1);
  2059. X    }
  2060. X
  2061. X    this_file_start_seconds = time((long *)0);
  2062. X    this_file_xfer_count = 0;
  2063. X
  2064. X    if(dumbtty)
  2065. X    {
  2066. X        dumbtty_newline();
  2067. X        dumbtty_pos = printf("Sending '%s' ",filename);
  2068. X        fflush(stdout);
  2069. X        return;
  2070. X    }
  2071. X
  2072. X    /* number */
  2073. X    clear_area(win,2,8,3);
  2074. X    sprintf(s50,"%-3d",Filcnt);
  2075. X    waddstr(win,s50);
  2076. X
  2077. X    /* filename */
  2078. X    if(strlen(filename) > 38)
  2079. X    {
  2080. X        strncpy(s50,filename,38);
  2081. X        s50[39] = 0;
  2082. X        cptr = s50;
  2083. X    }
  2084. X    clear_area(win,2,20,38);
  2085. X    waddstr(win,cptr);
  2086. X
  2087. X    /* length */
  2088. X    report_file_open_length(filestat->st_size);
  2089. X
  2090. X    /* mode */
  2091. X    report_file_open_mode(filestat->st_mode);
  2092. X
  2093. X    /* time of start of this file */
  2094. X    report_file_open_tod();
  2095. X
  2096. X    this_file_errors = 0;
  2097. X    report_error_count();
  2098. X}    /* end of report_file_send_open */
  2099. X
  2100. X/*+-------------------------------------------------------------------------
  2101. X    report_file_rcv_started(filename,length,last_mod_time,file_mode)
  2102. X
  2103. X  filenumber: row 2 col  8 len  3
  2104. X              row 2 col 12 len  7 clear "of ###"
  2105. X  filename:   row 2 col 20 len 38
  2106. X--------------------------------------------------------------------------*/
  2107. Xreport_file_rcv_started(filename,length,last_mod_time,file_mode)
  2108. Xchar *filename;
  2109. Xlong length;                /* if < 0, "UNKNOWN" */
  2110. Xlong last_mod_time;            /* not currently displayed */
  2111. Xunsigned short file_mode;    /* UNIX file modifier or zero */
  2112. X{
  2113. Xregister char *cptr;
  2114. Xchar s50[50];
  2115. X
  2116. X    if(log_packets)
  2117. X    {
  2118. X        write(log_packets,"file: ",6);
  2119. X        write(log_packets,filename,strlen(filename));
  2120. X        write(log_packets,"\n",1);
  2121. X    }
  2122. X
  2123. X    this_file_start_seconds = time((long *)0);
  2124. X    this_file_xfer_count = 0;
  2125. X
  2126. X    if(dumbtty)
  2127. X    {
  2128. X        dumbtty_newline();
  2129. X        dumbtty_pos = printf("Receiving '%s' ",filename) - 2;
  2130. X        fflush(stdout);
  2131. X        return;
  2132. X    }
  2133. X
  2134. X    /* filename */
  2135. X    if(strlen(filename) > 38)
  2136. X    {
  2137. X        strncpy(s50,filename,38);
  2138. X        s50[39] = 0;
  2139. X        cptr = s50;
  2140. X    }
  2141. X    else
  2142. X        cptr = filename;
  2143. X
  2144. X    clear_area(win,2,20,38);
  2145. X    waddstr(win,cptr);
  2146. X
  2147. X    /* file number */
  2148. X    clear_area(win,2,8,3);
  2149. X    Filcnt++;
  2150. X    sprintf(s50,"%-3d",Filcnt);    /* rz uses as file number 1-n */
  2151. X    waddstr(win,s50);
  2152. X
  2153. X/* if remote sender provides a file count, display it */
  2154. X    if(npats)
  2155. X    {
  2156. X        clear_area(win,2,12,7);    /* clear "of ###" */
  2157. X        sprintf(s50,"of %3d:",npats);
  2158. X        waddstr(win,s50);
  2159. X    }
  2160. X
  2161. X    /* length */
  2162. X    report_file_open_length(length);
  2163. X
  2164. X    /* mode */
  2165. X    report_file_open_mode(file_mode);
  2166. X
  2167. X    /* time of start of this file */
  2168. X    report_file_open_tod();
  2169. X
  2170. X    this_file_errors = 0;
  2171. X    report_error_count();
  2172. X}    /* end of report_file_rcv_started */
  2173. X
  2174. X/*+-------------------------------------------------------------------------
  2175. SHAR_EOF
  2176. true || echo 'restore of z/zcurses.c failed'
  2177. fi
  2178. echo 'End of ecu320 part 25'
  2179. echo 'File z/zcurses.c is continued in part 26'
  2180. echo 26 > _shar_seq_.tmp
  2181. exit 0
  2182.  
  2183. exit 0 # Just in case...
  2184.