
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by tralfaz!ove on Wed Jan 13 14:06:45 PST 1988
# Contents:  isearc.c line.c lock.c uehelp uecomp uelink
 
echo x - isearc.c
sed 's/^@//' > "isearc.c" <<'@//E*O*F isearc.c//'
/*
 * The functions in this file implement commands that perform incremental
 * searches in the forward and backward directions.  This "ISearch" command
 * is intended to emulate the same command from the original EMACS 
 * implementation (ITS).  Contains references to routines internal to
 * SEARCH.C.
 *
 * REVISION HISTORY:
 *
 *	D. R. Banks 9-May-86
 *	- added ITS EMACSlike ISearch
 *
 *	John M. Gamble 5-Oct-86
 *	- Made iterative search use search.c's scanner() routine.
 *	  This allowed the elimination of bakscan().
 *	- Put isearch constants into esearc.h
 *	- Eliminated the passing of 'status' to scanmore() and
 *	  checknext(), since there were no circumstances where
 *	  it ever equalled FALSE.
 */

#include        <stdio.h>
#include	"estruc.h"
#include        "edef.h"
#include	"esearc.h"

#if	ISRCH

extern int scanner();			/* Handy search routine */
extern int eq();			/* Compare chars, match case */
extern char tap[];			/* Reverse pattern array.*/
/* A couple of "own" variables for re-eat */

int	(*saved_get_char)();		/* Get character routine */
int	eaten_char = -1;		/* Re-eaten char */

/* A couple more "own" variables for the command string */

int	cmd_buff[CMDBUFLEN];		/* Save the command args here */
int	cmd_offset;			/* Current offset into command buff */
int	cmd_reexecute = -1;		/* > 0 if re-executing command */


/*
 * Subroutine to do incremental reverse search.  It actually uses the
 * same code as the normal incremental search, as both can go both ways.
 */
 
int risearch(f, n)
{
    LINE *curline;			/* Current line on entry	      */
    int  curoff;			/* Current offset on entry	      */

    /* remember the initial . on entry: */

    curline = curwp->w_dotp;		/* Save the current line pointer      */
    curoff  = curwp->w_doto;		/* Save the current offset	      */

    /* Make sure the search doesn't match where we already are:		      */

    backchar(TRUE, 1);			/* Back up a character		      */

#if	CRAY	/* immediate mode on */
	sends("\\(I)") ;
#endif

    if (!(isearch(f, -n)))		/* Call ISearch backwards	      */
    {					/* If error in search:		      */
	curwp->w_dotp = curline;	/* Reset the line pointer	      */
	curwp->w_doto = curoff;		/*  and the offset to original value  */
	curwp->w_flag |= WFMOVE;	/* Say we've moved		      */
	update(FALSE);			/* And force an update		      */
	mlwrite ("[search failed]");	/* Say we died			      */
    } else mlerase ();			/* If happy, just erase the cmd line  */

#if	CRAY	/* immediate mode off */
	sends("\\(i)") ;
#endif
}

/* Again, but for the forward direction */

int fisearch(f, n)
{
    LINE *curline;			/* Current line on entry	      */
    int  curoff;			/* Current offset on entry	      */

    /* remember the initial . on entry: */

    curline = curwp->w_dotp;		/* Save the current line pointer      */
    curoff  = curwp->w_doto;		/* Save the current offset	      */

    /* do the search */

#if	CRAY	/* immediate mode on */
	sends("\\(I)") ;
#endif

    if (!(isearch(f, n)))		/* Call ISearch forwards	      */
    {					/* If error in search:		      */
	curwp->w_dotp = curline;	/* Reset the line pointer	      */
	curwp->w_doto = curoff;		/*  and the offset to original value  */
	curwp->w_flag |= WFMOVE;	/* Say we've moved		      */
	update(FALSE);			/* And force an update		      */
	mlwrite ("[search failed]");	/* Say we died			      */
    } else mlerase ();			/* If happy, just erase the cmd line  */

#if	CRAY	/* immediate mode off */
	sends("\\(i)") ;
#endif
}

/*
 * Subroutine to do an incremental search.  In general, this works similarly
 * to the older micro-emacs search function, except that the search happens
 * as each character is typed, with the screen and cursor updated with each
 * new search character.  Because of this, the CRAY version must tell the
 * workstation to switch to immediate mode, so that every character is
 * flushed immediately.
 *
 * While searching forward, each successive character will leave the cursor
 * at the end of the entire matched string.  Typing a Control-S or Control-X
 * will cause the next occurrence of the string to be searched for (where the
 * next occurrence does NOT overlap the current occurrence).  A Control-R will
 * change to a backwards search, META will terminate the search and Control-G
 * will abort the search.  Rubout will back up to the previous match of the
 * string, or if the starting point is reached first, it will delete the
 * last character from the search string.
 *
 * While searching backward, each successive character will leave the cursor
 * at the beginning of the matched string.  Typing a Control-R will search
 * backward for the next occurrence of the string.  Control-S or Control-X
 * will revert the search to the forward direction.  In general, the reverse
 * incremental search is just like the forward incremental search inverted.
 *
 * In all cases, if the search fails, the user will be feeped, and the search
 * will stall until the pattern string is edited back into something that
 * exists (or until the search is aborted).
 */
 
