Newsgroups: comp.sources.misc
From: Peter Reilley <pvr@wang.com>
Subject:  v22i010:  beav - Binary file editor and viewer, Part01/09
Message-ID: <csm-v22i010=beav.150407@sparky.imd.sterling.com>
X-Md4-Signature: 0a4b724725e1fc94b009fef41b8e9d11
Date: Wed, 14 Aug 1991 20:06:00 GMT
Approved: kent@sparky.imd.sterling.com

Submitted-by: Peter Reilley <pvr@wang.com>
Posting-number: Volume 22, Issue 10
Archive-name: beav/part01
Environment: UNIX, AIX, MSDOS

        This release 1.30 of BEAV (Binary Editor And Viewer), is
a full featured binary file editor.	  Just about any operation that 
you could want to do to a binary file is possible with BEAV.   You 
can insert or delete in the middle of a file thereby changing it's size.
You can display and edit data in hex, octal, decimal, binary, ascii, 
or ebcdic formats.   You can display data in byte, word, or long word 
formats in either Intel or Motorola byte ordering.   You can send the 
formatted display mode to a file or printer.   And much more.

	The new features in release 1.30 include;

*	The n-way-split command allows a binary file to be split, 
byte by byte, among different output files.   This is useful in 
creating PROM image files.   The n-way-combine command can put 
PROM files together again.

*	BEAV should compile on BSD UNIX based machines now.   Thanks to 
some user suggestions.

*	Deleting a range of data is much faster now.

*	Commands that can take a lot of time can be stopped.

*	Memory allocation errors require a response from the user rather
than just printing a warning.  This is mostly a MSDOS problem.   Some
people didn't see the error message and complained about data loss.

*	Plus some bug fixes. 

pvr@wang.com (Peter Reilley)
-----
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 9)."
# Contents:  beav.lnk cinfo.c ebcdic.c fileio.c kbd.c makefile.286
#   makefile.bsd makefile.dos makefile.ibm makefile.uxv region.c
#   spawn.c tcap.c termio.c tty.c ttyio.c wangpc.c word.c
# Wrapped by pvr@elf on Mon Aug 12 13:51:28 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'beav.lnk' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'beav.lnk'\"
else
echo shar: Extracting \"'beav.lnk'\" \(193 characters\)
sed "s/^X//" >'beav.lnk' <<'END_OF_FILE'
XBASIC +BUFFER +CINFO +DISPLAY +ECHO +EXTEND + EBCDIC +
XFILE +FILEIO +FORMAT +KBD +LINE +MAIN +RANDOM +REGION +
XSEARCH +SPAWN +SYMBOL +TEXT +TTY +TTYIO +TTYKBD +
XWINDOW +WORD + WANGPC
XBEAV.EXE;
END_OF_FILE
if test 193 -ne `wc -c <'beav.lnk'`; then
    echo shar: \"'beav.lnk'\" unpacked with wrong size!
fi
# end of 'beav.lnk'
fi
if test -f 'cinfo.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cinfo.c'\"
else
echo shar: Extracting \"'cinfo.c'\" \(2478 characters\)
sed "s/^X//" >'cinfo.c' <<'END_OF_FILE'
X/*
X*		Character class tables.
X* Do it yourself character classification
X* macros, that understand the multinational character set,
X* and let me ask some questions the standard macros (in
X* ctype.h) don't let you ask.
X*/
X#define LINT_ARGS   1           /* enable lint type checking */
X#include	"def.h"
X
X/*
X* This table, indexed by a character drawn
X* from the 256 member character set, is used by my
X* own character type macros to answer questions about the
X* type of a character. It handles the full multinational
X* character set, and lets me ask some questions that the
X* standard "ctype" macros cannot ask.
X*/
Xchar    cinfo[256] =
X{
X
X	_C, _C, _C, _C,             /* 0x0X	 */
X	_C, _C, _C, _C,
X	_C, _C, _C, _C,
X	_C, _C, _C, _C,
X	_C, _C, _C, _C,             /* 0x1X	 */
X	_C, _C, _C, _C,
X	_C, _C, _C, _C,
X	_C, _C, _C, _C,
X	0, 0, 0, 0,                 /* 0x2X	 */
X	_W, 0, 0, _W,
X	0, 0, 0, 0,
X	0, 0, 0, 0,
X	_W, _W, _W, _W,             /* 0x3X	 */
X	_W, _W, _W, _W,
X	_W, _W, 0, 0,
X	0, 0, 0, 0,
X	0, _U | _W, _U | _W, _U | _W,/* 0x4X	 */
X	_U | _W, _U | _W, _U | _W, _U | _W,
X	_U | _W, _U | _W, _U | _W, _U | _W,
X	_U | _W, _U | _W, _U | _W, _U | _W,
X	_U | _W, _U | _W, _U | _W, _U | _W,/* 0x5X	 */
X	_U | _W, _U | _W, _U | _W, _U | _W,
X	_U | _W, _U | _W, _U | _W, 0,
X	0, 0, 0, _W,
X	0, _L | _W, _L | _W, _L | _W,/* 0x6X	 */
X	_L | _W, _L | _W, _L | _W, _L | _W,
X	_L | _W, _L | _W, _L | _W, _L | _W,
X	_L | _W, _L | _W, _L | _W, _L | _W,
X	_L | _W, _L | _W, _L | _W, _L | _W,/* 0x7X	 */
X	_L | _W, _L | _W, _L | _W, _L | _W,
X	_L | _W, _L | _W, _L | _W, 0,
X	0, 0, 0, _C,
X	0, 0, 0, 0,                 /* 0x8X	 */
X	0, 0, 0, 0,
X	0, 0, 0, 0,
X	0, 0, 0, 0,
X	0, 0, 0, 0,                 /* 0x9X	 */
X	0, 0, 0, 0,
X	0, 0, 0, 0,
X	0, 0, 0, 0,
X	0, 0, 0, 0,                 /* 0xAX	 */
X	0, 0, 0, 0,
X	0, 0, 0, 0,
X	0, 0, 0, 0,
X	0, 0, 0, 0,                 /* 0xBX	 */
X	0, 0, 0, 0,
X	0, 0, 0, 0,
X	0, 0, 0, 0,
X	_U | _W, _U | _W, _U | _W, _U | _W,/* 0xCX	 */
X	_U | _W, _U | _W, _U | _W, _U | _W,
X	_U | _W, _U | _W, _U | _W, _U | _W,
X	_U | _W, _U | _W, _U | _W, _U | _W,
X	0, _U | _W, _U | _W, _U | _W,/* 0xDX	 */
X	_U | _W, _U | _W, _U | _W, _U | _W,
X	_U | _W, _U | _W, _U | _W, _U | _W,
X	_U | _W, _U | _W, 0, _W,
X	_L | _W, _L | _W, _L | _W, _L | _W,/* 0xEX	 */
X	_L | _W, _L | _W, _L | _W, _L | _W,
X	_L | _W, _L | _W, _L | _W, _L | _W,
X	_L | _W, _L | _W, _L | _W, _L | _W,
X	0, _L | _W, _L | _W, _L | _W,/* 0xFX	 */
X	_L | _W, _L | _W, _L | _W, _L | _W,
X	_L | _W, _L | _W, _L | _W, _L | _W,
X	_L | _W, _L | _W, 0, 0
X};
X
END_OF_FILE
if test 2478 -ne `wc -c <'cinfo.c'`; then
    echo shar: \"'cinfo.c'\" unpacked with wrong size!
fi
# end of 'cinfo.c'
fi
if test -f 'ebcdic.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ebcdic.c'\"
else
echo shar: Extracting \"'ebcdic.c'\" \(2513 characters\)
sed "s/^X//" >'ebcdic.c' <<'END_OF_FILE'
X
X#define LINT_ARGS   1           /* enable lint type checking */
X#include    "def.h"
X
Xextern    char    ERR_ebcdic[];
X
X/* Function definitions */
X
X/* This table defines the translation from EBCDIC code to ASCII. */
X
Xchar    ebcdic_table[] =
X{
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 00-07 */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 08-0F */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 10-17 */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 18-1F */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 20-27 */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 28-2F */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 30-37 */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 38-3F */
X	0x20, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 40-47 */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x3C, 0x28, 0x2B, 0x2E,/* 48-4F */
X	0x26, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 50-57 */
X	0x2E, 0x2E, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,/* 58-5F */
X	0x2D, 0x2F, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 60-67 */
X	0x2E, 0x2E, 0x7C, 0x2E, 0x25, 0x5F, 0x3E, 0x3F,/* 68-6F */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x27, 0x2E, 0x2E,/* 70-77 */
X	0x2E, 0x60, 0x3A, 0x23, 0x40, 0x2C, 0x3D, 0x22,/* 78-7F */
X	0x2E, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,/* 80-87 */
X	0x68, 0x69, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 88-8F */
X	0x2E, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,/* 90-97 */
X	0x71, 0x72, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* 98-9F */
X	0x2E, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,/* A0-A7 */
X	0x79, 0x7A, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* A8-AF */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* B0-B7 */
X	0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* B8-BF */
X	0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,/* C0-C7 */
X	0x48, 0x49, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* C8-CF */
X	0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,/* D0-D7 */
X	0x51, 0x52, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* D8-DF */
X	0x5C, 0x2E, 0X53, 0x54, 0x55, 0x56, 0x57, 0x58,/* E0-E7 */
X	0x59, 0x5A, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E,/* E8-EF */
X	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,/* F0-F7 */
X	0x38, 0x39, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E/* F8-FF */
X};
X
X/* convert a ASCII character to an EBCDIC character */
Xchar    to_ebcdic (ch)
X
Xchar    ch;
X{
X	int     cnt;
X	char    buf[70], buf1[70];
X
X	for (cnt = 0; cnt < sizeof (ebcdic_table); cnt++)
X	{
X		if (ch == ebcdic_table[cnt])
X			return (cnt);
X	}
X	sprintf (buf1, ERR_ebcdic, R_BYTE_FMT(curwp));
X	sprintf (buf, buf1, ch);
X	writ_echo(buf);
X	return (0);
X}
END_OF_FILE
if test 2513 -ne `wc -c <'ebcdic.c'`; then
    echo shar: \"'ebcdic.c'\" unpacked with wrong size!
