home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume21
/
ecu
/
part22
< prev
next >
Wrap
Text File
|
1991-08-05
|
55KB
|
1,976 lines
Newsgroups: comp.sources.misc
From: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
Subject: v21i074: ecu - ECU async comm package rev 3.10, Part22/37
Message-ID: <1991Aug4.163026.18598@sparky.IMD.Sterling.COM>
X-Md4-Signature: fd2995b3260fbb6c80574e020f96075e
Date: Sun, 4 Aug 1991 16:30:26 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
Posting-number: Volume 21, Issue 74
Archive-name: ecu/part22
Environment: SCO, XENIX, ISC
Supersedes: ecu3: Volume 16, Issue 25-59
---- Cut Here and feed the following to sh ----
#!/bin/sh
# this is ecu310.22 (part 22 of ecu310)
# do not concatenate these parts, unpack them in order with /bin/sh
# file z/ecusz.c continued
#
if touch 2>&1 | fgrep 'amc' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
if test ! -r _shar_seq_.tmp; then
echo 'Please unpack part 1 first!'
exit 1
fi
(read Scheck
if test "$Scheck" != 22; then
echo Please unpack part "$Scheck" next!
exit 1
else
exit 0
fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
echo 'x - still skipping z/ecusz.c'
else
echo 'x - continuing file z/ecusz.c'
sed 's/^X//' << 'SHAR_EOF' >> 'z/ecusz.c' &&
X * sent by the receiver,in place of setjmp/longjmp
X * rdchk(fdes) returns non 0 if a character is available
X */
X while(rdchk(iofd))
X {
X switch(readline(1))
X {
X case CAN:
X case ZPAD:
X c = getinsync(1);
X if(c == ZACK)
X break;
X#if defined(TCFLSH)
X ioctl(iofd,TCFLSH,1);
X#endif
X /* zcrce - dinna wanna starta ping-pong game */
X zsdata(txbuf,0,ZCRCE);
X goto gotack;
X
X case XOFF: /* Wait a while for an XON */
X case XOFF|0200:
X readline(100);
X
X default:
X ++junkcount;
X }
X }
X#endif /* READCHECK */
X if(Txwindow)
X {
X while((tcount = Txpos - Lrxpos) >= Txwindow)
X {
X if(e != ZCRCQ)
X zsdata(txbuf,0,e = ZCRCQ);
X c = getinsync(1);
X if(c != ZACK)
X {
X#if defined(TCFLSH)
X ioctl(iofd,TCFLSH,1);
X#endif
X zsdata(txbuf,0,ZCRCE);
X goto gotack;
X }
X }
X }
X } while(n == blklen);
X
X for(;;)
X {
X stohdr(Txpos);
X zsbhdr(ZEOF,Txhdr);
X switch(err = getinsync(0))
X {
X case ZACK:
X continue;
X case ZRPOS:
X goto somemore;
X case ZRINIT:
X return(OK);
X case ZSKIP:
X report_file_close(6);
X fclose(in);
X return(c);
X default:
X sprintf(s128,"SEND protocol sync error 0x%04x: %s",err,Pathname);
X ecu_log_event(getppid(),s128); /* always log this */
X report_str(s128 + 5,1);
X skip_count++;
X report_error_count();
X report_file_byte_io(this_file_length);
X report_file_close(7);
X fclose(in);
X return(ERROR);
X }
X }
X} /* end of zsendfdata */
X
X/*+-------------------------------------------------------------------------
X getinsync(flag) - get back in sync with receiver
X--------------------------------------------------------------------------*/
Xgetinsync(flag)
Xint flag;
X{
X register c;
X
X for(;;)
X {
X switch(c = zgethdr(Rxhdr,0))
X {
X case ZCAN:
X case ZABORT:
X case ZFIN:
X case TIMEOUT:
X sprintf(s128,"Receiver %s",frametypes[c+FTOFFSET]);
X report_str(s128,1);
X return(ERROR);
X case ZRPOS:
X report_str("Receiver ZRPOS",1);
X /* ************************************* */
X /* If sending to a modem buffer,you */
X /* might send a break at this point to */
X /* dump the modem's buffer. */
X /* ************************************* */
X if(Lastn >= 0 && Lastread == Rxpos)
X {
X Dontread = TRUE;
X } else
X {
X clearerr(in); /* In case file EOF seen */
X fseek(in,Rxpos,0);
X }
X bytcnt = Lrxpos = Txpos = Rxpos;
X if(Lastsync == Rxpos) /* wht - original code */
X { /* wht - original code */
X /* save frame count at time of each occurrence (wht) */
X bad_condx_frame_count = this_file_frame_count; /* wht */
X /* save block length at time of error (wht) */
X if(++SameZrposAgain > 4) /* wht - original code */
X { /* wht */
X if(bad_condx_blklen == 0) /* wht */
X bad_condx_blklen = blklen; /* wht */
X if(blklen > 256) /* wht - 32->256 */
X {
X blklen /= 2; /* wht - original code */
X report_txblklen(blklen);
X }
X } /* wht */
X } /* wht - original code */
X Lastsync = Rxpos;
X report_send_stats(Txpos);
X return(c);
X case ZACK:
X report_str("",-1);
X Lrxpos = Rxpos;
X if(flag || Txpos == Rxpos)
X return(ZACK);
X continue;
X
X case ZRINIT:
X report_str("",-1);
X#if defined(LOG_XFER)
X sprintf(s128,"SEND success: %s",Pathname);
X ecu_log_event(getppid(),s128);
X#endif
X case ZSKIP:
X report_file_byte_io(this_file_length);
X report_file_close(0);
X fclose(in);
X return(c);
X case ERROR:
X default:
X report_str("Sending ZNAK",0);
X zsbhdr(ZNAK,Txhdr);
X continue;
X }
X }
X} /* end of getinsync */
X
X/*+-------------------------------------------------------------------------
X saybibi() - Say "bibi" to the receiver, try to do it cleanly
X--------------------------------------------------------------------------*/
Xsaybibi()
X{
X for(;;)
X {
X stohdr(0L); /* CAF Was zsbhdr - minor change */
X zshhdr(ZFIN,Txhdr); /* to make debugging easier */
X switch(zgethdr(Rxhdr,0))
X {
X case ZFIN:
X sendline('O');
X sendline('O');
X flushline();
X case ZCAN:
X case TIMEOUT:
X return;
X }
X }
X} /* end of saybibi */
X
X/*+-------------------------------------------------------------------------
X determine_transaction_time()
X--------------------------------------------------------------------------*/
Xdetermine_transaction_time()
X{
Xregister c;
Xstruct stat f;
Xchar *name;
X
X rewind_file_list();
X TotalLeft = 0;
X Filesleft = 0;
X while(get_file_list_name(&name))
X {
X f.st_size = -1;
X if((access(name,04) >= 0) && (stat(name,&f) >= 0))
X {
X c = f.st_mode & S_IFMT;
X if(c != S_IFDIR && c != S_IFBLK)
X {
X ++Filesleft;
X TotalLeft += f.st_size;
X }
X }
X }
X FilesTotal = Filesleft;
X rewind_file_list();
X} /* end of determine_transaction_time */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of ecusz.c */
SHAR_EOF
echo 'File z/ecusz.c is complete' &&
$TOUCH -am 0725125991 'z/ecusz.c' &&
chmod 0644 z/ecusz.c ||
echo 'restore of z/ecusz.c failed'
Wc_c="`wc -c < 'z/ecusz.c'`"
test 42014 -eq "$Wc_c" ||
echo 'z/ecusz.c: original size 42014, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= z/lint_args.h ==============
if test -f 'z/lint_args.h' -a X"$1" != X"-c"; then
echo 'x - skipping z/lint_args.h (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting z/lint_args.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'z/lint_args.h' &&
X/*+-----------------------------------------------------------------------
X lint_args.h
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
X/*:04-29-1991-00:01-afterlint-creation */
X
X#ifndef BUILDING_LINT_ARGS
X#ifdef LINT_ARGS
X
X/* baudtest.c */
Xvoid test_tty_and_line_baud(void );
X/* zcommon.c */
Xint get_home_dir(char *);
Xint mode(int );
Xint sendbrk(void );
Xint zmputs(char *);
Xunsigned int getspeed(int );
Xvoid get_curr_dir(char *,int );
X/* zcurses.c */
Xchar *get_elapsed_time(long );
Xchar *get_tod(int,char *);
Xchar *mode_map(unsigned short ,char *);
Xint clear_area(struct _win_st *,int ,int ,int );
Xint clear_area_char(struct _win_st *,int ,int ,int ,char );
Xint determine_output_mode(void );
Xint report_comm_baud_rate(unsigned int );
Xint report_error_count(void );
Xint report_file_byte_io(long );
Xint report_file_open_length(long );
Xint report_file_open_mode(unsigned short );
Xint report_file_rcv_started(char *,long ,long ,unsigned short );
Xvoid report_file_xfer_rate(char *, long, int);
Xint report_protocol_crc_type(char *);
Xint report_protocol_type(char *);
Xint report_rx_tx_count(void );
Xint report_xfer_mode(char *);
Xvoid no_curses_newline(void );
Xvoid report_file_close(int );
Xvoid report_file_open_tod(void );
Xvoid report_file_send_open(char *,struct stat *);
Xvoid report_init(char *);
Xvoid report_last_rxhdr(char *,int );
Xvoid report_last_txhdr(char *,int );
Xvoid report_mode(int );
Xvoid report_rx_ind(int );
Xvoid report_rxblklen(int );
Xvoid report_rxpos(long );
Xvoid report_str(char *,int );
Xvoid report_top_line(char *);
Xvoid report_transaction(char *);
Xvoid report_tx_ind(int );
Xvoid report_txblklen(int );
Xvoid report_txpos(long );
Xvoid report_uninit(int );
Xvoid report_window(void );
X/* zdebug.c */
X/* zmodem.c */
Xint noxrd7(void );
Xint stohdr(long );
Xint zdlread(void );
Xint zgeth1(void );
Xint zgethdr(char *,int );
Xint zgethex(void );
Xint zputhex(int );
Xint zrbhdr(char *);
Xint zrbhdr32(char *);
Xint zrdat32(char *,int );
Xint zrdata(char *,int );
Xint zrhhdr(char *);
Xint zsbh32(int,char *);
Xint zsbhdr(int ,unsigned char *);
Xint zsda32(char *,int ,int );
Xint zsdata(unsigned char *,int ,int );
Xint zsendline(int );
Xint zshhdr(int ,unsigned char *);
Xlong rclhdr(char *);
X
X#else /* compiler doesn't know about prototyping */
X
X/* baudtest.c */
Xvoid test_tty_and_line_baud();
X/* zcommon.c */
Xunsigned int getspeed();
Xvoid get_curr_dir();
X/* zcurses.c */
Xchar *get_elapsed_time();
Xchar *hhmmss();
Xchar *mode_map();
Xvoid no_curses_newline();
Xvoid report_file_close();
Xvoid report_file_open_tod();
Xvoid report_file_send_open();
Xvoid report_file_xfer_rate();
Xvoid report_init();
Xvoid report_last_rxhdr();
Xvoid report_last_txhdr();
Xvoid report_mode();
Xvoid report_rx_ind();
Xvoid report_rxblklen();
Xvoid report_rxpos();
Xvoid report_str();
Xvoid report_top_line();
Xvoid report_transaction();
Xvoid report_tx_ind();
Xvoid report_txblklen();
Xvoid report_txpos();
Xvoid report_uninit();
Xvoid report_window();
X/* zdebug.c */
X/* zmodem.c */
Xlong rclhdr();
X
X#endif /* LINT_ARGS */
X#endif /* BUILDING_LINT_ARGS */
X
X/* end of lint_args.h */
SHAR_EOF
$TOUCH -am 0725125991 'z/lint_args.h' &&
chmod 0644 z/lint_args.h ||
echo 'restore of z/lint_args.h failed'
Wc_c="`wc -c < 'z/lint_args.h'`"
test 3125 -eq "$Wc_c" ||
echo 'z/lint_args.h: original size 3125, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= z/zcommon.c ==============
if test -f 'z/zcommon.c' -a X"$1" != X"-c"; then
echo 'x - skipping z/zcommon.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
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.Mt-Park.GA.US
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/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
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)
Xint 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)
Xint new_mode;
X{
X static did0 = FALSE;
X report_mode(new_mode);
X switch(new_mode)
X {
X#if defined(M_SYSV)
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 0725125991 'z/zcommon.c' &&
chmod 0644 z/zcommon.c ||
echo 'restore of z/zcommon.c failed'
Wc_c="`wc -c < 'z/zcommon.c'`"
test 15678 -eq "$Wc_c" ||
echo 'z/zcommon.c: original size 15678, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= z/zcurses.c ==============
if test -f 'z/zcurses.c' -a X"$1" != X"-c"; then
echo 'x - skipping z/zcurses.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
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`----------------------------------------------------------'
X14| FE ___ OE ___ rcvd ________ xmtd ________ RTS _ CTS _
X15| flow xmtr CTS ____ XOFF ____ rcvr RTS ____ XOFF ____
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(skipped)
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_file_xfer_rate(text,count,final)
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/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
X/*:06-15-1991-05:47-root@n4hgf-report per-file xfer rate */
X/*:05-25-1991-14:51-wht@n4hgf-FAS/i display */
X/*:04-24-1991-01:22-wht@n4hgf-handle no_curses and single file xfer >= 1 hour */
X/*:02-03-1991-17:27-wht@n4hgf-show elapsed time during no curses xfer */
X/*:01-04-1991-15:54-wht@n4hgf-no_curses per-file xfer rate was wrong */
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 "../ecucurses.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#if defined(M_SYSV)
X# include <sys/machdep.h>
X#else
X# include <sys/at_ansi.h>
X# include <sys/kd.h>
X#endif
X#if defined(FASI)
X# include <local/fas.h>
X#endif /* FASI */
X
X#include "../pc_scr.h"
X#include "lint_args.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#if defined(FASI)
X#define WIN_LINES 17
X#else
X#define WIN_LINES 15
X#endif /* FASI */
X#define WIN_COLS 60
X#define WIN_TOPY 2
X#define WIN_LEFTX 8
X
Xextern char curr_dir[];
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;
Xlong this_file_xfer_count = 0;
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 s128[128];
X
X#if defined(FASI)
Xstruct fas_info fip_start;
X#endif /* FASI */
X
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#if defined(FASI)
X " FE ___ OE ___ rcvd ________ xmtd ________ RTS _ CTS _ ",
X " flow xmtr CTS ____ XOFF ____ rcvr RTS ____ XOFF ____ ",
X#endif /* FASI */
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 static char tod_str[32];
X long cur_time = time((long *)0);
X struct tm *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",
X 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,"XFERINFO transaction 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 + 9);
X#if defined(WHT)
X ecu_log_event(getppid(),s128);
X#endif
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#ifdef NO_PTY_CURSES
X struct stat pty_stat;
X#endif
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
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#if defined(FASI)
X { extern int iofd;
X (void)ioctl(iofd,FASIC_SIP,&fip_start);
X }
X#endif /* FASI */
X
X if(!initscr())
X exit(254);
X if(!stdscr)
X exit(254);
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 strcpy(s128,title);
X waddstr(win,s128);
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(s128,bottom_label,WIN_COLS - 6);
X s128[WIN_COLS - 6] = 0;
X wmove(win,WIN_LINES - 1,2);
X waddch(win,' ');
X waddstr(win,s128);
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{
Xchar *cptr;
X
X if(no_curses)
X {
X if(report_verbosity && status)
X {
X printf("R");
X if(++no_curses_pos > 75)
X {
X no_curses_newline();
X current_seconds = time((long *)0);
X elapsed_seconds = current_seconds - this_file_start_seconds;
X cptr = get_elapsed_time(elapsed_seconds);
X no_curses_pos = printf("%s elapsed ",cptr +
X ((elapsed_seconds < 3600L) ? 3 : 0));
X }
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{
Xchar *cptr;
X if(no_curses)
X {
X if(report_verbosity && status)
X {
X printf("T");
X if(++no_curses_pos > 75)
X {
X no_curses_newline();
X no_curses_newline();
X current_seconds = time((long *)0);
X elapsed_seconds = current_seconds - this_file_start_seconds;
X cptr = get_elapsed_time(elapsed_seconds);
X no_curses_pos = printf("%s elapsed ",cptr +
X ((elapsed_seconds < 3600L) ? 3 : 0));
X }
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 function 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
XIf FASI,
X FE: row 14 col 6 len 4
X OE: row 14 col 13 len 4
X rcvd count: row 14 col 22 len 8 unsigned long
X xmtd count: row 14 col 36 len 8 unsigned long
X RTS status: row 14 col 48 len 1
X CTS status: row 14 col 55 len 1
X xmtr CTS count: row 15 col 18 len 4
X xmtr XOFF count: row 15 col 28 len 4
X rcvr CTS count: row 15 col 42 len 4
X rcvr XOFF count: row 15 col 52 len 4
X--------------------------------------------------------------------------*/
Xreport_rx_tx_count()
X{
X extern unsigned long rx_char_count;
X extern unsigned long tx_char_count;
X#if defined(FASI)
X unsigned long ltmp;
X struct fas_info now;
X extern int iofd;
X#endif /* FASI */
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#if defined(FASI)
X if(!ioctl(iofd,FASIC_SIP,&now))
X {
X if((ltmp = now.framing_errors - fip_start.framing_errors) > 999L)
X ltmp = 999L;
X sprintf(s128,"%-3lu",ltmp);
X wmove(win,14,6);
X waddstr(win,s128);
X
X if((ltmp = now.overrun_errors - fip_start.overrun_errors) > 999L)
X ltmp = 999L;
X sprintf(s128,"%-3lu",ltmp);
X wmove(win,14,13);
X waddstr(win,s128);
X
X ltmp = now.characters_received - fip_start.characters_received;
X sprintf(s128,"%-8lu",ltmp);
X wmove(win,14,22);
X waddstr(win,s128);
X
X ltmp = now.characters_transmitted - fip_start.characters_transmitted;
X sprintf(s128,"%-8lu",ltmp);
X wmove(win,14,36);
X waddstr(win,s128);
X
X wmove(win,14,49);
X waddch(win,(now.mcr & MC_SET_RTS) ? 'T' : 'F');
X
X wmove(win,14,55);
X waddch(win,(now.msr & MS_CTS_PRESENT) ? 'T' : 'F');
X
X ltmp = now.xmtr_hw_flow_count - fip_start.xmtr_hw_flow_count;
X if(ltmp > 9999L)
X ltmp = 9999L;
X sprintf(s128,"%-4lu",ltmp);
X wmove(win,15,17);
X waddstr(win,s128);
X
X ltmp = now.xmtr_sw_flow_count - fip_start.xmtr_sw_flow_count;
X if(ltmp > 9999L)
X ltmp = 9999L;
X sprintf(s128,"%-4lu",ltmp);
X wmove(win,15,27);
X waddstr(win,s128);
X
X ltmp = now.rcvr_hw_flow_count - fip_start.rcvr_hw_flow_count;
X if(ltmp > 9999L)
X ltmp = 9999L;
X sprintf(s128,"%-4lu",ltmp);
X wmove(win,15,41);
X waddstr(win,s128);
X
X ltmp = now.rcvr_sw_flow_count - fip_start.rcvr_sw_flow_count;
X if(ltmp > 9999L)
X ltmp = 9999L;
X sprintf(s128,"%-4lu",ltmp);
X wmove(win,15,51);
X waddstr(win,s128);
X }
X#endif /* FASI */
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_file_xfer_rate(text,count,final)
X--------------------------------------------------------------------------*/
Xvoid
Xreport_file_xfer_rate(text,count,final)
Xchar *text;
Xlong count;
Xint final;
X{
X float rate = 0.0;
X float eff = 0.0;
X static long last_report = 0L;
X
X s128[0] = 0;
X
X current_seconds = time((long *)0);
SHAR_EOF
true || echo 'restore of z/zcurses.c failed'
fi
echo 'End of ecu310 part 22'
echo 'File z/zcurses.c is continued in part 23'
echo 23 > _shar_seq_.tmp
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.