2000-08-06 21:13:45 +00:00
|
|
|
/* $Id$ */
|
2000-06-06 05:53:49 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* cut.c *
|
|
|
|
* *
|
2002-01-04 17:57:40 +00:00
|
|
|
* Copyright (C) 1999-2002 Chris Allegretta *
|
2000-06-06 05:53:49 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
2001-10-24 11:33:54 +00:00
|
|
|
* the Free Software Foundation; either version 2, or (at your option) *
|
2000-06-06 05:53:49 +00:00
|
|
|
* any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2001-04-28 18:03:52 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "proto.h"
|
|
|
|
#include "nano.h"
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
#include <libintl.h>
|
|
|
|
#define _(string) gettext(string)
|
|
|
|
#else
|
|
|
|
#define _(string) (string)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int marked_cut; /* Is the cutbuffer from a mark */
|
|
|
|
static filestruct *cutbottom = NULL; /* Pointer to end of cutbuffer */
|
|
|
|
|
|
|
|
void add_to_cutbuffer(filestruct * inptr)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, _("add_to_cutbuffer called with inptr->data = %s\n"),
|
|
|
|
inptr->data);
|
|
|
|
#endif
|
|
|
|
|
2000-06-09 00:52:26 +00:00
|
|
|
totsize -= strlen(inptr->data);
|
2000-06-06 05:53:49 +00:00
|
|
|
if (cutbuffer == NULL) {
|
|
|
|
cutbuffer = inptr;
|
|
|
|
inptr->prev = NULL;
|
|
|
|
} else {
|
|
|
|
cutbottom->next = inptr;
|
|
|
|
inptr->prev = cutbottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
inptr->next = NULL;
|
|
|
|
cutbottom = inptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
2001-06-21 15:07:40 +00:00
|
|
|
/* Cut a marked segment instead of a whole line. Only called from
|
|
|
|
do_cut_text().
|
2001-05-29 04:21:44 +00:00
|
|
|
destructive is whether to actually modify the file structure, if not then
|
|
|
|
just copy the buffer into cutbuffer and don't pull it from the file */
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
void cut_marked_segment(filestruct * top, int top_x, filestruct * bot,
|
2001-05-29 04:21:44 +00:00
|
|
|
int bot_x, int destructive)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2001-05-17 03:41:00 +00:00
|
|
|
filestruct *tmp, *next, *botcopy;
|
2000-06-06 05:53:49 +00:00
|
|
|
char *tmpstr;
|
2001-06-21 23:58:47 +00:00
|
|
|
int newsize;
|
|
|
|
|
|
|
|
/* Special case for cutting part of one line */
|
|
|
|
if (top == bot) {
|
|
|
|
int swap;
|
|
|
|
|
|
|
|
tmp = copy_node(top);
|
|
|
|
newsize = abs(bot_x - top_x) + 1;
|
|
|
|
tmpstr = charalloc(newsize + 1);
|
|
|
|
|
|
|
|
/* Make top_x always be before bot_x */
|
|
|
|
if (top_x > bot_x) {
|
|
|
|
swap = top_x;
|
|
|
|
top_x = bot_x;
|
|
|
|
bot_x = swap;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(tmpstr, &top->data[top_x], newsize);
|
|
|
|
|
|
|
|
if (destructive) {
|
|
|
|
memmove(&top->data[top_x], &top->data[bot_x],
|
|
|
|
strlen(&top->data[bot_x]) + 1);
|
|
|
|
align(&top->data);
|
|
|
|
current_x = top_x;
|
|
|
|
update_cursor();
|
|
|
|
}
|
|
|
|
tmpstr[newsize - 1] = 0;
|
|
|
|
tmp->data = tmpstr;
|
|
|
|
add_to_cutbuffer(tmp);
|
|
|
|
dump_buffer(cutbuffer);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
/* Set up the beginning of the cutbuffer */
|
|
|
|
tmp = copy_node(top);
|
2001-05-17 11:35:43 +00:00
|
|
|
tmpstr = charalloc(strlen(&top->data[top_x]) + 1);
|
2000-06-06 05:53:49 +00:00
|
|
|
strcpy(tmpstr, &top->data[top_x]);
|
|
|
|
free(tmp->data);
|
|
|
|
tmp->data = tmpstr;
|
|
|
|
|
|
|
|
/* Chop off the end of the first line */
|
2001-05-17 11:35:43 +00:00
|
|
|
tmpstr = charalloc(top_x + 1);
|
2000-06-06 05:53:49 +00:00
|
|
|
strncpy(tmpstr, top->data, top_x);
|
2001-05-29 04:21:44 +00:00
|
|
|
|
|
|
|
if (destructive) {
|
|
|
|
free(top->data);
|
|
|
|
top->data = tmpstr;
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
next = tmp->next;
|
2001-05-29 04:21:44 +00:00
|
|
|
if (destructive)
|
|
|
|
add_to_cutbuffer(tmp);
|
|
|
|
else {
|
|
|
|
filestruct *tmpcopy = NULL;
|
|
|
|
|
|
|
|
tmpcopy = copy_node(tmp);
|
|
|
|
add_to_cutbuffer(tmpcopy);
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
totlines--;
|
2000-06-21 03:00:43 +00:00
|
|
|
totsize--; /* newline (add_to_cutbuffer doesn't count newlines) */
|
2000-06-06 05:53:49 +00:00
|
|
|
tmp = next;
|
|
|
|
}
|
|
|
|
while (next != bot && next != NULL);
|
|
|
|
|
|
|
|
dump_buffer(cutbuffer);
|
|
|
|
if (next == NULL)
|
|
|
|
return;
|
|
|
|
|
2001-05-29 04:21:44 +00:00
|
|
|
/* Now, paste bot[bot_x] into top[top_x] */
|
|
|
|
if (destructive) {
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2001-10-23 12:58:42 +00:00
|
|
|
tmpstr = charalloc(top_x + strlen(&bot->data[bot_x]) + 1);
|
2001-05-29 04:21:44 +00:00
|
|
|
strncpy(tmpstr, top->data, top_x);
|
|
|
|
strcpy(&tmpstr[top_x], &bot->data[bot_x]);
|
|
|
|
free(top->data);
|
|
|
|
top->data = tmpstr;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2001-05-29 04:21:44 +00:00
|
|
|
/* We explicitly don't decrement totlines here because we don't snarf
|
|
|
|
* up a newline when we're grabbing the last line of the mark. For
|
|
|
|
* the same reason, we don't do an extra totsize decrement. */
|
|
|
|
}
|
2001-05-17 03:41:00 +00:00
|
|
|
|
|
|
|
/* I honestly do not know why this is needed. After many hours of
|
2001-05-29 04:21:44 +00:00
|
|
|
using gdb on an OpenBSD box, I can honestly say something is
|
|
|
|
screwed somewhere. Not doing this causes update_line to annihilate
|
|
|
|
the last line copied into the cutbuffer when the mark is set ?!?!? */
|
2001-05-17 03:41:00 +00:00
|
|
|
botcopy = copy_node(bot);
|
2001-10-22 23:22:19 +00:00
|
|
|
null_at(&botcopy->data, bot_x);
|
2001-05-29 04:21:44 +00:00
|
|
|
next = botcopy->next;
|
2001-05-17 03:41:00 +00:00
|
|
|
add_to_cutbuffer(botcopy);
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2001-05-29 04:21:44 +00:00
|
|
|
if (destructive) {
|
|
|
|
free(bot);
|
|
|
|
|
|
|
|
top->next = next;
|
|
|
|
if (next != NULL)
|
|
|
|
next->prev = top;
|
|
|
|
|
|
|
|
dump_buffer(cutbuffer);
|
|
|
|
renumber(top);
|
|
|
|
current = top;
|
|
|
|
current_x = top_x;
|
|
|
|
|
|
|
|
/* If we're hitting the end of the buffer, we should clean that up. */
|
|
|
|
if (bot == filebot) {
|
|
|
|
if (next != NULL) {
|
|
|
|
filebot = next;
|
|
|
|
} else {
|
|
|
|
filebot = top;
|
2001-10-02 00:24:37 +00:00
|
|
|
if (top_x > 0)
|
|
|
|
new_magicline();
|
2001-05-29 04:21:44 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
2001-05-29 04:21:44 +00:00
|
|
|
if (top->lineno < edittop->lineno)
|
|
|
|
edit_update(top, CENTER);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
2001-10-22 03:15:31 +00:00
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int do_cut_text(void)
|
|
|
|
{
|
|
|
|
filestruct *tmp, *fileptr = current;
|
|
|
|
#ifndef NANO_SMALL
|
2001-10-22 03:15:31 +00:00
|
|
|
int dontupdate = 0;
|
2001-06-21 23:58:47 +00:00
|
|
|
int cuttingtoend = 0;
|
2000-06-06 05:53:49 +00:00
|
|
|
#endif
|
|
|
|
|
2001-06-21 15:07:40 +00:00
|
|
|
|
2000-08-07 14:39:32 +00:00
|
|
|
check_statblank();
|
2000-08-07 14:58:26 +00:00
|
|
|
if (fileptr == NULL || fileptr->data == NULL)
|
2000-06-06 05:53:49 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
tmp = fileptr->next;
|
|
|
|
|
2000-07-27 04:09:23 +00:00
|
|
|
if (!ISSET(KEEP_CUTBUFFER)) {
|
2000-06-06 05:53:49 +00:00
|
|
|
free_filestruct(cutbuffer);
|
|
|
|
cutbuffer = NULL;
|
2000-07-27 04:09:23 +00:00
|
|
|
|
2001-06-21 15:07:40 +00:00
|
|
|
marked_cut = 0;
|
2000-06-06 05:53:49 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, _("Blew away cutbuffer =)\n"));
|
|
|
|
#endif
|
|
|
|
}
|
2000-08-07 14:58:26 +00:00
|
|
|
|
|
|
|
/* Must let cutbuffer get blown away first before we do this... */
|
2000-10-26 01:44:42 +00:00
|
|
|
if (fileptr == filebot && !ISSET(MARK_ISSET))
|
2000-08-07 14:58:26 +00:00
|
|
|
return 0;
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
#ifndef NANO_SMALL
|
2000-07-24 18:28:30 +00:00
|
|
|
if (ISSET(CUT_TO_END) && !ISSET(MARK_ISSET)) {
|
2000-10-26 01:44:42 +00:00
|
|
|
if (current_x == strlen(current->data)) {
|
2001-06-10 20:41:20 +00:00
|
|
|
|
2001-06-21 15:07:40 +00:00
|
|
|
/* If the line is empty and we didn't just cut a non-blank
|
2001-06-12 23:22:26 +00:00
|
|
|
line, create a dummy line and add it to the cutbuffer */
|
2001-06-22 21:47:23 +00:00
|
|
|
if (marked_cut != 1 && current->next != filebot) {
|
2001-06-21 15:07:40 +00:00
|
|
|
|
2001-06-10 20:41:20 +00:00
|
|
|
filestruct *junk;
|
|
|
|
|
2001-06-21 15:07:40 +00:00
|
|
|
junk = NULL;
|
|
|
|
junk = make_new_node(current);
|
2002-02-15 19:17:02 +00:00
|
|
|
junk->data = charalloc(1);
|
2001-06-21 15:07:40 +00:00
|
|
|
junk->data[0] = 0;
|
2001-06-11 06:56:10 +00:00
|
|
|
|
2001-06-10 20:41:20 +00:00
|
|
|
add_to_cutbuffer(junk);
|
2001-06-21 15:07:40 +00:00
|
|
|
dump_buffer(cutbuffer);
|
|
|
|
|
2001-06-10 20:41:20 +00:00
|
|
|
}
|
2001-06-21 15:07:40 +00:00
|
|
|
|
2000-07-25 03:20:07 +00:00
|
|
|
do_delete();
|
2000-07-27 04:09:23 +00:00
|
|
|
SET(KEEP_CUTBUFFER);
|
2000-07-27 04:31:52 +00:00
|
|
|
marked_cut = 2;
|
2000-07-25 03:20:07 +00:00
|
|
|
return 1;
|
2000-10-26 01:44:42 +00:00
|
|
|
} else {
|
2000-07-25 03:20:07 +00:00
|
|
|
SET(MARK_ISSET);
|
|
|
|
SET(KEEP_CUTBUFFER);
|
|
|
|
|
|
|
|
mark_beginx = strlen(current->data);
|
|
|
|
mark_beginbuf = current;
|
|
|
|
cuttingtoend = 1;
|
|
|
|
}
|
2000-07-12 02:09:17 +00:00
|
|
|
}
|
2001-10-22 03:15:31 +00:00
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
if (ISSET(MARK_ISSET)) {
|
2001-10-02 23:55:09 +00:00
|
|
|
if (current->lineno <= mark_beginbuf->lineno) {
|
2001-10-22 03:15:31 +00:00
|
|
|
/* Don't do_update and move the screen position if the marked
|
|
|
|
area lies entirely within the screen buffer */
|
|
|
|
if (current->lineno == mark_beginbuf->lineno
|
|
|
|
|| (current->lineno >= edittop->lineno
|
|
|
|
&& mark_beginbuf->lineno <= editbot->lineno))
|
|
|
|
dontupdate = 1;
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
cut_marked_segment(current, current_x, mark_beginbuf,
|
2001-05-29 04:21:44 +00:00
|
|
|
mark_beginx, 1);
|
2001-10-02 23:55:09 +00:00
|
|
|
}
|
2001-10-22 03:15:31 +00:00
|
|
|
else {
|
|
|
|
/* Same as above, easier logic since we know it's a multi-line
|
|
|
|
cut and mark_beginbuf is before current */
|
|
|
|
if (mark_beginbuf->lineno >= edittop->lineno
|
|
|
|
&& current->lineno <= editbot->lineno)
|
|
|
|
dontupdate = 1;
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
cut_marked_segment(mark_beginbuf, mark_beginx, current,
|
2001-05-29 04:21:44 +00:00
|
|
|
current_x, 1);
|
2001-10-22 03:15:31 +00:00
|
|
|
}
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
placewewant = xplustabs();
|
|
|
|
UNSET(MARK_ISSET);
|
2000-07-27 04:09:23 +00:00
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
marked_cut = 1;
|
|
|
|
set_modified();
|
2001-10-22 03:15:31 +00:00
|
|
|
if (dontupdate || cuttingtoend) {
|
|
|
|
fix_editbot();
|
2000-07-25 03:20:07 +00:00
|
|
|
edit_refresh();
|
2001-10-22 03:15:31 +00:00
|
|
|
} else
|
2000-07-29 04:33:38 +00:00
|
|
|
edit_update(current, CENTER);
|
2000-07-27 04:31:52 +00:00
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
if (0) {
|
|
|
|
#endif
|
|
|
|
} else if (fileptr == fileage) {
|
|
|
|
/* we're cutting the first line */
|
|
|
|
if (fileptr->next != NULL) {
|
|
|
|
fileptr = fileptr->next;
|
|
|
|
tmp = fileptr;
|
|
|
|
fileage = fileptr;
|
|
|
|
add_to_cutbuffer(fileptr->prev);
|
2000-10-26 01:44:42 +00:00
|
|
|
totsize--; /* get the newline */
|
2000-06-06 05:53:49 +00:00
|
|
|
totlines--;
|
|
|
|
fileptr->prev = NULL;
|
|
|
|
current = fileptr;
|
2000-08-05 16:03:19 +00:00
|
|
|
edit_update(fileage, CENTER);
|
2000-06-06 05:53:49 +00:00
|
|
|
} else {
|
|
|
|
add_to_cutbuffer(fileptr);
|
|
|
|
fileage = make_new_node(NULL);
|
2001-05-17 11:35:43 +00:00
|
|
|
fileage->data = charalloc(1);
|
2000-06-09 00:52:26 +00:00
|
|
|
fileage->data[0] = '\0';
|
2000-06-06 05:53:49 +00:00
|
|
|
current = fileage;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fileptr->prev != NULL)
|
|
|
|
fileptr->prev->next = fileptr->next;
|
|
|
|
|
|
|
|
if (fileptr->next != NULL) {
|
|
|
|
(fileptr->next)->prev = fileptr->prev;
|
|
|
|
current = fileptr->next;
|
|
|
|
totlines--;
|
2000-10-26 01:44:42 +00:00
|
|
|
totsize--; /* get the newline */
|
|
|
|
}
|
|
|
|
/* No longer an else here, because we never get here anymore...
|
|
|
|
No need to cut the magic line, as it's empty */
|
2000-06-06 05:53:49 +00:00
|
|
|
add_to_cutbuffer(fileptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileptr == edittop)
|
|
|
|
edittop = current;
|
|
|
|
|
|
|
|
edit_refresh();
|
|
|
|
|
|
|
|
dump_buffer(cutbuffer);
|
|
|
|
reset_cursor();
|
|
|
|
|
|
|
|
set_modified();
|
|
|
|
marked_cut = 0;
|
|
|
|
current_x = 0;
|
|
|
|
placewewant = 0;
|
|
|
|
update_cursor();
|
|
|
|
renumber(tmp);
|
|
|
|
SET(KEEP_CUTBUFFER);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_uncut_text(void)
|
|
|
|
{
|
2000-12-10 17:03:25 +00:00
|
|
|
filestruct *tmp = current, *fileptr = current, *newbuf, *newend;
|
2000-06-06 05:53:49 +00:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
char *tmpstr, *tmpstr2;
|
2000-12-10 17:03:25 +00:00
|
|
|
filestruct *hold = current;
|
2000-06-06 05:53:49 +00:00
|
|
|
#endif
|
|
|
|
int i;
|
|
|
|
|
|
|
|
wrap_reset();
|
2000-08-07 14:39:32 +00:00
|
|
|
check_statblank();
|
2000-06-06 05:53:49 +00:00
|
|
|
if (cutbuffer == NULL || fileptr == NULL)
|
|
|
|
return 0; /* AIEEEEEEEEEEEE */
|
|
|
|
|
|
|
|
newbuf = copy_filestruct(cutbuffer);
|
|
|
|
for (newend = newbuf; newend->next != NULL && newend != NULL;
|
|
|
|
newend = newend->next) {
|
|
|
|
totlines++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hook newbuf into fileptr */
|
|
|
|
#ifndef NANO_SMALL
|
2000-07-27 04:31:52 +00:00
|
|
|
if (marked_cut) {
|
2000-06-06 05:53:49 +00:00
|
|
|
/* If there's only one line in the cutbuffer */
|
|
|
|
if (cutbuffer->next == NULL) {
|
|
|
|
tmpstr =
|
2001-05-17 11:35:43 +00:00
|
|
|
charalloc(strlen(current->data) + strlen(cutbuffer->data) +
|
2000-06-06 05:53:49 +00:00
|
|
|
1);
|
|
|
|
strncpy(tmpstr, current->data, current_x);
|
|
|
|
strcpy(&tmpstr[current_x], cutbuffer->data);
|
|
|
|
strcat(tmpstr, ¤t->data[current_x]);
|
|
|
|
free(current->data);
|
|
|
|
current->data = tmpstr;
|
|
|
|
current_x += strlen(cutbuffer->data);
|
|
|
|
totsize += strlen(cutbuffer->data);
|
2001-06-21 15:07:40 +00:00
|
|
|
if (strlen(cutbuffer->data) == 0)
|
|
|
|
totlines++;
|
2002-03-28 01:59:34 +00:00
|
|
|
/* If we've uncut a line, make sure there's a magicline after
|
|
|
|
it */
|
|
|
|
if (current->next == NULL)
|
|
|
|
new_magicline();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
placewewant = xplustabs();
|
|
|
|
update_cursor();
|
|
|
|
} else { /* yuck -- no kidding! */
|
|
|
|
tmp = current->next;
|
|
|
|
/* New beginning */
|
2001-05-17 11:35:43 +00:00
|
|
|
tmpstr = charalloc(current_x + strlen(newbuf->data) + 1);
|
2000-06-06 05:53:49 +00:00
|
|
|
strncpy(tmpstr, current->data, current_x);
|
|
|
|
strcpy(&tmpstr[current_x], newbuf->data);
|
|
|
|
totsize += strlen(newbuf->data) + strlen(newend->data) + 1;
|
|
|
|
|
|
|
|
/* New end */
|
2001-05-17 11:35:43 +00:00
|
|
|
tmpstr2 = charalloc(strlen(newend->data) +
|
2000-06-06 05:53:49 +00:00
|
|
|
strlen(¤t->data[current_x]) + 1);
|
|
|
|
strcpy(tmpstr2, newend->data);
|
|
|
|
strcat(tmpstr2, ¤t->data[current_x]);
|
|
|
|
|
|
|
|
free(current->data);
|
|
|
|
current->data = tmpstr;
|
|
|
|
current->next = newbuf->next;
|
|
|
|
newbuf->next->prev = current;
|
|
|
|
delete_node(newbuf);
|
|
|
|
|
|
|
|
current_x = strlen(newend->data);
|
|
|
|
placewewant = xplustabs();
|
|
|
|
free(newend->data);
|
|
|
|
newend->data = tmpstr2;
|
|
|
|
|
|
|
|
newend->next = tmp;
|
|
|
|
|
|
|
|
/* If tmp isn't null, we're in the middle: update the
|
2001-05-05 17:45:54 +00:00
|
|
|
* prev pointer. If it IS null, we're at the end; update
|
2000-06-06 05:53:49 +00:00
|
|
|
* the filebot pointer */
|
|
|
|
|
|
|
|
if (tmp != NULL)
|
|
|
|
tmp->prev = newend;
|
2000-12-10 05:44:02 +00:00
|
|
|
else {
|
|
|
|
/* Fix the editbot pointer too */
|
|
|
|
if (editbot == filebot)
|
|
|
|
editbot = newend;
|
2000-06-06 05:53:49 +00:00
|
|
|
filebot = newend;
|
2000-12-10 05:54:27 +00:00
|
|
|
new_magicline();
|
2000-12-10 05:44:02 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
/* Now why don't we update the totsize also */
|
|
|
|
for (tmp = current->next; tmp != newend; tmp = tmp->next)
|
|
|
|
totsize += strlen(tmp->data) + 1;
|
|
|
|
|
|
|
|
i = editbot->lineno;
|
|
|
|
|
|
|
|
current = newend;
|
2001-10-22 03:15:31 +00:00
|
|
|
if (i < newend->lineno) {
|
2000-07-29 04:33:38 +00:00
|
|
|
edit_update(current, CENTER);
|
2001-10-22 03:15:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
edit_refresh();
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2000-07-27 05:09:22 +00:00
|
|
|
/* If marked cut == 2, that means that we're doing a cut to end
|
|
|
|
and we don't want anything else on the line, so we have to
|
|
|
|
screw up all the work we just did and separate the line. There
|
|
|
|
must be a better way to do this, but not at 1AM on a work night. */
|
|
|
|
|
2001-06-21 15:07:40 +00:00
|
|
|
if (marked_cut == 2) {
|
2000-07-27 05:09:22 +00:00
|
|
|
tmp = make_new_node(current);
|
2001-05-17 11:35:43 +00:00
|
|
|
tmp->data = charalloc(strlen(¤t->data[current_x]) + 1);
|
2000-07-27 05:09:22 +00:00
|
|
|
strcpy(tmp->data, ¤t->data[current_x]);
|
2000-07-28 00:58:35 +00:00
|
|
|
splice_node(current, tmp, current->next);
|
2001-10-22 23:22:19 +00:00
|
|
|
null_at(¤t->data, current_x);
|
2000-07-27 13:03:31 +00:00
|
|
|
current = current->next;
|
|
|
|
current_x = 0;
|
|
|
|
placewewant = 0;
|
2001-06-21 15:07:40 +00:00
|
|
|
|
|
|
|
/* Extra line added, update stuff */
|
|
|
|
totlines++;
|
|
|
|
totsize++;
|
2000-07-27 05:09:22 +00:00
|
|
|
}
|
2000-12-10 05:44:02 +00:00
|
|
|
/* Renumber from BEFORE where we pasted ;) */
|
|
|
|
renumber(hold);
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
dump_buffer(fileage);
|
|
|
|
dump_buffer(cutbuffer);
|
|
|
|
set_modified();
|
|
|
|
edit_refresh();
|
2001-06-21 15:07:40 +00:00
|
|
|
UNSET(KEEP_CUTBUFFER);
|
2000-06-06 05:53:49 +00:00
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
if (0) {
|
|
|
|
#endif
|
|
|
|
} else if (fileptr != fileage) {
|
|
|
|
tmp = fileptr->prev;
|
|
|
|
tmp->next = newbuf;
|
|
|
|
newbuf->prev = tmp;
|
|
|
|
totlines++; /* Unmarked uncuts don't split lines */
|
|
|
|
} else {
|
|
|
|
fileage = newbuf;
|
|
|
|
totlines++; /* Unmarked uncuts don't split lines */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is so uncutting at the top of the buffer will work => */
|
|
|
|
if (current_y == 0)
|
|
|
|
edittop = newbuf;
|
|
|
|
|
|
|
|
/* Connect the end of the buffer to the filestruct */
|
|
|
|
newend->next = fileptr;
|
|
|
|
fileptr->prev = newend;
|
|
|
|
|
|
|
|
/* recalculate size *sigh* */
|
|
|
|
for (tmp = newbuf; tmp != fileptr; tmp = tmp->next)
|
|
|
|
totsize += strlen(tmp->data) + 1;
|
|
|
|
|
|
|
|
i = editbot->lineno;
|
|
|
|
renumber(newbuf);
|
2001-10-22 03:15:31 +00:00
|
|
|
if (i < newend->lineno) {
|
2000-07-29 04:33:38 +00:00
|
|
|
edit_update(fileptr, CENTER);
|
2001-10-22 03:15:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
edit_refresh();
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
|
|
|
dump_buffer_reverse(fileptr);
|
|
|
|
|
|
|
|
set_modified();
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
edit_refresh();
|
|
|
|
return 1;
|
|
|
|
}
|