v16i034: ECU async comm package rev 3.0, Part10/35

Warren Tucker wht at n4hgf.uucp
Sun Jan 6 16:20:36 AEST 1991


Submitted-by: wht at n4hgf.uucp (Warren Tucker)
Posting-number: Volume 16, Issue 34
Archive-name: ecu3/part10

---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is part 10 of ecu3
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= ecuxfer.c ==============
echo 'x - extracting ecuxfer.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecuxfer.c' &&
X/*+-------------------------------------------------------------------------
X	ecuxfer.c - file transfer
X	wht at n4hgf.Mt-Park.GA.US
X
X   000000000011111111112222222222333333333344444444445555555555666666666actually
X   012345678901234567890123456789012345678901234567890123456789012345678wider
X00:.--[ Send ZMODEM/CRC32 ]--------------------------------------------.
X01:|                                                                   |
X02:|  File? to send:                                                   |
X03:|  ................................................................ |
X04:|                                                                   |
X05:|  Binary: Y (no CR/LF translation)                                 |
X06:|  Overwrite destination files: Y                                   |
X07:|  Send full pathnames: N                                           |
X08:|  Transfer only newer files: N (if receiver supports)              |
X09:|                                                                   |
X-1:| TAB:next  ^B:prev  END:perform transfer  ESC:abort                |
X-0:`-------------------------------------------------------------------'
X
X  Defined functions:
X	file_xfer_done_bell()
X	file_xfer_start()
X	receive_files_from_remote(argc,argv)
X	report_send_status()
X	send_files_to_remote(argc,argv)
X	xfer_title_fragment()
X	xfrw_bot_msg(msg)
X	xfrw_display_cmd_line()
X	xfrw_get_single(nondelim_list)
X	xfrws_display_allvars()
X	xfrws_display_binary()
X	xfrws_display_literals()
X	xfrws_display_name()
X	xfrws_display_xfernew()
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-14-1990-20:40-wht at n4hgf-ecu3.00-flush old edit history */
X
X#include <curses.h>
X
X#define STDIO_H_INCLUDED
X#define OMIT_TERMIO_REFERENCES
X#include "ecu.h"
X#include "ecukey.h"
X#include "ecuxkey.h"
X#include "ecuerror.h"
X#include "pc_scr.h"
X
X#define END		XFend
X
X/* -- protocol xfer types -- */
X#define ECUSZ_X			1
X#define ECUSZ_Y			2
X#define ECUSZ_Z			3
X#define ECUSEA			4
X#define CKERMIT			5
X#define ECURZ_X			7
X#define ECURZ_Y			8
X#define ECURZ_Z			9
X
X/* --------------------- send window ----------------------------------- */
X/*      SNDW_LINES			calculated (xfrw_lines) */
X#define SNDW_COLS			79
X#define SNDW_TLY			2
X/*      SNDW_TLX			calculated (xfrw_tlx) */
X
X#define SNDW_FILE_LY		2
X#define SNDW_FILE_LX		3
X#define SNDW_FILE_Y			3
X#define SNDW_FILE_X			3
X#define SNDW_FILE_LEN		(SNDW_COLS - SNDW_FILE_X - 2)
X
X#define SNDW_BIN_Y			5
X#define SNDW_BIN_LX			3
X#define SNDW_BIN_X			11
X#define SNDW_BIN_LX2		13
X
X#define SNDW_OVERW_Y		6
X#define SNDW_OVERW_LX		3
X#define SNDW_OVERW_X		32
X
X#define SNDW_SNDFUL_Y		7
X#define SNDW_SNDFUL_LX		3
X#define SNDW_SNDFUL_X		24
X
X#define SNDW_XFRNEW_Y		8
X#define SNDW_XFRNEW_LX		3
X#define SNDW_XFRNEW_X		30
X
X#define SNDW_ZWINDW_Y		9
X#define SNDW_ZWINDW_LX		3
X#define SNDW_ZWINDW_X		16
X#define SNDW_ZWINDW_LEN		6
X
Xextern char curr_dir[];		/* current working directory */
Xextern int protocol_log_packets;
Xextern int last_child_wait_status;
X
Xlong file_xfer_start_time;	/* time() value at beginning of file xfer */
Xchar xfertype = -1;		/* file xfer type */
XWINDOW *xfrw;
Xchar xfrw_cols;
Xchar xfrw_lines;
Xchar xfrw_tlx;
X
Xchar p_binary;		/* xfer options -- not all apply to all protocols */
Xchar p_sendfull;
Xchar p_overwrite;
Xchar p_xfernew;
Xchar p_filelist[80];
Xint zwindw_size;
X
X/*+-------------------------------------------------------------------------
X	file_xfer_start()
X--------------------------------------------------------------------------*/
Xvoid
Xfile_xfer_start()
X{
X	time(&file_xfer_start_time);
X}	/* end of file_xfer_start */
X
X/*+-------------------------------------------------------------------------
X	file_xfer_done_bell()
X--------------------------------------------------------------------------*/
Xvoid
Xfile_xfer_done_bell()
X{
Xlong time();
Xlong xfer_time = time((long *)0) - file_xfer_start_time;
Xint xbell_count = 0;
Xextern int want_bell_notify;
X
X	sleep(1);
X	xbell_count = 1;
X	if(xfer_time >= 3600L)			/* >= one hour */
X		xbell_count = 3;
X	else if(xfer_time >= 1800L)		/* >= 1/2 hour */
X		xbell_count = 2;
X
X	if(want_bell_notify)
X		bell_notify(XBELL_ATTENTION);
X
X	xbell(XBELL_DONE,xbell_count);
X}	/* end of file_xfer_done_bell */
X
X/*+-------------------------------------------------------------------------
X	xfrw_bot_msg(msg)
X--------------------------------------------------------------------------*/
Xvoid
Xxfrw_bot_msg(msg)
Xchar *msg;
X{
Xregister itmp;
Xregister itmp2;
Xstatic last_msglen = 0;
Xchar msg2[80];
X
X	wmove(xfrw,xfrw_lines - 1,3);
X
X	if((itmp = strlen(msg)) == 0)
X	{
X		itmp2 = last_msglen + 2;
X		for(itmp = 0; itmp < itmp2; itmp++)
X			waddch(xfrw,(unsigned)sHR);
X		last_msglen = 0;
X	}
X	else
X	{
X		waddch(xfrw,' ');
X		if(itmp > xfrw_cols - 3 - 2)
X		{
X			strncpy(msg2,msg,xfrw_cols - 3 - 2);
X			msg2[xfrw_cols - 3 - 2 + 1] = 0;
X			waddstr(xfrw,msg2);
X			itmp = strlen(msg2);
X		}
X		else
X		{
X			waddstr(xfrw,msg);
X			itmp = strlen(msg);
X		}
X		waddch(xfrw,' ');
X		if((itmp2 = last_msglen - itmp) > 0)
X		{
X			while(itmp2--)
X				waddch(xfrw,(unsigned)sHR);
X		}
X		last_msglen = itmp;		/* remember last message length */
X	}
X	wrefresh(xfrw);
X}	/* end of xfrw_bot_msg */
X
X/*+-------------------------------------------------------------------------
X	xfrw_get_single(nondelim_list)
Xassumes cursor is already positioned
X--------------------------------------------------------------------------*/
Xint
Xxfrw_get_single(nondelim_list)
Xregister char *nondelim_list;
X{
Xregister uint itmp;
Xstatic char xfrw_nondelim_list[] =
X{
X	CR,NL,CTL_B,TAB,ESC,CTL_L,CTL_R,END
X};
X
X	itmp = winget_single(xfrw,nondelim_list,xfrw_nondelim_list);
X	if( (itmp & 0xFF) == 0x0D)
X		itmp = NL | 0x1000;
X	return(itmp);
X}	/* end of xfrw_get_single */
X
X/*+-------------------------------------------------------------------------
X	xfer_title_fragment(xfertype)
X--------------------------------------------------------------------------*/
Xchar *
Xxfer_title_fragment()
X{
Xregister char *cptr = "UNKNOWN";
X
X	switch(xfertype)
X	{
X		case ECURZ_X:
X		case ECUSZ_X: cptr = "XMODEM/CRC"; break;
X		case ECURZ_Y:
X		case ECUSZ_Y: cptr = "YMODEM/CRC"; break;
X		case ECURZ_Z:
X		case ECUSZ_Z: cptr = "ZMODEM/CRC32"; break;
X		case ECUSEA:  cptr = "SEAlink"; break;
X		case CKERMIT: cptr = "KERMIT/CRC" ;break;
X	}
X	return(cptr);
X}	/* end of xfer_title_fragment */
X
X/*+-------------------------------------------------------------------------
X	xfrw_display_cmd_line()
X--------------------------------------------------------------------------*/
Xvoid
Xxfrw_display_cmd_line()
X{
Xregister itmp;
Xchar *cmd_string = "TAB:next  ^B:prev  END:perform transfer  ESC:abort"; 
Xregister left_spaces = ((xfrw_cols - 2) - strlen(cmd_string)) / 2;
Xint x;
Xint y;
X
X	wmove(xfrw,xfrw_lines - 2,1);
X	wstandout(xfrw);
X	for(itmp = 0; itmp < left_spaces; itmp++)
X		waddch(xfrw,' ');
X	waddstr(xfrw,cmd_string);
X	getyx(xfrw,y,x);
X	while(++x < xfrw_cols)
X		waddch(xfrw,' '); 
X	wstandend(xfrw);
X
X}	/* end of xfrw_display_cmd_line */
X
X/*+-------------------------------------------------------------------------
X	xfrws_display_literals()
X--------------------------------------------------------------------------*/
Xvoid
Xxfrws_display_literals()
X{
X	wmove(xfrw,SNDW_FILE_LY,SNDW_FILE_LX);
X	if(xfertype == ECUSZ_X)
X		waddstr(xfrw,"File");
X	else
X		waddstr(xfrw,"File(s)");
X	waddstr(xfrw," to send:");
X
X	switch(xfertype)
X	{
X		case ECUSZ_Z:
X			wmove(xfrw,SNDW_XFRNEW_Y,SNDW_XFRNEW_LX);
X			waddstr(xfrw,"Transfer only newer files:");
X			wmove(xfrw,SNDW_SNDFUL_Y,SNDW_SNDFUL_LX);
X			waddstr(xfrw,"Send full pathames:");
X			wmove(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_LX);
X			waddstr(xfrw,"Window size:");
X		case CKERMIT:
X			wmove(xfrw,SNDW_OVERW_Y,SNDW_OVERW_LX);
X			waddstr(xfrw,"Overwrite destination files:");
X		case ECUSZ_Y:
X		case ECUSZ_X:
X			wmove(xfrw,SNDW_BIN_Y,SNDW_BIN_LX);
X			waddstr(xfrw,"Binary:");
X	}
X}	/* end of xfrws_display_literals */
X
X/*+-------------------------------------------------------------------------
X	xfrws_display_name()
X--------------------------------------------------------------------------*/
Xvoid
Xxfrws_display_name()
X{
X	clear_area(xfrw,SNDW_FILE_Y,SNDW_FILE_X,SNDW_FILE_LEN);
X	waddstr(xfrw,p_filelist);
X
X}	/* end of xfrws_display_name */
X
X/*+-------------------------------------------------------------------------
X	xfrws_display_binary()
X--------------------------------------------------------------------------*/
Xvoid
Xxfrws_display_binary()
X{
X	wmove(xfrw,SNDW_BIN_Y,SNDW_BIN_X);
X	waddch(xfrw,(p_binary) ? 'Y' : 'N');
X	if(p_binary)
X		waddstr(xfrw," (no NL-CR/LF translation)     ");
X	else
X		waddstr(xfrw," (NL-CR/LF translation enabled)");
X
X}	/* end of xfrws_display_binary */
X
X/*+-------------------------------------------------------------------------
X	xfrws_display_xfernew()
X--------------------------------------------------------------------------*/
Xvoid
Xxfrws_display_xfernew()
X{
X	wmove(xfrw,SNDW_XFRNEW_Y,SNDW_XFRNEW_X);
X	waddch(xfrw,(p_xfernew) ? 'Y' : 'N');
X	if(p_xfernew)
X		waddstr(xfrw," (if receiver supports)");
X	else
X		waddstr(xfrw,"                       ");
X}	/* end of xfrws_display_xfernew */
X
X/*+-------------------------------------------------------------------------
X	xfrws_display_allvars()
X--------------------------------------------------------------------------*/
Xvoid
Xxfrws_display_allvars()
X{
Xchar s16[16];
X
X	xfrws_display_name();
X	switch(xfertype)
X	{
X		case ECUSZ_Z:
X			xfrws_display_xfernew();
X			wmove(xfrw,SNDW_SNDFUL_Y,SNDW_SNDFUL_X);
X			waddch(xfrw,(p_sendfull) ? 'Y' : 'N');
X			wmove(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_X);
X			sprintf(s16,"%d",zwindw_size);
X			waddstr(xfrw,s16);
X		case CKERMIT:
X			wmove(xfrw,SNDW_OVERW_Y,SNDW_OVERW_X);
X			waddch(xfrw,(p_overwrite) ? 'Y' : 'N');
X		case ECUSZ_Y:
X		case ECUSZ_X:
X			xfrws_display_binary();
X	}
X}	/* end of xfrws_display_allvars */
X
X/*+-------------------------------------------------------------------------
X	report_send_status() - report file transmission result
Xreturns proc-type erc
Xfor "ecu knowledgeable" protocols only
X--------------------------------------------------------------------------*/
Xreport_send_status()
X{
Xint erc = 0;
Xunsigned int utmp;
Xulong colors_at_entry = colors_current;
Xchar *signal_name_text();
X
X	utmp = last_child_wait_status;
X	if((utmp & 0xFF) == 0)	/* exit() called */
X	{
X		utmp >>= 8;
X		if(utmp == 0)
X		{
X			setcolor(colors_notify);
X			pputs("[transfer successful]");
X			erc = 0;
X		}
X		else if(utmp == 255)
X		{
X			setcolor(colors_error);
X			pputs("[ecu error: transfer program usage error]");
X			erc = eFATAL_ALREADY;
X		}
X		else if(utmp == 254)
X		{
X			setcolor(colors_error);
X			pputs(
X			"[protocol failure: bad line conditions or remote not ready]");
X			erc = eFATAL_ALREADY;
X		}
X		else if(utmp == 253)
X		{
X			setcolor(colors_alert);
X			pputs("[no requested files exist]");
X			erc = eFATAL_ALREADY;
X		}
X		else if(utmp < 128)
X		{
X			setcolor(colors_alert);
X			if(utmp == 127)
X				pputs("[127 or more files skipped]");
X			else
X				pprintf("[%u files rejected]",utmp);
X			erc = 0;
X		}
X		else
X		{
X			setcolor(colors_alert);
X			pprintf("[transfer aborted by %s]",
X				signal_name_text(utmp & 0x7F));
X			erc = eProcAttn_Interrupt;
X		}
X	}
X	else
X	{
X		tcap_curbotleft();
X		setcolor(colors_error);
X		pprintf("[transfer killed by %s]",
X			signal_name_text(utmp & 0x7F));
X		erc = eProcAttn_Interrupt;
X	}
X
X	setcolor(colors_at_entry);
X	pputs("\n");
X	return(erc);
X
X}	/* end of report_send_status */
X
X/*+-----------------------------------------------------------------------
X	send_files_to_remote(argc,argv)
X------------------------------------------------------------------------*/
Xvoid
Xsend_files_to_remote(argc,argv)
Xint argc;
Xchar **argv;
X{
Xregister itmp;
Xregister input_state = 0;
Xregister input_state_mod;
Xint input_done;
Xint used_argv = 0;
Xchar execcmd[256];
Xchar s80[80];
Xchar flst[80];
Xuchar delim;	/* important to be unsigned to avoid sign extension */
XWINDOW *window_create();
Xchar bottom_label[64];
X
X	p_binary = 1;		/* assume p_binary xfer */
X	p_sendfull = 0;		/* assume no full pathnames */
X	p_overwrite = 1;	/* assume overwrite */
X	p_xfernew = 0;		/* assume send only newer */
X	p_filelist[0] = 0;	/* no filenames yet */
X#ifdef WHT
X	zwindw_size = 16384;	/* my preference */
X#else
X	zwindw_size = 0;	/* assume full streaming sz */
X#endif
X
X	switch(to_lower(*(argv[0] + 1)))
X	{
X		case 'x': xfertype = ECUSZ_X; break;
X		case 'y': xfertype = ECUSZ_Y; break;
X		case 'z': xfertype = ECUSZ_Z; break;
X		case 'k': xfertype = CKERMIT; break;
X		case 's': xfertype = ECUSEA; break;
X		default: ff(se,"send command invalid\n");
X			return;
X	}
X
X	kill_rcvr_process(SIGUSR1);	/* SIGUSR1 gives chance to close log file */
X
X/* define and open window */
X	input_state_mod = 0;
X	xfrw_tlx = (COLS - SNDW_COLS) / 2;
X	xfrw_cols = SNDW_COLS;
X	switch(xfertype)
X	{
X		case ECUSEA:
X			input_state_mod = 1;
X			xfrw_lines = 7;
X			break;
X		case ECUSZ_X:
X			input_state_mod = 2;
X			xfrw_lines = 9;
X			break;
X		case ECUSZ_Z:
X			input_state_mod = 6;
X		case CKERMIT:
X			if(!input_state_mod)
X				input_state_mod = 3;
X		case ECUSZ_Y:
X			if(!input_state_mod)
X				input_state_mod = 2;
X			xfrw_lines = input_state_mod + 7;
X			break;
X		default:
X			hangup(9999);
X	}
X
X	windows_start();
X	sprintf(execcmd,"Send %s",xfer_title_fragment());
X	xfrw = window_create(execcmd,-3,SNDW_TLY,(int)xfrw_tlx,
X			(int)xfrw_lines,(int)xfrw_cols);
X	xfrw_display_cmd_line();
X	xfrws_display_literals();
X	xfrws_display_allvars();
X	wmove(xfrw,0,27);
X	waddstr(xfrw," dir: ");
X	if(strlen(curr_dir) > (xfrw_cols - 32))
X	{
X		strncpy(s80,curr_dir,xfrw_cols - 32);
X		s80[xfrw_cols - 32] = 0;
X		waddstr(xfrw,s80);
X	}
X	else
X		waddstr(xfrw,curr_dir);
X	waddch(xfrw,' ');
X	flst[0] = 0;
X
XREENTER_INPUT_LOOP:
X	input_done = 0;
X	while(!input_done)
X	{
X		switch(input_state)
X		{
X			case 0:		/* filename(s) */
X				xfrw_bot_msg("enter file(s) to send");
XCASE_0_AGAIN:
X				if(used_argv || (argc == 1))
X				{
X					itmp = wingets(xfrw,SNDW_FILE_Y,SNDW_FILE_X,flst,
X						SNDW_FILE_LEN + 1,&delim,(p_filelist[0] != 0));
X				}
X				else
X				{
X					used_argv = 1;
X					flst[0] = 0;
X					for(itmp = 1; itmp < argc; itmp++)
X					{
X						if((strlen(flst) + strlen(argv[itmp]) + 1) > sizeof(flst))
X						{
X							xfrw_bot_msg("arguments too long ... reenter list");
X							ring_bell();
X							goto CASE_0_AGAIN;
X						}
X						strcat(flst,argv[itmp]);
X						if(itmp != (argc - 1))
X							strcat(flst," ");
X					}
X					delim = NL;
X				}
X				if(delim == ESC)
X					break;
X				if(strlen(flst))
X				{
X					strcpy(p_filelist,flst);
X					xfrws_display_name();
X					if(find_shell_chars(p_filelist))
X					{
X					char *expcmd;
X
X						if(expand_cmd_with_wildlist(p_filelist,&expcmd))
X						{
X							xfrw_bot_msg(expcmd);
X							ring_bell();
X							goto CASE_0_AGAIN;
X						}
X						expcmd[SNDW_FILE_LEN - 1] = 0;
X						clear_area(xfrw,SNDW_FILE_Y,SNDW_FILE_X,SNDW_FILE_LEN);
X						waddstr(xfrw,expcmd);
X						free(expcmd);
X					}
X				}
X				break;
X
X			case 1:		/* binary */
X				xfrw_bot_msg("Y: no conversion, N: NLs converted to CR/LF");
X				wmove(xfrw,SNDW_BIN_Y,SNDW_BIN_X);
X				wrefresh(xfrw);
X				delim = NL;
X				switch(itmp = xfrw_get_single("ny"))
X				{
X					case 0:
X					case 1:
X						p_binary = itmp;
X						xfrws_display_binary();
X						break;
X					default:
X						delim = itmp & 0xFF;
X						break;
X				}
X				break;
X
X			case 2:		/* overwrite */
X				xfrw_bot_msg("Y: overwrite, N: protect destination files");
X				wmove(xfrw,SNDW_OVERW_Y,SNDW_OVERW_X);
X				wrefresh(xfrw);
X				delim = NL;
X				switch(itmp = xfrw_get_single("ny"))
X				{
X					case 0:
X					case 1:
X						p_overwrite = itmp;
X						break;
X					default:
X						delim = itmp & 0xFF;
X						break;
X				}
X				break;
X
X			case 3:		/* send full pathnames */
X				xfrw_bot_msg(
X					"Y: full pathnames, N: strip directory portion from names");
X				wmove(xfrw,SNDW_SNDFUL_Y,SNDW_SNDFUL_X);
X				wrefresh(xfrw);
X				delim = NL;
X				switch(itmp = xfrw_get_single("ny"))
X				{
X					case 0:
X					case 1:
X						p_sendfull = itmp;
X						break;
X					default:
X						delim = itmp & 0xFF;
X						break;
X				}
X				break;
X
X			case 4:		/* src newer than dest */
X
X				xfrw_bot_msg(
X				"Y: send only if source newer than destination, N send all");
X				wmove(xfrw,SNDW_XFRNEW_Y,SNDW_XFRNEW_X);
X				wrefresh(xfrw);
X				delim = NL;
X				switch(itmp = xfrw_get_single("ny"))
X				{
X					case 0:
X					case 1:
X						p_xfernew = itmp;
X						xfrws_display_xfernew();
X						break;
X					default:
X						delim = itmp & 0xFF;
X						break;
X				}
X				break;
X
X			case 5:		/* window size */
X
X				xfrw_bot_msg(
X				"window size (max bytes sent before ACK required) 0 = stream");
XCASE_5_AGAIN:
X				sprintf(s80,"%d",zwindw_size);
X				clear_area(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_X,
X					SNDW_ZWINDW_LEN + 10);
X				itmp = wingets(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_X,s80,
X					SNDW_ZWINDW_LEN + 1,&delim,1);
X				if((delim == ESC))
X					break;
X				if( ((itmp = atoi(s80)) != 0) &&
X					((itmp < 256) || (itmp > 65536)))
X				{
X					ring_bell();
X					xfrw_bot_msg(
X						"window size must be 0 or 256 <= w <= 65536");
X					goto CASE_5_AGAIN;
X				}
X				zwindw_size = (itmp / 64) * 64;
X				sprintf(s80,"%d%s",zwindw_size,
X					(zwindw_size != itmp) ? " adjusted" : "" );
X				clear_area(xfrw,SNDW_ZWINDW_Y,SNDW_ZWINDW_X,
X					SNDW_ZWINDW_LEN + 10);
X				waddstr(xfrw,s80);
X				break;
X		}
X
X		switch(delim)
X		{
X			case CTL_B:
X				input_state = (input_state) ? input_state - 1 
X				                            : input_state_mod - 1;
X				break;
X
X			case TAB:
X			case NL:
X				input_state++;
X				input_state %= input_state_mod;
X				break;
X
X			case CTL_L:
X			case CTL_R:
X				tcap_clear_screen();
X				touchwin(stdscr);
X				wrefresh(stdscr);
X				touchwin(xfrw);
X				wrefresh(xfrw);
X				break;
X
X			case ESC:
X				xfrw_bot_msg("transfer abandoned");
X				input_done = 1;
X				break;
X
X			case END:
X				input_done = 1;
X				break;
X		}
X	}
X
X	if(delim == END)
X	{
X		if(!p_filelist[0])
X		{
X			ring_bell();
X			xfrw_bot_msg("No filenames entered!  Press <ENTER>");
X			(void)ttygetc(1);
X			input_state = 0;
X			goto REENTER_INPUT_LOOP;
X		}
X		xfrw_bot_msg("starting file transfer");
X	}
X
X	windows_end(xfrw);
X	tcap_cursor(SNDW_TLY + xfrw_lines + 1,0);
X
X	if(delim == ESC)
X	{
X		start_rcvr_process(1);
X		return;
X	}
X
X	bottom_label[0] = 0;
X	if(shm->Llogical[0])
X		sprintf(bottom_label,"-C \"'Connected to %s'\" ",shm->Llogical);
X
X/* we are going to do a transfer! */
X	switch(xfertype)
X	{
X		case ECUSZ_X:
X			sprintf(execcmd,"ecusz -X -. %d ",shm->Liofd);
X			strcat(execcmd,bottom_label);
X			if(protocol_log_packets)
X				strcat(execcmd,"-, ");
X			if(p_binary)
X				strcat(execcmd,"-b ");
X			else
X				strcat(execcmd,"-a ");
X			strcat(execcmd,p_filelist);
X			break;
X		case ECUSZ_Y:
X			sprintf(execcmd,"ecusz -Y -. %d -k ",shm->Liofd);
X			strcat(execcmd,bottom_label);
X			if(protocol_log_packets)
X				strcat(execcmd,"-, ");
X			if(p_binary)
X				strcat(execcmd,"-b ");
X			else
X				strcat(execcmd,"-a ");
X			strcat(execcmd,p_filelist);
X			break;
X
X		case ECUSZ_Z:
X			sprintf(execcmd,"ecusz -Z -. %d ",shm->Liofd);
X			strcat(execcmd,bottom_label);
X			if(zwindw_size)
X				sprintf(&execcmd[strlen(execcmd)]," -w %d ",zwindw_size);
X			if(protocol_log_packets)
X				strcat(execcmd,"-, ");
X			if(p_overwrite)
X				strcat(execcmd,"-y ");
X			else
X				strcat(execcmd,"-p ");
X			if(p_binary)
X				strcat(execcmd,"-b ");
X			else
X				strcat(execcmd,"-a ");
X			if(p_xfernew)
X				strcat(execcmd,"-n ");	/* overrides -y/-p choice earlier */
X			if(p_sendfull)
X				strcat(execcmd,"-f ");
X			strcat(execcmd,p_filelist);
X			break;
X
X		case ECUSEA:
X			sprintf(execcmd,"ecusea -. %d -/ %s -s ",shm->Liofd,curr_dir);
X			if(protocol_log_packets)
X				strcat(execcmd,"-, ");
X			strcat(execcmd,p_filelist);
X			break;
X
X		case CKERMIT:
X			sprintf(execcmd,"ckermit -l %d -b %u -p %c%s%s -s %s",
X					shm->Liofd,
X					shm->Lbaud,
X					(shm->Lparity) ? shm->Lparity : 'n',
X					(p_binary) ? " -i" : "",
X					(p_overwrite) ? "" : " -w",
X					p_filelist);
X			break;
X
X	}
X
X	file_xfer_start();
X
X	if(find_shell_chars(execcmd))
X	{
X	char *expcmd;
X
X		if(expand_cmd_with_wildlist(execcmd,&expcmd))
X		{
X			ff(se,"No files match\r\n");
X			return;
X		}
X		exec_cmd(expcmd);
X		free(expcmd);
X	}
X	else
X	{
X		exec_cmd(execcmd);
X		ff(se,"wierd 2\r\n");
X	}
X
X	lreset_ksr();
X
X	switch(xfertype)
X	{
X		case ECUSEA:
X		case ECUSZ_X:
X		case ECUSZ_Y:
X		case ECUSZ_Z:
X			xfertype = 1;		/* was ecusz */
X			break;
X		default:
X			xfertype = 0;
X			break;
X	}
X
X	if(xfertype)	/* ecu knowledgable */
X		report_send_status();
X	else
X	{
X		tcap_stand_out();
X		ff(se," transfer status %04x ",last_child_wait_status);
X		tcap_stand_end();
X		ff(se,"\r\n");
X	}
X
X	ff(se,"\r\n");
X
X	file_xfer_done_bell();
X	start_rcvr_process(1);
X}	/* end of send_files_to_remote */
X
X/*+-------------------------------------------------------------------------
X	receive_files_from_remote(argc,argv)
X--------------------------------------------------------------------------*/
Xvoid
Xreceive_files_from_remote(argc,argv)
Xint argc;
Xchar **argv;
X{
Xregister itmp;
Xchar execcmd[256];
Xint xfertype;
Xchar bottom_label[64];
X
X	sprintf(bottom_label,"-C 'Connected to %s' ",
X		(shm->Llogical[0]) ? shm->Llogical : "?");
X
X	switch(to_lower(*(argv[0] + 1)))
X	{
X		case 'k': xfertype = CKERMIT; break;
X		case 's': xfertype = ECUSEA; break;
X		case 'x': xfertype = ECURZ_X; break;
X		case 'y': xfertype = ECURZ_Y; break;
X		case 'z': xfertype = ECURZ_Z; break;
X		default: ff(se,"receive command invalid\n");
X			return;
X	}
X
X	if(xfertype == ECURZ_X)
X	{
X	char xfilenam[128];
X		kill_rcvr_process(SIGUSR1);
X		sprintf(execcmd,"ecurz -X -. %d -c ",shm->Liofd);
X		strcat(execcmd,bottom_label);
X		if(protocol_log_packets)
X			strcat(execcmd,"-, ");
X
X		ff(se,"    File name to receive via XMODEM/CRC:  ");
X		ttygets(xfilenam,sizeof(xfilenam),1);
X		if( (xfilenam[0] == ESC) || !strlen(xfilenam))
X		{
X			ff(se,"transfer abandoned\r\n");
X			start_rcvr_process(1);
X			return;
X		}
X		/* get xmodem ascii or binary */
X		ff(se,"Translate CR/LF to NL (y,n)? ");
X		switch(itmp = to_lower(ttygetc(0)))
X		{
X			case 'y': strcat(execcmd,"-a "); break;
X			case 'n': strcat(execcmd,"-b "); break;
X			default:
X				ff(se,"transfer abandoned\r\n");
X				start_rcvr_process(1);
X				return;
X		}
X		ff(se,"%s\r\n",(itmp == 'y') ? "yes" : "no");
X		strcat(execcmd,xfilenam);
X		file_xfer_start();
X		exec_cmd(execcmd);
X	}
X	else if(xfertype == ECURZ_Y)
X	{
X		ff(se,"\r\n");
X		kill_rcvr_process(SIGUSR1);
X		sprintf(execcmd,"ecurz -Y -. %d -y ",shm->Liofd);
X		strcat(execcmd,bottom_label);
X		if(protocol_log_packets)
X			strcat(execcmd,"-, ");
X		file_xfer_start();
X		exec_cmd(execcmd);
X	}
X	else if(xfertype == ECURZ_Z)
X	{
X		ff(se,"\r\n");
X		kill_rcvr_process(SIGUSR1);
X		sprintf(execcmd,"ecurz -Z -. %d ",shm->Liofd);
X		if(protocol_log_packets)
X			strcat(execcmd,"-, ");
X		strcat(execcmd,bottom_label);
X		file_xfer_start();
X		exec_cmd(execcmd);
X	}
X	else if(xfertype == CKERMIT)
X	{
X		kill_rcvr_process(SIGUSR1);
X		sprintf(execcmd,"ckermit -r -e 512 -l %d -b %d -p %c",
X			shm->Liofd,shm->Lbaud,(shm->Lparity) ? shm->Lparity : 'n');
X		ff(se,"    Translate CR/LF to NL (y,n)? ");
X		switch(itmp = to_lower(ttygetc(0)))
X		{
X			case 'y': strcat(execcmd," -i"); break;
X			case 'n': break;
X			default:
X				ff(se,"transfer abandoned\r\n");
X				start_rcvr_process(1);
X				return;
X		}
X		ff(se,"%s\r\n",(itmp == 'a') ? "yes" : "no");
X		file_xfer_start();
X		exec_cmd(execcmd);
X	}
X	else if(xfertype == ECUSEA)
X	{
X		kill_rcvr_process(SIGUSR1);
X		sprintf(execcmd,"ecusea -r -. %d -/ %s",shm->Liofd,curr_dir);
X		if(protocol_log_packets)
X			strcat(execcmd," -,");
X		file_xfer_start();
X		exec_cmd(execcmd);
X	}
X	lreset_ksr();
X	file_xfer_done_bell();
X	nap(20L);
X	start_rcvr_process(1);
X}	/* end of receive_files_from_remote */
X/* end of ecuxfer.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 1224223790 'ecuxfer.c' &&
chmod 0644 ecuxfer.c ||
echo 'restore of ecuxfer.c failed'
Wc_c="`wc -c < 'ecuxfer.c'`"
test 23483 -eq "$Wc_c" ||
	echo 'ecuxfer.c: original size 23483, current size' "$Wc_c"
# ============= esdutil.c ==============
echo 'x - extracting esdutil.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'esdutil.c' &&
X/*+----------------------------------------------------------------
X	esdutil.c - ecu extended string descriptor manipulation
X	wht at n4hgf.Mt-Park.GA.US
X
X  Defined functions:
X	append_zstr_to_esd(param,zstr)
X	end_of_cmd(param)
X	esdstrindex(esd1,esd2,index1_flag,index2_flag)
X	fgetesd(param,fileptr)
X	fputesd(param,fileptr,index_flag,nl_flag)
X	free_esd(tesd)
X	get_alpha_zstr(param,strbuf,strbuf_maxcb)
X	get_alphanum_zstr(param,strbuf,strbuf_maxcb)
X	get_cmd_char(param,pchar)
X	get_numeric_value(param,value)
X	get_numeric_zstr(param,strbuf,strbuf_maxcb)
X	get_switches(param,switches,switches_max)
X	get_word_zstr(param,strbuf,strbuf_maxcb)
X	init_esd(tesd,cptr,maxcb)
X	keyword_lookup(ktable,param)
X	make_esd(maxcb)
X	null_terminate_esd(tesd)
X	realloc_esd(tesd,maxcb)
X	show_esd(tesd,title)
X	skip_cmd_break(param)
X	skip_cmd_char(param,skipchar)
X	skip_colon(param)
X	skip_comma(param)
X	skip_paren(param,fLeft)
X	strindex(str1,str2)
X	strip_trailing_spaces_esd(ztext)
X	zero_esd(tesd)
X
XThis is old code; give me a break
X-----------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-14-1990-20:40-wht at n4hgf-ecu3.00-flush old edit history */
X
X#include <ctype.h>
X#include "ecu.h"
X#include "ecuerror.h"
X#include "esd.h"
X
Xextern int errno;
X
X/*+-------------------------------------------------------------------------
X    null_terminate_esd(&esd)
X    puts null at 'cb' position of string (standard esd always
X    has one more byte in buffer than maxcb says)
X--------------------------------------------------------------------------*/
Xvoid
Xnull_terminate_esd(tesd)
Xregister ESD *tesd;
X{
X	tesd->pb[tesd->cb] = 0;
X}   /* end of null_terminate_esd */
X
X/*+-----------------------------------------------------------------------
X	zero_esd(tesd)  zero an esd 
X------------------------------------------------------------------------*/
Xvoid
Xzero_esd(tesd)
Xregister ESD *tesd;
X{
X	tesd->cb = 0;				/* current count == 0 */
X	tesd->index = 0;			/* parse index to first position */
X	tesd->old_index = 0;		/* parse index to first position */
X	*tesd->pb = 0;				/* start with null terminated string */
X
X}	/* end of zero_esd */
X
X/*+-----------------------------------------------------------------------
X	init_esd(tesd,cptr,maxcb)  init an esd 
X------------------------------------------------------------------------*/
Xvoid
Xinit_esd(tesd,cptr,maxcb)
Xregister ESD *tesd;
Xchar *cptr;
Xregister maxcb;
X{
X	tesd->pb = cptr;			/* pointer to string */
X	tesd->maxcb = maxcb;		/* max characters in buffer */
X	zero_esd(tesd);
X
X}	/* end of init_esd */
X
X/*+-----------------------------------------------------------------------
X	esdptr = make_esd(maxcb)	allocate an esd and buffer
X------------------------------------------------------------------------*/
XESD *
Xmake_esd(maxcb)
Xregister maxcb;		/* desired maxcb */
X{
Xregister ESD *tesd;
Xregister actual_cb;
X
X	/* we get an extra character to ensure room for null past maxcb */
X	actual_cb = maxcb + 1;
X	if(actual_cb & 1)		/* even allocation */
X		++actual_cb;
X
X	if(!(tesd = (ESD *)malloc(sizeof(ESD))))
X		return((ESD *)0); 	/* return NULL if failure */
X
X	if(!(tesd->pb = malloc(actual_cb)))
X	{
X		free((char *)tesd);
X		return((ESD *)0); 	/* return NULL if failure */
X	}
X
X	init_esd(tesd,tesd->pb,maxcb);
X	return(tesd);
X
X}	/* end of make_esd */
X
X/*+-----------------------------------------------------------------------
X	esdptr = realloc_esd(maxcb)	- realloc an esd buffer
X------------------------------------------------------------------------*/
Xint
Xrealloc_esd(tesd,maxcb)
XESD *tesd;
Xregister maxcb;		/* desired maxcb */
X{
Xregister actual_cb;
X
X	if(!tesd)
X		return(eInternalLogicError);
X
X	/* we get an extra character to ensure room for null past maxcb */
X	actual_cb = maxcb + 1;
X	if(actual_cb & 1)		/* even allocation */
X		++actual_cb;
X
X	if(!(tesd->pb = realloc(tesd->pb,actual_cb)))
X	{
X		errno = ENOMEM;
X		ff(se,"\r\n\r\nMEMORY REALLOC FAILED. FATAL ERROR. SORRY.\r\n");
X		hangup(HANGUP_XMTR_LOGIC_ERROR);
X	}
X
X	return(0);
X
X}	/* end of realloc_esd */
X
X/*+-----------------------------------------------------------------------
X	free_esd(esdptr)
X------------------------------------------------------------------------*/
Xvoid
Xfree_esd(tesd)
Xregister ESD *tesd;
X{
X	if(tesd && tesd->pb)
X	{
X		free(tesd->pb);
X		free((char *)tesd);
X	}
X	else
X	{
X		errno = ENOMEM;
X		ff(se,"\r\n\r\nFREE_ESD FAILED. FATAL ERROR. SORRY.\r\n");
X		hangup(HANGUP_XMTR_LOGIC_ERROR);
X	}
X}
X
X/*+-------------------------------------------------------------------------
X	show_esd(tesd,title)
X--------------------------------------------------------------------------*/
Xvoid
Xshow_esd(tesd,title)
XESD *tesd;
Xchar *title;
X{
Xregister itmp;
X
X	if(title && *title)
X	{
X		pputs(title);
X		pputs("\n");
X	}
X	null_terminate_esd(tesd);
X	pputs(tesd->pb);
X	pputs("\n");
X	for(itmp = 0; itmp <= tesd->cb; itmp++)
X	{
X		if(itmp == tesd->old_index)
X			pputc('^');
X		else if(itmp == tesd->index)
X			pputc('^');
X		else
X			pputc(' ');
X		if((itmp > tesd->old_index) && (itmp > tesd->index))
X			break;
X	}
X	pprintf(" o%d i%d c%d\n",tesd->old_index,tesd->index,tesd->cb);
X
X}	/* end of show_esd */
X
X/*+----------------------------------------------------------------
X    strindex:  string index function
X
X  Returns position of 'str2' in 'str1' if found
X  If 'str2' is null, then 0 is returned (null matches anything)
X  Returns -1 if not found
X-----------------------------------------------------------------*/
Xint
Xstrindex(str1,str2)
Xchar *str1;	/* the (target) string to search */
Xchar *str2;	/* the (comparand) string to search for */
X{
Xregister istr1 = 0;
Xregister lstr2 = strlen(str2);
Xregister char *mstr = str1;	/* the (target) string to search */
X
X	if(*str2 == 0)			/* null string matches anything */
X		return(0);
X
X	while(*mstr)
X	{
X		if(*mstr == *str2)
X		{ /* we have a first char match... does rest of string match? */
X			if(!strncmp(mstr,str2,lstr2))
X				return(istr1);		/* if so, return match position */
X		}
X		mstr++;
X		istr1++;
X	}
X
X	return(-1);		/* if we exhaust target string, flunk */
X
X}   /* end of strindex */
X
X/*+-------------------------------------------------------------------------
X	esdstrindex(esd1,esd2,index1_flag,index2_flag)
X
X  Call strindex with esd1->pb and esd2->pb.
X  If index1_flag != 0, esd1->pb + esd1->index passed
X  If index2_flag != 0, esd2->pb + esd2->index passed
X--------------------------------------------------------------------------*/
Xesdstrindex(esd1,esd2,index1_flag,index2_flag)
Xregister ESD *esd1;
Xregister ESD *esd2;
Xregister index1_flag;
Xregister index2_flag;
X{
X	return(strindex((index1_flag) ? esd1->pb : esd1->pb + esd1->index,
X	    (index2_flag) ? esd2->pb : esd2->pb + esd2->index));
X
X}	/* end of esdstrindex */
X
X/*+----------------------------------------------------------------
X    keyword_lookup(ktable,param)
X
X  Lookup string in keyword_table struct array
X  Returns table->key_token if 'param' found in
X  'table', else -1
X
X  Beware substrings.  "type","typedef" will both match "type"
X-----------------------------------------------------------------*/
Xkeyword_lookup(ktable,param)
Xregister KEYTAB *ktable;
Xregister char *param;
X{
X/* register plen = strlen(param); */
X
X	while(ktable->key_word)
X	{
X/*		if(!strncmp(ktable->key_word,param,plen)) */
X		if(!strcmp(ktable->key_word,param))
X			return(ktable->key_token);
X		++ktable;
X	}   /* end of while */
X
X	return(-1);     /* search failed */
X
X}   /* end of keyword_lookup */
X
X/*+----------------------------------------------------------------
X    skip_cmd_break(param)
X
X  Finds next non-break
X
X  'param' is an esd with valid 'index' field
X  Returns  0             index field points to non-break character
X           eNoParameter  end of command found
X-----------------------------------------------------------------*/
Xint
Xskip_cmd_break(param)
Xregister ESD *param;
X{
Xregister cb = param->cb;
Xregister index = param->index;
Xregister char *pb = param->pb;
X
X	while(index < cb)
X	{
X		if(!isspace(*(pb + index)))
X			break;
X		index++;
X	}
X	param->old_index = param->index = index;
X	if(index >= cb)
X		return(eNoParameter);
X	return(0);
X
X}   /* end of skip_cmd_break */
X
X/*+-------------------------------------------------------------------------
X	end_of_cmd(param) - return 1 if at end of command
X--------------------------------------------------------------------------*/
Xint
Xend_of_cmd(param)
Xregister ESD *param;
X{
X	if(skip_cmd_break(param) || (*(param->pb + param->index) == ';') ||
X			(*(param->pb + param->index) == '#'))
X		return(1);
X	return(0);
X}	/* end of end_of_cmd */
X
X/*+-------------------------------------------------------------------------
X    erc = skip_cmd_char(param,skipchar)
X--------------------------------------------------------------------------*/
Xint
Xskip_cmd_char(param,skipchar)
Xregister ESD *param;
Xregister char skipchar;
X{
Xint erc;
X
X	if(erc = skip_cmd_break(param))
X		return(erc);
X
X	if(param->pb[param->index] == skipchar)
X	{
X		++param->index;
X		return(0);
X	}
X
X	return(eSyntaxError);
X
X}   /* end of skip_cmd_char */
X
X/*+-------------------------------------------------------------------------
X    erc = skip_colon(param)
X--------------------------------------------------------------------------*/
Xint
Xskip_colon(param)
Xregister ESD *param;
X{
X	register erc;
X
X	if(erc = skip_cmd_break(param))
X		return(erc);
X
X	if(param->pb[param->index] == ':')
X	{
X		++param->index;
X		return(0);
X	}
X
X	return(eCommaExpected);
X
X}   /* end of skip_colon */
X
X/*+-------------------------------------------------------------------------
X    erc = skip_comma(param)
X--------------------------------------------------------------------------*/
Xint
Xskip_comma(param)
Xregister ESD *param;
X{
X	register erc;
X
X	if(erc = skip_cmd_break(param))
X		return(erc);
X
X	if(param->pb[param->index] == ',')
X	{
X		++param->index;
X		return(0);
X	}
X
X	return(eCommaExpected);
X
X}   /* end of skip_comma */
X
X/*+-------------------------------------------------------------------------
X    erc = skip_paren(fparam,LEFT or RIGHT)
X--------------------------------------------------------------------------*/
Xint
Xskip_paren(param,fLeft)
Xregister ESD *param;
Xint fLeft;
X{
Xregister erc;
Xregister char search = (fLeft) ? '(' : ')';
X
X	if(erc = skip_cmd_break(param))
X		return(erc);
X
X	if(param->pb[param->index] == search)
X	{
X		param->index++;
X		return(0);
X	}
X	return((fLeft) ? eMissingLeftParen : eMissingRightParen);
X
X}   /* end of skip_paren */
X
X/*+-------------------------------------------------------------------------
X	get_cmd_char(param,pchar)
X--------------------------------------------------------------------------*/
Xint
Xget_cmd_char(param,pchar)
Xregister ESD *param;
Xchar *pchar;
X{
Xint erc;
X
X	if(erc = skip_cmd_break(param))
X		return(erc);
X	*pchar = param->pb[param->index++];
X	return(0);
X
X}	/* end of get_cmd_char */
X
X/*+----------------------------------------------------------------
X    get_alpha_zstr(&esd,&strbuf,strbuf_maxcb)
X
X  places next alphabetic string token [A-Za-z_] into
X  the null-terminated 'strbuf' string.  returns 0 or -1
X  or skip_cmd_break error codes
X-----------------------------------------------------------------*/
Xint
Xget_alpha_zstr(param,strbuf,strbuf_maxcb)
XESD *param;
Xregister char *strbuf;
Xint strbuf_maxcb;
X{
Xregister izstr;
Xregister schar;
Xregister char *pb = param->pb;
X
X	if(izstr = skip_cmd_break(param))
X		return(izstr);
X	izstr = 0;
X	while( (izstr < strbuf_maxcb-1) && (param->index < param->cb) )
X	{
X		schar = pb[param->index];
X		if((!isalpha(schar)) && (schar != '_'))
X			break;
X		strbuf[izstr++] = schar;
X		param->index++;
X	}
X
X	strbuf[izstr] = 0;
X	return(izstr ? 0 : eBadParameter);
X
X}   /* end of get_alpha_zstr */
X
X/*+----------------------------------------------------------------
X    get_alphanum_zstr(&esd,&strbuf,strbuf_maxcb)
X
X  places next alphanumeric string token [A-Za-z0-9_]
X  into the null-terminated 'strbuf' string.  returns 0
X  or -1 or skip_cmd_break error codes
X-----------------------------------------------------------------*/
Xint
Xget_alphanum_zstr(param,strbuf,strbuf_maxcb)
Xregister ESD *param;
Xregister char *strbuf;
Xint strbuf_maxcb;
X{
Xint izstr = 0;
Xint schar;
Xregister cb = param->cb;
Xregister index;
X
X	if(izstr = skip_cmd_break(param))
X		return(izstr);
X
X	index = param->index;
X	while( (izstr < strbuf_maxcb-1) && (index < cb))
X	{
X		schar = param->pb[index++];
X		if(isalnum(schar) || (schar == '_'))
X			strbuf[izstr++] = schar;
X		else
X		{
X			--index;
X			break;
X		}
X	}
X
X	param->index = index;
X	strbuf[izstr]=0;
X	return(izstr ? 0 : eBadParameter);
X
X}   /* end of get_alphanum_zstr */
X
X/*+----------------------------------------------------------------
X    get_numeric_zstr(&esd,&strbuf,strbuf_maxcb)
X    gets next numeric string token places it
X    into the null-terminated 'strbuf' string.  returns 0 or -1 
X    or skip_cmd_break error codes
X-----------------------------------------------------------------*/
Xint
Xget_numeric_zstr(param,strbuf,strbuf_maxcb)
Xregister ESD *param;
Xregister char *strbuf;
Xregister strbuf_maxcb;
X{
X	register izstr;
X	register schar;
X
X	if(izstr = skip_cmd_break(param))
X		return(izstr);
X
X	while( (izstr < strbuf_maxcb-1) && (param->index < param->cb) )
X	{
X		schar = param->pb[param->index++];
X		if( isdigit(schar) )
X			strbuf[izstr++]=schar;
X		else
X		{
X			--param->index;
X			break;
X		}
X	}
X
X	strbuf[izstr]=0;
X	return(izstr ? 0 : eBadParameter);
X
X}   /* end of get_numeric_zstr */
X
X/*+-----------------------------------------------------------------------
X	get_numeric_value(param,&long_var)
X------------------------------------------------------------------------*/
Xget_numeric_value(param,value)
Xregister ESD *param;
Xregister long *value;
X{
Xregister erc;
Xchar buf[32];
X
X	if(erc = get_numeric_zstr(param,buf,sizeof(buf)))
X		return(erc);
X	sscanf(buf,"%ld",value);
X	return(0);
X
X}	/* end of get_numeric_value */
X
X/*+----------------------------------------------------------------
X    get_word_zstr(&esd,&strbuf,strbuf_maxcb)
X
X  gets next word (continuous string of characters without spaces
X  or tabs) returns 0 or -1 or skip_cmd_break error codes
X-----------------------------------------------------------------*/
Xint
Xget_word_zstr(param,strbuf,strbuf_maxcb)
Xregister ESD *param;
Xregister char *strbuf;
Xregister strbuf_maxcb;
X{
X	register izstr;
X	register schar;
X
X	if(izstr = skip_cmd_break(param))
X		return(izstr);
X
X	strbuf_maxcb--;
X	while((izstr < strbuf_maxcb) && (param->index < param->cb))
X	{
X		schar = param->pb[param->index++];
X		if( (schar > 0x20) && (schar <= 0x7e))
X			strbuf[izstr++]=schar;
X		else
X		{
X			--param->index;
X			break;
X		}
X	}
X
X	strbuf[izstr]=0;
X	return(izstr ? 0 : eBadParameter);
X
X}   /* end of get_word_zstr */
X
X/*+-------------------------------------------------------------------------
X    strip_trailing_spaces_esd(param)
X--------------------------------------------------------------------------*/
Xvoid
Xstrip_trailing_spaces_esd(ztext)
Xregister ESD *ztext;
X{
X	while(ztext->cb &&
X		((ztext->pb[ztext->cb-1] == 0x20) || (ztext->pb[ztext->cb-1] == 0x20)))
X	{
X		ztext->cb--;
X	}
X}   /* end of strip_trailing_spaces_esd */
X
X/*+-------------------------------------------------------------------------
X	fgetesd(&esd,fileptr)
X
X  stdio read from FILE *fileptr into esd
X  returns param->cb set up not including trailing nl, param->index == 0
X--------------------------------------------------------------------------*/
Xint
Xfgetesd(param,fileptr)
Xregister ESD *param;
Xregister FILE *fileptr;
X{
Xregister char *cptr;
X
X	if(fgets(param->pb,param->maxcb,fileptr) == NULL)
X		return(eEOF);
X	if((cptr = strchr(param->pb,0x0A)) == NULL)
X		return(eBufferTooSmall);
X	param->cb = (int)(cptr - param->pb);
X	null_terminate_esd(param);
X	param->index = 0;
X	param->old_index = 0;
X	return(0);
X
X}	/* end of fgetesd */
X
X/*+-------------------------------------------------------------------------
X	fputesd(&esd,fileptr,index_flag,nl_flag)
X
X  write esd contents to stdio FILE *fileptr
X  if index_flag is true, write from param->index thru end of esd
X  otherwise, from start of esd
X  if nl_flag is true, append nl to write, else just esd contents
X--------------------------------------------------------------------------*/
Xint
Xfputesd(param,fileptr,index_flag,nl_flag)
Xregister ESD *param;
XFILE *fileptr;
Xint index_flag;
Xint nl_flag;
X{
Xregister char *cptr;
Xregister write_length;
X
X	if(index_flag)
X	{
X		cptr = &param->pb[param->index];
X		write_length = param->cb - param->index;
X	}
X	else
X	{
X		cptr = param->pb;
X		write_length = param->cb;
X	}
X
X	if(write_length)
X		fwrite(cptr,write_length,1,fileptr);
X
X	if(nl_flag)
X		fputc(0x0A,fileptr);
X
X	return(0);
X}	/* end of fputesd */
X
X/*+-----------------------------------------------------------------
X	append_zstr_to_esd(param,zstr)
X------------------------------------------------------------------*/
Xappend_zstr_to_esd(param,zstr)
XESD *param;
Xchar *zstr;
X{
Xregister zstrlen = strlen(zstr);
Xregister erc = 0;
X
X	if(zstrlen > (param->maxcb - param->cb))
X	{
X		zstrlen = param->maxcb - param->cb;
X		erc = eBufferTooSmall;
X	}
X
X	if(zstrlen)
X	{
X		strncpy(param->pb + param->cb,zstr,zstrlen);
X		param->cb += zstrlen;
X	}
X	return(erc);
X}
X
X/*+-------------------------------------------------------------------------
X    get_switches(param,switches,switches_max)
X--------------------------------------------------------------------------*/
Xint
Xget_switches(param,switches,switches_max)
XESD *param;
Xchar *switches;
Xint switches_max;
X{
Xregister itmp;
Xregister index;
Xregister char *pb = param->pb;
Xint cb = param->cb;
Xchar schar;
X
X	*switches = 0;
X
X	if(itmp = skip_cmd_break(param))
X		return(itmp);
X
X	index = param->index;
X	if(*(param->pb + index) != '-')
X		return(eNoSwitches);
X
X	switches_max--;
X	*switches++ = '-';
X	index++;
X	while((itmp < switches_max) && (index < cb))
X	{
X		schar = *(pb + index++);
X		if(isspace(schar))
X			break;
X		*switches++ = schar;
X	}
X
X	param->index = index;
X	*switches = 0;
X	return(0);
X
X}   /* end of get_switches() */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of esdutil.c */
SHAR_EOF
$TOUCH -am 1224223790 'esdutil.c' &&
chmod 0644 esdutil.c ||
echo 'restore of esdutil.c failed'
Wc_c="`wc -c < 'esdutil.c'`"
test 17780 -eq "$Wc_c" ||
	echo 'esdutil.c: original size 17780, current size' "$Wc_c"