isearch(f, n)
{
    int			status;		/* Search status */
    int			col;		/* prompt column */
    register int	cpos;		/* character number in search string  */
    register int	c;		/* current input character */
    register int	expc;		/* function expanded input char	      */
    char		pat_save[NPAT];	/* Saved copy of the old pattern str  */
    LINE		*curline;	/* Current line on entry	      */
    int			curoff;		/* Current offset on entry	      */
    int			init_direction;	/* The initial search direction	      */

    /* Initialize starting conditions */

    cmd_reexecute = -1;		/* We're not re-executing (yet?)      */
    cmd_offset = 0;			/* Start at the beginning of the buff */
    cmd_buff[0] = '\0';		/* Init the command buffer	      */
    strncpy (pat_save, pat, NPAT);	/* Save the old pattern string	      */
    curline = curwp->w_dotp;		/* Save the current line pointer      */
    curoff  = curwp->w_doto;		/* Save the current offset	      */
    init_direction = n;			/* Save the initial search direction  */

    /* This is a good place to start a re-execution: */

start_over:

    /* ask the user for the text of a pattern */
    col = promptpattern("ISearch: ");		/* Prompt, remember the col   */

    cpos = 0;					/* Start afresh		      */
    status = TRUE;				/* Assume everything's cool   */

    /*
       Get the first character in the pattern.  If we get an initial Control-S
       or Control-R, re-use the old search string and find the first occurrence
     */

    c = ectoc(expc = get_char());		/* Get the first character    */
    if ((c == IS_FORWARD) ||
        (c == IS_REVERSE) ||
        (c == IS_VMSFORW))			/* Reuse old search string?   */
    {
    	for (cpos = 0; pat[cpos] != 0; cpos++)	/* Yup, find the length	      */
    	    col = echochar(pat[cpos],col);	/*  and re-echo the string    */
	if (c == IS_REVERSE) {			/* forward search?	      */
	    n = -1;				/* No, search in reverse      */
	    backchar (TRUE, 1);			/* Be defensive about EOB     */
	} else
	    n = 1;				/* Yes, search forward	      */
	status = scanmore(pat, n);		/* Do the search	      */
	c = ectoc(expc = get_char());		/* Get another character      */
    }

    /* Top of the per character loop */
        	
    for (;;)					/* ISearch per character loop */
    {
	/* Check for special characters first: */
	/* Most cases here change the search */

	if (expc == metac)			/* Want to quit searching?    */
	    return (TRUE);			/* Quit searching now	      */

	switch (c)				/* dispatch on the input char */
	{
	  case IS_ABORT:			/* If abort search request    */
	    return(FALSE);			/* Quit searching again	      */

	  case IS_REVERSE:			/* If backward search	      */
	  case IS_FORWARD:			/* If forward search	      */
	  case IS_VMSFORW:			/*  of either flavor	      */
	    if (c == IS_REVERSE)		/* If reverse search	      */
		n = -1;				/* Set the reverse direction  */
	    else				/* Otherwise, 		      */
		n = 1;				/*  go forward		      */
	    status = scanmore(pat, n);		/* Start the search again     */
	    c = ectoc(expc = get_char());	/* Get the next char	      */
	    continue;				/* Go continue with the search*/

	  case IS_NEWLINE:			/* Carriage return	      */
	    c = '\n';				/* Make it a new line	      */
	    break;				/* Make sure we use it	      */

	  case IS_QUOTE:			/* Quote character	      */
	  case IS_VMSQUOTE:			/*  of either variety	      */
	    c = ectoc(expc = get_char());	/* Get the next char	      */

	  case IS_TAB:				/* Generically allowed	      */
	  case '\n':				/*  controlled characters     */
	    break;				/* Make sure we use it	      */

	  case IS_BACKSP:			/* If a backspace:            */
	  case IS_RUBOUT:			/*  or if a Rubout:	      */
	    if (cmd_offset <= 1)		/* Anything to delete?	      */
		return (TRUE);			/* No, just exit	      */
	    --cmd_offset;			/* Back up over the Rubout    */
	    cmd_buff[--cmd_offset] = '\0';	/* Yes, delete last char   */
	    curwp->w_dotp = curline;		/* Reset the line pointer     */
	    curwp->w_doto = curoff;		/*  and the offset	      */
	    n = init_direction;			/* Reset the search direction */
	    strncpy (pat, pat_save, NPAT);	/* Restore the old search str */
	    cmd_reexecute = 0;			/* Start the whole mess over  */
	    goto start_over;			/* Let it take care of itself */

	  /* Presumably a quasi-normal character comes here */

	  default:				/* All other chars    	      */
	    if (c < ' ')			/* Is it printable?	      */
	    {					/* Nope.		      */
		reeat (c);			/* Re-eat the char	      */
		return (TRUE);			/* And return the last status */
	    }
	}  /* Switch */

	/* I guess we got something to search for, so search for it	      */

	pat[cpos++] = c;			/* put the char in the buffer */
	if (cpos >= NPAT)			/* too many chars in string?  */
	{					/* Yup.  Complain about it    */
	    mlwrite("? Search string too long");
	    return(TRUE);			/* Return an error	      */
	}
	pat[cpos] = 0;				/* null terminate the buffer  */
	col = echochar(c,col);			/* Echo the character	      */
	if (!status) {				/* If we lost last time	      */
	    TTputc(BELL);		/* Feep again		      */
	    TTflush();			/* see that the feep feeps    */
	} else					/* Otherwise, we must have won*/
	    if (!(status = checknext(c, pat, n))) /* See if match	      */
		status = scanmore(pat, n);	/*  or find the next match    */
	c = ectoc(expc = get_char());		/* Get the next char	      */
    } /* for {;;} */
}

/*
 * Trivial routine to insure that the next character in the search string is
 * still true to whatever we're pointing to in the buffer.  This routine will
 * not attempt to move the "point" if the match fails, although it will 
 * implicitly move the "point" if we're forward searching, and find a match,
 * since that's the way forward isearch works.
 *
 * If the compare fails, we return FALSE and assume the caller will call
 * scanmore or something.
 */

int checknext (chr, patrn, dir)	/* Check next character in search string */
char	chr;			/* Next char to look for		 */
char	*patrn;			/* The entire search string (incl chr)   */
int	dir;			/* Search direction			 */
{
    register LINE *curline;		/* current line during scan	      */
    register int curoff;		/* position within current line	      */
    register int buffchar;		/* character at current position      */
    int status;				/* how well things go		      */


    /* setup the local scan pointer to current "." */

    curline = curwp->w_dotp;		/* Get the current line structure     */
    curoff  = curwp->w_doto;		/* Get the offset within that line    */

    if (dir > 0)			/* If searching forward		      */
    {
    	if (curoff == llength(curline)) /* If at end of line		      */
    	{
	    curline = lforw(curline);	/* Skip to the next line	      */
	    if (curline == curbp->b_linep)
		return (FALSE);		/* Abort if at end of buffer	      */
	    curoff = 0;			/* Start at the beginning of the line */
	    buffchar = '\n';		/* And say the next char is NL	      */
	} else
	    buffchar = lgetc(curline, curoff++); /* Get the next char	      */
	if (status = eq(buffchar, chr))	/* Is it what we're looking for?      */
	{
	    curwp->w_dotp = curline;	/* Yes, set the buffer's point	      */
	    curwp->w_doto = curoff;	/*  to the matched character	      */
	    curwp->w_flag |= WFMOVE;	/* Say that we've moved		      */
	}
	return (status);		/* And return the status	      */
    } else				/* Else, if reverse search:	      */
	return (match_pat (patrn));	/* See if we're in the right place    */
}

/*
 * This hack will search for the next occurrence of <pat> in the buffer, either
 * forward or backward.  It is called with the status of the prior search
 * attempt, so that it knows not to bother if it didn't work last time.  If
 * we can't find any more matches, "point" is left where it was before.  If
 * we do find a match, "point" will be at the end of the matched string for
 * forward searches and at the beginning of the matched string for reverse
 * searches.
 */
 
