2010-04-17 19:38:09 -04:00
|
|
|
/* line.c
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
|
|
|
* The functions in this file are a general set of line management utilities.
|
|
|
|
* They are the only routines that touch the text. They also touch the buffer
|
|
|
|
* and window structures, to make sure that the necessary updating gets done.
|
|
|
|
* There are routines in this file that handle the kill buffer too. It isn't
|
|
|
|
* here for any good reason.
|
|
|
|
*
|
|
|
|
* Note that this code only updates the dot and mark values in the window list.
|
|
|
|
* Since all the code acts on the current window, the buffer that we are
|
|
|
|
* editing must be being displayed, which means that "b_nwnd" is non zero,
|
|
|
|
* which means that the dot and mark values in the buffer headers are nonsense.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-14 21:10:03 -05:00
|
|
|
#include "line.h"
|
|
|
|
|
2013-09-14 10:01:16 -04:00
|
|
|
#include <assert.h>
|
2010-11-14 21:10:03 -05:00
|
|
|
#include <stdio.h>
|
2013-10-08 21:43:15 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-11-14 21:10:03 -05:00
|
|
|
|
2013-09-20 06:10:30 -04:00
|
|
|
#include "buffer.h"
|
2013-10-09 01:43:32 -04:00
|
|
|
#include "estruct.h"
|
2013-06-14 05:35:35 -04:00
|
|
|
#include "log.h"
|
2013-09-20 06:10:30 -04:00
|
|
|
#include "window.h"
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-09 23:42:33 -04:00
|
|
|
|
|
|
|
int tabmask = 0x07 ; /* tabulator mask */
|
|
|
|
|
2010-11-15 15:40:03 -05:00
|
|
|
#define BLOCK_SIZE 16 /* Line block chunk size. */
|
|
|
|
|
2013-06-06 01:08:32 -04:00
|
|
|
static int ldelnewline( void) ;
|
|
|
|
|
2013-09-25 01:23:52 -04:00
|
|
|
/* 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 */
|
2014-06-04 01:51:33 -04:00
|
|
|
static int klen ; /* length of kill buffer content */
|
|
|
|
static char *value = NULL ; /* temp buffer for value */
|
2013-09-25 01:23:52 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* return some of the contents of the kill buffer
|
|
|
|
*/
|
2014-06-04 01:51:33 -04:00
|
|
|
char *getkill( void) {
|
|
|
|
struct kill *kp ;
|
|
|
|
char *cp ;
|
2013-09-25 01:23:52 -04:00
|
|
|
|
|
|
|
if (kbufh == NULL)
|
|
|
|
/* no kill buffer....just a null string */
|
2014-06-04 01:51:33 -04:00
|
|
|
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 ;
|
2013-09-25 01:23:52 -04:00
|
|
|
else
|
2014-06-04 01:51:33 -04:00
|
|
|
size = kused ;
|
|
|
|
|
|
|
|
memcpy( cp, kp->d_chunk, size) ;
|
|
|
|
cp += size ;
|
2013-09-25 01:23:52 -04:00
|
|
|
}
|
2014-06-04 01:51:33 -04:00
|
|
|
|
|
|
|
*cp = 0 ;
|
2013-09-25 01:23:52 -04:00
|
|
|
|
|
|
|
/* and return the constructed value */
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-06-13 23:53:59 -04:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* location. Error if you try and move out of the buffer. Set the flag if the
|
|
|
|
* line pointer for dot changes.
|
|
|
|
*/
|
|
|
|
int backchar(int f, int n)
|
|
|
|
{
|
|
|
|
struct line *lp;
|
|
|
|
|
|
|
|
if (n < 0)
|
|
|
|
return forwchar(f, -n);
|
|
|
|
while (n--) {
|
|
|
|
if (curwp->w_doto == 0) {
|
|
|
|
if ((lp = lback(curwp->w_dotp)) == curbp->b_linep)
|
|
|
|
return FALSE;
|
|
|
|
curwp->w_dotp = lp;
|
|
|
|
curwp->w_doto = llength(lp);
|
|
|
|
curwp->w_flag |= WFMOVE;
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
unsigned char c;
|
|
|
|
curwp->w_doto--;
|
|
|
|
c = lgetc(curwp->w_dotp, curwp->w_doto);
|
|
|
|
if (is_beginning_utf8(c))
|
|
|
|
break;
|
|
|
|
} while (curwp->w_doto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move the cursor forwards by "n" characters. If "n" is less than zero call
|
|
|
|
* "backchar" to actually do the move. Otherwise compute the new cursor
|
|
|
|
* location, and move ".". Error if you try and move off the end of the
|
|
|
|
* buffer. Set the flag if the line pointer for dot changes.
|
|
|
|
*/
|
|
|
|
int forwchar(int f, int n)
|
|
|
|
{
|
|
|
|
if (n < 0)
|
|
|
|
return backchar(f, -n);
|
|
|
|
while (n--) {
|
|
|
|
int len = llength(curwp->w_dotp);
|
|
|
|
if (curwp->w_doto == len) {
|
|
|
|
if (curwp->w_dotp == curbp->b_linep)
|
|
|
|
return FALSE;
|
|
|
|
curwp->w_dotp = lforw(curwp->w_dotp);
|
|
|
|
curwp->w_doto = 0;
|
|
|
|
curwp->w_flag |= WFMOVE;
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
unsigned char c;
|
|
|
|
curwp->w_doto++;
|
|
|
|
c = lgetc(curwp->w_dotp, curwp->w_doto);
|
|
|
|
if (is_beginning_utf8(c))
|
|
|
|
break;
|
|
|
|
} while (curwp->w_doto < len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/*
|
2010-04-17 19:38:09 -04:00
|
|
|
* This routine allocates a block of memory large enough to hold a struct line
|
2005-05-31 11:50:56 -04:00
|
|
|
* containing "used" characters. The block is always rounded up a bit. Return
|
|
|
|
* a pointer to the new block, or NULL if there isn't any memory left. Print a
|
|
|
|
* message in the message line if no space.
|
|
|
|
*/
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lalloc(int used)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp;
|
2010-02-27 05:38:22 -05:00
|
|
|
int size;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2010-11-15 15:40:03 -05:00
|
|
|
size = (used + BLOCK_SIZE - 1) & ~(BLOCK_SIZE - 1);
|
|
|
|
if (size == 0) /* Assume that is an empty. */
|
|
|
|
size = BLOCK_SIZE; /* Line is for type-in. */
|
2010-04-17 19:38:09 -04:00
|
|
|
if ((lp = (struct line *)malloc(sizeof(struct line) + size)) == NULL) {
|
2015-01-21 08:30:01 -05:00
|
|
|
writestr( "(OUT OF MEMORY)") ;
|
2010-08-29 06:03:55 -04:00
|
|
|
return NULL;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
lp->l_size = size;
|
|
|
|
lp->l_used = used;
|
2010-08-29 06:03:55 -04:00
|
|
|
return lp;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete line "lp". Fix all of the links that might point at it (they are
|
|
|
|
* moved to offset 0 of the next line. Unlink the line from whatever buffer it
|
|
|
|
* might be in. Release the memory. The buffers are updated too; the magic
|
|
|
|
* conditions described in the above comments don't hold here.
|
|
|
|
*/
|
2010-04-17 19:38:09 -04:00
|
|
|
void lfree(struct line *lp)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
struct buffer *bp;
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_linep == lp)
|
|
|
|
wp->w_linep = lp->l_fp;
|
2005-09-30 18:26:09 -04:00
|
|
|
if (wp->w_dotp == lp) {
|
|
|
|
wp->w_dotp = lp->l_fp;
|
|
|
|
wp->w_doto = 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
if (wp->w_markp == lp) {
|
|
|
|
wp->w_markp = lp->l_fp;
|
|
|
|
wp->w_marko = 0;
|
|
|
|
}
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
bp = bheadp;
|
|
|
|
while (bp != NULL) {
|
|
|
|
if (bp->b_nwnd == 0) {
|
2005-09-30 18:26:09 -04:00
|
|
|
if (bp->b_dotp == lp) {
|
2005-05-31 11:50:56 -04:00
|
|
|
bp->b_dotp = lp->l_fp;
|
|
|
|
bp->b_doto = 0;
|
|
|
|
}
|
|
|
|
if (bp->b_markp == lp) {
|
|
|
|
bp->b_markp = lp->l_fp;
|
|
|
|
bp->b_marko = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bp = bp->b_bufp;
|
|
|
|
}
|
|
|
|
lp->l_bp->l_fp = lp->l_fp;
|
|
|
|
lp->l_fp->l_bp = lp->l_bp;
|
|
|
|
free((char *) lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine gets called when a character is changed in place in the current
|
|
|
|
* buffer. It updates all of the required flags in the buffer and window
|
|
|
|
* system. The flag used is passed as an argument; if the buffer is being
|
|
|
|
* displayed in more than 1 window we change EDIT t HARD. Set MODE if the
|
|
|
|
* mode line needs to be updated (the "*" has to be set).
|
|
|
|
*/
|
2005-10-01 03:22:55 -04:00
|
|
|
void lchange(int flag)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curbp->b_nwnd != 1) /* Ensure hard. */
|
2005-05-31 11:50:56 -04:00
|
|
|
flag = WFHARD;
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((curbp->b_flag & BFCHG) == 0) { /* First change, so */
|
|
|
|
flag |= WFMODE; /* update mode lines. */
|
2005-05-31 11:50:56 -04:00
|
|
|
curbp->b_flag |= BFCHG;
|
|
|
|
}
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_bufp == curbp)
|
|
|
|
wp->w_flag |= flag;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* insert spaces forward into text
|
|
|
|
*
|
|
|
|
* int f, n; default flag and numeric argument
|
|
|
|
*/
|
|
|
|
int insspace(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
linsert(n, ' ');
|
|
|
|
backchar(f, n);
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* linstr -- Insert a string at the current point
|
|
|
|
*/
|
|
|
|
|
2013-09-17 22:56:11 -04:00
|
|
|
int linstr( char *instr) {
|
|
|
|
int status = TRUE ;
|
|
|
|
|
|
|
|
if( instr != NULL) {
|
|
|
|
char tmpc ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-09-17 22:56:11 -04:00
|
|
|
while( (tmpc = *instr++)) {
|
2005-09-30 18:26:09 -04:00
|
|
|
status =
|
2013-09-17 22:56:11 -04:00
|
|
|
(tmpc == '\n' ? lnewline() : linsert( 1, tmpc)) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* Insertion error? */
|
2015-01-21 08:30:01 -05:00
|
|
|
if( status != TRUE) {
|
|
|
|
writestr( "%Out of memory while inserting") ;
|
|
|
|
return status ;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2013-09-17 22:56:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert "n" copies of the character "c" at the current location of dot. In
|
|
|
|
* the easy case all that happens is the text is stored in the line. In the
|
|
|
|
* hard case, the line has to be reallocated. When the window list is updated,
|
|
|
|
* take special care; I screwed it up once. You always update dot in the
|
|
|
|
* current window. You update mark, and a dot in another window, if it is
|
|
|
|
* greater than the place where you did the insert. Return TRUE if all is
|
|
|
|
* well, and FALSE on errors.
|
|
|
|
*/
|
|
|
|
|
2012-07-11 05:21:36 -04:00
|
|
|
static int linsert_byte(int n, int c)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
char *cp1;
|
|
|
|
char *cp2;
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp1;
|
|
|
|
struct line *lp2;
|
|
|
|
struct line *lp3;
|
2010-02-27 05:38:22 -05:00
|
|
|
int doto;
|
|
|
|
int i;
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-09-14 10:01:16 -04:00
|
|
|
assert( (curbp->b_mode & MDVIEW) == 0) ;
|
|
|
|
#if 0
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
2010-08-29 06:03:55 -04:00
|
|
|
return rdonly(); /* we are in read only mode */
|
2013-09-14 10:01:16 -04:00
|
|
|
#endif
|
2005-05-31 11:50:56 -04:00
|
|
|
lchange(WFEDIT);
|
2005-09-30 18:26:09 -04:00
|
|
|
lp1 = curwp->w_dotp; /* Current line */
|
|
|
|
if (lp1 == curbp->b_linep) { /* At the end: special */
|
2005-05-31 11:50:56 -04:00
|
|
|
if (curwp->w_doto != 0) {
|
2015-01-21 08:30:01 -05:00
|
|
|
writestr( "bug: linsert") ;
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((lp2 = lalloc(n)) == NULL) /* Allocate new line */
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-09-30 18:26:09 -04:00
|
|
|
lp3 = lp1->l_bp; /* Previous line */
|
|
|
|
lp3->l_fp = lp2; /* Link in */
|
2005-05-31 11:50:56 -04:00
|
|
|
lp2->l_fp = lp1;
|
|
|
|
lp1->l_bp = lp2;
|
|
|
|
lp2->l_bp = lp3;
|
2005-09-30 18:26:09 -04:00
|
|
|
for (i = 0; i < n; ++i)
|
2005-05-31 11:50:56 -04:00
|
|
|
lp2->l_text[i] = c;
|
|
|
|
curwp->w_dotp = lp2;
|
|
|
|
curwp->w_doto = n;
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
doto = curwp->w_doto; /* Save for later. */
|
|
|
|
if (lp1->l_used + n > lp1->l_size) { /* Hard: reallocate */
|
|
|
|
if ((lp2 = lalloc(lp1->l_used + n)) == NULL)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
cp1 = &lp1->l_text[0];
|
|
|
|
cp2 = &lp2->l_text[0];
|
|
|
|
while (cp1 != &lp1->l_text[doto])
|
|
|
|
*cp2++ = *cp1++;
|
|
|
|
cp2 += n;
|
|
|
|
while (cp1 != &lp1->l_text[lp1->l_used])
|
|
|
|
*cp2++ = *cp1++;
|
|
|
|
lp1->l_bp->l_fp = lp2;
|
|
|
|
lp2->l_fp = lp1->l_fp;
|
|
|
|
lp1->l_fp->l_bp = lp2;
|
|
|
|
lp2->l_bp = lp1->l_bp;
|
|
|
|
free((char *) lp1);
|
2005-09-30 18:26:09 -04:00
|
|
|
} else { /* Easy: in place */
|
|
|
|
lp2 = lp1; /* Pretend new line */
|
2005-05-31 11:50:56 -04:00
|
|
|
lp2->l_used += n;
|
|
|
|
cp2 = &lp1->l_text[lp1->l_used];
|
2005-09-30 18:26:09 -04:00
|
|
|
cp1 = cp2 - n;
|
2005-05-31 11:50:56 -04:00
|
|
|
while (cp1 != &lp1->l_text[doto])
|
|
|
|
*--cp2 = *--cp1;
|
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
for (i = 0; i < n; ++i) /* Add the characters */
|
|
|
|
lp2->l_text[doto + i] = c;
|
|
|
|
wp = wheadp; /* Update windows */
|
2005-05-31 11:50:56 -04:00
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_linep == lp1)
|
|
|
|
wp->w_linep = lp2;
|
|
|
|
if (wp->w_dotp == lp1) {
|
|
|
|
wp->w_dotp = lp2;
|
2005-09-30 18:26:09 -04:00
|
|
|
if (wp == curwp || wp->w_doto > doto)
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_doto += n;
|
|
|
|
}
|
|
|
|
if (wp->w_markp == lp1) {
|
|
|
|
wp->w_markp = lp2;
|
|
|
|
if (wp->w_marko > doto)
|
|
|
|
wp->w_marko += n;
|
|
|
|
}
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2012-07-11 05:21:36 -04:00
|
|
|
int linsert(int n, int c)
|
|
|
|
{
|
|
|
|
char utf8[6];
|
2013-09-14 10:01:16 -04:00
|
|
|
int bytes, i ;
|
2012-07-11 05:21:36 -04:00
|
|
|
|
2013-09-14 10:01:16 -04:00
|
|
|
assert( n > 0) ;
|
|
|
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
|
|
|
return rdonly(); /* we are in read only mode */
|
|
|
|
|
|
|
|
bytes = unicode_to_utf8(c, utf8) ;
|
2012-07-11 05:21:36 -04:00
|
|
|
if (bytes == 1)
|
|
|
|
return linsert_byte(n, (unsigned char) utf8[0]);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < bytes; j++) {
|
|
|
|
unsigned char c = utf8[j];
|
|
|
|
if (!linsert_byte(1, c))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/*
|
|
|
|
* Overwrite a character into the current line at the current position
|
|
|
|
*
|
2005-09-30 19:34:11 -04:00
|
|
|
* int c; character to overwrite on current position
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2013-06-06 01:08:32 -04:00
|
|
|
static int lowrite(int c)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
if (curwp->w_doto < curwp->w_dotp->l_used &&
|
2005-09-30 18:26:09 -04:00
|
|
|
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
|
|
|
|
((curwp->w_doto) & tabmask) == tabmask))
|
2012-07-11 13:43:16 -04:00
|
|
|
ldelchar(1, FALSE);
|
2010-08-29 06:03:55 -04:00
|
|
|
return linsert(1, c);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lover -- Overwrite a string at the current point
|
|
|
|
*/
|
2013-09-17 22:56:11 -04:00
|
|
|
int lover( char *ostr) {
|
|
|
|
int status = TRUE ;
|
|
|
|
|
|
|
|
if (ostr != NULL) {
|
|
|
|
char tmpc ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-09-17 22:56:11 -04:00
|
|
|
while( (tmpc = *ostr++)) {
|
2005-09-30 18:26:09 -04:00
|
|
|
status =
|
|
|
|
(tmpc == '\n' ? lnewline() : lowrite(tmpc));
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* Insertion error? */
|
2015-01-21 08:30:01 -05:00
|
|
|
if( status != TRUE) {
|
|
|
|
writestr( "%Out of memory while overwriting") ;
|
|
|
|
return status ;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2013-09-17 22:56:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert a newline into the buffer at the current location of dot in the
|
|
|
|
* current window. The funny ass-backwards way it does things is not a botch;
|
|
|
|
* it just makes the last line in the file not a special case. Return TRUE if
|
|
|
|
* everything works out and FALSE on error (memory allocation failure). The
|
|
|
|
* update of dot and mark is a bit easier then in the above case, because the
|
|
|
|
* split forces more updating.
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int lnewline(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
char *cp1;
|
|
|
|
char *cp2;
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp1;
|
|
|
|
struct line *lp2;
|
2010-02-27 05:38:22 -05:00
|
|
|
int doto;
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
2010-08-29 06:03:55 -04:00
|
|
|
return rdonly(); /* we are in read only mode */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
lchange(WFHARD | WFINS);
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
|
|
|
lchange(WFHARD);
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
lp1 = curwp->w_dotp; /* Get the address and */
|
|
|
|
doto = curwp->w_doto; /* offset of "." */
|
|
|
|
if ((lp2 = lalloc(doto)) == NULL) /* New first half line */
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-09-30 18:26:09 -04:00
|
|
|
cp1 = &lp1->l_text[0]; /* Shuffle text around */
|
2005-05-31 11:50:56 -04:00
|
|
|
cp2 = &lp2->l_text[0];
|
|
|
|
while (cp1 != &lp1->l_text[doto])
|
|
|
|
*cp2++ = *cp1++;
|
|
|
|
cp2 = &lp1->l_text[0];
|
|
|
|
while (cp1 != &lp1->l_text[lp1->l_used])
|
|
|
|
*cp2++ = *cp1++;
|
|
|
|
lp1->l_used -= doto;
|
|
|
|
lp2->l_bp = lp1->l_bp;
|
|
|
|
lp1->l_bp = lp2;
|
|
|
|
lp2->l_bp->l_fp = lp2;
|
|
|
|
lp2->l_fp = lp1;
|
2005-09-30 18:26:09 -04:00
|
|
|
wp = wheadp; /* Windows */
|
2005-05-31 11:50:56 -04:00
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_linep == lp1)
|
|
|
|
wp->w_linep = lp2;
|
|
|
|
if (wp->w_dotp == lp1) {
|
|
|
|
if (wp->w_doto < doto)
|
|
|
|
wp->w_dotp = lp2;
|
|
|
|
else
|
|
|
|
wp->w_doto -= doto;
|
|
|
|
}
|
|
|
|
if (wp->w_markp == lp1) {
|
|
|
|
if (wp->w_marko < doto)
|
|
|
|
wp->w_markp = lp2;
|
|
|
|
else
|
|
|
|
wp->w_marko -= doto;
|
|
|
|
}
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2012-07-11 13:43:16 -04:00
|
|
|
int lgetchar(unicode_t *c)
|
|
|
|
{
|
|
|
|
int len = llength(curwp->w_dotp);
|
|
|
|
char *buf = curwp->w_dotp->l_text;
|
|
|
|
return utf8_to_unicode(buf, curwp->w_doto, len, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ldelete() really fundamentally works on bytes, not characters.
|
|
|
|
* It is used for things like "scan 5 words forwards, and remove
|
|
|
|
* the bytes we scanned".
|
|
|
|
*
|
|
|
|
* If you want to delete characters, use ldelchar().
|
|
|
|
*/
|
|
|
|
int ldelchar(long n, int kflag)
|
|
|
|
{
|
|
|
|
while (n-- > 0) {
|
|
|
|
unicode_t c;
|
|
|
|
if (!ldelete(lgetchar(&c), kflag))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/*
|
|
|
|
* This function deletes "n" bytes, starting at dot. It understands how do deal
|
|
|
|
* with end of lines, etc. It returns TRUE if all of the characters were
|
|
|
|
* deleted, and FALSE if they were not (because dot ran into the end of the
|
|
|
|
* buffer. The "kflag" is TRUE if the text should be put in the kill buffer.
|
2005-09-30 19:34:11 -04:00
|
|
|
*
|
|
|
|
* long n; # of chars to delete
|
|
|
|
* int kflag; put killed text in kill buffer flag
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int ldelete(long n, int kflag)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
char *cp1;
|
|
|
|
char *cp2;
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *dotp;
|
2010-02-27 05:38:22 -05:00
|
|
|
int doto;
|
|
|
|
int chunk;
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
2010-08-29 06:03:55 -04:00
|
|
|
return rdonly(); /* we are in read only mode */
|
2005-05-31 11:50:56 -04:00
|
|
|
while (n != 0) {
|
|
|
|
dotp = curwp->w_dotp;
|
|
|
|
doto = curwp->w_doto;
|
2005-09-30 18:26:09 -04:00
|
|
|
if (dotp == curbp->b_linep) /* Hit end of buffer. */
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-09-30 18:26:09 -04:00
|
|
|
chunk = dotp->l_used - doto; /* Size of chunk. */
|
2005-05-31 11:50:56 -04:00
|
|
|
if (chunk > n)
|
|
|
|
chunk = n;
|
2005-09-30 18:26:09 -04:00
|
|
|
if (chunk == 0) { /* End of line, merge. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
lchange(WFHARD | WFKILLS);
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
|
|
|
lchange(WFHARD);
|
|
|
|
#endif
|
|
|
|
if (ldelnewline() == FALSE
|
2005-09-30 18:26:09 -04:00
|
|
|
|| (kflag != FALSE && kinsert('\n') == FALSE))
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
--n;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lchange(WFEDIT);
|
2005-09-30 18:26:09 -04:00
|
|
|
cp1 = &dotp->l_text[doto]; /* Scrunch text. */
|
2005-05-31 11:50:56 -04:00
|
|
|
cp2 = cp1 + chunk;
|
2005-09-30 18:26:09 -04:00
|
|
|
if (kflag != FALSE) { /* Kill? */
|
2005-05-31 11:50:56 -04:00
|
|
|
while (cp1 != cp2) {
|
|
|
|
if (kinsert(*cp1) == FALSE)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
++cp1;
|
|
|
|
}
|
|
|
|
cp1 = &dotp->l_text[doto];
|
|
|
|
}
|
|
|
|
while (cp2 != &dotp->l_text[dotp->l_used])
|
|
|
|
*cp1++ = *cp2++;
|
|
|
|
dotp->l_used -= chunk;
|
2005-09-30 18:26:09 -04:00
|
|
|
wp = wheadp; /* Fix windows */
|
2005-05-31 11:50:56 -04:00
|
|
|
while (wp != NULL) {
|
2005-09-30 18:26:09 -04:00
|
|
|
if (wp->w_dotp == dotp && wp->w_doto >= doto) {
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_doto -= chunk;
|
|
|
|
if (wp->w_doto < doto)
|
|
|
|
wp->w_doto = doto;
|
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
if (wp->w_markp == dotp && wp->w_marko >= doto) {
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_marko -= chunk;
|
|
|
|
if (wp->w_marko < doto)
|
|
|
|
wp->w_marko = doto;
|
|
|
|
}
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
n -= chunk;
|
|
|
|
}
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* getctext: grab and return a string with the text of
|
|
|
|
* the current line
|
|
|
|
*/
|
|
|
|
char *getctext(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp; /* line to copy */
|
2010-02-27 05:38:22 -05:00
|
|
|
int size; /* length of line to return */
|
|
|
|
char *sp; /* string pointer into line */
|
|
|
|
char *dp; /* string pointer into returned line */
|
2005-05-31 11:50:56 -04:00
|
|
|
static char rline[NSTRING]; /* line to return */
|
|
|
|
|
|
|
|
/* find the contents of the current line and its length */
|
|
|
|
lp = curwp->w_dotp;
|
|
|
|
sp = lp->l_text;
|
|
|
|
size = lp->l_used;
|
|
|
|
if (size >= NSTRING)
|
|
|
|
size = NSTRING - 1;
|
|
|
|
|
|
|
|
/* copy it across */
|
|
|
|
dp = rline;
|
|
|
|
while (size--)
|
|
|
|
*dp++ = *sp++;
|
|
|
|
*dp = 0;
|
2010-08-29 06:03:55 -04:00
|
|
|
return rline;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a newline. Join the current line with the next line. If the next line
|
|
|
|
* is the magic header line always return TRUE; merging the last line with the
|
|
|
|
* header line can be thought of as always being a successful operation, even
|
|
|
|
* if nothing is done, and this makes the kill buffer work "right". Easy cases
|
|
|
|
* can be done by shuffling data around. Hard cases require that lines be moved
|
|
|
|
* about in memory. Return FALSE on error and TRUE if all looks ok. Called by
|
|
|
|
* "ldelete" only.
|
|
|
|
*/
|
2013-06-06 01:08:32 -04:00
|
|
|
static int ldelnewline(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
char *cp1;
|
|
|
|
char *cp2;
|
2010-04-17 19:38:09 -04:00
|
|
|
struct line *lp1;
|
|
|
|
struct line *lp2;
|
|
|
|
struct line *lp3;
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-09-14 10:01:16 -04:00
|
|
|
assert( (curbp->b_mode & MDVIEW) == 0) ;
|
|
|
|
#if 0
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
2010-08-29 06:03:55 -04:00
|
|
|
return rdonly(); /* we are in read only mode */
|
2013-09-14 10:01:16 -04:00
|
|
|
#endif
|
2005-05-31 11:50:56 -04:00
|
|
|
lp1 = curwp->w_dotp;
|
|
|
|
lp2 = lp1->l_fp;
|
2005-09-30 18:26:09 -04:00
|
|
|
if (lp2 == curbp->b_linep) { /* At the buffer end. */
|
|
|
|
if (lp1->l_used == 0) /* Blank line. */
|
2005-05-31 11:50:56 -04:00
|
|
|
lfree(lp1);
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
if (lp2->l_used <= lp1->l_size - lp1->l_used) {
|
2005-05-31 11:50:56 -04:00
|
|
|
cp1 = &lp1->l_text[lp1->l_used];
|
|
|
|
cp2 = &lp2->l_text[0];
|
|
|
|
while (cp2 != &lp2->l_text[lp2->l_used])
|
|
|
|
*cp1++ = *cp2++;
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_linep == lp2)
|
|
|
|
wp->w_linep = lp1;
|
|
|
|
if (wp->w_dotp == lp2) {
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_dotp = lp1;
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_doto += lp1->l_used;
|
|
|
|
}
|
|
|
|
if (wp->w_markp == lp2) {
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_markp = lp1;
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_marko += lp1->l_used;
|
|
|
|
}
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
lp1->l_used += lp2->l_used;
|
|
|
|
lp1->l_fp = lp2->l_fp;
|
|
|
|
lp2->l_fp->l_bp = lp1;
|
|
|
|
free((char *) lp2);
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((lp3 = lalloc(lp1->l_used + lp2->l_used)) == NULL)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
cp1 = &lp1->l_text[0];
|
|
|
|
cp2 = &lp3->l_text[0];
|
|
|
|
while (cp1 != &lp1->l_text[lp1->l_used])
|
|
|
|
*cp2++ = *cp1++;
|
|
|
|
cp1 = &lp2->l_text[0];
|
|
|
|
while (cp1 != &lp2->l_text[lp2->l_used])
|
|
|
|
*cp2++ = *cp1++;
|
|
|
|
lp1->l_bp->l_fp = lp3;
|
|
|
|
lp3->l_fp = lp2->l_fp;
|
|
|
|
lp2->l_fp->l_bp = lp3;
|
|
|
|
lp3->l_bp = lp1->l_bp;
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
2005-09-30 18:26:09 -04:00
|
|
|
if (wp->w_linep == lp1 || wp->w_linep == lp2)
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_linep = lp3;
|
|
|
|
if (wp->w_dotp == lp1)
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_dotp = lp3;
|
2005-05-31 11:50:56 -04:00
|
|
|
else if (wp->w_dotp == lp2) {
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_dotp = lp3;
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_doto += lp1->l_used;
|
|
|
|
}
|
|
|
|
if (wp->w_markp == lp1)
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_markp = lp3;
|
2005-05-31 11:50:56 -04:00
|
|
|
else if (wp->w_markp == lp2) {
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_markp = lp3;
|
2005-05-31 11:50:56 -04:00
|
|
|
wp->w_marko += lp1->l_used;
|
|
|
|
}
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
free((char *) lp1);
|
|
|
|
free((char *) lp2);
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete all of the text saved in the kill buffer. Called by commands when a
|
|
|
|
* new kill context is being created. The kill buffer array is released, just
|
|
|
|
* in case the buffer has grown to immense size. No errors.
|
|
|
|
*/
|
2005-10-01 03:22:55 -04:00
|
|
|
void kdelete(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-08-08 22:03:42 -04:00
|
|
|
struct kill *kp; /* ptr to scan kill buffer chunk list */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
if (kbufh != NULL) {
|
|
|
|
|
|
|
|
/* first, delete all the chunks */
|
|
|
|
kbufp = kbufh;
|
|
|
|
while (kbufp != NULL) {
|
|
|
|
kp = kbufp->d_next;
|
|
|
|
free(kbufp);
|
|
|
|
kbufp = kp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and reset all the kill buffer pointers */
|
|
|
|
kbufh = kbufp = NULL;
|
2005-09-30 18:26:09 -04:00
|
|
|
kused = KBLOCK;
|
2014-06-04 01:51:33 -04:00
|
|
|
klen = 0 ;
|
|
|
|
if( value != NULL) {
|
|
|
|
free( value) ;
|
|
|
|
value = NULL ;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert a character to the kill buffer, allocating new chunks as needed.
|
|
|
|
* Return TRUE if all is well, and FALSE on errors.
|
2005-09-30 19:34:11 -04:00
|
|
|
*
|
|
|
|
* int c; character to insert in the kill buffer
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int kinsert(int c)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-08-08 22:03:42 -04:00
|
|
|
struct kill *nchunk; /* ptr to newly malloced chunk */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* check to see if we need a new chunk */
|
|
|
|
if (kused >= KBLOCK) {
|
2010-08-08 22:03:42 -04:00
|
|
|
if ((nchunk = (struct kill *)malloc(sizeof(struct kill))) == NULL)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2014-06-04 01:51:33 -04:00
|
|
|
if( kbufh == NULL) { /* set head ptr if first time */
|
2005-05-31 11:50:56 -04:00
|
|
|
kbufh = nchunk;
|
2014-06-04 01:51:33 -04:00
|
|
|
klen = 0 ;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
if (kbufp != NULL) /* point the current to this new one */
|
|
|
|
kbufp->d_next = nchunk;
|
|
|
|
kbufp = nchunk;
|
|
|
|
kbufp->d_next = NULL;
|
|
|
|
kused = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and now insert the character */
|
|
|
|
kbufp->d_chunk[kused++] = c;
|
2014-06-04 01:51:33 -04:00
|
|
|
klen += 1 ;
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Yank text back from the kill buffer. This is really easy. All of the work
|
|
|
|
* is done by the standard insert routines. All you do is run the loop, and
|
|
|
|
* check for errors. Bound to "C-Y".
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int yank(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int c;
|
|
|
|
int i;
|
|
|
|
char *sp; /* pointer into string to insert */
|
2010-08-08 22:03:42 -04:00
|
|
|
struct kill *kp; /* pointer into kill buffer */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
2010-08-29 06:03:55 -04:00
|
|
|
return rdonly(); /* we are in read only mode */
|
2005-05-31 11:50:56 -04:00
|
|
|
if (n < 0)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
/* make sure there is something to yank */
|
|
|
|
if (kbufh == NULL)
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE; /* not an error, just nothing */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* for each time.... */
|
|
|
|
while (n--) {
|
|
|
|
kp = kbufh;
|
|
|
|
while (kp != NULL) {
|
|
|
|
if (kp->d_next == NULL)
|
|
|
|
i = kused;
|
|
|
|
else
|
|
|
|
i = KBLOCK;
|
|
|
|
sp = kp->d_chunk;
|
|
|
|
while (i--) {
|
|
|
|
if ((c = *sp++) == '\n') {
|
|
|
|
if (lnewline() == FALSE)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
} else {
|
2012-07-11 13:43:16 -04:00
|
|
|
if (linsert_byte(1, c) == FALSE)
|
2010-08-29 06:03:55 -04:00
|
|
|
return FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
kp = kp->d_next;
|
|
|
|
}
|
|
|
|
}
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|