ads - XENIX V/386 async data scope part 1/3

Warren Tucker wht at tridom.uucp
Tue Sep 26 05:40:58 AEST 1989


ads 1.00 - Asynchronous Data Scope for SCO XENIX 386
...!gatech!emory!tridom!wht

This program acts as a data scope of sorts for asynchronous lines
on SCO XENIX 386 systems. The program lets you display the traffic
between any two tty lines. A log and replay feature is supported
in two ways:  either during the data scope session or off-line
using an auxiliary program (adsplog).

---- Cut Here and unpack ----
#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#	Packed Mon Sep 25 15:22:54 EDT 1989 by wht
#	from directory /u1/src/ads
#
# This is part 1 of a multipart archive                                    
# do not concatenate these parts, unpack them in order with /bin/sh        
#
#	Run the following text with /bin/sh to create:
#	  Makefile
#	  README
#	  ads.c
#	  ads.h
#	  adsfuncs.h
#	  adsplog.c
#	  afterlint.c
#	  cmdline.c
#	  curseslint.h
#	  keyboard.h
#	  lineio.c
#	  screen.c
#	  time.c
#	  x386sel/fixttiocom.c
#	  x386sel/select-update
#	  x386sel/select.asm
#	  x386sel/select.txt
#	  x386sel/ttiocom.c
#	  zgcc
#
if test -r s2_seq_.tmp
then echo "Must unpack archives in sequence!"
     next=`cat s2_seq_.tmp`; echo "Please unpack part $next next"
     exit 1; fi
