From 9ec9176c81eefafd9ae3e9bc47c026e59a765556 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Wed, 25 Sep 2013 13:23:52 +0800 Subject: [PATCH] Centralize kill buffer code in line.c --- edef.h | 4 +--- estruct.h | 12 ------------ eval.c | 26 -------------------------- eval.h | 1 - globals.c | 4 +--- line.c | 42 ++++++++++++++++++++++++++++++++++++++++++ line.h | 2 ++ 7 files changed, 46 insertions(+), 45 deletions(-) diff --git a/edef.h b/edef.h index da2323a..26d8909 100644 --- a/edef.h +++ b/edef.h @@ -62,9 +62,7 @@ extern int abortc; /* current abort command char */ extern int quotec; /* quote char during mlreply() */ extern int tabmask; extern char *cname[]; /* names of colors */ -extern struct kill *kbufp; /* current kill buffer chunk pointer */ -extern struct kill *kbufh; /* kill buffer header pointer */ -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 */ diff --git a/estruct.h b/estruct.h index a725ff5..2bcd834 100644 --- a/estruct.h +++ b/estruct.h @@ -245,7 +245,6 @@ #define HUGE 1000 /* Huge number */ #define NLOCKS 100 /* max # of file locks active */ #define NCOLORS 8 /* number of supported colors */ -#define KBLOCK 250 /* sizeof kill buffer chunks */ #define CONTROL 0x10000000 /* Control flag, or'ed in */ #define META 0x20000000 /* Meta flag, or'ed in */ @@ -414,15 +413,4 @@ struct terminal { #define TTbacg (*term.t_setback) #endif -/* The editor holds deleted text chunks in the struct kill buffer. The - * kill buffer is logically a stream of ascii characters, however - * due to its unpredicatable size, it gets implemented as a linked - * list of chunks. (The d_ prefix is for "deleted" text, as k_ - * was taken up by the keycode structure). - */ -struct kill { - struct kill *d_next; /* Link to next chunk, NULL if last. */ - char d_chunk[KBLOCK]; /* Deleted text. */ -}; - #endif diff --git a/eval.c b/eval.c index 0f4b90e..b0165fb 100644 --- a/eval.c +++ b/eval.c @@ -438,8 +438,6 @@ char *gtusr(char *vname) return errorm; } -extern char *getkill(void); - /* * gtenv() * @@ -569,30 +567,6 @@ char *gtenv(char *vname) exit(-12); /* again, we should never get here */ } -/* - * return some of the contents of the kill buffer - */ -char *getkill(void) -{ - int size; /* max number of chars to return */ - static char value[NSTRING]; /* temp buffer for value */ - - if (kbufh == NULL) - /* no kill buffer....just a null string */ - value[0] = 0; - else { - /* copy in the contents... */ - if (kused < NSTRING) - size = kused; - else - size = NSTRING - 1; - strncpy(value, kbufh->d_chunk, size); - } - - /* and return the constructed value */ - return value; -} - /* * set a variable * diff --git a/eval.h b/eval.h index 29cec28..d2a7364 100644 --- a/eval.h +++ b/eval.h @@ -21,7 +21,6 @@ void varinit( void) ; char *gtfun( char *fname) ; char *gtusr( char *vname) ; char *gtenv( char *vname) ; -char *getkill( void) ; int setvar( int f, int n) ; char *itoa( int i) ; char *getval( char *token) ; diff --git a/globals.c b/globals.c index 40ba064..f082ab7 100644 --- a/globals.c +++ b/globals.c @@ -76,9 +76,7 @@ char *cname[] = { /* names of colors */ , "HIGH" #endif }; -struct kill *kbufp = NULL; /* current kill buffer chunk pointer */ -struct kill *kbufh = NULL; /* kill buffer header pointer */ -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 */ diff --git a/line.c b/line.c index 11cf6d5..252688b 100644 --- a/line.c +++ b/line.c @@ -27,6 +27,48 @@ static int ldelnewline( void) ; +/* The editor holds deleted text chunks in the struct kill buffer. The + * kill buffer is logically a stream of ascii characters, however + * due to its unpredicatable size, it gets implemented as a linked + * list of chunks. (The d_ prefix is for "deleted" text, as k_ + * was taken up by the keycode structure). + */ + +#define KBLOCK 250 /* sizeof kill buffer chunks */ + +struct kill { + struct kill *d_next; /* Link to next chunk, NULL if last. */ + char d_chunk[KBLOCK]; /* Deleted text. */ +}; + +static struct kill *kbufp = NULL ; /* current kill buffer chunk pointer */ +static struct kill *kbufh = NULL ; /* kill buffer header pointer */ +static int kused = KBLOCK ; /* # of bytes used in kill buffer */ + +/* + * return some of the contents of the kill buffer + */ +char *getkill( void) +{ + int size; /* max number of chars to return */ + static char value[NSTRING]; /* temp buffer for value */ + + if (kbufh == NULL) + /* no kill buffer....just a null string */ + value[0] = 0; + else { + /* copy in the contents... */ + if (kused < NSTRING) + size = kused; + else + size = NSTRING - 1; + strncpy(value, kbufh->d_chunk, size); + } + + /* and return the constructed value */ + return value; +} + /* * Move the cursor backwards by "n" characters. If "n" is less than zero call * "forwchar" to actually do the move. Otherwise compute the new cursor diff --git a/line.h b/line.h index 248adb3..cdcc55e 100644 --- a/line.h +++ b/line.h @@ -25,6 +25,8 @@ struct line { #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c)) #define llength(lp) ((lp)->l_used) +char *getkill( void) ; + int backchar( int f, int n) ; int forwchar( int f, int n) ;