int scanmore(patrn, dir)	/* search forward or back for a pattern	      */
char	*patrn;			/* string to scan for			      */
int	dir;			/* direction to search			      */
{
	int	sts;			/* search status		      */

    	if (dir < 0)				/* reverse search?	      */
    	{
		rvstrcpy(tap, patrn);		/* Put reversed string in tap */
		sts = scanner(tap, REVERSE, PTBEG);
	}
	else
		sts = scanner(patrn, FORWARD, PTEND);	/* Nope. Go forward   */

	if (!sts)
	{
		TTputc(BELL);	/* Feep if search fails       */
		TTflush();		/* see that the feep feeps    */
	}

	return(sts);				/* else, don't even try	      */
}

/*
 * The following is a worker subroutine used by the reverse search.  It
 * compares the pattern string with the characters at "." for equality. If
 * any characters mismatch, it will return FALSE.
 *
 * This isn't used for forward searches, because forward searches leave "."
 * at the end of the search string (instead of in front), so all that needs to
 * be done is match the last char input.
 */

int match_pat (patrn)	/* See if the pattern string matches string at "."   */
char	*patrn;		/* String to match to buffer			     */
{
    register int  i;			/* Generic loop index/offset	      */
    register int buffchar;		/* character at current position      */
    register LINE *curline;		/* current line during scan	      */
    register int curoff;		/* position within current line	      */

    /* setup the local scan pointer to current "." */

    curline = curwp->w_dotp;		/* Get the current line structure     */
    curoff  = curwp->w_doto;		/* Get the offset within that line    */

    /* top of per character compare loop: */

    for (i = 0; i < strlen(patrn); i++)	/* Loop for all characters in patrn   */
    {
    	if (curoff == llength(curline)) /* If at end of line		      */
    	{
	    curline = lforw(curline);	/* Skip to the next line	      */
	    curoff = 0;			/* Start at the beginning of the line */
	    if (curline == curbp->b_linep)
		return (FALSE);		/* Abort if at end of buffer	      */
	    buffchar = '\n';		/* And say the next char is NL	      */
	} else
	    buffchar = lgetc(curline, curoff++); /* Get the next char	      */
	if (!eq(buffchar, patrn[i]))	/* Is it what we're looking for?      */
	    return (FALSE);		/* Nope, just punt it then	      */
    }
    return (TRUE);			/* Everything matched? Let's celebrate*/
}

/* Routine to prompt for I-Search string. */

int promptpattern(prompt)
char *prompt;
{
    char tpat[NPAT+20];

    strcpy(tpat, prompt);		/* copy prompt to output string */
    strcat(tpat, " [");			/* build new prompt string */
    expandp(pat, &tpat[strlen(tpat)], NPAT/2);	/* add old pattern */
    strcat(tpat, "]<META>: ");

    /* check to see if we are executing a command line */
    if (!clexec) {
	mlwrite(tpat);
    }
    return(strlen(tpat));
}

/* routine to echo i-search characters */

int echochar(c,col)
int	c;	/* character to be echoed */
int	col;	/* column to be echoed in */
{
    movecursor(term.t_nrow,col);		/* Position the cursor	      */
    if ((c < ' ') || (c == 0x7F))		/* Control character?	      */
    {
	switch (c)				/* Yes, dispatch special cases*/
	{
	  case '\n':				/* Newline		      */
	    TTputc('<');
	    TTputc('N');
	    TTputc('L');
	    TTputc('>');
	    col += 3;
	    break;

	  case '\t':				/* Tab			      */
	    TTputc('<');
	    TTputc('T');
	    TTputc('A');
	    TTputc('B');
	    TTputc('>');
	    col += 4;
	    break;

	  case 0x7F:				/* Rubout:		      */
	    TTputc('^');		/* Output a funny looking     */
	    TTputc('?');		/*  indication of Rubout      */
	    col++;				/* Count the extra char       */
	    break;

	  default:				/* Vanilla control char       */
	    TTputc('^');		/* Yes, output prefix	      */
    	    TTputc(c+0x40);		/* Make it "^X"		      */
	    col++;				/* Count this char	      */
	}
    } else
	TTputc(c);			/* Otherwise, output raw char */
    TTflush();				/* Flush the output	      */
    return(++col);				/* return the new column no   */
}

/*
 * Routine to get the next character from the input stream.  If we're reading
 * from the real terminal, force a screen update before we get the char. 
 * Otherwise, we must be re-executing the command string, so just return the
 * next character.
 */

int get_char ()
{
    int	c;				/* A place to get a character	      */

    /* See if we're re-executing: */

    if (cmd_reexecute >= 0)		/* Is there an offset?		      */
	if ((c = cmd_buff[cmd_reexecute++]) != 0)
	    return (c);			/* Yes, return any character	      */

    /* We're not re-executing (or aren't any more).  Try for a real char      */

    cmd_reexecute = -1;		/* Say we're in real mode again	      */
    update(FALSE);			/* Pretty up the screen		      */
    if (cmd_offset >= CMDBUFLEN-1)	/* If we're getting too big ...	      */
    {
	mlwrite ("? command too long");	/* Complain loudly and bitterly	      */
	return (metac);			/* And force a quit		      */
    }
    c = get1key();		/* Get the next character	      */
    cmd_buff[cmd_offset++] = c; /* Save the char for next time        */
    cmd_buff[cmd_offset] = '\0';/* And terminate the buffer	      */
    return (c);				/* Return the character		      */
}

/*
 * Hacky routine to re-eat a character.  This will save the character to be
 * re-eaten by redirecting the input call to a routine here.  Hack, etc.
 */

/* Come here on the next term.t_getchar call: */

int uneat()
{
    int c;

    term.t_getchar = saved_get_char;	/* restore the routine address	      */
    c = eaten_char;			/* Get the re-eaten char	      */
    eaten_char = -1;			/* Clear the old char		      */
    return(c);				/* and return the last char	      */
}

int reeat(c)
int	c;
{
    if (eaten_char != -1)		/* If we've already been here	      */
	return (NULL);			/* Don't do it again		      */
    eaten_char = c;			/* Else, save the char for later      */
    saved_get_char = term.t_getchar;	/* Save the char get routine	      */
    term.t_getchar = uneat;		/* Replace it with ours		      */
}
#else
isearch()
{
}
#endif
@//E*O*F isearc.c//
chmod u=rw,g=r,o=r isearc.c
 
echo x - line.c
sed 's/^@//' > "line.c" <<'@//E*O*F line.c//'
/*
 * The functions in this file are a general set of line management utilities.
 * They are the only routines that touch the text. They also touch the buffer
 * and window structures, to make sure that the necessary updating gets done.
 * There are routines in this file that handle the kill buffer too. It isn't
 * here for any good reason.
 *
 * Note that this code only updates the dot and mark values in the window list.
 * Since all the code acts on the current window, the buffer that we are
 * editing must be being displayed, which means that "b_nwnd" is non zero,
 * which means that the dot and mark values in the buffer headers are nonsense.
 */

#include	<stdio.h>
#include	"estruc.h"
#include	"edef.h"

