Extract struct buffer and struct window from estruct.h.

This commit is contained in:
Renaud 2013-09-20 18:10:30 +08:00
parent 39e23cb169
commit 87cd40ce6a
29 changed files with 163 additions and 120 deletions

View File

@ -15,6 +15,7 @@
#include <stdio.h>
#include "buffer.h"
#include "display.h"
#include "estruct.h"
#include "edef.h"
@ -22,6 +23,7 @@
#include "line.h"
#include "random.h"
#include "utf8.h"
#include "window.h"
#include "word.h"
/*

View File

@ -1,6 +1,7 @@
/* bindable.h -- implements bindable.c */
#include "bindable.h"
#include "defines.h"
#include "buffer.h"
#include "display.h"
#include "edef.h"

View File

@ -14,12 +14,12 @@
#include <stdio.h>
#include "defines.h"
#include "display.h"
#include "estruct.h"
/* #include "estruct.h" */
#include "edef.h"
#include "file.h"
#include "input.h"
#include "line.h"
#include "window.h"

View File

@ -1,7 +1,63 @@
#ifndef _BUFFER_H_
#define _BUFFER_H_
#include "estruct.h"
#include "crypt.h"
#include "line.h"
#define NFILEN 80 /* # of bytes, file name */
#define NBUFN 16 /* # of bytes, buffer name */
#define NPAT 128 /* # of bytes, pattern */
/*
* Text is kept in buffers. A buffer header, described below, exists for every
* buffer in the system. The buffers are kept in a big list, so that commands
* that search for a buffer by name can find the buffer header. There is a
* safe store for the dot and mark in the header, but this is only valid if
* the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
* the buffer is kept in a circularly linked list of lines, with a pointer to
* the header line in "b_linep".
* Buffers may be "Inactive" which means the files associated with them
* have not been read in yet. These get read in at "use buffer" time.
*/
struct buffer {
struct buffer *b_bufp; /* Link to next struct buffer */
struct line *b_dotp; /* Link to "." struct line structure */
struct line *b_markp; /* The same as the above two, */
struct line *b_linep; /* Link to the header struct line */
int b_doto; /* Offset of "." in above struct line */
int b_marko; /* but for the "mark" */
int b_mode; /* editor mode of this buffer */
char b_active; /* window activated flag */
char b_nwnd; /* Count of windows on buffer */
char b_flag; /* Flags */
char b_fname[NFILEN]; /* File name */
char b_bname[NBUFN]; /* Buffer name */
#if CRYPT
char b_key[NPAT]; /* current encrypted key */
#endif
};
#define BFINVS 0x01 /* Internal invisable buffer */
#define BFCHG 0x02 /* Changed since last write */
#define BFTRUNC 0x04 /* buffer was truncated when read */
/* mode flags */
#define NUMMODES 11 /* # of defined modes */
#define MDWRAP 0x0001 /* word wrap */
#define MDCMOD 0x0002 /* C indentation and fence match */
#define MDSPELL 0x0004 /* spell error parcing */
#define MDEXACT 0x0008 /* Exact matching for searches */
#define MDVIEW 0x0010 /* read-only buffer */
#define MDOVER 0x0020 /* overwrite mode */
#define MDMAGIC 0x0040 /* regular expresions in search */
#if CRYPT
#define MDCRYPT 0x0080 /* encrytion mode active */
#endif
#define MDASAVE 0x0100 /* auto-save mode */
#define MDUTF8 0x0200 /* utf8 mode */
#define MDDOS 0x0400 /* CRLF eol mode */
int usebuffer( int f, int n) ;
int nextbuffer( int f, int n) ;

View File

@ -1,7 +1,5 @@
/* crypt.c -- implements crypt.h */
#include "defines.h"
#include "crypt.h"
/* CRYPT.C

View File

@ -1,9 +1,9 @@
#ifndef _CRYPT_H_
#define _CRYPT_H_
#ifndef CRYPT
#error CRYPT should be defined
#elif CRYPT
#define CRYPT 1 /* file encryption enabled? */
#if CRYPT
void myencrypt( char *bptr, unsigned len) ;
#endif

View File