fi
# end of 'ebcdic.c'
fi
if test -f 'fileio.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fileio.c'\"
else
echo shar: Extracting \"'fileio.c'\" \(4365 characters\)
sed "s/^X//" >'fileio.c' <<'END_OF_FILE'
X/*
X*    file I/O.
X*/
X
X#ifdef UNIX
X#include	<sys/types.h> 
X#include	<fcntl.h> 
X#include	<sys/stat.h> 
X#endif
X#include        "def.h"
X
Xextern    char    MSG_cnt_wr[];
Xextern    char    MSG_wr_io_er[];
Xextern    char    MSG_rd_er[];
Xextern    char    MSG_bak[];
Xextern    char    MSG_backup[];
Xextern    char    MSG_back_er[];
Xextern    char    MSG_back_of[];
X
X#ifdef MSDOS
Xstatic  FILE * ffp;
X#endif
X
X#ifdef UNIX
Xstatic  int ffp;
X#endif
X
X/*
X* Open a file for reading.
X*/
Xchar    ffropen (fn)
Xchar   *fn;
X{
X#ifdef MSDOS
X	if ((ffp = fopen (fn, "rb")) == NULL)/* pvr */
X		return (FIOERR);
X	;
X	return (FIOSUC);
X#endif
X#ifdef UNIX
X	if ((ffp = open (fn, O_RDONLY)) == -1)/* pvr */
X		return (FIOERR);
X	;
X	return (FIOSUC);
X#endif
X}
X/*
X*   Get the file length
X*/
XA32 file_len ()
X{
X#ifdef MSDOS
X	return (filelength (fileno (ffp)));
X#endif
X#ifdef UNIX
X	struct	stat	st;
X
X	if (fstat (ffp, &st) == -1)
X		return (-1);
X	return (st.st_size);
X#endif
X}
X
X/*
X* Open a file for writing.
X* Return TRUE if all is well, and
X* FALSE on error (cannot create).
X*/
Xchar    ffwopen (fn)
Xchar   *fn;
X{
X#ifdef MSDOS
X	if ((ffp = fopen (fn, "wb")) == NULL)/* pvr */
X	{
X		err_echo (MSG_cnt_wr);
X		return (FIOERR);
X	}
X	return (FIOSUC);
X#endif
X#ifdef UNIX
X	/* set perms  1.13 */
X	if ((ffp = open (fn, O_WRONLY | O_CREAT, S_IREAD | S_IWRITE)) == -1)/* pvr */
X		return (FIOERR);
X	;
X	return (FIOSUC);
X#endif
X}
X
X/*
X* Close a file.
X* Should look at the status.
X*/
Xchar    ffclose ()
X{
X#ifdef MSDOS
X	fclose (ffp);
X#endif
X#ifdef UNIX
X	close (ffp);
X#endif
X	return (FIOSUC);
X}
X
X/*
X* Write a line to the already
X* opened file. The "buf" points to the
X* buffer, and the "nbuf" is its length.   pvr
X* Return the status.
X*/
Xchar    ffputline (buf, nbuf)
Xregister char   buf[];
Xint     nbuf;
X{
X	register int    i;
X
X#ifdef MSDOS
X	i = fwrite (buf, 1, nbuf, ffp);
X#endif
X#ifdef UNIX 
X	i = write (ffp, buf, nbuf);
X#endif
X
X	if ((i != nbuf)
X#ifdef MSDOS	
X	    || (ferror (ffp) != FALSE))
X#else
X		)
X#endif     
X		    {
X			err_echo (MSG_wr_io_er);
X			return (FIOERR);
X		}
X	return (FIOSUC);
X}
X
X/*
X* Read a line from a file, and store the bytes
X* in the supplied buffer. Stop on end of file or after 'nbuf' characters. pvr
X* the first byte in the buffer is the length in bytes.
X*/
Xchar    ffgetline (buf, nbuf, rbuf)
Xregister char   *buf;
Xregister LPOS   *rbuf, nbuf;
X{
X#ifdef MSDOS
X	*rbuf = fread (buf, 1, nbuf, ffp);
X#endif
X
X#ifdef UNIX
X	*rbuf = read (ffp, buf, nbuf);
X#endif
X
X	/* End of file.         */
X#ifdef MSDOS
X	if (ferror (ffp) != FALSE)
X	{
X		err_echo (MSG_rd_er);
X		return (FIOERR);
X	}
X#endif
X	if (*rbuf == 0)
X		return (FIOEOF);
X
X	return (FIOSUC);
X}
X
X/*
X*   Seek to specified position in file.
X*   Return the actual position in the file.
X*/
XA32     ffseek (posn)
XA32     posn;
X{
X#ifdef MSDOS
X	fseek (ffp, posn, SEEK_SET);
X	return (ftell (ffp));
X#endif
X#ifdef UNIX
X	return (lseek (ffp, posn, 0));
X#endif
X}
X
X/*
X* Some backup user on MS-DOS might want
X* to determine some rule for doing backups on that
X* system, and fix this. I don't use MS-DOS, so I don't
X* know what the right rules would be. Return TRUE so
X* the caller does not abort a write.
X*/
X#if BACKUP
Xbool    fbackupfile (fname)
Xchar   *fname;
X{
X	FILE * backupfile;
X	char    backname[128];
X	char   *source,
X	*backup;
X	extern char time_string[];
X	char    buf[80];
X
X	source = fname;
X	backup = backname;
X	while ((*source > 0) && (*source != '.'))
X	{
X		*backup = *source;
X		backup++;
X		source++;
X		*backup = 0;
X	}
X	strcat (backname, MSG_bak);
X	sprintf (buf, MSG_backup, fname, backname);
X	writ_echo (buf);
X	unlink (backname);
X#ifdef MSDOS
X	if (rename (backname, fname) > 0)
X#else
X		if ((link (fname, backname) != 0) || (unlink (fname) != 0))
X#endif
X		{
X			sprintf (buf, MSG_back_er, fname, backname);
X			err_echo (buf);
X			return (FALSE);
X		}
X	return (TRUE);              /* Hack.                */
X}
X
X#endif
X
X/*
X* The string "fn" is a file name.
X* Perform any required case adjustments. All systems
X* we deal with so far have case insensitive file systems.
X* We zap everything to lower case. The problem we are trying
X* to solve is getting 2 buffers holding the same file if
X* you visit one of them with the "caps lock" key down.
X* On UNIX file names are dual case, so we leave
X* everything alone.
X*/
Xvoid    adjustcase (fn)
Xregister char  *fn;
X{
X	register int    c;
X
X	while ((c = *fn) != 0)
X	{
X		if (c >= 'A' && c <= 'Z')
X			*fn = c + 'a' - 'A';
X		++fn;
X	}
X}
X
X
END_OF_FILE
if test 4365 -ne `wc -c <'fileio.c'`; then
    echo shar: \"'fileio.c'\" unpacked with wrong size!
