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

Warren Tucker wht at tridom.uucp
Mon Oct 9 07:51:24 AEST 1989


---- Cut Here and unpack ----
#!/bin/sh
# this is part 11 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file ecuutil.c continued
#
CurArch=11
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 ecuutil.c"
sed 's/^X//' << 'SHAR_EOF' >> ecuutil.c
X				(flag & IUCLC ) ? 1 : 0,
X				(flag & IXON  ) ? 1 : 0,
X				(flag & IXANY ) ? 1 : 0,
X				(flag & IXOFF ) ? 1 : 0);
X
X	flag = ttt->c_oflag;
X	pprintf("oflag: %07o OPOST:%d  OLCUC:%d  ONLCR:%d  OCRNL:%d  ONOCR:%d  ONLRET:%d  OFDEL:%d\n",
X				flag,
X				(flag & OPOST ) ? 1 : 0,
X				(flag & OLCUC ) ? 1 : 0,
X				(flag & ONLCR ) ? 1 : 0,
X				(flag & OCRNL ) ? 1 : 0,
X				(flag & ONOCR ) ? 1 : 0,
X				(flag & ONLRET) ? 1 : 0,
X				(flag & OFDEL ) ? 1 : 0);
X
X	flag = ttt->c_cflag;
X	pprintf("cflag: %07o ",ttt->c_cflag);
X	switch(flag & CBAUD)
X	{
X		case B0:	cptr = "HUP"; break;
X		case B50:	cptr = "50"; break;
X		case B75:	cptr = "75"; break;
X		case B110:	cptr = "110"; break;
X		case B134:	cptr = "134.5"; break;
X		case B150:	cptr = "150"; break;
X		case B200:	cptr = "200"; break;
X		case B300:	cptr = "300"; break;
X		case B600:	cptr = "600"; break;
X		case B1200:	cptr = "1200"; break;
X		case B1800:	cptr = "1800"; break;
X		case B2400:	cptr = "2400"; break;
X		case B4800:	cptr = "4800"; break;
X		case B9600:	cptr = "9600"; break;
X		case EXTA:	cptr = "EXTA(19200?)"; break;
X		case EXTB:	cptr = "EXTB(38400?)"; break;
X		default:	cptr = "????"; break;
X	}
X	dbits = 5 + ((flag & CSIZE) >> 4);
X	parity = (flag & PARENB) ? ((flag & PARODD) ? 'O' : 'E') : 'N';
X	pprintf("%s-%d-%c-%d ",cptr,dbits,parity,(flag & CSTOPB) ? 2 : 1);
X	switch(flag & CS8)
X	{
X		case CS8: pputs("CS8 "); break;
X		case CS7: pputs("CS7 "); break;
X		case CS6: pputs("CS6 "); break;
X		case CS5: pputs("CS5 "); break;
X	}
X	pprintf("CREAD:%d  HUPCL:%d  CLOCAL:%d\n",
X				(flag & CREAD ) ? 1 : 0,
X				(flag & HUPCL ) ? 1 : 0,
X				(flag & CLOCAL) ? 1 : 0);
X
X
X	flag = ttt->c_lflag;
X	pprintf("lflag: %07o ISIG:%d  ICANON:%d  XCASE:%d  ECHO:%d  ECHOE:%d\n",
X				flag,
X				(flag & ISIG  ) ? 1 : 0,
X				(flag & ICANON) ? 1 : 0,
X				(flag & XCASE ) ? 1 : 0,
X				(flag & ECHO  ) ? 1 : 0,
X				(flag & ECHOE ) ? 1 : 0);
X#if defined(M_XENIX)
X	pprintf(
X"               ECHOK:%d  ECHONL:%d  NOFLSH:%d  XCLUDE:%d\n",
X				(flag & ECHOK ) ? 1 : 0,
X				(flag & ECHONL) ? 1 : 0,
X				(flag & NOFLSH) ? 1 : 0,
X				(flag & XCLUDE) ? 1 : 0);
X#endif
X#if defined(pyr)
X	pprintf(
X"               ECHOK:%d  ECHONL:%d  NOFLSH:%d\n",
X				(flag & ECHOK ) ? 1 : 0,
X				(flag & ECHONL) ? 1 : 0,
X				(flag & NOFLSH) ? 1 : 0);
X#endif
X
X	pprintf("ctl chars: ");
X	for(i_cc = 0; i_cc < NCC; i_cc++)
X		pprintf("%02x   ",ttt->c_cc[i_cc]);
X	pprintf("  (hex)\n");
X	pprintf("           INTR QUIT ERAS KILL EOF  EOL  EOL2 SWTCH  VMIN-EOF VTIME-EOL\n");
X
X}	/* end of disp_termio */
X
X/*+-----------------------------------------------------------------------
X	disp_line_termio(fd)
X
XGet current termio structure for file descriptor fd
Xand display on stderr
X------------------------------------------------------------------------*/
Xvoid disp_line_termio(fd,text)
Xint fd;		/* file descriptor */
Xchar *text;
X{
Xstruct termio fd_termio;
Xchar text2[128];
X
X	ioctl(fd,TCGETA,&fd_termio);
X	sprintf(text2,"fd: %d  %s",fd,text);
X	disp_termio(&fd_termio,text2);
X
X}	/* end of disp_line_termio */
X
X/*+-----------------------------------------------------------------------
X	print_cwd(curdir) print and return current working directory
X------------------------------------------------------------------------*/
Xvoid print_cwd(curdir,buf_size)
Xchar *curdir;
Xint buf_size;
X{
X	ff(se,"%s\r\n",curr_dir);
X	strncpy(curdir,curr_dir,buf_size);
X}	/* end of print_cwd */
X
X/*+-----------------------------------------------------------------------
X	dummy_call() bypass optimizer (call from another module for noop)
X------------------------------------------------------------------------*/
Xvoid dummy_call() { ; }
X
X/*+-----------------------------------------------------------------------
X	ascii_name_to_hex(str3char)
X
X  return value of ascii ctl char name (e.g., "NUL") 0 - 0x1F
X  returns -1 if input not valid
X------------------------------------------------------------------------*/
Xascii_name_to_hex(str3char)
Xchar *str3char;
X{
Xregister char *cptr = ascii_ctlstr;
Xregister intval;
X
X	for(intval = 0; intval < 0x20; intval++)
X	{
X		if(	(to_lower(*str3char) == to_lower(*cptr))				&&
X			(to_lower(*(str3char + 1)) == to_lower(*(cptr + 1)))	&&
X			((to_lower(*(str3char + 2)) == to_lower(*(cptr + 2)))	||
X			(*(cptr + 2) == ' ')))
X			return(intval);
X		cptr += 3;
X	}
X
X	return(-1);
X
X}	/* end of ascii_name_to_hex */
X
X/*+-------------------------------------------------------------------------
X	ascii_to_hex(ascii)
X--------------------------------------------------------------------------*/
Xascii_to_hex(ascii)
Xchar *ascii;
X{
Xint hexval;
X	if(strlen(ascii) == 1)
X		return(*ascii);
X	else if(!strncmp(ascii,"0x",2))
X	{
X		sscanf(ascii + 2,"%x",&hexval);
X		return(hexval & 0xFF);
X	}
X	else if(*ascii == '^')
X		return(*(ascii + 1) & 0x1F);
X	else
X		return(ascii_name_to_hex(ascii));
X}	/* end of ascii_to_hex */
X
X/*+-------------------------------------------------------------------------
X	hex_to_ascii_name(char_val)
X
X  Returns pointer to static string containing three character ASCII
X  name for control character followed by a null.
X--------------------------------------------------------------------------*/
Xchar *
Xhex_to_ascii_name(char_val)
Xchar char_val;
X{
Xstatic char ascii_name[4];
X
X	if(char_val == 0x7F)
X		strcpy(ascii_name,"DEL");
X	else
X	{
X		strncpy(ascii_name,ascii_ctlstr + (char_val * 3),3);
X		ascii_name[3] = 0;
X	}
X
X	return(ascii_name);
X
X}	/* end of hex_to_ascii_name */
X
X/*+-------------------------------------------------------------------------
X	get_curr_dir(currdir,currdir_max)
X--------------------------------------------------------------------------*/
Xget_curr_dir(currdir,currdir_max)
Xchar *currdir;
Xint currdir_max;
X{
X#if defined(pyr)
Xchar *getwd();
X	return((getwd(currdir) == (char *)0) ? -1 : 0);
X#endif
X
X#if defined(M_XENIX)
X/* kludge since getcwd() did not seem to work ... and I heard it
Xpipes output of pwd as well */
X#define P_READ 0
X#define P_WRITE 1
Xint pipe_pid;
Xint pfd[2];
Xint count;
Xchar s40[40];
X
X	if(pipe(pfd) < 0)
X		return(-1);
X	if((pipe_pid = smart_fork()) == 0)
X	{
X		close(pfd[P_READ]);
X		close(TTYOUT);
X		dup(pfd[P_WRITE]);
X		close(pfd[P_WRITE]);
X		execl("/bin/pwd","pwd",(char *)0);
X		_exit(255);
X	}
X#if defined(FORK_DEBUG)
X	sprintf(s40,"DEBUG /bin/pwd pid %d",pipe_pid);
X	ecu_log_event(s40);	/* get_curr_dir */
X#endif
X	close(pfd[P_WRITE]);
X	if(pipe_pid == -1)
X	{
X		close(pfd[P_READ]);
X		return(-1);
X	}
X
X	while((count = read(pfd[P_READ],currdir,10)) != 0)
X	{
X		if(count < 0)
X		{
X			if(errno == EINTR)
X			{
X				errno = 0;
X				continue;
X			}
X			perror("pwd read error");
X			ff(se,"\r\n");
X			close(pfd[P_READ]);
X			return(-1);
X		}
X		currdir += count;
X		*currdir = 0;
X		if(*(currdir - 1) == '\n')
X		{
X			*(currdir - 1) = 0;
X			break;
X		}
X	}
X	close(pfd[P_READ]);
X#endif
X
X}	/* end of get_curr_dir */
X
X/*+-----------------------------------------------------------------------
X	get_home_dir(buffer):  leave plenty of room for result!
X------------------------------------------------------------------------*/
Xget_home_dir(home_dir)
Xchar *home_dir;
X{
Xregister char *cptr;
Xstatic char printed_error_msg = 0; /* only print err msg once per execution */
Xchar *getenv();
X#if BSD4
Xchar *getlogin();
X#endif
X
X	if(home_directory[0] != 'N')	/* if we have already determined, ... */
X	{
X		strcpy(home_dir,home_directory);	/* ... just copy and return */
X		return;
X	}
X
X	if(		((cptr = getenv("home")) == (char *)0)
X		&&	((cptr = getenv("HOME")) == (char *)0) )
X	{
X		if(printed_error_msg == 0)
X		{
X			ff(se,"Cannot read HOME environment parameter... \r\n");
X			ff(se,"gonna make a guess based on your user name\r\n");
X			printed_error_msg = 1;
X		}
X		strcpy(home_directory,"/usr/");
X#if defined(M_XENIX)
X		cuserid(&home_directory[strlen(home_directory) ]);
X#endif
X#if defined(pyr)
X		cptr = getlogin();
X		strcpy(&home_directory[strlen(home_directory) ],cptr);
X#endif
X#if((defined(M_XENIX) | defined(pyr)) == 0)
X\----> need M_XENIX or pyr defined
X#endif
X		ff(se,"using '%s'\r\n",home_directory);
X	}
X	else
X		strcpy(home_directory,cptr);	/* home directory to string */
X
X/* in case root is home */
X	if( (strlen(home_directory) == 1) && (home_directory[0] == '/'))
X		home_directory[0] = 0;		/* use null for home dir of root */
X
X	strcpy(home_dir,home_directory);
X
X}	/* end of get_home_dir */
X
X/*+-------------------------------------------------------------------------
X	mkdir(dpath,dmode)
X Directory-creating routines from Public Domain TAR by John Gilmore
X Make a directory.  Compatible with the mkdir() system call on 4.2BSD.
X--------------------------------------------------------------------------*/
X#define	TERM_SIGNAL(status)		((status) & 0x7F)
X#define TERM_COREDUMP(status)	(((status) & 0x80) != 0)
X#define TERM_VALUE(status)		((status) >> 8)
Xmkdir(dpath,dmode)
Xchar *dpath;
Xint dmode;
X{
X	int cpid,status;
X	struct stat statbuf;
X
X	if(stat(dpath,&statbuf) == 0)
X	{
X		errno = EEXIST;		/* Stat worked,so it already exists */
X		return(-1);
X	}
X
X	/* If stat fails for a reason other than non-existence,return error */
X	if(errno != ENOENT)
X		return(-1);
X
X	switch(cpid = fork())
X	{
X
X	case -1:			/* Error in fork() */
X		return(-1);		/* Errno is set already */
X
X	case 0:				/* Child process */
X		/*
X		 * Cheap hack to set mode of new directory.  Since this
X		 * child process is going away anyway,we zap its umask.
X		 * FIXME,this won't suffice to set SUID,SGID,etc. on this
X		 * directory.  Does anybody care?
X		 */
X		status = umask(0);	/* Get current umask */
X		status = umask(status | (0777 & ~dmode)); /* Set for mkdir */
X		execl("/bin/mkdir","mkdir",dpath,(char *)0);
X		_exit(-1);		/* Can't exec /bin/mkdir */
X
X	default:			/* Parent process */
X		while(cpid != wait(&status)) ;	/* Wait for kid to finish */
X	}
X
X	if(TERM_SIGNAL(status) != 0 || TERM_VALUE(status) != 0)
X	{
X		errno = EIO;		/* We don't know why,but */
X		return(-1);		/* /bin/mkdir failed */
X	}
X
X	return(0);
X}	/* end of mkdir */
X
X/*+-------------------------------------------------------------------------
X	make_dirs(pathname)
X
X  Directory-creating routines from Public Domain TAR by John Gilmore
X  After a file/link/symlink/dir creation has failed, see if it's because
X  some required directory was not present, and if so, create all
X  required dirs.
X
X  returns 0 if no directory made, else # levels required to get target
X--------------------------------------------------------------------------*/
Xint
Xmake_dirs(pathname)
Xregister char *pathname;
X{
X	register char *p;			/* Points into path */
X	int madeone = 0;			/* Did we do anything yet? */
X	int save_errno = errno;		/* Remember caller's errno */
X
X	if(errno != ENOENT)
X		return(0);		/* Not our problem */
X
X	for(p = strchr(pathname,'/'); p != NULL; p = strchr(p+1,'/'))
X	{
X		/* Avoid mkdir of empty string,if leading or double '/' */
X		if(p == pathname || p[-1] == '/')
X			continue;
X		/* Avoid mkdir where last part of path is '.' */
X		if(p[-1] == '.' && (p == pathname+1 || p[-2] == '/'))
X			continue;
X		*p = 0;				/* Truncate the path there */
X		if( !mkdir(pathname,0777))
X		{	/* Try to create it as a dir */
X			madeone++;		/* Remember if we made one */
X			*p = '/';
X			continue;
X		}
X		*p = '/';
X		if(errno == EEXIST)		/* Directory already exists */
X			continue;
X		/*
X		 * Some other error in the mkdir.  We return to the caller.
X		 */
X		break;
X	}
X	errno = save_errno;		/* Restore caller's errno */
X	return(madeone);		/* Tell them to retry if we made one */
X}	/* end of make_dirs */
X
X/*+-------------------------------------------------------------------------
X	make_ecu_subdir()
Xmust be called early in execution before wierd tty states set, etc.
X--------------------------------------------------------------------------*/
Xvoid
Xmake_ecu_subdir()
X{
Xint itmp;
Xstruct stat fst;
Xchar s256[256];
X
X	get_home_dir(s256);
X	strcat(s256,"/.ecu");
X	if((!(itmp = stat(s256,&fst))) && ((fst.st_mode & S_IFMT) != S_IFDIR))
X	{
X		ff(se,"~/.ecu is not a directory. Rename the file and try again.\n\n");
X		exit(1);
X	}
X	if(itmp)		/* if stat failed, try to make the directory */
X	{
X		strcat(s256,"/.");
X		if(make_dirs(s256))
X		{
X			if(stat(s256,&fst))
X			{
X				ff(se,"cannot make ~/.ecu subdirectory.\n");
X				perror(s256);
X				exit(1);
X			}
X		}
X	}
X}	/* end of make_ecu_subdir */
X
X/*+-------------------------------------------------------------------------
X	yes_or_no(strarg)
X  Returns 1 if first char is 'Y' or 'y'
X	or if strarg is numeric returns the numeric value
X	or if strarg is alpha == "on" returns 1
X  Returns 0 otherwise
X--------------------------------------------------------------------------*/
Xyes_or_no(strarg)
Xchar *strarg;
X{
X	if((strcmp(strarg,"on") == 0) || (to_lower(*strarg) == 'y'))
X		return(1);
X	else
X		return(atoi(strarg));
X}	/* end of yes_or_no */
X
X/*+-------------------------------------------------------------------------
X	find_shell_chars(command)
X--------------------------------------------------------------------------*/
Xfind_shell_chars(command)
Xchar *command;
X{
Xregister schar;
Xregister cchar;
Xregister char *scptr;
Xstatic char shell_chars[] = "~;*?'`{}[]$";
X
X	while(cchar = *command++)
X	{
X		scptr = shell_chars;
X		while(schar = *scptr++)
X			if(schar == cchar)
X				return(1);
X	}
X	return(0);
X}	/* end of find_shell_chars */
X
X/*+-------------------------------------------------------------------------
X	perror_errmsg(str)
X--------------------------------------------------------------------------*/
Xvoid
Xperror_errmsg(str)
Xchar *str;
X{
Xextern char errmsg[];
Xextern char *sys_errlist[];
Xextern int sys_nerr;
Xextern int errno;
X
X	if(errno > sys_nerr)
X		sprintf(errmsg,"%s: error %d",str,errno);
X	else
X		sprintf(errmsg,"%s: %s",str,sys_errlist[errno]);
X}	/* end of perror_errmsg */
X
X/*+-----------------------------------------------------------------------
X	mode_map(mode,mode_str)	build drwxrwxrwx string
X------------------------------------------------------------------------*/
Xchar *
Xmode_map(mode,mode_str)
Xunsigned short mode;
Xchar *mode_str;
X{
Xregister unsigned ftype = mode & S_IFMT;
Xregister char *rtn;
Xstatic char result[12];
X
X	rtn = (mode_str == (char *)0) ? result : mode_str;
X
X	/*          drwxrwxrwx */
X	/*          0123456789 */
X	strcpy(rtn,"----------");
X
X	switch(ftype)
X	{
X		case S_IFIFO:	*rtn = 'p'; break; /* FIFO (named pipe) */
X		case S_IFDIR:	*rtn = 'd'; break; /* directory */
X		case S_IFCHR:	*rtn = 'c'; break; /* character special */
X		case S_IFBLK:	*rtn = 'b'; break; /* block special */
X		case S_IFREG:	*rtn = '-'; break; /* regular */
X
X#if defined(pyr) | defined(BSD4)
X		case S_IFLNK:	*rtn = 'l'; break; /* symbolic link */
X		case S_IFSOCK:	*rtn = 's'; break; /* socket */
X#endif
X
X#if defined (M_XENIX) | defined(SYS5)
X		case S_IFNAM:						/* name space entry */
X			if(mode & S_INSEM)				/* semaphore */
X			{
X				*rtn = 's';
X				break;
X			}
X			if(mode & S_INSHD)				/* shared memory */
X			{
X				*rtn = 'm';
X				break;
X			}
X#endif
X
X		default:		*rtn = '?'; break;	/* ??? */
X	}
X
X	if(mode & 000400) *(rtn + 1) = 'r';
X	if(mode & 000200) *(rtn + 2) = 'w';
X	if(mode & 000100) *(rtn + 3) = 'x';
X	if(mode & 004000) *(rtn + 3) = 's';
X	if(mode & 000040) *(rtn + 4) = 'r';
X	if(mode & 000020) *(rtn + 5) = 'w';
X	if(mode & 000010) *(rtn + 6) = 'x';
X	if(mode & 002000) *(rtn + 6) = 's';
X	if(mode & 000004) *(rtn + 7) = 'r';
X	if(mode & 000002) *(rtn + 8) = 'w';
X	if(mode & 000001) *(rtn + 9) = 'x';
X	if(mode & 001000) *(rtn + 9) = 't';
X
X	return(rtn);
X
X}	/* end of mode_map */
X
X/* end of ecuutil.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo "File ecuutil.c is complete"
chmod 0644 ecuutil.c || echo "restore of ecuutil.c fails"
echo "x - extracting ecuwinutil.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuwinutil.c &&
X/* CHK=0xBACC */
X/*+-------------------------------------------------------------------------
X	ecuwinutil.c - curses window utilities
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	clear_area(win,y,x,len)
X	clear_area_char(win,y,x,len,fillchar)
X	winbox(win)
X	window_create(title,title_x,tly,tlx,lines,cols)
X	window_setup(win,title,title_x)
X	windows_end(last_win)
X	windows_end_signal()
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/*: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#include "ecukey.h"
X#include "pc_scr.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
Xint windows_active = 0;
Xint ttymode_before_window_start;
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{
X
X	ttymode_before_window_start = get_ttymode();
X	ttymode(0);
X	initscr();
X	savetty(); raw(); noecho(); nonl(); clear();
X	windows_active = 1;
X
X}	/* end of windows_start */
X
X/*+-------------------------------------------------------------------------
X	windows_end(last_win)
X--------------------------------------------------------------------------*/
Xvoid
Xwindows_end(last_win)
XWINDOW *last_win;
X{
X	if(last_win)
X		wrefresh(last_win);
X/*
X	resetty();
X*/
X	endwin();
X	curmove(LINES - 1,0);
X	ttymode(ttymode_before_window_start);
X	windows_active = 0;
X}	/* end of windows_end */
X
X/*+-------------------------------------------------------------------------
X	windows_end2()
X--------------------------------------------------------------------------*/
Xvoid
Xwindows_end2()
X{
X	endwin();
X	ttymode(ttymode_before_window_start);
X	windows_active = 0;
X}	/* end of windows_end2 */
X
X/*+-------------------------------------------------------------------------
X	windows_end_signal() -- called by hangup()
X--------------------------------------------------------------------------*/
Xvoid
Xwindows_end_signal()
X{
X	windows_end((WINDOW *)0);
X}	/* end of windows_end_signal */
X
X/*+-------------------------------------------------------------------------
X	winbox(win)
X--------------------------------------------------------------------------*/
Xwinbox(win)
XWINDOW *win;
X{
X	box(win,sVR,sHR);
X	wmove(win,0,0); waddch(win,sTL);
X	wmove(win,win->_maxy - 1,0); waddch(win,sBL);
X	wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,sBR);
X	wmove(win,0,win->_maxx - 1); waddch(win,sTR);
X
X}	/* end of winbox */
X
X/*+-------------------------------------------------------------------------
X	window_setup(win)
X--------------------------------------------------------------------------*/
Xvoid
Xwindow_setup(win,title,title_x)
XWINDOW *win;
Xchar *title;
X{
Xregister 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;
X{
Xregister WINDOW *nwin = newwin(lines,cols,tly,tlx);
X	
X	if(nwin)
X		window_setup(nwin,title,title_x);
X	return(nwin);
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 y;
Xregister x;
Xchar *buf;
Xregister bufsize;	/* includes room for null..field is 1 less */
Xregister uchar *delim;
Xint wait_for_key;
X{
Xregister 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 itmp;
Xregister nlen = strlen(nondelim_list);
Xregister dlen = strlen(delim_list);
Xregister ichar;
X
X	wrefresh(win);
X
X	while(1)
X	{
X		ichar = to_lower(ttygetc(1));
X		for(itmp = 0; itmp < nlen; itmp++)
X		{
X			if(ichar == nondelim_list[itmp])
X			{
X				waddch(win,to_upper(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		ring_bell();
X	}
X
X}	/* end of winget_single */
X/* end of ecuwinutil.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
chmod 0644 ecuwinutil.c || echo "restore of ecuwinutil.c fails"
echo "x - extracting ecuxenix.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > ecuxenix.c &&
X/* CHK=0x238C */
X#define MORSE
X/*+-----------------------------------------------------------------
X	ecuxenix.c -- XENIXisms and IBM-ATisms
X	Copyright 1986,1989 Warren H. Tucker, III. All Rights Reserved
X
X  Defined functions:
X	morse_bell(xbell_type,count)
X	rename(from,to)
X	send_bell_fd(fd,count,nap_msec)
X	send_get_response(token,narg,arg)
X	set_bell_fd(fd,pitch,duration)
X	set_default_escape_prompt()
X	show_escape_prompt()
X	xbell(type,count)
X	xbell_fd(fd,type,count)
X	xenix_bell_alarm(xbell_type)
X	xenix_bell_notify(xbell_type)
X	xenix_kbd_escape(xkey)
X	xenix_signal_str(sig)
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 "ecu.h"
X#include "ecukey.h"
X#include "ecufkey.h"
X#include "ecuxkey.h"
X#include "ecufork.h"
X#include "esd.h"
X
X#if defined(MORSE)
X#include <local/morse_dvr.h>
X#endif
X
Xchar *get_ttyname();
X
Xextern char curr_dir[]; /* current working key defns */
Xextern KDE keyset_table[];
Xextern char keyset_name[];
Xextern int want_bell_notify;	/* want xenix bell notify */
Xextern int current_colors;
X
XESD *icmd_prompt;		/* interactive command prompt */
Xint icmd_prompt_len;
X
X/*+-------------------------------------------------------------------------
X	show_escape_prompt()
X--------------------------------------------------------------------------*/
Xshow_escape_prompt()
X{
Xchar prompt_last;
X
X	prompt_last = 'd';	/* dummy */
X	if(icmd_prompt->cb)
X		prompt_last = *(icmd_prompt->pb + icmd_prompt->cb - 1);
X
X	icmd_prompt_len = 0;
X	shmx_make_rcvr_sleep(1);
X	if(!(current_colors & 0xFFFF0000L) || !(current_colors & 0xFFFFL))
X	{
X		/* fgnd: lt_green on black, bgnd: red on white */
X		setcolor(0x04070A00L);
X	}
X	stand_out();
X	if(icmd_prompt->cb)
X	{
X		ff(se," %s",icmd_prompt->pb);
X		icmd_prompt_len += icmd_prompt->cb + 1;
X	}
X	if(isalnum(prompt_last))
X	{
X		fputs(" %",se);
X		icmd_prompt_len += 2;
X	}
X	stand_end();
X	fputc(' ',se);
X	icmd_prompt_len++;
X	fflush(so);
X	return(icmd_prompt_len);
X
X}	/* end of show_escape_prompt */
X
X/*+-------------------------------------------------------------------------
X	set_default_escape_prompt()
X--------------------------------------------------------------------------*/
Xvoid
Xset_default_escape_prompt()
X{
Xregister char *cptr;
X
X	if((cptr = getenv("ECUPROMPT")) != (char *)0)
X	{
X		strncpy(icmd_prompt->pb,cptr,icmd_prompt->maxcb);
X		*(icmd_prompt->pb + icmd_prompt->maxcb - 1) = 0;
X		icmd_prompt->cb = strlen(icmd_prompt->pb);
X		null_terminate_esd(icmd_prompt);
X	}
X
X}	/* end of set_default_escape_prompt */
X
X/*+-------------------------------------------------------------------------
X	xenix_kbd_escape() -- xmtr got extended key -- process it
Xreturns(1)
X--------------------------------------------------------------------------*/
Xxenix_kbd_escape(xkey)
Xuchar xkey;
X{
Xregister itmp;
Xregister backspace_count;
Xregister KDE *tkde;
Xchar icmd_buf[128];
X
X	switch(xkey)
X	{
X		case XFhome:	 /* home key pressed ? */
X			backspace_count = show_escape_prompt();
X			ttygets(icmd_buf,sizeof(icmd_buf),0);
X			itmp = icmd_buf[0];
X			if((itmp == 0) || (itmp == 0x1B))
X			{
X				while(backspace_count--)
X					ff(se,"\b \b");
X				break;
X			}
X			switch(icmd(icmd_buf))
X			{
X				case 0:
X					break;
X				default:
X					hangup(HANGUP_OK);
X			}
X			break;
X
X		default:
X			if((itmp = xf_to_keyid(xkey)) < 0)
X			{
X				ring_bell();
X				break;
X			}
X			tkde = &keyset_table[itmp];
X			if((itmp = tkde->outcount) > 0)
X			{
X			register char *cptr = tkde->outstr;
X				while(itmp--)
X					lputc(*cptr++);
X			}
X			else if(tkde->outcount < 0)
X			{
X				switch(tkde->outcount)
X				{
X					case KACT_LOCAL_SHELL:
X						fputs("\r\n",se);
X						stand_out();
X						ff(se," local shell in %s ",curr_dir);
X						stand_end();
X						icmd("!");		/* spawn shell */
X				}
X			}
X			else
X				ring_bell();
X			break;
X	}
X	return(1);
X}	/* end of xenix_kbd_escape */
X
X/*+-------------------------------------------------------------------------
X	set_bell_fd(fd,pitch,duration)
XExample: 1B 5B 3D 34 30 30 30 3B 31 42 | .[=4000;1B
X--------------------------------------------------------------------------*/
Xvoid
Xset_bell_fd(fd,pitch,duration)
Xint fd;
Xint pitch;
Xint duration;
X{
Xchar bell_cmd[32];
X	sprintf(bell_cmd,"\033[=%d;%dB",pitch,duration);
X	write(fd,bell_cmd,strlen(bell_cmd));
X}	/* end of set_bell_fd */
X
X/*+-------------------------------------------------------------------------
X	send_bell_fd(fd,count,nap_msec)
X--------------------------------------------------------------------------*/
SHAR_EOF
echo "End of part 11"
echo "File ecuxenix.c is continued in part 12"
echo "12" > 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