BEAV (02/10) ver 1.2 Binary File Editor, new release

Peter Reilley pvr at wang.com
Thu Jun 6 23:25:43 AEST 1991


#! /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 10)."
# Contents:  echo.c format.c ttykbd.c window.c
# Wrapped by pvr at elf on Thu Mar 14 08:16:46 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'\" \(9451 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[];
X
X#include    "lintfunc.dec"
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
END_OF_FILE
if test 9451 -ne `wc -c <'echo.c'`; then
    echo shar: \"'echo.c'\" unpacked with wrong size!
fi
chmod +x 'echo.c'
# end of 'echo.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'\" \(8417 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#include    "lintfunc.dec"
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{FS+0, FS+1, FS+2, FS+3, FS+4, FS+5, FS+6, FS+7, FS+8, FS+9,
XFS+10, FS+11, FS+12, FS+13, FS+14, FS+15, FS+16, FS+17, FS+18, FS+19,
XFS+20, FS+21, FS+22, FS+23, FS+24, FS+25, FS+26, FS+27, FS+28, FS+29,
XFS+30, FS+31, FS+32, FS+33, FS+34, FS+35, FS+36, FS+37, FS+38, FS+39,
XFS+40, FS+41, FS+42, FS+43, FS+44, FS+45, FS+46, FS+47, FS+48, FS+49,
XFS+50, FS+51, FS+52, FS+53, FS+54, FS+55, FS+56, FS+57, FS+58, FS+59,
XFS+60, FS+61, FS+62, FS+63, FS+64, FS+65, FS+66, FS+67, FS+68, FS+69,
XFS+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{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{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{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{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{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{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{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{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{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{FC, FC + 7, FC + 14, FC + 21, FC + 29, FC + 36, FC + 43, FC + 50
X};
X
XROW_FMT octal_16_fmt =
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{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{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{FC, FC + 12, FC + 25, FC + 37
X};
X
XROW_FMT octal_32_fmt =
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{FS, FS + 12, FS + 24, FS + 36, FS + 48, FS + 60, FS + 72
X};
XROW_FMT octal_s_32_fmt =
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{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{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{FC, FC + 6, FC + 12, FC + 18, FC + 25,
X    FC + 31, FC + 37, FC + 43
X};
X
XROW_FMT decimal_16_fmt =
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{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{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{FC, FC + 11, FC + 23, FC + 34
X};
X
XROW_FMT decimal_32_fmt =
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{FS, FS + 11, FS + 22, FS + 33, FS + 44, FS + 55, FS + 66, FS + 77
X};
XROW_FMT decimal_s_32_fmt =
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{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{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{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{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{FC, FC + 5, FC + 10, FC + 15, FC + 21, FC + 26, FC + 31, FC + 36
X};
X
XROW_FMT hex_16_fmt =
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{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{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{FC, FC + 9, FC + 19, FC + 28
X};
X
XROW_FMT hex_32_fmt =
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{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{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{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{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{FC, FC + 17, FC + 34, FC + 51
X};
X
XROW_FMT binary_16_fmt =
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{FS, FS + 17, FS + 34, FS + 51, FS + 68
X};
XROW_FMT binary_s_16_fmt =
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{FC, FC + 33
X};
X
XROW_FMT binary_32_fmt =
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{FS, FS + 33
X};
XROW_FMT binary_s_32_fmt =
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 8417 -ne `wc -c <'format.c'`; then
    echo shar: \"'format.c'\" unpacked with wrong size!
fi
chmod +x 'format.c'
# end of 'format.c'
fi
if test -f 'ttykbd.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ttykbd.c'\"
else
echo shar: Extracting \"'ttykbd.c'\" \(11412 characters\)
sed "s/^X//" >'ttykbd.c' <<'END_OF_FILE'
X/*
X *      Wang PC keyboard handler
X */
X#define LINT_ARGS   1           /* enable lint type checking */
X#include    "def.h"
X
Xextern    char    MSG_sp_key[];
Xextern    char    MSG_byte_shift[];
Xextern    char    MSG_back_char[];
Xextern    char    MSG_quit[];
Xextern    char    MSG_forw_del_char[];
Xextern    char    MSG_toggle_swap[];
Xextern    char    MSG_forw_char[];
Xextern    char    MSG_abort[];
Xextern    char    MSG_ins_self[];
Xextern    char    MSG_back_del_char[];
Xextern    char    MSG_refresh[];
Xextern    char    MSG_forw_line[];
Xextern    char    MSG_back_line[];
Xextern    char    MSG_quote[];
Xextern    char    MSG_recall[];
Xextern    char    MSG_twiddle[];
Xextern    char    MSG_forw_page[];
Xextern    char    MSG_kill_region[];
Xextern    char    MSG_yank[];
Xextern    char    MSG_down_window[];
Xextern    char    MSG_ins_toggle[];
Xextern    char    MSG_display_buffers[];
Xextern    char    MSG_quit[];
Xextern    char    MSG_exit_flush_all[];
Xextern    char    MSG_set_file_name[];
Xextern    char    MSG_file_insert[];
Xextern    char    MSG_buf_size_lock[];
Xextern    char    MSG_flush_all[];
Xextern    char    MSG_down_window[];
Xextern    char    MSG_up_window[];
Xextern    char    MSG_file_read[];
Xextern    char    MSG_file_save[];
Xextern    char    MSG_file_visit[];
Xextern    char    MSG_file_write[];
Xextern    char    MSG_swap_dot_and_mark[];
Xextern    char    MSG_shrink_window[];
Xextern    char    MSG_display_position[];
Xextern    char    MSG_start_macro[];
Xextern    char    MSG_end_macro[];
Xextern    char    MSG_help[];
Xextern    char    MSG_only_window[];
Xextern    char    MSG_split_window[];
Xextern    char    MSG_use_buffer[];
Xextern    char    MSG_spawn_cli[];
Xextern    char    MSG_execute_macro[];
Xextern    char    MSG_goto_line[];
Xextern    char    MSG_ins_unit[];
Xextern    char    MSG_kill_buffer[];
Xextern    char    MSG_load_bindings[];
Xextern    char    MSG_forw_window[];
Xextern    char    MSG_back_window[];
Xextern    char    MSG_view_file[];
Xextern    char    MSG_enlarge_window[];
Xextern    char    MSG_ascii_mode[];
Xextern    char    MSG_binary_mode[];
Xextern    char    MSG_buffer_name[];
Xextern    char    MSG_decimal_mode[];
Xextern    char    MSG_ebcdic_mode[];
Xextern    char    MSG_hex_mode[];
Xextern    char    MSG_back_del_unit[];
Xextern    char    MSG_octal_mode[];
Xextern    char    MSG_display_version[];
Xextern    char    MSG_unit_size1[];
Xextern    char    MSG_unit_size2[];
Xextern    char    MSG_unit_size4[];
Xextern    char    MSG_reposition_window[];
Xextern    char    MSG_set_mark[];
Xextern    char    MSG_goto_eob[];
Xextern    char    MSG_goto_bob[];
Xextern    char    MSG_next_buff[];
Xextern    char    MSG_prev_buff[];
Xextern    char    MSG_query_replace[];
Xextern    char    MSG_display_bindings[];
Xextern    char    MSG_auto_save[];
Xextern    char    MSG_back_unit[];
Xextern    char    MSG_compare[];
Xextern    char    MSG_forw_del_unit[];
Xextern    char    MSG_forw_unit[];
Xextern    char    MSG_link_windows[];
Xextern    char    MSG_print[];
Xextern    char    MSG_back_search[];
Xextern    char    MSG_forw_search[];
Xextern    char    MSG_back_page[];
Xextern    char    MSG_copy_region[];
Xextern    char    MSG_extended_command[];
Xextern    char    MSG_up_window[];
Xextern    char    MSG_search_again[];
Xextern    char    MSG_bind_to_key[];
Xextern    char    MSG_file_visit_split[];
Xextern    char    MSG_yank_buffer[];
Xextern    char    MSG_save_region[];
Xextern    char    MSG_use_buffer_split[];
Xextern    char    MSG_no_f_tb[];
X
X#include    "lintfunc.dec"
X#define SPECIAL 0x1F            /* Special keys         */
X
Xtypedef    struct  key_name_array 
X    {
X    int     key_code;
X    char    *func_name_str;
X    char    *key_name_str;
X    }   KEY_NAME_ARRAY; 
X#if MSDOS
Xextern  bool    wang_pc;
Xextern  bool    ibm_pc;
X#endif
X/*
X * The keyboard's special characters, those things that are prefixed with
X * a 0x1F, are placed into the keyboard tables as KCTRL || 0x80 || x, for some
X * x, i.e. they have both the control and 0x80 bits set, so they won't conflict
X * with anything else on the keyboard.
X */
X
X
X/*
X * Names for the keys with basic keycode
X * between KFIRST and KLAST (inclusive). This is used by
X * the key name routine in "kbd.c".
X */
X#if MSDOS
XKEY_NAME_ARRAY wang_keys[] =
X{
X    KCTRL | 0x80, MSG_bind_to_key, "Indent", 
X/*  KCTRL | 0x81, NULL, "Page", */
X    KCTRL | 0x82, MSG_reposition_window, "Center",
X/*  KCTRL | 0x83, NULL, "DecTab", */
X/*  KCTRL | 0x84, NULL, "Format", */
X/*  KCTRL | 0x85, NULL, "Merge", */
X/*  KCTRL | 0x86, NULL, "Note", */
X    KCTRL | 0x87, MSG_set_mark, "Stop",
X    KCTRL | 0x88, MSG_forw_search, "Search", 
X    KCTRL | 0x89, MSG_yank, "Replace",
X    KCTRL | 0x8A, MSG_copy_region, "Copy",
X    KCTRL | 0x8B, MSG_kill_region, "Move",
X    KCTRL | 0x8C, MSG_extended_command, "Command",
X    KCTRL | 0x8D, MSG_forw_window, "UpDown",
X/*  KCTRL | 0x8E, NULL, "BlankKey", */
X    KCTRL | 0x8F, MSG_goto_line, "GoTo",
X/*  KCTRL | 0x90, NULL, "Sh-Indent", */
X/*  KCTRL | 0x91, NULL, "Sh-Page", */
X/*  KCTRL | 0x92, NULL, "Sh-Center", */
X/*  KCTRL | 0x93, NULL, "Sh-DecTab", */
X/*  KCTRL | 0x94, NULL, "Sh-Format", */
X/*  KCTRL | 0x95, NULL, "Sh-Merge", */
X/*  KCTRL | 0x96, NULL, "Sh-Note", */
X/*  KCTRL | 0x97, NULL, "Sh-Stop", */
X    KCTRL | 0x98, MSG_search_again, "Sh-Search",
X    KCTRL | 0x99, MSG_query_replace, "Sh-Replace",
X/*  KCTRL | 0x9A, NULL, "Sh-Copy", */
X/*  KCTRL | 0x9B, NULL, "Sh-Move", */
X/*  KCTRL | 0x9C, NULL, "Sh-Command", */
X    KCTRL | 0x9D, MSG_split_window, "Sh-UpDown",
X/*  KCTRL | 0x9E, NULL, "Sh-BlankKey", */
X/*  KCTRL | 0x9F, NULL, "Sh-GoTo", */
X    KCTRL | 0xC0, MSG_back_line, "North",
X    KCTRL | 0xC1, MSG_forw_char, "East",
X    KCTRL | 0xC2, MSG_forw_line, "South",
X    KCTRL | 0xC3, MSG_back_char, "West",
X    KCTRL | 0xC4, MSG_byte_shift, "Home",
X/*  KCTRL | 0xC5, NULL, "Execute", */
X    KCTRL | 0xC6, MSG_ins_toggle, "Insert",
X    KCTRL | 0xC7, MSG_forw_del_char, "Delete",
X    KCTRL | 0xC8, MSG_back_page, "PrevPage",
X    KCTRL | 0xC9, MSG_forw_page, "NextPage",
X/*  KCTRL | 0xCB, NULL, "Erase", */
X/*  KCTRL | 0xCD, NULL, "BackTab", */
X/*  KCTRL | 0xD0, NULL, "Sh-North", */
X    KCTRL | 0xD1, MSG_forw_unit, "Sh-East",
X/*  KCTRL | 0xD2, NULL, "Sh-South", */
X    KCTRL | 0xD3, MSG_back_unit, "Sh-West",
X/*  KCTRL | 0xD4, NULL, "Sh-Home", */
X    KCTRL | 0xD5, MSG_execute_macro, "Sh-Execute",
X/*  KCTRL | 0xD6, NULL, "Sh-Insert", */
X    KCTRL | 0xD7, MSG_forw_del_unit, "Sh-Delete",
X    KCTRL | 0xD8, MSG_goto_bob, "Sh-PrevPage",
X    KCTRL | 0xD9, MSG_goto_eob, "Sh-NextPage",
X/*  KCTRL | 0xDB, NULL, "Sh-Erase", */
X/*  KCTRL | 0xDC, NULL, "Sh-Tab", */
X/*  KCTRL | 0xDD, NULL, "Sh-BackTab", */
X    KCTRL | 0xE0, MSG_abort, "Cancel",
X    KMETA | KCTRL | 0xE0, MSG_abort, "Cancel",
X    KCTLX | KCTRL | 0xE0, MSG_abort, "Ctl-X Cancel",
X    KCTRL | 0xE1, MSG_display_bindings, "Help",
X/*  KCTRL | 0xE2, NULL, "Glossary", */
X    KCTRL | 0xE3, MSG_print, "Print",
X    KCTRL | 0xF1, MSG_help, "Sh-Help",
X/*  KCTRL | 0xF2, NULL, "Sh-Glossary", */
X/*  KCTRL | 0xF3, NULL, "Sh-Print", */
X    0, NULL, NULL
X    };
X
XKEY_NAME_ARRAY  ibm_keys[] =
X    {
X    KCTLX | 0x80 | 0x3B, MSG_display_bindings, "F1",
X    KCTLX | 0x80 | 0x3C, MSG_set_mark, "F2",
X    KCTLX | 0x80 | 0x3D, MSG_forw_search, "F3",
X    KCTLX | 0x80 | 0x3E, MSG_search_again, "F4",
X    KCTLX | 0x80 | 0x3F, MSG_query_replace, "F5",
X    KCTLX | 0x80 | 0x40, MSG_yank, "F6",
X    KCTLX | 0x80 | 0x41, MSG_copy_region, "F7",
X    KCTLX | 0x80 | 0x42, MSG_kill_region, "F8",
X    KCTLX | 0x80 | 0x43, MSG_goto_line, "F9",
X    KCTLX | 0x80 | 0x44, MSG_abort, "F10",
X    KCTLX | 0x80 | 0x54, MSG_help, "Sh-F1",
X    KCTLX | 0x80 | 0x55, MSG_file_read, "Sh-F2",
X    KCTLX | 0x80 | 0x56, MSG_file_save, "Sh-F3",
X    KCTLX | 0x80 | 0x57, MSG_file_visit, "Sh-F4",
X    KCTLX | 0x80 | 0x58, MSG_file_write, "Sh-F5",
X    KCTLX | 0x80 | 0x59, MSG_flush_all, "Sh-F6",
X    KCTLX | 0x80 | 0x5A, MSG_set_file_name, "Sh-F7",
X    KCTLX | 0x80 | 0x5B, MSG_file_insert, "Sh-F8",
X    KCTLX | 0x80 | 0x5C, MSG_exit_flush_all, "Sh-F9",
X    KCTLX | 0x80 | 0x5D, MSG_quit, "Sh-F10",
X    KCTLX | 0x80 | 0x5E, MSG_display_buffers, "Ctl-F1",
X    KCTLX | 0x80 | 0x5F, MSG_use_buffer, "Ctl-F2",
X    KCTLX | 0x80 | 0x60, MSG_kill_buffer, "Ctl-F3",
X    KCTLX | 0x80 | 0x61, MSG_next_buff, "Ctl-F4",
X    KCTLX | 0x80 | 0x62, MSG_prev_buff, "Ctl-F5",
X    KCTLX | 0x80 | 0x63, MSG_yank_buffer, "Ctl-F6",
X    KCTLX | 0x80 | 0x64, MSG_set_file_name, "Ctl-F7",
X    KCTLX | 0x80 | 0x65, MSG_file_insert, "Ctl-F8",
X    KCTLX | 0x80 | 0x66, MSG_exit_flush_all, "Ctl-F9",
X    KCTLX | 0x80 | 0x67, MSG_quit, "Ctl-F10",
X    KCTLX | 0x80 | 0x48, MSG_back_line, "North",
X    KCTLX | 0x80 | 0x4D, MSG_forw_char, "East",
X    KCTLX | 0x80 | 0x74, MSG_forw_unit, "Ctl-East",
X    KCTLX | 0x80 | 0x50, MSG_forw_line, "South",
X    KCTLX | 0x80 | 0x4B, MSG_back_char, "West",
X    KCTLX | 0x80 | 0x73, MSG_back_unit, "Ctl-West",
X    KCTLX | 0x80 | 0x49, MSG_back_page, "PageDown",
X    KCTLX | 0x80 | 0x47, MSG_goto_bob, "Home",
X    KCTLX | 0x80 | 0x51, MSG_forw_page, "PageUp",
X    KCTLX | 0x80 | 0x4F, MSG_goto_eob, "End",
X    KCTLX | 0x80 | 0x52, MSG_ins_toggle, "Insert",
X    KCTLX | 0x80 | 0x53, MSG_forw_del_char, "Delete",
X    KCTLX | 0x80 | 0x76, MSG_forw_window, "Ctl-PageDown",
X    KCTLX | 0x80 | 0x84, MSG_back_window, "Ctl-PageUp",
X    KCTLX | 0x80 | 0x72, MSG_print, "Ctl-Print",
X    KCTLX | 0x80 | 0x0F, MSG_forw_unit, "Sh-Tab",
X    0, NULL, NULL
X    };
X#endif
X/*
X * Read in a key, doing the low level mapping
X * of ASCII code to 11 bit code.  This level deals with
X * mapping the special keys into their spots in the C1
X * control area.  The C0 controls go right through, and
X * get remapped by "getkey".
X */
Xstatic int  unkey = KRANDOM;    /* jam - for ungetkey */
Xvoid ungetkey (k)
X{
X    unkey = k;
X}
X
Xint     getkbd ()
X{
X    register int    c;
X
X    if (unkey == KRANDOM)       /* jam */
X        c = ttgetc ();
X    else
X        {
X        c = unkey;
X        unkey = KRANDOM;
X        }
X    if (c == SPECIAL)
X        {
X        c = ttgetc ();
X        if ((c == 0xCD) || (c == 0xDD))/* Backtab is meta */
X            return (METACH);
X        return (c | KCTRL);
X        }
X    if (c == 0)
X        {
X        c = ttgetc ();
X        return (c | 0x80 | KCTLX);
X        }
X    return (c);
X}
X
X
X/*
X * Terminal specific keymap initialization.
X * Attach the special keys to the appropriate built
X * in functions.
X * As is the case of all the keymap routines, errors
X * are very fatal.
X */
Xvoid ttykeymapinit ()
X{
XKEY_NAME_ARRAY  *ptr;
Xint     i;
Xchar    buf[60];
X#if MSDOS
X    if (wang_pc)
X        ptr = wang_keys;
X
X    if (ibm_pc)
X        ptr = ibm_keys;
X
X    if (!wang_pc && !ibm_pc)
X        return;
X
X    i = 0;
X    while (ptr -> key_code != 0)
X        {
X        if (ptr -> func_name_str != NULL)
X            keydup (ptr -> key_code, ptr -> func_name_str);
X        ptr++;
X        i++;
X        }
X    sprintf (buf, MSG_sp_key, i);
X    writ_echo (buf);
X#endif
X}
X/* 
X*   Search key name array for given key code.
X*   return pointer to key name.
X*/
Xchar    *keystrings (key)
Xint     key;
X    {
X#if MSDOS
X    KEY_NAME_ARRAY  *ptr;
X    
X    if (wang_pc)
X        ptr = wang_keys;
X
X    if (ibm_pc)
X        ptr = ibm_keys;
X
X    if (!wang_pc && !ibm_pc)
X        return(NULL);
X
X    while (ptr -> key_code != 0)
X        {
X        if (key == ptr -> key_code)
X            {
X            return (ptr -> key_name_str);
X            }
X        ptr++;
X        }
X#endif
X    return (NULL);
X    }
END_OF_FILE
if test 11412 -ne `wc -c <'ttykbd.c'`; then
    echo shar: \"'ttykbd.c'\" unpacked with wrong size!
fi
chmod +x 'ttykbd.c'
# end of 'ttykbd.c'
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'\" \(12083 characters\)
sed "s/^X//" >'window.c' <<'END_OF_FILE'
X/*
X*       Window handling.
X*/
X#include    "def.h"
X
Xchar    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#include    "lintfunc.dec"
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*/
Xchar    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*/
Xchar    mvupwind (f, n, k)
X    int    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*/
Xchar    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
Xdelwind()
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
X        writ_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 12083 -ne `wc -c <'window.c'`; then
    echo shar: \"'window.c'\" unpacked with wrong size!
fi
chmod +x 'window.c'
# end of 'window.c'
fi
echo shar: End of archive 2 \(of 10\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 10 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 at wang.com <<<<<<<<<<<<<<<<<<<<<<<
                     Well, that about says it.



More information about the Alt.sources mailing list