fi
# end of 'fileio.c'
fi
if test -f 'kbd.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kbd.c'\"
else
echo shar: Extracting \"'kbd.c'\" \(3934 characters\)
sed "s/^X//" >'kbd.c' <<'END_OF_FILE'
X/*                      KBD.C
X*       Terminal independent keyboard handling.
X*/
X#define LINT_ARGS   1           /* enable lint type checking */
X#include    "def.h"
X
Xchar    *keystrings ();
X
Xextern    char    MSG_tab[];
Xextern    char    MSG_esc[];
Xextern    char    MSG_ctl_x[];
Xextern    char    MSG_ctl[];
Xextern    char    MSG_fn[];
Xextern    char    MSG_ret[];
Xextern    char    MSG_bksp[];
Xextern    char    MSG_space[];
Xextern    char    MSG_rubout[];
X
X
X/*
X* Read in a key, doing the terminal
X* independent prefix handling. The terminal specific
X* "getkbd" routine gets the first swing, and may return
X* one of the special codes used by the special keys
X* on the keyboard. The "getkbd" routine returns the
X* C0 controls as received; this routine moves them to
X* the right spot in 11 bit code.
X*/
Xint     getkey ()
X{
X
X	register int    c;
X	c = getkbd ();
X	if (c == METACH)            /* M-           */
X	{
X		c = KMETA | getctl ();
X#ifdef VT100KEY
X		if ((c & KCHAR) == '[')
X			c = KMETA | KCTRL | KCTLX | getctl ();	/* flag VT100 sequence */
X#endif
X	}
X	else if (c == CTRLCH)        /* C-           */
X		c = KCTRL | getctl ();
X	else if (c == CTMECH)    /* C-M-         */
X		c = KCTRL | KMETA | getctl ();
X	else if (c >= 0x00 && c <= 0x1F)/* Relocate control.    */
X		c = KCTRL | (c + '@');
X
X	if (c == (KCTRL | 'X'))     /* C-X          */
X		c = KCTLX | getctl ();
X	return (c);
X}
X
X
X/*
X* Used above.
X*/
Xint     getctl ()
X{
X
X	register int    c;
X
X#if 1
X	c = getkbd ();
X	if (c == METACH)            /* M-           */
X		c = KMETA | getctl ();
X	else
X		if (c == CTRLCH)        /* C-           */
X			c = KCTRL | getctl ();
X		else
X			if (c == CTMECH)    /* C-M-         */
X				c = KCTRL | KMETA | getctl ();
X			else
X				if (c >= 0x00 && c <= 0x1F)/* Relocate control.    */
X					c = KCTRL | (c + '@');
X#else
X	c = getkey ();              /* Note recursion   */
X	if (ISLOWER (c & 0xFF))
X		c = (c & ~0xFF) | TOUPPER (c & 0xFF);
X	if (c >= 0x00 && c <= 0x1F) /* Relocate control.    */
X		c = KCTRL | (c + '@');
X#endif
X	if (ISLOWER (c & 0xFF))
X		c = (c & ~0xFF) | TOUPPER (c & 0xFF);
X	return (c);
X}
X
X
X/*
X* Transform a key code into a name,
X* using a table for the special keys and combination
X* of some hard code and some general processing for
X* the rest. None of this code is terminal specific any
X* more. This makes adding keys easier.
X*/
Xvoid keyname (cp, k)
Xregister char  *cp;
Xregister int    k;
X{
X	register char  *np;
X	char    nbuf[3];
X
X	static char hex[] =
X	{
X		'0', '1', '2', '3',
X		'4', '5', '6', '7',
X		'8', '9', 'A', 'B',
X		'C', 'D', 'E', 'F'
X	};
X	*cp = 0;	/* terminate previous string */
X#ifdef VT100KEY
X	if ((k & (KMETA | KCTRL | KCTLX)) == (int)(KMETA | KCTRL | KCTLX))
X	{
X		sprintf (&cp[strlen (cp)], MSG_fn);
X		sprintf (&cp[strlen (cp)], "%c", k & KCHAR);
X		return;
X	}
X#endif
X	if (k & 0x80)
X	{
X		if ((np = keystrings (k)) != NULL)
X		{
X			if ((k & KMETA) != 0)
X				sprintf (&cp[strlen (cp)], MSG_esc);
X
X			strcat (cp, np);
X		}
X		else
X			cp[strlen (cp)] = 0;    /* null string */
X		return;
X	}
X
X	if ((k & KCTLX) != 0)
X	{
X		/* Ctl-X prefix.      */
X		sprintf (&cp[strlen (cp)], MSG_ctl_x);
X		k &= ~KCTLX;
X	}
X
X	if ((k & KMETA) != 0)
X	{
X		/* Add Esc- mark.     */
X		sprintf (&cp[strlen (cp)], MSG_esc);
X		k &= ~KMETA;
X	}
X
X	if (k == (KCTRL | 'I'))/* Some specials.   */
X		np = MSG_tab;
X	else
X	{
X		if (k == (KCTRL | 'M'))
X			np = MSG_ret;
X		else if (k == (KCTRL | 'H'))
X			np = MSG_bksp;
X		else if (k == ' ')
X			np = MSG_space;
X		else if (k == 0x7F)
X			np = MSG_rubout;
X		else
X		{
X			if ((k & KCTRL) != 0)
X			{
X				/* Add Ctl- mark.     */
X				sprintf (&cp[strlen (cp)], MSG_ctl);
X			}
X			np = &nbuf[0];
X			if (((k & KCHAR) >= 0x20 && (k & KCHAR) <= 0x7E)
X			    || ((k & KCHAR) >= 0xA0 && (k & KCHAR) <= 0xFE))
X			{
X				nbuf[0] = k & KCHAR;/* Graphic.     */
X				nbuf[1] = 0;
X			}
X			else
X			{
X				/* Non graphic.     */
X				nbuf[0] = hex[(k >> 4) & 0x0F];
X				nbuf[1] = hex[k & 0x0F];
X				nbuf[2] = 0;
X			}
X		}
X	}
X	strcat (cp, np);
X}
X
END_OF_FILE
if test 3934 -ne `wc -c <'kbd.c'`; then
    echo shar: \"'kbd.c'\" unpacked with wrong size!
fi
# end of 'kbd.c'
fi
if test -f 'makefile.286' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.286'\"
else
echo shar: Extracting \"'makefile.286'\" \(665 characters\)
sed "s/^X//" >'makefile.286' <<'END_OF_FILE'
X# This is a makefile for 286 xenix
XCFLAGS=     -O -Ml -DUNIX -DNOPROTO
X
XOFILES=		basic.o ebcdic.o fileio.o region.o text.o wangpc.o \
X	buffer.o echo.o main.o search.o tty.o window.o \
X	cinfo.o extend.o kbd.o spawn.o ttyio.o termio.o tcap.o word.o \
X	display.o file.o line.o random.o symbol.o ttykbd.o format.o
X
X
XCFILES=     basic.c ebcdic.c fileio.c region.c text.c wangpc.c \
X	buffer.c echo.c format.c main.c search.c tty.c window.c \
X	cinfo.c extend.c kbd.c spawn.c ttyio.c termio.c tcap.c word.c \
X	display.c file.c line.c random.c symbol.c ttykbd.c
X
XHFILES=     def.h
X
Xbeav:     $(OFILES)
X	$(CC) $(CFLAGS) $(OFILES) -ltermcap -lc -o beav
X
X(OFILES):  $(HFILES)
X
END_OF_FILE
if test 665 -ne `wc -c <'makefile.286'`; then
    echo shar: \"'makefile.286'\" unpacked with wrong size!
fi
# end of 'makefile.286'
fi
if test -f 'makefile.bsd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.bsd'\"
else
echo shar: Extracting \"'makefile.bsd'\" \(657 characters\)
sed "s/^X//" >'makefile.bsd' <<'END_OF_FILE'
X# This is the makefile for BSD UNIX
XCFLAGS=     -O -DUNIX -DBSD
X
XOFILES=		basic.o ebcdic.o fileio.o region.o text.o wangpc.o \
X	buffer.o echo.o main.o search.o tty.o window.o \
X	cinfo.o extend.o kbd.o spawn.o ttyio.o termio.o tcap.o word.o \
X	display.o file.o line.o random.o symbol.o ttykbd.o format.o
X
X
XCFILES=     basic.c ebcdic.c fileio.c region.c text.c wangpc.c \
X	buffer.c echo.c format.c main.c search.c tty.c window.c \
X	cinfo.c extend.c kbd.c spawn.c ttyio.c termio.c tcap.c word.c \
X	display.c file.c line.c random.c symbol.c ttykbd.c
X
XHFILES=     def.h
X
Xbeav:     $(OFILES)
X	$(CC) $(CFLAGS) $(OFILES) -ltermcap -lc -o beav
X
X(OFILES):  $(HFILES)
END_OF_FILE
if test 657 -ne `wc -c <'makefile.bsd'`; then
    echo shar: \"'makefile.bsd'\" unpacked with wrong size!
fi
# end of 'makefile.bsd'
fi
if test -f 'makefile.dos' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.dos'\"
else
echo shar: Extracting \"'makefile.dos'\" \(1947 characters\)
sed "s/^X//" >'makefile.dos' <<'END_OF_FILE'
X# makefile for BEAV under MSDOS using Microsoft MSC 5.1
X
XBASIC.OBJ: BASIC.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml BASIC.C ;
X
XBUFFER.OBJ: BUFFER.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml BUFFER.C ;
X
XCINFO.OBJ: CINFO.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml CINFO.C ;
X
XDISPLAY.OBJ: DISPLAY.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml DISPLAY.C ;
X
XEBCDIC.OBJ: EBCDIC.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml EBCDIC.C ;
X
XECHO.OBJ: ECHO.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml ECHO.C ;
X
XEXTEND.OBJ: EXTEND.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml EXTEND.C ;
X
XFILE.OBJ: FILE.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml FILE.C ;
X
XFILEIO.OBJ: FILEIO.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml FILEIO.C ;
X
XFORMAT.OBJ: FORMAT.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml FORMAT.C ;
X
XKBD.OBJ: KBD.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml KBD.C ;
X
XLINE.OBJ: LINE.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml LINE.C ;
X
XMAIN.OBJ: MAIN.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml MAIN.C ;
X
XRANDOM.OBJ: RANDOM.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml RANDOM.C ;
X
XREGION.OBJ: REGION.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml REGION.C ;
X
XSEARCH.OBJ: SEARCH.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml SEARCH.C ;
X
XSPAWN.OBJ: SPAWN.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml SPAWN.C ;
X
XSYMBOL.OBJ: SYMBOL.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml SYMBOL.C ;
X
XTEXT.OBJ: TEXT.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml TEXT.C ;
X
XTTY.OBJ: TTY.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml TTY.C ;
X
XTTYIO.OBJ: TTYIO.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml TTYIO.C ;
X
XTTYKBD.OBJ: TTYKBD.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml TTYKBD.C ;
X
XWANGPC.OBJ: WANGPC.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml WANGPC.C ;
X
XWINDOW.OBJ: WINDOW.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml WINDOW.C ;
X
XWORD.OBJ: WORD.C DEF.H  LINTFUNC.DEC
X CL -c  -Ml WORD.C ;
X
XBEAV.EXE: BASIC.OBJ BUFFER.OBJ CINFO.OBJ DISPLAY.OBJ ECHO.OBJ EXTEND.OBJ \
X        EBCDIC.OBJ FILE.OBJ FILEIO.OBJ FORMAT.OBJ KBD.OBJ LINE.OBJ \
X        MAIN.OBJ RANDOM.OBJ TEXT.OBJ \
X        REGION.OBJ SEARCH.OBJ SPAWN.OBJ SYMBOL.OBJ TTY.OBJ TTYIO.OBJ   \
X        TTYKBD.OBJ WINDOW.OBJ WORD.OBJ WANGPC.OBJ
X LINK   @beav.lnk
X
X
X
X
END_OF_FILE
if test 1947 -ne `wc -c <'makefile.dos'`; then
    echo shar: \"'makefile.dos'\" unpacked with wrong size!
