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

View File

@ -3,6 +3,8 @@ insert-string &env PATH
newline
insert-string $PATH
newline
insert-string &cat $PATH $PATH
newline
set %mypath $PATH
insert-string %mypath
newline
@ -11,6 +13,12 @@ newline
; Insert string with escaped characters
insert-string "hello, world~n"
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-string "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
next-line
@ -55,4 +63,7 @@ yank
insert-string $kill
save-file
beginning-of-file
set-mark
end-of-file
copy-region
insert-string $kill