Newsgroups: comp.sources.misc
From: Peter Reilley <pvr@wang.com>
Subject:  v22i011:  beav - Binary file editor and viewer, Part02/09
Message-ID: <1991Aug14.200638.5591@sparky.IMD.Sterling.COM>
X-Md4-Signature: 6c18f4f5f94beffa1da5f8f590062246
Date: Wed, 14 Aug 1991 20:06:38 GMT
Approved: kent@sparky.imd.sterling.com

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

#! /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 2 (of 9)."
# Contents:  echo.c extend.c format.c lintfunc.dec window.c
# Wrapped by pvr@elf on Mon Aug 12 13:51:30 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'echo.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'echo.c'\"
else
echo shar: Extracting \"'echo.c'\" \(7150 characters\)
sed "s/^X//" >'echo.c' <<'END_OF_FILE'
X/*
X*       Echo line reading and writing.
X* Common routines for reading
X* and writing characters in the echo line area
X* of the display screen. Used by the entire
X* known universe.
X*/
X#include    "def.h"
X
Xvoid    eerase ();
Xchar    ereply ();
Xchar    eread ();
Xvoid    eformat ();
Xvoid    eputi ();
Xvoid    eputs ();
Xvoid    eputc ();
X
X
Xextern    char    MSG_null[];
Xextern    char    MSG_y_n[];
Xextern    char    MSG_hex_dig[];
Xextern    char    MSG_hit_key[];
X
Xint     epresf = FALSE;         /* Stuff in echo line flag. */
X
X/*
X* Erase the echo line.
X*/
Xvoid eerase ()
X{
X	writ_echo (MSG_null);  /* clear the echo line */
X	epresf = FALSE;
X}
X
X
X/*
X* Ask "yes" or "no" question.
X* Return ABORT if the user answers the question
X* with the abort ("^G") character. Return FALSE
X* for "no" and TRUE for "yes". No formatting
X* services are available.
X*/
Xchar    eyesno (sp)
Xchar   *sp;
X{
X
X	register char   s;
X	char    buf[64];
X
X	for (;;)
X	{
X
X		s = ereply (MSG_y_n, buf, sizeof (buf), sp);
X		if (s == ABORT)
X			return (ABORT);
X		if (s != FALSE)
X		{
X
X			if (buf[0] == 'y' || buf[0] == 'Y')
X				return (TRUE);
X			if (buf[0] == 'n' || buf[0] == 'N')
X				return (FALSE);
X		}
X
X	}
X
X}
X
X
X/*
X* Write out a prompt, and read back a
X* reply. The prompt is now written out with full "eprintf"
X* formatting, although the arguments are in a rather strange
X* place. This is always a new message, there is no auto
X* completion, and the return is echoed as such.
X*/
X/* VARARGS3 */
Xchar    ereply (fp, buf, nbuf, arg)
Xchar   *fp;
Xchar   *buf;
Xint     nbuf;
Xchar   *arg;
X{
X	return (eread (fp, buf, nbuf, EFNEW | EFCR, arg));
X}
X
X
X/*
X* This is the general "read input from the
X* echo line" routine. The basic idea is that the prompt
X* string "prompt" is written to the echo line, and a one
X* line reply is read back into the supplied "buf" (with
X* maximum length "len"). The "flag" contains EFNEW (a
X* new prompt), an EFAUTO (autocomplete), or EFCR (echo
X* the carriage return as CR).
X*/
Xchar    eread (fp, buf, nbuf, flag, ap)
Xchar   *fp;
Xchar   *buf;
Xchar   *ap;
X{
X
X	register int    cpos;
X	register    SYMBOL * sp1;
X	register    SYMBOL * sp2;
X	register int    i;
X	register int    c;
X	register int    h;
X	register int    nhits;
X	register int    nxtra;
X	register int    bxtra;
X
X	int     quote_flag;
X
X	quote_flag = 0;
X	cpos = 0;
X	if (kbdmop != NULL)
X	{
X		/* In a macro.      */
X		while ((c = *kbdmop++) != '\0')
X			buf[cpos++] = c;
X		buf[cpos] = '\0';
X		goto done;
X	}
X
X	if ((flag & EFNEW) != 0 || ttrow != nrow - 1)
X	{
X
X		ttcolor (CTEXT);
X		ttmove (nrow - 1, 0);
X		epresf = TRUE;
X	}
X	else
X		eputc (' ');
X	eformat (fp, ap);
X	tteeol ();
X	ttflush ();
X	for (;;)
X	{
X		c = getkey ();
X		if (c == ' ' && (flag & EFAUTO) != 0)
X		{
X			nhits = 0;
X			nxtra = HUGE;
X			for (h = 0; h < NSHASH; ++h)
X			{
X				sp1 = symbol[h];
X				while (sp1 != NULL)
X				{
X					for (i = 0; i < cpos; ++i)
X					{
X						if (buf[i] != sp1 -> s_name[i])
X							break;
X					}
X
X					if (i == cpos)
X					{
X						if (nhits == 0)
X							sp2 = sp1;
X						++nhits;
X						bxtra = getxtra (sp1, sp2, cpos);
X						if (bxtra < nxtra)
X							nxtra = bxtra;
X					}
X
X					sp1 = sp1 -> s_symp;
X				}
X			}
X
X			if (nhits == 0)     /* No completion.   */
X				continue;
X			for (i = 0; i < nxtra && cpos < nbuf - 1; ++i)
X			{
X				c = sp2 -> s_name[cpos];
X				buf[cpos++] = c;
X				eputc (c);
X			}
X
X			ttflush ();
X			if (nhits != 1)     /* Fake a CR if there   */
X				continue;       /* is 1 choice.     */
X			c = (KCTRL | 'M');
X		}
X		if (quote_flag)
X		{
X			c = c & 0x1f;
X			quote_flag = 0;
X		}
X
X
X		switch (c)
X		{
X		case (KCTRL | 'Q'):
X			quote_flag = 1;
X			break;
X		case (KCTRL | 'M'): /* Return, done.    */
X			buf[cpos] = '\0';
X			if (kbdmip != NULL)
X			{
X				if (kbdmip + cpos + 1 > &kbdm[NKBDM - 3])
X				{
X					(void) ctrlg (FALSE, 0, KRANDOM);
X					ttflush ();
X					return (ABORT);
X				}
X
X				for (i = 0; i < cpos; ++i)
X					*kbdmip++ = buf[i];
X				*kbdmip++ = '\0';
X			}
X
X			if ((flag & EFCR) != 0)
X			{
X				ttputc (0x0D);
X				ttflush ();
X			}
X
X			goto done;
X
X		case (KCTRL | 'G'): /* Bell, abort.     */
X			eputc (0x07);
X			(void) ctrlg (FALSE, 0, KRANDOM);
X			ttflush ();
X			return (ABORT);
X
X		case 0x7F:          /* Rubout, erase.   */
X		case (KCTRL | 'H'): /* Backspace, erase.    */
X			if (cpos != 0)
X			{
X				ttputc ('\b');
X				ttputc (' ');
X				ttputc ('\b');
X				--ttcol;
X				if (ISCTRL (buf[--cpos]) != FALSE)
X				{
X					ttputc ('\b');
X					ttputc (' ');
X					ttputc ('\b');
X					--ttcol;
X				}
X
X				ttflush ();
X			}
X			break;
X
X		case (KCTRL | 'U'): /* C-U, kill line.  */
X			while (cpos != 0)
X			{
X				ttputc ('\b');
X				ttputc (' ');
X				ttputc ('\b');
X				--ttcol;
X				if (ISCTRL (buf[--cpos]) != FALSE)
X				{
X					ttputc ('\b');
X					ttputc (' ');
X					ttputc ('\b');
X					--ttcol;
X				}
X
X			}
X
X			ttflush ();
X			break;
X
X		default:            /* All the rest.    */
X			if ((cpos < nbuf - 1) && ((c & ~KCHAR) == 0))
X			{
X				buf[cpos++] = c;
X				eputc (c);
X				ttflush ();
X			}
X		}                   /* End switch */
X
X	}
X
Xdone:
X	if (buf[0] == '\0')
X		return (FALSE);
X	return (TRUE);
X}
X
X
X/*
X* The "sp1" and "sp2" point to extended command
X* symbol table entries. The "cpos" is a horizontal position
X* in the name. Return the longest block of characters that can
X* be autocompleted at this point. Sometimes the two symbols
X* are the same, but this is normal.
X*/
Xint     getxtra (sp1, sp2, cpos)
XSYMBOL * sp1;
XSYMBOL * sp2;
X{
X
X	register int    i;
X
X	i = cpos;
X	for (;;)
X	{
X
X		if (sp1 -> s_name[i] != sp2 -> s_name[i])
X			break;
X		if (sp1 -> s_name[i] == '\0')
X			break;
X		++i;
X	}
X
X	return (i - cpos);
X}
X
X/*
X* Printf style formatting. This is
X* called by both "eprintf" and "ereply", to provide
X* formatting services to their clients. The move to the
X* start of the echo line, and the erase to the end of
X* the echo line, is done by the caller.
X*/
Xvoid eformat (fp, ap)
Xchar  *fp;
Xchar  *ap;
X{
X
X	register int    c;
X
X	while ((c = *fp++) != '\0')
X	{
X
X		if (c != '%')
X			eputc (c);
X		else
X		{
X
X			c = *fp++;
X			switch (c)
X			{
X
X			case 'd':
X				eputi (*(int *) ap, 10);
X				ap += sizeof (int);
X				break;
X
X			case 'x':       /* krw */
X				eputi (*(int *) ap, 16);
X				ap += sizeof (int);
X				break;
X
X			case 'o':
X				eputi (*(int *) ap, 8);
X				ap += sizeof (int);
X				break;
X
X			case 's':
X				eputs (ap);
X				ap += sizeof (char *);
X				break;
X
X			default:
X				eputc (c);
X			}
X
X		}
X
X	}
X
X}
X
X
X/*
X* Put integer, in radix "r".
X*/
Xvoid eputi (i, r)
Xint    i;
Xint    r;
X{
X	static char *convert =
X	{
X		MSG_hex_dig
X	};
X
X
X	register int    q;
X
X	if ((q = i / r) != 0)
X		eputi (q, r);
X	eputc (convert[i % r]);
X
X}
X
X
X/*
X* Put string.
X*/
Xvoid eputs (s)
Xchar  *s;
X{
X	register int    c;
X
X	while ((c = *s++) != '\0')
X		eputc (c);
X}
X
X
X/*
X* Put character. Watch for
X* control characters, and for the line
X* getting too long.
X*/
Xvoid eputc (c)
Xint    c;
X{
X
X	if (ttcol < ncol)
X	{
X
X		if (ISCTRL (c) != FALSE)
X		{
X
X			eputc ('^');
X			c ^= 0x40;
X		}
X
X		ttputc (c);
X		++ttcol;
X	}
X
X}
X/*
X *   Print warning message and wait for the user to hit a key.
X */
Xvoid    err_echo (buf)
Xchar    *buf;
X{
X	char   ch[NCOL * 2];
X
X	strcpy (ch, buf);
X	strcat (ch, MSG_hit_key);
X	writ_echo (ch);
X	ttbeep ();
X	while (ttgetc () != CTL_G);
X	{
X		ttbeep ();
X		ttflush ();
X	}
X}
END_OF_FILE
if test 7150 -ne `wc -c <'echo.c'`; then
    echo shar: \"'echo.c'\" unpacked with wrong size!
