in cut.c, make marked_line a static enum instead of a static int, and
add a few formatting cleanups git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2056 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
be246c008b
commit
07e2589f80
|
@ -112,6 +112,8 @@ CVS code -
|
||||||
in files.c, and replace them with a static file_format enum.
|
in files.c, and replace them with a static file_format enum.
|
||||||
Change the openfilestruct structure accordingly in order to
|
Change the openfilestruct structure accordingly in order to
|
||||||
handle this. (DLR)
|
handle this. (DLR)
|
||||||
|
- cut.c:
|
||||||
|
- Make marked_line a static enum instead of a static int. (DLR)
|
||||||
- files.c:
|
- files.c:
|
||||||
read_file()
|
read_file()
|
||||||
- Rename variable fileformat to format, to avoid confusion with
|
- Rename variable fileformat to format, to avoid confusion with
|
||||||
|
|
44
src/cut.c
44
src/cut.c
|
@ -30,9 +30,8 @@
|
||||||
|
|
||||||
static bool keep_cutbuffer = FALSE;
|
static bool keep_cutbuffer = FALSE;
|
||||||
/* Should we keep the contents of the cutbuffer? */
|
/* Should we keep the contents of the cutbuffer? */
|
||||||
static int marked_cut;
|
static cut_type marked_cut = CUT_LINE;
|
||||||
/* Is the cutbuffer from a mark? 0 means whole-line cut, 1
|
/* What type of cut is in the cutbuffer? */
|
||||||
* means mark, and 2 means cut-from-cursor. */
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
static bool concatenate_cut = FALSE;
|
static bool concatenate_cut = FALSE;
|
||||||
/* Should we add this cut string to the end of the last one? */
|
/* Should we add this cut string to the end of the last one? */
|
||||||
|
@ -210,7 +209,7 @@ void do_cut_text(void)
|
||||||
if (!keep_cutbuffer) {
|
if (!keep_cutbuffer) {
|
||||||
free_filestruct(cutbuffer);
|
free_filestruct(cutbuffer);
|
||||||
cutbuffer = NULL;
|
cutbuffer = NULL;
|
||||||
marked_cut = 0;
|
marked_cut = CUT_LINE;
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
concatenate_cut = FALSE;
|
concatenate_cut = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
@ -238,7 +237,7 @@ void do_cut_text(void)
|
||||||
/* If the line is empty and we didn't just cut a non-blank
|
/* If the line is empty and we didn't just cut a non-blank
|
||||||
* line, create a dummy blank line and add it to the
|
* line, create a dummy blank line and add it to the
|
||||||
* cutbuffer. */
|
* cutbuffer. */
|
||||||
if (marked_cut != 1 && current->next != filebot) {
|
if (marked_cut != CUT_MARKED && current->next != filebot) {
|
||||||
filestruct *junk = make_new_node(current);
|
filestruct *junk = make_new_node(current);
|
||||||
|
|
||||||
junk->data = charalloc(1);
|
junk->data = charalloc(1);
|
||||||
|
@ -250,7 +249,7 @@ void do_cut_text(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
do_delete();
|
do_delete();
|
||||||
marked_cut = 2;
|
marked_cut = CUT_TO_END;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
SET(MARK_ISSET);
|
SET(MARK_ISSET);
|
||||||
|
@ -269,9 +268,10 @@ void do_cut_text(void)
|
||||||
/* If we just did a marked cut of part of a line, we should add
|
/* If we just did a marked cut of part of a line, we should add
|
||||||
* the first line of any cut done immediately afterward to the
|
* the first line of any cut done immediately afterward to the
|
||||||
* end of this cut, as Pico does. */
|
* end of this cut, as Pico does. */
|
||||||
if (current == mark_beginbuf && current_x < strlen(current->data))
|
if (current == mark_beginbuf && current_x <
|
||||||
|
strlen(current->data))
|
||||||
concatenate_cut = TRUE;
|
concatenate_cut = TRUE;
|
||||||
marked_cut = 1;
|
marked_cut = CUT_MARKED;
|
||||||
edit_refresh();
|
edit_refresh();
|
||||||
set_modified();
|
set_modified();
|
||||||
return;
|
return;
|
||||||
|
@ -300,7 +300,7 @@ void do_cut_text(void)
|
||||||
current_x = 0;
|
current_x = 0;
|
||||||
edit_refresh();
|
edit_refresh();
|
||||||
set_modified();
|
set_modified();
|
||||||
marked_cut = 0;
|
marked_cut = CUT_LINE;
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
concatenate_cut = FALSE;
|
concatenate_cut = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
@ -323,9 +323,9 @@ void do_uncut_text(void)
|
||||||
* we're not at the beginning of the line. If we are at the
|
* we're not at the beginning of the line. If we are at the
|
||||||
* beginning of the line, set placewewant to 0. Pico does both of
|
* beginning of the line, set placewewant to 0. Pico does both of
|
||||||
* these. */
|
* these. */
|
||||||
if (marked_cut == 0) {
|
if (marked_cut == CUT_LINE) {
|
||||||
if (current_x > 0)
|
if (current_x > 0)
|
||||||
marked_cut = 2;
|
marked_cut = CUT_TO_END;
|
||||||
else
|
else
|
||||||
placewewant = 0;
|
placewewant = 0;
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ void do_uncut_text(void)
|
||||||
if (current->next == NULL)
|
if (current->next == NULL)
|
||||||
new_magicline();
|
new_magicline();
|
||||||
|
|
||||||
if (marked_cut == 0 || cutbuffer->next != NULL) {
|
if (marked_cut == CUT_LINE || cutbuffer->next != NULL) {
|
||||||
newbuf = copy_filestruct(cutbuffer);
|
newbuf = copy_filestruct(cutbuffer);
|
||||||
for (newend = newbuf; newend->next != NULL && newend != NULL;
|
for (newend = newbuf; newend->next != NULL && newend != NULL;
|
||||||
newend = newend->next)
|
newend = newend->next)
|
||||||
|
@ -343,7 +343,7 @@ void do_uncut_text(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hook newbuf in at current. */
|
/* Hook newbuf in at current. */
|
||||||
if (marked_cut != 0) {
|
if (marked_cut != CUT_LINE) {
|
||||||
filestruct *hold = current;
|
filestruct *hold = current;
|
||||||
|
|
||||||
/* If there's only one line in the cutbuffer... */
|
/* If there's only one line in the cutbuffer... */
|
||||||
|
@ -351,10 +351,12 @@ void do_uncut_text(void)
|
||||||
size_t buf_len = strlen(cutbuffer->data);
|
size_t buf_len = strlen(cutbuffer->data);
|
||||||
size_t cur_len = strlen(current->data);
|
size_t cur_len = strlen(current->data);
|
||||||
|
|
||||||
current->data = charealloc(current->data, cur_len + buf_len + 1);
|
current->data = charealloc(current->data, cur_len +
|
||||||
|
buf_len + 1);
|
||||||
charmove(current->data + current_x + buf_len,
|
charmove(current->data + current_x + buf_len,
|
||||||
current->data + current_x, cur_len - current_x + 1);
|
current->data + current_x, cur_len - current_x + 1);
|
||||||
strncpy(current->data + current_x, cutbuffer->data, buf_len);
|
strncpy(current->data + current_x, cutbuffer->data,
|
||||||
|
buf_len);
|
||||||
/* Use strncpy() to not copy the null terminator. */
|
/* Use strncpy() to not copy the null terminator. */
|
||||||
|
|
||||||
current_x += buf_len;
|
current_x += buf_len;
|
||||||
|
@ -374,7 +376,7 @@ void do_uncut_text(void)
|
||||||
|
|
||||||
/* New end. */
|
/* New end. */
|
||||||
tmpstr2 = charalloc(strlen(newend->data) +
|
tmpstr2 = charalloc(strlen(newend->data) +
|
||||||
strlen(¤t->data[current_x]) + 1);
|
strlen(¤t->data[current_x]) + 1);
|
||||||
strcpy(tmpstr2, newend->data);
|
strcpy(tmpstr2, newend->data);
|
||||||
strcat(tmpstr2, ¤t->data[current_x]);
|
strcat(tmpstr2, ¤t->data[current_x]);
|
||||||
|
|
||||||
|
@ -408,10 +410,10 @@ void do_uncut_text(void)
|
||||||
current = newend;
|
current = newend;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If marked cut == 2, it means that we're doing a cut to end
|
/* If we're doing a cut to end, we don't want anything else on
|
||||||
* and we don't want anything else on the line, so we have to
|
* the line, so we have to screw up all the work we just did and
|
||||||
* screw up all the work we just did and separate the line. */
|
* separate the line. */
|
||||||
if (marked_cut == 2) {
|
if (marked_cut == CUT_TO_END) {
|
||||||
tmp = make_new_node(current);
|
tmp = make_new_node(current);
|
||||||
tmp->data = mallocstrcpy(NULL, current->data + current_x);
|
tmp->data = mallocstrcpy(NULL, current->data + current_x);
|
||||||
splice_node(current, tmp, current->next);
|
splice_node(current, tmp, current->next);
|
||||||
|
|
|
@ -145,6 +145,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Enumeration types. */
|
/* Enumeration types. */
|
||||||
|
typedef enum {
|
||||||
|
CUT_LINE, CUT_MARKED, CUT_TO_END
|
||||||
|
} cut_type;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NIX_FILE, DOS_FILE, MAC_FILE
|
NIX_FILE, DOS_FILE, MAC_FILE
|
||||||
} file_format;
|
} file_format;
|
||||||
|
|
Loading…
Reference in New Issue