@ -1,8 +1,10 @@
/* Must define one of
VMS | V7 | USG | BSD | MSDOS
*/
#define USG 1
#define CRYPT 1 /* file encryption enabled? */
#define NSTRING 128 /* # of bytes, string buffers */
#define PKCODE 1
#define SCROLLCODE 1 /* scrolling code P.K. */
#define ENVFUNC 1

View File

@ -17,6 +17,7 @@
#include <stdarg.h>
#include <unistd.h>
#include "buffer.h"
#include "estruct.h"
#include "edef.h"
#include "line.h"

13
edef.h
View File

@ -10,6 +10,7 @@
#ifndef EDEF_H_
#define EDEF_H_
#include "buffer.h"
#include "estruct.h"
#include <stdlib.h>
@ -67,7 +68,17 @@ extern int kused; /* # of bytes used in KB */
extern struct window *swindow; /* saved window pointer */
extern int *kbdptr; /* current position in keyboard buf */
extern int *kbdend; /* ptr to end of the keyboard */
extern int kbdmode; /* current keyboard macro mode */
#if 0
#define STOP 0 /* keyboard macro not in use */
#define PLAY 1 /* playing */
#define RECORD 2 /* recording */
#endif
typedef enum {
STOP, PLAY, RECORD
} kbdstate ;
extern kbdstate kbdmode ; /* current keyboard macro mode */
extern int kbdrep; /* number of repetitions */
extern int restflag; /* restricted use? */
extern int lastkey; /* last keystoke */

View File

@ -158,7 +158,9 @@
#define ISRCH 1 /* Incremental searches like ITS EMACS */
#define WORDPRO 1 /* Advanced word processing features */
#define APROP 1 /* Add code for Apropos command */
#if 0
#define CRYPT 1 /* file encryption enabled? */
#endif
#define MAGIC 1 /* include regular expression matching? */
#define AEDIT 1 /* advanced editing options: en/detabbing */
#define PROC 1 /* named procedures */
@ -251,9 +253,11 @@
#include "retcode.h"
#if 0
#define STOP 0 /* keyboard macro not in use */
#define PLAY 1 /* playing */
#define RECORD 2 /* recording */
#endif
/* Directive definitions */
@ -384,96 +388,6 @@
int cexit( int status) ;
#endif
/*
* There is a window structure allocated for every active display window. The
* windows are kept in a big list, in top to bottom screen order, with the
* listhead at "wheadp". Each window contains its own values of dot and mark.
* The flag field contains some bits that are set by commands to guide
* redisplay. Although this is a bit of a compromise in terms of decoupling,
* the full blown redisplay is just too expensive to run for every input
* character.
*/
struct window {
struct window *w_wndp; /* Next window */
struct buffer *w_bufp; /* Buffer displayed in window */
struct line *w_linep; /* Top line in the window */
struct line *w_dotp; /* Line containing "." */
struct line *w_markp; /* Line containing "mark" */
int w_doto; /* Byte offset for "." */
int w_marko; /* Byte offset for "mark" */
char w_toprow; /* Origin 0 top row of window */
char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
#if COLOR
char w_fcolor; /* current forground color */
char w_bcolor; /* current background color */
#endif
};
#define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */
#define WFEDIT 0x04 /* Editing within a line */
#define WFHARD 0x08 /* Better to a full display */
#define WFMODE 0x10 /* Update mode line. */
#define WFCOLR 0x20 /* Needs a color change */
#if SCROLLCODE
#define WFKILLS 0x40 /* something was deleted */
#define WFINS 0x80 /* something was inserted */
#endif
/*
* Text is kept in buffers. A buffer header, described below, exists for every
* buffer in the system. The buffers are kept in a big list, so that commands
* that search for a buffer by name can find the buffer header. There is a
* safe store for the dot and mark in the header, but this is only valid if
* the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
* the buffer is kept in a circularly linked list of lines, with a pointer to
* the header line in "b_linep".
* Buffers may be "Inactive" which means the files associated with them
* have not been read in yet. These get read in at "use buffer" time.
*/
struct buffer {
struct buffer *b_bufp; /* Link to next struct buffer */
struct line *b_dotp; /* Link to "." struct line structure */
struct line *b_markp; /* The same as the above two, */
struct line *b_linep; /* Link to the header struct line */
int b_doto; /* Offset of "." in above struct line */
int b_marko; /* but for the "mark" */
int b_mode; /* editor mode of this buffer */
char b_active; /* window activated flag */
char b_nwnd; /* Count of windows on buffer */
char b_flag; /* Flags */
char b_fname[NFILEN]; /* File name */
char b_bname[NBUFN]; /* Buffer name */
#if CRYPT
char b_key[NPAT]; /* current encrypted key */
#endif
};
#define BFINVS 0x01 /* Internal invisable buffer */
#define BFCHG 0x02 /* Changed since last write */
#define BFTRUNC 0x04 /* buffer was truncated when read */
/* mode flags */
#define NUMMODES 11 /* # of defined modes */
#define MDWRAP 0x0001 /* word wrap */
#define MDCMOD 0x0002 /* C indentation and fence match */
#define MDSPELL 0x0004 /* spell error parcing */
#define MDEXACT 0x0008 /* Exact matching for searches */
#define MDVIEW 0x0010 /* read-only buffer */
#define MDOVER 0x0020 /* overwrite mode */
#define MDMAGIC 0x0040 /* regular expresions in search */
#if CRYPT
#define MDCRYPT 0x0080 /* encrytion mode active */
#endif
#define MDASAVE 0x0100 /* auto-save mode */
#define MDUTF8 0x0200 /* utf8 mode */
#define MDDOS 0x0400 /* CRLF eol mode */
/*
* The starting position of a region, and the size of the region in
* characters, is kept in a region structure. Used by the region commands.

1
exec.c
View File

@ -22,6 +22,7 @@
#include "flook.h"
#include "input.h"
#include "line.h"
#include "window.h"
/* directive name table:
This holds the names of all the directives.... */

