home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-21 | 53.8 KB | 1,894 lines |
- Newsgroups: comp.sources.misc
- From: pvr@wang.com (Peter Reilley)
- Subject: v26i042: beav - Binary file editor and viewer, v1.32, Part06/09
- Message-ID: <1991Nov21.230311.1795@sparky.imd.sterling.com>
- X-Md4-Signature: bcdbfdfae60a165cb15130d717e26304
- Date: Thu, 21 Nov 1991 23:03:11 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: pvr@wang.com (Peter Reilley)
- Posting-number: Volume 26, Issue 42
- Archive-name: beav/part06
- Environment: UNIX, AIX, MS-DOS, AMIGA
- Supersedes: beav: Volume 22, Issue 10-18
-
- #! /bin/sh
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # Contents: amibeav.lnk amiga.c line.c symbol.c ttyio.c
- # Wrapped by kent@sparky on Thu Nov 21 16:47:01 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 6 (of 9)."'
- if test -f 'amibeav.lnk' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'amibeav.lnk'\"
- else
- echo shar: Extracting \"'amibeav.lnk'\" \(281 characters\)
- sed "s/^X//" >'amibeav.lnk' <<'END_OF_FILE'
- XFROM LIB:c.o+
- Xamiga.o basic.o ebcdic.o fileio.o region.o text.o wangpc.o
- Xbuffer.o echo.o main.o search.o tty.o window.o
- Xcinfo.o extend.o kbd.o spawn.o ttyio.o termio.o tcap.o word.o
- Xdisplay.o file.o line.o random.o symbol.o ttykbd.o format.o
- XTO "beav"
- XLIB LIB:lc.lib LIB:amiga.lib
- END_OF_FILE
- if test 281 -ne `wc -c <'amibeav.lnk'`; then
- echo shar: \"'amibeav.lnk'\" unpacked with wrong size!
- fi
- # end of 'amibeav.lnk'
- fi
- if test -f 'amiga.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'amiga.c'\"
- else
- echo shar: Extracting \"'amiga.c'\" \(13875 characters\)
- sed "s/^X//" >'amiga.c' <<'END_OF_FILE'
- X/* -*-C-*-
- X *
- X * Module : amiga.c
- X *
- X * Author : Simon J Raybould. (sie@fulcrum.bt.co.uk).
- X *
- X * Date : Tuesday 11th June 1991.
- X *
- X * Desc : amiga specifics for beav binary editor.
- X *
- X *
- X * This file is public domain and you can do what you want with it, even roll
- X * it up into a ball and toss it for your cat to chase. I accept no
- X * resposibility for it being unfit for any purpose (including a feline toy).
- X * Any bugs you can either fix them yourself or tell me and I'll do it.
- X * Any major fixes should be reported to me and I will inform the main keeper
- X * of beav to be sure they are fixed in the next release. This only applies to
- X * bugs in THIS FILE or in AMIGA sections of other files. Any other bugs to the
- X * original author.
- X *
- X * SJR - 25.Aug.91
- X *
- X *
- X */
- X
- X#ifdef AMIGA
- X
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <errno.h>
- X#include <signal.h>
- X#include <libraries/dosextens.h>
- X#include <exec/memory.h>
- X#include <intuition/intuition.h>
- X
- X#include "def.h"
- X
- X#define SCRBUFSIZ 1024 /* buffered screen io */
- X
- Xstruct NewWindow nw = {
- X 0, 0, 640,256, -1,-1, NULL,
- X WINDOWDEPTH|WINDOWDRAG|SMART_REFRESH|ACTIVATE|BORDERLESS,
- X NULL, NULL,
- X "BEAV V1.32 Amiga Port by S.J.Raybould (sie@fulcrum.bt.co.uk) Sep 1991",
- X NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN
- X};
- X
- X/* Opens/allocations we'll need to clean up */
- Xstruct Library *IntuitionBase = NULL;
- Xstruct Window *win = NULL, *OpenWindow();
- Xstruct IOStdReq *writeReq = NULL; /* I/O request block pointer */
- Xstruct MsgPort *writePort = NULL; /* replyport for writes */
- X
- Xstruct IOStdReq *readReq = NULL; /* I/O request block pointer */
- Xstruct MsgPort *readPort = NULL; /* replyport for reads */
- X
- Xstruct MsgPort *CreatePort();
- XBOOL OpenedConsole = FALSE;
- XUBYTE ibuf;
- XBYTE OpenConsole();
- Xvoid CloseConsole(), QueueRead(), ConWrite();
- X
- X
- Xint nrow; /* Terminal size, rows. */
- Xint ncol; /* Terminal size, columns. */
- X#ifdef CRAP
- Xint tceeol = 3; /* Costs. */
- X#endif CRAP
- X
- Xint kbdpoll; /* in O_NDELAY mode */
- Xint kbdqp; /* there is a char in kbdq */
- X
- Xchar scrbuf[SCRBUFSIZ]; /* buffered screen io */
- Xshort scrbufpos = 0; /* current write position */
- X
- X/* CODE TO REPLACE STUFF IN termio.c */
- X
- X/*
- X * This function gets called just before we go back home to the command
- X * interpreter. On VMS it puts the terminal back in a reasonable state.
- X * Another no-operation on CPM.
- X */
- Xvoid
- Xttclose()
- X{
- X /* Put TTY back in sesible state */
- X if(!(CheckIO(readReq))) AbortIO(readReq);
- X WaitIO(readReq);
- X if(OpenedConsole) CloseConsole(writeReq);
- X if(readReq) DeleteExtIO(readReq);
- X if(readPort) DeletePort(readPort);
- X if(writeReq) DeleteExtIO(writeReq);
- X if(writePort) DeletePort(writePort);
- X if(win) CloseWindow(win);
- X if(IntuitionBase) CloseLibrary(IntuitionBase);
- X}
- X
- X/*
- X * Flush terminal buffer. Does real work where the terminal output is buffered
- X * up. A no-operation on systems where byte at a time terminal I/O is done.
- X */
- Xvoid
- Xttflush()
- X{
- X if(scrbufpos>0) {
- X ConWrite(writeReq, scrbuf, scrbufpos);
- X scrbufpos = 0;
- X }
- X}
- X
- X/*
- X * Write a character to the display. On VMS, terminal output is buffered, and
- X * we just put the characters in the big array, after checking for overflow.
- X * On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
- X * MS-DOS (use the very very raw console output routine).
- X */
- Xvoid ttputc(c)
- X{
- X if(scrbufpos < SCRBUFSIZ)
- X scrbuf[scrbufpos++] = c;
- X else {
- X ConWrite(writeReq, scrbuf, scrbufpos);
- X scrbufpos = 0;
- X scrbuf[scrbufpos++] = c;
- X }
- X}
- X
- Xvoid
- Xttputs(char *str)
- X{
- X while(*str)
- X ttputc(*str++);
- X}
- X
- X/*
- X * Read a character from the terminal, performing no editing and doing no echo
- X * at all. More complex in VMS that almost anyplace else, which figures. Very
- X * simple on CPM, because the system can do exactly what you want.
- X */
- Xttgetc()
- X{
- X char c, ConGetChar();
- X static char Buffer[8], ri=0, wi=0;
- X
- X if(kbdqp)
- X kbdqp = FALSE;
- X /* If we stil have chars from last time, return them */
- X if(ri<wi)
- X return Buffer[ri++]&0x7f;
- X
- X /* Else empty the buffer and start a new read */
- X ri=wi=0;
- X c = ConGetChar(readPort, &ibuf);
- X /*
- X * Attempt some translations !
- X * This is the place to extend, if you wish to add some more.
- X * SEE RKM L&D 1.3 pg 654 for more info.
- X */
- X if((unsigned char)c == (unsigned char)0x9b) { /* ANSI esc start */
- X c = ConGetChar(readPort, &ibuf);
- X switch(c) {
- X case 'A': /* UP */
- X Buffer[wi++] = 0x10; /* ^P */
- X break;
- X case 'B': /* DOWN */
- X Buffer[wi++] = 0x0e; /* ^N */
- X break;
- X case 'C': /* RIGHT */
- X Buffer[wi++] = 0x06; /* ^F */
- X break;
- X case 'D': /* LEFT */
- X Buffer[wi++] = 0x02; /* ^B */
- X break;
- X case '0': /* F1 */
- X ConGetChar(readPort, &ibuf); /* discard tilde */
- X Buffer[wi++] = 0x1b; /* HELP = "ESC ?" */
- X Buffer[wi++] = '?';
- X break;
- X case '1': /* F2 or SHIFTED function key */
- X c = ConGetChar(readPort, &ibuf); /* Get next char to see if it's a tilde */
- X switch(c) {
- X case '~': /* was definately F2 */
- X Buffer[wi++] = 0x1b; /* mark-set = "ESC ." */
- X Buffer[wi++] = '.';
- X break;
- X case '0': /* SHIFTED F1 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* binding-for-key = "Ctl-X ?" */
- X Buffer[wi++] = '?';
- X break;
- X case '1': /* SHIFTED F2 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* file-read = "Ctl-X Ctl-R" */
- X Buffer[wi++] = 0x12;
- X break;
- X case '2': /* SHIFTED F3 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* file-save = "Ctl-X Ctl-S" */
- X Buffer[wi++] = 0x13;
- X break;
- X case '3': /* SHIFTED F4 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* file-visit = "Ctl-X Ctl-V" */
- X Buffer[wi++] = 0x16;
- X break;
- X case '4': /* SHIFTED F5 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* file-write = "Ctl-X Ctl-W" */
- X Buffer[wi++] = 0x17;
- X break;
- X case '5': /* SHIFTED F6 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* save-all-buffers = "Ctl-X return" */
- X Buffer[wi++] = '\r';
- X break;
- X case '6': /* SHIFTED F7 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* buffer-set-file-name = "Ctl-X Ctl-F" */
- X Buffer[wi++] = 0x06;
- X break;
- X case '7': /* SHIFTED F8 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* insert-file = "Ctl-X TAB" */
- X Buffer[wi++] = '\t';
- X break;
- X case '8': /* SHIFTED F9 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* quit-save-all = "Ctl-X Ctl-E" */
- X Buffer[wi++] = 0x05;
- X break;
- X case '9': /* SHIFTED F10 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x03; /* quit-no-save = "Ctl-C" */
- X break;
- X }
- X break;
- X case '2': /* F3 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x1b; /* search-forv = "ESC s" */
- X Buffer[wi++] = 's';
- X break;
- X case '3': /* F4 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x1b; /* search-again = "ESC t" */
- X Buffer[wi++] = 't';
- X break;
- X case '4': /* F5 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x1b; /* replace = "ESC %" */
- X Buffer[wi++] = '%';
- X break;
- X case '5': /* F6 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x19; /* yank = "Ctl-Y" */
- X break;
- X case '6': /* F7 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x1b; /* copy-mark-to-cursor = "ESC w" */
- X Buffer[wi++] = 'w';
- X break;
- X case '7': /* F8 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x17; /* delete-mark-to-cursor = "Ctl-W" */
- X break;
- X case '8': /* F9 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x18; /* move-to-byte = "Ctl-X G" */
- X Buffer[wi++] = 'G';
- X break;
- X case '9': /* F10 */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x07; /* abort-cmd = "Ctl-G" */
- X break;
- X case '?': /* HELP */
- X ConGetChar(readPort, &ibuf); /* Discard the tilde */
- X Buffer[wi++] = 0x1b; /* help = "ESC ?" */
- X Buffer[wi++] = '?';
- X break;
- X }
- X return Buffer[ri++]&0x7f;
- X } else /* not an ANSI sequence */
- X return c&0x7f;
- X}
- X
- X/*
- X * This function is called once to set up the terminal device streams.
- X * On VMS, it translates TT until it finds the terminal, then assigns
- X * a channel to it and sets it raw. On CPM it is a no-op.
- X */
- X
- Xvoid ttopen()
- X{
- X int Sig;
- X ULONG conreadsig, windowsig;
- X BYTE error;
- X struct Screen Screen; /* get a copy of WBENCHSCREEN in here */
- X
- X
- X if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0))) {
- X printf("Can't open intuition\n");
- X ttclose();
- X exit(10);
- X }
- X /* Create reply port and io block for writing to console */
- X if(!(writePort = CreatePort("LARN.console.write",0))) {
- X printf("Can't create write port\n");
- X ttclose();
- X exit(10);
- X }
- X if(!(writeReq = (struct IOStdReq *)
- X CreateExtIO(writePort,(LONG)sizeof(struct IOStdReq)))) {
- X printf("Can't create write request\n");
- X ttclose();
- X exit(10);
- X }
- X /* Create reply port and io block for reading from console */
- X if(!(readPort = CreatePort("LARN.console.read",0))) {
- X printf("Can't create read port\n");
- X ttclose();
- X exit(10);
- X }
- X if(!(readReq = (struct IOStdReq *)
- X CreateExtIO(readPort,(LONG)sizeof(struct IOStdReq)))) {
- X printf("Can't create read request\n");
- X ttclose();
- X exit(10);
- X }
- X if(!GetScreenData(&Screen, sizeof(struct Screen), WBENCHSCREEN, NULL)) {
- X printf("Can't get screen size\n");
- X ttclose();
- X exit(10);
- X }
- X nrow = Screen.Height/8-3;
- X ncol = Screen.Width/8;
- X nw.Height = Screen.Height;
- X nw.Width = Screen.Width;
- X
- X /* don't allow a larger number of rows than we can handle */
- X if (nrow > NROW)
- X nrow = NROW;
- X /* don't allow a larger number of cols than we can handle */
- X if (ncol > NCOL)
- X ncol = NCOL;
- X
- X /* Open a window */
- X if(!(win = OpenWindow(&nw))) {
- X printf("Can't open window\n");
- X ttclose();
- X exit(10);
- X }
- X /* Now, attach a console to the window */
- X if(error = OpenConsole(writeReq,readReq,win)) {
- X printf("Can't open console.device\n");
- X ttclose();
- X exit(10);
- X } else
- X OpenedConsole = TRUE;
- X
- X QueueRead(readReq,&ibuf); /* send the first console read request */
- X conreadsig = 1 << readPort->mp_SigBit;
- X windowsig = 1 << win->UserPort->mp_SigBit;
- X for(Sig=0; Sig<NSIG; Sig++)
- X signal(Sig, SIG_IGN);
- X
- X kbdpoll = FALSE;
- X /* on all screens we are not sure of the initial position of the cursor */
- X ttrow = 999;
- X ttcol = 999;
- X}
- X
- X/* END OF TERMIO REPLACEMENT CODE */
- X
- X/* Attach console device to an open Intuition window.
- X * This function returns a value of 0 if the console
- X * device opened correctly and a nonzero value (the error
- X * returned from OpenDevice) if there was an error.
- X */
- XBYTE OpenConsole(writereq, readreq, window)
- Xstruct IOStdReq *writereq;
- Xstruct IOStdReq *readreq;
- Xstruct Window *window;
- X{
- X BYTE error;
- X
- X writereq->io_Data = (APTR) window;
- X writereq->io_Length = sizeof(struct Window);
- X error = OpenDevice("console.device", 0, writereq, 0);
- X readreq->io_Device = writereq->io_Device; /* clone required parts */
- X readreq->io_Unit = writereq->io_Unit;
- X return(error);
- X}
- X
- Xvoid CloseConsole(struct IOStdReq *writereq)
- X{
- X CloseDevice(writereq);
- X}
- X
- X/* Output a single character to a specified console
- X */
- Xvoid ConPutChar(struct IOStdReq *writereq, UBYTE character)
- X{
- X writereq->io_Command = CMD_WRITE;
- X writereq->io_Data = (APTR)&character;
- X writereq->io_Length = 1;
- X DoIO(writereq);
- X /* command works because DoIO blocks until command is done
- X * (otherwise ptr to the character could become invalid)
- X */
- X}
- X
- X
- X/* Output a stream of known length to a console
- X */
- Xvoid ConWrite(struct IOStdReq *writereq, UBYTE *string, LONG length)
- X{
- X writereq->io_Command = CMD_WRITE;
- X writereq->io_Data = (APTR)string;
- X writereq->io_Length = length;
- X DoIO(writereq);
- X /* command works because DoIO blocks until command is done
- X * (otherwise ptr to string could become invalid in the meantime)
- X */
- X}
- X
- X
- X/* Output a NULL-terminated string of characters to a console
- X */
- Xvoid ConPuts(struct IOStdReq *writereq,UBYTE *string)
- X{
- X writereq->io_Command = CMD_WRITE;
- X writereq->io_Data = (APTR)string;
- X writereq->io_Length = -1; /* means print till terminating null */
- X DoIO(writereq);
- X}
- X
- X/* Queue up a read request to console, passing it pointer
- X * to a buffer into which it can read the character
- X */
- Xvoid QueueRead(struct IOStdReq *readreq, UBYTE *whereto)
- X{
- X readreq->io_Command = CMD_READ;
- X readreq->io_Data = (APTR)whereto;
- X readreq->io_Length = 1;
- X SendIO(readreq);
- X}
- X
- Xstruct IOStdReq *readreq; /* ttkeyready() needs to be able to see this */
- X
- X/* Wait for a character
- X */
- Xchar ConGetChar(struct MsgPort *msgport, UBYTE *whereto)
- X{
- X register temp;
- X
- X WaitPort(msgport);
- X readreq = (struct IOStdReq *)GetMsg(msgport);
- X temp = *whereto; /* get the character */
- X QueueRead(readreq,whereto); /* then re-use the request block*/
- X return((char)temp);
- X}
- X
- X/* typahead(): Check to see if any characters are already in the
- X keyboard buffer
- X On the amiga, we do this by checking if the outstanding read request
- X has been satisfied yet by calling CheckIO().
- X*/
- Xttkeyready ()
- X{
- X if(!kbdqp)
- X kbdqp = CheckIO(readreq)?1:0;
- X return kbdqp;
- X}
- X
- X/* UNIX support stuff */
- X
- X#define BLOCKSIZE 4096
- X
- Xlink(char *SPath, char *DPath)
- X{
- X int sfd, dfd, Bytes;
- X char BlkBuf[BLOCKSIZE];
- X
- X if((sfd = open(SPath, O_RDONLY)) == -1)
- X return -1;
- X if((dfd = open(DPath, O_WRONLY|O_CREAT|O_TRUNC)) == -1)
- X return -1;
- X while((Bytes = read(sfd, BlkBuf, BLOCKSIZE)) > 0)
- X write(dfd, BlkBuf, Bytes);
- X close(sfd);
- X close(dfd);
- X return 0;
- X}
- X
- X#endif /* AMIGA */
- END_OF_FILE
- if test 13875 -ne `wc -c <'amiga.c'`; then
- echo shar: \"'amiga.c'\" unpacked with wrong size!
- fi
- # end of 'amiga.c'
- fi
- if test -f 'line.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'line.c'\"
- else
- echo shar: Extracting \"'line.c'\" \(14071 characters\)
- sed "s/^X//" >'line.c' <<'END_OF_FILE'
- X/*
- X* Text line handling.
- X* The functions in this file
- X* are a general set of line management
- X* utilities. They are the only routines that
- X* touch the text. They also touch the buffer
- X* and window structures, to make sure that the
- X* necessary updating gets done. There are routines
- X* in this file that handle the kill buffer too.
- X* It isn't here for any good reason.
- X*
- X* Note that this code only updates the dot and
- X* mark values in the window list. Since all the code
- X* acts on the current window, the buffer that we
- X* are editing must be being displayed, which means
- X* that "b_nwnd" is non zero, which means that the
- X* dot and mark values in the buffer headers are
- X* nonsense.
- X*/
- X
- X#include "def.h"
- X
- Xvoid l_fix_up ();
- X
- Xextern char MSG_cnt_alloc[];
- X#if RUNCHK
- Xextern char ERR_no_alloc[];
- Xextern char ERR_db_dalloc[];
- Xextern char ERR_lock[];
- Xextern char ERR_lock_del[];
- X#endif
- X
- Xextern LINE *cur_pat;
- Xextern LINE *cur_mask;
- Xextern bool read_pat_mode;
- Xextern BUFFER sav_buf;
- X
- X/*
- X* This routine allocates a block
- X* of memory large enough to hold a LINE
- X* containing "size" characters. Return a pointer
- X* to the new block, or NULL if there isn't
- X* any memory left. Print a message in the
- X* message line if no space.
- X*/
- XLINE * lalloc (size)
- Xregister int size;
- X{
- X register LINE * lp;
- X char buf[NCOL], buf1[NCOL];
- X#if RUNCHK
- X if (read_pat_mode)
- X printf (ERR_no_alloc);
- X#endif
- X
- X if ((lp = (LINE *) malloc (sizeof (LINE) + size)) == NULL)
- X {
- X sprintf (buf1, MSG_cnt_alloc, R_POS_FMT(curwp));
- X sprintf (buf, buf1, (A32)size);
- X err_echo (buf);
- X curbp -> b_flag |= BFBAD;/* may be trashed */
- X curwp -> w_flag |= WFMODE;
- X update ();
- X return (NULL);
- X }
- X lp -> l_size = size;
- X lp -> l_used = 0;
- X lp -> l_file_offset = 0; /* set resonable initial value */
- X return (lp);
- X}
- X
- X
- X/*
- X* Delete line "lp". Fix all of the
- X* links that might point at it (they are
- X* moved to offset 0 of the next line.
- X* Unlink the line from whatever buffer it
- X* might be in. Release the memory. The
- X* buffers are updated too; the magic conditions
- X* described in the above comments don't hold
- X* here.
- X*/
- X
- Xvoid lfree (lp)
- Xregister LINE * lp;
- X{
- X register BUFFER * bp;
- X register WINDOW * wp;
- X
- X#if RUNCHK
- X if (read_pat_mode)
- X printf (ERR_db_dalloc);
- X#endif
- X
- X wp = wheadp;
- X while (wp != NULL)
- X {
- X if (wp -> w_linep == lp)
- X {
- X wp -> w_linep = lp -> l_fp;
- X wp -> w_loff = 0;
- X }
- X
- X if (wp -> w_dotp == lp)
- X {
- X wp -> w_dotp = lp -> l_fp;
- X wp -> w_doto = 0;
- X }
- X
- X if (wp -> w_markp == lp)
- X {
- X wp -> w_markp = lp -> l_fp;
- X wp -> w_marko = 0;
- X }
- X
- X wp = wp -> w_wndp;
- X }
- X
- X bp = bheadp;
- X while (bp != NULL)
- X {
- X if (bp -> b_nwnd == 0)
- X {
- X if (bp -> b_dotp == lp)
- X {
- X bp -> b_dotp = lp -> l_fp;
- X bp -> b_doto = 0;
- X }
- X
- X if (bp -> b_markp == lp)
- X {
- X bp -> b_markp = lp -> l_fp;
- X bp -> b_marko = 0;
- X }
- X }
- X bp = bp -> b_bufp;
- X }
- X
- X lp -> l_bp -> l_fp = lp -> l_fp;
- X lp -> l_fp -> l_bp = lp -> l_bp;
- X free ((char *) lp);
- X}
- X
- X
- X/*
- X* This routine gets called when
- X* a character is changed in place in the
- X* current buffer. It updates all of the required
- X* flags in the buffer and window system. The flag
- X* used is passed as an argument; if the buffer is being
- X* displayed in more than 1 window we change EDIT to
- X* HARD. Set MODE if the mode line needs to be
- X* updated (the "*" has to be set).
- X*/
- Xvoid lchange (flag)
- Xregister int flag;
- X{
- X register WINDOW * wp;
- X
- X if (curbp -> b_nwnd != 1) /* Ensure hard. */
- X flag = WFHARD;
- X if ((curbp -> b_flag & BFCHG) == 0)
- X {
- X /* First change, so */
- X flag |= WFMODE; /* update mode lines. */
- X curbp -> b_flag |= BFCHG;
- X }
- X
- X wp = wheadp;
- X while (wp != NULL)
- X {
- X if (wp -> w_bufp == curbp)
- X wp -> w_flag |= flag;
- X wp = wp -> w_wndp;
- X }
- X}
- X
- X
- X/*
- X * Break the line "dotp" in two at the position "doto."
- X */
- X
- XLINE *l_break_in_two (lp, lo, extra)
- Xregister LINE *lp;
- Xregister LPOS lo, extra;
- X{
- X register LINE *new_lp;
- X register D8 *cp1;
- X register D8 *cp2;
- X LPOS cnt, i;
- X
- X i = 0;
- X cnt = lp -> l_used - lo;
- X if ((new_lp = lalloc (cnt + extra)) == NULL)
- X return (NULL);
- X
- X cp1 = &lp -> l_text[lo]; /* starting location, source */
- X cp2 = &new_lp -> l_text[0]; /* starting location, destination */
- X
- X /* kill bytes in the current line */
- X while (i++ < cnt)
- X {
- X *cp2++ = *cp1++;
- X }
- X lp -> l_used -= cnt;
- X new_lp -> l_used = cnt;
- X new_lp -> l_file_offset = new_lp -> l_file_offset + lo;
- X
- X /* insert into chain */
- X new_lp -> l_fp = lp -> l_fp;
- X lp -> l_fp = new_lp;
- X new_lp -> l_bp = lp;
- X new_lp -> l_fp -> l_bp = new_lp;
- X return (new_lp);
- X}
- X
- X/*
- X* Insert "n" copies of the character "c"
- X* at the current location of dot. In the easy case
- X* all that happens is the text is stored in the line.
- X* Always allocate some extra space in line so that edit
- X* will be faster next time but will save space in the general case.
- X* In the hard case, the line has to be reallocated.
- X* When the window list is updated, take special
- X* care; I screwed it up once. You always update dot
- X* in the current window. You update mark, and a
- X* dot in another window, if it is greater than
- X* the place where you did the insert. Return TRUE
- X* if all is well, and FALSE on errors.
- X*/
- Xbool linsert (n, c)
- Xuchar c;
- X{
- X register D8 *cp1;
- X register D8 *cp2;
- X register LINE * lp1;
- X register LINE * lp2;
- X register short doto;
- X register int i;
- X register WINDOW * wp;
- X
- X#if RUNCHK
- X /* check that buffer size can be changed */
- X if (curbp -> b_flag & BFSLOCK)
- X {
- X writ_echo (ERR_lock);
- X return (FALSE);
- X }
- X#endif
- X
- X lchange (WFMOVE);
- X lp1 = curwp -> w_dotp; /* Current line */
- X if (lp1 == curbp -> b_linep)
- X {
- X /* At the end: special */
- X /* break the current line at the end */
- X if ((lp2 = l_break_in_two (lp1, lp1 -> l_used, (LPOS)n + NBLOCK)) == NULL)
- X return (FALSE);
- X for (i = 0; i < n; ++i) /* Add the characters */
- X lp2 -> l_text[i] = c;
- X lp2 -> l_used = n;
- X curwp -> w_dotp = lp2;
- X curwp -> w_doto = n;
- X return (TRUE);
- X }
- X
- X doto = curwp -> w_doto; /* Save for later. */
- X if (lp1 -> l_used + n > lp1 -> l_size)
- X {
- X /* break the current line and let the normal insert do it */
- X if ((lp2 = l_break_in_two (lp1, doto, (LPOS)n + NBLOCK)) == NULL)
- X return (FALSE);
- X lp1 -> l_text[doto] = c;
- X lp1 -> l_used++;
- X curwp -> w_doto++;
- X if (curwp -> w_doto >= lp1 -> l_used)
- X {
- X curwp -> w_dotp = lp2;
- X curwp -> w_doto = 0;
- X }
- X if (n > 1)
- X return (linsert (n - 1, c)); /* handle the rest in normal maner */
- X }
- X else
- X {
- X /* Easy: in place */
- X lp2 = lp1; /* Pretend new line */
- X lp2 -> l_used += n;
- X cp2 = &lp1 -> l_text[lp1 -> l_used];
- X cp1 = cp2 - n;
- X while (cp1 != &lp1 -> l_text[doto])
- X *--cp2 = *--cp1;
- X for (i = 0; i < n; ++i) /* Add the characters */
- X lp2 -> l_text[doto + i] = c;
- X move_ptr (curwp, (A32)n, TRUE, TRUE, TRUE);
- X }
- X
- X wp = wheadp; /* Update windows */
- X while (wp != NULL)
- X {
- X if ((wp -> w_linep == lp1) && (wp -> w_loff >= lp1 -> l_used))
- X {
- X wp -> w_linep = lp2;
- X wp -> w_loff -= lp1 -> l_used;
- X }
- X
- X /* move dot to next line but not to head line */
- X if ((wp -> w_dotp == lp1) && (wp -> w_doto >= lp1 -> l_used) &&
- X (wp -> w_dotp -> l_fp -> l_size != 0))
- X {
- X wp -> w_dotp = lp2;
- X wp -> w_doto -= (lp1 -> l_used - 1);
- X }
- X
- X if ((wp -> w_markp == lp1) && (wp -> w_marko >= lp1 -> l_used))
- X {
- X wp -> w_markp = lp2;
- X wp -> w_marko -= (lp1 -> l_used - 1);
- X }
- X
- X wp = wp -> w_wndp;
- X }
- X l_fix_up (lp1); /* re-adjust file offsets */
- X return (TRUE);
- X}
- X
- X/*
- X* This function deletes n_bytes,
- X* starting at dot. It understands how to deal
- X* with end of lines, etc. It returns TRUE if all
- X* of the characters were deleted, and FALSE if
- X* they were not (because dot ran into the end of
- X* the buffer). The "kflag" is TRUE if the text
- X* should be put in the kill buffer.
- X*/
- Xbool ldelete (n_bytes, kflag)
- XA32 n_bytes;
- X{
- X register LINE *dotp, *lp, *lp_prev, *lp_next;
- X register LPOS doto, l_cnt;
- X register WINDOW *wp;
- X D8 *cp1, *cp2;
- X D32 n_byt, dot_pos;
- X
- X#if RUNCHK
- X /* check that buffer size can be changed */
- X if (curbp -> b_flag & BFSLOCK)
- X {
- X writ_echo (ERR_lock_del);
- X return (FALSE);
- X }
- X#endif
- X lchange (WFMOVE);
- X doto = curwp -> w_doto;
- X dotp = curwp -> w_dotp;
- X lp_prev = dotp -> l_bp;
- X dot_pos = DOT_POS(curwp);
- X
- X /* if at the end of the buffer then delete nothing */
- X if (dot_pos >= BUF_SIZE(curwp))
- X {
- X l_fix_up (dotp); /* re-adjust file offsets */
- X return (TRUE);
- X }
- X
- X /* save dot and mark positions for later restore */
- X wp = wheadp;
- X while (wp != NULL)
- X {
- X wp->w_dot_temp = DOT_POS (wp);
- X if (wp->w_markp != NULL) /* mark may not be set */
- X wp->w_mark_temp = MARK_POS (wp);
- X wp->w_wind_temp = WIND_POS (wp);
- X wp = wp -> w_wndp;
- X }
- X
- X /* is delete wholy within one line? */
- X if ((doto + n_bytes) < dotp -> l_used)
- X {
- X cp1 = &dotp -> l_text[doto];/* Scrunch text. */
- X cp2 = cp1 + n_bytes;
- X
- X /* put stuff to delete into the kill buffer */
- X if (kflag != FALSE)
- X {
- X /* Kill? */
- X while (cp1 != cp2)
- X {
- X if (b_append_c (&sav_buf, *cp1) == FALSE)
- X return (FALSE);
- X ++cp1;
- X }
- X cp1 = &dotp -> l_text[doto];
- X }
- X /* kill bytes in the current line */
- X while (cp2 < &dotp -> l_text[dotp -> l_used])
- X *cp1++ = *cp2++;
- X
- X dotp -> l_used -= n_bytes;
- X }
- X else
- X { /* wholesale delete by moving lines to save buffer */
- X if (doto != 0)
- X {
- X if ((lp = l_break_in_two (dotp, doto, 0l)) == NULL)
- X return (FALSE);
- X }
- X else
- X lp = dotp;
- X
- X n_byt = n_bytes;
- X /* now handle whole lines if necessary */
- X while (n_byt > 0)
- X {
- X lp_next = lp -> l_fp;
- X
- X if (n_byt < lp -> l_used)
- X {
- X /* get last piece of a line */
- X lp_next = l_break_in_two (lp, n_byt, 0l);
- X }
- X n_byt -= lp -> l_used;
- X if (kflag)
- X {
- X /* remove form linked list */
- X lp -> l_bp -> l_fp = lp -> l_fp;
- X lp -> l_fp -> l_bp = lp -> l_bp;
- X /* append it to the save buffer */
- X b_append_l (&sav_buf, lp);
- X }
- X else
- X /* if we don't want it, free it */
- X lfree (lp);
- X lp = lp_next;
- X }
- X }
- X l_fix_up (lp_prev); /* re-adjust file offsets */
- X
- X /* adjust dot and marks in other windows */
- X /* this should be ok because the save buffer dosn't disturb l_file_offset */
- X wp = wheadp; /* Fix windows */
- X while (wp != NULL)
- X {
- X if (curbp == wp -> w_bufp)
- X {
- X A32 temp;
- X
- X /* if dot is before delete position, do nothing */
- X if (dot_pos <= (temp = wp -> w_dot_temp))
- X {
- X /* step back to the previous line */
- X wp -> w_doto = 0;
- X wp -> w_dotp = lp_prev;
- X
- X /* if dot is in deleted range, set to dot position */
- X if (temp > dot_pos + n_bytes)
- X /* if after deleted range, move back deleted ammount */
- X move_ptr (wp, temp - n_bytes, TRUE, TRUE, FALSE);
- X else
- X /* if in the deleted range, move to curwp dot position */
- X move_ptr (wp, dot_pos, TRUE, TRUE, FALSE);
- X }
- X /* mark may not be set in some windows */
- X if (wp -> w_markp != NULL)
- X {
- X /* do the same for mark */
- X if (dot_pos <= (temp = wp->w_mark_temp))
- X {
- X /* if in or after the deleted range, move to curwp dot position */
- X wp -> w_marko = curwp -> w_doto;
- X wp -> w_markp = curwp -> w_dotp;
- X
- X /* if mark after deleted range */
- X if (temp > dot_pos + n_bytes)
- X {
- X /* if after deleted range, move back deleted ammount */
- X /* move dot then swap with mark to produce result */
- X move_ptr (wp, temp - n_bytes, TRUE, TRUE, FALSE);
- X lp_next = wp -> w_dotp;
- X wp -> w_dotp = wp -> w_markp;
- X wp -> w_markp = lp_next;
- X l_cnt = wp -> w_doto;
- X wp -> w_doto = wp -> w_marko;
- X wp -> w_marko = l_cnt;
- X }
- X }
- X }
- X /* if window position is before delete position, do nothing */
- X if (dot_pos <= (temp = wp -> w_wind_temp))
- X {
- X /* set window position to dot position */
- X wp -> w_loff = 0;
- X wp -> w_linep = wp -> w_dotp;
- X wind_on_dot (wp);
- X }
- X }
- X wp = wp -> w_wndp;
- X }
- X /* update buffer display */
- X if ((blistp -> b_nwnd != 0) &&
- X (blistp -> b_type == BTLIST))
- X listbuffers ();
- X return (TRUE);
- X}
- X/*
- X* Replace character at dot position.
- X*/
- Xvoid lreplace (n, c)
- Xint n;
- Xchar c;
- X{
- X lchange (WFEDIT);
- X while (n--)
- X {
- X DOT_CHAR(curwp) = c & 0xff;
- X move_ptr (curwp, 1L, TRUE, FALSE, TRUE);
- X }
- X}
- X
- X/*
- X* Replace plen characters before dot with argument string.
- X*/
- Xbool lrepl_str (plen, rstr, mstr)
- X
- Xregister int plen; /* length to remove */
- Xregister LINE *rstr; /* replace string */
- Xregister LINE *mstr; /* mask string */
- X{
- X register int i; /* used for random characters */
- X register LINE *dotp; /* pointer to line structure */
- X register int doto; /* offset into line */
- X register int rlen; /* rplace string length */
- X register char c; /* temp storage for char */
- X register char mask; /* temp storage for mask */
- X
- X /*
- X * make the string lengths match (either pad the line
- X * so that it will fit, or scrunch out the excess).
- X * be careful with dot's offset.
- X */
- X doto = curwp -> w_doto;
- X rlen = rstr -> l_used;
- X if (plen > rlen)
- X {
- X ldelete ((A32)(plen - rlen), FALSE);
- X }
- X else if (plen < rlen)
- X {
- X if (linsert (rlen - plen, ' ') == FALSE)
- X return (FALSE);
- X }
- X curwp -> w_doto = doto;
- X dotp = curwp -> w_dotp; /* save dot line for later */
- X
- X /* do the replacement. */
- X for (i = 0; i < rlen; i++)
- X {
- X c = DOT_CHAR(curwp);
- X mask = mstr -> l_text[i];
- X DOT_CHAR(curwp) = (c & mask) | (rstr -> l_text[i] & ~mask);
- X move_ptr (curwp, 1L, TRUE, FALSE, TRUE);
- X }
- X curwp -> w_doto = doto;
- X curwp -> w_dotp = dotp;
- X lchange (WFHARD);
- X return (TRUE);
- X}
- X
- X/*
- X* Line fixup.
- X* This fixes the 'l_file_offset' variable in
- X* each line structure.
- X* This is necessary after every change in the size
- X* of the buffer.
- X*/
- Xvoid l_fix_up (line)
- X
- XLINE * line; /* points to buffer header line */
- X
- X{
- X long offset;
- X
- X offset = line -> l_file_offset;/* starting offset */
- X offset += line -> l_used;
- X for (;;)
- X {
- X line = line -> l_fp;
- X if (line -> l_size == 0)
- X return;
- X line -> l_file_offset = offset;
- X offset += line -> l_used;
- X }
- X}
- END_OF_FILE
- if test 14071 -ne `wc -c <'line.c'`; then
- echo shar: \"'line.c'\" unpacked with wrong size!
- fi
- # end of 'line.c'
- fi
- if test -f 'symbol.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'symbol.c'\"
- else
- echo shar: Extracting \"'symbol.c'\" \(18744 characters\)
- sed "s/^X//" >'symbol.c' <<'END_OF_FILE'
- X/*
- X* Symbol table stuff.
- X* Symbol tables, and keymap setup.
- X* The terminal specific parts of building the
- X* keymap has been moved to a better place.
- X*/
- X#include "def.h"
- X
- Xvoid keyadd ();
- Xvoid keydup ();
- X
- X
- 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_del_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[];
- Xextern char MSG_n_split[];
- Xextern char MSG_n_combine[];
- Xextern char MSG_show_save_buf[];
- X
- X/*
- X* Defined by "main.c".
- X*/
- Xextern char ctrlg (); /* Abort out of things */
- Xextern char quit (); /* Quit */
- Xextern char ctlxlp (); /* Begin macro */
- Xextern char ctlxrp (); /* End macro */
- Xextern char ctlxe (); /* Execute macro */
- Xextern char showversion (); /* Show version numbers, etc. */
- Xextern char flushnquit (); /* Flush buffers & exit (fitz) */
- Xextern char flush_all (); /* Flush buffers (jam) */
- Xextern char autosave (); /* autosave function (jam) */
- X
- X/*
- X* Defined by "search.c".
- X*/
- Xextern char forwsearch (); /* Search forward */
- Xextern char backsearch (); /* Search backwards */
- Xextern char searchagain (); /* Repeat last search command */
- Xextern char queryrepl (); /* Query replace */
- Xextern char compare (); /* Compare two windows */
- Xextern char recall (); /* Recall last search string */
- X
- X/*
- X* Defined by "basic.c".
- X*/
- Xextern char backchar (); /* Move backward by characters */
- Xextern char forwchar (); /* Move forward by characters */
- Xextern char gotobob (); /* Move to start of buffer */
- Xextern char gotoeob (); /* Move to end of buffer */
- Xextern char forwline (); /* Move forward by lines */
- Xextern char backline (); /* Move backward by lines */
- Xextern char forwpage (); /* Move forward by pages */
- Xextern char backpage (); /* Move backward by pages */
- Xextern char setmark (); /* Set mark */
- Xextern char swapmark (); /* Swap "." and mark */
- Xextern char gotoline (); /* Go to a specified line. */
- X
- X/*
- X* Defined by "buffer.c".
- X*/
- Xextern char listbuffers (); /* Display list of buffers */
- Xextern char showsavebuf (); /* Show the save buffer contents */
- Xextern char usebuffer (); /* Switch a window to a buffer */
- Xextern char use_buffer (); /* ditto, plus window split */
- Xextern char killbuffer (); /* Make a buffer go away. */
- Xextern char next_buf (); /* goto next buffer */
- Xextern char prev_buf (); /* goto prev buffer */
- Xextern char yank_buffer (); /* yank buffer by name */
- Xextern char buffername (); /* change buffer name */
- Xextern char bufsizlock (); /* lock buffer size */
- X
- X/*
- X* Defined by "file."
- X*/
- Xextern char fileread (); /* Get a file, read only */
- Xextern char filevisit (); /* Get a file, read write */
- Xextern char file_visit (); /* ditto , plus window split */
- Xextern char filewrite (); /* Write a file */
- Xextern char filesave (); /* Save current file */
- Xextern char filename (); /* Adjust file name */
- Xextern char fileinsert (); /* insert file to cursor (jam ) */
- Xextern char viewfile (); /* readonly file visit (jam) */
- X
- X/*
- X* Defined by "random.c".
- X*/
- X
- Xextern char dispshift (); /* Increment display shift */
- Xextern char selfinsert (); /* Insert character */
- Xextern char insert_toggle (); /* toggle insert mode (jam) */
- Xextern char insertunit (); /* insert unit (pvr) */
- Xextern char showcpos (); /* Show the cursor position */
- Xextern char twiddle (); /* Twiddle units */
- Xextern char forwdel (); /* Forward delete */
- Xextern char backdel (); /* Backward delete */
- Xextern char quote (); /* Insert literal */
- Xextern char asciimode (); /* display ASCII data */
- Xextern char ebcdicmode (); /* display EBCDIC data */
- Xextern char decimalmode (); /* display DECIMAL data */
- Xextern char hexmode (); /* display HEX data */
- Xextern char octalmode (); /* display OCTAL data */
- Xextern char binarymode (); /* display BINARY data */
- Xextern char dispsize1 (); /* display in BYTE format */
- Xextern char dispsize2 (); /* display in WORD format */
- Xextern char dispsize4 (); /* display in DWORD format*/
- Xextern char dispswapbyte (); /* Display swaped bytes pvr */
- Xextern char yank (); /* Yank back from killbuffer. */
- Xextern char linkwind (); /* Link all windows on one buffer. */
- Xextern char n_way_split (); /* Split buffer into n buffers. */
- Xextern char n_way_combine (); /* Combine n buffers into one. */
- X
- X/*
- X* Defined by "region.c".
- X*/
- Xextern char killregion (); /* Kill region. */
- Xextern char copyregion (); /* Copy region to kill buffer. */
- Xextern char save_region (); /* Save region in named buffer. */
- X
- X/*
- X* Defined by "spawn.c".
- X*/
- Xextern char spawncli (); /* Run CLI in a subjob. */
- Xextern char clock (); /* display time in modeline */
- X
- X/*
- X* Defined by "window.c".
- X*/
- Xextern char reposition (); /* Reposition window */
- Xextern char refresh (); /* Refresh the screen */
- Xextern char nextwind (); /* Move to the next window */
- Xextern char prevwind (); /* Move to the previous window */
- Xextern char mvdnwind (); /* Move window down */
- Xextern char mvupwind (); /* Move window up */
- Xextern char onlywind (); /* Make current window only one */
- Xextern char delwind (); /* Delete current window */
- Xextern char splitwind (); /* Split current window */
- Xextern char enlargewind (); /* Enlarge display window. */
- Xextern char shrinkwind (); /* Shrink window. */
- X
- X/*
- X* Defined by "word.c".
- X*/
- Xextern char backunit (); /* Backup by units */
- Xextern char forwunit (); /* Advance by units */
- Xextern char delfunit (); /* Delete forward unit. */
- Xextern char delbunit (); /* Delete backward unit. */
- X
- X/*
- X* Defined by "extend.c".
- X*/
- Xextern char extend (); /* Extended commands. */
- Xextern char help (); /* Help key. */
- Xextern char bindtokey (); /* Modify key bindings. */
- Xextern char wallchart (); /* Make wall chart. */
- Xextern void check_extend (); /* load extended key file */
- Xextern char load_extend (); /* load extended file by name */
- X
- X/*
- X* Defined by "display.c
- X*/
- Xextern char print (); /* print window from mark to dot */
- X
- Xtypedef struct
- X{
- X
- X short k_key; /* Key to bind. */
- X char (*k_funcp) (); /* Function. */
- X char *k_name; /* Function name string. */
- X char k_modify; /* modify bit */
- X} KEY;
- X
- X/*
- X* Default key binding table. This contains
- X* the function names, the symbol table name, and (possibly)
- X* a key binding for the builtin functions. There are no
- X* bindings for C-U or C-X. These are done with special
- X* code, but should be done normally.
- X*/
- XKEY key[] =
- X{
- X KCTRL | 'A', dispshift, MSG_byte_shift, 0,
- X KCTRL | 'B', backchar, MSG_back_char, SSRCH | SRPLC,
- X KCTRL | 'C', quit, MSG_quit, 0,/* pvr */
- X KCTRL | 'D', forwdel, MSG_forw_del_char, SMOD | SSIZE | SSRCH | SRPLC,
- X KCTRL | 'E', dispswapbyte, MSG_toggle_swap, SSRCH | SRPLC,/* pvr */
- X KCTRL | 'F', forwchar, MSG_forw_char, SSRCH | SRPLC,
- X KCTRL | 'G', ctrlg, MSG_abort, SSRCH | SRPLC,
- X KCTRL | 'I', selfinsert, MSG_ins_self, SMOD | SSRCH | SRPLC,
- X KCTRL | 'H', backdel, MSG_back_del_char, SMOD | SSIZE | SSRCH | SRPLC,
- X KCTRL | 'L', refresh, MSG_refresh, SSRCH | SRPLC,
- X KCTRL | 'N', forwline, MSG_forw_line, SSRCH | SRPLC,
- X KCTRL | 'P', backline, MSG_back_line, SSRCH | SRPLC,
- X KCTRL | 'Q', quote, MSG_quote, 0,
- X KCTRL | 'R', recall, MSG_recall, SSRCH | SRPLC,
- X KCTRL | 'T', twiddle, MSG_twiddle, SMOD | SSRCH | SRPLC,
- X KCTRL | 'V', forwpage, MSG_forw_page, SRPLC,
- X KCTRL | 'W', killregion, MSG_kill_region, SMOD | SSIZE,
- X KCTRL | 'Y', yank, MSG_yank, SMOD | SSIZE,
- X KCTRL | 'Z', mvdnwind, MSG_down_window, 0,/* fitz */
- X KCTLX | KCTRL | 'A', insert_toggle, MSG_ins_toggle, SSRCH | SRPLC,
- X KCTLX | KCTRL | 'B', listbuffers, MSG_display_buffers, 0,
- X KCTLX | KCTRL | 'C', quit, MSG_quit, 0,
- X KCTLX | KCTRL | 'E', flushnquit, MSG_exit_flush_all, 0,/* fitz */
- X KCTLX | KCTRL | 'F', filename, MSG_set_file_name, SMOD,/* jam */
- X KCTLX | KCTRL | 'I', fileinsert, MSG_file_insert, SMOD | SSIZE,
- X KCTLX | KCTRL | 'L', bufsizlock, MSG_buf_size_lock, 0,
- X KCTLX | KCTRL | 'M', flush_all, MSG_flush_all, 0,
- X KCTLX | KCTRL | 'N', mvdnwind, MSG_down_window, 0,
- X KCTLX | KCTRL | 'P', mvupwind, MSG_up_window, 0,
- X KCTLX | KCTRL | 'R', fileread, MSG_file_read, 0,
- X KCTLX | KCTRL | 'S', filesave, MSG_file_save, 0,
- X KCTLX | KCTRL | 'V', filevisit, MSG_file_visit, 0,
- X KCTLX | KCTRL | 'W', filewrite, MSG_file_write, 0,
- X KCTLX | KCTRL | 'X', swapmark, MSG_swap_dot_and_mark, 0,
- X KCTLX | KCTRL | 'Z', shrinkwind, MSG_shrink_window, 0,
- X KCTLX | '=', showcpos, MSG_display_position, 0,
- X KCTLX | '(', ctlxlp, MSG_start_macro, 0,
- X KCTLX | ')', ctlxrp, MSG_end_macro, 0,
- X KCTLX | '?', help, MSG_help, 0,
- X KCTLX | '0', delwind, MSG_del_window, 0,
- X KCTLX | '1', onlywind, MSG_only_window, 0,
- X KCTLX | '2', splitwind, MSG_split_window, 0,
- X KCTLX | 'B', usebuffer, MSG_use_buffer, 0,
- X KCTLX | 'C', spawncli, MSG_spawn_cli, 0,/* fitz */
- X KCTLX | 'E', ctlxe, MSG_execute_macro, 0,
- X KCTLX | 'G', gotoline, MSG_goto_line, 0,
- X KCTLX | 'I', insertunit, MSG_ins_unit, SMOD | SSIZE | SSRCH | SRPLC,
- X KCTLX | 'K', killbuffer, MSG_kill_buffer, 0,
- X KCTLX | 'L', load_extend, MSG_load_bindings, 0,
- X KCTLX | 'N', nextwind, MSG_forw_window, 0,
- X KCTLX | 'P', prevwind, MSG_back_window, 0,
- X KCTLX | 'V', viewfile, MSG_view_file, 0,/* jam */
- X KCTLX | 'Z', enlargewind, MSG_enlarge_window, 0,
- X KMETA | KCTRL | 'A', asciimode, MSG_ascii_mode, SSRCH | SRPLC, /* pvr */
- X KMETA | KCTRL | 'B', binarymode, MSG_binary_mode, SSRCH | SRPLC, /* pvr */
- X KMETA | KCTRL | 'F', n_way_combine, MSG_n_combine, SSIZE | SMOD, /* pvr */
- X KMETA | KCTRL | 'N', buffername, MSG_buffer_name, 0,
- X KMETA | KCTRL | 'D', decimalmode, MSG_decimal_mode, SSRCH | SRPLC, /* pvr */
- X KMETA | KCTRL | 'E', ebcdicmode, MSG_ebcdic_mode, SSRCH | SRPLC, /* pvr */
- X KMETA | KCTRL | 'H', hexmode, MSG_hex_mode, SSRCH | SRPLC, /* pvr */
- X KMETA | KCTRL | 'K', delbunit, MSG_back_del_unit, SMOD | SSIZE | SSRCH | SRPLC,
- X KMETA | KCTRL | 'O', octalmode, MSG_octal_mode, SSRCH | SRPLC, /* pvr */
- X KMETA | KCTRL | 'S', n_way_split, MSG_n_split, 0, /* pvr */
- X KMETA | KCTRL | 'V', showversion, MSG_display_version, 0,
- X KMETA | KCTRL | 'W', showsavebuf, MSG_show_save_buf, 0,
- X KMETA | '1', dispsize1, MSG_unit_size1, SSRCH | SRPLC,/* pvr */
- X KMETA | '2', dispsize2, MSG_unit_size2, SSRCH | SRPLC,/* pvr */
- X KMETA | '4', dispsize4, MSG_unit_size4, SSRCH | SRPLC,/* pvr */
- X KMETA | '!', reposition, MSG_reposition_window, 0,
- X KMETA | '.', setmark, MSG_set_mark, 0,
- X KMETA | '>', gotoeob, MSG_goto_eob, SSRCH | SRPLC,
- X KMETA | '<', gotobob, MSG_goto_bob, SSRCH | SRPLC,
- X KMETA | '+', next_buf, MSG_next_buff, 0,
- X KMETA | '-', prev_buf, MSG_prev_buff, 0,
- X KMETA | '%', queryrepl, MSG_query_replace, SMOD,
- X KMETA | '?', wallchart, MSG_display_bindings, 0,
- X KMETA | 'A', autosave, MSG_auto_save, 0,
- X KMETA | 'B', backunit, MSG_back_unit, SSRCH | SRPLC,
- X KMETA | 'C', compare, MSG_compare, 0,
- X KMETA | 'D', delfunit, MSG_forw_del_unit, SMOD | SSIZE | SSRCH | SRPLC,
- X KMETA | 'F', forwunit, MSG_forw_unit, SSRCH | SRPLC,
- X KMETA | 'G', use_buffer, MSG_use_buffer_split, 0,
- X KMETA | 'K', bindtokey, MSG_bind_to_key, 0,
- X KMETA | 'L', linkwind, MSG_link_windows, 0,
- X KMETA | 'O', save_region, MSG_save_region, 0,
- X KMETA | 'P', print, MSG_print, 0,
- X KMETA | 'R', backsearch, MSG_back_search, 0,
- X KMETA | 'S', forwsearch, MSG_forw_search, 0,
- X KMETA | 'T', searchagain, MSG_search_again, 0,
- X KMETA | 'U', file_visit, MSG_file_visit_split, 0,
- X KMETA | 'V', backpage, MSG_back_page, SRPLC,
- X KMETA | 'W', copyregion, MSG_copy_region, 0,
- X KMETA | 'X', extend, MSG_extended_command, 0,
- X KMETA | 'Y', yank_buffer, MSG_yank_buffer, SMOD | SSIZE,
- X KMETA | 'Z', mvupwind, MSG_up_window, 0
- X};
- X
- X#define NKEY (sizeof(key) / sizeof(key[0]))
- X
- X/*
- X* Symbol table lookup.
- X* Return a pointer to the SYMBOL node, or NULL if
- X* the symbol is not found.
- X*/
- XSYMBOL * symlookup (cp)
- Xregister char *cp;
- X{
- X register SYMBOL * sp;
- X
- X sp = symbol[symhash (cp)];
- X while (sp != NULL)
- X {
- X if (strcmp (cp, sp -> s_name) == 0)
- X return (sp);
- X sp = sp -> s_symp;
- X }
- X return (NULL);
- X}
- X
- X
- X/*
- X* Take a string, and compute the symbol table
- X* bucket number. This is done by adding all of the characters
- X* together, and taking the sum mod NSHASH. The string probably
- X* should not contain any GR characters; if it does the "*cp"
- X* may get a nagative number on some machines, and the "%"
- X* will return a negative number!
- X*/
- Xint symhash (cp)
- Xregister char *cp;
- X{
- X register int c;
- X register int n;
- X
- X n = 0;
- X while ((c = *cp++) != 0)
- X n += c;
- X return (n % NSHASH);
- X}
- X
- X
- X/*
- X* Build initial keymap. The funny keys
- X* (commands, odd control characters) are mapped using
- X* a big table and calls to "keyadd". The printing characters
- X* are done with some do-it-yourself handwaving. The terminal
- X* specific keymap initialization code is called at the
- X* very end to finish up. All errors are fatal.
- X*/
- Xvoid keymapinit ()
- X{
- X register SYMBOL * sp;
- X register KEY * kp;
- X register int i;
- X
- X for (i = 0; i < NKEYS; ++i)
- X binding[i] = NULL;
- X for (kp = &key[0]; kp < &key[NKEY]; ++kp)
- X keyadd (kp -> k_key, kp -> k_funcp, kp -> k_name, kp -> k_modify);
- X keydup (KCTLX | KCTRL | 'G', MSG_abort);
- X keydup (KMETA | KCTRL | 'G', MSG_abort);
- X keydup (0x7F, MSG_back_del_char);
- X keydup (KMETA | 'Q', MSG_quote);
- X keydup (KMETA | 0x7F, MSG_back_del_unit);
- X /*
- X * Should be bound by "tab" already.
- X */
- X if ((sp = symlookup (MSG_ins_self)) == NULL)
- X abort ();
- X for (i = 0x20; i < 0x7F; ++i)
- X {
- X if (binding[i] != NULL)
- X abort ();
- X binding[i] = sp;
- X ++sp -> s_nkey;
- X }
- X ttykeymapinit ();
- X}
- X
- X
- X/*
- X* Create a new builtin function "name"
- X* with function "funcp". If the "new" is a real
- X* key, bind it as a side effect. All errors
- X* are fatal.
- X*/
- Xvoid keyadd (new, funcp, name, modify)
- Xbool (*funcp) ();
- Xchar *name;
- X{
- X register SYMBOL * sp;
- X register int hash;
- X
- X if ((sp = (SYMBOL *) malloc (sizeof (SYMBOL))) == NULL)
- X abort ();
- X hash = symhash (name);
- X sp -> s_symp = symbol[hash];
- X symbol[hash] = sp;
- X sp -> s_nkey = 0;
- X sp -> s_name = name;
- X sp -> s_funcp = funcp;
- X sp -> s_modify = modify;
- X if (new >= 0)
- X {
- X /* Bind this key. */
- X if (binding[new] != NULL)
- X abort ();
- X binding[new] = sp;
- X ++sp -> s_nkey;
- X }
- X}
- X
- X/*
- X* Bind key "new" to the existing
- X* routine "name". If the name cannot be found,
- X* or the key is already bound, abort.
- X*/
- Xvoid keydup (new, name)
- Xregister int new;
- Xchar *name;
- X{
- X register SYMBOL * sp;
- X
- X if (binding[new] != NULL || (sp = symlookup (name)) == NULL)
- X {
- X printf (MSG_no_f_tb, name);
- X abort ();
- X }
- X binding[new] = sp;
- X ++sp -> s_nkey;
- X}
- END_OF_FILE
- if test 18744 -ne `wc -c <'symbol.c'`; then
- echo shar: \"'symbol.c'\" unpacked with wrong size!
- fi
- # end of 'symbol.c'
- fi
- if test -f 'ttyio.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ttyio.c'\"
- else
- echo shar: Extracting \"'ttyio.c'\" \(3055 characters\)
- sed "s/^X//" >'ttyio.c' <<'END_OF_FILE'
- X/*
- X*
- X* MS-DOS terminal I/O. TTYIO.C
- X*/
- X
- X#include "def.h"
- X#ifdef MSDOS
- X
- X
- Xvoid ttopen ();
- Xvoid ttclose (); /* stub */
- Xvoid ttputc ();
- Xvoid putline ();
- Xvoid ttflush (); /* stub */
- Xint ttkeyready ();
- Xint ttgetc ();
- Xvoid ttraw ();
- Xvoid ttcooked ();
- Xvoid set_crt_type ();
- X
- X#include "dos.h"
- X
- Xint slot;
- Xint scr_type;
- X#define SCREEN_PORT (video_port)
- Xstatic int video_port =
- X{
- X 0x1010
- X};
- X
- Xextern bool wang_pc;
- Xextern bool ibm_pc;
- Xint nrow; /* Terminal size, rows. */
- Xint ncol; /* Terminal size, columns. */
- Xint last_key;
- X
- X/*
- X* Initialization.
- X* Almost no operation in MS-DOS.
- X*/
- Xvoid ttopen ()
- X{
- X if (wang_pc && !ibm_pc)
- X set_crt_type ();
- X nrow = NROW;
- X ncol = NCOL;
- X}
- X
- Xvoid ttclose ()
- X{
- X}
- Xvoid ttflush ()
- X{
- X}
- X/*
- X* Write character.
- X*/
- Xvoid ttputc (c)
- X{
- X bdos (6, c, 0);
- X}
- X
- Xvoid putline (row, startcol, stringsize, string)
- Xint row,
- Xstartcol,
- Xstringsize;
- Xchar *string;
- X{
- X extern int tthue;
- X unsigned short *screen;
- X int x,
- X attribute;
- X char c_row, c_col, i;
- X union REGS regs;
- X
- X if (ibm_pc)
- X {
- X c_row = row - 1;
- X c_col = startcol - 1;
- X for (i = 0; i < stringsize; i++)
- X {
- X regs.h.ah = 2;
- X regs.h.dh = c_row;
- X regs.h.dl= c_col;
- X regs.h.bh = 0;
- X int86 (0x10, ®s, ®s); /* set cursor position */
- X
- X if (tthue == CTEXT)
- X regs.h.bl = 0x07;
- X if (tthue == CMODE)
- X regs.h.bl = 0x70;
- X regs.h.ah = 9;
- X regs.h.bh = 0;
- X regs.h.al = string[i];
- X regs.x.cx= 1;
- X int86 (0x10, ®s, ®s); /* set cursor position */
- X c_col++;
- X }
- X }
- X else if (wang_pc)
- X {
- X if (tthue == CTEXT)
- X attribute = 0x00;
- X else
- X attribute = 0x02;
- X
- X x = stringsize;
- X screen = (unsigned short *) WANG_CHARACTER_SCREEN;
- X screen += ((row - 1) * 80) + startcol - 1;
- X outp (SCREEN_PORT, 01);
- X while (x--)
- X {
- X *screen = (*string++ << 8) | attribute;
- X screen++;
- X }
- X outp (SCREEN_PORT, 00);
- X }
- X}
- X
- X/*
- X* return with a TRUE if key was struck.
- X*/
- Xint ttkeyready ()
- X{
- X int cnt;
- X
- X if (last_key != 0)
- X return (1);
- X
- X last_key = bdos (6, 0xff, 0);
- X last_key &= 0xff;
- X if (last_key == 0)
- X return (0);
- X else
- X return (1);
- X}
- X
- X/*
- X* Read character.
- X*/
- Xint ttgetc ()
- X{
- X int c;
- X if (last_key != 0)
- X {
- X c = last_key;
- X last_key = 0;
- X return (c);
- X }
- X ttcooked ();
- X c = (bdos (7, 0, 0) & 0xFF);
- X ttraw ();
- X return (c);
- X}
- X
- X/* disable nasty cntrl-c during disk io!
- X*/
- Xvoid ttraw ()
- X{
- X union REGS inregs, outregs;
- X
- X inregs.h.al = 1;
- X inregs.h.ah = 0x33;
- X inregs.h.dl = 0;
- X intdos (&inregs, &outregs);
- X /*
- X cntrlcoff();
- X*/
- X}
- X
- X/* re enable cntrl-c for keyboard
- X*/
- Xvoid ttcooked ()
- X{
- X union REGS inregs, outregs;
- X
- X inregs.h.al = 1;
- X inregs.h.ah = 0x33;
- X intdos (&inregs, &outregs);
- X inregs.h.dl = 1;
- X /*
- X cntrlcon();
- X*/
- X}
- X
- X/* switch physical monitors
- X*/
- Xstatic char str[] =
- X{
- X 0x1b, '/', 1, 's'
- X};
- X
- Xvoid set_crt_type ()
- X{
- X char active_screen;
- X
- X active_screen = getscreenstate ();
- X slot = active_screen & 0x0f;
- X scr_type = (active_screen & 0x70) >> 4;
- X video_port = 0x1010 | (slot << 8);
- X}
- X#endif
- END_OF_FILE
- if test 3055 -ne `wc -c <'ttyio.c'`; then
- echo shar: \"'ttyio.c'\" unpacked with wrong size!
- fi
- # end of 'ttyio.c'
- fi
- echo shar: End of archive 6 \(of 9\).
- cp /dev/null ark6isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 9 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-