[comp.sources.misc] v13i016: tipx

wht@gatech.edu@tridom.UUCP (Warren H. Tucker) (05/30/90)

Posting-number: Volume 13, Issue 16
Submitted-by: wht@gatech.edu@tridom.UUCP (Warren H. Tucker)
Archive-name: tipx/part04

#!/bin/sh
# This is part 04 of tipx
if touch 2>&1 | fgrep 'mmdd' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= xfer/zcurses.c ==============
echo "x - extracting xfer/zcurses.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > xfer/zcurses.c &&
X/*+-------------------------------------------------------------------------
X	zcurses.c -- tip file transfer program curses interface
X	wht%n4hgf@emory.mathcs.emory.edu
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	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/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
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
X#include "zlint.h"
X
Xlong time();
Xextern char *tzname[];
Xstruct tm *localtime();
X
X#ifdef IBMPC
X#define sTL		0xDA
X#define sTR		0xBF
X#define sBL		0xC0
X#define sBR		0xD9
X#define sLT		0xC3	/* left hand T */
X#define sRT		0xB4	/* right hand T */
X#define sVR		0xB3	/* vertical rule */
X#define sHR		0xC4	/* horizontal rule */
X#else
X#define sTL		'.'
X#define sTR		'.'
X#define sBL		'`'
X#define sBR		'\''
X#define sLT		'+'
X#define sRT		'+'
X#define sVR		'|'
X#define sHR		'-'
X#endif
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 tipsz_flag;	/* tipsz == 1, tiprz == 0 */
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 curses_installed = 0;		/* curses not yet active */
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 *get_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	clear_area(win,row,col,len)
X--------------------------------------------------------------------------*/
Xclear_area(win,row,col,len)
XWINDOW	*win;
Xint row;
Xint col;
Xint len;
X{
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	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	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(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(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(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(curses_installed)
X	{
X		elapsed_seconds = current_seconds - start_seconds;
X		if(elapsed_seconds)
X		{
X			rate = (float)total_data_chars_xfered / (float)elapsed_seconds;
X			if(zcurses_baud_rate)
X				eff  = 100 * (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		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		curses_installed = 0;
X	}
X
X}	/* end of report_uninit */
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(curses_installed)
X		return;
X
X	initscr();
X	crmode();
X	noecho();
X	nonl();
X	clear();
X	curses_installed = 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(tipsz_flag)
X	{
X		clear_area(win,2,15,3);
X		sprintf(s128,"%3d",npats);
X		waddstr(win,s128);
X	}
X	else	/* tiprz */
X	{
X		clear_area(win,2,11,8);	/* clear "of ###" */
X		waddstr(win,":");
X	}
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	start_seconds = time((long *)0);
X	current_seconds = start_seconds;
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 defined(M_SYS5)
X	wmove(win,1,54);
X	waddch(win,(status) ? 'R' : ' ');
X	wmove(win,1,54);
X	wrefresh(win);
X#endif
X}	/* end of report_rx_ind */
X
X/*+-------------------------------------------------------------------------
X	report_tx_ind(status)
X--------------------------------------------------------------------------*/
Xvoid
Xreport_tx_ind(status)
Xint status;
X{
X#if defined(M_SYS5)
X	wmove(win,1,56);
X	waddch(win,(status) ? 'T' : ' ');
X	wmove(win,1,56);
X	wrefresh(win);
X#endif
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)
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	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	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	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	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{
Xint i;
Xchar tmp[16];
Xchar rdchar;
X	if(
X#if defined(M_SYS5)
X		rdchk(0)
X#else
X		!ioctl(0,FIONREAD,&i) && i
X#endif
X			)
X	{
X		read(0,&rdchar,1);
X		rdchar &= 0x7f;
X		if(rdchar == 0x0C || rdchar == 0x012)	/* ^L or ^R */
X		{
X			touchwin(stdscr);
X			wrefresh(stdscr);
X			touchwin(win);
X			wrefresh(win);
X		}
X	}
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	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	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(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(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(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	if(log_packets)
X	{
X		write(log_packets,"info: ",6);
X		write(log_packets,rptstr,strlen(rptstr));
X		write(log_packets,"\n",1);
X	}
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	clear_area(win,8,41,8);
X	this_file_start_seconds = time((long *)0);
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	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	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	/* 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	/* 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	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("End of file",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	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	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 0521190890 xfer/zcurses.c &&
chmod 0644 xfer/zcurses.c ||
echo "restore of xfer/zcurses.c failed"
set `wc -c xfer/zcurses.c`;Wc_c=$1
if test "$Wc_c" != "28447"; then
	echo original size 28447, current size $Wc_c
fi
# ============= xfer/zdebug.c ==============
echo "x - extracting xfer/zdebug.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > xfer/zdebug.c &&
X/* see zcurses.c report_lasthdr() */
X/*+:EDITS:*/
X/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
Xint header_debug = 0;
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0521180090 xfer/zdebug.c &&
chmod 0644 xfer/zdebug.c ||
echo "restore of xfer/zdebug.c failed"
set `wc -c xfer/zdebug.c`;Wc_c=$1
if test "$Wc_c" != "180"; then
	echo original size 180, current size $Wc_c
fi
# ============= xfer/zlint.h ==============
echo "x - extracting xfer/zlint.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > xfer/zlint.h &&
X/*+-----------------------------------------------------------------------
X	zlint.h
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
X
X/* zcommon.c */
Xstatic  unsigned int getspeed();
Xvoid get_curr_dir();
X/* zcurses.c */
Xchar *get_elapsed_time();
Xchar *get_tod();
Xchar *mode_map();
Xvoid report_file_close();
Xvoid report_file_open_tod();
Xvoid report_file_send_open();
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/* vi: set ts=4 sw=4: */
X/* end of zlint.h */
SHAR_EOF
$TOUCH -am 0521180190 xfer/zlint.h &&
chmod 0644 xfer/zlint.h ||
echo "restore of xfer/zlint.h failed"
set `wc -c xfer/zlint.h`;Wc_c=$1
if test "$Wc_c" != "907"; then
	echo original size 907, current size $Wc_c
fi
# ============= xfer/zmodem.c ==============
echo "x - extracting xfer/zmodem.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > xfer/zmodem.c &&
X/*+-------------------------------------------------------------------------
X	zmodem.c - ZMODEM protocol primitives
X    based on code by Chuck Forsberg
X	tip adaptation by wht%n4hgf@emory.mathcs.emory.edu
X
X  Entry point Functions:
X	zsbhdr(type,hdr) send binary header
X	zshhdr(type,hdr) send hex header
X	zgethdr(hdr,eflag) receive header - binary or hex
X	zsdata(buf,len,frameend) send data
X	zrdata(buf,len) receive data
X	stohdr(pos) store position data in Txhdr
X	long rclhdr(hdr) recover position offset from header
X
X  Defined functions:
X	noxrd7()
X	rclhdr(hdr)
X	stohdr(pos)
X	zdlread()
X	zgeth1()
X	zgethdr(hdr,eflag)
X	zgethex()
X	zputhex(c)
X	zrbhdr(hdr)
X	zrbhdr32(hdr)
X	zrdat32(buf,length)
X	zrdata(buf,length)
X	zrhhdr(hdr)
X	zsbh32(hdr,type)
X	zsbhdr(type,hdr)
X	zsda32(buf,length,frameend)
X	zsdata(buf,length,frameend)
X	zsendline(c)
X	zshhdr(type,hdr)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
X
X#include "zmodem.h"			/* wht */
X#include "zlint.h"
X
Xextern char s128[];				/* wht */
Xextern int Zctlesc;				/* wht */
Xextern int Zmodem;				/* wht */
Xextern long cr3tab[];			/* wht */
Xextern unsigned Baudrate;		/* wht */
Xextern unsigned short crctab[];	/* wht */
X
Xint Rxtimeout = 100;		/* Tenths of seconds to wait for something */
X
X#if !defined(UNSL)
X#define UNSL
X#endif
X
X
X
Xstatic lastsent;	/* Last char we sent */
Xstatic evenp;		/* Even parity seen on header */
X
X/* Globals used by ZMODEM functions */
Xchar Attn[ZATTNLEN+1];	/* Attention string rx sends to tx on err */
Xchar Rxhdr[4];		/* Received header */
Xchar Txhdr[4];		/* Transmitted header */
Xint Crc32;		/* Display flag indicating 32 bit CRC being received */
Xint Crc32t;		/* Display flag indicating 32 bit CRC being sent */
Xint Rxcount;		/* Count of data bytes received */
Xint Rxframeind;		/* ZBIN ZBIN32,or ZHEX type of frame received */
Xint Rxtimeout;	/* Tenths of seconds to wait for something */
Xint Rxtype;		/* Type of header received */
Xint Txfcs32;		/* TURE means send binary frames with 32 bit FCS */
Xint Zrwindow;	/* RX window size (controls garbage count) */
Xlong Rxpos;	/* Received file position */
Xlong Txpos;	/* Transmitted file position */
X
Xchar *frametypes[] = 
X{
X	"Carrier Lost",		/* -3 */
X	"TIMEOUT",			/* -2 */
X	"ERROR",			/* -1 */
X/* #define FTOFFSET 3 moved to zmodem.h */
X	"ZRQINIT",
X	"ZRINIT",
X	"ZSINIT",
X	"ZACK ",
X	"ZFILE",
X	"ZSKIP",
X	"ZNAK ",
X	"ZABORT",
X	"ZFIN ",
X	"ZRPOS",
X	"ZDATA",
X	"ZEOF ",
X	"ZFERR",
X	"ZCRC ",
X	"ZCHALLENGE",
X	"ZCOMPL",
X	"ZCAN ",
X	"ZFREECNT",
X	"ZCOMMAND",
X	"ZSTDERR",
X	"xxxxx"
X#define FRTYPES 22	/* Total number of frame types in this array */
X	/*  not including psuedo negative entries */
X};
X
Xstatic char masked[] = "8 bit transparent path required";
Xstatic char badcrc[] = "Bad CRC";
X
X/* Send ZMODEM binary header hdr of type type */
Xzsbhdr(type,hdr)
Xregister unsigned char *hdr;
X{
X	register int n;
X	register unsigned crc;
X
X	report_tx_ind(1);
X	sprintf(s128,"hdr %s %ld",frametypes[type+FTOFFSET],rclhdr(hdr));
X	report_last_txhdr(s128,0);
X
X	xsendline(ZPAD); 
X	xsendline(ZDLE);
X
X	if(Crc32t=Txfcs32)
X		zsbh32(hdr,type);
X	else 
X	{
X		xsendline(ZBIN); 
X		zsendline(type); 
X		crc = updcrc(type,0);
X
X		for(n=4; --n >= 0; ++hdr)
X		{
X			zsendline(*hdr);
X			crc = updcrc(*hdr,crc);
X		}
X		crc = updcrc(0,updcrc(0,crc));
X		zsendline(crc>>8);
X		zsendline(crc);
X	}
X	if(type != ZDATA)
X		flushline();
X	report_tx_ind(0);
X}
X
X
X/* Send ZMODEM binary header hdr of type type */
Xzsbh32(hdr,type)
Xregister char *hdr;
X{
X	register int n;
X	register UNSL long crc;
X
X	report_tx_ind(1);
X	xsendline(ZBIN32);  
X	zsendline(type);
X	crc = 0xFFFFFFFFL; 
X	crc = UPDC32(type,crc);
X
X	for(n=4; --n >= 0; ++hdr)
X	{
X		crc = UPDC32((0377 & *hdr),crc);
X		zsendline(*hdr);
X	}
X	crc = ~crc;
X	for(n=4; --n >= 0;)
X	{
X		zsendline((int)crc);
X		crc >>= 8;
X	}
X	report_tx_ind(0);
X}
X
X/* Send ZMODEM HEX header hdr of type type */
Xzshhdr(type,hdr)
Xregister unsigned char *hdr;
X{
X	register int n;
X	register unsigned short crc;
X
X	report_tx_ind(1);
X
X	sprintf(s128,"hdr %s %ld",frametypes[type+FTOFFSET],rclhdr(hdr));
X	report_last_txhdr(s128,0);
X	sendline(ZPAD); 
X	sendline(ZPAD); 
X	sendline(ZDLE); 
X	sendline(ZHEX);
X	zputhex(type);
X	Crc32t = 0;
X
X	crc = updcrc(type,0);
X	for(n=4; --n >= 0; ++hdr)
X	{
X		zputhex(*hdr); 
X		crc = updcrc(*hdr,crc);
X/*		crc = updcrc((0377 & *hdr),crc);  original - wht */
X	}
X	crc = updcrc(0,updcrc(0,crc));
X	zputhex(crc>>8); 
X	zputhex(crc);
X
X	/* Make it printable on remote machine */
X	sendline(015); 
X	sendline(012);
X	/*
X	 * Uncork the remote in case a fake XOFF has stopped data flow
X	 */
X	if(type != ZFIN && type != ZACK)
X		sendline(021);
X	flushline();
X	report_tx_ind(0);
X}
X
X/*
X * Send binary array buf of length length,with ending ZDLE sequence frameend
X */
Xstatic char *Zendnames[] = { "ZCRCE","ZCRCG","ZCRCQ","ZCRCW"};
X
Xzsdata(buf,length,frameend)
Xregister unsigned char *buf;
X{
X	register unsigned short crc;
X
X	report_tx_ind(1);
X
X	sprintf(s128,"data %s %d bytes",Zendnames[frameend-ZCRCE&3],length);
X	report_last_txhdr(s128,0);
X	if(Crc32t)
X		zsda32(buf,length,frameend);
X	else 
X	{
X		crc = 0;
X		for(;--length >= 0; ++buf)
X		{
X			zsendline(*buf); 
X			crc = updcrc(*buf,crc);
X		}
X		xsendline(ZDLE); 
X		xsendline(frameend);
X		crc = updcrc(frameend,crc);
X
X		crc = updcrc(0,updcrc(0,crc));
X		zsendline(crc>>8); 
X		zsendline(crc);
X	}
X	if(frameend == ZCRCW)
X	{
X		xsendline(XON);  
X		flushline();
X	}
X	report_tx_ind(0);
X
X}
X
Xzsda32(buf,length,frameend)
Xregister char *buf;
X{
X	register int c;
X	register UNSL long crc;
X
X	report_tx_ind(1);
X
X	crc = 0xFFFFFFFFL;
X	for(;--length >= 0; ++buf)
X	{
X		c = *buf & 0377;
X		if(c & 0140)
X			xsendline(lastsent = c);
X		else
X			zsendline(c);
X		crc = UPDC32(c,crc);
X	}
X	xsendline(ZDLE); 
X	xsendline(frameend);
X	crc = UPDC32(frameend,crc);
X
X	crc = ~crc;
X	for(length=4; --length >= 0;)
X	{
X		zsendline((int)crc);  
X		crc >>= 8;
X	}
X	report_tx_ind(0);
X}
X
X/*
X * Receive array buf of max length with ending ZDLE sequence
X *  and CRC.  Returns the ending character or error code.
X *  NB: On errors may store length+1 bytes!
X */
Xzrdata(buf,length)
Xregister char *buf;
X{
X	register int c;
X	register unsigned short crc;
X	register char *end;
X	register int d;
X
X	report_rx_ind(1);
X
X	if(Rxframeind == ZBIN32)
X	{
X		report_rx_ind(0);
X		return(zrdat32(buf,length));
X	}
X
X	crc = Rxcount = 0;  
X	end = buf + length;
X	while(buf <= end)
X	{
X		if((c = zdlread()) & ~0377)
X		{
Xcrcfoo:
X			switch(c)
X			{
X			case GOTCRCE:
X			case GOTCRCG:
X			case GOTCRCQ:
X			case GOTCRCW:
X				crc = updcrc(((d=c)&0377),crc);
X				if((c = zdlread()) & ~0377)
X					goto crcfoo;
X				crc = updcrc(c,crc);
X				if((c = zdlread()) & ~0377)
X					goto crcfoo;
X				crc = updcrc(c,crc);
X				if(crc & 0xFFFF)
X				{
X					report_str(badcrc,0);
X					report_rx_ind(0);
X					return(ERROR);
X				}
X				Rxcount = length - (end - buf);
X				report_rxblklen(Rxcount);
X				sprintf(s128,"data %s %d bytes",
X					Zendnames[d-GOTCRCE&3],Rxcount);
X				report_last_rxhdr(s128,0);
X				report_rx_ind(0);
X				return(d);
X			case GOTCAN:
X				report_str("Sender Cancelled",1);
X				report_rx_ind(0);
X				return(ZCAN);
X			case TIMEOUT:
X				report_str("TIMEOUT",1);
X				report_rx_ind(0);
X				return(c);
X			default:
X				report_str("Bad data subpacket",1);
X				report_rx_ind(0);
X				return(c);
X			}
X		}
X		*buf++ = c;
X		crc = updcrc(c,crc);
X	}
X	report_str("Data subpacket too long",1);
X	report_rx_ind(0);
X	return(ERROR);
X}
X
Xzrdat32(buf,length)
Xregister char *buf;
X{
X	register int c;
X	register UNSL long crc;
X	register char *end;
X	register int d;
X
X	report_rx_ind(1);
X	crc = 0xFFFFFFFFL;  
X	Rxcount = 0;  
X	end = buf + length;
X	while(buf <= end)
X	{
X		if((c = zdlread()) & ~0377)
X		{
Xcrcfoo:
X			switch(c)
X			{
X			case GOTCRCE:
X			case GOTCRCG:
X			case GOTCRCQ:
X			case GOTCRCW:
X				d = c;  
X				c &= 0377;
X				crc = UPDC32(c,crc);
X				if((c = zdlread()) & ~0377)
X					goto crcfoo;
X				crc = UPDC32(c,crc);
X				if((c = zdlread()) & ~0377)
X					goto crcfoo;
X				crc = UPDC32(c,crc);
X				if((c = zdlread()) & ~0377)
X					goto crcfoo;
X				crc = UPDC32(c,crc);
X				if((c = zdlread()) & ~0377)
X					goto crcfoo;
X				crc = UPDC32(c,crc);
X				if(crc != 0xDEBB20E3)
X				{
X					report_str(badcrc,0);
X					report_rx_ind(0);
X					return(ERROR);
X				}
X				Rxcount = length - (end - buf);
X				report_rxblklen(Rxcount);
X				sprintf(s128,"data %s %d bytes",
X					Zendnames[d-GOTCRCE&3],Rxcount);
X				report_last_rxhdr(s128,0);
X				report_rx_ind(0);
X				return(d);
X			case GOTCAN:
X				report_str("Sender Canceled",1);
X				report_rx_ind(0);
X				return(ZCAN);
X			case TIMEOUT:
X				report_str("TIMEOUT",1);
X				report_rx_ind(0);
X				return(c);
X			default:
X				report_str("Bad data subpacket",1);
X				report_rx_ind(0);
X				return(c);
X			}
X		}
X		*buf++ = c;
X		crc = UPDC32(c,crc);
X	}
X	report_str("Data subpacket too long",1);
X	report_rx_ind(0);
X	return(ERROR);
X}
X
X
X/*
X * Read a ZMODEM header to hdr,either binary or hex.
X *  eflag controls local display of non zmodem characters:
X *	0:  no display
X *	1:  display printing characters only
X *	2:  display all non ZMODEM characters
X *  On success,set Zmodem to 1,set Rxpos and return type of header.
X *   Otherwise return negative on error.
X *   Return ERROR instantly if ZCRCW sequence,for fast error recovery.
X */
Xzgethdr(hdr,eflag)
Xchar *hdr;
X{
Xregister int c,n,cancount;
X
X	report_rx_ind(1);
X	n = Zrwindow + Baudrate;	/* Max bytes before start of frame */
X	Rxframeind = Rxtype = 0;
X
Xstartover:
X	cancount = 5;
Xagain:
X	/* Return immediate ERROR if ZCRCW sequence seen */
X	switch(c = readline(Rxtimeout))
X	{
X	case RCDO:
X	case TIMEOUT:
X		goto fifi;
X	case CAN:
Xgotcan:
X		if(--cancount <= 0)
X		{
X			c = ZCAN; 
X			goto fifi;
X		}
X		switch(c = readline(1))
X		{
X		case TIMEOUT:
X			goto again;
X		case ZCRCW:
X			c = ERROR;
X			/* **** FALL THRU TO **** */
X		case RCDO:
X			goto fifi;
X		default:
X			break;
X		case CAN:
X			if(--cancount <= 0)
X			{
X				c = ZCAN; 
X				goto fifi;
X			}
X			goto again;
X		}
X		/* **** FALL THRU TO **** */
X	default:
Xagn2:
X		if( --n == 0)
X		{
X			report_str("Garbage count exceeded",1);
X			report_last_rxhdr("Noise",0);
X			report_rx_ind(0);
X			return(ERROR);
X		}
X		goto startover;
X	case ZPAD|0200:		/* This is what we want. */
X	case ZPAD:		/* This is what we want. */
X		evenp = c & 0200;
X		break;
X	}
X	cancount = 5;
Xsplat:
X	switch(c = noxrd7())
X	{
X	case ZPAD:
X		goto splat;
X	case RCDO:
X	case TIMEOUT:
X		goto fifi;
X	default:
X		goto agn2;
X	case ZDLE:		/* This is what we want. */
X		break;
X	}
X
X	switch(c = noxrd7())
X	{
X	case RCDO:
X	case TIMEOUT:
X		goto fifi;
X	case ZBIN:
X		Rxframeind = ZBIN;  
X		Crc32 = FALSE;
X		c =  zrbhdr(hdr);
X		break;
X	case ZBIN32:
X		Crc32 = Rxframeind = ZBIN32;
X		c =  zrbhdr32(hdr);
X		break;
X	case ZHEX:
X		Rxframeind = ZHEX;  
X		Crc32 = FALSE;
X		c =  zrhhdr(hdr);
X		break;
X	case CAN:
X		goto gotcan;
X	default:
X		goto agn2;
X	}
X	Rxpos = hdr[ZP3] & 0377;
X	Rxpos = (Rxpos<<8) + (hdr[ZP2] & 0377);
X	Rxpos = (Rxpos<<8) + (hdr[ZP1] & 0377);
X	Rxpos = (Rxpos<<8) + (hdr[ZP0] & 0377);
Xfifi:
X	switch(c)
X	{
X	case GOTCAN:
X		c = ZCAN;
X		/* **** FALL THRU TO **** */
X	case ZNAK:
X	case ZCAN:
X	case ERROR:
X	case TIMEOUT:
X	case RCDO:
X		sprintf(s128,"Got %s",frametypes[c+FTOFFSET]);
X		report_str(s128,1);
X		/* **** FALL THRU TO **** */
X	default:
X		if(c >= -3 && c <= FRTYPES)
X			sprintf(s128,"hdr %s %ld",frametypes[c+FTOFFSET],Rxpos);
X		else
X			sprintf(s128,"hdr 0x%02x? %ld",c,Rxpos);
X		report_last_rxhdr(s128,0);
X	}
X	report_rx_ind(0);
X	return(c);
X}
X
X/* Receive a binary style header (type and position) */
Xzrbhdr(hdr)
Xregister char *hdr;
X{
X	register int c,n;
X	register unsigned short crc;
X
X	if((c = zdlread()) & ~0377)
X		return(c);
X	Rxtype = c;
X	crc = updcrc(c,0);
X
X	for(n=4; --n >= 0; ++hdr)
X	{
X		if((c = zdlread()) & ~0377)
X			return(c);
X		crc = updcrc(c,crc);
X		*hdr = c;
X	}
X	if((c = zdlread()) & ~0377)
X		return(c);
X	crc = updcrc(c,crc);
X	if((c = zdlread()) & ~0377)
X		return(c);
X	crc = updcrc(c,crc);
X	if(crc & 0xFFFF)
X	{
X		if(evenp)
X			report_str(masked,1);
X		report_str(badcrc,0);
X		return(ERROR);
X	}
X#if defined(ZMODEM)
X	Protocol = ZMODEM;
X#endif
X	Zmodem = 1;
X	return(Rxtype);
X}
X
X/* Receive a binary style header (type and position) with 32 bit FCS */
Xzrbhdr32(hdr)
Xregister char *hdr;
X{
X	register int c,n;
X	register UNSL long crc;
X
X	if((c = zdlread()) & ~0377)
X		return(c);
X	Rxtype = c;
X	crc = 0xFFFFFFFFL; 
X	crc = UPDC32(c,crc);
X
X	for(n=4; --n >= 0; ++hdr)
X	{
X		if((c = zdlread()) & ~0377)
X			return(c);
X		crc = UPDC32(c,crc);
X		*hdr = c;
X	}
X	for(n=4; --n >= 0;)
X	{
X		if((c = zdlread()) & ~0377)
X			return(c);
X		crc = UPDC32(c,crc);
X	}
X	if(crc != 0xDEBB20E3)
X	{
X		if(evenp)
X			report_str(masked,1);
X		report_str(badcrc,0);
X		return(ERROR);
X	}
X#if defined(ZMODEM)
X	Protocol = ZMODEM;
X#endif
X	Zmodem = 1;
X	return(Rxtype);
X}
X
X
X/* Receive a hex style header (type and position) */
Xzrhhdr(hdr)
Xchar *hdr;
X{
X	register int c;
X	register unsigned short crc;
X	register int n;
X
X	if((c = zgethex()) < 0)
X		return(c);
X	Rxtype = c;
X	crc = updcrc(c,0);
X
X	for(n=4; --n >= 0; ++hdr)
X	{
X		if((c = zgethex()) < 0)
X			return(c);
X		crc = updcrc(c,crc);
X		*hdr = c;
X	}
X	if((c = zgethex()) < 0)
X		return(c);
X	crc = updcrc(c,crc);
X	if((c = zgethex()) < 0)
X		return(c);
X	crc = updcrc(c,crc);
X	if(crc & 0xFFFF)
X	{
X		report_str(badcrc,0); 
X		return(ERROR);
X	}
X	if(readline(1) == '\r')	/* Throw away possible cr/lf */
X		readline(1);
X#if defined(ZMODEM)
X	Protocol = ZMODEM;
X#endif
X	Zmodem = 1; 
X	return(Rxtype);
X}
X
X/* Send a byte as two hex digits */
Xzputhex(c)
Xregister int c;
X{
X	static char digits[]	= "0123456789abcdef";
X
X	sendline(digits[(c&0xF0)>>4]);
X	sendline(digits[(c)&0xF]);
X}
X
X/*
X * Send character c with ZMODEM escape sequence encoding.
X *  Escape XON,XOFF. Escape CR following @ (Telenet net escape)
X */
Xzsendline(c)
X{
X
X	/* Quick check for non control characters */
X	if(c & 0140)
X		xsendline(lastsent = c);
X	else 
X	{
X		switch(c &= 0377)
X		{
X		case ZDLE:
X			xsendline(ZDLE);
X			xsendline(lastsent = (c ^= 0100));
X			break;
X		case 015:
X		case 0215:
X			if(!Zctlesc && (lastsent & 0177) != '@')
X				goto sendit;
X			/* **** FALL THRU TO **** */
X		case 020:
X		case 021:
X		case 023:
X		case 0220:
X		case 0221:
X		case 0223:
X			xsendline(ZDLE);
X			c ^= 0100;
Xsendit:
X			xsendline(lastsent = c);
X			break;
X		default:
X			if(Zctlesc && ! (c & 0140))
X			{
X				xsendline(ZDLE);
X				c ^= 0100;
X			}
X			xsendline(lastsent = c);
X		}
X	}
X}
X
X/* Decode two lower case hex digits into an 8 bit byte value */
Xzgethex()
X{
X	register int c;
X
X	c = zgeth1();
X	return(c);
X}
Xzgeth1()
X{
X	register int c,n;
X
X	if((c = noxrd7()) < 0)
X		return(c);
X	n = c - '0';
X	if(n > 9)
X		n -= ('a' - ':');
X	if(n & ~0xF)
X		return(ERROR);
X	if((c = noxrd7()) < 0)
X		return(c);
X	c -= '0';
X	if(c > 9)
X		c -= ('a' - ':');
X	if(c & ~0xF)
X		return(ERROR);
X	c += (n<<4);
X	return(c);
X}
X
X/*
X * Read a byte,checking for ZMODEM escape encoding
X *  including CAN*5 which represents a quick abort
X */
Xzdlread()
X{
X	register int c;
X
Xagain:
X	/* Quick check for non control characters */
X	if((c = readline(Rxtimeout)) & 0140)
X		return(c);
X	switch(c)
X	{
X	case ZDLE:
X		break;
X	case 023:
X	case 0223:
X	case 021:
X	case 0221:
X		goto again;
X	default:
X		if(Zctlesc && !(c & 0140))
X		{
X			goto again;
X		}
X		return(c);
X	}
Xagain2:
X	if((c = readline(Rxtimeout)) < 0)
X		return(c);
X	if(c == CAN && (c = readline(Rxtimeout)) < 0)
X		return(c);
X	if(c == CAN && (c = readline(Rxtimeout)) < 0)
X		return(c);
X	if(c == CAN && (c = readline(Rxtimeout)) < 0)
X		return(c);
X	switch(c)
X	{
X	case CAN:
X		return(GOTCAN);
X	case ZCRCE:
X	case ZCRCG:
X	case ZCRCQ:
X	case ZCRCW:
X		return(c | GOTOR);
X	case ZRUB0:
X		return(0177);
X	case ZRUB1:
X		return(0377);
X	case 023:
X	case 0223:
X	case 021:
X	case 0221:
X		goto again2;
X	default:
X		if(Zctlesc && ! (c & 0140))
X		{
X			goto again2;
X		}
X		if((c & 0140) ==  0100)
X			return(c ^ 0100);
X		break;
X	}
X	sprintf(s128,"Bad escape sequence %x",c);
X	report_str(s128,1);
X	return(ERROR);
X}
X
X/*
X * Read a character from the modem line with timeout.
X *  Eat parity,XON and XOFF characters.
X */
Xnoxrd7()
X{
X	register int c;
X
X	for(;;)
X	{
X		if((c = readline(Rxtimeout)) < 0)
X			return(c);
X		switch(c &= 0177)
X		{
X		case XON:
X		case XOFF:
X			continue;
X		default:
X			if(Zctlesc && !(c & 0140))
X				continue;
X		case '\r':
X		case '\n':
X		case ZDLE:
X			return(c);
X		}
X	}
X}
X
X/* Store long integer pos in Txhdr */
Xstohdr(pos)
Xlong pos;
X{
X	Txhdr[ZP0] = pos;
X	Txhdr[ZP1] = pos>>8;
X	Txhdr[ZP2] = pos>>16;
X	Txhdr[ZP3] = pos>>24;
X}
X
X/* Recover a long integer from a header */
Xlong
Xrclhdr(hdr)
Xregister char *hdr;
X{
X	register long l;
X
X	l = (hdr[ZP3] & 0377);
X	l = (l << 8) | (hdr[ZP2] & 0377);
X	l = (l << 8) | (hdr[ZP1] & 0377);
X	l = (l << 8) | (hdr[ZP0] & 0377);
X	return(l);
X}
X
X/* end of zmodem.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0521180190 xfer/zmodem.c &&
chmod 0644 xfer/zmodem.c ||
echo "restore of xfer/zmodem.c failed"
set `wc -c xfer/zmodem.c`;Wc_c=$1
if test "$Wc_c" != "16500"; then
	echo original size 16500, current size $Wc_c
fi
# ============= xfer/zmodem.h ==============
echo "x - extracting xfer/zmodem.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > xfer/zmodem.h &&
X/*+-------------------------------------------------------------------------
X	zmodem.h -- common include filefor tiprz/tipsz
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:05-21-1990-16:00-wht@tridom-adapt ecu xfer protocols for tipwht */
X
X#if defined(pyr)
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <sgtty.h>
X#define OS "BSD4.x"
X#if defined(LLITOUT)
X#include <strings.h>
X#endif
X#endif
X
X#if defined(M_UNIX)
X#define OS "UNIX"
X#undef M_XENIX
X#endif
X
X#if !defined(OS)
X#if !defined(M_XENIX)
X#define XENIX
X#endif
X#endif
X
X#if defined(M_XENIX) || defined(M_UNIX)
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <termio.h>
X#include <sys/ioctl.h>
X#include <string.h>
X#define MODE2OK
X#endif
X
X#if defined(pyr)
X#if defined(TIOCSBRK)
X#define CANBREAK
X#endif
X#endif
X#if defined(M_XENIX) || defined(M_UNIX)
X#define CANBREAK
X#endif
X
X#if !defined(READCHECK)
X#if defined(FIONREAD)
X#define READCHECK
X#endif
X#if defined(SV)
X#define READCHECK
X#endif
X#endif
X
X#define ACK 6
X#define CAN ('X'&037)
X#define CPMEOF 032
X#define ENQ 005
X#define EOT 4
X#define ERROR (-1)
X#define ERRORMAX 5
X#define FALSE 0
X#define NAK 025
X#define OK 0
X#define PATHLEN 257	/* ready for 4.2 bsd ? */
X#define RCDO (-3)
X#define SOH 1
X#define STX 2
X#define TIMEOUT (-2)
X#define TRUE 1
X#define UNIXFILE 0xF000	/* The S_IFMT file mask bit for stat */
X#define WANTCRC 0103	/* send C not NAK to get crc not checksum */
X
X#define WANTG 0107	/* Send G not NAK to get nonstop batch xmsn */
X#define WCEOT (-10)
X#define XOFF ('s'&037)
X#define XON ('q'&037)
X
X/*
X * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
X *  NOTE: First argument 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#define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF))
X
X
X#define ZPAD '*'	/* 052 Padding character begins frames */
X#define ZDLE 030	/* Ctrl-X Zmodem escape - `ala BISYNC DLE */
X#define ZDLEE (ZDLE^0100)	/* Escaped ZDLE as transmitted */
X#define ZBIN 'A'	/* Binary frame indicator */
X#define ZHEX 'B'	/* HEX frame indicator */
X#define ZBIN32 'C'	/* Binary frame with 32 bit FCS */
X
X/* Frame types (see array "frametypes" in zm.c) */
X#define ZRQINIT	0	/* Request receive init */
X#define ZRINIT	1	/* Receive init */
X#define ZSINIT 2	/* Send init sequence (optional) */
X#define ZACK 3		/* ACK to above */
X#define ZFILE 4		/* File name from sender */
X#define ZSKIP 5		/* To sender: skip this file */
X#define ZNAK 6		/* Last packet was garbled */
X#define ZABORT 7	/* Abort batch transfers */
X#define ZFIN 8		/* Finish session */
X#define ZRPOS 9		/* Resume data trans at this position */
X#define ZDATA 10	/* Data packet(s) follow */
X#define ZEOF 11		/* End of file */
X#define ZFERR 12	/* Fatal Read or Write error Detected */
X#define ZCRC 13		/* Request for file CRC and response */
X#define ZCHALLENGE 14	/* Receiver's Challenge */
X#define ZCOMPL 15	/* Request is complete */
X#define ZCAN 16		/* Other end canned session with CAN*5 */
X#define ZFREECNT 17	/* Request for free bytes on filesystem */
X#define ZCOMMAND 18	/* Command from sending program */
X#define ZSTDERR 19	/* Output to standard error, data follows */
X
X/* ZDLE sequences */
X#define ZCRCE 'h'	/* CRC next, frame ends, header packet follows */
X#define ZCRCG 'i'	/* CRC next, frame continues nonstop */
X#define ZCRCQ 'j'	/* CRC next, frame continues, ZACK expected */
X#define ZCRCW 'k'	/* CRC next, ZACK expected, end of frame */
X#define ZRUB0 'l'	/* Translate to rubout 0177 */
X#define ZRUB1 'm'	/* Translate to rubout 0377 */
X
X/* zdlread return values (internal) */
X/* -1 is general error, -2 is timeout */
X#define GOTOR 0400
X#define GOTCRCE (ZCRCE|GOTOR)	/* ZDLE-ZCRCE received */
X#define GOTCRCG (ZCRCG|GOTOR)	/* ZDLE-ZCRCG received */
X#define GOTCRCQ (ZCRCQ|GOTOR)	/* ZDLE-ZCRCQ received */
X#define GOTCRCW (ZCRCW|GOTOR)	/* ZDLE-ZCRCW received */
X#define GOTCAN	(GOTOR|030)	/* CAN*5 seen */
X
X/* Byte positions within header array */
X#define ZF0	3	/* First flags byte */
X#define ZF1	2
X#define ZF2	1
X#define ZF3	0
X#define ZP0	0	/* Low order 8 bits of position */
X#define ZP1	1
X#define ZP2	2
X#define ZP3	3	/* High order 8 bits of file position */
X
X/* Bit Masks for ZRINIT flags byte ZF0 */
X#define CANFDX	01	/* Rx can send and receive true FDX */
X#define CANOVIO	02	/* Rx can receive data during disk I/O */
X#define CANBRK	04	/* Rx can send a break signal */
X#define CANCRY	010	/* Receiver can decrypt */
X#define CANLZW	020	/* Receiver can uncompress */
X#define CANFC32	040	/* Receiver can use 32 bit Frame Check */
X#define ESCCTL 0100	/* Receiver expects ctl chars to be escaped */
X#define ESC8   0200	/* Receiver expects 8th bit to be escaped */
X
X/* Parameters for ZSINIT frame */
X#define ZATTNLEN 32	/* Max length of attention string */
X/* Bit Masks for ZSINIT flags byte ZF0 */
X#define TESCCTL 0100	/* Transmitter expects ctl chars to be escaped */
X#define TESC8   0200	/* Transmitter expects 8th bit to be escaped */
X
X/* Parameters for ZFILE frame */
X/* Conversion options one of these in ZF0 */
X#define ZCBIN	1	/* Binary transfer - inhibit conversion */
X#define ZCNL	2	/* Convert NL to local end of line convention */
X#define ZCRESUM	3	/* Resume interrupted file transfer */
X/* Management include options, one of these ored in ZF1 */
X#define ZMSKNOLOC	0200	/* Skip file if not present at rx */
X/* Management options, one of these ored in ZF1 */
X#define ZMMASK	037	/* Mask for the choices below */
X#define ZMNEWL	1	/* Transfer if source newer or longer */
X#define ZMCRC	2	/* Transfer if different file CRC or length */
X#define ZMAPND	3	/* Append contents to existing file (if any) */
X#define ZMCLOB	4	/* Replace existing file */
X#define ZMNEW	5	/* Transfer if source newer */
X	/* Number 5 is alive ... */
X#define ZMDIFF	6	/* Transfer if dates or lengths different */
X#define ZMPROT	7	/* Protect destination file */
X/* Transport options, one of these in ZF2 */
X#define ZTLZW	1	/* Lempel-Ziv compression */
X#define ZTCRYPT	2	/* Encryption */
X#define ZTRLE	3	/* Run Length encoding */
X/* Extended options for ZF3, bit encoded */
X#define ZXSPARS	64	/* Encoding for sparse file operations */
X
X/* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */
X#define ZCACK1	1	/* Acknowledge, then do command */
X
X/* FTOFFSET is offset for frametypes array in tipzm.c */
X#define FTOFFSET 3
X
Xlong rclhdr();
X
X#include "zlint.h"
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0521180190 xfer/zmodem.h &&
chmod 0644 xfer/zmodem.h ||
echo "restore of xfer/zmodem.h failed"
set `wc -c xfer/zmodem.h`;Wc_c=$1
if test "$Wc_c" != "6734"; then
	echo original size 6734, current size $Wc_c
fi
exit 0

------------------------------------------------------------------
Warren Tucker, Tridom Corporation      ...!gatech!emory!tridom!wht
home address:                                 ...!gatech!n4hgf!wht