$kill returns full copy of kill buffer.

This commit is contained in:
Renaud 2014-06-04 13:51:33 +08:00
parent 79b57c96d1
commit cc06049046
2 changed files with 45 additions and 13 deletions

45
line.c
View File

@ -49,26 +49,38 @@ struct kill {
static struct kill *kbufp = NULL ; /* current kill buffer chunk pointer */ static struct kill *kbufp = NULL ; /* current kill buffer chunk pointer */
static struct kill *kbufh = NULL ; /* kill buffer header pointer */ static struct kill *kbufh = NULL ; /* kill buffer header pointer */
static int kused = KBLOCK ; /* # of bytes used in kill buffer */ static int kused = KBLOCK ; /* # of bytes used in kill buffer */
static int klen ; /* length of kill buffer content */
static char *value = NULL ; /* temp buffer for value */
/* /*
* return some of the contents of the kill buffer * return some of the contents of the kill buffer
*/ */
char *getkill( void) char *getkill( void) {
{ struct kill *kp ;
int size; /* max number of chars to return */ char *cp ;
static char value[NSTRING]; /* temp buffer for value */
if (kbufh == NULL) if (kbufh == NULL)
/* no kill buffer....just a null string */ /* no kill buffer....just a null string */
value[0] = 0; return "" ;
else {
/* copy in the contents... */ if( value != NULL)
if( kbufh == kbufp && kused < NSTRING) free( value) ;
size = kused;
value = (char *) malloc( klen + 1) ;
cp = value ;
for( kp = kbufh ; kp != NULL ; kp = kp->d_next) {
int size ;
if( kp->d_next != NULL)
size = KBLOCK ;
else else
size = NSTRING - 1; size = kused ;
strncpy(value, kbufh->d_chunk, size);
memcpy( cp, kp->d_chunk, size) ;
cp += size ;
} }
*cp = 0 ;
/* and return the constructed value */ /* and return the constructed value */
return value; return value;
@ -712,6 +724,11 @@ void kdelete(void)
/* and reset all the kill buffer pointers */ /* and reset all the kill buffer pointers */
kbufh = kbufp = NULL; kbufh = kbufp = NULL;
kused = KBLOCK; kused = KBLOCK;
klen = 0 ;
if( value != NULL) {
free( value) ;
value = NULL ;
}
} }
} }
@ -729,8 +746,11 @@ int kinsert(int c)
if (kused >= KBLOCK) { if (kused >= KBLOCK) {
if ((nchunk = (struct kill *)malloc(sizeof(struct kill))) == NULL) if ((nchunk = (struct kill *)malloc(sizeof(struct kill))) == NULL)
return FALSE; return FALSE;
if (kbufh == NULL) /* set head ptr if first time */ if( kbufh == NULL) { /* set head ptr if first time */
kbufh = nchunk; kbufh = nchunk;
klen = 0 ;
}
if (kbufp != NULL) /* point the current to this new one */ if (kbufp != NULL) /* point the current to this new one */
kbufp->d_next = nchunk; kbufp->d_next = nchunk;
kbufp = nchunk; kbufp = nchunk;
@ -740,6 +760,7 @@ int kinsert(int c)
/* and now insert the character */ /* and now insert the character */
kbufp->d_chunk[kused++] = c; kbufp->d_chunk[kused++] = c;
klen += 1 ;
return TRUE; return TRUE;
} }

View File

@ -3,6 +3,8 @@ insert-string &env PATH
newline newline
insert-string $PATH insert-string $PATH
newline newline
insert-string &cat $PATH $PATH
newline
set %mypath $PATH set %mypath $PATH
insert-string %mypath insert-string %mypath
newline newline
@ -11,6 +13,12 @@ newline
; Insert string with escaped characters ; Insert string with escaped characters
insert-string "hello, world~n" insert-string "hello, world~n"
newline newline
; Insert 512 long token [will be truncated to sizeof istring buffer - 2 (510)]
insert-string 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
newline
; Insert 512 long quoted string [will be truncated to sizeof istring buffer - 3 (509)]
insert-string "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
newline
; Insert long quoted string [will be truncated to NSTRING - 2 (126)] ; Insert long quoted string [will be truncated to NSTRING - 2 (126)]
insert-string "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" insert-string "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
next-line next-line
@ -55,4 +63,7 @@ yank
insert-string $kill insert-string $kill
save-file save-file
beginning-of-file beginning-of-file
set-mark
end-of-file
copy-region
insert-string $kill