#if	MEGAMAX
overlay "line"
#endif

KILL *ykbuf;	/* ptr to current kill buffer chunk being yanked */
int ykboff;	/* offset into that chunk */

/*
 * This routine allocates a block of memory large enough to hold a LINE
 * containing "used" characters. The block is always rounded up a bit. Return
 * a pointer to the new block, or NULL if there isn't any memory left. Print a
 * message in the message line if no space.
 */
LINE	*
lalloc(used)
register int	used;
{
	register LINE	*lp;
	register int	size;
	char *malloc();

	size = (used+NBLOCK-1) & ~(NBLOCK-1);
	if (size == 0)				/* Assume that an empty */
		size = NBLOCK;			/* line is for type-in. */
	if ((lp = (LINE *) malloc(sizeof(LINE)+size)) == NULL) {
		mlwrite("Cannot allocate %d bytes", size);
		return (NULL);
	}
	lp->l_size = size;
	lp->l_used = used;
	return (lp);
}

/*
 * Delete line "lp". Fix all of the links that might point at it (they are
 * moved to offset 0 of the next line. Unlink the line from whatever buffer it
 * might be in. Release the memory. The buffers are updated too; the magic
 * conditions described in the above comments don't hold here.
 */
lfree(lp)
register LINE	*lp;
{
	register BUFFER *bp;
	register WINDOW *wp;

	wp = wheadp;
	while (wp != NULL) {
		if (wp->w_linep == lp)
			wp->w_linep = lp->l_fp;
		if (wp->w_dotp	== lp) {
			wp->w_dotp  = lp->l_fp;
			wp->w_doto  = 0;
		}
		if (wp->w_markp == lp) {
			wp->w_markp = lp->l_fp;
			wp->w_marko = 0;
		}
		wp = wp->w_wndp;
	}
	bp = bheadp;
	while (bp != NULL) {
		if (bp->b_nwnd == 0) {
			if (bp->b_dotp	== lp) {
				bp->b_dotp = lp->l_fp;
				bp->b_doto = 0;
			}
			if (bp->b_markp == lp) {
				bp->b_markp = lp->l_fp;
				bp->b_marko = 0;
			}
		}
		bp = bp->b_bufp;
	}
	lp->l_bp->l_fp = lp->l_fp;
	lp->l_fp->l_bp = lp->l_bp;
	free((char *) lp);
}

/*
 * This routine gets called when a character is changed in place in the current
 * buffer. It updates all of the required flags in the buffer and window
 * system. The flag used is passed as an argument; if the buffer is being
 * displayed in more than 1 window we change EDIT t HARD. Set MODE if the
 * mode line needs to be updated (the "*" has to be set).
 */
lchange(flag)
register int	flag;
{
	register WINDOW *wp;

	if (curbp->b_nwnd != 1) 		/* Ensure hard. 	*/
		flag = WFHARD;
	if ((curbp->b_flag&BFCHG) == 0) {	/* First change, so	*/
		flag |= WFMODE; 		/* update mode lines.	*/
		curbp->b_flag |= BFCHG;
	}
	wp = wheadp;
	while (wp != NULL) {
		if (wp->w_bufp == curbp)
			wp->w_flag |= flag;
		wp = wp->w_wndp;
	}
}

insspace(f, n)	/* insert spaces forward into text */

int f, n;	/* default flag and numeric argument */

{
	linsert(n, ' ');
	backchar(f, n);
}

/*
 * Insert "n" copies of the character "c" at the current location of dot. In
 * the easy case all that happens is the text is stored in the line. In the
 * hard case, the line has to be reallocated. When the window list is updated,
 * take special care; I screwed it up once. You always update dot in the
 * current window. You update mark, and a dot in another window, if it is
 * greater than the place where you did the insert. Return TRUE if all is
 * well, and FALSE on errors.
 */
linsert(n, c)
{
	register char	*cp1;
	register char	*cp2;
	register LINE	*lp1;
	register LINE	*lp2;
	register LINE	*lp3;
	register int	doto;
	register int	i;
	register WINDOW *wp;

/* test */
/*char	mybuf[81] ;
for (i=0; i<80; i++) mybuf[i] = curwp->w_dotp->l_text[i] ;
mybuf[80] = NULL ;
printf("B<%s>\n", mybuf) ;
*/
/*end test */

        if (curbp->b_mode&MDVIEW)       /* don't allow this command if	*/
		return(rdonly());	/* we are in read only mode	*/
	lchange(WFEDIT);
	lp1 = curwp->w_dotp;			/* Current line 	*/
	if (lp1 == curbp->b_linep) {		/* At the end: special	*/
		if (curwp->w_doto != 0) {
			mlwrite("bug: linsert");
			return (FALSE);
		}
		if ((lp2=lalloc(n)) == NULL)	/* Allocate new line	*/
			return (FALSE);
		lp3 = lp1->l_bp;		/* Previous line	*/
		lp3->l_fp = lp2;		/* Link in		*/
		lp2->l_fp = lp1;
		lp1->l_bp = lp2;
		lp2->l_bp = lp3;
		for (i=0; i<n; ++i)
			lp2->l_text[i] = c;
		curwp->w_dotp = lp2;
		curwp->w_doto = n;
		return (TRUE);
	}
	doto = curwp->w_doto;			/* Save for later.	*/
	if (lp1->l_used+n > lp1->l_size) {	/* Hard: reallocate	*/
		if ((lp2=lalloc(lp1->l_used+n)) == NULL)
			return (FALSE);
		cp1 = &lp1->l_text[0];
		cp2 = &lp2->l_text[0];
		while (cp1 != &lp1->l_text[doto])
			*cp2++ = *cp1++;
		cp2 += n;
		while (cp1 != &lp1->l_text[lp1->l_used])
			*cp2++ = *cp1++;
		lp1->l_bp->l_fp = lp2;
		lp2->l_fp = lp1->l_fp;
		lp1->l_fp->l_bp = lp2;
		lp2->l_bp = lp1->l_bp;
		free((char *) lp1);
	} else {				/* Easy: in place	*/
		lp2 = lp1;			/* Pretend new line	*/
		lp2->l_used += n;
		cp2 = &lp1->l_text[lp1->l_used];
		cp1 = cp2-n;
		while (cp1 != &lp1->l_text[doto])
			*--cp2 = *--cp1;
	}
	for (i=0; i<n; ++i)			/* Add the characters	*/
		lp2->l_text[doto+i] = c;
	wp = wheadp;				/* Update windows	*/
	while (wp != NULL) {
		if (wp->w_linep == lp1)
			wp->w_linep = lp2;
		if (wp->w_dotp == lp1) {
			wp->w_dotp = lp2;
			if (wp==curwp || wp->w_doto>doto)
				wp->w_doto += n;
		}
		if (wp->w_markp == lp1) {
			wp->w_markp = lp2;
			if (wp->w_marko > doto)
				wp->w_marko += n;
		}
		wp = wp->w_wndp;
	}

/* test */
/*for (i=0; i<80; i++) mybuf[i] = curwp->w_dotp->l_text[i] ;
mybuf[80] = NULL ;
printf("A<%s>\n", mybuf) ;
*/
/*end test */

	return (TRUE);
}