fi
# end of 'makefile.dos'
fi
if test -f 'makefile.ibm' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.ibm'\"
else
echo shar: Extracting \"'makefile.ibm'\" \(666 characters\)
sed "s/^X//" >'makefile.ibm' <<'END_OF_FILE'
X# This is a makefile for IBM  RS/6000  
XCFLAGS=     -O -DUNIX -DNOPROTO
X
XOFILES=		basic.o ebcdic.o fileio.o region.o text.o wangpc.o \
X	buffer.o echo.o main.o search.o tty.o window.o \
X	cinfo.o extend.o kbd.o spawn.o ttyio.o termio.o tcap.o word.o \
X	display.o file.o line.o random.o symbol.o ttykbd.o format.o
X
X
XCFILES=     basic.c ebcdic.c fileio.c region.c text.c wangpc.c \
X	buffer.c echo.c format.c main.c search.c tty.c window.c \
X	cinfo.c extend.c kbd.c spawn.c ttyio.c termio.c tcap.c word.c \
X	display.c file.c line.c random.c symbol.c ttykbd.c
X
XHFILES=     def.h
X
Xbeav:     $(OFILES)
X	$(CC) $(CFLAGS) $(OFILES) -ltermcap -lc -o beav
X
X(OFILES):  $(HFILES)
X
END_OF_FILE
if test 666 -ne `wc -c <'makefile.ibm'`; then
    echo shar: \"'makefile.ibm'\" unpacked with wrong size!
fi
# end of 'makefile.ibm'
fi
if test -f 'makefile.uxv' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.uxv'\"
else
echo shar: Extracting \"'makefile.uxv'\" \(663 characters\)
sed "s/^X//" >'makefile.uxv' <<'END_OF_FILE'
X# This is the makefile for System V UNIX
XCFLAGS=     -O -DUNIX -DSYSV
X
XOFILES=		basic.o ebcdic.o fileio.o region.o text.o wangpc.o \
X	buffer.o echo.o main.o search.o tty.o window.o \
X	cinfo.o extend.o kbd.o spawn.o ttyio.o termio.o tcap.o word.o \
X	display.o file.o line.o random.o symbol.o ttykbd.o format.o
X
X
XCFILES=     basic.c ebcdic.c fileio.c region.c text.c wangpc.c \
X	buffer.c echo.c format.c main.c search.c tty.c window.c \
X	cinfo.c extend.c kbd.c spawn.c ttyio.c termio.c tcap.c word.c \
X	display.c file.c line.c random.c symbol.c ttykbd.c
X
XHFILES=     def.h
X
Xbeav:     $(OFILES)
X	$(CC) $(CFLAGS) $(OFILES) -ltermcap -lc -o beav
X
X(OFILES):  $(HFILES)
END_OF_FILE
if test 663 -ne `wc -c <'makefile.uxv'`; then
    echo shar: \"'makefile.uxv'\" unpacked with wrong size!
fi
# end of 'makefile.uxv'
fi
if test -f 'region.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'region.c'\"
else
echo shar: Extracting \"'region.c'\" \(4256 characters\)
sed "s/^X//" >'region.c' <<'END_OF_FILE'
X/*
X*       Region based commands.
X* The routines in this file
X* deal with the region, that magic space
X* between "." and mark. Some functions are
X* commands. Some functions are just for
X* internal use.
X*/
X#include    "def.h"
X
Xbool getregion ();
X
Xextern    char    MSG_sv_in_b[];
Xextern    char    MSG_sav_slf[];
Xextern    char    MSG_no_mark[];
Xextern    char    MSG_procing[];
X
Xextern    BUFFER  sav_buf;
X
X/*
X* Kill the region. Ask "getregion"
X* to figure out the bounds of the region.
X* Move "." to the start, and kill the characters.
X*/
Xchar    killregion (f, n, k)
X{
X	register char   s;
X	REGION region;
X	WINDOW * wp;
X	int     error;
X
X	if ((s = getregion (&region)) != TRUE)
X		return (s);
X	if ((lastflag & CFKILL) == 0)/* This is a kill type  */
X		bclear (&sav_buf);
X	thisflag |= CFKILL;         /* kill buffer stuff.   */
X	curwp -> w_dotp = region.r_linep;
X	curwp -> w_doto = region.r_offset;
X	error = ldelete (region.r_size, TRUE);
X	/* cause the save buffer display to be updated if needed */
X	if (sav_buf.b_nwnd != 0)
X		showsavebuf ();
X	writ_echo (okmsg);
X	return (error);
X}
X
X
X/*
X* Copy all of the characters in the
X* region to the kill buffer. Don't move dot
X* at all. This is a bit like a kill region followed
X* by a yank.
X*/
Xchar    copyregion (f, n, k)
X{
X	register    LINE * linep;
X	register int    loffs, j;
X	register char   s;
X	REGION region;
X	char        buf[80], buf1[40];
X
X	j = 0;
X	if ((s = getregion (&region)) != TRUE)
X		return (s);
X	if ((lastflag & CFKILL) == 0)/* Kill type command.   */
X		bclear (&sav_buf);
X	thisflag |= CFKILL;
X	linep = region.r_linep;     /* Current line.    */
X	loffs = region.r_offset;    /* Current offset.  */
X	while (region.r_size--)
X	{
X		if ((s = b_append_c (&sav_buf, lgetc (linep, loffs))) != TRUE)
X			return (s);
X		++loffs;
X		if ((j++ & 0x2ff) == 0)
X		{
X			sprintf (buf1, MSG_procing, R_POS_FMT(curwp));
X			sprintf (buf, buf1, DOT_POS (curwp));
X			writ_echo (buf);
X			/* check if we should quit */
X			if (ttkeyready ())
X			{
X				wind_on_dot_all();
X				if (ttgetc () == '*')
X					return (FALSE);
X			}
X		}
X	}
X	/* cause the save buffer display to be updated if needed */
X	if (sav_buf.b_nwnd != 0)
X		showsavebuf ();
X	/* update buffer display */
X	if ((blistp -> b_nwnd != 0) &&
X	    (blistp -> b_type == BTLIST))
X		listbuffers ();
X	writ_echo (okmsg);
X	return (TRUE);
X}
X
X/*
X* This routine figures out the bound of the region
X* in the current window, and stores the results into the fields
X* of the REGION structure. Dot and mark are usually close together,
X* but I don't know the order. The size is kept in a long. At the
X* end, after the size is figured out, it is assigned to the size
X* field of the region structure. If this assignment loses any bits,
X* then we print an error. This is "type independent" overflow
X* checking. All of the callers of this routine should be ready to
X* get an ABORT status, because I might add a "if regions is big,
X* ask before clobberring" flag.
X*/
Xbool getregion (rp)
Xregister    REGION * rp;
X{
X	if (curwp -> w_markp == NULL)
X	{
X		writ_echo (MSG_no_mark);
X		return (FALSE);
X	}
X
X	if (DOT_POS(curwp) < MARK_POS(curwp))
X	{
X		rp -> r_linep = curwp -> w_dotp;
X		rp -> r_offset = curwp -> w_doto;
X		rp -> r_size = MARK_POS(curwp) - DOT_POS(curwp);
X	}
X	else
X	{
X		rp -> r_linep = curwp -> w_markp;
X		rp -> r_offset = curwp -> w_marko;
X		rp -> r_size = DOT_POS(curwp) - MARK_POS(curwp);
X	}
X	return (TRUE);
X}
X
X/* save some region in a buffer
X* (use _usebuffer to handle non-existent buffers)
X* 
X* hack as it uses kill buffer to transfer stuff (quick and dirty!)
X* and doesn't do clever things at all with dot in destination buffer!
X*/
Xchar    save_region (f, n, k)
X{
X	char    bufn[NBUFN];
X	char    oldbufn[NBUFN];
X	register char   s;
X
X	if ((s = ereply (MSG_sv_in_b, bufn, NBUFN, NULL)) != TRUE)
X		return (s);
X
X	if (strcmp (bufn, curbp -> b_bname) == 0)
X	{
X		writ_echo (MSG_sav_slf);
X		return (FALSE);
X	}
X
X	/* save this name for ughly reversal */
X	strcpy (oldbufn, curbp -> b_bname);
X
X	/* copy stuff using killbuffer as work space -  hack !! * than move it to
X    named place using yank - Quick AND Dirty */
X	copyregion (f, n, k);
X	_usebuffer (bufn);
X	curbp -> b_type = BTSAVE;   /* mark as a saved buffer */
X
X	yank (f, n, k);
X	_usebuffer (oldbufn);
X	writ_echo (okmsg);
X	return (TRUE);
X}
X
X
END_OF_FILE
if test 4256 -ne `wc -c <'region.c'`; then
    echo shar: \"'region.c'\" unpacked with wrong size!
