1
/* $Id: cut.c,v 1.44 2005/12/08 07:09:08 dolorous Exp $ */
1
/* $Id: cut.c,v 1.56 2006/06/18 15:26:51 dolorous Exp $ */
2
2
/**************************************************************************
5
5
* Copyright (C) 1999-2004 Chris Allegretta *
6
* Copyright (C) 2005 David Lawrence Ramsey *
6
* Copyright (C) 2005-2006 David Lawrence Ramsey *
7
7
* This program is free software; you can redistribute it and/or modify *
8
8
* it under the terms of the GNU General Public License as published by *
9
9
* the Free Software Foundation; either version 2, or (at your option) *
38
38
keep_cutbuffer = FALSE;
41
/* If we're not on the last line of the file, move all the text of the
42
* current line, plus the newline at the end, to the cutbuffer. If we
43
* are, move all of the text of the current line to the cutbuffer. In
41
/* If we aren't on the last line of the file, move all the text of the
42
* current line, plus the newline at the end, into the cutbuffer. If we
43
* are, move all of the text of the current line into the cutbuffer. In
44
44
* both cases, set the current place we want to the beginning of the
46
46
void cut_line(void)
69
69
openfile->placewewant = xplustabs();
72
/* If we're not at the end of the current line, move all the text from
73
* the current cursor position to the end of the current line,
74
* not counting the newline at the end, to the cutbuffer. If we are,
75
* and we're not on the last line of the file, move the newline at the
76
* end to the cutbuffer, and set the current place we want to where the
72
/* If we aren't at the end of the current line, move all the text from
73
* the current cursor position to the end of the current line, not
74
* counting the newline at the end, into the cutbuffer. If we are, and
75
* we're not on the last line of the file, move the newline at the end
76
* into the cutbuffer, and set the current place we want to where the
77
77
* newline used to be. */
78
78
void cut_to_eol(void)
84
84
if (openfile->current_x < data_len)
85
85
/* If we're not at the end of the line, move all the text from
86
86
* the current position up to it, not counting the newline at
87
* the end, to the cutbuffer. */
87
* the end, into the cutbuffer. */
88
88
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
89
89
openfile->current_x, openfile->current, data_len);
90
90
else if (openfile->current != openfile->filebot) {
91
91
/* If we're at the end of the line, and it isn't the last line
92
92
* of the file, move all the text from the current position up
93
93
* to the beginning of the next line, i.e, the newline at the
94
* end, to the cutbuffer. */
94
* end, into the cutbuffer. */
95
95
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
96
96
openfile->current_x, openfile->current->next, 0);
97
97
openfile->placewewant = xplustabs();
101
/* Move all the text from the current cursor position to the end of the
102
* file into the cutbuffer. */
103
void cut_to_eof(void)
105
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
106
openfile->current_x, openfile->filebot,
107
strlen(openfile->filebot->data));
100
109
#endif /* !NANO_TINY */
102
/* Move text from the current filestruct into the cutbuffer. */
103
void do_cut_text(void)
111
/* Move text from the current filestruct into the cutbuffer. If
112
* copy_text is TRUE, copy the text back into the filestruct afterward.
113
* If cut_till_end is TRUE, move all text from the current cursor
114
* position to the end of the file into the cutbuffer. */
117
bool copy_text, bool cut_till_end
124
filestruct *cb_save = NULL;
125
/* The current end of the cutbuffer, before we add text to
127
size_t cb_save_len = 0;
128
/* The length of the string at the current end of the cutbuffer,
129
* before we add text to it. */
130
bool old_no_newlines = ISSET(NO_NEWLINES);
105
133
assert(openfile->current != NULL && openfile->current->data != NULL);
109
135
/* If keep_cutbuffer is FALSE and the cutbuffer isn't empty, blow
110
136
* away the text in the cutbuffer. */
111
137
if (!keep_cutbuffer && cutbuffer != NULL) {
147
if (cutbuffer != NULL) {
148
/* If the cutbuffer isn't empty, save where it currently
149
* ends. This is where the new text will be added. */
151
cb_save_len = strlen(cutbottom->data);
154
/* Set NO_NEWLINES to TRUE, so that we don't disturb the last
155
* line of the file when moving text to the cutbuffer. */
119
160
/* Set keep_cutbuffer to TRUE, so that the text we're going to move
120
161
* into the cutbuffer will be added to the text already in the
121
162
* cutbuffer instead of replacing it. */
122
163
keep_cutbuffer = TRUE;
124
165
#ifndef NANO_TINY
125
if (openfile->mark_set) {
126
/* If the mark is on, move the marked text to the cutbuffer and
167
/* If cut_till_end is TRUE, move all text up to the end of the
168
* file into the cutbuffer. */
170
} else if (openfile->mark_set) {
171
/* If the mark is on, move the marked text to the cutbuffer, and
127
172
* turn the mark off. */
129
174
openfile->mark_set = FALSE;
136
181
/* Otherwise, move the entire line into the cutbuffer. */
186
/* Copy the text in the cutbuffer, starting at its saved end if
187
* there is one, back into the filestruct. This effectively
188
* uncuts the text we just cut without marking the file as
190
if (cutbuffer != NULL) {
191
if (cb_save != NULL) {
192
cb_save->data += cb_save_len;
193
copy_from_filestruct(cb_save, cutbottom);
194
cb_save->data -= cb_save_len;
196
copy_from_filestruct(cutbuffer, cutbottom);
199
/* Set NO_NEWLINES back to what it was before, since we're done
200
* disturbing the text. */
201
if (!old_no_newlines)
205
/* Leave the text in the cutbuffer, and mark the file as
209
/* Update the screen. */
143
213
dump_filestruct(cutbuffer);
217
/* Move text from the current filestruct into the cutbuffer. */
218
void do_cut_text_void(void)
228
/* Move text from the current filestruct into the cutbuffer, and copy it
229
* back into the filestruct afterward. */
230
void do_copy_text(void)
232
do_cut_text(TRUE, FALSE);
148
235
/* Cut from the current cursor position to the end of the file. */
149
236
void do_cut_till_end(void)
151
assert(openfile->current != NULL && openfile->current->data != NULL);
155
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
156
openfile->current_x, openfile->filebot,
157
strlen(openfile->filebot->data));
163
dump_filestruct(cutbuffer);
238
do_cut_text(FALSE, TRUE);
166
240
#endif /* !NANO_TINY */