fi
# end of 'echo.c'
fi
if test -f 'extend.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'extend.c'\"
else
echo shar: Extracting \"'extend.c'\" \(10920 characters\)
sed "s/^X//" >'extend.c' <<'END_OF_FILE'
X/*
X*   Extended (M-X) commands.
X*/
X#include    "def.h"
X
Xextern    char    MSG_not_now[];
Xextern    char    MSG_func[];
Xextern    char    MSG_unk_func[];
Xextern    char    MSG_cmd_t_ex[];
Xextern    char    MSG_unk_ext[];
Xextern    char    MSG_d_b[];
Xextern    char    MSG_unbd[];
Xextern    char    MSG_bnd_to[];
Xextern    char    MSG_ins_self[];
Xextern    char    MSG_bnd_file[];
Xextern    char    MSG_bld_wall[];
Xextern    char    MSG_wall_head[];
Xextern    char    MSG_beavrc[];
Xextern    char    MSG_null[];
X
X
X#ifdef CUSTOMIZE 
X
Xchar *flook();
X
Xstatic char *bindnm =
X{
X	0
X};                              /* file name for customized key bindings */
X#endif 
X
X/*
X* This function modifies the keyboard
X* binding table, by adjusting the entries in the
X* big "bindings" array. Most of the grief deals with the
X* prompting for additional arguments. This code does not
X* work right if there is a keyboard macro floating around.
X* Should be fixed.
X*/
Xbool bindtokey ()
X{
X
X	register int    s;
X	register char  *cp;
X	register    SYMBOL * sp;
X	register int    c;
X	char    xname[NXNAME];
X#ifdef CUSTOMIZE
X	char    xname2[NXNAME];
X	FILE * bindf;
X#endif 
X
X	if (kbdmip != NULL || kbdmop != NULL)
X	{
X		writ_echo (MSG_not_now);
X		return (FALSE);
X	}
X
X	if ((s = eread (MSG_func, xname, NXNAME, EFAUTO, NULL)) != TRUE)
X		return (s);
X	if ((sp = symlookup (xname)) == NULL)
X	{
X		writ_echo (MSG_unk_func);
X		return (FALSE);
X	}
X
X#ifdef CUSTOMIZE
X	strcpy (xname2, xname);
X#endif 
X	eputc (' ');
X	eputc ('K');
X	eputc ('e');
X	eputc ('y');
X	eputc (':');
X	eputc (' ');
X	ttflush ();
X	c = getkey ();              /* Read key.        */
X	keyname (xname, c);         /* Display keyname. */
X	eputs (xname);
X	ttflush ();
X	if (binding[c] != NULL)     /* Unbind old, and  */
X		--binding[c] -> s_nkey;
X	binding[c] = sp;            /* rebind new.      */
X	++sp -> s_nkey;
X	sp -> s_modify |= SBOUND;	/* flag as altered key binding */
X
X	return (TRUE);
X}
X
X
X/*
X* Extended command. Call the message line
X* routine to read in the command name and apply autocompletion
X* to it. When it comes back, look the name up in the symbol table
X* and run the command if it is found and has the right type.
X* Print an error if there is anything wrong.
X*/
Xchar    extend (f, n, k)
X{
X
X	register    SYMBOL * sp;
X	register char   s;
X	char    xname[NXNAME];
X
X	if ((s = eread (MSG_cmd_t_ex, xname, NXNAME, EFNEW | EFAUTO, NULL)) != TRUE)
X		return (s);
X	if ((sp = symlookup (xname)) != NULL)
X		return ((*sp -> s_funcp) (f, n, KRANDOM));
X	writ_echo (MSG_unk_ext);
X	return (ABORT);
X}
X
X
X/*
X* Read a key from the keyboard, and look it
X* up in the binding table. Display the name of the function
X* currently bound to the key. Say that the key is not bound
X* if it is indeed not bound, or if the type is not a
X* "builtin". This is a bit of overkill, because this is the
X* only kind of function there is.
X*/
Xbool help ()
X{
X	register    SYMBOL * sp;
X	register int    c;
X	char    b[20];
X	char    buf[80];
X
X	writ_echo (MSG_d_b);
X
X	c = getkey ();
X	keyname (b, c);
X	if ((sp = binding[c]) == NULL)
X	{
X		sprintf (buf, MSG_unbd, b);
X		writ_echo (buf);
X	}
X	else
X	{
X		sprintf (buf, MSG_bnd_to, b, sp -> s_name);
X		writ_echo (buf);
X	}
X	return (TRUE);
X}
X
X/*
X*   Sort the lines in the buffer.
X*/
Xvoid    sort_buf (b_ptr, cnt)
XBUFFER  *b_ptr;
Xint     cnt;
X{
X	LINE    *lp1, *lp2;
X	bool    no_swap;
X	int     loop1, loop2;
X
X	for (loop1 = cnt; loop1 > 0; loop1--)
X	{
X		no_swap = TRUE;
X		lp1 = b_ptr -> b_linep -> l_fp; /* point to first line */
X		lp2 = lp1 -> l_fp;      /* point to next line */
X		for (loop2 = 0; loop2 <= loop1; loop2++)
X		{
X			/* compare strings and swap if necessary */
X			if (0 < strcmp (&lp1 -> l_text[HFUNCCOL], &lp2 -> l_text[HFUNCCOL]))
X			{
X				lp1 -> l_bp -> l_fp = lp2;  /* get pointer to first string */
X				lp2 -> l_fp -> l_bp = lp1;  /* make it point to second string */
X
X				lp1 -> l_fp = lp2 -> l_fp;
X				lp2 -> l_bp = lp1 -> l_bp;
X
X				lp1 -> l_bp = lp2;
X				lp2 -> l_fp = lp1;
X
X				lp2 -> l_file_offset = lp1 -> l_file_offset;
X				lp1 -> l_file_offset = lp2 -> l_file_offset + lp2 -> l_used;
X
X				no_swap = FALSE;
X			}
X			else
X			{
X				/* if no swap then advance both pointers */
X				lp1 = lp2;
X			}
X			lp2 = lp1 -> l_fp;
X		}
X		/* quick exit if sort is finished sooner than expected */
X		if (no_swap)
X		{
X			return;
X		}
X	}
X}
X
X/*
X* This function creates a table, listing all
X* of the command keys and their current bindings, and stores
X* the table in the standard pop-op buffer (the one used by the
X* directory list command, the buffer list command, etc.). This
X* lets the editor produce it's own wall chart. The bindings to
X* "ins-self" are only displayed if there is an argument.
X*/
Xchar    wallchart (f, n, k)
X{
X
X	register char   s;
X	register int    key, i, j;
X	register    SYMBOL * sp;
X	register char  *cp1;
X	register char  *cp2;
X	char    buf[64];
X	WINDOW  *wp;
X
X	if ((s = bclear (blistp)) != TRUE)/* Clear it out.    */
X		return (s);
X	i = 0;
X	(void) strcpy (blistp -> b_fname, MSG_null);
X	blistp -> b_flag = BFVIEW;
X	blistp -> b_type = BTHELP;
X	writ_echo (MSG_bld_wall);
X	sprintf (buf, MSG_wall_head);
X	if (addline (buf) == FALSE)
X		return;
X	for (key = 0; key < NKEYS; ++key)
X	{
X		/* For all keys.    */
X		sp = binding[key];
X		if (sp != NULL &&
X		    (f != FALSE || strcmp (sp -> s_name, MSG_ins_self) != 0))
X		{
X			cp1 = &buf[0];
X			while (cp1 < &buf[HFUNCCOL])/* Goto column 3.  */
X				*cp1++ = ' ';
X			if ((sp -> s_modify & SBOUND) == 0)	/* comment out default binding */
X				buf[0] = '#';
X			cp2 = sp -> s_name; /* Add function name.   */
X			while (*cp1++ = *cp2++)
X				;
X			cp1--;
X			while (cp1 < &buf[HKEY])/* Goto column 32.  */
X				*cp1++ = ' ';
X			keyname (&buf[HKEY], key);
X			cp1 = &buf[strlen(buf)];
X			while (cp1 < &buf[HKEYCODE])/* Goto column 50.  */
X				*cp1++ = ' ';
X			sprintf (&buf[HKEYCODE], "%4X", key);
X			if (addline (buf) == FALSE)
X				break; /* lets go with what we have */
X			i++;
X		}
X	}
X
X	/* list unbound functions lest they get lost */
X	for (j = 0; j < NSHASH; j++)
X	{
X		sp = symbol[j];
X		while (sp != NULL)
X		{
X			if (sp -> s_nkey == 0)
X			{
X				cp1 = &buf[0];
X				while (cp1 < &buf[HFUNCCOL])/* Goto column 3.  */
X					*cp1++ = ' ';
X				buf[0] = '#';
X				cp2 = sp -> s_name; /* Add function name.   */
X				while (*cp1++ = *cp2++)
X					;
X				cp1--;
X				while (cp1 < &buf[HENDCOL])
X					*cp1++ = ' ';
X				*cp1 = 0;
X				i++;
X				if (addline (buf) == FALSE)
X					break; /* lets go with what we have */
X			}
X			sp = sp -> s_symp;
X		}
X	}
X	sort_buf (blistp, i);      /* sort buffer lines */
X	popblist ();
X	writ_echo (MSG_null);
X	/* make new window the current window */
X	wp = wheadp;
X	while (wp != NULL)
X	{
X		if (wp -> w_bufp == blistp)
X		{
X			curwp = wp;
X			curbp = wp -> w_bufp;
X			return (TRUE);
X		}
X		wp = wp -> w_wndp;
X	}
X	return (TRUE);
X}
X
X/* check for BEAVFIL and read it in if found
X* - also, set local file variable for bindtokey for saving new defs
X* (this is some what of a hack as it only handles 'bindtokey' changes at 
X* this time - also local file io !!!)
X*/
Xvoid check_extend (sfname)
X
Xchar *sfname;	/* name of startup file (null if default) */
X
X{
X	char *fname;	/* resulting file name to execute */
X	char	rc_name[40];	/* fixed up name of rc file */
X	char	*term;
X	char *getenv();
X	register    SYMBOL * sp;
X	char    funcname[NXNAME + 1];
X	char    keybind[NXNAME + 1];
X	int     keyval;
X	FILE * bindf;
X
X	/* look up the startup file */
X	if ((sfname != NULL) && (*sfname != 0))
X		fname = flook(sfname, TRUE);
X	else
X	{
X#ifdef UNIX
X		/* hidden file under unix */
X		strcpy (&rc_name[0], ".");
X		strcpy (&rc_name[1], MSG_beavrc);
X
X		if ((term = getenv("TERM")) != 0)
X		{
X			strcpy (&rc_name[strlen(rc_name)], ".");
X			strcpy (&rc_name[strlen(rc_name)], term);
X		}
X		fname = flook(rc_name, TRUE);
X		/* if fixed up name is not there then check original */
X		if (fname == NULL)
X		{
X			/* hidden file under unix */
X			strcpy (&rc_name[0], ".");
X			strcpy (&rc_name[1], MSG_beavrc);
X			fname = flook(rc_name, TRUE);
X		}
X#else
X		strcpy (rc_name, MSG_beavrc);
X		fname = flook(rc_name, TRUE);
X#endif
X	}
X	/* if it isn't around, don't sweat it */
X	if (fname == NULL)
X		return;
X
X	if (bindf = fopen(fname, "r"))
X	{
X		char	buffr[80];
X		char	*buffp;
X
X		buffp = buffr;
X		while (fread (buffp++, sizeof(char), 1, bindf) == 1)
X		{
X			/* scanf is unhappy with commas */
X			if (buffp[-1] == ',')
X				buffp[-1] = '-';
X
X			/* did we get a whole line */
X			if (buffp[-1] == '\n')
X			{
X				*buffp = 0;	/* terminate line */
X				buffp = buffr;
X				sscanf (buffr, "%s %s %x", funcname, keybind, &keyval);
X				if ((buffr[0] == '#') || (keyval == 0))
X					continue;
X				if (sp = symlookup (funcname))
X				{
X					if (binding[keyval] != NULL)/* Unbind old, and  */
X						--binding[keyval] -> s_nkey;
X					binding[keyval] = sp;/* rebind new.      */
X					++sp -> s_nkey;
X					sp -> s_modify |= SBOUND;	/* flag as altered key binding */
X				}
X			}
X		}
X		fclose (bindf);
X	}
X}
X
X/*	Look up the existance of a file along the normal or PATH
X	environment variable. Look first in the HOME directory if
X	asked and possible
X*/
X
Xchar *flook(fname, hflag)
X
Xchar *fname;	/* base file name to search for */
Xint hflag;	/* Look in the HOME environment variable first? */
X
X{
X	register char *home;	/* path to home directory */
X	register char *path;	/* environmental PATH variable */
X	register char *sp;	/* pointer into path spec */
X	register int i;		/* index */
X	static char fspec[128];	/* full path spec to search */
X	char *getenv();
X	FILE * bindf;
X
X	if (hflag) {
X		home = getenv("HOME");
X		if (home != NULL) {
X			/* build home dir file spec */
X			strcpy(fspec, home);
X			if (fspec[strlen(fspec) - 1] != '/')
X				strcat(fspec, "/");
X			strcat(fspec, fname);
X
X			/* and try it out */
X			if (bindf = fopen(fspec, "r"))
X			{
X				fclose(bindf);
X				return(fspec);
X			}
X		}
X	}
X
X	/* always try the current directory first */
X	if (bindf = fopen(fname, "r"))
X	{
X		fclose(bindf);
X		return(fname);
X	}
X
X	/* get the PATH variable */
X	path = getenv("PATH");
X	if (path != NULL)
X		while (*path) {
X
X			/* build next possible file spec */
X			sp = fspec;
X			while (*path && (*path != PATHCHR))
X				*sp++ = *path++;
X
X			/* add a terminating dir separator if we need it */
X			if (sp[-1] != SEPCHAR)
X				*sp++ = SEPCHAR;
X
X			*sp = 0;
X			strcat(fspec, fname);
X
X			/* and try it out */
X			if (bindf = fopen(fspec, "r"))
X			{
X				fclose(bindf);
X				return(fspec);
X			}
X
X			if (*path == PATHCHR)
X				++path;
X		}
X
X	return(NULL);	/* no such luck */
X}
X
X
X/* interactive method for loading binding file
X* (uses above routine, obviously)
X*/
Xchar    load_extend ()
X{
X
X#ifdef CUSTOMIZE
X	register char   s;
X	char    fname[NFILEN];
X
X	if ((s = ereply (MSG_bnd_file, fname, NFILEN, NULL)) != TRUE)
X		return (s);
X	check_extend (fname);
X	writ_echo (okmsg);
X#endif
X	return (TRUE);
X}
X
Xint     find_keyval (name)
Xchar   *name;
X{
X	SYMBOL * sp;
X	int     key;
X
X	for (key = 0; key < NKEYS; ++key)
X	{
X		/* For all keys.    */
X		sp = binding[key];
X		if (sp != NULL && (strcmp (sp -> s_name, name) == 0))
X			return (key);
X	}
X	return (0);
X}
END_OF_FILE
if test 10920 -ne `wc -c <'extend.c'`; then
    echo shar: \"'extend.c'\" unpacked with wrong size!