fi
# end of 'region.c'
fi
if test -f 'spawn.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'spawn.c'\"
else
echo shar: Extracting \"'spawn.c'\" \(1388 characters\)
sed "s/^X//" >'spawn.c' <<'END_OF_FILE'
X/*
X*    MS-DOS spawn command.com
X*/
X#include        "def.h"
X
Xextern    char    MSG_shell[];
Xextern    char    MSG_def_shell[];
Xextern    char    MSG_pmpt[];
Xextern    char    MSG_pt[];
Xextern    char    MSG_pme[];
Xextern    char    MSG_null[];
X
X/* #include     <dos.h> */
X#if MSDOS
X#include        "process.h"
X#endif
Xchar   *cspec = NULL;           /* Command string.      */
Xchar   *pspec = NULL;
X
X/*
X* Create a subjob with a copy
X* of the command intrepreter in it. When the
X* command interpreter exits, mark the screen as
X* garbage so that you do a full repaint.
X*/
Xbool spawncli (f, n, k)
X{
X#if MSDOS
X
X	char   *getenv ();
X	char    old_prompt[128];
X	char    prompt_line[128];
X
X	ttcolor (CTEXT);            /* Normal color.        */
X	ttmove (nrow - 1, 0);       /* Last line.           */
X	ttflush ();
X	ttcooked ();
X#ifndef IBM
X	strcpy (prompt_line, MSG_pmpt);
X	pspec = getenv (MSG_pt);
X	strcpy (old_prompt, pspec);
X	strcat (prompt_line, pspec);
X	if (strlen (prompt_line - strlen (MSG_pme)) >= 64)
X	/* VERY rude, but setenv not found */
X	{
X		if (putenv (MSG_pmpt) == -1)
X			exit (1);
X	}
X	else
X		if (putenv (prompt_line) == -1)
X			exit (1);
X
X#endif
X	if (!cspec && !(cspec = getenv (MSG_shell)))/* jam */
X		cspec = MSG_def_shell;
X	spawnl (P_WAIT, cspec, MSG_null, NULL);
X	putenv (MSG_pme);
X	if (putenv (old_prompt) == -1)
X		exit (1);
X	ttraw ();
X	sgarbf = TRUE;
X#endif
X	return (TRUE);
X}
X
END_OF_FILE
if test 1388 -ne `wc -c <'spawn.c'`; then
    echo shar: \"'spawn.c'\" unpacked with wrong size!
fi
# end of 'spawn.c'
fi
if test -f 'tcap.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tcap.c'\"
else
echo shar: Extracting \"'tcap.c'\" \(2567 characters\)
sed "s/^X//" >'tcap.c' <<'END_OF_FILE'
X/*	tcap:	Unix V5, V7 and BS4.2 Termcap video driver
X		for beav
X*/
X
X#include "def.h"
X
X#ifdef UNIX
X
X#define	MARGIN	8
X#define	SCRSIZ	64
X#define	NPAUSE	10			/* # times thru update to pause */
X#define BEL     0x07
X#define ESC     0x1B
X
Xextern char     *tgoto();
X
X#ifdef NOPROTO
Xextern int      ttputc();
X#endif
X
X#if	COLOR
Xextern int		tcapfcol();
Xextern int		tcapbcol();
X#endif
X
X#define TCAPSLEN 315
Xchar tcapbuf[TCAPSLEN];
Xchar *UP, PC, *CM, *CE, *CL, *SO, *SE;
X
X#ifdef BSD
X#include <sys/ioctl.h>
Xstruct ttysize ttysize;
X#endif /* BSD */
X
Xtcapopen()
X{
X	char *getenv();
X	char *t, *p, *tgetstr();
X	char tcbuf[1024];
X	char *tv_stype;
X	char err_str[72];
X
X	if ((tv_stype = getenv("TERM")) == NULL)
X	{
X		puts("Environment variable TERM not defined!\r");
X		ttclose();
X		exit(1);
X	}
X
X	if ((tgetent(tcbuf, tv_stype)) != 1)
X	{
X		sprintf(err_str, "Unknown terminal type %s!\r", tv_stype);
X		puts(err_str);
X		ttclose();	/* fix in 1.13 */
X		exit(1);
X	}
X
X
X#ifdef BSD
X	if (ioctl(0, TIOCGSIZE, &ttysize) == 0
X	    && ttysize.ts_lines > 0) {
X		nrow = ttysize.ts_lines;
X	} else
X#endif /* BSD */
X		if ((nrow=(short)tgetnum("li")-1) == -1){
X			puts("termcap entry incomplete (lines)\r");
X			ttclose();	/* fix in 1.13 */
X			exit(1);
X		}
X	printf ("nrow %d, ncol %d\n", nrow, ncol);
X	/* don't allow to specify a larger number of rows than we can handle 1.13 */
X	if (nrow > NROW)
X		nrow = NROW;
X
X	if ((ncol=(short)tgetnum("co")) == -1){
X		puts("Termcap entry incomplete (columns)\r");
X		ttclose();	/* fix in 1.13 */
X		exit(1);
X	}
X	/* don't allow to specify a larger number of cols than we can handle 1.13 */
X	if (ncol > NCOL)
X		ncol = NCOL;
X
X	p = tcapbuf;
X	t = tgetstr("pc", &p);
X	if(t)
X		PC = *t;
X
X	CL = tgetstr("cl", &p);
X	CM = tgetstr("cm", &p);
X	CE = tgetstr("ce", &p);
X	UP = tgetstr("up", &p);
X	SE = tgetstr("se", &p);
X	SO = tgetstr("so", &p);
X
X	if(CL == NULL || CM == NULL || UP == NULL)
X	{
X		puts("Incomplete termcap entry\r");
X		ttclose();	/* fix in 1.13 */
X		exit(1);
X	}
X
X	if (p >= &tcapbuf[TCAPSLEN])
X	{
X		puts("Terminal description too big!\r");
X		ttclose();	/* fix in 1.13 */
X		exit(1);
X	}
X}
X
Xtcapmove(row, col)
Xregister int row, col;
X{
X	putpad(tgoto(CM, col, row));
X}
X
Xtcapeeol()
X{
X	putpad(CE);
X}
X
Xtcapeeop()
X{
X	putpad(CL);
X}
X
Xtcaprev(state)		/* change reverse video status */
Xint state;		/* FALSE = normal video, TRUE = reverse video */
X
X{
X	static int revstate = FALSE;
X	if (state) {
X		if (SO != NULL)
X			putpad(SO);
X	} else
X		if (SE != NULL)
X			putpad(SE);
X}
X
Xputpad(str)
Xchar    *str;
X{
X	tputs(str, 1, ttputc);
X}
X
Xputnpad(str, n)
Xchar    *str;
X{
X	tputs(str, n, ttputc);
X}
X
X#endif
END_OF_FILE
if test 2567 -ne `wc -c <'tcap.c'`; then
    echo shar: \"'tcap.c'\" unpacked with wrong size!
