ecu - SCO XENIX V/{2,3}86 Extended CU part 05/47

Warren Tucker wht at tridom.uucp
Mon Oct 9 07:43:52 AEST 1989


---- Cut Here and unpack ----
#!/bin/sh
# this is part 5 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file ecuicmd.c continued
#
CurArch=5
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file ecuicmd.c"
sed 's/^X//' << 'SHAR_EOF' >> ecuicmd.c
X		break;
X
X		case CTlog:
X		case CTloff:
X		case CTllp:
X		icmd_log(token,narg,arg);
X		break;
X
X		case CTnl:
X		case CTnlin:
X		case CTnlout:
X		nlin_nlout_control(token,narg,arg);
X		break;
X
X		case CTparity:
X		if(narg > 1)
X		{
X			switch(to_lower(*arg[1]))
X			{
X				case 'n':
X					Lparity = 0; break;
X				case 'e':
X				case 'o':
X					Lparity = to_lower(*arg[1]); break;
X				default:
X					ff(se,"   unrecognized parity: %c\r\n",*arg[1]);
X					goto PARITY_DONE;
X			}
X			lset_parity(1);
X		}
X		ff(se,"   parity set to %c\r\n",
X			(Lparity) ? to_upper(Lparity) : 'N');
XPARITY_DONE: ;
X		break;
X
X		case CTpid:
X		ff(se,": xmtr %d, rcvr: %d, parent: %d, group: %d\r\n",
X			getpid(0),rcvr_pid,getppid(0),getpgrp(0));
X		break;
X
X		case CTpwd:
X		fputs(" ",se);
X		stand_out();
X		ff(se," %s ",curr_dir);
X		stand_end();
X		fputs("\r\n",se);
X		break;
X
X		case CTredial:
X		(void)hayes_redial(arg,narg);
X		break;
X
X		case CTrev:
X		fputs("\r\n",se);
X		fputs(hello_str,se);
X		fputs("\r\n",se);
X		ff(se,"%s\r\n",revision);
X		break;
X
X#if !defined(M_XENIX)
X		case CTte:
X		if(narg > 1)
X		{
X			if(sscanf(arg[1],"%x",&cmd_escape) && (cmd_escape < 0x7F))
X				ff(se,"   tty escape set to "); 
X			else
X			{
X				ff(se,"  invalid parameter must be 01 to 7E: setting to ");
X				cmd_escape = '%';
X			}
X		}
X		else
X			ff(se,"   tty escape is ");
X
X		ff(se,"0x%02x (%s)\r\n",cmd_escape,make_char_graphic(cmd_escape,1));
X		break;
X#endif
X
X		case CTtime:
X		get_tod(4,cmd);
X		ff(se,": %s\r\n",cmd);
X		break;
X
X		case CTts:
X		ff(se,"\r\n");
X		sprintf(s80,"TTYIN termio (ttymode=%d)",current_ttymode);
X		disp_line_termio(TTYIN,s80);
X		ff(se,"\r\n");
X		disp_line_termio(Liofd,"comm line termio");
X		break;
X
X		case CTtty:
X		ff(se,"   %s\r\n",get_ttyname());
X		break;
X
X		case CTda:
X		case CToa:
X		case CTxa:
X		case CTax:
X		icmd_conversion(token,narg,arg);
X		break;
X
X		case CTansi:
X		if(narg > 1)
X			shmx_set_rcvr_ansi(ansi_filter = yes_or_no(arg[1]));
X		ff(se,"  ansi filter %s%s\r\n",(ansi_filter) ? "on" : "off",
X					(ansi_filter == 2) ? ": log unknown" : "");
X		break;
X
X		case CTbn:
X		if(narg > 1)
X		{
X			want_bell_notify = yes_or_no(arg[1]);
X			shmx_set_rcvr_bn(want_bell_notify);
X		}
X		ff(se,"  bell notify %s%s\r\n",
X					want_bell_notify ? "on" : "off",
X					(want_bell_notify == 2) ? ": ring on incoming char" : "");
X		break;
X
X		case CTfkey:
X		if(narg < 2)
X			keyset_display();
X		else
X		{
X			switch(keyset_read(arg[1]))
X			{
X				case  0: keyset_display(); break;
X				case -1: ff(se," cannot find ~/.ecu/keys\r\n"); break;
X				case -2: ff(se," not found in ~/.ecu/keys\r\n"); break;
X			}
X		}
X		break;
X
X		case CTstat:
X		ff(se,"\r\n\r\nDate/time");
X		icmd("time");
X		ff(se,"Console: %s  communications line: %s  ",get_ttyname(),Lline);
X		ff(se,"%u-%c-1\r\n",Lbaud,(Lparity) ? to_upper(Lparity) : 'N');
X		if(Lmodem_off_hook)
X		{
X			ff(se,"Connected to %s (%s) at %s (elapsed %s)\r\n",
X				Ldescr,Ltelno,epoch_secs_to_str(Loff_hook_time,1,s80),
X				get_elapsed_time(time((long *)0) - Loff_hook_time));
X		}
X		ff(se,"Current directory: %s\r\n",curr_dir);
X		ff(se,"Total chars transmitted: %ld",xmit_chars);
X		if(Lmodem_off_hook)
X			ff(se," (since CONNECT %ld)\r\n",xmit_chars_this_connect);
X		else
X			fputs("\r\n",se);
X		shmx_rc_report(&rcvr_chars,&rcvr_chars_this_connect);
X		ff(se,"Total chars received:    %ld",rcvr_chars);
X		if(Lmodem_off_hook)
X			ff(se," (since CONNECT %ld)\r\n",rcvr_chars_this_connect);
X		else
X			fputs("\r\n",se);
X		ff(se,"Ansi filter %s\r\n",(ansi_filter) ? "on" : "off");
X		if(keyset_name[0])
X			ff(se,"Function key set '%s' loaded\r\n",keyset_name);
X		else
X			ff(se,"No function key set loaded\r\n");
X		if(rcvr_log)
X			ff(se,"Session log open: %s (%s mode)\r\n",
X				rcvr_log_file,(rcvr_log_raw) ? "raw" : "filtered");
X		else
X			ff(se,"Session logging not active\r\n");
X		ff(se,"Bell notify is %s\r\n",(want_bell_notify) ? "on" : "off");
X		ff(se,"Duplex: %s\r\n",(Lfull_duplex) ? "full" : "half");
X		ff(se,"CR conversion:  incoming %s  outgoing %s\r\n",
X			(Ladd_nl_incoming) ? "CR/LF" : "CR",
X			(Ladd_nl_outgoing) ? "CR/LF" : "CR");
X		fputs("\r\n",se);
X		break;
X
X		case CTxlog:
X		if(narg > 1)
X		{
X			protocol_log_packets = yes_or_no(arg[1]);
X		}
X		ff(se,"  protocol packet logging %s\r\n",
X			(protocol_log_packets) ? "on" : "off");
X		break;
X
X		case CTsgr:
X		send_get_response(token,narg,arg);
X		break;
X
X/*
X		case CTmkdir:
X		if(narg < 2)
X			ff(se,"  no argument\r\n");
X		if(mkdir(arg[2],0755))
X		{
X			ff(se,"  ");
X			pperror(arg[2]);
X		}
X		else
X			ff(se,"  made directory %s\r\n",arg[2]);
X		break;
X*/
X
X		case 0:
X		ff(se,"   procedure command not allowed in interactive mode\r\n");
X		break;
X
X		default:
X		do_proc(narg,arg);
X		break;
X
X	}
X	return(0);		/* 0 == do not end program */
X
X}	/* end of icmd */
X
X/* end of ecuicmd.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo "File ecuicmd.c is complete"
chmod 0644 ecuicmd.c || echo "restore of ecuicmd.c fails"
echo "x - extracting ecuicmhelp.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuicmhelp.c &&
X/* CHK=0xBDC0 */
X/*+-------------------------------------------------------------------------
X	ecuicmhelp.c -- help for icmd commands
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	calculate_help_right_column()
X	display_help_screen()
X	display_help_stderr(cmd)
X	help_cmd_line_setup(prompt)
X	help_get_cmd()
X	icmd_help(narg,arg)
X	search_cmd_list_pcmd(cmd)
X	show_cmds()
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-03-1989-22:57-wht------------- ecu 2.00 ---------------- */
X/*:06-24-1989-16:53-wht-flush edits --- ecu 1.95 */
X
X#include <curses.h>
X#define OMIT_TERMIO_REFERENCES
X#define STDIO_H_INCLUDED
X#include "ecu.h"
X#define NEED_P_CMD
X#include "ecucmd.h"
X#include "ecukey.h"
X#include "pc_scr.h"
X
X#include "stdio_lint.h"
X
X#define PDAT	"/usr/lib/ecu/ecuhelp.data"
X
Xextern int rcvr_pid;
X
Xlong start_pos[TOKEN_QUAN];
Xint start_pos_has_been_read = 0;
Xchar help_filename[256] = "";
XFILE *fpdat;		/* help data file */
Xint help_right_column = 0;	/* right column for show_cmds */
Xint help_longest_cmd = 0;
Xint help_longest_descr = 0;
X
X/*+-------------------------------------------------------------------------
X	search_cmd_list_pcmd(cmd)
X--------------------------------------------------------------------------*/
XP_CMD *
Xsearch_cmd_list_pcmd(cmd)
Xregister char *cmd;
X{
Xregister P_CMD *cmd_list = icmd_cmds;
X
X	while(cmd_list->token != -1)
X	{
X		if(minunique(cmd_list->cmd,cmd,cmd_list->min))
X			break;
X		cmd_list++;
X	}
X	if(cmd_list->token == -1)
X		return((P_CMD *)0);
X	else
X		return(cmd_list);
X
X}	/* end of search_cmd_list_pcmd */
X
X/*+-------------------------------------------------------------------------
X	display_help_stderr(cmd)
X--------------------------------------------------------------------------*/
Xdisplay_help_stderr(cmd)
Xchar *cmd;
X{
Xregister itmp;
XP_CMD *pcmd;
Xchar buf[128];
X
X	if(! (pcmd = search_cmd_list_pcmd(cmd)))
X	{
X		ff(se,"'%s' is not a valid command\r\n",cmd);
X		return;
X	}
X
X	if(!start_pos[pcmd->token])
X	{
X		ff(se,"no help available for '%s'\r\n",cmd);
X		return;
X	}
X
X	fseek(fpdat,start_pos[pcmd->token],0);
X	ff(se,"\r\n");
X	while(fgets(buf,sizeof(buf),fpdat) != NULL)
X	{
X		itmp = strlen(buf);
X		buf[--itmp] = 0;
X		if(itmp == 0)
X			break;
X		ff(se,"%s\r\n",buf);
X	}
X
X}	/* end of display_help_stderr */
X
X/*+-------------------------------------------------------------------------
X	calculate_help_right_column()
X--------------------------------------------------------------------------*/
Xvoid
Xcalculate_help_right_column()
X{
Xregister itmp;
Xregister P_CMD *pcmd = icmd_cmds;
X
X	if(help_right_column)	/* already bee thru here? */
X		return;				/* ... seems so */
X
X	while(pcmd->token != -1)
X	{
X		if(!*pcmd->descr)
X		{
X			pcmd++;
X			continue;
X		}
X		itmp = strlen(pcmd->cmd);
X		if(itmp > help_longest_cmd)
X			help_longest_cmd = itmp;
X		itmp = strlen(pcmd->descr);
X		if(itmp > help_longest_descr)
X			help_longest_descr = itmp;
X		pcmd++;
X	}
X	help_right_column = 1 + help_longest_cmd + 2 + help_longest_descr + 3;
X
X}	/* end of calculate_help_right_column */
X
X/*+-------------------------------------------------------------------------
X	help_cmd_line_setup(prompt)
X--------------------------------------------------------------------------*/
Xvoid
Xhelp_cmd_line_setup(prompt)
Xchar *prompt;
X{
Xregister icol;
Xint y;
Xint x;
X
X	wmove(stdscr,LINES - 1,0);
X	wstandout(stdscr);
X	waddch(stdscr,' ');
X	waddch(stdscr,' ');
X	waddstr(stdscr,prompt);
X	getyx(stdscr,y,x);
X	for(icol = x; icol < COLS-1; icol++)
X		waddch(stdscr,' ');
X	wmove(stdscr,y,x);
X	wstandend(stdscr);
X	wrefresh(stdscr);
X}	/* end of help_cmd_line_setup */
X
X/*+-------------------------------------------------------------------------
X	char *help_get_cmd()
X--------------------------------------------------------------------------*/
Xchar *
Xhelp_get_cmd()
X{
Xregister y;
Xregister x;
Xstatic char cmd[15];
Xchar delim;
X
X	help_cmd_line_setup("Enter command name (ESC to quit):  ");
X	wstandout(stdscr);
X	getyx(stdscr,y,x);
X	wingets(stdscr,y,x,cmd,sizeof(cmd) - 1,&delim,0);
X	wstandend(stdscr);
X	if((delim == ESC) || (cmd[0] == 0))
X		return((char *)0);
X	else
X		return(cmd);
X}	/* end of help_get_cmd */
X
X
X/*+-------------------------------------------------------------------------
X	display_help_screen()
X--------------------------------------------------------------------------*/
Xdisplay_help_screen()
X{
Xregister itmp;
Xregister P_CMD *pcmd = icmd_cmds;
Xregister y = 1;
Xregister x = 0;
Xchar s80[80];
X
X	wclear(stdscr);
X	wmove(stdscr,0,0);
X	wstandout(stdscr);
X	waddstr(stdscr,
X" ecu command list    (capitalized portion sufficient for cmd recognition)");
X	getyx(stdscr,y,x);
X	for(itmp = x; itmp < COLS-1; itmp++)
X		waddch(stdscr,' ');
X	wstandend(stdscr);
X
X	pcmd = icmd_cmds;
X	y = 1;
X	x = 0;
X	while(pcmd->token != -1)
X	{
X		if(!*pcmd->descr)
X		{
X			pcmd++;
X			continue;
X		}
X		wmove(stdscr,y,x);
X		strcpy(s80,pcmd->cmd);
X		pad_zstr_to_len(s80,help_longest_cmd + 2);
X		for(itmp = 0; itmp < pcmd->min; itmp++)
X			s80[itmp] = to_upper(s80[itmp]);
X		waddstr(stdscr,s80);
X
X		strcpy(s80,pcmd->descr);
X		pad_zstr_to_len(s80,help_longest_descr + 1);
X		waddstr(stdscr,s80);
X
X		if(!x)
X			waddch(stdscr,sVR);
X		y++;
X		if(y >= LINES - 2)
X		{
X			y = 1;
X			x = help_right_column;
X		}
X		pcmd++;
X	}
X
X}	/* end of display_help_screen */
X
X/*+-------------------------------------------------------------------------
X	show_cmds()
Xcommands with null descriptions are "undocumented"
X--------------------------------------------------------------------------*/
Xshow_cmds()
X{
Xregister char *cptr;
Xint rcvr_active = (rcvr_pid > 0) || (rcvr_pid == -2);
X
X	if(rcvr_active && (rcvr_pid != -2))
X		kill_rcvr_process(SIGUSR1);
X
X	calculate_help_right_column();
X	windows_start();
X	scrollok(stdscr,0);
X	display_help_screen();
X	while(cptr = help_get_cmd())
X	{
X		curmove(LINES - 1,0);
X		wclrtoeol(stdscr);
X		wrefresh(stdscr);
X		display_help_stderr(cptr);
X		ff(se,"press return:  ");
X		ttygetc(1);
X		display_help_screen();
X	}
X	wmove(stdscr,LINES - 1,0);
X	wclrtoeol(stdscr);
X	windows_end(stdscr);
X	curmove(LINES - 1,0);
X	if(rcvr_active)
X		start_rcvr_process(0);
X
X}	/* end of show_cmds */
X
X/*+-------------------------------------------------------------------------
X	icmd_help(narg,arg)
X--------------------------------------------------------------------------*/
Xvoid
Xicmd_help(narg,arg)
Xint narg;
Xchar **arg;
X{
Xregister char *cptr;
Xint src_line = 0;
Xchar *getenv();
X
X	ff(se,"\r\n");
X	if(!help_filename[0])
X	{
X		if((cptr = getenv("ECUHELP")) == NULL)
X			cptr = PDAT;
X		strcpy(help_filename,cptr);
X	}
X
X	if((fpdat = fopen(help_filename,"r")) == NULL)
X	{
X		perror(help_filename); fputc('\r',se);
X		return;
X	}
X
X	if(!start_pos_has_been_read)
X	{
X		fread((char *)start_pos,sizeof(long),TOKEN_QUAN,fpdat);
X		start_pos_has_been_read = 1;
X	}
X
X	if(narg > 1)
X		display_help_stderr(arg[1]);
X	else
X		show_cmds();
X
X	fclose(fpdat);
X}	/* end of icmd_help */
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
chmod 0644 ecuicmhelp.c || echo "restore of ecuicmhelp.c fails"
echo "x - extracting eculine.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > eculine.c &&
X/* CHK=0x8562 */
X
X#define NO_SELECT
X
X#if defined(M_I286) && !defined(NO_SELECT)
X#define NO_SELECT
X#endif
X
X/*+-----------------------------------------------------------------------
X	eculine.c -- line related procedures
X Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	lbreak()
X	lclear_xmtr_xoff()
X	lclose()
X	lget_xon_xoff(ixon,ixoff)
X	lgetc_timeout(msec)
X	lgetc_xmtr()
X	lgets_timeout(lrwt)
X	lflush(flush_type)
X	llookfor(lookfor,msecs,echo_flag)
X	lnew_baud_rate(new_baud)
X	lopen()
X	lopen_err_text(lerr)
X	lputc(lchar)
X	lputc_paced(pace_msec,lchar)
X	lputs(string)
X	lputs_paced(pace_msec,string)
X	lquiet(msecs,echo_flag)
X	lrdchk_xmtr()
X	lreset_ksr()
X	lset_baud_rate(ioctl_flag)
X	lset_parity(ioctl_flag)
X	ltoggle_dtr()
X	lxon_xoff(flag)
X	valid_baud_rate(baud)
X
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-03-1989-22:57-wht------------- ecu 2.00 ---------------- */
X/*:06-30-1989-00:32-wht-ltoggle_dtr no longer lopen/lclose, but open/close */
X/*:06-24-1989-16:53-wht-flush edits --- ecu 1.95 */
X
X#include "ecu.h"
X#include "ecukey.h"
X#include "ecuhangup.h"
X
Xextern int errno;
Xextern long xmit_chars;
Xextern long xmit_chars_this_connect;
Xextern int xenix_lgetc_count;
Xextern int xenix_vmin;
Xextern int interrupt;		/* SIGINT flag: see xmtr_SIGINT_handler */
X
X#define LPUTS_NAP_COUNT	20
X
X#if defined(M_I386)
X#if defined(NO_SELECT)
Xchar *select_rev_modifier = "-386n";
X#else
Xchar *select_rev_modifier = "-386s";
X#include <sys/select.h>
X#endif
X#else
Xchar *select_rev_modifier = "-286n";
X#endif
X
X/*+-------------------------------------------------------------------------
X	lgetc_xmtr() -- xmtr version of get char from line
Xalso called by rcvr code when xenix_lgetc_buf empty and xenix_vmin == 1
X--------------------------------------------------------------------------*/
Xuchar
Xlgetc_xmtr()
X{
Xint itmp;
Xextern int errno;
Xuchar char_rtnd;
X
XREAD_AGAIN:
X	if((itmp = read(Liofd,&char_rtnd,1)) < 1)
X	{
X		if(!itmp)
X		{
X			pperror("lgetc_xmtr: zero length read\n");
X			hangup(HANGUP_LINE_READ_ERROR);
X		}
X		if(errno == EINTR)			/* if signal interrupted, ... */
X		{
X			if(interrupt)
X				return(0);
X			goto READ_AGAIN;
X		}
X		hangup(HANGUP_LINE_READ_ERROR);
X	}
X	shmr_rcvd_chars(1);
X	if(Lparity)
X		char_rtnd &= 0x7F;
X	return(char_rtnd);
X
X}	/* end of lgetc_xmtr */
X
X/*+-------------------------------------------------------------------------
X	lrdchk_xmtr() -- rdchk(Liofd) for xmtr
X--------------------------------------------------------------------------*/
Xint
Xlrdchk_xmtr()
X{
X	return(rdchk(Liofd));
X}	/* end of lrdchk_xmtr */
X
X/*+-------------------------------------------------------------------------
X	char *lgets_timeout(LRWT *) - may be called by xmtr only
X
Xto1 and to2 are unsigned long values in milliseconds (not
Xcurrently supported well under BSD4); to1 is the time to wait
Xfor the first character, to2 the time to wait for subsequent
Xcharacters.
X
Xif raw_flag 0,     non-printables are stripped from beginning
X                   and end of received characters (i.e., modem
X                   response reads); NULs discarded, parity stripped
Xif raw_flag 1,     full raw read buffer returned
X
X0x80 in raw_flag indicates console interrupts should be enabled.
Xif interrupt thus detected, the procedure returns "!Interrupted"
Xwithout reseting variable 'interrupt'
X
Xbuffer is address to read chars into
X
Xbufsize is buffer max size (allowing room for terminating null)
Xwhich should be at least 2 if raw_size includes 0x80 bit,
Xelse at least 12 characters if 0x80 omitted.
X
Xcount is a int which, at return, receives the actual count read
X
X--------------------------------------------------------------------------*/
Xchar *
Xlgets_timeout(lrwt)
XLRWT *lrwt;
X{
X/**********************/
X#if defined(NO_SELECT)
X/**********************/
X
Xregister actual_count = 0;
Xregister char *cptr = lrwt->buffer;
Xint max_count = lrwt->bufsize;
Xchar *rtn_val;
Xint timeout_counter;
Xint qc1;
Xint qc2;
Xint raw_mode = lrwt->raw_flag & 0x0F;
Xint check_sigint = (lrwt->raw_flag & 0x80);
Xint old_ttymode = get_ttymode();	/* save original tty mode */
Xint delim_len;
Xlong quantum;
Xlong ltmp;
Xlong nap(long);
X
X	delim_len = (lrwt->delim) ? strlen(lrwt->delim) : 0;
X
X	if((Lbaud < 300) && lrwt->to2)
X		if(lrwt->to2 < 300L) lrwt->to2 = 300L;
X	else if((Lbaud < 1200) && lrwt->to2)
X		if(lrwt->to2 < 200L) lrwt->to2 = 100L;
X
X/* shortest interval */
X	ltmp = (lrwt->to1 < lrwt->to2) ? lrwt->to1 : lrwt->to2;
X
X/* calculate wait quantum */
X	quantum = ltmp / 10L;				/* try for ten ticks */
X
X#if defined(M_I386)
X	if(quantum < 40L)
X		quantum = 40L;
X#else
X	if(quantum < 20L)
X		quantum = 20L;
X#endif
X	qc1 = lrwt->to1 / quantum;
X	if(!qc1) qc1 = 1L;
X	qc2 = lrwt->to2 / quantum;
X	if(!qc2) qc2 = 1L;
X
X/* perform the lrtw function using nap() and rdchk()
X   input: qc1 is first nap count (for first charcters) 
X          qc2 is 2nd nap count (for subsequent characters) 
X          quantum is the nap period in milliseconds
X          cptr is char* to receive read string
X          max_count is max number of characters incl null
X          lrwt->raw_flag as described above
X
X  output: lrwt->count is actual count of return result
X          lrwt->buffer is return read buffer
X*/
X	max_count--;				/* leave room for null */
X
X	if(check_sigint)
X		ttymode(2);				/* let console interrupt long timeouts */
X
X	timeout_counter = qc1;		/* first timeout */ 
X	*cptr = 0;					/* init result string */
X	while(timeout_counter--)
X	{
X		nap(quantum);
X
X		if(check_sigint && interrupt)
X			goto INTERRUPTED;
X
X		while(lrdchk_xmtr())
X		{
X			*cptr = lgetc_xmtr();
X
X			if(check_sigint && interrupt)
X				goto INTERRUPTED;
X
X			if(*cptr == 0)
X				continue;
X
X			if(!raw_mode && (*cptr == CR))
X					continue;
X
X			if(lrwt->echo)
X				pputc(*cptr);
X
X			*++cptr = 0;
X			if(++actual_count == 1)
X			{
X				if(!lrwt->to2)
X					break;
X				timeout_counter = qc2;
X			}
X
X			if(--max_count == 0)
X				goto BOTTOM;
X
X			if(delim_len && (actual_count >= delim_len) &&
X					!strncmp(lrwt->delim,cptr - delim_len,delim_len))
X				goto BOTTOM;
X		}
X	}
X
X/******************************/
X#else /* other than NO_SELECT */
X/******************************/
X/* --- use select --- */
Xregister actual_count = 0;
Xregister char *cptr = lrwt->buffer;
Xregister max_count = lrwt->bufsize;
Xregister raw_mode = lrwt->raw_flag & 0x0F;
Xint check_sigint = (lrwt->raw_flag & 0x80);
Xint old_ttymode = get_ttymode();	/* save original tty mode */
Xint fdmask;
Xint delim_len;
Xstruct timeval tval;
Xchar *rtn_val;
X
X	delim_len = (lrwt->delim) ? strlen(lrwt->delim) : 0;
X
X	if((Lbaud < 300) && lrwt->to2)
X		if(lrwt->to2 < 300L) lrwt->to2 = 300L;
X	else if((Lbaud < 1200) && lrwt->to2)
X		if(lrwt->to2 < 200L) lrwt->to2 = 100L;
X
X	tval.tv_sec = lrwt->to1 / 1000L;
X	tval.tv_usec = (lrwt->to1 % 1000L) * 1000L;
X
X/* perform the lrtw function
X
X  output: lrwt->count is actual count of return result
X          lrwt->buffer is return read buffer
X*/
X	max_count--;				/* leave room for null */
X
X	if(check_sigint)
X		ttymode(2);				/* let console interrupt long timeouts */
X
X	*cptr = 0;					/* init result string */
X	while(1)
X	{
XCHECK_INTERRUPT:
X		if(check_sigint && interrupt)
X			goto INTERRUPTED;
X
X		errno = 0;
X		fdmask = 1 << Liofd;
X		if(select(32,&fdmask,(int *)0,(int *)0,&tval) != 1)
X		{
X			if(errno == EINTR)
X				continue;
X			break;
X		}
X
X		while(rdchk(Liofd))
X		{
X			*cptr = lgetc_xmtr();
X
X			if(check_sigint && interrupt)
X				goto INTERRUPTED;
X
X			if(lrwt->echo)
X				pputc(*cptr);
X
X			if(*cptr == 0)
X				continue;
X
X			if(!raw_mode && (*cptr == CR))
X					continue;
X
X			*++cptr = 0;
X
X			if(actual_count++ == 0)
X			{
X				if(!lrwt->to2)
X					break;
X				tval.tv_sec = lrwt->to2 / 1000L;
X				tval.tv_usec = (lrwt->to2 % 1000L) * 1000L;
X			}
X
X			if(--max_count == 0)
X				goto BOTTOM;
X
X			if(delim_len && (actual_count >= delim_len) &&
X					!strncmp(lrwt->delim,cptr - delim_len,delim_len))
X				goto BOTTOM;
X		}
X	}
X
X#endif	/* NO_SELECT */
X
X/********* common post processing for select() / no select() ************/
XBOTTOM:
X	if(check_sigint)
X		ttymode(old_ttymode);
X	if(raw_mode)
X	{
X		lrwt->count = actual_count;
X		return(lrwt->buffer);
X	}
X	cptr = lrwt->buffer;
X	while(((*cptr > 0) && (*cptr < SPACE)) || (*cptr >= DEL))
X		cptr++;
X	rtn_val = cptr;
X	actual_count = 0;
X	while(((*cptr &= 0x7F) >= SPACE) && (*cptr < DEL))
X	{
X		cptr++;
X		actual_count++;
X	}
X	*cptr = 0;
X	strcpy(lrwt->buffer,rtn_val);
X	lrwt->count = actual_count;
X	return(lrwt->buffer);
X
XINTERRUPTED:
X	ttymode(old_ttymode);
X	strcpy(lrwt->buffer,"!Interrupted");
X	lrwt->count = strlen(lrwt->buffer);
X	return((char *)0);
X
X}	/* end of lgets_timeout */
X
X/*+-------------------------------------------------------------------------
X	lgetc_timeout(msec) - may be called by xmtr only
X
X reads one character from line unless msec passes with no receipt.
X return char if received, else -1 if timeout
X--------------------------------------------------------------------------*/
Xint
Xlgetc_timeout(msec)
Xlong msec;
X{
Xuchar rtn_char;
X#if defined(NO_SELECT)
Xlong nap();
Xlong count;
X
XAGAIN:
X	count = msec;
X	while(!lrdchk_xmtr())
X	{
X		if(interrupt)
X			return(-1);
X		if((count -= nap(20L)) <= 0)
X			return(-1);
X	}
X
X#else
X
Xint fdmask;
Xstruct timeval tval;
X
XAGAIN:
X	tval.tv_sec = msec / 1000L;
X	tval.tv_usec = (msec % 1000L) * 1000L;
X	fdmask = 1 << Liofd;
X	if(select(32,&fdmask,(int *)0,(int *)0,&tval) < 1)
X		return(-1);
X	if(!lrdchk_xmtr())
X		return(-1);
X	if(interrupt)
X		return(-1);
X#endif
X
X	rtn_char = lgetc_xmtr();
X	if(!rtn_char)
X		goto AGAIN;
X	return(rtn_char);
X
X}	/* end of lgetc_timeout */
X
X/*+-------------------------------------------------------------------------
X	llookfor(lookfor,msecs,echo_flag)
Xreturn 1 if successful, else 0 if no match
X--------------------------------------------------------------------------*/
Xint
Xllookfor(lookfor,msecs,echo_flag)
Xchar *lookfor;
Xulong msecs;
Xint echo_flag;
X{
Xregister lookfor_len = strlen(lookfor);
Xregister lchar;
Xchar *lastfew = malloc(lookfor_len);
Xint success_flag = 0;
Xint old_ttymode = get_ttymode();
X
X	if(!lastfew)
X	{
X		pputs("memory exhausted\n");
X		return(0);
X	}
X
X	ttymode(2);
X
X	memset(lastfew,0,lookfor_len);
X	while((lchar = lgetc_timeout(msecs)) >= 0)
X	{
X		if(!lchar)		/* skip nulls */
X			continue;
X		if(echo_flag)
X			pputc(lchar);
X		memcpy(lastfew,lastfew + 1,lookfor_len - 1);
X		*(lastfew + lookfor_len - 1) = lchar;
X		if(!strncmp(lastfew,lookfor,lookfor_len))
X		{
X			success_flag = 1;
X			break;
X		}
X	}
X	free(lastfew);
X	ttymode(old_ttymode);
X	return(success_flag);
X}	/* end of llookfor */
X
X/*+-------------------------------------------------------------------------
X	lquiet(msecs,echo_flag)
X--------------------------------------------------------------------------*/
Xvoid
Xlquiet(msecs,echo_flag)
Xulong msecs;
Xint echo_flag;
X{
Xregister lchar;
Xint old_ttymode = get_ttymode();
X
X	ttymode(2);
X	while((lchar = lgetc_timeout(msecs)) >= 0)
X	{
X		if(interrupt)	/* if interrupt, return */
X			break;
X		if(!lchar)		/* skip nulls */
X			continue;
X		if(echo_flag)
X			pputc(lchar);
X	}
X	ttymode(old_ttymode);
X
X}	/* end of lquiet */
X
X/*+-------------------------------------------------------------------------
X	lflush(flush_type) -- flush line driver input &/or output buffers
X
X0 == input buffer
X1 == output buffer
X2 == both buffers
X--------------------------------------------------------------------------*/
Xvoid
Xlflush(flush_type)
Xint flush_type;
X{
X	xenix_lgetc_count = 0;
X	switch(flush_type)
X	{
X		case 0:
X			ioctl(TTYIN,TCFLSH,(char *)0); break;
X		case 1:
X			ioctl(TTYIN,TCFLSH,(char *)1); break;
X		case 2:
X			ioctl(TTYIN,TCFLSH,(char *)2); break;
X	}
X}	/* end of lflush */
X
X/*+-------------------------------------------------------------------------
X	lreset_ksr()
X
X  This procedure restores the termio for the
X  comm line to the values in Ltermio
X--------------------------------------------------------------------------*/
Xvoid
Xlreset_ksr()
X{
X	ioctl(Liofd,TCSETA,(char *)&Ltermio);
X
X}	/* end of lreset_ksr */
X
X/*+-----------------------------------------------------------------------
X	lputc(lchar) -- write lchar to comm line
X------------------------------------------------------------------------*/
Xvoid
Xlputc(lchar)
Xchar lchar;
X{
X	while(write(Liofd,&lchar,1) < 0)
X	{
X		if(errno == EINTR)
X			continue;
X		pperror("lputc write error");
X		hangup(HANGUP_XMTR_WRITE_ERROR);
X	}
X	xmit_chars++;
X	xmit_chars_this_connect++;
X}	/* end of lputc */
X
X/*+-----------------------------------------------------------------------
X	lputc_paced(pace_msec,lchar) -- write lchar to comm line
X  with time between each character 
X------------------------------------------------------------------------*/
Xvoid
Xlputc_paced(pace_msec,lchar)
Xregister pace_msec;
Xchar lchar;
X{
X
X	lputc(lchar);	
X	nap((long)(pace_msec ? pace_msec : LPUTS_NAP_COUNT));
X
X}	/* end of lputc_paced */
X
X/*+-----------------------------------------------------------------------
X	lputs(string) -- write string to comm line
X------------------------------------------------------------------------*/
Xvoid
Xlputs(string)
Xregister char *string;
X{
X	while(*string)
X		lputc(*string++);
X}
X
X/*+-----------------------------------------------------------------------
X	lputs_paced(pace_msec,string) -- write string to comm line
X  with time between each character 
X------------------------------------------------------------------------*/
Xvoid
Xlputs_paced(pace_msec,string)
Xregister pace_msec;
Xregister char *string;
X{
X	while(*string)
X		lputc_paced(pace_msec,*string++);
X
X}	/* end of lputs_paced */
X
X/*+-------------------------------------------------------------------------
X	valid_baud_rate(baud) -- returns (positive) baud rate selector
Xor -1 if invalid baud rate
X--------------------------------------------------------------------------*/
Xvalid_baud_rate(baud)
Xuint baud;
X{
X	switch(baud)
X	{
X		case 110: return(B110);
X		case 300: return(B300);
X		case 600: return(B600);
X		case 1200: return(B1200);
X		case 2400: return(B2400);
X		case 4800: return(B4800);
X		case 9600: return(B9600);
X		case 19200: return(EXTA);
X		case 38400: return(EXTB);
X		default: return(-1);
X	}
X
X}	/* end of valid_baud_rate */
X
X/*+-----------------------------------------------------------------------
X	lset_baud_rate(ioctl_flag)
X
X  If 'ioctl_flag' is set, then perform ioctl call
X  is executed after setting baud rate
X------------------------------------------------------------------------*/
Xlset_baud_rate(ioctl_flag)
Xint ioctl_flag;
X{
Xint baud_selector = valid_baud_rate(Lbaud);
X
X	if(baud_selector == -1)
X		baud_selector = valid_baud_rate(Lbaud = DEFAULT_BAUD_RATE);
X
X	Ltermio.c_cflag &= ~CBAUD;
X	Ltermio.c_cflag |= baud_selector;
X
X#if defined(HO_HUM)
X	if(ioctl_flag)
X#endif
X		 ioctl(Liofd,TCSETA,(char *)&Ltermio);
X	return(0);
X
X}	/* end of lset_baud_rate */
X
X/*+-------------------------------------------------------------------------
X	lnew_baud_rate(new_baud)
X--------------------------------------------------------------------------*/
Xint
Xlnew_baud_rate(new_baud)
Xuint new_baud;
X{
X	if(valid_baud_rate(new_baud) < 0)
X		return(-1);
X	if(Lbaud != new_baud)
X		Lmodem_already_init = 0;
X	Lbaud = new_baud;
X	lset_baud_rate(1);
X	return(0);
X}	/* end of lnew_baud_rate */
X
X/*+-----------------------------------------------------------------------
X	lset_parity(ioctl_flag)
X
X  If 'ioctl_flag' is set, then perform ioctl call
X  is executed after setting parity
X------------------------------------------------------------------------*/
Xvoid
Xlset_parity(ioctl_flag)
Xint ioctl_flag;
X{
X	Ltermio.c_cflag &= ~(CS8 | PARENB | PARODD);
X	switch(to_lower(Lparity))
X	{
X		case 'e':
X			Ltermio.c_cflag |= CS7 | PARENB;
X			Ltermio.c_iflag |= ISTRIP;
X			break;
X		case 'o':
SHAR_EOF
echo "End of part 5"
echo "File eculine.c is continued in part 6"
echo "6" > s2_seq_.tmp
exit 0
-- 
-------------------------------------------------------------------
Warren Tucker, Tridom Corporation       ...!gatech!emory!tridom!wht 
Ker-au'-lo-phon.  An 8-foot partial flue-stop, having metal pipes
surmounted by adjustable rings, and with a hole bored near the top
of each pipe, producing a soft and "reedy" tone.



More information about the Alt.sources mailing list