echo "x - extracting Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X# Makefile for ads
X#+:EDITS:
X#:09-22-1989-18:57-wht-add adsplog
X#:05-14-1989-16:33-wht-creation
X
X.SUFFIXES: .o .c .h
X
XSHELL = /bin/sh
X
XCOMMONFLAGS = -i -Zi #-Ox
XCFLAGS = $(COMMONFLAGS) -c -DLINT_ARGS
XLFLAGS = $(COMMONFLAGS) -ltcap -ltermlib -lx
X.c.o:;	cc $(CFLAGS) $*.c
X
XSRC = \
X	ads.c\
X	adsplog.c\
X	cmdline.c\
X	lineio.c\
X	screen.c\
X	time.c
X
XADS_OBJ	= \
X	ads.o\
X	cmdline.o\
X	lineio.o\
X	screen.o\
X	time.o
X
XADSPLOG_OBJ = \
X	adsplog.o\
X	time.o
X
XSHAR_FILES = \
X	Makefile\
X	README\
X	ads.c\
X	ads.h\
X	adsfuncs.h\
X	adsplog.c\
X	afterlint.c\
X	cmdline.c\
X	curseslint.h\
X	keyboard.h\
X	lineio.c\
X	screen.c\
X	time.c\
X	x386sel/fixttiocom.c\
X	x386sel/select-update\
X	x386sel/select.asm\
X	x386sel/select.txt\
X	x386sel/ttiocom.c\
X	zgcc
X
Xall: ads adsplog
X
Xads: $(ADS_OBJ)
X	cc $(LFLAGS) $(ADS_OBJ) -o $@
X
Xadsplog: $(ADSPLOG_OBJ)
X	cc $(LFLAGS) $(ADSPLOG_OBJ) -o $@
X
Xads.fls: $(SRC)
X	ls $(SRC) >ads.fls
X
Xlint: ads.fls afterlint
X	echo > adsfuncs.h
X	csh zgcc ads.fls adsfuncs.h $(CFLAGS)
X
Xclean:
X	rm -f $(ADS_OBJ) $(ADSPLOG_OBJ)
X
Xclobber: clean
X	rm -f ads
X
Xafterlint:
X	cc -Ox afterlint.c -o $@
X
Xshar:
X	shar -v -D -c -o/tmp/ads.sh. -l32 $(SHAR_FILES)
X
X#
X# MAKE DEPEND: regenerate .c:.h, .ol:.c, .ol:.asm dependencies automatically
X#
Xdepend:
X		rm -f depend.tmp
X		if test '$(SRC)' ;\
X		then (grep '^#include' $(SRC) \
X		| sed	-e 's?:[^<]*<\([^>]*\)>.*?: /usr/include/\1?'\
X			-e 's?:[^"]*"\([^"]*\)".*?: \1?'\
X			-e 's?\(.*\)\.c?\1.o?'\
X		 >> depend.tmp) ;\
X		fi
X
X		echo '/^# DO NOT DELETE THIS LINE' >exdep.tmp
X		echo '.+1,$$d' >>exdep.tmp
X		echo 'r depend.tmp' >> exdep.tmp
X		echo 'w' >> exdep.tmp
X		cp Makefile Makefile.new
X		ex Makefile.new < exdep.tmp
X		/bin/rm exdep.tmp depend.tmp
X		echo '#	DEPENDENCIES MUST END AT END OF	FILE' >>Makefile.new
X		echo '#	IF YOU PUT STUFF HERE IT WILL GO AWAY'>>Makefile.new
X		echo '#	see make depend	above'>>Makefile.new
X		mv Makefile Makefile.bak
X		mv Makefile.new Makefile
X
X# DO NOT DELETE THIS LINE
Xads.o: /usr/include/curses.h
Xads.o: /usr/include/sys/select.h
Xads.o: ads.h
Xadsplog.o: /usr/include/stdio.h
Xadsplog.o: ads.h
Xcmdline.o: ads.h
Xlineio.o: ads.h
Xscreen.o: /usr/include/curses.h
Xscreen.o: ads.h
Xscreen.o: keyboard.h
Xtime.o: /usr/include/stdio.h
Xtime.o: /usr/include/sys/time.h
Xtime.o: ads.h
X#	DEPENDENCIES MUST END AT END OF	FILE
X#	IF YOU PUT STUFF HERE IT WILL GO AWAY
X#	see make depend	above
SHAR_EOF
chmod 0644 Makefile || echo "restore of Makefile fails"
echo "x - extracting README (Text)"
sed 's/^X//' << 'SHAR_EOF' > README &&
X
Xads 1.00 - Asynchronous Data Scope for SCO XENIX 386
X...!gatech!emory!tridom!wht
X
XThis program acts as a data scope of sorts for asynchronous lines
Xon SCO XENIX 386 systems. The program lets you display the traffic
Xbetween any two tty lines. A log and replay feature is supported
Xin two ways:  either during the data scope session or off-line
Xusing an auxiliary program (adsplog).
X
XUse ads to display on-line data, log and replay during a test.
XUse adsplog to display log files after testing has been completed.
X
XSCO XENIX V/386 Release 2.3.1 (and evidently 2.3.2) have
Xa broken-dead, yet fixable, BSD-style select() feature which is
Xneeded to support ads.  Also, select() is missing from libc.a.
XThe x386sel subdirectory in this release
Xhas information (thanks to csch at netcs, ivar at acc, and ag at elgar)
Xon how to fix the kernel and to add select() to libc.a.
X
XUsage for ads can be obtained by running the program without
Xarguments.  Sinc adsplog has default actions when no arguments are
Xgiven, usage information is given here:
X
Xusage: adsplog [-t] [logname]
X-t causes elapsed time information to be displayed.
Xlogname defaults to 'ads.log' (the name used by ads)
X
Xafterlint and zgcc are used to build header file adsfuncs.h
Xand may have other applications.
X
XFiles:
X-------------------------
XMakefile
XREADME
Xads.c
Xads.h
Xadsfuncs.h
Xadsplog.c
Xafterlint.c
Xcmdline.c
Xcurseslint.h
Xkeyboard.h
Xlineio.c
Xscreen.c
Xtime.c
Xx386sel/fixttiocom.c
Xx386sel/select-update
Xx386sel/select.asm
Xx386sel/select.txt
Xx386sel/ttiocom.c
Xzgcc
SHAR_EOF
chmod 0644 README || echo "restore of README fails"
echo "x - extracting ads.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ads.c &&
Xchar *revision = "1.00";
X/*+-------------------------------------------------------------------------
X	ads.c - async data scope for SCO XENIX V/386
X	...!gatech!emory!tridom!wht
X
X  Defined functions:
X	ads()
X	adslog(line)
X	adslog_control(state)
X	adslog_init(line)
X	adslog_read(pdevice,ptime_then,buf,bufmax,pcount)
X	adsplay()
X	endprog()
X	main(argc,argv,envp)
X	main_label()
X	play_label(eof)
X
XThis program was put together using several "junkbox" code fragments and
Xain't (Southern USA for 'isn't) exactly as small as it could be.
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:09-22-1989-19:35-wht-more logging features */
X/*:09-06-1989-21:24-wht-logging */
X/*:05-13-1989-16:14-wht-creation */
X
X#define M_TERMCAP
X#include <curses.h>
X#include <sys/select.h>
X#include "ads.h"
X
XWINDOW *window_create();
Xlong time();
Xchar *strchr();
Xchar *secs_to_str();
X
XLCB lcbs[2];
XLCB *l0 = &lcbs[0];
XLCB *l1 = &lcbs[1];
Xint logging = 0;
XFILE *fplog = (FILE *)0;
Xchar *adslog_name = LOGNAME;
Xchar title[32];
Xchar devname0[32];
Xchar devname1[32];
XWINDOW *win;
Xint ymax;
Xlong time0;
Xlong time_now;
X
X/*+-------------------------------------------------------------------------
X	endprog() - end program cleanly
X--------------------------------------------------------------------------*/
Xvoid
Xendprog()
X{
X	windows_end();
X	exit(0);
X}	/* end of endprog */
X
X/*+-------------------------------------------------------------------------
X	main_label() - display main screen label
X--------------------------------------------------------------------------*/
Xvoid
Xmain_label()
X{
X	clear_area(win,1,2,75);
X	wstandout(win);
X	waddstr(win," on line ");
X	wstandend(win);
X	waddstr(win,
X		"      commands: l-log on n-log off r-replay log e-erase log q-quit");
X	wrefresh(win);
X}	/* end of main_label */
X
X/*+-------------------------------------------------------------------------
X	play_label(eof) - display replay screen label
X--------------------------------------------------------------------------*/
Xvoid
Xplay_label(eof)
Xint eof;
X{
X	clear_area(win,1,2,75);
X	wstandout(win);
X	if(eof)
X	{
X		waddstr(win," replay EOF ");
X		wstandend(win);
X		waddstr(win,
X			"                                      commands: r-rewind q-quit");
X	}
X	else
X	{
X		waddstr(win," replaying  ");
X		wstandend(win);
X		waddstr(win,
X			" commands: f-faster s-slower p-pause c-continue r-rewind q-quit");
X	}
X	wrefresh(win);
X}	/* end of play_label */
X
X/*+-------------------------------------------------------------------------
X	adslog_init(line) - initialize/reset logging buffer in lcb
X--------------------------------------------------------------------------*/
Xvoid
Xadslog_init(line)
XLCB *line;
X{
X	line->logbuf_ptr = line->logbuf;
X	line->logbuf_count = 0;
X}	/* end of adslog_init */
X
X/*+-------------------------------------------------------------------------
X	adslog(line) - write log information for line to log file
X--------------------------------------------------------------------------*/
Xvoid
Xadslog(line)
XLCB *line;
X{
Xlong time_val = time((long *)0);
X
X	if(!line->logbuf_count)
X		return;
X	fputc(((line->line_num) ? 0x80 : 0) + line->logbuf_count,fplog);
X	fwrite((char *)&time_val,sizeof(long),1,fplog);
X	fwrite(line->logbuf,1,line->logbuf_count,fplog);
X	adslog_init(line);
X
X}	/* end of adslog */
X
X/*+-------------------------------------------------------------------------
X	adslog_read(ptime_then,buf,bufmax,pcount) - read log file
X--------------------------------------------------------------------------*/
Xint
Xadslog_read(pdevice,ptime_then,buf,bufmax,pcount)
Xint *pdevice;
Xlong *ptime_then;
Xchar *buf;
Xint bufmax;
Xint *pcount;
X{
Xint itmp;
Xint first_byte;
X
X	if((first_byte = fgetc(fplog)) == EOF)
X		return(EOF);
X	if(fread((char *)ptime_then,sizeof(long),1,fplog) != 1)
X		return(EOF);
X	*buf = 0;
X
X	switch(first_byte & 0xFF)
X	{
X		case LOG_OPEN:
X			fgets(buf,bufmax,fplog);
X			if(itmp = strlen(buf))
X				buf[itmp - 1] = 0;
X			return(LOG_OPEN);
X
X		case LOG_TIMEOUT:
X			return(adslog_read(pdevice,ptime_then,buf,bufmax,pcount));
X
X		case LOG_CLOSE:
X			if(itmp = strlen(buf))
X				buf[itmp - 1] = 0;
X			return(LOG_CLOSE);
X	}
X
X	*pdevice = (first_byte & 0x80) ? 1 : 0;
X	*pcount = first_byte & 0x7F;
X
X	if(fread(buf,1,*pcount,fplog) != *pcount)
X		return(EOF);
X
X	return(*pdevice);
X
X}	/* end of adslog_read */
X
X/*+-------------------------------------------------------------------------
X	adslog_control(state) - turn on/off logging, display state on screen
X--------------------------------------------------------------------------*/
Xvoid
Xadslog_control(state)
Xint state;
X{
Xint y,x;
X
X	getyx(win,y,x);
X	switch(state)
X	{
X		case 1:
X			if(logging)
X				break;
X			if(fplog = fopen(adslog_name,"a"))
X			{
X				logging = 1;
X				adslog_init(l0);
X				adslog_init(l1);
X				wmove(win,0,64);
X				waddstr(win," logging on  ");
X				wmove(win,y,x);
X				wrefresh(win);
X				fputc(LOG_OPEN,fplog);
X				time_now = time((long *)0);
X				fwrite((char *)&time_now,sizeof(time_now),1,fplog);
X				fprintf(fplog,"%s %s\n",devname0,devname1);
X			}
X			else
X				fputc(7,stderr);
X			break;
X		case 0:
X			wmove(win,0,64);
X			wstandout(win);
X			waddstr(win," logging off ");
X			wstandend(win);
X			wmove(win,y,x);
X			wrefresh(win);
X			if(!logging)
X				break;
X			adslog(l0);
X			adslog(l1);
X			fputc(LOG_CLOSE,fplog);
X			time_now = time((long *)0);
X			fwrite((char *)&time_now,sizeof(time_now),1,fplog);
X			fclose(fplog);
X			logging = 0;
X			fplog = (FILE *)0;
X			wmove(win,y,x);
X			wrefresh(win);
X			break;
X	}
X}	/* end of adslog_control */
X
X/*+-------------------------------------------------------------------------
X	no_log_file() - tell user that no log file can be found
X--------------------------------------------------------------------------*/
Xvoid
Xno_log_file()
X{
X	clear_area(win,1,2,75);
X	wstandout(win);
X	waddstr(win," no log file ... press any key to continue ");
X	wstandend(win);
X	wrefresh(win);
X	ttygetc(0);
X	main_label();
X
X}	/* end of no_log_file */
X
X/*+-------------------------------------------------------------------------
X	adsplay() - replay log
X--------------------------------------------------------------------------*/
Xvoid
Xadsplay()
X{
Xregister itmp;
Xregister printable;
Xint device;
Xint count;
Xint y;
Xint x = 2;
Xint log_type;
Xint cmd;
Xlong nap_msec;
Xlong time_then;
Xchar buf[128];
Xchar *bptr;
X
X	if(!(fplog = fopen(adslog_name,"r")))
X	{
X		no_log_file();
X		return;
X	}
X
X	for(y = 2; y < ymax + 1; y++)
X		clear_area(win,y,2,75);
X
X	y = 5;
X	wmove(win,y,x);
X	wstandout(win);
X	waddstr(win," log segments recorded: ");
X	wstandend(win);
X	wrefresh(win);
X	y += 2;
X	while((log_type = adslog_read(&device,&time_then,buf,
X		sizeof(buf),&count)) != EOF)
X	{
X		if(log_type != LOG_OPEN)
X			continue;
X		wmove(win,y++,x);
X		waddstr(win,buf);
X		waddstr(win," on ");
X		waddstr(win,secs_to_str(time_then,4,(char *)0));
X	}
X	y++;
X	wmove(win,y,x);
X	wstandout(win);
X	waddstr(win," press space to replay, 'q' to quit ");
X	wstandend(win);
X	wrefresh(win);
X
XSO_SUE_ME:	/* labels have their place */
X	switch(cmd = ttygetc(0))
X	{
X		case ' ':
X			break;
X		case 'q':
X			y++;
X			for(itmp = 2; itmp < y; itmp++)
X				clear_area(win,itmp,2,75);
X			y = 3;
X			wmove(win,y,x);
X			fclose(fplog);
X			return;
X		default:
X			fputc(7,stderr);
X			goto SO_SUE_ME;
X	}
X
X	y++;
X	for(itmp = 2; itmp < y; itmp++)
X		clear_area(win,itmp,2,75);
X
XREWIND:
X	play_label(0);
X	y = 3;
X	x = 2;
X	fclose(fplog);						/* clearerr(fplog), rewind(fplog) ... */
X	fplog = fopen(adslog_name,"r");		/* ... did not seem to work */
X	nap_msec = 0L;
X	while((log_type = adslog_read(&device,&time_then,buf,sizeof(buf),&count))
X		!= EOF)
X	{
X		switch(log_type)
X		{
X			case LOG_OPEN:
X			case LOG_TIMEOUT:
X			case LOG_CLOSE:
X				continue;
X		}
X
X		bptr = buf;
X		while(count--)
X		{
X			wmove(win,y,x);
X			if(!device)
X				wstandout(win);
X			printable = *bptr & 0x7F;
X			if((printable >= 0x20) && (printable != 0x7F))
X				wprintw(win,"%c%02x",printable,*bptr);
X			else
X				wprintw(win,".%02x",*bptr);
X			if(!device)
X				wstandend(win);
X			waddch(win,' ');
X			x += 4;
X			if(x > 75)
X			{
X				y++;
X				x = 2;
X				if(y > ymax)
X				{
X					y = 3;
X					if(!nap_msec)
X						nap_msec = 300L;
X				}
X				if(y <= ymax)
X				{
X					clear_area(win,y,x,75);
X					if(y + 1 <= ymax)
X						clear_area(win,y + 1,x,75);
X				}
X				if(nap_msec)
X				{
X					wrefresh(win);
X					nap(nap_msec);
X				}
X			}
X			wrefresh(win);
X			bptr++;
X			if(rdchk(0))
X			{
XGET_CMD:
X				switch(cmd = ttygetc(0))
X				{
X					case 'f':
X						if(nap_msec > 50)
X							nap_msec -= 50;
X						break;
X					case 's':
X						nap_msec += 50;
X						break;
X					case 'p':
X						goto GET_CMD;
X					case 'c':
X						break;
X					case 'r':
X						for(y = 2; y < ymax + 1; y++)
X							clear_area(win,y,2,75);
X						wrefresh(win);
X						goto REWIND;
X					case 'q':
X						fclose(fplog);
X						return;
X					default:
X						fputc(7,stderr);
X						break;
X				}
X			}
X		}
X	}
X	fclose(fplog);
X	play_label(1);
X	while(1)
X	{
X		switch(cmd = ttygetc(0))
X		{
X			case 'r':
X				for(y = 2; y < ymax + 1; y++)
X					clear_area(win,y,2,75);
X				wrefresh(win);
X				goto REWIND;
X			case 'q':
X				fclose(fplog);
X				return;
X			default:
X				fputc(7,stderr);
X				break;
X
X		}
X	}
X
X}	/* end of adsplay */
X
X/*+-------------------------------------------------------------------------
X	ads() - display async traffic on main screen, optionally logging
X--------------------------------------------------------------------------*/
Xvoid
Xads()
X{
Xint fdmask;
Xint fdmask_l0  = 1 << l0->iofd;
Xint fdmask_l1  = 1 << l1->iofd;
Xint fdmask_kbd = 1 << 0;
Xint fdmask_source = fdmask_l0 | fdmask_l1 | fdmask_kbd;
Xunsigned char rdchar;
Xint y = 3;
Xint x = 2;
Xstruct timeval timeval_500msec;
Xstruct stat statbuf;
X
X	adslog_init(l0);
X	adslog_init(l1);
X
X	while(1)
X	{
X		fdmask = fdmask_source;
X		timeval_500msec.tv_sec = 0;
X		timeval_500msec.tv_usec = 500L * 1000L;
X		select(32,&fdmask,(int *)0,(int *)0,&timeval_500msec);
X		if(!fdmask && logging)
X		{
X			adslog(l0);
X			adslog(l1);
X			fputc(LOG_TIMEOUT,fplog);
X			time_now = time((long *)0);
X			fwrite((char *)&time_now,sizeof(time_now),1,fplog);
X		}
X		if(fdmask & fdmask_l0)
X		{
X			while(rdchk(l0->iofd))
X			{
X				read(l0->iofd,l0->logbuf_ptr,1);
X				write(l1->iofd,l0->logbuf_ptr,1);
X				rdchar = *l0->logbuf_ptr & 0x7F;
X				wmove(win,y,x);
X				wstandout(win);
X				if((rdchar >= 0x20) && (rdchar != 0x7F))
X					wprintw(win,"%c%02x",rdchar,rdchar);
X				else
X					wprintw(win,".%02x",rdchar);
X				wstandend(win);
X				waddch(win,' ');
X				x += 4;
X				if(x > 75)
X				{
X					y++;
X					x = 2;
X					if(y > ymax)
X						y = 3;
X					if(y <= ymax)
X					{
X						clear_area(win,y,2,75);
X						if(y + 1 <= ymax)
X							clear_area(win,y + 1,2,75);
X					}
X					wrefresh(win);
X				}
X				if(logging)
X				{
X					adslog(l1);
X					l0->logbuf_ptr++;
X					if(++l0->logbuf_count == LOGBUFMAX)
X						adslog(l0);
X				}
X			}
X			wrefresh(win);
X		}
X		if(fdmask & fdmask_l1)
X		{
X			while(rdchk(l1->iofd))
X			{
X				read(l1->iofd,l1->logbuf_ptr,1);
X				write(l0->iofd,l1->logbuf_ptr,1);
X				rdchar = *l1->logbuf_ptr & 0x7F;
X				wmove(win,y,x);
X				if((rdchar >= 0x20) && (rdchar != 0x7F))
X					wprintw(win,"%c%02x ",rdchar,rdchar);
X				else
X					wprintw(win,".%02x ",rdchar);
X				x += 4;
X				if(x > 75)
X				{
X					y++;
X					x = 2;
X					if(y > ymax)
X						y = 3;
X					if(y <= ymax)
X					{
X						clear_area(win,y,2,75);
X						if(y + 1 <= ymax)
X							clear_area(win,y + 1,2,75);
X					}
X					wrefresh(win);
X				}
X				if(logging)
X				{
X					adslog(l0);
X					l1->logbuf_ptr++;
X					if(++l1->logbuf_count == LOGBUFMAX)
X						adslog(l1);
X				}
X			}
X			wrefresh(win);
X		}
X		if(fdmask & fdmask_kbd)
X		{
X			switch(rdchar = ttygetc(0))
X			{
X				case 'l':
X					adslog_control(1);
X					break;
X				case 'n':
X					adslog_control(0);
X					break;
X				case 'e':
X#if defined(NEUROTIC)
X					if(stat(adslog_name,&statbuf))
X					{
X						no_log_file();
X						break;
X					}
X#endif
X					clear_area(win,1,2,75);
X					wstandout(win);
X					waddstr(win," erase log file (y,n)? ");
X					wstandend(win);
X					wrefresh(win);
X					if(ttygetc(0) == 'y')
X					{
X						adslog_control(0);
X						unlink(adslog_name);
X					}
X					main_label();
X					break;
X				case 'r':
X					adslog_control(0);
X					adsplay();
X					main_label();
X					x = 2;
X					for(y = 2; y < ymax + 1; y++)
X						clear_area(win,y,2,75);
X					y = 3;
X					wmove(win,y,x);
X					wrefresh(win);
X					break;
X				case 'q':
X					adslog_control(0);
X					return;
X			}
X		}
X	}
X}	/* end of ads */
X
X/*+-------------------------------------------------------------------------
X	main(argc,argv,envp)
X--------------------------------------------------------------------------*/
Xmain(argc,argv,envp)
Xint argc;
Xchar **argv;
Xchar **envp;
X{
Xint itmp;
Xint y,x;
Xchar *parity_string();
Xchar *lopen_err_text();
X
X	cmdline(argc,argv);
X
X	if(itmp = lopen(l0))
X	{
X		fprintf(stderr,"line 1: %s\n",lopen_err_text(itmp));
X		exit(1);
X	}
X
X	if(itmp = lopen(l1))
X	{
X		fprintf(stderr,"line 2: %s\n",lopen_err_text(itmp));
X		exit(1);
X	}
X	l0->line_num = 0;
X	l1->line_num = 1;
X
X	lflush(l0);
X	lflush(l1);
X
X	signal(SIGHUP,endprog);
X	signal(SIGTERM,endprog);
X	signal(SIGINT,endprog);
X
X	windows_start();
X	ymax = LINES - 3;
X	sprintf(title,"ads %s",revision);
X	if(!(win = window_create(title,3,0,0,LINES-1,COLS - 1)))
X	{
X		windows_end();
X		fprintf(stderr,"cannot create window!\n");
X		exit(0);
X	}
X
X	sprintf(devname0,"%s-%u-%c",l0->line + 5,
X		l0->baud,l0->parity,l0->baud,l0->parity);
X	wmove(win,0,18);
X	wstandout(win);
X	waddch(win,' ');
X	waddstr(win,devname0);
X	waddch(win,' ');
X	wstandend(win);
X
X	sprintf(devname1,"%s-%u-%c",l1->line + 5,
X		l1->baud,l1->parity,l0->baud,l0->parity);
X	getyx(win,y,x);
X	wmove(win,y,x + 2);
X	waddch(win,' ');
X	waddstr(win,devname1);
X	waddch(win,' ');
X
X	main_label();
X	adslog_control(0);
X	ads();
X
X	windows_end();
X	exit(0);
X}	/* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of ads.c */
SHAR_EOF
chmod 0644 ads.c || echo "restore of ads.c fails"
echo "x - extracting ads.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > ads.h &&
X/*+-------------------------------------------------------------------------
X	ads.h
X	...!gatech!emory!tridom!wht
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:05-13-1989-15:44-wht-creation */
X
X#if !defined(WINDOW)		/* if curses.h not installed */
X#include <stdio.h>
X#include <termio.h>
X#else
X#ifdef LINT_ARGS
X#include "curseslint.h"
X#endif
X#endif
X#include <ctype.h>
X#include <fcntl.h>
X#include <signal.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <errno.h>
X
X#if !defined(ushort)
X#define ushort unsigned short
X#endif
X#if !defined(uchar)
X#define uchar unsigned char
X#endif
X#if !defined(uint)
X#define uint unsigned int
X#endif
X#if !defined(ulong)
X#define ulong unsigned long
X#endif
X
X#define ff fprintf
X#define se stderr
X
X/* log-related definitions */
X#define LOGNAME	"ads.log"
X#define LOGBUFMAX	64
X#define LOG_OPEN	0xF1
X#define LOG_TIMEOUT	0xF2
X#define LOG_CLOSE	0xF3
X
X/* lopen() and related routines error codes */
X#define LOPEN_INVALID	-1		/* for invalid tty name */
X#define LOPEN_OPNFAIL	-2		/* could not open line */
X
Xtypedef struct lcb
X{
X	int iofd;					/* file descriptor for line */
X	int parity;					/* 0==NONE, 'e' == even, 'o' == odd */
X	int	line_num;				/* line number: 0 or 1 */
X	char LCKname[128];			/* lock file name */
X	uint baud;					/* baud rate */
X	char descr[64];				/* description of remote */
X	char line[64];				/* /dev/ttyname for outgoing line */
X	struct termio termio;		/* attributes for the line to remote */
X	char logbuf[LOGBUFMAX];		/* log buffer */
X	char *logbuf_ptr;			/* pointer into log buffer */
X	int logbuf_count;			/* count of characters in log buffer */
X}	LCB;
X
Xextern LCB lcbs[];
X
X#include "adsfuncs.h"
SHAR_EOF
chmod 0644 ads.h || echo "restore of ads.h fails"
echo "x - extracting adsfuncs.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > adsfuncs.h &&
X/*+-----------------------------------------------------------------------
X	adsfuncs.h
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:09-25-1989-15:20-afterlint-creation */
X
X#ifndef BUILDING_LINT_ARGS
X#ifdef LINT_ARGS
X
X/* ads.c */
Xint adslog_read(int *,long *,char *,int ,int *);
Xint main(int ,char * *,char * *);
Xvoid ads(void);
Xvoid adslog(struct lcb *);
Xvoid adslog_control(int );
Xvoid adslog_init(struct lcb *);
Xvoid adsplay(void);
Xvoid endprog(void);
Xvoid main_label(void);
Xvoid no_log_file(void);
Xvoid play_label(int );
X/* adsplog.c */
Xint main(int ,char * *,char * *);
Xvoid logdump(char *,int ,int );
Xvoid logdump16(unsigned short );
Xvoid logdump4(unsigned char );
Xvoid logdump8(unsigned char );
X/* cmdline.c */
Xchar *str_token(char *,char *);
Xint cmdline(int ,char * *);
Xvoid parse_tty_arg(char *,struct lcb *);
Xvoid usage(char *,char *);
X/* lineio.c */
Xchar *lopen_err_text(int );
Xint lopen(struct lcb *);
Xint lset_baud_rate(struct lcb *,int );
Xint valid_baud_rate(unsigned int );
Xvoid lbreak(struct lcb *);
Xvoid lclear_xoff(struct lcb *);
Xvoid lclose(struct lcb *);
Xvoid lflush(struct lcb *);
Xvoid lget_xon_xoff(struct lcb *,int *,int *);
Xvoid lset_parity(struct lcb *,int );
Xvoid ltoggle_dtr(struct lcb *);
Xvoid lxon_xoff(struct lcb *,int );
X/* screen.c */
Xint winbox(struct _win_st *);
Xint winget_single(struct _win_st *,char *,char *);
Xint wingets(struct _win_st *,int ,int ,char *,int ,unsigned char *,int );
Xstruct _win_st *window_create(char *,int ,int ,int ,int ,int );
Xunsigned int ttygetc(int );
Xvoid clear_area(struct _win_st *,int ,int ,int );
Xvoid clear_area_char(struct _win_st *,int ,int ,int ,char );
Xvoid putc_stderr(char );
Xvoid window_setup(struct _win_st *,char *,int );
Xvoid windows_end(void);
Xvoid windows_start(void);
X/* time.c */
Xchar *get_elapsed_time(long );
Xchar *get_tod(int ,char *);
Xchar *secs_to_str(long ,int ,char *);
X
X#else		/* compiler doesn't know about prototyping */
X
X/* ads.c */
Xvoid ads();
Xvoid adslog();
Xvoid adslog_control();
Xvoid adslog_init();
Xvoid adsplay();
Xvoid endprog();
Xvoid main_label();
Xvoid no_log_file();
Xvoid play_label();
X/* adsplog.c */
Xvoid logdump();
Xvoid logdump16();
Xvoid logdump4();
Xvoid logdump8();
X/* cmdline.c */
Xchar *str_token();
Xvoid parse_tty_arg();
Xvoid usage();
X/* lineio.c */
Xchar *lopen_err_text();
Xvoid lbreak();
Xvoid lclear_xoff();
Xvoid lclose();
Xvoid lflush();
Xvoid lget_xon_xoff();
Xvoid lset_parity();
Xvoid ltoggle_dtr();
Xvoid lxon_xoff();
X/* screen.c */
Xstruct _win_st *window_create();
Xunsigned int ttygetc();
Xvoid clear_area();
Xvoid clear_area_char();
Xvoid putc_stderr();
Xvoid window_setup();
Xvoid windows_end();
Xvoid windows_start();
X/* time.c */
Xchar *get_elapsed_time();
Xchar *get_tod();
Xchar *secs_to_str();
X
X#endif /* LINT_ARGS */
X#endif /* BUILDING_LINT_ARGS */
X
X/* end of adsfuncs.h */
SHAR_EOF
chmod 0644 adsfuncs.h || echo "restore of adsfuncs.h fails"
echo "x - extracting adsplog.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > adsplog.c &&
X/*+-------------------------------------------------------------------------
X	adsplog.c - display log files produced by ads
X	...!gatech!emory!tridom!wht
X
X  usage: adsplog [-t] [logname]
X  -t causes elapsed time information to be displayed.
X  logname defaults to 'ads.log' (the name used by ads)
X
X  Defined functions:
X	secs_to_str(secs,type,buf)
X	get_elapsed_time(elapsed_seconds)
X	get_tod(type,buf)
X	logdump(str,count,offset)
X	logdump16(int16)
X	logdump4(int4)
X	logdump8(int8)
X	main(argc,argv,envp)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:09-22-1989-19:42-wht-more logging features */
X/*:09-06-1989-21:24-wht-creation */
X
X#include <stdio.h>
X#include "ads.h"
X
XFILE *fplog;
Xchar *adslog_name = LOGNAME;
Xlong time0 = -1;
X
X/*+-----------------------------------------------------------------------
X	logdump#... subservient routines
X------------------------------------------------------------------------*/
Xvoid logdump4(int4)
Xuchar int4;
X{
X	int4 &= 15;
X	putchar((int4 >= 10) ? (int4 + 'A' - 10) : (int4 + '0'));
X}
X
Xvoid logdump8(int8)
Xuchar int8;
X{
X	logdump4(int8 >> 4);
X	logdump4(int8);
X}
X
Xvoid logdump16(int16)
Xushort int16;
X{
X	logdump8(int16 >> 8);
X	logdump8(int16);
X}
X
X
X/*+-----------------------------------------------------------------
X	logdump(str,count,offset)
X------------------------------------------------------------------*/
Xvoid
Xlogdump(str,count,offset)
Xchar *str;
Xint count;
Xint offset;
X{
Xint istr = 0;
Xregister ipos;
Xregister itmp;
X
X	while(istr < count)
X	{
X		logdump8(istr + offset);
X		putchar(' ');
X		for(itmp = 0; itmp < 16; ++itmp)
X		{
X			ipos = istr + itmp;
X			if(ipos >= count)
X			{
X				fputs("   ",stdout);
X				continue;
X			}
X			putchar(' ');
X			logdump8(str[ipos]);
X		}
X		fputs(" | ",stdout);
X		for(itmp = 0; itmp < 16; ++itmp)
X		{
X			ipos = istr + itmp;
X			if( (ipos) >= count)
X				putchar(' ');
X			else
X			{
X				putchar((str[ipos] >= ' ' && str[ipos] < 0x7f)
X		 			? str[ipos] : '.' );
X			}
X		}
X		istr += 16;
X		fputs(" |\n",stdout);
X		if(istr < count)
X			fputs("   ",stdout);
X	}   /* end of while(istr < count) */
X
X}	/* end of logdump */
X
X/*+-------------------------------------------------------------------------
X	main(argc,argv,envp)
X--------------------------------------------------------------------------*/
Xmain(argc,argv,envp)
Xint argc;
Xchar **argv;
Xchar **envp;
X{
Xint itmp;
Xint device;
Xint last_device = -1;
Xint first_byte;
Xint count;
Xint offset;
Xint show_timing = 0;
Xlong time_then;
Xchar buf[128];
X
X	for(itmp = 1; itmp < argc; itmp++)
X	{
X		if(*argv[itmp] == '-')
X		{
X			switch(*(argv[itmp] + 1))
X			{
X				case 't':
X					show_timing = 1;
X					break;
X			}
X			continue;
X		}
X		adslog_name = argv[itmp];
X	}
X	if(!(fplog = fopen(adslog_name,"r")))
X	{
X		perror(adslog_name);
X		exit(1);
X	}
X	printf("--- %s printed %s ---\n",adslog_name,get_tod(4,(char *)0));
X	while((first_byte = fgetc(fplog)) != EOF)
X	{
X		if(fread((char *)&time_then,sizeof(time_then),1,fplog) != 1)
X		{
X			puts("premature eof");
X			exit(0);
X		}
X
X		switch(first_byte & 0xFF)
X		{
X			case LOG_OPEN:
X				buf[0] = 0;
X				fgets(buf,sizeof(buf),fplog);
X				if(itmp = strlen(buf))
X					buf[itmp - 1] = 0;
X				time0 = time_then;
X				printf("\nLOG OPEN: %s on %s\n",buf,
X					secs_to_str(time0,4,(char *)0));
X				/* fall through */
X
X			case LOG_TIMEOUT:
X				offset = 0;
X				last_device = -1;
X				continue;
X
X			case LOG_CLOSE:
X				if(itmp = strlen(buf))
X					buf[itmp - 1] = 0;
X				printf("\nLOG CLOSE: %s\n",
X					secs_to_str(time0,4,(char *)0));
X				continue;
X		}
X
X		device = first_byte & 0x80;
X		count = first_byte & 0x7F;
X
X		if(fread(buf,1,count,fplog) != count)
X		{
X			puts("premature eof");
X			exit(0);
X		}
X
X		if(device == last_device)
X			fputs("   ",stdout);
X		else
X		{
X			if(show_timing)
X				printf("%s\n",get_elapsed_time(time_then - time0));
X			fputs(device ? "-> " : "<- ",stdout);
X			offset = 0;
X		}
X
X		logdump(buf,count,offset);
X
X		offset += count;
X		last_device = device;
X	}
X	exit(0);
X}	/* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of adsplog.c */
SHAR_EOF
chmod 0644 adsplog.c || echo "restore of adsplog.c fails"
echo "x - extracting afterlint.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > afterlint.c &&
X/* CHK=0xE825 */
X/*+-------------------------------------------------------------------------
X	afterlint.c -- process -Zg output
X
X   Use with zgcc:
X
X	#!/bin/csh
X	#zgcc -- build prototyping "LINT_ARGS"
X	echo C sources in $1';' result file $2
X	rm -f zg.t
X	foreach i(`cat $1`)
X	cc -DBUILDING_LINT_ARGS -Zg $argv[3-] $i > zg1.t
X	sort zg1.t > zg2.t
X	echo '/ *' $i '* /' >> zg.t    #remove spaces inside comment markers
X	cat zg2.t >> zg.t
X	end
X	afterlint zg.t $2
X	rm -f zg.t zg?.t
X	echo Output in $2
X
X  Defined functions:
X	emit_editnote(fp)
X	main(argc,argv,envp)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-13-1988-19:50-wht-creation */
X
X#include <stdio.h>
X
X#define ff fprintf
X
X#ifdef BSD4
X#include <sys/time.h>
X#define strchr index
X#define strrchr rindex
Xchar *index();
Xchar *rindex();
X/**************************/
X#else	/* assuming XENIX */
X/**************************/
X#include <time.h>
X#include <sys/types.h>
X#include <sys/timeb.h>
Xchar *strchr();
Xchar *strrchr();
X#endif	/* system dependencies */
X
Xextern long time();
Xextern struct tm *localtime();
X
X/*+-------------------------------------------------------------------------
X	emit_editnote(fp)
X--------------------------------------------------------------------------*/
Xvoid
Xemit_editnote(fp)
XFILE	*fp;
X{
X	struct tm *ltime;
X	long cur_time;
X#ifdef XENIX
X#ifdef MESSED_UP_DST
X	struct timeb tp;
X#endif
X#endif
X
X	cur_time = time((long *)0);
X
X#ifdef XENIX
X#ifdef MESSED_UP_DST
X	ftime(&tp);				/* localtime() does not know about DST */
X	if(tp.dstflag)			/* so we adjust with ftime, which does know */
X		cur_time += 3600L;	/* problem in BSD too, but no ftime there */
X#endif
X#endif
X
X	ltime = localtime(&cur_time);
X
X	fputs("/*+:EDITS:*/\n",fp);
X
X	ff(fp,"/*:%02d-%02d-%04d-%02d:%02d-afterlint-creation */\n",
X	    ltime->tm_mon+1,ltime->tm_mday,ltime->tm_year + 1900,
X	    ltime->tm_hour,ltime->tm_min);
X
X}	/* end of emit_editnote */
X
X/*+-------------------------------------------------------------------------
X	main(argc,argv,envp)
X--------------------------------------------------------------------------*/
Xmain(argc,argv,envp)
Xint argc;
Xchar	**argv;
Xchar	**envp;
X{
X	register char *cptr;
X	register FILE *fpin;
X	register FILE *fpout;
X	char	buf[256];
X	char	*basename;
X
X	if(argc < 2)
X	{
X		ff(stderr,"usage: afterlint <infile> [<outfile>]\n");
X		ff(stderr,"if outfile not supplied, output is to stdout\n");
X		exit(1);
X	}
X
X	if((fpin = fopen(argv[1],"r")) == NULL)
X	{
X		perror(argv[1]);
X		exit(1);
X	}
X
X	if(argc > 2)
X	{
X		if((fpout = fopen(argv[2],"w")) == NULL)
X		{
X			perror(argv[2]);
X			exit(1);
SHAR_EOF
echo "End of part 1"
echo "File afterlint.c is continued in part 2"
echo "2" > s2_seq_.tmp
exit 0
-- 
-------------------------------------------------------------------
Warren Tucker, Tridom Corporation       ...!gatech!emory!tridom!wht 
"Might as well be frank, monsieur.  It would take a miracle to get
you out of Casablanca and the Germans have outlawed miracles."



More information about the Alt.sources mailing list