fi
# end of 'extend.c'
fi
if test -f 'format.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'format.c'\"
else
echo shar: Extracting \"'format.c'\" \(8671 characters\)
sed "s/^X//" >'format.c' <<'END_OF_FILE'
X/*
X* The module devines the format of the screen display.
X*/
X
X#define LINT_ARGS   1           /* enable lint type checking */
X#include    "def.h"
X
X
Xextern    char    hex_str[];
Xextern    char    hex_l_str[];
Xextern    char    octal_str[];
Xextern    char    octal_l_str[];
Xextern    char    decimal_str[];
Xextern    char    decimal_l_str[];
Xextern    char    char_str[];
X
X
X/* These structures contain the format for the displayed line */
X
X
X#define FC 13
X#define FS 0
X
Xuchar    ascii_s_posn[] =
X{
X	FS+0, FS+1, FS+2, FS+3, FS+4, FS+5, FS+6, FS+7, FS+8, FS+9,
X	    FS+10, FS+11, FS+12, FS+13, FS+14, FS+15, FS+16, FS+17, FS+18, FS+19,
X	    FS+20, FS+21, FS+22, FS+23, FS+24, FS+25, FS+26, FS+27, FS+28, FS+29,
X	    FS+30, FS+31, FS+32, FS+33, FS+34, FS+35, FS+36, FS+37, FS+38, FS+39,
X	    FS+40, FS+41, FS+42, FS+43, FS+44, FS+45, FS+46, FS+47, FS+48, FS+49,
X	    FS+50, FS+51, FS+52, FS+53, FS+54, FS+55, FS+56, FS+57, FS+58, FS+59,
X	    FS+60, FS+61, FS+62, FS+63, FS+64, FS+65, FS+66, FS+67, FS+68, FS+69,
X	    FS+70, FS+71, FS+72, FS+73, FS+74, FS+75, FS+76, FS+77, FS+78, FS+79,
X};
X
XROW_FMT text_fmt =
X{
X	TEXT, BYTES, 128, 128, 128, 1, 1, FALSE, char_str, hex_l_str, hex_str,
X	    ascii_s_posn, 0};
X
XROW_FMT ascii_fmt =
X{
X	ASCII, BYTES, 64, 64, 64, 1, 1, FALSE, char_str, hex_l_str, hex_str,
X	    &ascii_s_posn[FC], 0};
X
XROW_FMT ascii_s_fmt =
X{
X	ASCII, BYTES, 32, 32, 1, 1, 1, FALSE,  char_str, hex_l_str, hex_str,
X	    ascii_s_posn, 0};
X
XROW_FMT ebcdic_fmt =
X{
X	EBCDIC, BYTES, 64, 64, 64, 1, 1, FALSE, char_str, hex_l_str, hex_str,
X	    &ascii_s_posn[FC], 0};
X
XROW_FMT ebcdic_s_fmt =
X{
X	EBCDIC, BYTES, 32, 32, 1, 1, 1, FALSE, char_str, hex_l_str, hex_str,
X	    ascii_s_posn, 0};
X
Xuchar    octal_8_posn[] =
X{
X	FC, FC + 4, FC + 8, FC + 12, FC + 16, FC + 20,
X	    FC + 24, FC + 28, FC + 33, FC + 37, FC + 41,
X	    FC + 45, FC + 49, FC + 53, FC + 57, FC + 61
X};
X
XROW_FMT octal_8_fmt =
X{
X	OCTAL, BYTES, 16, 16, 16, 1, 3, TRUE, octal_str, octal_l_str, octal_str,
X	    octal_8_posn, 0};
X
Xuchar    octal_s_8_posn[] =
X{
X	FS, FS + 4, FS + 8, FS + 12, FS + 16, FS + 20,
X	    FS + 24, FS + 28, FS + 32, FS + 36, FS + 40,
X	    FS + 44, FS + 48, FS + 52, FS + 56, FS + 60,
X	    FS + 64, FS + 68, FS + 72, FS + 76, FS + 80
X};
XROW_FMT octal_s_8_fmt =
X{
X	OCTAL, BYTES, 8, 8, 1, 1, 3, TRUE, octal_str, octal_l_str, octal_str,
X	    octal_s_8_posn, 0};
X
Xuchar    octal_16_posn[] =
X{
X	FC, FC + 7, FC + 14, FC + 21, FC + 29, FC + 36, FC + 43, FC + 50
X};
X
XROW_FMT octal_16_fmt =
X{
X	OCTAL, WORDS, 8, 16, 16, 2, 6, TRUE, octal_str, octal_l_str, octal_str,
X	    octal_16_posn, 0};
X
Xuchar    octal_s_16_posn[] =
X{
X	FS, FS + 7, FS + 14, FS + 21, FS + 28, FS + 35,
X	    FS + 42, FS + 49, FS + 56, FS + 63, FS + 70, FS + 77
X};
XROW_FMT octal_s_16_fmt =
X{
X	OCTAL, WORDS, 4, 8, 2, 2, 6, TRUE, octal_str, octal_l_str, octal_str,
X	    octal_s_16_posn, 0};
X
Xuchar    octal_32_posn[] =
X{
X	FC, FC + 12, FC + 25, FC + 37
X};
X
XROW_FMT octal_32_fmt =
X{
X	OCTAL, DWORDS, 4, 16, 16, 4, 11, TRUE, octal_l_str, octal_l_str, octal_str,
X	    octal_32_posn, 0};
X
Xuchar    octal_s_32_posn[] =
X{
X	FS, FS + 12, FS + 24, FS + 36, FS + 48, FS + 60, FS + 72
X};
XROW_FMT octal_s_32_fmt =
X{
X	OCTAL, DWORDS, 2, 8, 4, 4, 11, TRUE, octal_l_str, octal_l_str, octal_str,
X	    octal_s_32_posn, };
X
XROW_FMT decimal_8_fmt =
X{
X	DECIMAL, BYTES, 16, 16, 16, 1, 3, TRUE, decimal_str, decimal_l_str, decimal_str,
X	    octal_8_posn, 0};
X
XROW_FMT decimal_s_8_fmt =
X{
X	DECIMAL, BYTES, 8, 8, 1, 1, 3, TRUE, decimal_str, decimal_l_str, decimal_str,
X	    octal_s_8_posn, 0};
X
Xuchar    decimal_16_posn[] =
X{
X	FC, FC + 6, FC + 12, FC + 18, FC + 25,
X	    FC + 31, FC + 37, FC + 43
X};
X
XROW_FMT decimal_16_fmt =
X{
X	DECIMAL, WORDS, 8, 16, 16, 2, 5, TRUE, decimal_str, decimal_l_str, decimal_str,
X	    decimal_16_posn, 0};
X
Xuchar    decimal_s_16_posn[] =
X{
X	FS, FS + 6, FS + 12, FS + 18, FS + 24,
X	    FS + 30, FS + 36, FS + 42, FS + 48,
X	    FS + 54, FS + 60, FS + 66, FS + 72, FS + 78
X};
XROW_FMT decimal_s_16_fmt =
X{
X	DECIMAL, WORDS, 4, 8, 2, 2, 5, TRUE, decimal_str, decimal_l_str, decimal_str,
X	    decimal_s_16_posn, 0};
X
Xuchar    decimal_32_posn[] =
X{
X	FC, FC + 11, FC + 23, FC + 34
X};
X
XROW_FMT decimal_32_fmt =
X{
X	DECIMAL, DWORDS, 4, 16, 16, 4, 10, TRUE, decimal_l_str, decimal_l_str, decimal_str,
X	    decimal_32_posn, 0};
X
Xuchar    decimal_s_32_posn[] =
X{
X	FS, FS + 11, FS + 22, FS + 33, FS + 44, FS + 55, FS + 66, FS + 77
X};
XROW_FMT decimal_s_32_fmt =
X{
X	DECIMAL, DWORDS, 4, 16, 4, 4, 10, TRUE, decimal_l_str, decimal_l_str, decimal_str,
X	    decimal_s_32_posn, 0};
X
Xuchar    hex_8_posn[] =
X{
X	FC, FC + 3, FC + 6, FC + 9, FC + 12, FC + 15,
X	    FC + 18, FC + 21, FC + 25, FC + 28, FC + 31,
X	    FC + 34, FC + 37, FC + 40, FC + 43, FC + 46,
X	    FC + 50, FC + 51, FC + 52, FC + 53, FC + 54,
X	    FC + 55, FC + 56, FC + 57, FC + 58, FC + 59,
X	    FC + 60, FC + 61, FC + 62, FC + 63, FC + 64,
X	    FC + 65
X};
X
XROW_FMT hex_8_fmt =
X{
X	HEX, BYTES, 16, 16, 16, 1, 2, TRUE, hex_str, hex_l_str, hex_str,
X	    hex_8_posn, 0};
X
X
Xuchar    hex_s_8_posn[] =
X{
X	FS, FS + 3, FS + 6, FS + 9, FS + 12, FS + 15,
X	    FS + 18, FS + 21, FS + 24, FS + 27, FS + 30,
X	    FS + 33, FS + 36, FS + 39, FS + 42, FS + 45,
X	    FS + 48, FS + 51, FS + 54, FS + 57, FS + 60,
X	    FS + 63, FS + 66, FS + 69, FS + 72, FS + 75,
X	    FS + 78, FS + 80, FS + 80, FS + 80, FS + 80,
X	    FS + 80
X};
XROW_FMT hex_s_8_fmt =
X{
X	HEX, BYTES, 8, 8, 1, 1, 2, TRUE, hex_str, hex_l_str, hex_str,
X	    hex_s_8_posn, 0};
X
Xuchar    hex_16_posn[] =
X{
X	FC, FC + 5, FC + 10, FC + 15, FC + 21, FC + 26, FC + 31, FC + 36
X};
X
XROW_FMT hex_16_fmt =
X{
X	HEX, WORDS, 8, 16, 16, 2, 4, TRUE, hex_str, hex_l_str, hex_str,
X	    hex_16_posn, 0};
X
Xuchar    hex_s_16_posn[] =
X{
X	FS, FS + 5, FS + 10, FS + 15, FS + 20, FS + 25,
X	    FS + 30, FS + 35, FS + 40, FS + 45, FS + 50,
X	    FS + 55, FS + 60, FS + 65, FS + 70, FS + 75
X};
XROW_FMT hex_s_16_fmt =
X{
X	HEX, WORDS, 8, 16, 2, 2, 4, TRUE, hex_str, hex_l_str, hex_str,
X	    hex_s_16_posn, 0};
X
Xuchar    hex_32_posn[] =
X{
X	FC, FC + 9, FC + 19, FC + 28
X};
X
XROW_FMT hex_32_fmt =
X{
X	HEX, DWORDS, 4, 16, 16, 4, 8, TRUE, hex_l_str, hex_l_str, hex_str,
X	    hex_32_posn, 0};
X
Xuchar    hex_s_32_posn[] =
X{
X	FS, FS + 9, FS + 18, FS + 27, FS + 36, FS + 45, FS + 54, FS + 63, FS + 72
X};
XROW_FMT hex_s_32_fmt =
X{
X	HEX, DWORDS, 4, 16, 4, 4, 8, TRUE, hex_l_str, hex_l_str, hex_str,
X	    hex_s_32_posn, 0};
X
XROW_FMT binary_8_fmt =
X{
X	BINARY, BYTES, 4, 4, 4, 1, 8, FALSE, hex_str, hex_l_str, hex_str,
X	    hex_32_posn, 0};  /* use the hex position array */
X
XROW_FMT binary_s_8_fmt =
X{
X	BINARY, BYTES, 4, 4, 1, 1, 8, FALSE, hex_str, hex_l_str, hex_str,
X	    hex_s_32_posn, 0};  /* use the hex position array */
X
Xuchar    binary_16_posn[] =
X{
X	FC, FC + 17, FC + 34, FC + 51
X};
X
XROW_FMT binary_16_fmt =
X{
X	BINARY, WORDS, 4, 8, 8, 2, 16, FALSE, hex_str, hex_l_str, hex_str,
X	    binary_16_posn, 0};
X
Xuchar    binary_s_16_posn[] =
X{
X	FS, FS + 17, FS + 34, FS + 51, FS + 68
X};
XROW_FMT binary_s_16_fmt =
X{
X	BINARY, WORDS, 2, 4, 2, 2, 16, FALSE, hex_str, hex_l_str, hex_str,
X	    binary_s_16_posn, 0};
X
Xuchar    binary_32_posn[] =
X{
X	FC, FC + 33
X};
X
XROW_FMT binary_32_fmt =
X{
X	BINARY, DWORDS, 2, 8, 8, 4, 32, FALSE, hex_l_str, hex_l_str, hex_str,
X	    binary_32_posn, 0};
X
Xuchar    binary_s_32_posn[] =
X{
X	FS, FS + 33
X};
XROW_FMT binary_s_32_fmt =
X{
X	BINARY, DWORDS, 1, 4, 4, 4, 32, FALSE, hex_l_str, hex_l_str, hex_str,
X	    binary_s_32_posn, 0};
X
X/* I must do this because C does not allow forward initialization of
X	structures */
Xinit_fmt()
X{
X	text_fmt.r_srch_fmt = &text_fmt;
X	ascii_fmt.r_srch_fmt = &ascii_s_fmt;
X	ascii_s_fmt.r_srch_fmt = &ascii_fmt;
X	ebcdic_fmt.r_srch_fmt = &ebcdic_s_fmt;
X	ebcdic_s_fmt.r_srch_fmt = &ebcdic_fmt;
X	octal_8_fmt.r_srch_fmt = &octal_s_8_fmt;
X	octal_s_8_fmt.r_srch_fmt = &octal_8_fmt;
X	octal_16_fmt.r_srch_fmt = &octal_s_16_fmt;
X	octal_s_16_fmt.r_srch_fmt = &octal_16_fmt;
X	octal_32_fmt.r_srch_fmt = &octal_s_32_fmt;
X	octal_s_32_fmt.r_srch_fmt = &octal_32_fmt;
X	decimal_8_fmt.r_srch_fmt = &decimal_s_8_fmt;
X	decimal_s_8_fmt.r_srch_fmt = &decimal_8_fmt;
X	decimal_16_fmt.r_srch_fmt = &decimal_s_16_fmt;
X	decimal_s_16_fmt.r_srch_fmt = &decimal_16_fmt;
X	decimal_32_fmt.r_srch_fmt = &decimal_s_32_fmt;
X	decimal_s_32_fmt.r_srch_fmt = &decimal_32_fmt;
X	hex_8_fmt.r_srch_fmt = &hex_s_8_fmt;
X	hex_s_8_fmt.r_srch_fmt = &hex_8_fmt;
X	hex_16_fmt.r_srch_fmt = &hex_s_16_fmt;
X	hex_s_16_fmt.r_srch_fmt = &hex_16_fmt;
X	hex_32_fmt.r_srch_fmt = &hex_s_32_fmt;
X	hex_s_32_fmt.r_srch_fmt = &hex_32_fmt;
X	binary_8_fmt.r_srch_fmt = &binary_s_8_fmt;
X	binary_s_8_fmt.r_srch_fmt = &binary_8_fmt;
X	binary_16_fmt.r_srch_fmt = &binary_s_16_fmt;
X	binary_s_16_fmt.r_srch_fmt = &binary_16_fmt;
X	binary_32_fmt.r_srch_fmt = &binary_s_32_fmt;
X	binary_s_32_fmt.r_srch_fmt = &binary_32_fmt;
X}
END_OF_FILE
if test 8671 -ne `wc -c <'format.c'`; then
    echo shar: \"'format.c'\" unpacked with wrong size!
