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

Warren Tucker wht at tridom.uucp
Tue Sep 26 05:42:11 AEST 1989


---- Cut Here and unpack ----
#!/bin/sh
# this is part 2 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file afterlint.c continued
#
CurArch=2
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 afterlint.c"
sed 's/^X//' << 'SHAR_EOF' >> afterlint.c
X		}
X		basename = argv[2];
X	}
X	else
X		fpout = stdout;
X
X	ff(fpout,
X	    "/*+-----------------------------------------------------------------------\n");
X	if(argc > 2)
X		ff(fpout,"\t%s\n",basename);
X	else
X		ff(fpout,"\tfunction declarations\n",basename);
X	ff(fpout,
X	    "------------------------------------------------------------------------*/\n");
X
X	emit_editnote(fpout);
X	ff(fpout,"\n");
X	ff(fpout,"#ifndef BUILDING_LINT_ARGS\n");
X	ff(fpout,"#ifdef LINT_ARGS\n\n");
X
X	while(fgets(buf,sizeof(buf),fpin) != NULL)
X	{
X		cptr = (strncmp(buf,"/*global*/  ",12)) ? buf : buf + 12;
X		fputs(cptr,fpout);
X	}
X
X	ff(fpout,"\n#else\t\t/* compiler doesn't know about prototyping */\n\n");
X
X	fclose(fpin);
X	fpin = fopen(argv[1],"r");
X
X	while(fgets(buf,sizeof(buf),fpin) != NULL)
X	{
X		cptr = (strncmp(buf,"/*global*/  ",12)) ? buf : buf + 12;
X		if(strncmp(cptr,"int ",4))
X		{
X			if(strchr(cptr,'('))
X			{
X				while(*cptr != '(')
X					fputc(*cptr++,fpout);
X				fputs("();\n",fpout);
X			}
X			else
X				fputs(cptr,fpout);
X		}
X	}
X
X	ff(fpout,"\n#endif /* LINT_ARGS */\n");
X	ff(fpout,"#endif /* BUILDING_LINT_ARGS */\n");
X	ff(fpout,"\n/* end of %s */\n",
X	    (argc > 2) ? basename : "function declarations");
X
X	fclose(fpin);
X	fclose(fpout);
X	exit(0);
X}	/* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo "File afterlint.c is complete"
chmod 0644 afterlint.c || echo "restore of afterlint.c fails"
echo "x - extracting cmdline.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > cmdline.c &&
X/*+-------------------------------------------------------------------------
X	cmdline.c - ads command line handler
X	...!gatech!emory!tridom!wht
X
X  Defined functions:
X	cmdline(argc,argv)
X	parse_tty_arg(spec,lcb)
X	str_token(parsestr,termchars)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:05-13-1989-16:15-wht-creation */
X
X#include "ads.h"
X
Xextern char *revision;
X
X/*+-------------------------------------------------------------------------
X	usage(reason,additional)
X--------------------------------------------------------------------------*/
Xvoid
Xusage(reason,additional)
Xchar *reason;
Xchar *additional;
X{
X	fputs("\n",se);
X	ff(se,"ads %s - async data scope\n",revision);
X	fputs("usage: ads <l1> <l2>\n",se);
X	fputs("line specifiers <l1> and <l2> are of the format xx-bbbb-p\n",se);
X	fputs("where xx is /dev/ttyxx\n",se);
X	fputs("      bbbb is optional baud rate\n",se);
X	fputs("      p is optional parity (N,E,O)\n",se);
X	fputs("default baud rate is 9600, default parity to N\n",se);
X	fputs("\n",se);
X
X	if(*reason)
X	{
X		ff(se,"%s",reason);
X		if(*additional)
X			ff(se,": %s",additional);
X		fputs("\n\n",se);
X	}
X			
X	exit(1);
X
X}	/* end of usage */
X
X/*+-----------------------------------------------------------------------
X	str_token(parsestr,termchars)
X
XGet next token from string parsestr ((char *)0 on 2nd, 3rd, etc.
Xcalls), where tokens are nonempty strings separated by runs of chars
Xfrom termchars.  Writes nulls into parsestr to end tokens.
Xtermchars need not remain constant from call to call.
X
XThe above describes the action taken if PWD_PARSE is not enabled
Xif PWD_PARSE is enabled, scan a la /etc/passwd strings
X------------------------------------------------------------------------*/
Xstatic char *str_token_static = (char *)0;
Xchar *str_token(parsestr,termchars)
Xchar *parsestr;
Xchar *termchars;
X{
Xregister int first = 1;
Xregister char *termptr;
Xregister char *parseptr;
Xchar *token;
X
X	if(parsestr == (char *)0 && str_token_static == (char *)0)
X		return((char *)0);
X
X	if(parsestr)
X		parseptr = parsestr;
X	else
X       parseptr = str_token_static;
X
X	while(*parseptr)
X	{
X		for(termptr = termchars; *termptr != 0; termptr++)
X		{
X			if(*parseptr == *termptr)
X#ifdef PWD_PARSE
X				goto FOUND_TERM;
X#else
X				break;
X#endif
X		}
X#ifndef PWD_PARSE
X		if(!*termptr)
X			break;
X#endif
X		parseptr++;
X	}
X
X	if(!*parseptr)
X	{
X		str_token_static = (char *)0;
X		return((char *)0);
X	}
X
X#ifdef PWD_PARSE
XFOUND_TERM:
X#endif
X	token = parseptr;
X	while(*parseptr)
X	{
X		for(termptr = termchars; *termptr;)
X		{
X			if(*parseptr == *termptr++)
X			{
X				str_token_static = parseptr + 1;
X				*parseptr = 0;
X				return(token);
X			}
X		}
X		parseptr++;
X	}
X	str_token_static = (char *)0;
X	return(token);
X}	/* end of str_token */
X
X/*+-------------------------------------------------------------------------
X	parse_tty_arg(spec,lcb)
Xparam type xx-bbbb-p
Xwhere xx is /dev/ttyxx
X      bbbb is numeric baud rate
X      p is N,E,O,M,S
Xdefault baud rate to 9600
Xdefault parity to N
X--------------------------------------------------------------------------*/
Xvoid
Xparse_tty_arg(spec,lcb)
Xchar *spec;
Xregister LCB* lcb;
X{
Xregister char *cptr;
Xchar orig_spec[64];
X
X	strcpy(orig_spec,spec);
X
X	if(!(cptr = str_token(spec,"-")))
X		usage("null parameter","");
X
X	strcpy(lcb->line,"/dev/tty");
X	strcat(lcb->line,cptr);
X	lcb->baud = 9600;
X	lcb->parity = 0;
X
X	if(!(cptr = str_token((char *)0,"-")))
X		return;
X	if(!valid_baud_rate(lcb->baud = atoi(cptr)))
X		usage("invalid baud rate",orig_spec);
X
X	if(!(cptr = str_token((char *)0,"-")))
X		return;
X	if(isupper(*cptr))
X		*cptr = tolower(*cptr);
X	switch(*cptr)
X	{
X		case 'n':
X			*cptr = 0;
X		case 'e':
X		case 'p':
X			lcb->parity = *cptr;
X			break;
X		default:
X			usage("invalid parity",orig_spec);
X	}
X}	/* end of parse_tty_arg */
X
X/*+-------------------------------------------------------------------------
X	cmdline(argc,argv)
X--------------------------------------------------------------------------*/
Xint
Xcmdline(argc,argv)
Xint argc;
Xchar **argv;
X{
Xregister int iargv;
Xint itmp;
Xint positional_count = 0;
Xregister LCB* lcb;
X
X	if(argc == 1)
X		usage("","");
X
X	for(iargv = 1; iargv < argc; iargv++)
X	{
X		if(*argv[iargv] == '-')		/* if switch argument */
X		{
X			;
X		}   /* end of if '-' switch argument */
X		else /* positional argument */
X		{
X			if(positional_count == 2)
X			{
X				usage("Too many positional args","");
X				exit(1);
X			}
X			lcb = &lcbs[positional_count++];
X			parse_tty_arg(argv[iargv],lcb);
X		}
X	}
X
X	if(positional_count != 2)
X		usage("need two lines","");
X
X
X}	/* end of cmdline */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of cmdline.c */
SHAR_EOF
chmod 0644 cmdline.c || echo "restore of cmdline.c fails"
echo "x - extracting curseslint.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > curseslint.h &&
X/*global*/  char *longname(char *,char *);
X/*global*/  int mvcur(int ,int ,int ,int );
X/*global*/  int mvprintw(int ,int ,char *);
X/*global*/  int mvscanw(int ,int ,char *);
X/*global*/  int mvwprintw(struct _win_st *,int ,int ,char *,);
X/*global*/  int mvwscanw(struct _win_st *,int ,int ,char *);
X/*global*/  struct _win_st *newwin(int ,int ,int ,int );
X/*global*/  int overlay(struct _win_st *,struct _win_st *);
X/*global*/  int overwrite(struct _win_st *,struct _win_st *);
X/*global*/  int printw(char *);
X/*global*/  int scanw(char *);
X/*global*/  int scroll(struct _win_st *);
X/*global*/  int setterm(char *);
X/*global*/  struct _win_st *subwin(struct _win_st *,int ,int ,int ,int );
X/*global*/  int waddch(struct _win_st *,char );
X/*global*/  int waddstr(struct _win_st *,char *);
X/*global*/  int wclear(struct _win_st *);
X/*global*/  int wclrtobot(struct _win_st *);
X/*global*/  int wclrtoeol(struct _win_st *);
X/*global*/  int wdeleteln(struct _win_st *);
X/*global*/  int werase(struct _win_st *);
X/*global*/  int wgetch(struct _win_st *);
X/*global*/  int wgetstr(struct _win_st *,char *);
X/*global*/  int winsertln(struct _win_st *);
X/*global*/  int wmove(struct _win_st *,int ,int );
X/*global*/  int wprintw(struct _win_st *,char *,);
X/*global*/  int wrefresh(struct _win_st *);
X/*global*/  int wscanw(struct _win_st *,char *);
X/*global*/  int wstandout(struct _win_st *);
X/*global*/  int wstandend(struct _win_st *);
SHAR_EOF
chmod 0644 curseslint.h || echo "restore of curseslint.h fails"
echo "x - extracting keyboard.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > keyboard.h &&
X/*+-------------------------------------------------------------------------
X	keyboard.h
X	...!gatech!emory!tridom!wht
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:05-14-1989-12:23-wht-creation */
X
X#define CTL_B		0x02
X#define CTL_C		0x03
X#define CTL_D		0x04
X#define BS			0x08
X#define NL			0x0A
X#define TAB			0x09
X#define CTL_L		0x0C
X#define CR			0x0D
X#define XON			0x11
X#define CTL_R		0x12
X#define XOFF		0x13
X#define CTL_U		0x15
X#define ESC			0x1B
X#define CTL_BSLASH	0x1C
X#define CTL_Z		0x1A
X#define SPACE		0x20
X#define DEL			0x7F
X
X#define XFcurup	(0x80 | 'A')
X#define XFcurdn	(0x80 | 'B')
X#define XFcurrt	(0x80 | 'C')
X#define XFcurlf	(0x80 | 'D')
X#define XFcur5	(0x80 | 'E')
X#define XFend	(0x80 | 'F')
X#define XFpgdn	(0x80 | 'G')
X#define XFhome	(0x80 | 'H')
X#define XFpgup	(0x80 | 'I')
X#define XFins	(0x80 | 'L')
X#define XF1		(0x80 | 'M')
X#define XF2		(0x80 | 'N')
X#define XF3		(0x80 | 'O')
X#define XF4		(0x80 | 'P')
X#define XF5		(0x80 | 'Q')
X#define XF6		(0x80 | 'R')
X#define XF7		(0x80 | 'S')
X#define XF8		(0x80 | 'T')
X#define XF9		(0x80 | 'U')
X#define XF10	(0x80 | 'V')
X#define XF11	(0x80 | 'W')
X#define XF12	(0x80 | 'X')
X#define XFbktab	(0x80 | 'Z')
X
X/* end of keyboard.h */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
chmod 0644 keyboard.h || echo "restore of keyboard.h fails"
echo "x - extracting lineio.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > lineio.c &&
X/*+-------------------------------------------------------------------------
X	lineio.c -- copy one tty to another (expensive EIA cable)
X	...!gatech!emory!tridom!wht
X
X  Defined functions:
X	lbreak(lcb)
X	lclear_xoff(lcb)
X	lclose(lcb)
X	lget_xon_xoff(lcb,ixon,ixoff)
X	lflush(lcb)
X	lopen(lcb)
X	lopen_err_text(lerr)
X	lset_baud_rate(lcb,ioctl_flag)
X	lset_parity(lcb,ioctl_flag)
X	ltoggle_dtr(lcb)
X	lxon_xoff(lcb,flag)
X	valid_baud_rate(baud)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:05-13-1989-15:36-wht-creation */
X
X#include "ads.h"
X
X/*+-------------------------------------------------------------------------
X	lflush(lcb)
X--------------------------------------------------------------------------*/
Xvoid
Xlflush(lcb)
Xregister LCB *lcb;
X{
X	ioctl(lcb->iofd,TCFLSH,(char *)2); /* flush input and output */
X}	/* end of lflush */
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(lcb,ioctl_flag)
X
X  If 'ioctl_flag' is set,then ioctl(lcb->iofd,TCSETA,&lcb->termio)
X  is executed after setting baud rate
X------------------------------------------------------------------------*/
Xlset_baud_rate(lcb,ioctl_flag)
Xregister LCB *lcb;
Xint ioctl_flag;
X{
Xint baud_selector = valid_baud_rate(lcb->baud);
X
X	if(baud_selector < 0)
X	{
X		ff(se,"   invalid baud rate: %u\r\n",lcb->baud);
X		ff(se,"valid rates: 110,300,600,1200,2400,4800,9600,19200\r\n");
X		return(-1);
X	}
X	lcb->termio.c_cflag &= ~CBAUD;
X	lcb->termio.c_cflag |= baud_selector;
X
X	if(ioctl_flag)
X		 ioctl(lcb->iofd,TCSETA,(char *)&lcb->termio);
X	return(0);
X
X}	/* end of lset_baud_rate */
X
X/*+-----------------------------------------------------------------------
X	lset_parity(lcb,ioctl_flag)
X
X  If 'ioctl_flag' is set,then ioctl(lcb->iofd,TCSETA,&lcb->termio)
X  is executed after setting parity
X------------------------------------------------------------------------*/
Xvoid
Xlset_parity(lcb,ioctl_flag)
Xregister LCB *lcb;
Xint ioctl_flag;
X{
X	lcb->termio.c_cflag &= ~(CS8 | PARENB | PARODD);
X	switch(lcb->parity)
X	{
X		case 'e':
X		case 'E':
X			lcb->termio.c_cflag |= CS7 | PARENB;
X			lcb->termio.c_iflag |= ISTRIP;
X			break;
X		case 'o':
X		case 'O':
X			lcb->termio.c_cflag |= PARODD | CS7 | PARENB;
X			lcb->termio.c_iflag |= ISTRIP;
X			break;
X		default:
X			ff(se,"invalid parity: %c ... defaulting to no parity\r\n");
X		case 0:
X		case 'n':
X		case 'N':
X			lcb->termio.c_cflag |= CS8;
X			lcb->termio.c_iflag &= ~(ISTRIP);
X			lcb->parity = 0;
X			break;
X	}			
X
X	if(ioctl_flag)
X		 ioctl(lcb->iofd,TCSETA,(char *)&lcb->termio);
X
X}	/* end of lset_parity */
X
X/*+-------------------------------------------------------------------------
X	lclear_xoff(lcb) - simulate XON from remote system
X--------------------------------------------------------------------------*/
Xvoid
Xlclear_xoff(lcb)
Xregister LCB *lcb;
X{
X	ioctl(lcb->iofd,TCXONC,(char *)1); /* restart xmtr output */
X}	/* end of lclear_xoff */
X
X/*+-------------------------------------------------------------------------
X	lbreak(lcb) - send break to remote
X--------------------------------------------------------------------------*/
Xvoid
Xlbreak(lcb)
Xregister LCB *lcb;
X{
X	ioctl(lcb->iofd,TCSBRK,(char *)0);
X}	/* end of lbreak */
X
X/*+----------------------------------------------------------------------
X	lopen(lcb) - open line
Xreturns negative LOPEN_ codes if failure 
X------------------------------------------------------------------------*/
Xint
Xlopen(lcb)
Xregister LCB *lcb;
X{
Xregister int itmp;
X
X	if(!strcmp(lcb->line,"/dev/tty"))
X		return(LOPEN_INVALID);
X	lcb->iofd = open(lcb->line,O_RDWR | O_NDELAY,0777);
X	if(lcb->iofd < 0)
X		return(LOPEN_OPNFAIL);
X	else
X	{
X		fcntl(lcb->iofd,F_SETFL,O_RDWR);
X		ioctl(lcb->iofd,TCGETA,(char *) &lcb->termio);
X		lcb->termio.c_iflag = (IGNPAR | IGNBRK | IXOFF );
X		lcb->termio.c_cflag |= (CREAD | HUPCL);
X		lcb->termio.c_lflag = 0;
X
X		lcb->termio.c_cc[VMIN]   = 1;
X		lcb->termio.c_cc[VTIME]  = 1;
X		lset_baud_rate(lcb,0);		/* do not perform ioctl */
X		lset_parity(lcb,1);			/* do perform ioctl */
X	}
X
X	return(0);
X
X}	/* end of lopen */
X
X/*+-----------------------------------------------------------------------
X	lclose(lcb) - close line
X------------------------------------------------------------------------*/
Xvoid
Xlclose(lcb)
Xregister LCB *lcb;
X{
X	if(lcb->iofd < 0)
X		return;
X	close(lcb->iofd);
X	lcb->iofd = -1;
X
X}	/* end of lclose */
X
X/*+-------------------------------------------------------------------------
X	ltoggle_dtr(lcb) - drop, pause, raise DTR
X--------------------------------------------------------------------------*/
Xvoid
Xltoggle_dtr(lcb)
Xregister LCB *lcb;
X{
X	lclose(lcb);
X	nap(300L);
X	lopen(lcb);
X	ioctl(lcb->iofd,TCSETA,(char *)&lcb->termio);
X	nap(100L);
X}	/* end of ltoggle_dtr */
X
X/*+-------------------------------------------------------------------------
X	lxon_xoff(lcb,flag) - control XON/XOFF flow control
X
XIXON specifies whether or not we respond to xon/xoff characters
XIXOFF specifies whether or not we generate XON/XOFF characters
X--------------------------------------------------------------------------*/
Xvoid
Xlxon_xoff(lcb,flag)
Xregister LCB *lcb;
Xint flag;
X{
X	if(flag & IXON)
X		lcb->termio.c_iflag |= IXON;
X	else
X		lcb->termio.c_iflag &= ~IXON;
X
X	if(flag & IXOFF)
X		lcb->termio.c_iflag |= IXOFF;
X	else
X		lcb->termio.c_iflag &= ~IXOFF;
X
X	ioctl(lcb->iofd,TCSETA,(char *)&lcb->termio);
X
X}	/* end of lxon_xoff */
X
X/*+-------------------------------------------------------------------------
X	lget_xon_xoff(lcb,ixon,ixoff) - XON/XOFF flow control status
X--------------------------------------------------------------------------*/
Xvoid
Xlget_xon_xoff(lcb,ixon,ixoff)
Xregister LCB *lcb;
Xint *ixon;
Xint *ixoff;
X{
X	*ixon  = (lcb->termio.c_iflag & IXON) != 0;
X	*ixoff = (lcb->termio.c_iflag & IXOFF) != 0;
X}	/* end of lget_xon_xoff */
X
X/*+-------------------------------------------------------------------------
X	lopen_err_text(lerr) - LOPEN_ error code to text
X--------------------------------------------------------------------------*/
Xchar *
Xlopen_err_text(lerr)
Xint lerr;
X{
Xstatic char lerr_s32[32];
X
X	switch(lerr)
X	{
X		case LOPEN_INVALID: return("invalid line name");
X		case LOPEN_OPNFAIL: return("line open error (not installed?)");
X	}
X	sprintf(lerr_s32,"pid %d using line",lerr);
X	return(lerr_s32);
X}	/* end of lopen_err_text */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of lineio.c */
SHAR_EOF
chmod 0644 lineio.c || echo "restore of lineio.c fails"
echo "x - extracting screen.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > screen.c &&
X/*+-------------------------------------------------------------------------
X	screen.c - ads curses window utilities
X	...!gatech!emory!tridom!wht
X
X  Defined functions:
X	clear_area(win,y,x,len)
X	clear_area_char(win,y,x,len,fillchar)
X	putc_stderr(ch)
X	ttygetc(xkey_ok)
X	winbox(win)
X	window_create(title,title_x,tly,tlx,lines,cols)
X	window_setup(win,title,title_x)
X	windows_end()
X	windows_start()
X	winget_single(win,nondelim_list,delim_list)
X	wingets(win,y,x,buf,bufsize,delim,wait_for_key)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:05-14-1989-12:22-wht-creation */
X
X#define M_TERMCAP
X#include <curses.h>
X#include "ads.h"
X#include "keyboard.h"
X
Xint windows_active = 0;
X
X/* ruling characters */
X#define sTL			0
X#define sTR			1
X#define sBL			2
X#define sBR			3
X#define sLT			4		/* left hand T */
X#define sRT			5		/* right hand T */
X#define sVR			6		/* vertical rule */
X#define sHR			7		/* horizontal rule */
X
X#define PC_sTL		0xDA
X#define PC_sTR		0xBF
X#define PC_sBL		0xC0
X#define PC_sBR		0xD9
X#define PC_sLT		0xC3	/* left hand T */
X#define PC_sRT		0xB4	/* right hand T */
X#define PC_sVR		0xB3	/* vertical rule */
X#define PC_sHR		0xC4	/* horizontal rule */
X
X#define OTHER_sTL	'.'
X#define OTHER_sTR	'.'
X#define OTHER_sBL	'`'
X#define OTHER_sBR	'\''
X#define OTHER_sLT	'+'		/* left hand T */
X#define OTHER_sRT	'+'		/* right hand T */
X#define OTHER_sVR	'-'		/* vertical rule */
X#define OTHER_sHR	'|'		/* horizontal rule */
X
Xchar *rule;
Xchar rule_PC[] =
X{
X	PC_sTL, PC_sTR, PC_sBL, PC_sBR, PC_sLT, PC_sRT, PC_sVR, PC_sHR
X};
X
Xchar rule_OTHER[] =
X{
X	OTHER_sTL, OTHER_sTR, OTHER_sBL, OTHER_sBR, OTHER_sLT,
X	OTHER_sRT, OTHER_sVR, OTHER_sHR
X};
X
X/*+-------------------------------------------------------------------------
X	putc_stderr(ch) - local routine to write char to stderr
X--------------------------------------------------------------------------*/
Xvoid 
Xputc_stderr(ch)
Xchar ch;
X{
X	fputc(ch,stderr);
X}	/* end of putc_stderr */
X
X/*+-------------------------------------------------------------------------
X	ttygetc(xkey_ok) -- get a key from the keyboard
X
Xmap extended keys to sign-bit-set special value
Xif xkey_ok is 0, disallow extended keys
X--------------------------------------------------------------------------*/
Xstatic char *dole_out_rd_char = (char *)0;
Xuint
Xttygetc(xkey_ok)
Xint xkey_ok;
X{
Xuchar ctmp;
Xextern int errno;
Xregister uint itmp = 0;
Xstatic uchar rd_char[10];
X
X	if(dole_out_rd_char)		/* handle (very unlikely) FAST typist */
X	{
X		if(itmp = *dole_out_rd_char++)
X			return(itmp);
X		else
X			dole_out_rd_char = (char *)0;
X	}
X
XGET_KEY:
X	errno = 0;
X	if(read(0,&ctmp,1) < 0)
X	{
X		if(errno == EINTR)
X			goto GET_KEY;
X		perror("keyboard");
X		endprog();
X	}
X	ctmp &= 0x7F;
X
X	if(ctmp == ESC)	/* if escape */
X	{
X		itmp = 0;
X		nap((long)40);
X		while((!isalpha(ctmp)) && (itmp < sizeof(rd_char) - 1))
X		{
X			if(rdchk(0) <= 0)
X				break;
X			read(0,&ctmp,1);
X			rd_char[itmp++] = ctmp & 0x7F;
X			nap((long)20);
X		}
X		rd_char[itmp] = 0;
X		if(!itmp)				/* no subsequent chars, so ... */
X			return(ESC);		/* return the escape */
X		else if((itmp == 2) && (rd_char[0] == '['))
X		{
X			switch(rd_char[1] | 0x80)
X			{
X				case XFcurup: case XFcurdn: case XFcurrt: case XFcurlf:
X				case XFend: case XFpgdn: case XFhome: case XFpgup: case XFins:
X				case XF1: case XF2: case XF3: case XF4: case XF5: case XF6:
X				case XF7: case XF8: case XF9: case XF10: case XF11: case XF12:
X				case XFbktab:
X					if(xkey_ok)
X						return(rd_char[1] | 0x80);
X					/* fall thru -- xkey not allowed */
X				default:
X					fputc(0x08,stderr);
X					goto GET_KEY;
X			}
X		}
X		else		/* not func key -- we have a FAST typist */
X		{
X			dole_out_rd_char = rd_char;
X			return(ESC);
X		}
X	}
X	else
X		return(ctmp);
X}	/* end if ttygetc */
X
X/*+-------------------------------------------------------------------------
X	clear_area_char(win,y,x,len,fillchar)
X--------------------------------------------------------------------------*/
Xvoid
Xclear_area_char(win,y,x,len,fillchar)
XWINDOW	*win;
Xint y;
Xint x;
Xint len;
Xchar fillchar;
X{
X	wmove(win,y,x);
X	while(len-- > 0)
X		waddch(win,fillchar);
X	wmove(win,y,x);
X
X}	/* end of clear_area_char */
X
X/*+-------------------------------------------------------------------------
X	clear_area(win,y,x,len)
X--------------------------------------------------------------------------*/
Xvoid
Xclear_area(win,y,x,len)
XWINDOW	*win;
Xint y;
Xint x;
Xint len;
X{
X	clear_area_char(win,y,x,len,' ');
X}	/* end of clear_area_char */
X
X/*+-------------------------------------------------------------------------
X	windows_start()
X--------------------------------------------------------------------------*/
Xvoid
Xwindows_start()
X{
Xregister char *cptr;
X
X	initscr();
X	savetty(); raw(); noecho(); nonl();
X	if(strcmp(getcap(cptr),"ansi"))
X		rule = rule_PC;
X	else
X		rule = rule_OTHER;
X	windows_active = 1;
X
X}	/* end of windows_start */
X
X/*+-------------------------------------------------------------------------
X	windows_end()
X--------------------------------------------------------------------------*/
Xvoid
Xwindows_end()
X{
Xchar *tgoto();
X
X	if(!windows_active)
X		return;
X	resetty();
X	endwin();
X	tputs(tgoto(CM,0,LINES - 1),1,putc_stderr);
X	windows_active = 0;
X}	/* end of windows_end */
X
X/*+-------------------------------------------------------------------------
X	winbox(win)
X--------------------------------------------------------------------------*/
Xwinbox(win)
XWINDOW	*win;
X{
X	box(win,rule[sVR],rule[sHR]);
X	wmove(win,0,0);
X	waddch(win,rule[sTL]);
X	wmove(win,win->_maxy - 1,0);
X	waddch(win,rule[sBL]);
X	wmove(win,win->_maxy - 1,win->_maxx - 1);
X	waddch(win,rule[sBR]);
X	wmove(win,0,win->_maxx - 1);
X	waddch(win,rule[sTR]);
X
X}	/* end of winbox */
X
X/*+-------------------------------------------------------------------------
X	window_setup(win)
X--------------------------------------------------------------------------*/
Xvoid
Xwindow_setup(win,title,title_x)
XWINDOW *win;
Xchar *title;
Xint title_x;
X{
Xregister int stand = (title_x < 0);
X
X	if(stand)
X		title_x = -title_x;
X
X	scrollok(win,0);		/* do not scroll */
X	winbox(win);
X	wmove(win,0,title_x);
X	waddch(win,'[');
X	if(stand)
X		wstandout(win);
X	wprintw(win," %s ",title);
X	if(stand)
X		wstandend(win);
X	waddch(win,']');
X}	/* end of window_setup */
X
X/*+-------------------------------------------------------------------------
X	window_create(title,title_x,tly,tlx,lines,cols)
Xif title_x negative, make title "stand" out
X--------------------------------------------------------------------------*/
XWINDOW *
Xwindow_create(title,title_x,tly,tlx,lines,cols)
Xchar *title;
Xint title_x;
Xint tly;
Xint tlx;
Xint lines;
Xint cols;
X{
XWINDOW *nwin = newwin(lines,cols,tly,tlx);
X	
X	if(nwin)
X		window_setup(nwin,title,title_x);
X	return(nwin);
X
X}	/* end of window_create */
X
X/*+-------------------------------------------------------------------------
X	wingets
X numchars = wingets(win,y,x,buf,bufsize,&delim,wait_for_key)
X
XThis procedure reads a string from win and returns the number
Xof characters read.  -1 is returned if an abort is signaled by the
Xkeyboard user.
X--------------------------------------------------------------------------*/
Xint
Xwingets(win,y,x,buf,bufsize,delim,wait_for_key)
Xregister WINDOW *win;
Xregister int y;
Xregister int x;
Xchar *buf;
Xregister int bufsize;	/* includes room for null..field is 1 less */
Xregister uchar *delim;
Xint wait_for_key;
X{
Xregister int count;
Xregister char *cptr = buf;
X
X	if(!wait_for_key)
X		clear_area_char(win,y,x,bufsize-1,'_');
X
X	wmove(win,y,x);
X	count = 0;			/* no characters in string */
X	*cptr = 0;			/* start with null string */
X
X	while(1)
X	{
X		wrefresh(win);
X		*delim = ttygetc(1);
X		if((*delim < 0x20) || (*delim >= 0x7F))
X		{
X			switch(*delim)
X			{
X				case CR:
X					*delim = NL;
X				case NL:
X					wrefresh(win);
X					return(count);
X
X				case BS:
X					if(count)
X					{
X						count--;
X						*--cptr = 0;
X						wmove(win,y,x + count);
X						waddch(win,'_');
X						wmove(win,y,x + count);
X					}
X					continue;
X
X				case ESC:
X				case CTL_U:
X					while(count--)
X					{
X						*--cptr = 0;
X						wmove(win,y,x + count);
X						waddch(win,'_');
X					}
X					cptr = buf;
X					count = 0;
X					wmove(win,y,x);
X					wrefresh(win);
X					if(*delim == ESC)
X						return(-1);
X					continue;
X
X				default:
X					wrefresh(win);
X					return(-1);
X			}	/* end of switch(*delim) */
X			/*NOTREACHED*/
X		}		/* end of if read delimiter */
X
X		if(count == bufsize-1)
X			continue;
X		if(wait_for_key)
X		{
X			clear_area_char(win,y,x,bufsize-1,'_');
X			wait_for_key = 0;
X		}
X		waddch(win,*delim);
X		*cptr++ = *delim;
X		*cptr = 0;
X		count++;
X	}	/* end of while can get character */
X					
X}	/* end of wingets */
X
X/*+-------------------------------------------------------------------------
X	winget_single(win,nondelim_list,delim_list)
X
XThis procedure assumes cursor is positioned, repeats reading a non-echoing
Xcharacter from the keyboard until it matches a character in nondelim_list
Xor delim_list.  delim_list is expected to contain printable characters
Xand no upper-case characters.
X
XIf no match occurs, the bell is rung and the keyboard is read again.
X
XIf the input character matches a character in delim_list, the index (0-n)
Xof the character in delim_list is returned.  If a match occurs, an
Xupper-case version of the matching character is placed in the window.
X
XIf the input character matches a character in nondelim_list, the character
Xis returned or'ed with 0x1000
X
X--------------------------------------------------------------------------*/
Xint
Xwinget_single(win,nondelim_list,delim_list)
XWINDOW	*win;
Xregister char *nondelim_list;
Xregister char *delim_list;
X{
Xregister int itmp;
Xregister int nlen = strlen(nondelim_list);
Xregister int dlen = strlen(delim_list);
Xregister int ichar;
X
X	wrefresh(win);
X
X	while(1)
X	{
X		ichar = ttygetc(1);
X		ichar = islower(ichar) ? ichar : tolower(ichar);
X		for(itmp = 0; itmp < nlen; itmp++)
X		{
X			if(ichar == nondelim_list[itmp])
X			{
X				waddch(win,islower(ichar) ? toupper(ichar) : ichar);
X				wrefresh(win);
X				return(itmp);
X			}
X		}
X		for(itmp = 0; itmp < dlen; itmp++)
X		{
X			if(ichar == delim_list[itmp])
X				return(ichar | 0x1000);
X		}
X		fputc(0x08,stderr);
X	}
X
X}	/* end of winget_single */
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of screen.c */
SHAR_EOF
chmod 0644 screen.c || echo "restore of screen.c fails"
echo "x - extracting time.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > time.c &&
X/*+-------------------------------------------------------------------------
X	time.c - ads/adsplog time-related routines
X	...!gatech!emory!tridom!wht
X
X  Defined functions:
X	get_elapsed_time(elapsed_seconds)
X	get_tod(type,buf)
X	secs_to_str(secs,type,buf)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:09-24-1989-18:36-wht-creation */
X
X#include <stdio.h>
X#include <sys/time.h>
X#include "ads.h"
X
X/*+-----------------------------------------------------------------------
X	char *secs_to_str(secs,type,buf) - secvs since 1/1/70 to string
X
X  time of day types:
X	0		hh:mm
X	1		hh:mm:ss
X	2		mm-dd-yyyy hh:mm
X	3		mm-dd-yyyy hh:mm:ss
X	4		mm-dd-yyyy hh:mm:ss (UTC hh:mm)
X	5		mm-dd-yyyy
X
X	returns 'buf' address
X
X------------------------------------------------------------------------*/
Xchar *
Xsecs_to_str(secs,type,buf)
Xlong secs;
Xint type;
Xchar *buf;
X{
Xstruct tm *lt;			/* local time */
Xstruct tm *gmtime();
Xstruct tm *localtime();
Xstatic char s40[40];
X
X	if(!buf)
X		buf = s40;
X
X	lt = localtime(&secs);
X	switch(type)
X	{
X		default:
X		case 0:
X			sprintf(buf,"%02d:%02d",lt->tm_hour,lt->tm_min);
X			break;
X
X		case 1:
X			sprintf(buf,"%02d:%02d:%02d",lt->tm_hour,lt->tm_min,lt->tm_sec);
X			break;
X
X		case 2:
X			sprintf(buf,"%02d-%02d-%04d %02d:%02d",
X				lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
X				lt->tm_hour,lt->tm_min);
X			break;
X
X		case 3:
X			sprintf(buf,"%02d-%02d-%04d %02d:%02d:%02d",
X				lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
X				lt->tm_hour,lt->tm_min,lt->tm_sec);
X			break;
X
X		case 4:
X			sprintf(buf,"%02d-%02d-%04d %02d:%02d:%02d",
X				lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
X				lt->tm_hour,lt->tm_min,lt->tm_sec);
X			lt = gmtime(&secs);
X			sprintf(&buf[strlen(buf) ]," (UTC %02d:%02d)",
X				lt->tm_hour,lt->tm_min);
X			break;
X
X		case 5:
X			sprintf(buf,"%02d-%02d-%04d",
X				lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900);
X			break;
X
X	}
X
X	return(buf);
X}	/* end of secs_to_str */
X
X/*+-----------------------------------------------------------------------
X	char *get_tod(type,buf) - get time of day (see secs_to_str)
Xreturns 'buf' address
X------------------------------------------------------------------------*/
Xchar *
Xget_tod(type,buf)
Xint type;
Xchar *buf;
X{
Xlong time();
X	return(secs_to_str(time((long *)0),type,buf));
X}	/* end of get_tod */
X
X/*+-----------------------------------------------------------------------
X	char *get_elapsed_time(elapsed_seconds) - elapsed secs to string
X
X  "hh:mm:ss" static string address is returned
X------------------------------------------------------------------------*/
Xchar *
Xget_elapsed_time(elapsed_seconds)
Xlong elapsed_seconds;
X{
Xstatic char elapsed_time_str[40];
Xlong hh,mm,ss;
X
X	hh = elapsed_seconds / 3600;
X	elapsed_seconds -= hh * 3600;
X	mm = elapsed_seconds / 60L;
X	elapsed_seconds -= mm * 60L;
X	ss = elapsed_seconds;
X
X	sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss);
X	return(elapsed_time_str);
X}	/* end of get_elapsed_time */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of time.c */
SHAR_EOF
chmod 0644 time.c || echo "restore of time.c fails"
mkdir x386sel
echo "x - extracting x386sel/fixttiocom.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > x386sel/fixttiocom.c &&
X/*+-------------------------------------------------------------------------
X	fixttiocom.c - change ttiocom to Ttiocom calls in /usr/sys/sys/libsys.a
XThis program patched my Xenix 386 2.3.1 system library (a copy of which
Xhad been named libfix.a, fixed, verified, then moved to libsys.a)
X--------------------------------------------------------------------------*/
SHAR_EOF
echo "End of part 2"
echo "File x386sel/fixttiocom.c is continued in part 3"
echo "3" > 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