# ============= esiointf.c ==============
echo 'x - extracting esiointf.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'esiointf.c' &&
X/*+-------------------------------------------------------------------------
X	esiointf.c - esio/FAS interface
X	wht at n4hgf.Mt-Park.GA.US
X
X  Defined functions:
X	pcmd_esio(param)
X	display_esio(sip)
X	icmd_esio(narg,arg)
X	ier_text(ier)
X	lcr_text(lcr)
X	mcr_text(mcr)
X	msr_text(msr)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:12-24-1990-00:51-wht-creation */
X
X#if	defined(ESIO_IN_USE)
X#ifndef WHT
X#define WHT
X#endif
X#include "ecu.h"
X#include "ecuerror.h"
X#include "esd.h"
X#include <local/esio.h>
X
Xextern int proctrace;
X
X/*+-------------------------------------------------------------------------
X	msr_text(msr)
X--------------------------------------------------------------------------*/
Xchar *
Xmsr_text(msr)
Xuchar msr;
X{
Xstatic char txt[50];
X
X	txt[0] = '*';
X	txt[1] = 0;
X	if(!msr)
X	{
X		strcat(txt,"NULL*");
X		return(txt);
X	}
X	if(msr & MS_CTS_DELTA) strcat(txt,"dCTS*");
X	if(msr & MS_DSR_DELTA) strcat(txt,"dDSR*");
X	if(msr & MS_RING_TEDGE) strcat(txt,"dRI*");
X	if(msr & MS_DCD_DELTA) strcat(txt,"dDCD*");
X	if(msr & MS_CTS_PRESENT) strcat(txt,"CTS*");
X	if(msr & MS_DSR_PRESENT) strcat(txt,"DSR*");
X	if(msr & MS_RING_PRESENT) strcat(txt,"RING*");
X	if(msr & MS_DCD_PRESENT) strcat(txt,"DCD*");
X	return(txt);
X
X}	/* end of msr_text */
X
X/*+-------------------------------------------------------------------------
X	mcr_text(mcr)
X--------------------------------------------------------------------------*/
Xchar *
Xmcr_text(mcr)
Xuchar mcr;
X{
Xstatic char txt[32];
X
X	txt[0] = '*';
X	txt[1] = 0;
X	if(!mcr)
X	{
X		strcat(txt,"NULL*");
X		return(txt);
X	}
X	if(mcr & MC_SET_DTR) strcat(txt,"DTR*");
X	if(mcr & MC_SET_RTS) strcat(txt,"RTS*");
X	if(mcr & MC_SET_OUT1) strcat(txt,"OUT1*");
X	if(mcr & MC_SET_OUT2) strcat(txt,"OUT2*");
X	if(mcr & MC_SET_LOOPBACK) strcat(txt,"LOOPBACK*");
X	return(txt);
X
X}	/* end of mcr_text */
X
X/*+-------------------------------------------------------------------------
X	lcr_text(lcr)
X--------------------------------------------------------------------------*/
Xchar *
Xlcr_text(lcr)
Xuchar lcr;
X{
Xstatic char txt[64];
X
X	sprintf(txt,"*%ddb*",(lcr & LC_WORDLEN_MASK) + 5);
X	strcat(txt,(lcr & LC_STOPBITS_LONG) ? "2" : "1");
X	strcat(txt,"sb*");
X	if(lcr & LC_ENABLE_PARITY)
X	{
X		strcat(txt,"PARITY*");
X		if(lcr & LC_STICK_PARITY)
X			strcat(txt,(lcr & LC_EVEN_PARITY) ? "MARK*" : "SPACE*");
X		else
X			strcat(txt,(lcr & LC_EVEN_PARITY) ? "EVEN*" : "ODD*" );
X	}
X	else
X		strcat(txt,"NOPAR*");
X	if(lcr & LC_SET_BREAK_LEVEL)
X		strcat(txt,"SETBREAK*");
X	if(lcr & LC_ENABLE_DIVISOR)
X		strcat(txt,"ENABDIV*");
X	return(txt);
X
X}	/* end of lcr_text */
X
X/*+-------------------------------------------------------------------------
X	ier_text(ier)
X--------------------------------------------------------------------------*/
Xchar *
Xier_text(ier)
Xuchar ier;
X{
Xstatic char txt[32];
X
X	txt[0] = '*';
X	txt[1] = 0;
X	if(!ier)
X	{
X		strcat(txt,"NULL*");
X		return(txt);
X	}
X	if(ier & IE_RECV_DATA_AVAILABLE) strcat(txt,"RDAV*");
X	if(ier & IE_XMIT_HOLDING_BUFFER_EMPTY) strcat(txt,"TBMT*");
X	if(ier & IE_LINE_STATUS) strcat(txt,"LS*");
X	if(ier & IE_MODEM_STATUS) strcat(txt,"MS*");
X	return(txt);
X
X}	/* end of ier_text */
X
X/*+-------------------------------------------------------------------------
X	display_esio(sip)
X--------------------------------------------------------------------------*/
Xvoid
Xdisplay_esio(sip)
Xstruct esio_info *sip;
X{
X
X	pprintf("base address: %04x irq=%u ",sip->uart_port_0,sip->vec);
X	pputs("device is ");
X	if(sip->device_flags.s & DF_DEVICE_IS_NS16550)
X		pputs("16550\n");
X	else if(sip->device_flags.s & DF_DEVICE_IS_I82510)
X		pputs("82510\n");
X	else
X		pputs("16450\n");
X	pprintf("MSR=%s   ",msr_text(sip->msr));
X	pprintf("MCR=%s\n",mcr_text(sip->mcr));
X	pprintf("LCR=%s   ",lcr_text(sip->lcr));
X	pprintf("IER=%s\n",ier_text(sip->ier));
X	pprintf("recv ring cnt=%4d  ",sip->recv_ring_cnt);
X	pprintf("xmit ring cnt=%4d\n",sip->xmit_ring_cnt);
X	pprintf("characters received    =%8ld\n",sip->characters_received);
X	pprintf("characters transmited  =%8ld\n",sip->characters_transmitted);
X	pprintf("modem status events    =%8ld\n",sip->modem_status_events);
X	pprintf("total interrupt entries=%8ld\n",sip->total_interrupts);
X	pprintf("overrun errors=%ld  ",sip->overrun_errors);
X	pprintf("framing errors=%ld  ",sip->framing_errors);
X	pprintf("parity errors=%ld\n",sip->parity_errors);
X	pprintf("rings detected=%ld  ",sip->rings_detected);
X	pprintf("breaks detected=%ld\n",sip->breaks_detected);
X	pprintf("xmtr flow off XON/XOFF=%ld  RTS/CTS=%ld\n",
X		sip->xmtr_sw_flow_count,sip->xmtr_hw_flow_count);
X	pprintf("rcvr flow off XON/XOFF=%ld  RTS/CTS=%ld\n",
X		sip->rcvr_sw_flow_count,sip->rcvr_hw_flow_count);
X
X}	/* end of display_esio */
X
X/*+-------------------------------------------------------------------------
X	esio_msr() - return modem status register contents
X--------------------------------------------------------------------------*/
Xuchar
Xesio_msr()
X{
Xulong ltmp;
X
X	return((uchar)ioctl(shm->Liofd,FASIOC_MCR,(char *)&ltmp));
X	return(ltmp);
X}	/* end of esio_msr */
X
X/*+-------------------------------------------------------------------------
X	esio_line_errors() - return UART error count
X--------------------------------------------------------------------------*/
Xulong
Xesio_line_errors()
X{
Xstruct esio_info sinfo,*sip = &sinfo;
X
X	if((ioctl(shm->Liofd,FASIOC_SIP,(char *)sip)) < 0)
X		return(0);
X	return(sip->parity_errors + sip->framing_errors + sip->overrun_errors);
X
X}	/* end of esio_line_errors */
X
X/*+-------------------------------------------------------------------------
X	esio_rings_detected() - return number of RI trailing edges
X--------------------------------------------------------------------------*/
Xulong
Xesio_rings_detected()
X{
Xstruct esio_info sinfo,*sip = &sinfo;
X
X	if((ioctl(shm->Liofd,FASIOC_SIP,(char *)sip)) < 0)
X		return(0);
X	return(sip->rings_detected);
X
X}	/* end of esio_rings_detected */
X
X/*+-------------------------------------------------------------------------
X	esio_breaks_detected() - return number of BREAKs detected
X--------------------------------------------------------------------------*/
Xulong
Xesio_breaks_detected()
X{
Xstruct esio_info sinfo,*sip = &sinfo;
X
X	if((ioctl(shm->Liofd,FASIOC_SIP,(char *)sip)) < 0)
X		return(0);
X	return(sip->breaks_detected);
X
X}	/* end of esio_breaks_detected */
X
X/*+-------------------------------------------------------------------------
X	pcmd_esio(param)
Xesio [-switches] <str-cmd>>
X
Xwhere <str-cmd> is 'd[isplay]'
X                or 'r[eset]'
X
Xesio 'd'
Xesio 'r'
X--------------------------------------------------------------------------*/
Xint
Xpcmd_esio(param)
XESD *param;
X{
Xint erc;
Xchar switches[8];
XESD *tesd = (ESD *)0;
Xchar *cmd;
Xstruct esio_info sinfo,*sip = &sinfo;
X
X	get_switches(param,switches,sizeof(switches));
X	if(!(tesd = make_esd(64)))
X		return(eNoMemory);
X	if(!(erc = gstr(param,tesd,1)))
X	{
X		skip_cmd_break(tesd);
X		switch(to_lower(*(tesd->pb + tesd->index)))
X		{
X			case 'd':	/* display */
X				if((ioctl(shm->Liofd,FASIOC_SIP,(char *)sip)) < 0)
X				{
X					pperror("ioctl FASIOC_SIP");
X					erc = eFATAL_ALREADY;
X				}
X				else
X					display_esio(sip);
X				break;
X
X			case 'r':	/* reset */
X				if((ioctl(shm->Liofd,FASIOC_RESET_STAT,(char *)0)) < 0)
X				{
X					pperror("ioctl FASIOC_RESET_STAT");
X					erc = eFATAL_ALREADY;
X				}
X				else if(proctrace)
X					pputs("statistics reset\n");
X				break;
X
X			default:
X				pputs("invalid subcommand '");
X				pputs(tesd->pb);
X				pputs("'\n");
X				erc = eFATAL_ALREADY;
X				break;
X		}
X	}
X
X	if(tesd)
X		free_esd(tesd);
X	return(erc);
X
X}	/* end of pcmd_esio */
X
X/*+-------------------------------------------------------------------------
X	icmd_esio(narg,arg)
X--------------------------------------------------------------------------*/
Xvoid
Xicmd_esio(narg,arg)
Xint narg;
Xchar **arg;
X{
Xstruct esio_info sinfo,*sip = &sinfo;
X
X	if((narg > 1) && (to_lower(*arg[1]) == 'r'))
X	{
X		if((ioctl(shm->Liofd,FASIOC_RESET_STAT,(char *)0)) < 0)
X		{
X			pperror("   ioctl FASIOC_RESET_STAT");
X			return;
X		}
X		ff(se,"  esio statistics reset\r\n");
X	}
X	else
X	{
X		if((ioctl(shm->Liofd,FASIOC_SIP,(char *)sip)) < 0)
X		{
X			pperror("   ioctl FASIOC_SIP");
X			return;
X		}
X		ff(se,"\r\n");
X		display_esio(sip);
X	}
X
X}	/* end of icmd_esio */
X
X#endif /* ESIO_IN_USE */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of esiointf.c */
SHAR_EOF
$TOUCH -am 1226024490 'esiointf.c' &&
chmod 0644 esiointf.c ||
echo 'restore of esiointf.c failed'
Wc_c="`wc -c < 'esiointf.c'`"
test 8287 -eq "$Wc_c" ||
	echo 'esiointf.c: original size 8287, current size' "$Wc_c"
true || echo 'restore of expresp.c failed'
echo End of part 10, continue with part 11
exit 0
--------------------------------------------------------------------
Warren Tucker, TuckerWare emory!n4hgf!wht or wht at n4hgf.Mt-Park.GA.US
Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols

exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent at 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 at uunet.uu.net.



More information about the Comp.sources.misc mailing list