~ubuntu-branches/debian/lenny/nano/lenny

« back to all changes in this revision

Viewing changes to src/cut.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach
  • Date: 2006-07-04 19:56:57 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20060704195657-0m31jgrthxdlvpgi
Tags: 1.3.12-1
* The "Quiebra Mítica" release.
* New upstream development release.
* debian/nanorc: sync with nanorc.sample, which now uses includes for
  highlight patterns.
* debian/patches/*.dpatch: removed, included in new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
/**************************************************************************
3
3
 *   cut.c                                                                *
4
4
 *                                                                        *
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;
39
39
}
40
40
 
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
45
45
 * current line. */
46
46
void cut_line(void)
55
55
}
56
56
 
57
57
#ifndef NANO_TINY
58
 
/* Move all currently marked text to the cutbuffer, and set the current
59
 
 * place we want to where the text used to start. */
 
58
/* Move all currently marked text into the cutbuffer, and set the
 
59
 * current place we want to where the text used to start. */
60
60
void cut_marked(void)
61
61
{
62
62
    filestruct *top, *bot;
69
69
    openfile->placewewant = xplustabs();
70
70
}
71
71
 
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)
79
79
{
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();
98
98
    }
99
99
}
 
100
 
 
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)
 
104
{
 
105
    move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
 
106
        openfile->current_x, openfile->filebot,
 
107
        strlen(openfile->filebot->data));
 
108
}
100
109
#endif /* !NANO_TINY */
101
110
 
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. */
 
115
void do_cut_text(
 
116
#ifndef NANO_TINY
 
117
        bool copy_text, bool cut_till_end
 
118
#else
 
119
        void
 
120
#endif
 
121
        )
104
122
{
 
123
#ifndef NANO_TINY
 
124
    filestruct *cb_save = NULL;
 
125
        /* The current end of the cutbuffer, before we add text to
 
126
         * it. */
 
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);
 
131
#endif
 
132
 
105
133
    assert(openfile->current != NULL && openfile->current->data != NULL);
106
134
 
107
 
    check_statusblank();
108
 
 
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) {
116
142
#endif
117
143
    }
118
144
 
 
145
#ifndef NANO_TINY
 
146
    if (copy_text) {
 
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. */
 
150
            cb_save = cutbottom;
 
151
            cb_save_len = strlen(cutbottom->data);
 
152
        }
 
153
 
 
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. */
 
156
        SET(NO_NEWLINES);
 
157
    }
 
158
#endif
 
159
 
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;
123
164
 
124
165
#ifndef NANO_TINY
125
 
    if (openfile->mark_set) {
126
 
        /* If the mark is on, move the marked text to the cutbuffer and
 
166
    if (cut_till_end) {
 
167
        /* If cut_till_end is TRUE, move all text up to the end of the
 
168
         * file into the cutbuffer. */
 
169
        cut_to_eof();
 
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. */
128
173
        cut_marked();
129
174
        openfile->mark_set = FALSE;
136
181
        /* Otherwise, move the entire line into the cutbuffer. */
137
182
        cut_line();
138
183
 
 
184
#ifndef NANO_TINY
 
185
    if (copy_text) {
 
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
 
189
         * modified. */
 
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;
 
195
            } else
 
196
                copy_from_filestruct(cutbuffer, cutbottom);
 
197
        }
 
198
 
 
199
        /* Set NO_NEWLINES back to what it was before, since we're done
 
200
         * disturbing the text. */
 
201
        if (!old_no_newlines)
 
202
            UNSET(NO_NEWLINES);
 
203
    } else
 
204
#endif
 
205
        /* Leave the text in the cutbuffer, and mark the file as
 
206
         * modified. */
 
207
        set_modified();
 
208
 
 
209
    /* Update the screen. */
139
210
    edit_refresh();
140
 
    set_modified();
141
211
 
142
212
#ifdef DEBUG
143
213
    dump_filestruct(cutbuffer);
144
214
#endif
145
215
}
146
216
 
147
 
#ifndef NANO_TINY
 
217
/* Move text from the current filestruct into the cutbuffer. */
 
218
void do_cut_text_void(void)
 
219
{
 
220
    do_cut_text(
 
221
#ifndef NANO_TINY
 
222
        FALSE, FALSE
 
223
#endif
 
224
        );
 
225
}
 
226
 
 
227
#ifndef NANO_TINY
 
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)
 
231
{
 
232
    do_cut_text(TRUE, FALSE);
 
233
}
 
234
 
148
235
/* Cut from the current cursor position to the end of the file. */
149
236
void do_cut_till_end(void)
150
237
{
151
 
    assert(openfile->current != NULL && openfile->current->data != NULL);
152
 
 
153
 
    check_statusblank();
154
 
 
155
 
    move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
156
 
        openfile->current_x, openfile->filebot,
157
 
        strlen(openfile->filebot->data));
158
 
 
159
 
    edit_refresh();
160
 
    set_modified();
161
 
 
162
 
#ifdef DEBUG
163
 
    dump_filestruct(cutbuffer);
164
 
#endif
 
238
    do_cut_text(FALSE, TRUE);
165
239
}
166
240
#endif /* !NANO_TINY */
167
241
 
170
244
{
171
245
    assert(openfile->current != NULL && openfile->current->data != NULL);
172
246
 
173
 
#ifndef DISABLE_WRAPPING
174
 
    wrap_reset();
175
 
#endif
176
 
 
177
 
    check_statusblank();
178
 
 
179
247
    /* If the cutbuffer is empty, get out. */
180
248
    if (cutbuffer == NULL)
181
249
        return;
188
256
     * cutbuffer ends. */
189
257
    openfile->placewewant = xplustabs();
190
258
 
 
259
    /* Mark the file as modified. */
 
260
    set_modified();
 
261
 
 
262
    /* Update the screen. */
191
263
    edit_refresh();
192
 
    set_modified();
193
264
 
194
265
#ifdef DEBUG
195
266
    dump_filestruct_reverse();