/*
 * Insert a newline into the buffer at the current location of dot in the
 * current window. The funny ass-backwards way it does things is not a botch;
 * it just makes the last line in the file not a special case. Return TRUE if
 * everything works out and FALSE on error (memory allocation failure). The
 * update of dot and mark is a bit easier then in the above case, because the
 * split forces more updating.
 */
lnewline()
{
	register char	*cp1;
	register char	*cp2;
	register LINE	*lp1;
	register LINE	*lp2;
	register int	doto;
	register WINDOW *wp;

        if (curbp->b_mode&MDVIEW)       /* don't allow this command if	*/
		return(rdonly());	/* we are in read only mode	*/
	lchange(WFHARD);
	lp1  = curwp->w_dotp;			/* Get the address and	*/
	doto = curwp->w_doto;			/* offset of "."	*/
	if ((lp2=lalloc(doto)) == NULL) 	/* New first half line	*/
		return (FALSE);
	cp1 = &lp1->l_text[0];			/* Shuffle text around	*/
	cp2 = &lp2->l_text[0];
	while (cp1 != &lp1->l_text[doto])
		*cp2++ = *cp1++;
	cp2 = &lp1->l_text[0];
	while (cp1 != &lp1->l_text[lp1->l_used])
		*cp2++ = *cp1++;
	lp1->l_used -= doto;
	lp2->l_bp = lp1->l_bp;
	lp1->l_bp = lp2;
	lp2->l_bp->l_fp = lp2;
	lp2->l_fp = lp1;
	wp = wheadp;				/* Windows		*/
	while (wp != NULL) {
		if (wp->w_linep == lp1)
			wp->w_linep = lp2;
		if (wp->w_dotp == lp1) {
			if (wp->w_doto < doto)
				wp->w_dotp = lp2;
			else
				wp->w_doto -= doto;
		}
		if (wp->w_markp == lp1) {
			if (wp->w_marko < doto)
				wp->w_markp = lp2;
			else
				wp->w_marko -= doto;
		}
		wp = wp->w_wndp;
	}
	return (TRUE);
}

/*
 * This function deletes "n" bytes, starting at dot. It understands how do deal
 * with end of lines, etc. It returns TRUE if all of the characters were
 * deleted, and FALSE if they were not (because dot ran into the end of the
 * buffer. The "kflag" is TRUE if the text should be put in the kill buffer.
 */
ldelete(n, kflag)

long n; 	/* # of chars to delete */
int kflag;	/* put killed text in kill buffer flag */

{
	register char	*cp1;
	register char	*cp2;
	register LINE	*dotp;
	register int	doto;
	register int	chunk;
	register WINDOW *wp;

        if (curbp->b_mode&MDVIEW)       /* don't allow this command if	*/
		return(rdonly());	/* we are in read only mode	*/
	while (n != 0) {
		dotp = curwp->w_dotp;
		doto = curwp->w_doto;
		if (dotp == curbp->b_linep)	/* Hit end of buffer.	*/
			return (FALSE);
		chunk = dotp->l_used-doto;	/* Size of chunk.	*/
		if (chunk > n)
			chunk = n;
		if (chunk == 0) {		/* End of line, merge.	*/
			lchange(WFHARD);
			if (ldelnewline() == FALSE
			|| (kflag!=FALSE && kinsert('\n')==FALSE))
				return (FALSE);
			--n;
			continue;
		}
		lchange(WFEDIT);
		cp1 = &dotp->l_text[doto];	/* Scrunch text.	*/
		cp2 = cp1 + chunk;
		if (kflag != FALSE) {		/* Kill?		*/
			while (cp1 != cp2) {
				if (kinsert(*cp1) == FALSE)
					return (FALSE);
				++cp1;
			}
			cp1 = &dotp->l_text[doto];
		}
		while (cp2 != &dotp->l_text[dotp->l_used])
			*cp1++ = *cp2++;
		dotp->l_used -= chunk;
		wp = wheadp;			/* Fix windows		*/
		while (wp != NULL) {
			if (wp->w_dotp==dotp && wp->w_doto>=doto) {
				wp->w_doto -= chunk;
				if (wp->w_doto < doto)
					wp->w_doto = doto;
			}
			if (wp->w_markp==dotp && wp->w_marko>=doto) {
				wp->w_marko -= chunk;
				if (wp->w_marko < doto)
					wp->w_marko = doto;
			}
			wp = wp->w_wndp;
		}
		n -= chunk;
	}
	return (TRUE);
}

/*
 * Delete a newline. Join the current line with the next line. If the next line
 * is the magic header line always return TRUE; merging the last line with the
 * header line can be thought of as always being a successful operation, even
 * if nothing is done, and this makes the kill buffer work "right". Easy cases
 * can be done by shuffling data around. Hard cases require that lines be moved
 * about in memory. Return FALSE on error and TRUE if all looks ok. Called by
 * "ldelete" only.
 */
ldelnewline()
{
	register char	*cp1;
	register char	*cp2;
	register LINE	*lp1;
	register LINE	*lp2;
	register LINE	*lp3;
	register WINDOW *wp;

        if (curbp->b_mode&MDVIEW)       /* don't allow this command if	*/
		return(rdonly());	/* we are in read only mode	*/
	lp1 = curwp->w_dotp;
	lp2 = lp1->l_fp;
	if (lp2 == curbp->b_linep) {		/* At the buffer end.	*/
		if (lp1->l_used == 0)		/* Blank line.		*/
			lfree(lp1);
		return (TRUE);
	}
	if (lp2->l_used <= lp1->l_size-lp1->l_used) {
		cp1 = &lp1->l_text[lp1->l_used];
		cp2 = &lp2->l_text[0];
		while (cp2 != &lp2->l_text[lp2->l_used])
			*cp1++ = *cp2++;
		wp = wheadp;
		while (wp != NULL) {
			if (wp->w_linep == lp2)
				wp->w_linep = lp1;
			if (wp->w_dotp == lp2) {
				wp->w_dotp  = lp1;
				wp->w_doto += lp1->l_used;
			}
			if (wp->w_markp == lp2) {
				wp->w_markp  = lp1;
				wp->w_marko += lp1->l_used;
			}
			wp = wp->w_wndp;
		}
		lp1->l_used += lp2->l_used;
		lp1->l_fp = lp2->l_fp;
		lp2->l_fp->l_bp = lp1;
		free((char *) lp2);
		return (TRUE);
	}
	if ((lp3=lalloc(lp1->l_used+lp2->l_used)) == NULL)
		return (FALSE);
	cp1 = &lp1->l_text[0];
	cp2 = &lp3->l_text[0];
	while (cp1 != &lp1->l_text[lp1->l_used])
		*cp2++ = *cp1++;
	cp1 = &lp2->l_text[0];
	while (cp1 != &lp2->l_text[lp2->l_used])
		*cp2++ = *cp1++;
	lp1->l_bp->l_fp = lp3;
	lp3->l_fp = lp2->l_fp;
	lp2->l_fp->l_bp = lp3;
	lp3->l_bp = lp1->l_bp;
	wp = wheadp;
	while (wp != NULL) {
		if (wp->w_linep==lp1 || wp->w_linep==lp2)
			wp->w_linep = lp3;
		if (wp->w_dotp == lp1)
			wp->w_dotp  = lp3;
		else if (wp->w_dotp == lp2) {
			wp->w_dotp  = lp3;
			wp->w_doto += lp1->l_used;
		}
		if (wp->w_markp == lp1)
			wp->w_markp  = lp3;
		else if (wp->w_markp == lp2) {
			wp->w_markp  = lp3;
			wp->w_marko += lp1->l_used;
		}
		wp = wp->w_wndp;
	}
	free((char *) lp1);
	free((char *) lp2);
	return (TRUE);
}