fi
# end of 'format.c'
fi
if test -f 'lintfunc.dec' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lintfunc.dec'\"
else
echo shar: Extracting \"'lintfunc.dec'\" \(8644 characters\)
sed "s/^X//" >'lintfunc.dec' <<'END_OF_FILE'
Xextern  char *flook(char *fname,int hflag);
Xextern  char *keystrings(int key);
Xextern  char addline(char *text);
Xextern  char anycb(void );
Xextern  char asciimode(void );
Xextern  char autosave(void );
Xextern  char backchar(int f,int n,int k);
Xextern  char backdel(int f,int n,int k);
Xextern  char backline(int f,int n,int k);
Xextern  char backpage(int f,int n,int k);
Xextern  char backsearch(void );
Xextern  char backsrch(void );
Xextern  char backunit(int f,int n,int k);
Xextern  char bclear(struct BUFFER *bp);
Xextern  char binarymode(void );
Xextern  char bindtokey(void );
Xextern  char buffername(void );
Xextern  char bufsizlock(void );
Xextern  char b_append_c(struct BUFFER *buf_p,unsigned char ch);
Xextern  char compare(void );
Xextern  char copyregion(int f,int n,int k);
Xextern  char ctlxe(int f,int n,int k);
Xextern  char ctlxlp(int f,int n,int k);
Xextern  char ctlxrp(int f,int n,int k);
Xextern  char ctrlg(int f,int n,int k);
Xextern  char decimalmode(void );
Xextern  char dec_chr_ok(char *char_buf,char *max_str,char chr,char pos);
Xextern  char delbunit(int f,int n,int k);
Xextern  char delfunit(int f,int n,int k);
Xextern  char delwind(void );
Xextern  char dispshift(int f,int n,int k);
Xextern  char dispsize1(void );
Xextern  char dispsize2(void );
Xextern  char dispsize4(void );
Xextern  char dispswapbyte(int f,int n,int k);
Xextern  char ebcdicmode(void );
Xextern  char enlargewind(int f,int n,int k);
Xextern  char eread(char *fp,char *buf,int nbuf,int flag,char *ap);
Xextern  char ereply(char *fp,char *buf,int nbuf,char *arg);
Xextern  char execute(int c,int f,int n);
Xextern  char extend(int f,int n,int k);
Xextern  char eyesno(char *sp);
Xextern  char fbackupfile(char *fname);
Xextern  char ffclose(void );
Xextern  char ffgetline(char *buf,unsigned int nbuf,unsigned int *rbuf);
Xextern  char ffputline(char *buf,int nbuf);
Xextern  char ffropen(char *fn);
Xextern  char ffwopen(char *fn);
Xextern  char fileinsert(void );
Xextern  char filename(void );
Xextern  char fileread(void );
Xextern  char filesave(void );
Xextern  char filevisit(void );
Xextern  char filewrite(void );
Xextern  char file_visit(int f,int n,int k);
Xextern  char fill_out(void );
Xextern  char flushnquit(int f,int n,int k);
Xextern  char flush_all(void );
Xextern  char forwchar(int f,int n,int k);
Xextern  char forwdel(int f,int n,int k);
Xextern  char forwline(int f,int n,int k);
Xextern  char forwpage(int f,int n,int k);
Xextern  char forwsearch(void );
Xextern  char forwsrch(void );
Xextern  char forwunit(int f,int n,int k);
Xextern  char getregion(struct reg *rp);
Xextern  char getscreenstate(void );
Xextern  char gotobob(void );
Xextern  char gotoeob(void );
Xextern  char gotoline(int f,int n,int k);
Xextern  char help(void );
Xextern  char hexmode(void );
Xextern  char insertunit(int f,int n,int k);
Xextern  char insert_toggle(void );
Xextern  char killablebufs(struct BUFFER *bp);
Xextern  char killbuffer(void );
Xextern  char killregion(int f,int n,int k);
Xextern  char ldelete(unsigned long n_bytes,int kflag);
Xextern  char linkwind(void );
Xextern  char linsert(int n,unsigned char c);
Xextern  char listbuffers(void );
Xextern  char load_extend(void );
Xextern  char load_file(char *fname,unsigned long start,unsigned long end);
Xextern  char lreplace(int n,char c);
Xextern  char lrepl_str(int plen,struct LINE *rstr,struct LINE *mstr);
Xextern  char makelist(void );
Xextern  char move_ptr(struct WINDOW *wp,long len,char dot,char fix,char rel);
Xextern  char mvdnwind(int f,int n,int k);
Xextern  char mvupwind(int f,int n,int k);
Xextern  char nextwind(void );
Xextern  char next_buf(void );
Xextern  char n_way_combine(int f,int n,int k);
Xextern  char n_way_split(int f,int n,int k);
Xextern  char octalmode(void );
Xextern  char onebuf(struct BUFFER *bp);
Xextern  char onlywind(void );
Xextern  char parse_f_name(char *fn,unsigned long *start,unsigned long *end);
Xextern  char pickone(void );
Xextern  char popblist(void );
Xextern  char prevwind(void );
Xextern  char prev_buf(void );
Xextern  char print(void );
Xextern  char queryrepl(int f,int n,int k);
Xextern  char quit(int f,int n,int k);
Xextern  char quote(int f,int n,int k);
Xextern  char readin(char *fname,unsigned long start,unsigned long end);
Xextern  char readpattern(void );
Xextern  char recall(void );
Xextern  char refresh(void );
Xextern  char replaceit(void );
Xextern  char reposition(void );
Xextern  char save_region(int f,int n,int k);
Xextern  char searchagain(void );
Xextern  char selfinsert(int f,int n,int k);
Xextern  char setmark(void );
Xextern  char showcpos(int f,int n,int k);
Xextern  char showsavebuf(void );
Xextern  char showversion(int f,int n,int k);
Xextern  char shrinkwind(int f,int n,int k);
Xextern  char spawncli(int f,int n,int k);
Xextern  char splitwind(void );
Xextern  char swapmark(void );
Xextern  char to_ebcdic(char ch);
Xextern  char twiddle(void );
Xextern  char usebuffer(void );
Xextern  char use_buffer(void );
Xextern  char viewfile(void );
Xextern  char vtputd(struct WINDOW *wp,int row);
Xextern  char wallchart(int f,int n,int k);
Xextern  char wind_on_dot(struct WINDOW *wp);
Xextern  char writeout(char *fn,unsigned long start,unsigned long end);
Xextern  char yank(int f,int n,int k);
Xextern  char yank_buffer(void );
Xextern  char _killbuffer(char *bufn);
Xextern  char _usebuffer(char *bufn);
Xextern  char _yankbuffer(char *bufn);
Xextern  int find_keyval(char *name);
Xextern  int getctl(void );
Xextern  int getkbd(void );
Xextern  int getkey(void );
Xextern  int getsysconfig(union REGS *outregs,struct SREGS *segregs);
Xextern  int getxtra(struct SYMBOL *sp1,struct SYMBOL *sp2,int cpos);
Xextern  int symhash(char *cp);
Xextern  int ttgetc(void );
Xextern  int ttkeyready(void );
Xextern  struct BUFFER *bcreate(char *bname);
Xextern  struct BUFFER *bfind(char *bname,int cflag);
Xextern  struct LINE *lalloc(int size);
Xextern  struct LINE *l_break_in_two(struct LINE *lp,unsigned int lo,unsigned int extra);
Xextern  struct SYMBOL *symlookup(char *cp);
Xextern  struct WINDOW *wpopup(void );
Xextern  unsigned int fill_buf(struct WINDOW *wp,struct LINE *lin,unsigned int lin_off,char *w_buff,unsigned int cnt);
Xextern  unsigned int get_curcol(struct WINDOW *wp);
Xextern  unsigned int get_currow(struct WINDOW *wp);
Xextern  unsigned long ffseek(unsigned long posn);
Xextern  unsigned long file_len(void );
Xextern  unsigned long get_long(unsigned char *w_buf);
Xextern  unsigned short get_int(unsigned char *w_buf);
Xextern  unsigned short get_save_char(void );
Xextern  void adjustcase(char *fn);
Xextern  void asciiparm(int n);
Xextern  void bad_key(int key);
Xextern  void bin_to_text(char *bin_buf,char *txt_buf,unsigned int len,struct ROW_FMT *fmt_ptr);
Xextern  void b_append_l(struct BUFFER *buf_p,struct LINE *lp);
Xextern  void check_extend(char *sfname);
Xextern  void edinit(char *bname);
Xextern  void eerase(void );
Xextern  void eformat(char *fp,char *ap);
Xextern  void eputc(int c);
Xextern  void eputi(int i,int r);
Xextern  void eputs(char *s);
Xextern  void err_echo(char *buf);
Xextern  void funky_name(char *bname,int n);
Xextern  void is_wang(void );
Xextern  void keyadd(int new,char (*funcp)(),char *name,int modify);
Xextern  void keydup(int new,char *name);
Xextern  void keymapinit(void );
Xextern  void keyname(char *cp,int k);
Xextern  void lchange(int flag);
Xextern  void lfree(struct LINE *lp);
Xextern  void l_fix_up(struct LINE *line);
Xextern  void main(int argc,char * *argv);
Xextern  void makename(char *bname,char *fname);
Xextern  void mem_line(int row,struct vid *vvp);
Xextern  void modeline(struct WINDOW *wp);
Xextern  void next_pat(void );
Xextern  void putline(int row,int startcol,int stringsize,char *string);
Xextern  void save_buf_home(void );
Xextern  void save_buf_init(void );
Xextern  void set_crt_type(void );
Xextern  void set_mode_vars(void );
Xextern  void sort_buf(struct BUFFER *b_ptr,int cnt);
Xextern  void ttbeep(void );
Xextern  void ttclose(void );
Xextern  void ttcolor(int color);
Xextern  void ttcooked(void );
Xextern  void tteeol(void );
Xextern  void tteeop(void );
Xextern  void ttflush(void );
Xextern  void ttinit(void );
Xextern  void ttmove(int row,int col);
Xextern  void ttnowindow(void );
Xextern  void ttopen(void );
Xextern  void ttputc(int c);
Xextern  void ttraw(void );
Xextern  void tttidy(void );
Xextern  void ttykeymapinit(void );
Xextern  void ucopy(struct vid *vvp,struct vid *pvp);
Xextern  void uline(int row,struct vid *vvp,struct vid *pvp);
Xextern  void ungetkey(int k);
Xextern  void update(void );
Xextern  void vteeol(void );
Xextern  void vtinit(void );
Xextern  void vtmove(int row,int col);
Xextern  void vtputc(int c);
Xextern  void vttidy(void );
Xextern  void wind_on_dot_all(void );
Xextern  void writ_echo(char *buf);
Xextern  void _lowercase(char *s);
END_OF_FILE
if test 8644 -ne `wc -c <'lintfunc.dec'`; then
    echo shar: \"'lintfunc.dec'\" unpacked with wrong size!