1
exec.h
View File

@ -1,6 +1,7 @@
#ifndef _EXEC_H_
#define _EXEC_H_
#include "buffer.h"
#include "estruct.h"
int namedcmd( int f, int n) ;

View File

@ -3,6 +3,7 @@
#include "random.h"
#include "display.h"
#include "file.h"
#include "window.h"
/*
* This is the general command execution routine. It handles the fake binding

2
file.c
View File

@ -1,6 +1,5 @@
/* file.c -- implements file.h */
#include "estruct.h"
#include "file.h"
/* file.c
@ -17,6 +16,7 @@
#include "buffer.h"
#include "crypt.h"
#include "defines.h"
#include "estruct.h"
#include "edef.h"
#include "execute.h"

7
file.h
View File

@ -1,11 +1,12 @@
#ifndef _FILE_H_
#define _FILE_H_
#include "crypt.h"
#include "retcode.h"
#ifndef CRYPT
#error CRYPT should be defined.
#elif CRYPT
#if CRYPT
#include "buffer.h"
void cryptbufferkey( struct buffer *bp) ;
int set_encryption_key( int f, int n) ;
#endif

View File

@ -1,6 +1,5 @@
/* fileio.c -- implements fileio.h */
#include "defines.h"
#include "fileio.h"
/* FILEIO.C
@ -15,9 +14,9 @@
#include <stdlib.h>
#include <string.h>
#if CRYPT
#include "crypt.h"
#include "defines.h"
#if CRYPT
boolean is_crypted ; /* currently encrypting? */
#endif

View File