fi
# end of 'tcap.c'
fi
if test -f 'termio.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'termio.c'\"
else
echo shar: Extracting \"'termio.c'\" \(4593 characters\)
sed "s/^X//" >'termio.c' <<'END_OF_FILE'
X/*
X * The functions in this file negotiate with the operating system for
X * characters, and write characters in a barely buffered fashion on the display.
X * All operating systems.
X */
X
X#include	<sys/types.h>    /* 1.13 */
X
X#ifdef UNIX    /* System V */
X
X#include    <stdio.h>
X#include    <signal.h>
X#if BSD
X#include    <sys/ioctl.h>
X#else
X#include    <termio.h>
X#endif /* BSD */
X#include    <errno.h>
X#include    <fcntl.h>
X#include    "def.h"
Xint kbdflgs;            /* saved keyboard fd flags  */
Xint kbdpoll;            /* in O_NDELAY mode         */
Xint kbdqp;          /* there is a char in kbdq  */
Xchar kbdq;          /* char we've already read  */
X
X#ifdef BSD
Xstruct	sgttyb	otermb;
Xstruct	sgttyb	ntermb;
X#else
Xstruct  termio  otermio;    /* original terminal characteristics */
Xstruct  termio  ntermio;    /* charactoristics to use inside */
X#endif /* BSD */
Xextern	errno;		/* System error number -- Necessary when compiling in BSD 1.13 */
X
Xint     nrow;                   /* Terminal size, rows.         */
Xint     ncol;                   /* Terminal size, columns.      */
X
X/*
X * This function is called once to set up the terminal device streams.
X * On VMS, it translates TT until it finds the terminal, then assigns
X * a channel to it and sets it raw. On CPM it is a no-op.
X */
X
Xvoid ttopen()
X{
X#ifdef BSD
X	struct ttysize ttysize;
X
X	ioctl(0, TIOCGETP, &otermb);	/* save settings	*/
X	ntermb = otermb;			/* setup new settings	*/
X	ntermb.sg_flags &= ~ECHO;
X	ntermb.sg_flags |= RAW;
X	ioctl(0, TIOCSETP, &ntermb); 	/* and activate them	*/
X	kbdpoll = FALSE;
X
X	/* on all screens we are not sure of the initial position
X       of the cursor                    */
X	ttrow = 999;
X	ttcol = 999;
X	if (ioctl(0, TIOCGSIZE, &ttysize) == 0) {
X		nrow = ttysize.ts_lines;
X		ncol = ttysize.ts_cols;
X	} else {
X		nrow = NROW;
X		ncol = NCOL;
X	}
X#else
X	ioctl(0, TCGETA, &otermio); /* save old settings */
X	ntermio.c_iflag = 0;        /* setup new settings */
X	ntermio.c_oflag = 0;
X	ntermio.c_cflag = otermio.c_cflag;
X	ntermio.c_lflag = 0;
X	ntermio.c_line = otermio.c_line;
X	ntermio.c_cc[VMIN] = 1;
X	ntermio.c_cc[VTIME] = 0;
X	ioctl(0, TCSETAW, &ntermio); /* and activate them */
X	kbdflgs = fcntl( 0, F_GETFL, 0 );
X	kbdpoll = FALSE;
X	/* on all screens we are not sure of the initial position
X       of the cursor                    */
X	ttrow = 999;
X	ttcol = 999;
X	nrow = NROW;
X	ncol = NCOL;
X#endif 
X}
X
X/*
X * This function gets called just before we go back home to the command
X * interpreter. On VMS it puts the terminal back in a reasonable state.
X * Another no-operation on CPM.
X */
Xvoid  ttclose()
X{
X#ifdef BSD
X	if (ioctl(0, TIOCSETP, &otermb) == -1) /* restore terminal settings */
X		printf ("closing ioctl on dev 0 failure, error = %d\n", errno);
X#else
X	if (ioctl(0, TCSETAW, &otermio) == -1) /* restore terminal settings */
X		printf ("closing ioctl on dev 0 failure, error = %d\n", errno);
X	if (fcntl(0, F_SETFL, kbdflgs) == -1)
X		printf ("closing fcntl on dev 0 failure, error = %d\n", errno);
X#endif
X
X}
X
X/*
X * Write a character to the display. On VMS, terminal output is buffered, and
X * we just put the characters in the big array, after checking for overflow.
X * On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
X * MS-DOS (use the very very raw console output routine).
X */
Xvoid ttputc(c)
X{
X	fputc(c, stdout);
X}
X
X/*
X * Flush terminal buffer. Does real work where the terminal output is buffered
X * up. A no-operation on systems where byte at a time terminal I/O is done.
X */
Xvoid ttflush()
X{
X	fflush(stdout);
X}
X
X/*
X * Read a character from the terminal, performing no editing and doing no echo
X * at all. More complex in VMS that almost anyplace else, which figures. Very
X * simple on CPM, because the system can do exactly what you want.
X */
Xttgetc()
X{
X	if( kbdqp )
X		kbdqp = FALSE;
X	else
X	{
X#ifdef BSD
X		int count;
X
X		if (kbdpoll && (ioctl(0, FIONREAD, &count), count == 0))
X			return FALSE;
X		read(0, &kbdq, 1);
X#else
X		if( kbdpoll && fcntl( 0, F_SETFL, kbdflgs ) < 0 )
X			return FALSE;
X		kbdpoll = FALSE;
X		while (read(0, &kbdq, 1) != 1)
X			;
X#endif
X	}
X	return ( kbdq & 127 );
X}
X
X/* typahead():    Check to see if any characters are already in the
X        keyboard buffer
X*/
Xttkeyready ()
X{
X	if( !kbdqp )
X	{
X#ifdef BSD
X		int count;
X
X		if (!kbdpoll && (ioctl(0, FIONREAD, &count), count == 0))
X			return FALSE;
X		kbdpoll = TRUE;    /*  fix in 1.13 */
X		kbdqp = TRUE;
X#else
X		if( !kbdpoll && fcntl( 0, F_SETFL, kbdflgs | O_NDELAY ) < 0 )
X			return(FALSE);
X		kbdpoll = TRUE;    /*  fix in 1.13 */
X		kbdqp = (1 == read( 0, &kbdq, 1 ));
X#endif
X
X	}
X	return ( kbdqp );
X}
X#endif
END_OF_FILE
if test 4593 -ne `wc -c <'termio.c'`; then
    echo shar: \"'termio.c'\" unpacked with wrong size!
fi
# end of 'termio.c'
fi
if test -f 'tty.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tty.c'\"
else
echo shar: Extracting \"'tty.c'\" \(5931 characters\)
sed "s/^X//" >'tty.c' <<'END_OF_FILE'
X/*
X*    Wang PC terminal display        TTY.C
X*
X*/
X#include        "def.h"
X
Xvoid    ttinit ();
Xvoid    tttidy ();
Xvoid    ttmove ();
Xvoid    tteeol ();
Xvoid    tteeop ();
Xvoid    ttbeep ();
Xvoid    asciiparm ();
Xvoid    ttnowindow ();    /* stub */
Xvoid    ttcolor ();
Xextern void tcapopen ();
Xextern void tcapmove ();
X
X#if     GOSLING
Xvoid    ttinsl ();
Xvoid    ttdell ();
X#endif
X
X#ifdef MSDOS
X#include    "dos.h"
Xextern  bool    ibm_pc, mem_map;
X#endif
X#define BEL     0x07            /* BEL character.               */
X#define ESC     0x1B            /* ESC character.               */
X
Xextern int  ttrow;
Xextern int  ttcol;
Xextern int  tttop;
Xextern int  ttbot;
Xextern int  tthue;
X
Xint     tceeol = 3;             /* Costs.                       */
Xint     rowb = NROW;
X
X/*
X* Initialize the terminal when the editor
X* gets started up.
X*/
Xvoid    ttinit ()
X{
X#ifdef MSDOS
X	ttraw ();
X#endif
X#ifdef UNIX 
X	tcapopen();
X#endif
X}
X
X/*
X* Clean up the terminal, in anticipation of
X* a return to the command interpreter.
X*/
Xvoid    tttidy ()
X{
X#ifdef MSDOS
X	ttcooked ();
X#endif
X}
X
X/*
X* Move the cursor to the specified
X* origin 0 row and column position. Try to
X* optimize out extra moves; redisplay may
X* have left the cursor in the right
X* location last time!
X*/
Xvoid    ttmove (row, col)
X{
X#ifdef MSDOS
X	union   REGS    regs;
X
X	/* Move in both axes */
X	if (ibm_pc)
X	{
X		regs.h.ah = 2;
X		regs.h.dh = (char)row;
X		regs.h.dl = (char)col;
X		regs.h.bh = 0;
X		int86 (0x10, &regs, &regs); /* set cursor position */
X	}
X	else
X#endif
X#ifdef UNIX
X		tcapmove(row, col);
X#endif
X#if ANSI
X	{
X		ttputc (ESC);
X		ttputc ('[');
X		asciiparm (row + 1);
X		ttputc (';');
X		asciiparm (col + 1);
X		ttputc ('H');
X	}
X#endif
X	ttrow = row;
X	ttcol = col;
X}
X
X/*
X* Erase to end of line.
X*/
Xvoid    tteeol ()
X{
X	char    col, row, i;
X#ifdef MSDOS
X	union   REGS    regs;
X
X	if (ibm_pc)
X	{
X		regs.h.ah = 3;
X		regs.h.bh = 0;
X		int86 (0x10, &regs, &regs); /* get cursor position */
X		col = regs.h.dl;
X		row = regs.h.dh;
X		for (i = col ; i < (NCOL - 1); i++)
X		{
X			regs.h.ah = 0x0e;
X			regs.h.bl = 0;
X			regs.h.bh = 0;
X			regs.h.al = ' ';
X			int86 (0x10, &regs, &regs); /* set cursor position */
X		}
X		/* put cursor back to original position */
X		regs.h.ah = 2;
X		regs.h.bh = 0;
X		regs.h.dl = col;
X		regs.h.dh = row;
X		int86 (0x10, &regs, &regs); /* get cursor position */
X	}
X	else
X#endif
X#if ANSI
X		{
X			ttputc (ESC);
X			ttputc ('[');
X#ifdef MSDOS
X			if (ibm_pc)
X				ttputc ('0');    /* this is necessary in IBM PC's */
X#endif
X			ttputc ('K');
X		}
X#endif
X#ifdef UNIX
X	tcapeeol();
X#endif
X}
X
X/*
X* Erase to end of page.
X* only ever used when cursor is at 0,0, so IBM screen erase
X* is same as eop
X*/
Xvoid    tteeop ()
X{
X#ifdef MSDOS
X	union   REGS    regs;
X	char    i, j;
X
X	if (ibm_pc)
X	{
X		for (j = 0 ; j < nrow; j++)
X		{
X			for (i = 0 ; i < NCOL; i++)
X			{
X				regs.h.ah = 0x0e;
X				regs.h.bl = 0;
X				regs.h.bh = 0;
X				regs.h.al = ' ';
X				int86 (0x10, &regs, &regs); /* set cursor position */
X			}
X		}
X	}
X	else
X#endif
X#if	ANSI
X		{
X			ttcolor (CTEXT);
X			ttputc (ESC);
X			ttputc ('[');
X#ifdef MSDOS
X			if (ibm_pc)
X				ttputc ('0');
X			else
X#endif
X				ttputc ('2');
X			ttputc ('J');
X		}
X#endif
X#ifdef UNIX
X	tcapeeop();
X#endif
X}
X
X/*
X* Make a noise.
X*/
Xvoid    ttbeep ()
X{
X	ttputc (BEL);
X	ttflush ();
X}
X
X/*
X* Convert a number to decimal
X* ascii, and write it out. Used to
X* deal with numeric arguments.
X*/
Xvoid    asciiparm (n)
Xregister int    n;
X{
X	register int    q;
X
X	q = n / 10;
X	if (q != 0)
X		asciiparm (q);
X	ttputc ((n % 10) + '0');
X}
X
X#if     GOSLING
X/*
X* Insert a block of blank lines onto the
X* screen, using a scrolling region that starts at row
X* "row" and extends down to row "bot".  Deal with the one
X* line case, which is a little bit special, with special
X* case code.
X*/
Xvoid    ttinsl (row, bot, nchunk)
X{
X	if (row == bot)
X	{
X		/* Funny case.          */
X		if (nchunk != 1)
X			abort ();
X		ttmove (row, 0);
X		tteeol ();
X	}
X	else
X	{
X		/* General case.        */
X		ttputc (ESC);
X		ttputc ('/');
X		asciiparm (row + 1);
X		ttputc (';');
X		asciiparm (bot + 1);
X		ttputc (';');
X		asciiparm (nchunk);
X		ttputc (';');
X		ttputc ('0');
X		ttputc ('S');
X	}
X}
X
X/*
X* Delete a block of lines, with the uppermost
X* line at row "row", in a screen slice that extends to
X* row "bot". The "nchunk" is the number of lines that have
X* to be deleted.  Watch for the pathalogical 1 line case,
X* where the scroll region is *not* the way to do it.
X* The block delete is used by the slightly more
X* optimal display code.
X*/
Xvoid    ttdell (row, bot, nchunk)
X{
X	if (row == bot)
X	{
X		/* Funny case.          */
X		if (nchunk != 1)
X			abort ();
X		ttmove (row, 0);
X		tteeol ();
X	}
X	else
X	{
X		/* General case.        */
X		ttputc (ESC);
X		ttputc ('/');
X		asciiparm (row + 1);
X		ttputc (';');
X		asciiparm (bot + 1);
X		ttputc (';');
X		asciiparm (nchunk);
X		ttputc (';');
X		ttputc ('1');
X		ttputc ('S');
X	}
X}
X#endif
X
X/*
X* Switch to full screen scroll. This is
X* used by "spawn.c" just before is suspends the
X* editor, and by "display.c" when it is getting ready
X* to exit.  This is a no-op.
X*/
Xvoid    ttnowindow (){
X}
X
X/*
X* Set the current writing color to the
X* specified color. Watch for color changes that are
X* not going to do anything (the color is already right)
X* and don't send anything to the display.
X*/
Xvoid    ttcolor (color)
Xregister int    color;
X{
X#ifdef MSDOS
X	if (mem_map)
X	{
X		tthue = color;          /* Save the color.      */
X		return;
X	}
X#endif
X#ifdef UNIX
X	if (color == CTEXT)
X		tcaprev (FALSE);
X	else	
X		tcaprev (TRUE);
X	tthue = color;          /* Save the color.      */
X#endif
X#if ANSI
X	if (color != tthue)
X	{
X		if (color == CTEXT)
X		{                   /* Normal video.        */
X			ttputc (ESC);
X			ttputc ('[');
X			ttputc ('0');
X			ttputc ('m');
X		}
X		else
X			if (color == CMODE)
X			{               /* Reverse video.       */
X				ttputc (ESC);
X				ttputc ('[');
X				ttputc ('7');
X				ttputc ('m');
X			}
X		tthue = color;          /* Save the color.      */
X	}
X#endif
X}
END_OF_FILE
if test 5931 -ne `wc -c <'tty.c'`; then
    echo shar: \"'tty.c'\" unpacked with wrong size!