/*
 * Delete all of the text saved in the kill buffer. Called by commands when a
 * new kill context is being created. The kill buffer array is released, just
 * in case the buffer has grown to immense size. No errors.
 */
kdelete()
{
	KILL *kp;	/* ptr to scan kill buffer chunk list */

	if (kbufh != NULL) {

		/* first, delete all the chunks */
		kbufp = kbufh;
		while (kbufp != NULL) {
			kp = kbufp->d_next;
			free(kbufp);
			kbufp = kp;
		}

		/* and reset all the kill buffer pointers */
		kbufh = kbufp = NULL;
		kused = KBLOCK; 		
	}
}

/*
 * Insert a character to the kill buffer, allocating new chunks as needed.
 * Return TRUE if all is well, and FALSE on errors.
 */

kinsert(c)

int c;		/* character to insert in the kill buffer */

{
	KILL *nchunk;	/* ptr to newly malloced chunk */

	/* check to see if we need a new chunk */
	if (kused >= KBLOCK) {
		if ((nchunk = (KILL *)malloc(sizeof(KILL))) == NULL)
			return(FALSE);
		if (kbufh == NULL)	/* set head ptr if first time */
			kbufh = nchunk;
		if (kbufp != NULL)	/* point the current to this new one */
			kbufp->d_next = nchunk;
		kbufp = nchunk;
		kbufp->d_next = NULL;
		kused = 0;
	}

	/* and now insert the character */
	kbufp->d_chunk[kused++] = c;
	return(TRUE);
}

/*
 * Yank text back from the kill buffer. This is really easy. All of the work
 * is done by the standard insert routines. All you do is run the loop, and
 * check for errors. Bound to "C-Y".
 */
yank(f, n)
{
	register int	c;
	register int	i;
	register char	*sp;	/* pointer into string to insert */
	KILL *kp;		/* pointer into kill buffer */

        if (curbp->b_mode&MDVIEW)       /* don't allow this command if	*/
		return(rdonly());	/* we are in read only mode	*/
	if (n < 0)
		return (FALSE);
	/* make sure there is something to yank */
	if (kbufh == NULL)
		return(TRUE);		/* not an error, just nothing */

	/* for each time.... */
	while (n--) {
		kp = kbufh;
		while (kp != NULL) {
			if (kp->d_next == NULL)
				i = kused;
			else
				i = KBLOCK;
			sp = kp->d_chunk;
			while (i--) {
				if ((c = *sp++) == '\n') {
					if (lnewline() == FALSE)
						return (FALSE);
				} else {
					if (linsert(1, c) == FALSE)
						return (FALSE);
				}
			}
			kp = kp->d_next;
		}
	}
	return (TRUE);
}


@//E*O*F line.c//
chmod u=rw,g=r,o=r line.c
 
echo x - lock.c
sed 's/^@//' > "lock.c" <<'@//E*O*F lock.c//'

/*	LOCK:	File locking command routines for MicroEMACS
		written by Daniel Lawrence
								*/

#include <stdio.h>
#include "estruc.h"
#include "edef.h"

#if	FILOCK
#if	BSD
#include <sys/errno.h>

extern int sys_nerr;		/* number of system error messages defined */
extern char *sys_errlist[];	/* list of message texts */
extern int errno;		/* current error */

char *lname[NLOCKS];	/* names of all locked files */
int numlocks;		/* # of current locks active */

/* lockchk:	check a file for locking and add it to the list */

lockchk(fname)

char *fname;	/* file to check for a lock */

{
	register int i;		/* loop indexes */
	register int status;	/* return status */
	char *undolock();

	/* check to see if that file is already locked here */
	if (numlocks > 0)
		for (i=0; i < numlocks; ++i)
			if (strcmp(fname, lname[i]) == 0)
				return(TRUE);

	/* if we have a full locking table, bitch and leave */
	if (numlocks == NLOCKS) {
		mlwrite("LOCK ERROR: Lock table full");
		return(ABORT);
	}

	/* next, try to lock it */
	status = lock(fname);
	if (status == ABORT)	/* file is locked, no override */
		return(ABORT);
	if (status == FALSE)	/* locked, overriden, dont add to table */
		return(TRUE);

	/* we have now locked it, add it to our table */
	lname[++numlocks - 1] = (char *)malloc(strlen(fname) + 1);
	if (lname[numlocks - 1] == NULL) {	/* malloc failure */
		undolock(fname);		/* free the lock */
		mlwrite("Cannot lock, out of memory");
		--numlocks;
		return(ABORT);
	}

	/* everthing is cool, add it to the table */
	strcpy(lname[numlocks-1], fname);
	return(TRUE);
}

/*	lockrel:	release all the file locks so others may edit */

lockrel()

{
	register int i;		/* loop index */
	register int status;	/* status of locks */
	register int s;		/* status of one unlock */

	status = TRUE;
	if (numlocks > 0)
		for (i=0; i < numlocks; ++i) {
			if ((s = unlock(lname[i])) != TRUE)
				status = s;
			free(lname[i]);
		}
	numlocks = 0;
	return(status);
}

/* lock:	Check and lock a file from access by others
		returns	TRUE = files was not locked and now is
			FALSE = file was locked and overridden
			ABORT = file was locked, abort command
*/

lock(fname)

char *fname;	/* file name to lock */

