wht@n4hgf.uucp (Warren Tucker) (01/06/91)
Submitted-by: wht@n4hgf.uucp (Warren Tucker) Posting-number: Volume 16, Issue 45 Archive-name: ecu3/part21 ---- Cut Here and feed the following to sh ---- #!/bin/sh # This is part 21 of ecu3 if touch 2>&1 | fgrep 'amc' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= z/zcommon.c ============== if test ! -d 'z'; then echo 'x - creating directory z' mkdir 'z' fi echo 'x - extracting z/zcommon.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'z/zcommon.c' && X/*+------------------------------------------------------------------------- X zcommon.c - ecurz/ecusz common code X derived from public domain code by Chuck Forsberg X ecu adaptation wht%n4hgf@gatech.edu X X Defined functions: X cancel_transaction(0) X get_curr_dir(currdir,currdir_max) X get_home_dir(home_dir) X getspeed(code) X mode(new_mode) X rdchk(f) X rdchk(f) X sendbrk() X zmputs(str) X X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */ X X#include <stdio.h> X#include <signal.h> X#include <setjmp.h> X#include <ctype.h> X#include <pwd.h> X#include "zmodem.h" X Xextern unsigned char vmin_count; Xextern int Zmodem; Xextern unsigned Baudrate; Xextern int Twostop; /* Use two stop bits */ X X#if defined(LLITOUT) Xlong Locmode; /* Saved "local mode" for 4.x BSD "new driver" */ Xlong Locbit = LLITOUT; /* Bit SUPPOSED to disable output translations */ X#endif X Xstruct X{ X unsigned baudr; X int speedcode; X} speeds[] = X{ X 110, B110, X 300, B300, X 600, B600, X 1200, B1200, X 2400, B2400, X 4800, B4800, X 9600, B9600, X 19200, EXTA, X 38400, EXTB, X 0, X}; X X/* crctab calculated by Mark G. Mendel,Network Systems Corporation */ Xunsigned short crctab[256] = X{ X 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7, X 0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef, X 0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6, X 0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de, X 0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485, X 0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d, X 0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4, X 0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc, X 0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823, X 0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b, X 0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12, X 0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a, X 0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41, X 0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49, X 0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70, X 0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78, X 0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f, X 0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067, X 0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e, X 0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256, X 0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d, X 0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405, X 0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c, X 0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634, X 0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab, X 0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3, X 0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a, X 0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92, X 0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9, X 0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1, X 0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8, X 0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0 X}; X X#if defined(WANT_UPDCRC_HERE) /* wht -- moved to zmodem.h */ X/* X * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. X * NOTE: First srgument must be in range 0 to 255. X * Second argument is referenced twice. X * X * Programmers may incorporate any or all code into their programs, X * giving proper credit within the source. Publication of the X * source routines is permitted so long as proper credit is given X * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, X * Omen Technology. X */ X X#define updcrc(cp,crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp) X#endif X X/* X First,the polynomial itself and its table of feedback terms. The X polynomial is: X 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 X X Note that we take it "backwards" and put the highest-order term in the X lowest-order bit. The X^32 term is "implied"; the LSB is the X^31 X term,etc. The X^0 term (usually shown as "+1") results in the MSB being X 1. Note that the usual hardware shift register implementation,which is X what we're using (we're merely optimizing it by doing eight-bit chunks at X a time) shifts bits into the lowest-order term. In our X implementation,that means shifting towards the right. Why do we do it X this way? Because the calculated CRC must be transmitted in order from X highest-order term to lowest-order term. UARTs transmit characters in X order from LSB to MSB. By storing the CRC this way, we hand it to the X UART in the order low-byte to high-byte; the UART sends each low-bit to X hight-bit; and the result is transmission bit by bit from highest- to X lowest-order term without requiring any bit shuffling on our part. X Reception works similarly. X X The feedback terms table consists of 256 32-bit entries. Notes: X X The macro for using the table is UPDC32 is located in zmodem.h X X It might not be obvious,but the feedback terms simply represent the X results of eight shift/xor opera- tions for all combinations of data X and CRC register values. X X The values must be right-shifted by eight bits by the "UPDC32" logic; X the shift must be unsigned (bring in zeroes). On some hardware you X could probably optimize the shift in assembler by using byte-swap X instructions. X*/ X Xlong cr3tab[] = /* CRC polynomial 0xedb88320 */ X{ X 0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535,0x9e6495a3, X 0x0edb8832,0x79dcb8a4,0xe0d5e91e,0x97d2d988,0x09b64c2b,0x7eb17cbd,0xe7b82d07,0x90bf1d91, X 0x1db71064,0x6ab020f2,0xf3b97148,0x84be41de,0x1adad47d,0x6ddde4eb,0xf4d4b551,0x83d385c7, X 0x136c9856,0x646ba8c0,0xfd62f97a,0x8a65c9ec,0x14015c4f,0x63066cd9,0xfa0f3d63,0x8d080df5, X 0x3b6e20c8,0x4c69105e,0xd56041e4,0xa2677172,0x3c03e4d1,0x4b04d447,0xd20d85fd,0xa50ab56b, X 0x35b5a8fa,0x42b2986c,0xdbbbc9d6,0xacbcf940,0x32d86ce3,0x45df5c75,0xdcd60dcf,0xabd13d59, X 0x26d930ac,0x51de003a,0xc8d75180,0xbfd06116,0x21b4f4b5,0x56b3c423,0xcfba9599,0xb8bda50f, X 0x2802b89e,0x5f058808,0xc60cd9b2,0xb10be924,0x2f6f7c87,0x58684c11,0xc1611dab,0xb6662d3d, X 0x76dc4190,0x01db7106,0x98d220bc,0xefd5102a,0x71b18589,0x06b6b51f,0x9fbfe4a5,0xe8b8d433, X 0x7807c9a2,0x0f00f934,0x9609a88e,0xe10e9818,0x7f6a0dbb,0x086d3d2d,0x91646c97,0xe6635c01, X 0x6b6b51f4,0x1c6c6162,0x856530d8,0xf262004e,0x6c0695ed,0x1b01a57b,0x8208f4c1,0xf50fc457, X 0x65b0d9c6,0x12b7e950,0x8bbeb8ea,0xfcb9887c,0x62dd1ddf,0x15da2d49,0x8cd37cf3,0xfbd44c65, X 0x4db26158,0x3ab551ce,0xa3bc0074,0xd4bb30e2,0x4adfa541,0x3dd895d7,0xa4d1c46d,0xd3d6f4fb, X 0x4369e96a,0x346ed9fc,0xad678846,0xda60b8d0,0x44042d73,0x33031de5,0xaa0a4c5f,0xdd0d7cc9, X 0x5005713c,0x270241aa,0xbe0b1010,0xc90c2086,0x5768b525,0x206f85b3,0xb966d409,0xce61e49f, X 0x5edef90e,0x29d9c998,0xb0d09822,0xc7d7a8b4,0x59b33d17,0x2eb40d81,0xb7bd5c3b,0xc0ba6cad, X 0xedb88320,0x9abfb3b6,0x03b6e20c,0x74b1d29a,0xead54739,0x9dd277af,0x04db2615,0x73dc1683, X 0xe3630b12,0x94643b84,0x0d6d6a3e,0x7a6a5aa8,0xe40ecf0b,0x9309ff9d,0x0a00ae27,0x7d079eb1, X 0xf00f9344,0x8708a3d2,0x1e01f268,0x6906c2fe,0xf762575d,0x806567cb,0x196c3671,0x6e6b06e7, X 0xfed41b76,0x89d32be0,0x10da7a5a,0x67dd4acc,0xf9b9df6f,0x8ebeeff9,0x17b7be43,0x60b08ed5, X 0xd6d6a3e8,0xa1d1937e,0x38d8c2c4,0x4fdff252,0xd1bb67f1,0xa6bc5767,0x3fb506dd,0x48b2364b, X 0xd80d2bda,0xaf0a1b4c,0x36034af6,0x41047a60,0xdf60efc3,0xa867df55,0x316e8eef,0x4669be79, X 0xcb61b38c,0xbc66831a,0x256fd2a0,0x5268e236,0xcc0c7795,0xbb0b4703,0x220216b9,0x5505262f, X 0xc5ba3bbe,0xb2bd0b28,0x2bb45a92,0x5cb36a04,0xc2d7ffa7,0xb5d0cf31,0x2cd99e8b,0x5bdeae1d, X 0x9b64c2b0,0xec63f226,0x756aa39c,0x026d930a,0x9c0906a9,0xeb0e363f,0x72076785,0x05005713, X 0x95bf4a82,0xe2b87a14,0x7bb12bae,0x0cb61b38,0x92d28e9b,0xe5d5be0d,0x7cdcefb7,0x0bdbdf21, X 0x86d3d2d4,0xf1d4e242,0x68ddb3f8,0x1fda836e,0x81be16cd,0xf6b9265b,0x6fb077e1,0x18b74777, X 0x88085ae6,0xff0f6a70,0x66063bca,0x11010b5c,0x8f659eff,0xf862ae69,0x616bffd3,0x166ccf45, X 0xa00ae278,0xd70dd2ee,0x4e048354,0x3903b3c2,0xa7672661,0xd06016f7,0x4969474d,0x3e6e77db, X 0xaed16a4a,0xd9d65adc,0x40df0b66,0x37d83bf0,0xa9bcae53,0xdebb9ec5,0x47b2cf7f,0x30b5ffe9, X 0xbdbdf21c,0xcabac28a,0x53b39330,0x24b4a3a6,0xbad03605,0xcdd70693,0x54de5729,0x23d967bf, X 0xb3667a2e,0xc4614ab8,0x5d681b02,0x2a6f2b94,0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d X}; X X#if defined(FIONREAD) X/* X * Return non 0 iff something to read from io descriptor f X */ Xrdchk(f) X{ X static long lf; X X ioctl(f,FIONREAD,&lf); X return((int) lf); X} X#endif X X#if defined(SV) X#include <fcntl.h> X Xchar checked = '\0' ; X/* X * Nonblocking I/O is a bit different in System V,Release 2 X */ Xrdchk(f) X{ X int lf,savestat; X X savestat = fcntl(f,F_GETFL) ; X fcntl(f,F_SETFL,savestat | O_NDELAY) ; X lf = read(f,&checked,1) ; X fcntl(f,F_SETFL,savestat) ; X return(lf) ; X} X#endif X X Xstatic unsigned Xgetspeed(code) X{ X register n; X X for(n=0; speeds[n].baudr; ++n) X if(speeds[n].speedcode == code) X return(speeds[n].baudr); X return(38400); /* Assume fifo if ioctl failed */ X} X X X X#if defined(ICANON) Xstruct termio oldtty,tty; X#else Xstruct sgttyb oldtty,tty; Xstruct tchars oldtch,tch; X#endif X Xextern int iofd; /* File descriptor for ioctls & reads */ X X/* X * mode(n) X * 3: save old tty stat, set raw mode with flow control X * 2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g X * 1: save old tty stat, set raw mode X * 0: restore original tty mode X */ Xmode(new_mode) X{ X static did0 = FALSE; X report_mode(new_mode); X switch(new_mode) X { X#if defined(M_SYS5) X case 2: /* Un-raw mode used by sz,sb when -g detected */ X if(!did0) X (void) ioctl(iofd,TCGETA,&oldtty); X tty = oldtty; X tty.c_iflag &= ~(IXON | IXOFF | IXANY); X X#if defined(RTSFLOW) X if(tty.c_cflag & (RTSFLOW | CTSFLOW)) X tty.c_iflag = BRKINT; X else X tty.c_iflag = BRKINT|IXON; X#else X tty.c_iflag = BRKINT|IXON; X#endif X X tty.c_oflag = 0; /* Transparent output */ X X tty.c_cflag &= ~PARENB; /* Disable parity */ X tty.c_cflag |= CS8; /* Set character size = 8 */ X if(Twostop) X tty.c_cflag |= CSTOPB; /* Set two stop bits */ X X X#if defined(READCHECK) X tty.c_lflag = Zmodem ? 0 : ISIG; X tty.c_cc[VINTR] = Zmodem ? -1:030; /* Interrupt char */ X#else X tty.c_lflag = ISIG; X tty.c_cc[VINTR] = Zmodem ? 03:030; /* Interrupt char */ X#endif X tty.c_cc[VQUIT] = -1; /* Quit char */ X#if defined(NFGVMIN) X tty.c_cc[VMIN] = 1; X#else X tty.c_cc[VMIN] = 3; /* This many chars satisfies reads */ X#endif X tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */ X X (void) ioctl(iofd,TCSETAW,&tty); X did0 = TRUE; X return(OK); X case 1: X case 3: X if(!did0) X (void) ioctl(iofd,TCGETA,&oldtty); X tty = oldtty; X tty.c_iflag &= ~(IXON | IXOFF | IXANY); X X#if defined(RTSFLOW) X tty.c_iflag = new_mode == 3 ? (IGNBRK | RTSFLOW) : IGNBRK; X#else X tty.c_iflag = new_mode == 3 ? (IGNBRK | IXOFF) : IGNBRK; X#endif X X /* No echo,crlf mapping,INTR,QUIT,delays,no erase/kill */ X tty.c_lflag &= ~(ECHO | ICANON | ISIG); X X tty.c_oflag = 0; /* Transparent output */ X X tty.c_cflag &= ~PARENB; /* Same baud rate,disable parity */ X tty.c_cflag |= CS8; /* Set character size = 8 */ X if(Twostop) X tty.c_cflag |= CSTOPB; /* Set two stop bits */ X#if defined(NFGVMIN) X tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */ X#else X tty.c_cc[VMIN] = vmin_count; /* This many chars satisfies reads */ X#endif X tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */ X (void) ioctl(iofd,TCSETAW,&tty); X did0 = TRUE; X Baudrate = getspeed(tty.c_cflag & CBAUD); X report_comm_baud_rate(Baudrate); X return(OK); X#endif X#if defined(pyr) X /* X * NOTE: this should transmit all 8 bits and at the same time X * respond to XOFF/XON flow control. If no FIONREAD or other X * READCHECK alternative,also must respond to INTRRUPT char X * This doesn't work with BSD4. It should work with LLITOUT, X * but LLITOUT was broken on the machine I tried it on. X */ X case 2: /* Un-raw mode used by sz,sb when -g detected */ X if(!did0) X { X ioctl(iofd,TIOCEXCL,0); X ioctl(iofd,TIOCGETP,&oldtty); X ioctl(iofd,TIOCGETC,&oldtch); X#if defined(LLITOUT) X ioctl(TIOCLGET,&Locmode); /* Get "local mode" */ X#endif X } X tty = oldtty; X tch = oldtch; X#if defined(READCHECK) X tch.t_intrc = Zmodem ? -1:030; /* Interrupt char */ X#else X tch.t_intrc = Zmodem ? 03:030; /* Interrupt char */ X#endif X tty.sg_flags |= (ODDP|EVENP|CBREAK); X tty.sg_flags &= ~(ALLDELAY|CRMOD|ECHO|LCASE); X ioctl(iofd,TIOCSETP,&tty); X ioctl(iofd,TIOCSETC,&tch); X#if defined(LLITOUT) X ioctl(TIOCLBIS,&Locbit); X#endif X/* un-raw doesn't work w/o lit out *//*wht code was 99 */ X cancel_transaction(0); X did0 = TRUE; X return(OK); X case 1: X case 3: X if(!did0) X { X ioctl(iofd,TIOCEXCL,0); X ioctl(iofd,TIOCGETP,&oldtty); X ioctl(iofd,TIOCGETC,&oldtch); X#if defined(LLITOUT) X ioctl(TIOCLGET,&Locmode); /* Get "local mode" */ X#endif X } X tty = oldtty; X tty.sg_flags |= RAW; X tty.sg_flags &= ~ECHO; X ioctl(iofd,TIOCSETP,&tty); X did0 = TRUE; X Baudrate = getspeed(tty.sg_ospeed); X report_comm_baud_rate(Baudrate); X return(OK); X#endif X case 0: X if(!did0) X return(ERROR); X#if defined(M_SYS5) X (void) ioctl(iofd,TCSBRK,1); /* Wait for output to drain */ X (void) ioctl(iofd,TCFLSH,1); /* Flush input queue */ X (void) ioctl(iofd,TCSETAW,&oldtty); /* Restore modes */ X (void) ioctl(iofd,TCXONC,1); /* Restart output */ X#endif X#if defined(pyr) X ioctl(iofd,TIOCSETP,&oldtty); X ioctl(iofd,TIOCSETC,&oldtch); X ioctl(iofd,TIOCNXCL,0); X#if defined(LLITOUT) X ioctl(TIOCLSET,&Locmode); /* Restore "local mode" */ X#endif X#endif X X return(OK); X default: X return(ERROR); X } X} X X/*+------------------------------------------------------------------------- X sendbrk() X--------------------------------------------------------------------------*/ Xsendbrk() X{ X#if defined(pyr) X sleep(1); X ioctl(iofd,TIOCSBRK,0); X sleep(1); X ioctl(iofd,TIOCCBRK,0); X#endif X#if defined(M_SYS5) X ioctl(iofd,TCSBRK,0); X#endif X} /* end of sendbrk */ X X/*+------------------------------------------------------------------------- X get_curr_dir(currdir,currdir_max) X--------------------------------------------------------------------------*/ Xvoid Xget_curr_dir(currdir,currdir_max) Xchar *currdir; Xint currdir_max; X{ X#if defined(pyr) X getwd(currdir); X#endif X X#if defined(M_SYS5) X getcwd(currdir,currdir_max); X#endif X X} /* end of get_curr_dir */ X X/*+------------------------------------------------------------------------- X zmputs(str) - send a string to the modem X Xprocessing for \336 (sleep 1 sec) and \335 (break signal) X--------------------------------------------------------------------------*/ Xzmputs(str) Xregister char *str; X{ Xregister char strch; X X while(strch = *str++) X { X switch(strch) X { X case '\336': X sleep(1); X continue; X case '\335': X sendbrk(); X continue; X default: X sendline(strch); X } X } X} /* end of zmputs */ X X/*+----------------------------------------------------------------------- X get_home_dir(home_dir): leave plenty of room for result! X------------------------------------------------------------------------*/ Xget_home_dir(home_dir) Xchar *home_dir; X{ Xstatic char home_directory[256] = ""; Xstruct passwd *pwent; Xstruct passwd *getpwuid(); X X if(home_directory[0]) X { X strcpy(home_dir,home_directory); X return(0); X } X X if(!(pwent = getpwuid(getuid()))) X { X perror("cannot get pwent for you!!"); X exit(1); X } X strcpy(home_directory,pwent->pw_dir); X strcpy(home_dir,pwent->pw_dir); X endpwent(); X return(0); X X} /* end of get_home_dir */ X X/* end of zcommon.c */ X/* vi: set tabstop=4 shiftwidth=4: */ SHAR_EOF $TOUCH -am 0814204290 'z/zcommon.c' && chmod 0644 z/zcommon.c || echo 'restore of z/zcommon.c failed' Wc_c="`wc -c < 'z/zcommon.c'`" test 15601 -eq "$Wc_c" || echo 'z/zcommon.c: original size 15601, current size' "$Wc_c" # ============= z/zcurses.c ============== echo 'x - extracting z/zcurses.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'z/zcurses.c' && X/*+------------------------------------------------------------------------- X zcurses.c -- ecu file transfer program curses interface X X 000000000011111111112222222222333333333344444444445555555550 X 012345678901234567890123456789012345678901234567890123456789 X00.-[ prog+rev ]-- <dir> ------------------------------------. X01| ZMODEM_6____ _40_____________________________________ | X02| File ### of ###: _38__________________________________ | X03| File position: _8______ length: _8______ -rwxrwxrwx | X04| _55____________________________________________________ | transaction X05| _55____________________________________________________ | last rx/tx hdr X06| Comm I/O: rx _8______ tx _8______ bytes | X07| Baud rate: _5___ BINARY blklen: _____ comm mode: RAW-g | X08| Time: started: __:__:__ this file: __:__:__ window: | X09| __:__:__ elapsed: __:__:__ __:__:__ ________ | X10| Errors: this file: _3_ total: _4__ files skipped: _3_ | X11| _55____________________________________________________ | err str X12| _55____________________________________________________ | comment str X13| _55____________________________________________________ | remote info X14`----------------------------------------------------------' X X Defined functions: X clear_area(win,row,col,len) X clear_area_char(win,row,col,len,fillchar) X determine_output_mode() X get_elapsed_time(elapsed_seconds) X get_tod(type,tod) X mode_map(mode,mode_str) X report_comm_baud_rate(baud_rate) X report_error_count() X report_file_byte_io(count) X report_file_close() X report_file_open_length(length) X report_file_open_mode(file_mode) X report_file_open_tod() X report_file_rcv_started(filename,length,last_mod_time,file_mode) X report_file_send_open(filename,filestat) X report_init(title) X report_last_rxhdr(rptstr,error_flag) X report_last_txhdr(rptstr,error_flag) X report_mode(mode) X report_protocol_crc_type(str) X report_protocol_type(str) X report_rx_ind(status) X report_rx_tx_count() X report_rxblklen(blklen) X report_rxpos(rxpos) X report_str(rptstr,error_flag) X report_top_line(topstr) X report_transaction(str) X report_tx_ind(status) X report_txblklen(blklen) X report_txpos(txpos) X report_uninit(sig) X report_window() X report_xfer_mode(str) X X------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:12-18-1990-21:26-wht@n4hgf-better output control */ X/*:12-04-1990-04:07-wht@n4hgf-handle slow terminal using faster line */ X/*:12-04-1990-03:04-wht@n4hgf-choose ruling chars based on multiscreen or not */ X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */ X/*:08-14-1990-20:41-wht@n4hgf-ecu3.00-flush old edit history */ X X#include <curses.h> X#include <sys/types.h> X#include <sys/stat.h> X#include <ctype.h> X#include <signal.h> X#include <time.h> X#include <sys/timeb.h> X#include <sys/machdep.h> X X#include "../pc_scr.h" X#include "zlint.h" X Xlong time(); Xextern char *tzname[]; Xstruct tm *localtime(); X Xunsigned char sTL = at_TL; Xunsigned char sTR = at_TR; Xunsigned char sBL = at_BL; Xunsigned char sBR = at_BR; Xunsigned char sLT = at_LT; Xunsigned char sRT = at_RT; Xunsigned char sVR = at_VR; Xunsigned char sHR = at_HR; X X#define WIN_LINES 15 X#define WIN_COLS 60 X#define WIN_TOPY 2 X#define WIN_LEFTX 8 X Xextern char curr_dir[]; Xextern char s128[]; Xextern char *bottom_label; Xextern int Filcnt; Xextern int ecusz_flag; /* ecusz == 1, ecurz == 0 */ Xextern int force_no_curses; Xextern int skip_count; Xextern int npats; Xextern long rxpos; Xextern int log_packets; Xextern long Txpos; Xextern long Rxpos; X XWINDOW *win; Xint (*original_sigint_handler)(); Xint (*original_sigquit_handler)(); Xint (*original_sigterm_handler)(); Xint report_init_complete = 0; Xint report_verbosity; Xint no_curses = 0; Xint no_curses_pos = 0; Xint this_file_errors; Xint total_errors; Xint show_window = 0; Xlong current_seconds = 0; Xlong start_seconds = 0; Xlong this_file_start_seconds = 0; Xlong elapsed_seconds = 0; Xunsigned long total_data_chars_xfered = 0L; Xunsigned int zcurses_baud_rate = 0; Xchar s256[256]; X Xchar *win_template[] = X{ X/*00000000001111111111222222222233333333334444444444555555555 */ X/*01234567890123456789012345678901234567890123456789012345678 */ X/*.----------------------------------------------------------. */ X " ", /* 1 */ X " File ### of ###: _____________________________________ ", /* 2 */ X " File position: ________ length: ________ ", /* 3 */ X " ", /* 4 */ X " tx: ______________________ rx: ______________________ ", /* 5 */ X " Comm I/O: rx ________ tx ________ bytes ", /* 6 */ X " Baud rate: _____ ______ blklen: _____ comm mode: ______ ", /* 7 */ X " Time: started: __:__:__ this file: __:__:__ ", /* 8 */ X " __:__:__ elapsed: __:__:__ __:__:__ ", /* 9 */ X " Errors: this file: ___ total: ____ files skipped: ___ ", /* 10 */ X " ", /* 11 */ X " ", /* 12 */ X " ", /* 13 */ X/*`----------------------------------------------------------' */ X(char *)0 X}; X X/*+----------------------------------------------------------------------- X char *get_elapsed_time(elapsed_seconds) X hh:mm:ss returned X static string address is returned X------------------------------------------------------------------------*/ Xchar * Xget_elapsed_time(elapsed_seconds) Xlong elapsed_seconds; X{ X static char elapsed_time_str[10]; X long hh,mm,ss; X X hh = elapsed_seconds / 3600; X elapsed_seconds -= hh * 3600; X mm = elapsed_seconds / 60L; X elapsed_seconds -= mm * 60L; X ss = elapsed_seconds; X X sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss); X return(elapsed_time_str); X} /* end of get_elapsed_time */ X X/*+----------------------------------------------------------------------- X char *get_tod(type,tod) X X time of day types: X 0 hh:mm X 1 hh:mm:ss X 2 mm-dd-yyyy hh:mm X X static string address is returned X if tod != (char *)0, time is returned there too X------------------------------------------------------------------------*/ Xchar * Xget_tod(type,tod) Xint type; Xchar *tod; X{ X long cur_time = 0; X struct tm *lt; /* local time */ X static char tod_str[32]; X#if defined(M_SYS5) X struct timeb tp; X#endif X X cur_time = time((long *)0); X lt = localtime(&cur_time); X X switch(type) X { X case 0: X sprintf(tod_str,"%02d:%02d",lt->tm_hour,lt->tm_min); X break; X X default: X case 1: X sprintf(tod_str,"%02d:%02d:%02d",lt->tm_hour,lt->tm_min,lt->tm_sec); X break; X X case 2: X sprintf(tod_str,"%02d-%02d-%04d %02d:%02d", X lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900, X lt->tm_hour,lt->tm_min); X break; X } X X if(tod != (char *)0) X strcpy(tod,tod_str); X X return(tod_str); X} /* end of get_tod */ X X/*+----------------------------------------------------------------------- X mode_map(mode,mode_str) build drwxrwxrwx string X------------------------------------------------------------------------*/ Xchar * Xmode_map(mode,mode_str) Xunsigned short mode; Xchar *mode_str; X{ Xregister unsigned ftype = mode & S_IFMT; Xregister char *rtn; Xstatic char result[12]; X X rtn = (mode_str == (char *)0) ? result : mode_str; X X /* drwxrwxrwx */ X /* 0123456789 */ X strcpy(rtn,"----------"); X X switch(ftype) X { X case S_IFIFO: *rtn = 'p'; break; /* FIFO (named pipe) */ X case S_IFDIR: *rtn = 'd'; break; /* directory */ X case S_IFCHR: *rtn = 'c'; break; /* character special */ X case S_IFBLK: *rtn = 'b'; break; /* block special */ X case S_IFREG: *rtn = '-'; break; /* regular */ X X#if defined(pyr) | defined(BSD4) X case S_IFLNK: *rtn = 'l'; break; /* symbolic link */ X case S_IFSOCK: *rtn = 's'; break; /* socket */ X#endif X X#if defined(M_SYS5) X case S_IFNAM: /* name space entry */ X if(mode & S_INSEM) /* semaphore */ X { X *rtn = 's'; X break; X } X if(mode & S_INSHD) /* shared memory */ X { X *rtn = 'm'; X break; X } X#endif X X default: *rtn = '?'; break; /* ??? */ X } X X if(mode & 000400) *(rtn + 1) = 'r'; X if(mode & 000200) *(rtn + 2) = 'w'; X if(mode & 000100) *(rtn + 3) = 'x'; X if(mode & 004000) *(rtn + 3) = 's'; X if(mode & 000040) *(rtn + 4) = 'r'; X if(mode & 000020) *(rtn + 5) = 'w'; X if(mode & 000010) *(rtn + 6) = 'x'; X if(mode & 002000) *(rtn + 6) = 's'; X if(mode & 000004) *(rtn + 7) = 'r'; X if(mode & 000002) *(rtn + 8) = 'w'; X if(mode & 000001) *(rtn + 9) = 'x'; X if(mode & 001000) *(rtn + 9) = 't'; X X return(rtn); X X} /* end of mode_map */ X X/*+------------------------------------------------------------------------- X no_curses_newline() X--------------------------------------------------------------------------*/ Xvoid Xno_curses_newline() X{ X if(no_curses_pos) X printf("\r\n"); X no_curses_pos = 0; X X} /* end of no_curses_newline */ X X/*+------------------------------------------------------------------------- X clear_area(win,row,col,len) X--------------------------------------------------------------------------*/ Xclear_area(win,row,col,len) XWINDOW *win; Xint row; Xint col; Xint len; X{ X if(no_curses) X return; X wmove(win,row,col); X while(len-- > 0) X waddch(win,' '); X wmove(win,row,col); X X} /* end of clear_area */ X X/*+------------------------------------------------------------------------- X clear_area_char(win,row,col,len,fillchar) X--------------------------------------------------------------------------*/ Xclear_area_char(win,row,col,len,fillchar) XWINDOW *win; Xint row; Xint col; Xint len; Xchar fillchar; X{ X if(no_curses) X return; X wmove(win,row,col); X while(len-- > 0) X waddch(win,fillchar); X wmove(win,row,col); X X} /* end of clear_area_char */ X X/*+------------------------------------------------------------------------- X report_top_line(topstr) X top line: row 1 col 17 length 42 X--------------------------------------------------------------------------*/ Xvoid Xreport_top_line(topstr) Xchar *topstr; X{ Xchar s42[42]; X X if(no_curses) X { X no_curses_newline(); X no_curses_pos = printf("%s",topstr); X fflush(stdout); X return; X } X X clear_area(win,1,17,42); X if(strlen(topstr) < 40) X waddstr(win,topstr); X else X { X strncpy(s42,topstr,40); X s42[40] = 0; X waddstr(win,s42); X } X} /* end of report_top_line */ X X/*+------------------------------------------------------------------------- X report_xfer_mode(modestr) BINARY/ASCII X protocol xfer type: row 7 col 20 length 6 X--------------------------------------------------------------------------*/ Xreport_xfer_mode(str) Xchar *str; X{ Xchar s10[10]; X X if(no_curses) X return; X if(strlen(str) > 6) X { X strncpy(s10,str,6); X s10[7] = 0; X str = s10; X } X clear_area(win,7,20,6); X waddstr(win,str); X wrefresh(win); X X} /* end of report_xfer_mode */ X X/*+------------------------------------------------------------------------- X report_protocol_type(str) X X protocol type: row 1 col 3 length 6 string X--------------------------------------------------------------------------*/ Xreport_protocol_type(str) Xregister char *str; X{ Xchar s10[10]; X X if(no_curses) X { X return; X } X X if(strlen(str) > 6) X { X strncpy(s10,str,6); X s10[7] = 0; X str = s10; X } X clear_area(win,1,3,6); X waddstr(win,str); X wrefresh(win); X X} /* end of report_protocol_type */ X X/*+------------------------------------------------------------------------- X report_protocol_crc_type(str) X X protocol crc type: row 1 col 9 length 6 X--------------------------------------------------------------------------*/ Xreport_protocol_crc_type(str) Xregister char *str; X{ Xchar s8[8]; X X if(no_curses) X { X return; X } X X if(strlen(str) > 6) X { X strncpy(s8,str,6); X s8[7] = 0; X str = s8; X } X clear_area(win,1,9,6); X waddstr(win,str); X wrefresh(win); X X} /* end of report_protocol_crc_type */ X X/*+------------------------------------------------------------------------- X report_uninit(sig) X--------------------------------------------------------------------------*/ Xvoid Xreport_uninit(sig) Xint sig; /* if -1, called by normal code, else kill() value */ X{ X float rate = 0.0; X float eff = 0.0; X X if(report_init_complete) X { X current_seconds = time((long *)0); X elapsed_seconds = current_seconds - start_seconds; X if(elapsed_seconds && (zcurses_baud_rate > 50)) X { X rate = (float)total_data_chars_xfered / (float)elapsed_seconds; X if(zcurses_baud_rate) X eff = 100.0 * (rate / ((float)zcurses_baud_rate / 10.0)); X } X if(rate > 0.01) X { X sprintf(s128,"Transfer rate ~= %.0f ch/sec (%.0f%%)", X rate,(eff > 0.5) ? eff : 0.0); X if(log_packets) X { X write(log_packets,"info: ",6); X write(log_packets,s128,strlen(s128)); X write(log_packets,"\n",1); X } X report_top_line(s128); X } X if(no_curses) X no_curses_newline(); X else X { X report_file_byte_io(0L); X report_rx_tx_count(); X wmove(win,WIN_LINES - 1,WIN_COLS - 1); X wrefresh(win); X endwin(); X fprintf(stderr,"\r\n\r\n\r\n"); X fflush(stderr); X } X report_init_complete = 0; X } X X} /* end of report_uninit */ X X/*+------------------------------------------------------------------------- X determine_output_mode() X--------------------------------------------------------------------------*/ Xint Xdetermine_output_mode() X{ X int monitor_type; X struct stat dn; X struct stat tty_stat; X struct stat pty_stat; X X if(force_no_curses) X { X no_curses = 1; X report_verbosity = 1; X report_init_complete = 1; X return(1); X } X X if(ioctl(0,CONS_GET,&monitor_type) < 0) /* not multiscreen */ X { X sTL = vanilla_TL; X sTR = vanilla_TR; X sBL = vanilla_BL; X sBR = vanilla_BR; X sLT = vanilla_LT; X sRT = vanilla_RT; X sVR = vanilla_VR; X sHR = vanilla_HR; X X /* X * if tty (console) is not character special, only report X * basic progress X */ X memset((char *)&dn,0,sizeof(dn)); X stat("/dev/null",&dn); X if(fstat(0,&tty_stat) || X ((tty_stat.st_mode & S_IFMT) != S_IFCHR) || X (dn.st_rdev == tty_stat.st_rdev)) X { X no_curses = 1; X report_verbosity = 0; X report_init_complete = 1; X return(1); X } X X#ifdef NO_PTY_CURSES X /* X * if pty (must be xterm), send clear screen and no curses X */ X if(!stat("/dev/ttyp0",&pty_stat) && X (pty_stat.st_rdev & 0xFF00) == (tty_stat.st_rdev & 0xFF00)) X { X static char ff[] = "\033[H\0332J\r\n"; X write(2,ff,strlen(ff)); X no_curses = 1; X report_verbosity = 1; X report_init_complete = 1; X return(1); X } X#endif X X /* X * if non-multiscreen tty baud rate not at least that X * of the attached line, use no curses, but do be a bit X * more verbose than if tty not char special X */ X test_tty_and_line_baud(); X } X X return(no_curses); X X} /* end of determine_output_mode */ X X/*+------------------------------------------------------------------------- X report_init(title) X "top line": row 1 col 11 len 21 X file quan: row 2 col 15 len 3 X row 2 col 12 len 7 clear "of ###" X start time: row 8 col 21 len 8 X "window:" row 8 col 50 len 7 X--------------------------------------------------------------------------*/ Xvoid Xreport_init(title) Xchar *title; X{ X register int itmp; X register char *cptr; X char buf[80]; X X if(report_init_complete) X return; X X start_seconds = time((long *)0); X current_seconds = start_seconds; X X if(no_curses) X return; X X initscr(); X crmode(); X noecho(); X nonl(); X clear(); X report_init_complete = 1; X win = newwin(WIN_LINES,WIN_COLS,WIN_TOPY,WIN_LEFTX); X box(win,sVR,sHR); X wmove(win,0,0); waddch(win,sTL); X wmove(win,win->_maxy - 1,0); waddch(win,sBL); X wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,sBR); X wmove(win,0,win->_maxx - 1); waddch(win,sTR); X wmove(win,0,2); X wstandout(win); X waddch(win,'['); X waddch(win,' '); X waddstr(win,title); X waddch(win,' '); X waddch(win,']'); X wstandend(win); X waddch(win,sHR); X waddch(win,sHR); X waddch(win,' '); X itmp = WIN_COLS - 2 - 7 - strlen(title); X curr_dir[itmp] = 0; X waddstr(win,curr_dir); X waddch(win,' '); X if(bottom_label) X { X strncpy(buf,bottom_label,WIN_COLS - 6); X buf[WIN_COLS - 6] = 0; X wmove(win,WIN_LINES - 1,2); X waddch(win,' '); X waddstr(win,buf); X waddch(win,' '); X } X X itmp = 0; X while(1) X { X if(win_template[itmp] == (char *)0) X break; X wmove(win,itmp + 1,1); X waddstr(win,win_template[itmp++]); X } X if(ecusz_flag) X { X clear_area(win,2,15,3); X sprintf(s128,"%3d",npats); X waddstr(win,s128); X#if defined(FORK_DEBUG) X sprintf(s128,"DEBUG ecusz pid %d",getpid()); X#endif X } X else /* ecurz */ X { X clear_area(win,2,11,8); /* clear "of ###" */ X waddstr(win,":"); X#if defined(FORK_DEBUG) X sprintf(s128,"DEBUG ecurz pid %d",getpid()); X#endif X } X X#if defined(FORK_DEBUG) X ecu_log_event(getppid(),s128); X#endif X X clear_area(win,1,11,21); X report_error_count(); X clear_area(win,8,21,8); /* starting time */ X waddstr(win,get_tod(1,(char *)0)); X X if(show_window) X { X wmove(win,8,50); X waddstr(win,"window:"); X wmove(win,9,50); X waddstr(win,"+0"); X } X X wrefresh(win); X X} /* end of report_init */ X X/*+------------------------------------------------------------------------- X report_rx_ind(status) X--------------------------------------------------------------------------*/ Xvoid Xreport_rx_ind(status) Xint status; X{ X if(no_curses) X { X if(report_verbosity && status) X { X printf("R"); X if(++no_curses_pos > 75) X no_curses_newline(); X fflush(stdout); X } X return; X } X wmove(win,1,54); X waddch(win,(status) ? 'R' : ' '); X wmove(win,1,54); X wrefresh(win); X} /* end of report_rx_ind */ X X/*+------------------------------------------------------------------------- X report_tx_ind(status) X--------------------------------------------------------------------------*/ Xvoid Xreport_tx_ind(status) Xint status; X{ X if(no_curses) X { X if(report_verbosity && status) X { X printf("T"); X if(++no_curses_pos > 75) X no_curses_newline(); X fflush(stdout); X } X return; X } X wmove(win,1,56); X waddch(win,(status) ? 'T' : ' '); X wmove(win,1,56); X wrefresh(win); X} /* end of report_tx_ind */ X X/*+------------------------------------------------------------------------- X report_window() - if enable, show open widow size X--------------------------------------------------------------------------*/ Xvoid Xreport_window() X{ X if(show_window && !no_curses) X { X long ltmp; X wmove(win,9,50); X if((ltmp = (Txpos - Rxpos)) > 999999L) X waddstr(win,">+999999"); X else if(ltmp < -999999L) X ; X else X { X sprintf(s128,"%+-8ld",ltmp); X waddstr(win,s128); X if(log_packets) X { X write(log_packets,"window: ",8); X write(log_packets,s128,strlen(s128)); X write(log_packets,"\n",1); X } X } X } X} /* end of report_window */ X X/*+------------------------------------------------------------------------- X report_rx_tx_count() X X This procedure may be counted upon to perform wrefresh(win) X X rx char count: row 6 col 16 len 8 unsigned long X tx char count: row 6 col 29 len 8 unsigned long X session elapsed time: row 9 col 21 len 8 X this file elapsed time: row 9 col 41 len 8 X current tod: row 9 col 3 len 8 X window: row 9 col 50 len 8 X--------------------------------------------------------------------------*/ Xreport_rx_tx_count() X{ X extern unsigned long rx_char_count; X extern unsigned long tx_char_count; X X register char *cptr; X X if(no_curses) X { X return; X } X X sprintf(s128,"%8ld",rx_char_count); X wmove(win,6,16); X waddstr(win,s128); X sprintf(s128,"%8ld",tx_char_count); X wmove(win,6,29); X waddstr(win,s128); X X /* now time of day */ X wmove(win,9,3); X cptr = get_tod(1,(char *)0); X waddstr(win,cptr); X current_seconds = time((long *)0); X elapsed_seconds = current_seconds - start_seconds; X cptr = get_elapsed_time(elapsed_seconds); X wmove(win,9,21); X waddstr(win,cptr); X if(this_file_start_seconds) X elapsed_seconds = current_seconds - this_file_start_seconds; X else X elapsed_seconds = 0; X cptr = get_elapsed_time(elapsed_seconds); X wmove(win,9,41); X waddstr(win,cptr); X X report_window(); X X wrefresh(win); /* calling procs expect this to occur always */ X X} /* end of report_rx_tx_count */ X X/*+------------------------------------------------------------------------- X report_mode(mode) X X comm mode row 7 col 52 length 6 X 3: save old tty stat, set raw mode with flow control X 2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g X 1: save old tty stat, set raw mode X 0: restore original tty mode X--------------------------------------------------------------------------*/ Xvoid Xreport_mode(mode) Xint mode; X{ Xchar *cptr; Xchar tmp[8]; X X if(no_curses) X { X return; X } X X clear_area(win,7,52,6); X switch(mode) X { X case 0: X cptr = "NORMAL"; X break; X case 1: X cptr = "RAW"; X break; X case 2: X cptr = "RAW-g"; X break; X case 3: X cptr = "RAW-f"; X break; X default: X sprintf(tmp,"%5u",mode); X cptr = tmp; X } X waddstr(win,cptr); X wrefresh(win); X if(log_packets) X { X write(log_packets,"mode: ",6); X write(log_packets,cptr,strlen(cptr)); X write(log_packets,"\n",1); X } X X} /* end of report_mode */ X X/*+------------------------------------------------------------------------- X report_rxblklen(blklen) Xrow 7 col 35 5 chars X--------------------------------------------------------------------------*/ Xvoid Xreport_rxblklen(blklen) Xint blklen; X{ X char tmp[10]; X X if(no_curses) X { X return; X } X X sprintf(tmp,"%5u",blklen); X clear_area(win,7,35,5); X waddstr(win,tmp); X wrefresh(win); X} /* end of report_rxblklen */ X X/*+------------------------------------------------------------------------- X report_txblklen(blklen) Xrow 7 col 35 5 chars X--------------------------------------------------------------------------*/ Xvoid Xreport_txblklen(blklen) Xint blklen; X{ X if(no_curses) X { X return; X } X X report_rxblklen(blklen); X} /* end of report_txblklen */ X X/*+------------------------------------------------------------------------- X report_rxpos(rxpos) row 3 col 19 len 8 X--------------------------------------------------------------------------*/ Xvoid Xreport_rxpos(rxpos) Xlong rxpos; X{ Xchar tmp[16]; X#if defined(M_SYS5) Xchar refr; X X if(no_curses) X { X return; X } X X if(rdchk(0)) X { X read(0,&refr,1); X if(refr == 0x0C || refr == 0x012) /* ^L or ^R */ X { X write(2,"\033[2J",4); X nap((long)60); X touchwin(stdscr); X wrefresh(stdscr); X touchwin(win); X wrefresh(win); X } X } X#endif X X if((rxpos > 99999999L) || (rxpos < 0L)) X return; X X sprintf(tmp,"%8lu",rxpos); X wmove(win,3,19); X waddstr(win,tmp); X wrefresh(win); X report_rx_tx_count(); /* which will do a refresh */ X} /* end of report_rxpos */ X X/*+------------------------------------------------------------------------- X report_txpos(txpos) X--------------------------------------------------------------------------*/ Xvoid Xreport_txpos(txpos) Xlong txpos; X{ X if(no_curses) X { X return; X } X X report_rxpos(txpos); X} /* end of report_txpos */ X X/*+------------------------------------------------------------------------- X report_error_count() X DOES NOT PERFORM A REFRESH CYCLE X X this file: row 10 col 22 len 3 X total: row 10 col 33 len 4 X skipped: row 10 col 53 len 3 X--------------------------------------------------------------------------*/ Xreport_error_count() X{ X char tmp[16]; X X if(no_curses) X { X return; X } X X wmove(win,10,22); X sprintf(tmp,"%3d",this_file_errors); X if(this_file_errors) X wstandout(win); X waddstr(win,tmp); X if(this_file_errors) X wstandend(win); X X wmove(win,10,33); X sprintf(tmp,"%4d",total_errors); X if(total_errors) X wstandout(win); X waddstr(win,tmp); X if(total_errors) X wstandend(win); X X wmove(win,10,53); X sprintf(tmp,"%3d",skip_count); X waddstr(win,tmp); X wrefresh(win); X X} /* end of report_error_count */ X X/*+------------------------------------------------------------------------- X report_last_txhdr(rptstr,error_flag) X 5,7,22 X--------------------------------------------------------------------------*/ Xvoid Xreport_last_txhdr(rptstr,error_flag) Xregister char *rptstr; Xint error_flag; X{ Xchar s24[24]; X X if(log_packets) X { X write(log_packets,"tx: ",6); X write(log_packets,rptstr,strlen(rptstr)); X write(log_packets,"\n",1); X } X X if(no_curses) X { X if(error_flag) X { X no_curses_newline(); X no_curses_pos = printf("%s ",rptstr); X ++this_file_errors; X ++total_errors; X } X return; X } X X if(strlen(rptstr) > 22) X { X strncpy(s24,rptstr,22); X s24[23] = 0; X rptstr = s24; X } X clear_area(win,5,7,22); X waddstr(win,rptstr); X X if(error_flag) X { X ++this_file_errors; X ++total_errors; X report_error_count(); X } X X} /* end of report_last_txhdr */ X X/*+------------------------------------------------------------------------- X report_last_rxhdr(rptstr,error_flag) X 5,35,22 X--------------------------------------------------------------------------*/ Xvoid Xreport_last_rxhdr(rptstr,error_flag) Xregister char *rptstr; Xint error_flag; X{ Xchar s24[24]; Xextern int log_packets; X X if(log_packets) X { X write(log_packets,"rx: ",6); X write(log_packets,rptstr,strlen(rptstr)); X write(log_packets,"\n",1); X } X X if(no_curses) X { X if(error_flag) X { X no_curses_newline(); X no_curses_pos = printf("%s ",rptstr); X ++this_file_errors; X ++total_errors; X } X return; X } X X if(strlen(rptstr) > 22) X { X strncpy(s24,rptstr,22); X s24[23] = 0; X rptstr = s24; X } X clear_area(win,5,35,22); X waddstr(win,rptstr); X X if(error_flag) X { X ++this_file_errors; X ++total_errors; X report_error_count(); X } X report_window(); X X} /* end of report_last_rxhdr */ X X/*+------------------------------------------------------------------------- X report_str(rptstr,error_flag) row 11/12 col 3 len 55 X X error_flag == 0 for status/progress message X == 1 for bump error count, unless rptstr is null X in which case, merely clear error string area X == 2 write string on bottom line (not an error) X == 3 write string on transaction line (not an error) X == -1 use error line but do not bump error count X--------------------------------------------------------------------------*/ Xvoid Xreport_str(rptstr,error_flag) Xregister char *rptstr; Xint error_flag; X{ Xchar s60[60]; Xextern int log_packets; X X if(log_packets) X { X sprintf(s60,"rpt %d:",error_flag); X write(log_packets,s60,strlen(s60)); X write(log_packets,rptstr,strlen(rptstr)); X write(log_packets,"\n",1); X } X X if(no_curses) X { X if(!strlen(rptstr)) X return; X switch(error_flag) X { X case 0: X break; X case 1: X this_file_errors++; X total_errors++; X case -1: X case 2: X case 3: X no_curses_newline(); X no_curses_pos = printf("%s ",rptstr); X fflush(stdout); X } X return; X } X X if(strlen(rptstr) > 55) X { X strncpy(s60,rptstr,55); X s60[55] = 0; X rptstr = s60; X } X X switch(error_flag) X { X case 0: X clear_area(win,12,3,55); X break; X case 1: X this_file_errors++; X total_errors++; X report_error_count(); X case -1: X clear_area(win,11,3,55); X break; X case 2: X clear_area(win,13,3,55); X break; X case 3: X clear_area(win,4,3,55); X break; X } X X waddstr(win,rptstr); X wrefresh(win); X X} /* end of report_str */ X X/*+------------------------------------------------------------------------- X report_transaction() X--------------------------------------------------------------------------*/ Xvoid Xreport_transaction(str) Xchar *str; X{ X report_str(str,3); X} /* end of report_transaction */ X X/*+------------------------------------------------------------------------- X report_file_open_tod() -- time of start of this file X X this file open time: row 8 col 41 length 8 X--------------------------------------------------------------------------*/ Xvoid Xreport_file_open_tod() X{ X if(no_curses) X return; X clear_area(win,8,41,8); X waddstr(win,get_tod(1,(char *)0)); X wrefresh(win); X} /* end of report_file_open_tod */ X X/*+------------------------------------------------------------------------- X report_file_open_mode(file_mode) X mode map: row 4 col 46 len 10 X--------------------------------------------------------------------------*/ Xreport_file_open_mode(file_mode) Xunsigned short file_mode; X{ X if(no_curses) X return; X clear_area(win,3,46,10); X waddstr(win,mode_map(file_mode,(char *)0)); X wrefresh(win); X} /* end of report_file_open_mode */ X X/*+------------------------------------------------------------------------- X report_file_open_length(long_length) X length: row 3 col 36 len 8 X--------------------------------------------------------------------------*/ Xreport_file_open_length(length) Xlong length; X{ X if(no_curses) X return; X clear_area(win,3,36,8); X if(length <= 0) X waddstr(win,"unknown"); X else X { X sprintf(s128,"%8lu",length); X waddstr(win,s128); X } X wrefresh(win); X} /* end of report_file_open_length */ X X/*+------------------------------------------------------------------------- X report_file_send_open(filename,filestat) X X filename: row 2 col 20 len 38 X number: row 2 col 8 len 3 X length: row 3 col 36 len 8 X mode: row 3 col 46 len 10 X time of start of this file: row 4 col 47 length 8 hh:mm:ss X--------------------------------------------------------------------------*/ Xvoid Xreport_file_send_open(filename,filestat) Xchar *filename; Xstruct stat *filestat; X{ Xchar s50[50]; Xregister char *cptr = filename; X X if(log_packets) X { X write(log_packets,"file: ",6); X write(log_packets,filename,strlen(filename)); X write(log_packets,"\n",1); X } X X this_file_start_seconds = time((long *)0); X X if(no_curses) X { X no_curses_newline(); X no_curses_pos = printf("Sending '%s' ",filename); X fflush(stdout); X return; X } X X /* number */ X clear_area(win,2,8,3); X sprintf(s50,"%3d",Filcnt); X waddstr(win,s50); X X /* filename */ X if(strlen(filename) > 38) X { X strncpy(s50,filename,38); X s50[39] = 0; X cptr = s50; X } X clear_area(win,2,20,38); X waddstr(win,cptr); X X /* length */ X report_file_open_length(filestat->st_size); X X /* mode */ X report_file_open_mode(filestat->st_mode); X X /* time of start of this file */ X report_file_open_tod(); X X this_file_errors = 0; X report_error_count(); X} /* end of report_file_send_open */ X X/*+------------------------------------------------------------------------- X report_file_rcv_started(filename,length,last_mod_time,file_mode) X X filenumber: row 2 col 8 len 3 X row 2 col 12 len 7 clear "of ###" X filename: row 2 col 20 len 38 X--------------------------------------------------------------------------*/ Xreport_file_rcv_started(filename,length,last_mod_time,file_mode) Xchar *filename; Xlong length; /* if < 0, "UNKNOWN" */ Xlong last_mod_time; /* not currently displayed */ Xunsigned short file_mode; /* UNIX file modifier or zero */ X{ Xregister char *cptr; Xchar s50[50]; X X if(log_packets) X { X write(log_packets,"file: ",6); X write(log_packets,filename,strlen(filename)); X write(log_packets,"\n",1); X } X X this_file_start_seconds = time((long *)0); X X if(no_curses) X { X no_curses_newline(); X no_curses_pos = printf("Receiving '%s' ",filename) - 2; X fflush(stdout); X return; X } X X /* filename */ X if(strlen(filename) > 38) X { X strncpy(s50,filename,38); X s50[39] = 0; X cptr = s50; X } X else X cptr = filename; X X clear_area(win,2,20,38); X waddstr(win,cptr); X X /* file number */ X clear_area(win,2,8,3); X sprintf(s50,"%3d",Filcnt); /* rz uses as file number 1-n */ X waddstr(win,s50); X X/* if remote sender provides a file count, display it */ X if(npats) X { X clear_area(win,2,12,7); /* clear "of ###" */ X sprintf(s50,"of %3d:",npats); X waddstr(win,s50); X } X X /* length */ X report_file_open_length(length); X X /* mode */ X report_file_open_mode(file_mode); X X /* time of start of this file */ X report_file_open_tod(); X X this_file_errors = 0; X report_error_count(); X} /* end of report_file_rcv_started */ X X/*+------------------------------------------------------------------------- X report_file_close() X--------------------------------------------------------------------------*/ Xvoid report_file_close() X{ X char *eof = "End of file"; X float rate = 0.0; X float eff = 0.0; X X if(no_curses) X { X current_seconds = time((long *)0); X elapsed_seconds = current_seconds - this_file_start_seconds; X no_curses_newline(); X no_curses_pos += X printf("Transfer time was %s",get_elapsed_time(elapsed_seconds)); X no_curses_newline(); X if(elapsed_seconds && (zcurses_baud_rate > 50)) X { X rate = (float)total_data_chars_xfered / (float)elapsed_seconds; X if(zcurses_baud_rate) X eff = 100.0 * (rate / ((float)zcurses_baud_rate / 10.0)); X } X if(rate > 0.01) X { X no_curses_pos += X printf("Transfer rate ~= %.0f ch/sec (%.0f%%)", X rate,(eff > 0.5) ? eff : 0.0); X no_curses_newline(); X } X if(this_file_errors) X { X no_curses_pos += X printf("Errors for this file were %d",this_file_errors); X no_curses_newline(); X } X return; X } X X if(show_window) X { X clear_area(win,9,50,8); X waddstr(win,"+0"); X Txpos = 0; X Rxpos = 0; X } X X report_str(eof,0); X wrefresh(win); X this_file_start_seconds = 0; X X} /* end of report_file_close */ X X/*+------------------------------------------------------------------------- X report_comm_baud_rate(baud_rate) X X baud rate: row 7 col 14 length 5 X--------------------------------------------------------------------------*/ Xreport_comm_baud_rate(baud_rate) Xunsigned int baud_rate; X{ X char tstr8[8]; X X zcurses_baud_rate = baud_rate; X X if(no_curses) X { X return; X } X X clear_area(win,7,14,5); X if(baud_rate == 0) X waddstr(win,"?"); X else X X { X sprintf(tstr8,"%5u",baud_rate); X waddstr(win,tstr8); X } X wrefresh(win); X X} /* end of report_comm_baud_rate */ X X/*+------------------------------------------------------------------------- X report_file_byte_io(count) X--------------------------------------------------------------------------*/ Xreport_file_byte_io(count) Xlong count; X{ X X total_data_chars_xfered += (long)count; X X if(no_curses) X { X if(count) X { X no_curses_newline(); X printf("Transferred %lu bytes for this file\r\n",count); X no_curses_newline(); X } X return; X } X X if(total_data_chars_xfered) X { X sprintf(s128,"Total file bytes transferred: %lu", X total_data_chars_xfered); X report_str(s128,-1); X } X X} /* end of report_file_byte_io */ X X/* end of zcurses.c */ X/* vi: set tabstop=4 shiftwidth=4: */ SHAR_EOF $TOUCH -am 1226003290 'z/zcurses.c' && chmod 0644 z/zcurses.c || echo 'restore of z/zcurses.c failed' Wc_c="`wc -c < 'z/zcurses.c'`" test 33753 -eq "$Wc_c" || echo 'z/zcurses.c: original size 33753, current size' "$Wc_c" # ============= z/zdebug.c ============== echo 'x - extracting z/zdebug.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'z/zdebug.c' && X/* see zcurses.c report_lasthdr() */ X/*+:EDITS:*/ X/*:08-14-1990-20:41-wht@n4hgf-ecu3.00-flush old edit history */ Xint header_debug = 0; X/* vi: set tabstop=4 shiftwidth=4: */ SHAR_EOF $TOUCH -am 0814204290 'z/zdebug.c' && chmod 0644 z/zdebug.c || echo 'restore of z/zdebug.c failed' Wc_c="`wc -c < 'z/zdebug.c'`" test 174 -eq "$Wc_c" || echo 'z/zdebug.c: original size 174, current size' "$Wc_c" true || echo 'restore of z/zlint.h failed' echo End of part 21, continue with part 22 exit 0 -------------------------------------------------------------------- Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US Hacker Extraordinaire d' async PADs, pods, proteins and protocols exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.