fi
# end of 'tty.c'
fi
if test -f 'ttyio.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ttyio.c'\"
else
echo shar: Extracting \"'ttyio.c'\" \(3055 characters\)
sed "s/^X//" >'ttyio.c' <<'END_OF_FILE'
X/*
X*
X*   MS-DOS terminal I/O.               TTYIO.C
X*/
X
X#include        "def.h"
X#ifdef	MSDOS
X
X
Xvoid    ttopen ();
Xvoid    ttclose (); /* stub */
Xvoid    ttputc ();
Xvoid    putline ();
Xvoid    ttflush (); /* stub */
Xint     ttkeyready ();
Xint     ttgetc ();
Xvoid    ttraw ();
Xvoid    ttcooked ();
Xvoid    set_crt_type ();
X
X#include    "dos.h"
X
Xint     slot;
Xint     scr_type;
X#define SCREEN_PORT (video_port)
Xstatic int  video_port =
X{
X	0x1010
X};
X
Xextern  bool    wang_pc;
Xextern  bool    ibm_pc;
Xint     nrow;                   /* Terminal size, rows.         */
Xint     ncol;                   /* Terminal size, columns.      */
Xint     last_key;
X
X/*
X* Initialization.
X* Almost no operation in MS-DOS.
X*/
Xvoid ttopen ()
X{
X	if (wang_pc && !ibm_pc)
X		set_crt_type ();
X	nrow = NROW;
X	ncol = NCOL;
X}
X
Xvoid ttclose ()
X{
X}
Xvoid ttflush ()
X{
X}
X/*
X* Write character.
X*/
Xvoid ttputc (c)
X{
X	bdos (6, c, 0);
X}
X
Xvoid putline (row, startcol, stringsize, string)
Xint     row,
Xstartcol,
Xstringsize;
Xchar   *string;
X{
X	extern int  tthue;
X	unsigned short *screen;
X	int     x,
X	attribute;
X	char    c_row, c_col, i;
X	union   REGS    regs;
X
X	if (ibm_pc)
X	{
X		c_row = row - 1;
X		c_col = startcol - 1;
X		for (i = 0; i < stringsize; i++)
X		{
X			regs.h.ah = 2;
X			regs.h.dh = c_row;
X			regs.h.dl= c_col;
X			regs.h.bh = 0;
X			int86 (0x10, &regs, &regs); /* set cursor position */
X
X			if (tthue == CTEXT)
X				regs.h.bl = 0x07;
X			if (tthue == CMODE)
X				regs.h.bl = 0x70;
X			regs.h.ah = 9;
X			regs.h.bh = 0;
X			regs.h.al = string[i];
X			regs.x.cx= 1;
X			int86 (0x10, &regs, &regs); /* set cursor position */
X			c_col++;
X		}
X	}
X	else if (wang_pc)
X	{
X		if (tthue == CTEXT)
X			attribute = 0x00;
X		else
X			attribute = 0x02;
X
X		x = stringsize;
X		screen = (unsigned short *) WANG_CHARACTER_SCREEN;
X		screen += ((row - 1) * 80) + startcol - 1;
X		outp (SCREEN_PORT, 01);
X		while (x--)
X		{
X			*screen = (*string++ << 8) | attribute;
X			screen++;
X		}
X		outp (SCREEN_PORT, 00);
X	}
X}
X
X/* 
X*   return with a TRUE if key was struck.
X*/
Xint     ttkeyready ()
X{
X	int	cnt;
X
X	if (last_key != 0)
X		return (1);
X
X	last_key = bdos (6, 0xff, 0);
X	last_key &= 0xff;
X	if (last_key == 0)
X		return (0);
X	else
X		return (1);
X}
X
X/*
X* Read character.
X*/
Xint     ttgetc ()
X{
X	int     c;
X	if (last_key != 0)
X	{
X		c = last_key;
X		last_key = 0;
X		return (c);
X	}
X	ttcooked ();
X	c = (bdos (7, 0, 0) & 0xFF);
X	ttraw ();
X	return (c);
X}
X
X/* disable nasty cntrl-c during disk io!
X*/
Xvoid ttraw ()
X{
X	union REGS inregs, outregs;
X
X	inregs.h.al = 1;
X	inregs.h.ah = 0x33;
X	inregs.h.dl = 0;
X	intdos (&inregs, &outregs);
X	/*
X    cntrlcoff();
X*/
X}
X
X/* re enable cntrl-c for keyboard 
X*/
Xvoid ttcooked ()
X{
X	union REGS inregs, outregs;
X
X	inregs.h.al = 1;
X	inregs.h.ah = 0x33;
X	intdos (&inregs, &outregs);
X	inregs.h.dl = 1;
X	/*
X    cntrlcon();
X*/
X}
X
X/* switch physical monitors
X*/
Xstatic char str[] =
X{
X	0x1b, '/', 1, 's'
X};
X
Xvoid     set_crt_type ()
X{
X	char    active_screen;
X
X	active_screen = getscreenstate ();
X	slot = active_screen & 0x0f;
X	scr_type = (active_screen & 0x70) >> 4;
X	video_port = 0x1010 | (slot << 8);
X}
X#endif
END_OF_FILE
if test 3055 -ne `wc -c <'ttyio.c'`; then
    echo shar: \"'ttyio.c'\" unpacked with wrong size!