fi
# end of 'lintfunc.dec'
fi
if test -f 'window.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'window.c'\"
else
echo shar: Extracting \"'window.c'\" \(10806 characters\)
sed "s/^X//" >'window.c' <<'END_OF_FILE'
X/*
X*       Window handling.
X*/
X#include    "def.h"
X
Xbool    mvupwind ();
Xbool    shrinkwind ();
X
Xextern    char    MSG_no_splt[];
Xextern    char    MSG_cnt_al_w[];
Xextern    char    MSG_one_w[];
Xextern    char    MSG_imp_chg[];
X
X/*
X* Reposition the window so as to center on the dot.
X*/
Xbool reposition ()
X{
X	long    l_val;
X
X	l_val = DOT_POS(curwp) - (curwp -> w_ntrows * R_BYTES(curwp) / 2);
X	move_ptr (curwp, l_val, FALSE, TRUE, FALSE);
X	curwp -> w_flag |= WFHARD;
X	return (TRUE);
X}
X
X/*
X* The command make the next
X* window (next => down the screen)
X* the current window. There are no real
X* errors, although the command does
X* nothing if there is only 1 window on
X* the screen.
X*/
Xbool nextwind ()
X{
X
X	register    WINDOW * wp;
X
X	if ((wp = curwp -> w_wndp) == NULL)
X		wp = wheadp;
X	curwp = wp;
X	curbp = wp -> w_bufp;
X	return (TRUE);
X}
X
X
X/*
X* This command makes the previous
X* window (previous => up the screen) the
X* current window. There arn't any errors,
X* although the command does not do a lot
X* if there is 1 window.
X*/
Xbool prevwind ()
X{
X
X	register    WINDOW * wp1;
X	register    WINDOW * wp2;
X
X	wp1 = wheadp;
X	wp2 = curwp;
X	if (wp1 == wp2)
X		wp2 = NULL;
X	while (wp1 -> w_wndp != wp2)
X		wp1 = wp1 -> w_wndp;
X	curwp = wp1;
X	curbp = wp1 -> w_bufp;
X	return (TRUE);
X}
X
X
X/*
X* This command moves the current
X* window down by "arg" lines. Recompute
X* the top line in the window. The move up and
X* move down code is almost completely the same;
X* most of the work has to do with reframing the
X* window, and picking a new dot. We share the
X* code by having "move down" just be an interface
X* to "move up".
X*/
Xbool    mvdnwind (f, n, k)
Xregister int    n;
X{
X	return (mvupwind (f, -n, KRANDOM));
X}
X
X
X/*
X* Move the current window up by "arg"
X* lines. Recompute the new top line of the window.
X* Look to see if "." is still on the screen. If it is,
X* you win. If it isn't, then move "." to center it
X* in the new framing of the window (this command does
X* not really move "."; it moves the frame).
X*/
Xbool    mvupwind (f, n, k)
Xint    n;
X{
X	A32   l_val, l_bytes;
X
X	l_bytes = (A32)R_BYTES(curwp);     /* number of bytes in a row */
X	l_val = n * l_bytes;     /* number of bytes to move */
X	move_ptr (curwp, l_val, FALSE, TRUE, TRUE);  /* move window */
X
X	/* check that dot is in window */
X	while (DOT_POS(curwp) < WIND_POS(curwp))
X	{
X		/* dot is before the first window line */
X		move_ptr (curwp, l_bytes, TRUE, TRUE, TRUE);
X	}
X	while (DOT_POS (curwp) >=
X	    ((l_bytes * curwp -> w_ntrows) + WIND_POS(curwp)))
X	{
X		/* dot is after the last window line */
X		move_ptr (curwp, -l_bytes, TRUE, TRUE, TRUE);
X	}
X	curwp -> w_flag |= WFHARD;
X	return (TRUE);
X}
X
X
X/*
X* This command makes the current
X* window the only window on the screen.
X* Try to set the framing
X* so that "." does not have to move on
X* the display. Some care has to be taken
X* to keep the values of dot and mark
X* in the buffer structures right if the
X* distruction of a window makes a buffer
X* become undisplayed.
X*/
Xbool    onlywind ()
X{
X
X	register    WINDOW * wp;
X	register    LINE * lp;
X	register int    i;
X
X	while (wheadp != curwp)
X	{
X
X		wp = wheadp;
X		wheadp = wp -> w_wndp;
X		if (--wp -> w_bufp -> b_nwnd == 0)
X		{
X
X			wp -> w_bufp -> b_dotp = wp -> w_dotp;
X			wp -> w_bufp -> b_doto = wp -> w_doto;
X			wp -> w_bufp -> b_markp = wp -> w_markp;
X			wp -> w_bufp -> b_marko = wp -> w_marko;
X		}
X
X		free ((char *) wp);
X	}
X
X	while (curwp -> w_wndp != NULL)
X	{
X
X		wp = curwp -> w_wndp;
X		curwp -> w_wndp = wp -> w_wndp;
X		if (--wp -> w_bufp -> b_nwnd == 0)
X		{
X
X			wp -> w_bufp -> b_dotp = wp -> w_dotp;
X			wp -> w_bufp -> b_doto = wp -> w_doto;
X			wp -> w_bufp -> b_markp = wp -> w_markp;
X			wp -> w_bufp -> b_marko = wp -> w_marko;
X		}
X
X		free ((char *) wp);
X	}
X
X	lp = curwp -> w_linep;
X	i = curwp -> w_toprow;
X	while (i != 0 && lback (lp) != curbp -> b_linep)
X	{
X
X		--i;
X		lp = lback (lp);
X	}
X
X	curwp -> w_toprow = 0;
X	curwp -> w_ntrows = nrow - 2;/* 2 = mode, echo.  */
X	curwp -> w_linep = lp;
X	curwp -> w_flag |= WFMODE | WFHARD;
X	return (TRUE);
X}
X
X/*
X * Delete the current window, placing its space in the window above,
X * or, if it is the top window, the window below. Bound to C-X 0.
X */
X
Xbool	delwind()
X
X{
X	register WINDOW *wp;	/* window to recieve deleted space */
X	register WINDOW *lwp;	/* ptr window before curwp */
X	register int target;	/* target line to search for */
X
X	/* if there is only one window, don't delete it */
X	if (wheadp->w_wndp == NULL) {
X		return(FALSE);
X	}
X
X	/* find window before curwp in linked list */
X	wp = wheadp;
X	lwp = NULL;
X	while (wp != NULL) {
X		if (wp == curwp)
X			break;
X		lwp = wp;
X		wp = wp->w_wndp;
X	}
X
X	/* find recieving window and give up our space */
X	wp = wheadp;
X	if (curwp->w_toprow == 0) {
X		/* find the next window down */
X		target = curwp->w_ntrows + 1;
X		while (wp != NULL) {
X			if (wp->w_toprow == target)
X				break;
X			wp = wp->w_wndp;
X		}
X		if (wp == NULL)
X			return(FALSE);
X		wp->w_toprow = 0;
X		wp->w_ntrows += target;
X	} else {
X		/* find the next window up */
X		target = curwp->w_toprow - 1;
X		while (wp != NULL) {
X			if ((wp->w_toprow + wp->w_ntrows) == target)
X				break;
X			wp = wp->w_wndp;
X		}
X		if (wp == NULL)
X			return(FALSE);
X		wp->w_ntrows += 1 + curwp->w_ntrows;
X	}
X
X	/* get rid of the current window */
X	if (--curwp->w_bufp->b_nwnd == 0) {
X		curwp->w_bufp->b_dotp = curwp->w_dotp;
X		curwp->w_bufp->b_doto = curwp->w_doto;
X		curwp->w_bufp->b_markp = curwp->w_markp;
X		curwp->w_bufp->b_marko = curwp->w_marko;
X	}
X	if (lwp == NULL)
X		wheadp = curwp->w_wndp;
X	else
X		lwp->w_wndp = curwp->w_wndp;
X	free((char *)curwp);
X	curwp = wp;
X	wp -> w_flag |= WFMODE | WFHARD;
X	curbp = wp->w_bufp;
X	return(TRUE);
X}
X
X/*
X* Split the current window. A window
X* smaller than 3 lines cannot be split.
X* The only other error that is possible is
X* a "malloc" failure allocating the structure
X* for the new window.
X*/
Xbool splitwind ()
X{
X
X	register    WINDOW * wp;
X	register int    ntru;
X	register int    ntrl;
X	register int    ntrd;
X	register    WINDOW * wp1;
X	register    WINDOW * wp2;
X	char    buf[80], buf1[40];
X
X	if (curwp -> w_ntrows < 3)
X	{
X		sprintf (buf1, MSG_no_splt, R_BYTE_FMT(curwp));
X		sprintf (buf, buf1, curwp -> w_ntrows);
X		writ_echo (buf);
X		return (FALSE);
X	}
X
X	if ((wp = (WINDOW *) malloc (sizeof (WINDOW))) == NULL)
X	{
X		err_echo (MSG_cnt_al_w);
X		return (FALSE);
X	}
X
X	++curbp -> b_nwnd;          /* Displayed twice.  */
X	wp -> w_bufp = curbp;
X	wp -> w_dotp = curwp -> w_dotp;
X	wp -> w_doto = curwp -> w_doto;
X	wp -> w_unit_offset = curwp -> w_unit_offset;
X	wp -> w_markp = curwp -> w_markp;
X	wp -> w_marko = curwp -> w_marko;
X	wp -> w_flag = 0;
X	wp -> w_disp_shift = curwp -> w_disp_shift;
X	wp -> w_intel_mode = curwp -> w_intel_mode;
X	wp -> w_fmt_ptr = curwp -> w_fmt_ptr;
X	ntru = (curwp -> w_ntrows - 1) / 2;/* Upper size         */
X	ntrl = (curwp -> w_ntrows - 1) - ntru;/* Lower size      */
X
X	if (ntrd <= get_currow (curwp))
X	{
X		/* Old is upper window.      */
X		curwp -> w_ntrows = ntru;
X		wp -> w_wndp = curwp -> w_wndp;
X		curwp -> w_wndp = wp;
X		wp -> w_toprow = curwp -> w_toprow + ntru + 1;
X		wp -> w_ntrows = ntrl;
X	}
X	else
X	{
X		/* Old is lower window       */
X		wp1 = NULL;
X		wp2 = wheadp;
X		while (wp2 != curwp)
X		{
X			wp1 = wp2;
X			wp2 = wp2 -> w_wndp;
X		}
X
X		if (wp1 == NULL)
X			wheadp = wp;
X		else
X			wp1 -> w_wndp = wp;
X		wp -> w_wndp = curwp;
X		wp -> w_toprow = curwp -> w_toprow;
X		wp -> w_ntrows = ntru;
X		++ntru;                 /* Mode line.        */
X		curwp -> w_toprow += ntru;
X		curwp -> w_ntrows = ntrl;
X	}
X
X	wind_on_dot (curwp);        /* put window on the dot */
X	wp -> w_loff = curwp -> w_loff;/* do the same for the new window */
X	wp -> w_linep = curwp -> w_linep;
X	curwp -> w_flag |= WFMODE | WFHARD;
X	wp -> w_flag |= WFMODE | WFHARD;
X	return (TRUE);
X}
X
X
X/*
X* Enlarge the current window.
X* Find the window that loses space. Make
X* sure it is big enough. If so, hack the window
X* descriptions, and ask redisplay to do all the
X* hard work. You don't just set "force reframe"
X* because dot would move.
X*/
Xbool enlargewind (f, n, k)
X{
X	register    WINDOW * adjwp;
X	register    LINE * lp;
X	register int    i;
X
X	if (n < 0)
X		return (shrinkwind (f, -n, KRANDOM));
X	if (wheadp -> w_wndp == NULL)
X	{
X
X		writ_echo (MSG_one_w);
X		return (FALSE);
X	}
X
X	if ((adjwp = curwp -> w_wndp) == NULL)
X	{
X		adjwp = wheadp;
X		while (adjwp -> w_wndp != curwp)
X			adjwp = adjwp -> w_wndp;
X	}
X
X	if (adjwp -> w_ntrows <= n)
X	{
X		writ_echo (MSG_imp_chg);
X		return (FALSE);
X	}
X
X	if (curwp -> w_wndp == adjwp)
X	{
X		/* Shrink below.     */
X		lp = adjwp -> w_linep;
X		for (i = 0; i < n && lp != adjwp -> w_bufp -> b_linep; ++i)
X			lp = lforw (lp);
X		adjwp -> w_linep = lp;
X		adjwp -> w_toprow += n;
X	}
X	else
X	{
X		/* Shrink above.     */
X		lp = curwp -> w_linep;
X		for (i = 0; i < n && lback (lp) != curbp -> b_linep; ++i)
X			lp = lback (lp);
X		curwp -> w_linep = lp;
X		curwp -> w_toprow -= n;
X	}
X
X	curwp -> w_ntrows += n;
X	adjwp -> w_ntrows -= n;
X	curwp -> w_flag |= WFMODE | WFHARD;
X	adjwp -> w_flag |= WFMODE | WFHARD;
X	return (TRUE);
X}
X
X
X/*
X* Shrink the current window.
X* Find the window that gains space. Hack at
X* the window descriptions. Ask the redisplay to
X* do all the hard work.
X*/
Xbool shrinkwind (f, n, k)
X{
X	register    WINDOW * adjwp;
X	register    LINE * lp;
X	register int    i;
X
X	if (n < 0)
X		return (enlargewind (f, -n, KRANDOM));
X	if (wheadp -> w_wndp == NULL)
X	{
X		writ_echo (MSG_one_w);
X		return (FALSE);
X	}
X
X	if ((adjwp = curwp -> w_wndp) == NULL)
X	{
X		adjwp = wheadp;
X		while (adjwp -> w_wndp != curwp)
X			adjwp = adjwp -> w_wndp;
X	}
X
X	if (curwp -> w_ntrows <= n)
X	{
X		writ_echo (MSG_imp_chg);
X		return (FALSE);
X	}
X
X	if (curwp -> w_wndp == adjwp)
X	{
X		/* Grow below.       */
X		lp = adjwp -> w_linep;
X		for (i = 0; i < n && lback (lp) != adjwp -> w_bufp -> b_linep; ++i)
X			lp = lback (lp);
X		adjwp -> w_linep = lp;
X		adjwp -> w_toprow -= n;
X	}
X	else
X	{
X		/* Grow above.       */
X		lp = curwp -> w_linep;
X		for (i = 0; i < n && lp != curbp -> b_linep; ++i)
X			lp = lforw (lp);
X		curwp -> w_linep = lp;
X		curwp -> w_toprow += n;
X	}
X
X	curwp -> w_ntrows -= n;
X	adjwp -> w_ntrows += n;
X	curwp -> w_flag |= WFMODE | WFHARD;
X	adjwp -> w_flag |= WFMODE | WFHARD;
X	return (TRUE);
X}
X
X
X/*
X* Pick a window for a pop-up.
X* Split the screen if there is only
X* one window. Pick the uppermost window that
X* isn't the current window. An LRU algorithm
X* might be better. Return a pointer, or
X* NULL on error.
X*/
XWINDOW * wpopup ()
X{
X
X	register    WINDOW * wp;
X
X	if (wheadp -> w_wndp == NULL
X	    && splitwind () == FALSE)
X		return (NULL);
X	wp = wheadp;                /* Find window to use    */
X	while (wp != NULL && wp == curwp)
X		wp = wp -> w_wndp;
X	return (wp);
X}
X
X
X/*
X* Refresh the display. 
X* In the normal case the
X* call to "update" in "main.c" refreshes the screen,
X* and all of the windows need not be recomputed.
X*/
Xbool refresh ()
X{
X	sgarbf = TRUE;
X	return (TRUE);
X}
END_OF_FILE
if test 10806 -ne `wc -c <'window.c'`; then
    echo shar: \"'window.c'\" unpacked with wrong size!
fi
# end of 'window.c'
fi
echo shar: End of archive 2 \(of 9\).
cp /dev/null ark2isdone
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.