@ -1,7 +1,7 @@
#ifndef _FILEIO_H_
#define _FILEIO_H_
#include "retcode.h"
#include "crypt.h"
typedef enum {
FIOSUC, /* File I/O, success. */
@ -18,9 +18,9 @@ typedef enum {
#define FTYPE_MAC 4
/* FTYPE_MIXED [ 3, 5, 6, 7] */
#ifndef CRYPT
#error CRYPT should be defined.
#elif CRYPT
#if CRYPT
#include "retcode.h"
extern boolean is_crypted ; /* currently encrypting? */
#endif

View File

@ -1,4 +1,7 @@
#include "estruct.h"
#include "crypt.h"
#include "defines.h"
/* #include "estruct.h" */
#include "edef.h"
/* initialized global definitions */
@ -79,7 +82,7 @@ int kused = KBLOCK; /* # of bytes used in kill buffer */
struct window *swindow = NULL; /* saved window pointer */
int *kbdptr; /* current position in keyboard buf */
int *kbdend = &kbdm[0]; /* ptr to end of the keyboard */
int kbdmode = STOP; /* current keyboard macro mode */
kbdstate kbdmode = STOP; /* current keyboard macro mode */
int kbdrep = 0; /* number of repetitions */
int restflag = FALSE; /* restricted use? */
int lastkey = 0; /* last keystoke */

View File

@ -27,13 +27,14 @@
#include <stdio.h>
#include "basic.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h"
#include "edef.h"
#include "input.h"
#include "line.h"
#include "search.h"
#include "window.h"
static int isearch( int f, int n) ;
static int checknext( char chr, char *patrn, int dir) ;

2
line.c
View File

@ -18,8 +18,10 @@
#include <assert.h>
#include <stdio.h>
#include "buffer.h"
#include "edef.h"
#include "log.h"
#include "window.h"
#define BLOCK_SIZE 16 /* Line block chunk size. */

3
log.c
View File

@ -1,8 +1,5 @@
#include "log.h"
#include "retcode.h"
static void logdump( const char *buf, ...) {
}

1
main.c
View File

@ -74,6 +74,7 @@
#include "search.h"
#include "termio.h"
#include "version.h"
#include "window.h"
/* For MSDOS, increase the default stack space. */
#if MSDOS & TURBO

View File

@ -12,6 +12,7 @@
#include <stdio.h>
#include "basic.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h"
#include "edef.h"
@ -20,6 +21,7 @@
#include "line.h"
#include "log.h"
#include "search.h"
#include "window.h"
int tabsize; /* Tab size (0: use real tabs) */

View File

@ -12,10 +12,12 @@
#include <stdio.h>
#include "buffer.h"
#include "estruct.h"
#include "edef.h"
#include "line.h"
#include "log.h"
#include "window.h"
/*
* Kill the region. Ask "getregion"

View File

@ -63,12 +63,14 @@
#include <stdio.h>
#include "basic.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h"
#include "edef.h"
#include "input.h"
#include "line.h"
#include "log.h"
#include "window.h"
#if defined(MAGIC)
/*

View File

@ -11,6 +11,8 @@
#include <stdio.h>
#include <unistd.h>
#include "defines.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h"

View File

@ -12,8 +12,9 @@
#include <stdio.h>
#include "basic.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h"
/* #include "estruct.h" */
#include "edef.h"
#include "execute.h"
#include "line.h"

View File

@ -1,7 +1,47 @@
#ifndef _WINDOW_H_
#define _WINDOW_H_
#include "estruct.h"
#include "defines.h" /* COLOR, SCROLLCODE */
#include "buffer.h" /* buffer, line */
/*
* There is a window structure allocated for every active display window. The
* windows are kept in a big list, in top to bottom screen order, with the
* listhead at "wheadp". Each window contains its own values of dot and mark.
* The flag field contains some bits that are set by commands to guide
* redisplay. Although this is a bit of a compromise in terms of decoupling,
* the full blown redisplay is just too expensive to run for every input
* character.
*/
struct window {
struct window *w_wndp; /* Next window */
struct buffer *w_bufp; /* Buffer displayed in window */
struct line *w_linep; /* Top line in the window */
struct line *w_dotp; /* Line containing "." */
struct line *w_markp; /* Line containing "mark" */
int w_doto; /* Byte offset for "." */
int w_marko; /* Byte offset for "mark" */
char w_toprow; /* Origin 0 top row of window */
char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
#if COLOR
char w_fcolor; /* current forground color */
char w_bcolor; /* current background color */
#endif
};
#define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */
#define WFEDIT 0x04 /* Editing within a line */
#define WFHARD 0x08 /* Better to a full display */
#define WFMODE 0x10 /* Update mode line. */
#define WFCOLR 0x20 /* Needs a color change */
#if SCROLLCODE
#define WFKILLS 0x40 /* something was deleted */
#define WFINS 0x80 /* something was inserted */
#endif
int reposition( int f, int n);
int redraw( int f, int n) ;

2
word.c
View File

@ -13,12 +13,14 @@
#include <stdio.h>
#include "basic.h"
#include "buffer.h"
#include "estruct.h"
#include "edef.h"
#include "line.h"
#include "log.h"
#include "random.h"
#include "region.h"
#include "window.h"
/* Word wrap on n-spaces. Back-over whatever precedes the point on the current
* line and stop on the first word-break or the beginning of the line. If we