home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / ecu / part25 < prev    next >
Encoding:
Text File  |  1992-09-13  |  57.0 KB  |  2,178 lines

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