fi
# end of 'ttyio.c'
fi
if test -f 'wangpc.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'wangpc.c'\"
else
echo shar: Extracting \"'wangpc.c'\" \(3064 characters\)
sed "s/^X//" >'wangpc.c' <<'END_OF_FILE'
X#define LINT_ARGS   1           /* enable lint type checking */
X#include "def.h"
X#if MSDOS
X#include "dos.h"
X
Xtypedef struct SCREENINFO
X{
X	unsigned char   state;
X	unsigned char   scanoff;
X	unsigned short  bufseg;
X	unsigned char   colors;
X	unsigned char   row;
X	unsigned char   col;
X	unsigned char   attr;
X	unsigned char   auxmod;
X	unsigned char   auxmod2;
X} SCREENINFO;
X
Xtypedef struct SYSCONFIG
X{
X	unsigned short  version;
X	unsigned short  memsize;
X	unsigned short  reserved[2];
X	unsigned short  screen_count;
X	unsigned short  screens[4];
X} SYSCONFIG;
X
X#define SENDCHAR 6
X#define SENDLINE 0x0d
X#define BIOS 0x88
X#define GETSYSCON 1
X
Xbool    wang_pc = FALSE;
Xbool    ibm_pc = FALSE;
Xbool    mem_map = FALSE;
X
Xvoid    is_wang ()
X{
X	union REGS inregs, outregs;
X	struct SREGS    segregs;
X	unsigned char *memptr;
X	unsigned char    c;
X	int     i;
X	static  char wang_id[] = {
X		"WANG"					};
X	static  char ret_str[6];
X	char    *chr_ptr;
X
X	chr_ptr = ret_str;
X	/* test for Wang PC */
X	memptr = (unsigned char *)0xFC003FC2L;
X	wang_pc = TRUE;
X	for (i=0;(i<4 && wang_pc);i++)
X	{
X		if(*memptr != wang_id[i])
X			wang_pc = FALSE;
X		memptr++;
X	}
X
X	if (wang_pc)
X	{
X		mem_map = TRUE;
X		ret_str[0] = 0xFF;      /* set to known value */
X		mem_map = TRUE;
X		inregs.h.al = 0x02;
X		inregs.h.ah = 0x44;
X		inregs.x.bx = 0;
X		inregs.x.cx = 1;
X		inregs.x.dx = FP_OFF (chr_ptr);
X		segregs.ds = FP_SEG (chr_ptr);
X
X		int86x (0x21, &inregs, &outregs, &segregs);
X		if (ret_str[0] == 0x11)
X		{
X			ibm_pc = TRUE;
X			return;
X		}
X		ibm_pc = FALSE;
X		return;
X	}
X
X	/* Must be an IBM or clone */
X	memptr = (unsigned char *)0xF000FFFEL;
X	c = *memptr;
X	switch(c)
X	{
X	case 0xFC:  /* IBM AT or clone */
X	case 0xFD:  /* IBM PC Jr */
X	case 0xFE:  /* IBM XT or clone */
X	case 0xFF:  /* IBM PC or clone */
X		mem_map = TRUE;
X		ibm_pc = TRUE;
X		return;
X	}
X}
X
Xint     getsysconfig (outregs, segregs)
Xunion REGS * outregs;
Xstruct SREGS   *segregs;
X{
X	union REGS inregs;
X
X	inregs.h.al = GETSYSCON;
X
X	int86x (BIOS, &inregs, outregs, segregs);
X}
X
Xchar    getscreenstate ()
X{
X	struct SREGS    segregs;
X	union REGS outregs;
X
X	struct SYSCONFIG   *config;
X	struct SCREENINFO  *screeninfo;
X	unsigned short *shortptr;
X	unsigned int    screen_count;
X
X	getsysconfig (&outregs, &segregs);
X
X	/* set pointer to force register info into a long pointer. */
X	shortptr = (unsigned short *) & config;
X
X	/* Offset is first, it comes back in BX */
X	*shortptr = (unsigned short) outregs.x.bx;
X	shortptr++;
X
X	/* segment is in ES */
X	*shortptr = (unsigned short) segregs.es;
X
X	/* Now, the config pointer should be set to the config table. */
X	/*  printf("Version = %04x \n",config->version);
X    printf("Memsize = %04x \n",config->memsize);
X    printf("Screens = %04x \n",config->screen_count);
X*/
X	screen_count = config -> screen_count;
X	while (screen_count)
X	{
X		shortptr = (unsigned short *) & screeninfo;
X		*shortptr = (unsigned short) config -> screens[screen_count - 1];
X		shortptr++;
X		*shortptr = (unsigned short) segregs.es;
X		if (screeninfo -> state & 0x80)
X			break;
X		screen_count--;
X	}
X	return (screeninfo -> state);
X}
X#endif
END_OF_FILE
if test 3064 -ne `wc -c <'wangpc.c'`; then
    echo shar: \"'wangpc.c'\" unpacked with wrong size!
fi
# end of 'wangpc.c'
fi
if test -f 'word.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'word.c'\"
else
echo shar: Extracting \"'word.c'\" \(2825 characters\)
sed "s/^X//" >'word.c' <<'END_OF_FILE'
X/*
X*       Word mode commands.
X* The routines in this file
X* implement commands that work unit at
X* a time. There are all sorts of unit mode
X* commands. If I do any sentence and/or paragraph
X* mode commands, they are likely to be put in
X* this file.
X*/
X#define LINT_ARGS   1           /* enable lint type checking */
X#include    "def.h"
X
Xextern  BUFFER	sav_buf;
Xchar    forwunit ();
X
X/*
X* Move the cursor backward by
X* "n" units. All of the details of motion
X* are performed by the "backchar" and "forwchar"
X* routines. Error if you try to move beyond
X* the buffers.
X*/
Xchar    backunit (f, n, k)
X{
X	char    ret;
X
X	if (n < 0)
X		return (forwunit (f, -n, KRANDOM));
X
X	curwp -> w_unit_offset = 0;
X	while (n--)
X	{
X		ret = move_ptr (curwp, -(long)R_B_PER_U(curwp), TRUE, TRUE, TRUE);
X	}
X	wind_on_dot (curwp);
X	curwp -> w_flag |= WFMODE;  /* update mode line */
X	return (ret);
X}
X
X
X/*
X* Move the cursor forward by
X* the specified number of units. All of the
X* motion is done by "forwchar". Error if you
X* try and move beyond the buffer's end.
X*/
Xchar    forwunit (f, n, k)
X{
X
X	if      (n < 0)
X		return (backunit (f, -n, KRANDOM));
X
X	curwp -> w_unit_offset = 0;
X	while (n--)
X	{
X		move_ptr (curwp, (long)R_B_PER_U(curwp), TRUE, TRUE, TRUE);
X	}
X	wind_on_dot (curwp);
X	curwp -> w_flag |= WFMODE;  /* update mode line */
X	return (TRUE);
X}
X
X
X/*
X* Kill forward by "n" units. The rules for final
X* status are now different. It is not considered an error
X* to delete fewer units than you asked. This lets you say
X* "kill lots of units" and have the command stop in a reasonable
X* way when it hits the end of the buffer.
X*/
Xbool delfunit (f, n, k)
X{
X	register    LINE * dotp;
X	register int    doto;
X
X	if (n < 0)
X		return (FALSE);
X	if ((lastflag & CFKILL) == 0)/* Purge kill buffer.   */
X		bclear (&sav_buf);
X	thisflag |= CFKILL;
X	while (n--)
X	{
X		ldelete ((A32)(R_B_PER_U(curwp)), TRUE);
X	}
X	curwp -> w_flag |= WFHARD;
X	curwp -> w_unit_offset = 0;
X	return (TRUE);
X}
X
X
X/*
X* Kill backwards by "n" units. The rules
X* for success and failure are now different, to prevent
X* strange behavior at the start of the buffer. The command
X* only fails if something goes wrong with the actual delete
X* of the characters. It is successful even if no characters
X* are deleted, or if you say delete 5 units, and there are
X* only 4 units left. I considered making the first call
X* to "backchar" special, but decided that that would just
X* be wierd. Normally this is bound to "M-Rubout" and
X* to "M-Backspace".
X*/
Xbool delbunit (f, n, k)
X{
X	int size;
X
X	if (n < 0)
X		return (FALSE);
X	if ((lastflag & CFKILL) == 0)/* Purge kill buffer.   */
X		bclear (&sav_buf);
X	thisflag |= CFKILL;
X	size = R_B_PER_U(curwp);
X	while (n--)
X	{
X		if (move_ptr (curwp, -((long)size), TRUE, TRUE, TRUE))
X			ldelete ((A32)size, TRUE);
X	}
X	curwp -> w_flag |= WFHARD;
X	return (TRUE);
X}
X
END_OF_FILE
if test 2825 -ne `wc -c <'word.c'`; then
    echo shar: \"'word.c'\" unpacked with wrong size!
fi
# end of 'word.c'
fi
echo shar: End of archive 1 \(of 9\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 9 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0


-- 
>>>>>>>>>>>>>>>> Peter Reilley ..... pvr@wang.com <<<<<<<<<<<<<<<<<<<<<<<
                     Well, that about says it.

exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.