{
	register char *locker;	/* lock error message */
	register int status;	/* return status */
	char msg[NSTRING];	/* message string */
	char *dolock();

	/* attempt to lock the file */
	locker = dolock(fname);
	if (locker == NULL)	/* we win */
		return(TRUE);

	/* file failed...abort */
	if (strncmp(locker, "LOCK", 4) == 0) {
		lckerror(locker);
		return(ABORT);
	}

	/* someone else has it....override? */
	strcpy(msg, "File in use by ");
	strcat(msg, locker);
	strcat(msg, ", overide?");
	status = mlyesno(msg);		/* ask them */
	if (status == TRUE)
		return(FALSE);
	else
		return(ABORT);
}

/*	unlock:	Unlock a file
		this only warns the user if it fails
							*/

unlock(fname)

char *fname;	/* file to unlock */

{
	register char *locker;	/* undolock return string */
	char *undolock();

	/* unclock and return */
	locker = undolock(fname);
	if (locker == NULL)
		return(TRUE);

	/* report the error and come back */
	lckerror(locker);
	return(FALSE);
}

lckerror(errstr)	/* report a lock error */

char *errstr;		/* lock error string to print out */

{
	char obuf[NSTRING];	/* output buffer for error message */

	strcpy(obuf, errstr);
	strcat(obuf, " - ");
	if (errno < sys_nerr)
		strcat(obuf, sys_errlist[errno]);
	else
		strcat(obuf, "[can not get system error message]");
	mlwrite(obuf);
}
#endif
#else
lckhello()	/* dummy function */
{
}
#endif
@//E*O*F lock.c//
chmod u=rw,g=r,o=r lock.c
 
echo x - uehelp
sed 's/^@//' > "uehelp" <<'@//E*O*F uehelp//'
=>		Cray/Sun MicroEMACS 3.8 Help screens		(9/18/87)
 
M-? or <F8>	Display this help window, ^<r3> to remove it.
M-A or <F9>	Apropos.  List commands related to a key word.
 
 
^V or <r4>        Scroll down		M-< or <r2>	Begining of file
^Z or <r1>        Scroll up		M-> or <r5>	End of file
-----------------------------------------------------------------------
=>		(0) Notation
 
**** the command is not implemented
M-   use the <ESC> key prior to using another key
^A   use control key at the same time as the A key
 
function keys:	<r> right	<R> shifted right	^<r> control right  
		<f> top		<F> shifted top		^<f> control top
-----------------------------------------------------------------------
=>		(1) MOVING THE CURSOR
 
^F      Forward character   M-F <r15>   Forward word	Keypad arrows
^B      Backward character  M-B <r13>   Backward word	are active!
^A <r7> Front of line	    M-G         Goto a line
^E <r9> End of line		
^N      Next line           M-N         Front of paragraph
^P      Previous line       M-P         End of paragraph
-----------------------------------------------------------------------
=>		(2) MOUSE SUPPORT
 
Left button:   cut text.  Press down, move to end of region, release.
Middle button: set mark at mouse cursor.
Right button:  Yank back text from kill buffer to current mouse location.
 
   To move the text cursor, move the mouse cursor to the desired location
and leave it motionless for ~1/5 second.
-----------------------------------------------------------------------
=>		(3) DELETING & INSERTING
 
<--             Delete previous character
^D              Delete next character
^C    <F3>      Insert a space
M-<-- <R13>     Delete previous word
M-D   <R15>     Delete next word
^K              Close (delete) to end of line
-----------------------------------------------------------------------
=>		(3a) MORE DELETING & INSERTING
 
<RETURN>   Insert a newline             <TAB>  Advance to next tab stop
^J         Insert a newline and indent  M-^W   Delete paragraph
^O         Open (insert) line
^W         Delete region between mark (set using M-<spacebar>) and cursor
M-W        Copy region to kill buffer
^X ^O      Delete blank lines around cursor
-----------------------------------------------------------------------
=>		(4) SEARCHING
 
^S		Search forward from cursor position.
^R		Reverse search from cursor position.
^X S  <r6>	Forward incremental search
^X R  <r3>	Reverse incremental search
(note: Terminate ^S/^R search string with ESC ESC.  Terminate an
incremental search at the current location with an arrow key).
-----------------------------------------------------------------------
=>		(5) REPLACING
 
M-R  <F1>   Replace all instances of first typed-in string with second
            typed-in string.  End the string with ESC ESC.
M-^R <F2>   Replace with query.  Answer with:
	^G  cancel			.   exit to entry point
	!   replace the rest		Y    replace & continue
	?   Get a list of options	N   no replacement & continue
-----------------------------------------------------------------------
=>		(6) CAPITALIZING & TRANSPOSING
 
M-U		UPPERCASE word
M-C		Capitalize word		^T	Transpose characters
M-L		lowercase word
^X ^L <F5>	lowercase region
^X ^U <F4>	uppercase region
^Q		Quote next entry, so control codes may be entered into text
-----------------------------------------------------------------------
=>		(7) REGIONS & THE KILL BUFFER
 
M-<spacebar> <r11>	set MARK at current position
^X ^X			eXchange mark and cursor
 
A REGION will then be continuously-defined as the area between the mark and
the current cursor position.  The KILL BUFFER is the text which has been
most recently saved or deleted.
-----------------------------------------------------------------------
=>		(8) COPYING AND MOVING
 
^W  Delete (Wipe) region		M-W <f8> copy region to KILL buffer
^Y  Yankback save buffer at cursor
Generally, the procedure for copying or moving text is:
    1)  Mark a REGION using M-<spacebar> at beginning and cursor at end.
    2)  Delete it (with ^W) or copy it (with M-W) into the KILL buffer.
    3)  Move the cursor to the desired location and yank it back (with ^Y).
-----------------------------------------------------------------------
=>		(9) MODES OF OPERATION
^X M  <F6>	Add mode in buffer              M-M    Add global mode
^X ^M <F7>	Delete mode in buffer           M-^M   Delete global mode
OVER		Replaces (overwrites) rather than inserts characters
**** WRAP	Turns on word wrap (automatic carraige return).
VIEW		Allows viewing file without insertion and deletion.
CMODE		Automatic indenting for C program entry
EXACT/MAGIC	Changes how search and replace commands work (see next page)
-----------------------------------------------------------------------
=>		(10) SEARCH AND REPLACE MODES
 
EXACT	Uppper/lower case is not ignored in searches
MAGIC   Regular pattern matching characters are active
    .   Matches any one character
    *   Matches any any number of the preceding character
    ^   Beginning of line        [ ]   Character class enclosure
    $   End of line              \     Quote next character
-----------------------------------------------------------------------
=>		(11) ON-SCREEN FORMATTING
 
^X F		Set fill column
Mn-<tab>	Set tab spacing to n charecters between tabs stops
M-Q		Format paragraph so that text lies between margins
^X =		Position report -- displays line number, char count,
                                   file size and character under cursor
