From 87cd40ce6a597d7d31487ed35f6836c1f6a17b8e Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Fri, 20 Sep 2013 18:10:30 +0800 Subject: [PATCH] Extract struct buffer and struct window from estruct.h. --- basic.c | 2 ++ bindable.c | 1 + buffer.c | 4 +-- buffer.h | 58 ++++++++++++++++++++++++++++++++- crypt.c | 2 -- crypt.h | 6 ++-- defines.h | 6 ++-- display.c | 1 + edef.h | 13 +++++++- estruct.h | 94 +++--------------------------------------------------- exec.c | 1 + exec.h | 1 + execute.c | 1 + file.c | 2 +- file.h | 7 ++-- fileio.c | 5 ++- fileio.h | 8 ++--- globals.c | 7 ++-- isearch.c | 3 +- line.c | 2 ++ log.c | 3 -- main.c | 1 + random.c | 2 ++ region.c | 2 ++ search.c | 2 ++ spawn.c | 2 ++ window.c | 3 +- window.h | 42 +++++++++++++++++++++++- word.c | 2 ++ 29 files changed, 163 insertions(+), 120 deletions(-) diff --git a/basic.c b/basic.c index 73bc4c7..dd8f2a7 100644 --- a/basic.c +++ b/basic.c @@ -15,6 +15,7 @@ #include +#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" /* diff --git a/bindable.c b/bindable.c index 2dd341a..b23f431 100644 --- a/bindable.c +++ b/bindable.c @@ -1,6 +1,7 @@ /* bindable.h -- implements bindable.c */ #include "bindable.h" +#include "defines.h" #include "buffer.h" #include "display.h" #include "edef.h" diff --git a/buffer.c b/buffer.c index acddc03..495fa93 100644 --- a/buffer.c +++ b/buffer.c @@ -14,12 +14,12 @@ #include +#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" diff --git a/buffer.h b/buffer.h index 2118c44..6eb70e3 100644 --- a/buffer.h +++ b/buffer.h @@ -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) ; diff --git a/crypt.c b/crypt.c index 27d78b7..3384410 100644 --- a/crypt.c +++ b/crypt.c @@ -1,7 +1,5 @@ /* crypt.c -- implements crypt.h */ -#include "defines.h" - #include "crypt.h" /* CRYPT.C diff --git a/crypt.h b/crypt.h index dd7bea3..e0ea3e9 100644 --- a/crypt.h +++ b/crypt.h @@ -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 diff --git a/defines.h b/defines.h index 73e7919..0c99915 100644 --- a/defines.h +++ b/defines.h @@ -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 diff --git a/display.c b/display.c index a27709a..d318504 100644 --- a/display.c +++ b/display.c @@ -17,6 +17,7 @@ #include #include +#include "buffer.h" #include "estruct.h" #include "edef.h" #include "line.h" diff --git a/edef.h b/edef.h index feddb9a..da2323a 100644 --- a/edef.h +++ b/edef.h @@ -10,6 +10,7 @@ #ifndef EDEF_H_ #define EDEF_H_ +#include "buffer.h" #include "estruct.h" #include @@ -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 */ diff --git a/estruct.h b/estruct.h index fd8700a..87e71e1 100644 --- a/estruct.h +++ b/estruct.h @@ -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. diff --git a/exec.c b/exec.c index f9a4995..2a6fa25 100644 --- a/exec.c +++ b/exec.c @@ -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.... */ diff --git a/exec.h b/exec.h index 27f6b11..e0604c7 100644 --- a/exec.h +++ b/exec.h @@ -1,6 +1,7 @@ #ifndef _EXEC_H_ #define _EXEC_H_ +#include "buffer.h" #include "estruct.h" int namedcmd( int f, int n) ; diff --git a/execute.c b/execute.c index 7de8667..184893b 100644 --- a/execute.c +++ b/execute.c @@ -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 diff --git a/file.c b/file.c index 007972e..30a32c5 100644 --- a/file.c +++ b/file.c @@ -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" diff --git a/file.h b/file.h index 42f4e18..d60e264 100644 --- a/file.h +++ b/file.h @@ -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 diff --git a/fileio.c b/fileio.c index 2f0fd4e..070ca49 100644 --- a/fileio.c +++ b/fileio.c @@ -1,6 +1,5 @@ /* fileio.c -- implements fileio.h */ -#include "defines.h" #include "fileio.h" /* FILEIO.C @@ -15,9 +14,9 @@ #include #include -#if CRYPT -#include "crypt.h" +#include "defines.h" +#if CRYPT boolean is_crypted ; /* currently encrypting? */ #endif diff --git a/fileio.h b/fileio.h index 3afb4dc..3ee7ff2 100644 --- a/fileio.h +++ b/fileio.h @@ -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 diff --git a/globals.c b/globals.c index 0b35876..40ba064 100644 --- a/globals.c +++ b/globals.c @@ -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 */ diff --git a/isearch.c b/isearch.c index 39d2d70..2b07baf 100644 --- a/isearch.c +++ b/isearch.c @@ -27,13 +27,14 @@ #include #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) ; diff --git a/line.c b/line.c index ab50369..11cf6d5 100644 --- a/line.c +++ b/line.c @@ -18,8 +18,10 @@ #include #include +#include "buffer.h" #include "edef.h" #include "log.h" +#include "window.h" #define BLOCK_SIZE 16 /* Line block chunk size. */ diff --git a/log.c b/log.c index debf1b4..49d0189 100644 --- a/log.c +++ b/log.c @@ -1,8 +1,5 @@ #include "log.h" -#include "retcode.h" - - static void logdump( const char *buf, ...) { } diff --git a/main.c b/main.c index abe7f05..840ecfb 100644 --- a/main.c +++ b/main.c @@ -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 diff --git a/random.c b/random.c index dfbab69..2bcbcc1 100644 --- a/random.c +++ b/random.c @@ -12,6 +12,7 @@ #include #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) */ diff --git a/region.c b/region.c index 19e77f1..3a390b1 100644 --- a/region.c +++ b/region.c @@ -12,10 +12,12 @@ #include +#include "buffer.h" #include "estruct.h" #include "edef.h" #include "line.h" #include "log.h" +#include "window.h" /* * Kill the region. Ask "getregion" diff --git a/search.c b/search.c index 372a067..c242f1f 100644 --- a/search.c +++ b/search.c @@ -63,12 +63,14 @@ #include #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) /* diff --git a/spawn.c b/spawn.c index 6342b63..abe9cce 100644 --- a/spawn.c +++ b/spawn.c @@ -11,6 +11,8 @@ #include #include +#include "defines.h" + #include "buffer.h" #include "display.h" #include "estruct.h" diff --git a/window.c b/window.c index 2dbc0cf..f9cf8bf 100644 --- a/window.c +++ b/window.c @@ -12,8 +12,9 @@ #include #include "basic.h" +#include "buffer.h" #include "display.h" -#include "estruct.h" +/* #include "estruct.h" */ #include "edef.h" #include "execute.h" #include "line.h" diff --git a/window.h b/window.h index 5e0417c..60d17b2 100644 --- a/window.h +++ b/window.h @@ -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) ; diff --git a/word.c b/word.c index da3b456..8420912 100644 --- a/word.c +++ b/word.c @@ -13,12 +13,14 @@ #include #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