M-^C		Count words/lines/chars in marked region
-----------------------------------------------------------------------
=>		(12) MULTIPLE WINDOWS
 
Many WINDOWS may be active at once on the screen.  All windows may show
different parts of the same buffer, or each may display a different one.
^X 2 ^<r11> split the current window	^X O ^<r5> Change to next window
^X 0 ^<r3>  delete current window	^X P ^<r2> Change to previous window
^X 1 ^<r6>  delete all other windows    M-^V ^<r1> Page down next window
					M-^Z ^<r4> Page up next window
-----------------------------------------------------------------------
=>		(13) CONTROLLING WINDOWS AND THE SCREEN
 
^X ^  ^<r15> Enlarge current window   ^X W ^<r7>  Resize window to <n> lines
^X ^Z ^<r13> Shrink current window    M-S         Change screen to <n> lines
^X ^N        Move window down         M-T         Change screen to <n> columns
^X ^P        Move window up
M-^L  ^<r9>  Reposition window
^L           Refresh the screen
-----------------------------------------------------------------------
=>		(14) MULTIPLE BUFFERS
A BUFFER is a named area containing a document being edited.  Many buffers
may be activated at once.
^X B  <R7> Switch to another buffer.  <CR> = use just-previous buffer
^X X  <R4> Switch to next buffer in buffer list
M-^N  <R6> Change name of current buffer
^X K  <R9> Delete a non-displayed buffer.
^X ^B <R5> Display buffer directory in a window
-----------------------------------------------------------------------
=>		(15) READING FROM DISK
 
^X ^F <f1>	Find file; read into a new buffer created from filename.
		(This is the usual way to begin editing a new file.)
^X ^R <f2>	Read file into current buffer, erasing its previous contents.
		No new buffer will be created.
^X ^I <f3>	Insert file into current buffer at cursor's location.
^X ^V <f4>	Find a file to make current in VIEW mode
-----------------------------------------------------------------------
=>		(16) SAVING TO DISK
 
^X ^S <f5>	Save current buffer to disk
^X ^W <f6>	Write current buffer to disk
^X N  <f7>	Change file name of current buffer
M-Z		Write out all changed buffers and exit MicroEMACS
 
 
-----------------------------------------------------------------------
=>		(17) ACCESSING THE OPERATING SYSTEM
 
**** ^X !	Send one command to the operating system and return
**** ^X @	Pipe DOS command results to buffer
**** ^X #	Filter buffer through DOS filter program
**** ^X C	Start a new command processor under MicroEMACS
**** ^X D	Suspend MicroEMACS into the background (UNIX BSD4.2 only)
^X ^C	Exit MicroEMACS
-----------------------------------------------------------------------
=>		(18) KEY BINDINGS AND COMMANDS
 
M-K	Bind a key to a command        M-A <F9> Describe a class of commands
M-^K	Unbind a key from a command
^X ?	Describe command bound to a key
M-X	Execute a named (and possibly unbound) command
{Describe-bindings}
	Display a list of all commands and key bindings to a buffer
-----------------------------------------------------------------------
=>		(19) COMMAND EXECUTION
Commands can be specified as command lines in the form:
	<optional repeat count> {command-name} <optional arguments>
{Execute-command-line}	execute a typed in command line
{Execute-buffer}	executes commands lines in a buffer
{Execute-file}		executes command lines from a file
{clear-message-line}	clears the message line during execution
   M-~			clears the change flag for a buffer
-----------------------------------------------------------------------
=>		(20) MACRO EXECUTION
 
^X ( <R2>	Start recording keyboard macro
^X ) <R3>	Stop recording keyboard macro
^X E <R1>	Execute keyboard macro
M-<n> {store-macro}	Start recording named macro
      !endm		Stop recording named macro
{execute-macro-n}	Execute macro n (where n is from 1 to 20)
-----------------------------------------------------------------------
=>		(21) SPECIAL KEYS
 
^G		Cancel current command and return to top level of processing.
^U or <f9>	Universal repeat.  May be followed by an integer (default = 4)
		and repeats the next command that many times.
M-<digit>	Similar to ^U, but for this distributed implementation
		this should only be used for single digits.
@//E*O*F uehelp//
chmod u=rw,g=r,o=r uehelp
 
echo x - uecomp
sed 's/^@//' > "uecomp" <<'@//E*O*F uecomp//'
* select printlog=uelog
*/
* hcc -c -Obcdefi ansi.c
* hcc -c -Obcdefi basic.c
* hcc -c -Obcdefi bind.c
* hcc -c -Obcdefi buffer.c
* hcc -c -Obcdefi displa.c
* hcc -c -Obcdefi file.c
* hcc -c -Obcdefi fileio.c
* hcc -c -Obcdefi input.c
* hcc -c -Obcdefi line.c
* hcc -c -Obcdefi lock.c
* hcc -c -Obcdefi main.c
* hcc -c -Obcdefi random.c
* hcc -c -Obcdefi region.c
* hcc -c -Obcdefi search.c
* hcc -c -Obcdefi spawn.c
* hcc -c -Obcdefi termio.c
* hcc -c -Obcdefi window.c
* hcc -c -Obcdefi word.c
* hcc -c -Obcdefi exec.c
* hcc -c -Obcdefi eval.c
* hcc -c -Obcdefi isearc.c
* hcc -c -Obcdefi io.c
*/
*/ make a library
* destroy templib
* build nl=templib, b=(ansi.o, basic.o, bind.o, buffer.o, displa.o)
* build ol=templib, b=(file.o, fileio.o, input.o, line.o, lock.o, random.o),a
* build ol=templib, b=(region.o, search.o, spawn.o, termio.o),a
* build ol=templib, b=(window.o, word.o, exec.o, eval.o, isearc.o),a
* build ol=templib, b=(io.o),a
*/
*/ link em up
* hcc -Obcdefi main.o -lib templib -lib clibt -o uemacs
@//E*O*F uecomp//
chmod u=rw,g=r,o=r uecomp
 
echo x - uelink
sed 's/^@//' > "uelink" <<'@//E*O*F uelink//'
* select printlog=uelog
*/
* hcc -Obcdefi -c <1>.c
*/ make a library
* destroy templib
* build nl=templib, b=(ansi.o, basic.o, bind.o, buffer.o, displa.o)
* build ol=templib, b=(file.o, fileio.o, input.o, line.o, lock.o, random.o),a
* build ol=templib, b=(region.o, search.o, spawn.o, termio.o),a
* build ol=templib, b=(window.o, word.o, exec.o, eval.o, isearc.o),a
* build ol=templib, b=(io.o),a
*/
*/ link em up
* hcc -Obcdefi main.o -lib templib -lib clibt -o uemacs
@//E*O*F uelink//
chmod u=rw,g=r,o=r uelink
 
exit 0
