restructure things so that every file has its own openfilestruct, and so

that the values in it are used directly instead of being periodically
synced up with the globals; accordingly, remove the globals; this
changes pretty much every function


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2835 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-07-08 20:09:16 +00:00
parent 64661ac140
commit 6ad59cd29b
12 changed files with 1163 additions and 1304 deletions

View File

@ -7,6 +7,17 @@ CVS code -
backup_lines(). (DLR) backup_lines(). (DLR)
- Reorder some functions for consistency. (DLR) - Reorder some functions for consistency. (DLR)
- Rename variable open_files openfile, for consistency. (DLR) - Rename variable open_files openfile, for consistency. (DLR)
- Restructure things so that every file has its own
openfilestruct, and so that the values in it are used directly
instead of being periodically synced up with the globals.
Accordingly, remove the globals. Changes to pretty much
every function. Rename global_init() resize_init(), rename
add_open_file() make_new_buffer(), rename load_buffer()
open_buffer(), rename open_prevnext_file()
switch_to_prevnext_buffer(), rename open_prevfile_void()
switch_to_prev_buffer(), rename open_nextfile_void()
switch_to_next_buffer(), remove load_file(), and remove
load_open_file(). (DLR)
- global.c: - global.c:
shortcut_init() shortcut_init()
- Simplify wording of nano_gotoline_msg. (Jordi) - Simplify wording of nano_gotoline_msg. (Jordi)

View File

@ -110,7 +110,7 @@ void update_color(void)
for (e = tmpsyntax->extensions; e != NULL; e = e->next) { for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
/* Set colorstrings if we matched the extension regex. */ /* Set colorstrings if we matched the extension regex. */
if (regexec(&e->val, filename, 0, NULL, 0) == 0) if (regexec(&e->val, openfile->filename, 0, NULL, 0) == 0)
colorstrings = tmpsyntax->color; colorstrings = tmpsyntax->color;
if (colorstrings != NULL) if (colorstrings != NULL)

View File

@ -45,10 +45,10 @@ void cutbuffer_reset(void)
* place we want to where the line used to start. */ * place we want to where the line used to start. */
void cut_line(void) void cut_line(void)
{ {
if (current->next != NULL) { if (openfile->current->next != NULL) {
move_to_filestruct(&cutbuffer, &cutbottom, current, 0, move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, 0,
current->next, 0); openfile->current->next, 0);
placewewant = xplustabs(); openfile->placewewant = xplustabs();
} }
} }
@ -64,7 +64,7 @@ void cut_marked(void)
(const filestruct **)&bot, &bot_x, NULL); (const filestruct **)&bot, &bot_x, NULL);
move_to_filestruct(&cutbuffer, &cutbottom, top, top_x, bot, bot_x); move_to_filestruct(&cutbuffer, &cutbottom, top, top_x, bot, bot_x);
placewewant = xplustabs(); openfile->placewewant = xplustabs();
} }
/* If we're not at the end of the current line, move all the text from /* If we're not at the end of the current line, move all the text from
@ -75,24 +75,24 @@ void cut_marked(void)
* used to be. */ * used to be. */
void cut_to_eol(void) void cut_to_eol(void)
{ {
size_t data_len = strlen(current->data); size_t data_len = strlen(openfile->current->data);
assert(current_x <= data_len); assert(openfile->current_x <= data_len);
if (current_x < data_len) if (openfile->current_x < data_len)
/* If we're not at the end of the line, move all the text from /* If we're not at the end of the line, move all the text from
* the current position up to it, not counting the newline at * the current position up to it, not counting the newline at
* the end, to the cutbuffer. */ * the end, to the cutbuffer. */
move_to_filestruct(&cutbuffer, &cutbottom, current, current_x, move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
current, data_len); openfile->current_x, openfile->current, data_len);
else if (current->next != NULL) { else if (openfile->current->next != NULL) {
/* If we're at the end of the line, and it isn't the magicline, /* If we're at the end of the line, and it isn't the magicline,
* move all the text from the current position up to the * move all the text from the current position up to the
* beginning of the next line, i.e, the newline at the end, to * beginning of the next line, i.e, the newline at the end, to
* the cutbuffer. */ * the cutbuffer. */
move_to_filestruct(&cutbuffer, &cutbottom, current, current_x, move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
current->next, 0); openfile->current_x, openfile->current->next, 0);
placewewant = xplustabs(); openfile->placewewant = xplustabs();
} }
} }
#endif /* !NANO_SMALL */ #endif /* !NANO_SMALL */
@ -100,7 +100,7 @@ void cut_to_eol(void)
/* Move text from the current filestruct into the cutbuffer. */ /* Move text from the current filestruct into the cutbuffer. */
void do_cut_text(void) void do_cut_text(void)
{ {
assert(current != NULL && current->data != NULL); assert(openfile->current != NULL && openfile->current->data != NULL);
check_statusblank(); check_statusblank();
@ -120,11 +120,11 @@ void do_cut_text(void)
keep_cutbuffer = TRUE; keep_cutbuffer = TRUE;
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (ISSET(MARK_ISSET)) { if (openfile->mark_set) {
/* If the mark is on, move the marked text to the cutbuffer and /* If the mark is on, move the marked text to the cutbuffer and
* turn the mark off. */ * turn the mark off. */
cut_marked(); cut_marked();
UNSET(MARK_ISSET); openfile->mark_set = FALSE;
} else if (ISSET(CUT_TO_END)) } else if (ISSET(CUT_TO_END))
/* Otherwise, if the CUT_TO_END flag is set, move all text up to /* Otherwise, if the CUT_TO_END flag is set, move all text up to
* the end of the line into the cutbuffer. */ * the end of the line into the cutbuffer. */
@ -138,7 +138,7 @@ void do_cut_text(void)
set_modified(); set_modified();
#ifdef DEBUG #ifdef DEBUG
dump_buffer(cutbuffer); dump_filestruct(cutbuffer);
#endif #endif
} }
@ -146,18 +146,18 @@ void do_cut_text(void)
/* Cut from the current cursor position to the end of the file. */ /* Cut from the current cursor position to the end of the file. */
void do_cut_till_end(void) void do_cut_till_end(void)
{ {
assert(current != NULL && current->data != NULL); assert(openfile->current != NULL && openfile->current->data != NULL);
check_statusblank(); check_statusblank();
move_to_filestruct(&cutbuffer, &cutbottom, current, current_x, move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
filebot, 0); openfile->current_x, openfile->filebot, 0);
edit_refresh(); edit_refresh();
set_modified(); set_modified();
#ifdef DEBUG #ifdef DEBUG
dump_buffer(cutbuffer); dump_filestruct(cutbuffer);
#endif #endif
} }
#endif /* !NANO_SMALL */ #endif /* !NANO_SMALL */
@ -165,7 +165,7 @@ void do_cut_till_end(void)
/* Copy text from the cutbuffer into the current filestruct. */ /* Copy text from the cutbuffer into the current filestruct. */
void do_uncut_text(void) void do_uncut_text(void)
{ {
assert(current != NULL && current->data != NULL); assert(openfile->current != NULL && openfile->current->data != NULL);
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
wrap_reset(); wrap_reset();
@ -183,12 +183,12 @@ void do_uncut_text(void)
/* Set the current place we want to where the text from the /* Set the current place we want to where the text from the
* cutbuffer ends. */ * cutbuffer ends. */
placewewant = xplustabs(); openfile->placewewant = xplustabs();
edit_refresh(); edit_refresh();
set_modified(); set_modified();
#ifdef DEBUG #ifdef DEBUG
dump_buffer_reverse(); dump_filestruct_reverse();
#endif #endif
} }

File diff suppressed because it is too large Load Diff

View File

@ -43,24 +43,9 @@ unsigned long flags = 0; /* Our flag containing many options */
WINDOW *topwin; /* Top buffer */ WINDOW *topwin; /* Top buffer */
WINDOW *edit; /* The file portion of the editor */ WINDOW *edit; /* The file portion of the editor */
WINDOW *bottomwin; /* Bottom buffer */ WINDOW *bottomwin; /* Bottom buffer */
char *filename = NULL; /* Name of the file */
#ifndef NANO_SMALL
struct stat originalfilestat; /* Stat for the file as we loaded it */
#endif
int editwinrows = 0; /* How many rows long is the edit int editwinrows = 0; /* How many rows long is the edit
window? */ window? */
filestruct *current; /* Current buffer pointer */
size_t current_x = 0; /* Current x-coordinate in the edit
window */
ssize_t current_y = 0; /* Current y-coordinate in the edit
window */
filestruct *fileage = NULL; /* Our file buffer */
filestruct *edittop = NULL; /* Pointer to the top of the edit
buffer with respect to the
file struct */
filestruct *filebot = NULL; /* Last node in the file struct */
filestruct *cutbuffer = NULL; /* A place to store cut text */ filestruct *cutbuffer = NULL; /* A place to store cut text */
#ifndef DISABLE_JUSTIFY #ifndef DISABLE_JUSTIFY
filestruct *jusbuffer = NULL; /* A place to store unjustified text */ filestruct *jusbuffer = NULL; /* A place to store unjustified text */
@ -68,10 +53,8 @@ filestruct *jusbuffer = NULL; /* A place to store unjustified text */
partition *filepart = NULL; /* A place to store a portion of the partition *filepart = NULL; /* A place to store a portion of the
file struct */ file struct */
#ifdef ENABLE_MULTIBUFFER
openfilestruct *openfile = NULL; openfilestruct *openfile = NULL;
/* The list of open file buffers */ /* The list of open file buffers */
#endif
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC) #if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
char *whitespace = NULL; /* Characters used when displaying char *whitespace = NULL; /* Characters used when displaying
@ -102,12 +85,6 @@ char *backup_dir = NULL; /* Backup directory. */
#endif #endif
char *answer = NULL; /* Answer str to many questions */ char *answer = NULL; /* Answer str to many questions */
size_t totlines = 0; /* Total number of lines in the file */
size_t totsize = 0; /* Total number of characters in the
file */
size_t placewewant = 0; /* The column we'd like the cursor
to jump to when we go to the
next or previous line */
ssize_t tabsize = -1; /* Our internal tabsize variable. The ssize_t tabsize = -1; /* Our internal tabsize variable. The
default value is set in main(). */ default value is set in main(). */
@ -117,13 +94,6 @@ char *hblank = NULL; /* A horizontal blank line */
char *help_text; /* The text in the help window */ char *help_text; /* The text in the help window */
#endif #endif
/* More stuff for the marker select */
#ifndef NANO_SMALL
filestruct *mark_beginbuf; /* The begin marker buffer */
size_t mark_beginx; /* X value in the string to start */
#endif
#ifndef DISABLE_OPERATINGDIR #ifndef DISABLE_OPERATINGDIR
char *operating_dir = NULL; /* Operating directory, which we can't */ char *operating_dir = NULL; /* Operating directory, which we can't */
char *full_operating_dir = NULL;/* go higher than */ char *full_operating_dir = NULL;/* go higher than */
@ -331,9 +301,9 @@ void shortcut_init(bool unjustify)
N_("Go to the end of the current paragraph"); N_("Go to the end of the current paragraph");
#endif #endif
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
const char *nano_openprev_msg = const char *nano_prevfile_msg =
N_("Switch to the previous file buffer"); N_("Switch to the previous file buffer");
const char *nano_opennext_msg = const char *nano_nextfile_msg =
N_("Switch to the next file buffer"); N_("Switch to the next file buffer");
#endif #endif
const char *nano_verbatim_msg = N_("Insert character(s) verbatim"); const char *nano_verbatim_msg = N_("Insert character(s) verbatim");
@ -413,7 +383,8 @@ void shortcut_init(bool unjustify)
/* Translators: try to keep this string under 10 characters long */ /* Translators: try to keep this string under 10 characters long */
sc_init_one(&main_list, NANO_EXIT_KEY, sc_init_one(&main_list, NANO_EXIT_KEY,
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
openfile != NULL && openfile != openfile->next ? N_("Close") : openfile != NULL && openfile != openfile->next ?
N_("Close") :
#endif #endif
exit_msg, IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY, exit_msg, IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
NANO_NO_KEY, VIEW, do_exit); NANO_NO_KEY, VIEW, do_exit);
@ -590,12 +561,12 @@ void shortcut_init(bool unjustify)
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
sc_init_one(&main_list, NANO_NO_KEY, N_("Previous File"), sc_init_one(&main_list, NANO_NO_KEY, N_("Previous File"),
IFHELP(nano_openprev_msg, NANO_OPENPREV_KEY), NANO_NO_KEY, IFHELP(nano_prevfile_msg, NANO_PREVFILE_KEY), NANO_NO_KEY,
NANO_OPENPREV_ALTKEY, VIEW, open_prevfile_void); NANO_PREVFILE_ALTKEY, VIEW, switch_to_prev_buffer_void);
sc_init_one(&main_list, NANO_NO_KEY, N_("Next File"), sc_init_one(&main_list, NANO_NO_KEY, N_("Next File"),
IFHELP(nano_opennext_msg, NANO_OPENNEXT_KEY), NANO_NO_KEY, IFHELP(nano_nextfile_msg, NANO_NEXTFILE_KEY), NANO_NO_KEY,
NANO_OPENNEXT_ALTKEY, VIEW, open_nextfile_void); NANO_NEXTFILE_ALTKEY, VIEW, switch_to_next_buffer_void);
#endif #endif
sc_init_one(&main_list, NANO_NO_KEY, N_("Verbatim Input"), sc_init_one(&main_list, NANO_NO_KEY, N_("Verbatim Input"),
@ -1201,8 +1172,6 @@ void thanks_for_all_the_fish(void)
if (help_text != NULL) if (help_text != NULL)
free(help_text); free(help_text);
#endif #endif
if (filename != NULL)
free(filename);
if (answer != NULL) if (answer != NULL)
free(answer); free(answer);
if (cutbuffer != NULL) if (cutbuffer != NULL)
@ -1240,19 +1209,9 @@ void thanks_for_all_the_fish(void)
free(t); free(t);
} }
#endif #endif
#ifdef ENABLE_MULTIBUFFER
/* Free the memory associated with each open file buffer. */ /* Free the memory associated with each open file buffer. */
if (openfile != NULL) { if (openfile != NULL)
/* Make sure openfile->fileage is up to date, in case we've
* cut the top line of the file. */
openfile->fileage = fileage;
free_openfilestruct(openfile); free_openfilestruct(openfile);
}
#else
if (fileage != NULL)
free_filestruct(fileage);
#endif
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
if (syntaxstr != NULL) if (syntaxstr != NULL)
free(syntaxstr); free(syntaxstr);

View File

@ -32,74 +32,75 @@
void do_first_line(void) void do_first_line(void)
{ {
size_t pww_save = placewewant; size_t pww_save = openfile->placewewant;
current = fileage; openfile->current = openfile->fileage;
placewewant = 0; openfile->placewewant = 0;
current_x = 0; openfile->current_x = 0;
if (edittop != fileage || need_vertical_update(pww_save)) if (openfile->edittop != openfile->fileage ||
need_vertical_update(pww_save))
edit_update(TOP); edit_update(TOP);
} }
void do_last_line(void) void do_last_line(void)
{ {
size_t pww_save = placewewant; size_t pww_save = openfile->placewewant;
current = filebot; openfile->current = openfile->filebot;
placewewant = 0; openfile->placewewant = 0;
current_x = 0; openfile->current_x = 0;
if (edittop->lineno + (editwinrows / 2) != filebot->lineno || if (openfile->edittop->lineno + (editwinrows / 2) !=
need_vertical_update(pww_save)) openfile->filebot->lineno || need_vertical_update(pww_save))
edit_update(CENTER); edit_update(CENTER);
} }
void do_home(void) void do_home(void)
{ {
size_t pww_save = placewewant; size_t pww_save = openfile->placewewant;
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (ISSET(SMART_HOME)) { if (ISSET(SMART_HOME)) {
size_t current_x_save = current_x; size_t current_x_save = openfile->current_x;
current_x = indent_length(current->data); openfile->current_x = indent_length(openfile->current->data);
if (current_x == current_x_save || if (openfile->current_x == current_x_save ||
current->data[current_x] == '\0') openfile->current->data[openfile->current_x] == '\0')
current_x = 0; openfile->current_x = 0;
placewewant = xplustabs(); openfile->placewewant = xplustabs();
} else { } else {
#endif #endif
current_x = 0; openfile->current_x = 0;
placewewant = 0; openfile->placewewant = 0;
#ifndef NANO_SMALL #ifndef NANO_SMALL
} }
#endif #endif
check_statusblank(); check_statusblank();
if (need_horizontal_update(pww_save)) if (need_horizontal_update(pww_save))
update_line(current, current_x); update_line(openfile->current, openfile->current_x);
} }
void do_end(void) void do_end(void)
{ {
size_t pww_save = placewewant; size_t pww_save = openfile->placewewant;
current_x = strlen(current->data); openfile->current_x = strlen(openfile->current->data);
placewewant = xplustabs(); openfile->placewewant = xplustabs();
check_statusblank(); check_statusblank();
if (need_horizontal_update(pww_save)) if (need_horizontal_update(pww_save))
update_line(current, current_x); update_line(openfile->current, openfile->current_x);
} }
void do_page_up(void) void do_page_up(void)
{ {
size_t pww_save = placewewant; size_t pww_save = openfile->placewewant;
const filestruct *current_save = current; const filestruct *current_save = openfile->current;
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
wrap_reset(); wrap_reset();
#endif #endif
/* If the first line of the file is onscreen, move current up there /* If the first line of the file is onscreen, move current up there
* and put the cursor at the beginning of the line. */ * and put the cursor at the beginning of the line. */
if (edittop == fileage) { if (openfile->edittop == openfile->fileage) {
current = fileage; openfile->current = openfile->fileage;
placewewant = 0; openfile->placewewant = 0;
} else { } else {
edit_scroll(UP, editwinrows - 2); edit_scroll(UP, editwinrows - 2);
@ -107,25 +108,27 @@ void do_page_up(void)
/* If we're in smooth scrolling mode and there's at least one /* If we're in smooth scrolling mode and there's at least one
* page of text left, move the current line of the edit window * page of text left, move the current line of the edit window
* up a page. */ * up a page. */
if (ISSET(SMOOTH_SCROLL) && current->lineno > editwinrows - 2) { if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno >
editwinrows - 2) {
int i; int i;
for (i = 0; i < editwinrows - 2; i++) for (i = 0; i < editwinrows - 2; i++)
current = current->prev; openfile->current = openfile->current->prev;
} }
/* If we're not in smooth scrolling mode or there isn't at least /* If we're not in smooth scrolling mode or there isn't at least
* one page of text left, put the cursor at the beginning of the * one page of text left, put the cursor at the beginning of the
* top line of the edit window, as Pico does. */ * top line of the edit window, as Pico does. */
else { else {
#endif #endif
current = edittop; openfile->current = openfile->edittop;
placewewant = 0; openfile->placewewant = 0;
#ifndef NANO_SMALL #ifndef NANO_SMALL
} }
#endif #endif
} }
/* Get the equivalent x-coordinate of the new line. */ /* Get the equivalent x-coordinate of the new line. */
current_x = actual_x(current->data, placewewant); openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
/* Update all the lines that need to be updated. */ /* Update all the lines that need to be updated. */
edit_redraw(current_save, pww_save); edit_redraw(current_save, pww_save);
@ -135,17 +138,18 @@ void do_page_up(void)
void do_page_down(void) void do_page_down(void)
{ {
size_t pww_save = placewewant; size_t pww_save = openfile->placewewant;
const filestruct *current_save = current; const filestruct *current_save = openfile->current;
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
wrap_reset(); wrap_reset();
#endif #endif
/* If the last line of the file is onscreen, move current down /* If the last line of the file is onscreen, move current down
* there and put the cursor at the beginning of the line. */ * there and put the cursor at the beginning of the line. */
if (edittop->lineno + editwinrows > filebot->lineno) { if (openfile->edittop->lineno + editwinrows >
current = filebot; openfile->filebot->lineno) {
placewewant = 0; openfile->current = openfile->filebot;
openfile->placewewant = 0;
} else { } else {
edit_scroll(DOWN, editwinrows - 2); edit_scroll(DOWN, editwinrows - 2);
@ -153,26 +157,27 @@ void do_page_down(void)
/* If we're in smooth scrolling mode and there's at least one /* If we're in smooth scrolling mode and there's at least one
* page of text left, move the current line of the edit window * page of text left, move the current line of the edit window
* down a page. */ * down a page. */
if (ISSET(SMOOTH_SCROLL) && current->lineno + editwinrows - 2 <= if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno +
filebot->lineno) { editwinrows - 2 <= openfile->filebot->lineno) {
int i; int i;
for (i = 0; i < editwinrows - 2; i++) for (i = 0; i < editwinrows - 2; i++)
current = current->next; openfile->current = openfile->current->next;
} }
/* If we're not in smooth scrolling mode or there isn't at least /* If we're not in smooth scrolling mode or there isn't at least
* one page of text left, put the cursor at the beginning of the * one page of text left, put the cursor at the beginning of the
* top line of the edit window, as Pico does. */ * top line of the edit window, as Pico does. */
else { else {
#endif #endif
current = edittop; openfile->current = openfile->edittop;
placewewant = 0; openfile->placewewant = 0;
#ifndef NANO_SMALL #ifndef NANO_SMALL
} }
#endif #endif
} }
/* Get the equivalent x-coordinate of the new line. */ /* Get the equivalent x-coordinate of the new line. */
current_x = actual_x(current->data, placewewant); openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
/* Update all the lines that need to be updated. */ /* Update all the lines that need to be updated. */
edit_redraw(current_save, pww_save); edit_redraw(current_save, pww_save);
@ -187,18 +192,19 @@ void do_up(void)
#endif #endif
check_statusblank(); check_statusblank();
if (current->prev == NULL) if (openfile->current->prev == NULL)
return; return;
assert(current_y == current->lineno - edittop->lineno); assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
current = current->prev; openfile->current = openfile->current->prev;
current_x = actual_x(current->data, placewewant); openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
/* If we're on the first row of the edit window, scroll up one line /* If we're on the first row of the edit window, scroll up one line
* if we're in smooth scrolling mode, or up half a page if we're * if we're in smooth scrolling mode, or up half a page if we're
* not. */ * not. */
if (current_y == 0) if (openfile->current_y == 0)
edit_scroll(UP, edit_scroll(UP,
#ifndef NANO_SMALL #ifndef NANO_SMALL
ISSET(SMOOTH_SCROLL) ? 1 : ISSET(SMOOTH_SCROLL) ? 1 :
@ -210,8 +216,8 @@ void do_up(void)
* if we're not on the first page, and the latter needs to be * if we're not on the first page, and the latter needs to be
* drawn. */ * drawn. */
if (need_vertical_update(0)) if (need_vertical_update(0))
update_line(current->next, 0); update_line(openfile->current->next, 0);
update_line(current, current_x); update_line(openfile->current, openfile->current_x);
} }
void do_down(void) void do_down(void)
@ -221,18 +227,19 @@ void do_down(void)
#endif #endif
check_statusblank(); check_statusblank();
if (current->next == NULL) if (openfile->current->next == NULL)
return; return;
assert(current_y == current->lineno - edittop->lineno); assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
current = current->next; openfile->current = openfile->current->next;
current_x = actual_x(current->data, placewewant); openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
/* If we're on the last row of the edit window, scroll down one line /* If we're on the last row of the edit window, scroll down one line
* if we're in smooth scrolling mode, or down half a page if we're * if we're in smooth scrolling mode, or down half a page if we're
* not. */ * not. */
if (current_y == editwinrows - 1) if (openfile->current_y == editwinrows - 1)
edit_scroll(DOWN, edit_scroll(DOWN,
#ifndef NANO_SMALL #ifndef NANO_SMALL
ISSET(SMOOTH_SCROLL) ? 1 : ISSET(SMOOTH_SCROLL) ? 1 :
@ -244,23 +251,25 @@ void do_down(void)
* if we're not on the first page, and the latter needs to be * if we're not on the first page, and the latter needs to be
* drawn. */ * drawn. */
if (need_vertical_update(0)) if (need_vertical_update(0))
update_line(current->prev, 0); update_line(openfile->current->prev, 0);
update_line(current, current_x); update_line(openfile->current, openfile->current_x);
} }
void do_left(bool allow_update) void do_left(bool allow_update)
{ {
size_t pww_save = placewewant; size_t pww_save = openfile->placewewant;
if (current_x > 0)
current_x = move_mbleft(current->data, current_x); if (openfile->current_x > 0)
else if (current != fileage) { openfile->current_x = move_mbleft(openfile->current->data,
openfile->current_x);
else if (openfile->current != openfile->fileage) {
do_up(); do_up();
current_x = strlen(current->data); openfile->current_x = strlen(openfile->current->data);
} }
placewewant = xplustabs(); openfile->placewewant = xplustabs();
check_statusblank(); check_statusblank();
if (allow_update && need_horizontal_update(pww_save)) if (allow_update && need_horizontal_update(pww_save))
update_line(current, current_x); update_line(openfile->current, openfile->current_x);
} }
void do_left_void(void) void do_left_void(void)
@ -270,19 +279,20 @@ void do_left_void(void)
void do_right(bool allow_update) void do_right(bool allow_update)
{ {
size_t pww_save = placewewant; size_t pww_save = openfile->placewewant;
assert(current_x <= strlen(current->data)); assert(openfile->current_x <= strlen(openfile->current->data));
if (current->data[current_x] != '\0') if (openfile->current->data[openfile->current_x] != '\0')
current_x = move_mbright(current->data, current_x); openfile->current_x = move_mbright(openfile->current->data,
else if (current->next != NULL) { openfile->current_x);
else if (openfile->current->next != NULL) {
do_down(); do_down();
current_x = 0; openfile->current_x = 0;
} }
placewewant = xplustabs(); openfile->placewewant = xplustabs();
check_statusblank(); check_statusblank();
if (allow_update && need_horizontal_update(pww_save)) if (allow_update && need_horizontal_update(pww_save))
update_line(current, current_x); update_line(openfile->current, openfile->current_x);
} }
void do_right_void(void) void do_right_void(void)

File diff suppressed because it is too large Load Diff

View File

@ -160,20 +160,17 @@ typedef struct filestruct {
ssize_t lineno; /* The line number. */ ssize_t lineno; /* The line number. */
} filestruct; } filestruct;
#ifdef ENABLE_MULTIBUFFER
typedef struct openfilestruct { typedef struct openfilestruct {
char *filename; char *filename; /* Current file's name. */
#ifndef NANO_SMALL filestruct *fileage; /* Current file's first line. */
struct stat originalfilestat;
#endif
struct openfilestruct *next;
/* Next node. */
struct openfilestruct *prev;
/* Previous node. */
filestruct *fileage; /* Current file. */
filestruct *filebot; /* Current file's last line. */ filestruct *filebot; /* Current file's last line. */
filestruct *edittop; /* Current top of edit window. */ filestruct *edittop; /* Current top of edit window. */
filestruct *current; /* Current file's line. */ filestruct *current; /* Current file's line. */
size_t current_x; /* Current file's x-coordinate
* position. */
ssize_t current_y; /* Current file's y-coordinate
* position. */
size_t placewewant; /* Current file's place we want. */
#ifndef NANO_SMALL #ifndef NANO_SMALL
filestruct *mark_beginbuf; filestruct *mark_beginbuf;
/* Current file's beginning marked /* Current file's beginning marked
@ -181,18 +178,22 @@ typedef struct openfilestruct {
size_t mark_beginx; /* Current file's beginning marked size_t mark_beginx; /* Current file's beginning marked
* line's x-coordinate position. */ * line's x-coordinate position. */
#endif #endif
size_t current_x; /* Current file's x-coordinate
* position. */
size_t placewewant; /* Current file's place we want. */
size_t totlines; /* Current file's total number of size_t totlines; /* Current file's total number of
* lines. */ * lines. */
size_t totsize; /* Current file's total size. */ size_t totsize; /* Current file's total size. */
unsigned long flags; /* Current file's flags: modification bool modified; /* Current file's modification
* status (and marking status, if * status. */
* available). */ #ifndef NANO_SMALL
bool mark_set; /* Current file's marking status. */
file_format fmt; /* Current file's format. */ file_format fmt; /* Current file's format. */
} openfilestruct; struct stat originalfilestat;
/* Current file's stat. */
#endif #endif
struct openfilestruct *next;
/* Next node. */
struct openfilestruct *prev;
/* Previous node. */
} openfilestruct;
typedef struct partition { typedef struct partition {
filestruct *fileage; filestruct *fileage;
@ -268,37 +269,35 @@ typedef struct syntaxtype {
/* Bitwise flags so that we can save space (or, more correctly, not /* Bitwise flags so that we can save space (or, more correctly, not
* waste it). */ * waste it). */
#define MODIFIED (1<<0) #define CASE_SENSITIVE (1<<0)
#define CASE_SENSITIVE (1<<1) #define CONST_UPDATE (1<<1)
#define MARK_ISSET (1<<2) #define NO_HELP (1<<2)
#define CONST_UPDATE (1<<3) #define NOFOLLOW_SYMLINKS (1<<3)
#define NO_HELP (1<<4) #define SUSPEND (1<<4)
#define NOFOLLOW_SYMLINKS (1<<5) #define NO_WRAP (1<<5)
#define SUSPEND (1<<6) #define AUTOINDENT (1<<6)
#define NO_WRAP (1<<7) #define VIEW_MODE (1<<7)
#define AUTOINDENT (1<<8) #define USE_MOUSE (1<<8)
#define VIEW_MODE (1<<9) #define USE_REGEXP (1<<9)
#define USE_MOUSE (1<<10) #define TEMP_FILE (1<<10)
#define USE_REGEXP (1<<11) #define CUT_TO_END (1<<11)
#define TEMP_FILE (1<<12) #define BACKWARDS_SEARCH (1<<12)
#define CUT_TO_END (1<<13) #define MULTIBUFFER (1<<13)
#define BACKWARDS_SEARCH (1<<14) #define SMOOTH_SCROLL (1<<14)
#define MULTIBUFFER (1<<15) #define REBIND_DELETE (1<<15)
#define SMOOTH_SCROLL (1<<16) #define NO_CONVERT (1<<16)
#define REBIND_DELETE (1<<17) #define BACKUP_FILE (1<<17)
#define NO_CONVERT (1<<18) #define NO_RCFILE (1<<18)
#define BACKUP_FILE (1<<19) #define NO_COLOR_SYNTAX (1<<19)
#define NO_RCFILE (1<<20) #define PRESERVE (1<<20)
#define NO_COLOR_SYNTAX (1<<21) #define HISTORYLOG (1<<21)
#define PRESERVE (1<<22) #define RESTRICTED (1<<22)
#define HISTORYLOG (1<<23) #define SMART_HOME (1<<23)
#define RESTRICTED (1<<24) #define WHITESPACE_DISPLAY (1<<24)
#define SMART_HOME (1<<25) #define MORE_SPACE (1<<25)
#define WHITESPACE_DISPLAY (1<<26) #define TABS_TO_SPACES (1<<26)
#define MORE_SPACE (1<<27) #define QUICK_BLANK (1<<27)
#define TABS_TO_SPACES (1<<28) #define USE_UTF8 (1<<28)
#define QUICK_BLANK (1<<29)
#define USE_UTF8 (1<<30)
/* Control key sequences. Changing these would be very, very bad. */ /* Control key sequences. Changing these would be very, very bad. */
#define NANO_CONTROL_SPACE 0 #define NANO_CONTROL_SPACE 0
@ -443,10 +442,10 @@ typedef struct syntaxtype {
#define NANO_TOFILES_KEY NANO_CONTROL_T #define NANO_TOFILES_KEY NANO_CONTROL_T
#define NANO_APPEND_KEY NANO_ALT_A #define NANO_APPEND_KEY NANO_ALT_A
#define NANO_PREPEND_KEY NANO_ALT_P #define NANO_PREPEND_KEY NANO_ALT_P
#define NANO_OPENPREV_KEY NANO_ALT_LCARAT #define NANO_PREVFILE_KEY NANO_ALT_LCARAT
#define NANO_OPENNEXT_KEY NANO_ALT_RCARAT #define NANO_NEXTFILE_KEY NANO_ALT_RCARAT
#define NANO_OPENPREV_ALTKEY NANO_ALT_COMMA #define NANO_PREVFILE_ALTKEY NANO_ALT_COMMA
#define NANO_OPENNEXT_ALTKEY NANO_ALT_PERIOD #define NANO_NEXTFILE_ALTKEY NANO_ALT_PERIOD
#define NANO_BRACKET_KEY NANO_ALT_RBRACKET #define NANO_BRACKET_KEY NANO_ALT_RBRACKET
#define NANO_NEXTWORD_KEY NANO_CONTROL_SPACE #define NANO_NEXTWORD_KEY NANO_CONTROL_SPACE
#define NANO_PREVWORD_KEY NANO_ALT_SPACE #define NANO_PREVWORD_KEY NANO_ALT_SPACE

View File

@ -37,14 +37,6 @@
extern ssize_t wrap_at; extern ssize_t wrap_at;
#endif #endif
extern int editwinrows; extern int editwinrows;
extern size_t current_x;
extern ssize_t current_y;
extern size_t totlines;
extern size_t placewewant;
#ifndef NANO_SMALL
extern size_t mark_beginx;
#endif
extern size_t totsize;
extern unsigned long flags; extern unsigned long flags;
extern ssize_t tabsize; extern ssize_t tabsize;
extern int currslen; extern int currslen;
@ -72,8 +64,6 @@ extern char *backup_dir;
#endif #endif
extern WINDOW *topwin, *edit, *bottomwin; extern WINDOW *topwin, *edit, *bottomwin;
extern char *filename;
extern struct stat originalfilestat;
extern char *answer; extern char *answer;
extern char *hblank; extern char *hblank;
#ifndef DISABLE_HELP #ifndef DISABLE_HELP
@ -90,19 +80,13 @@ extern char *alt_speller;
#endif #endif
extern struct stat fileinfo; extern struct stat fileinfo;
extern filestruct *current, *fileage, *edittop, *filebot;
extern filestruct *cutbuffer; extern filestruct *cutbuffer;
#ifndef DISABLE_JUSTIFY #ifndef DISABLE_JUSTIFY
extern filestruct *jusbuffer; extern filestruct *jusbuffer;
#endif #endif
extern partition *filepart; extern partition *filepart;
#ifndef NANO_SMALL
extern filestruct *mark_beginbuf;
#endif
#ifdef ENABLE_MULTIBUFFER
extern openfilestruct *openfile; extern openfilestruct *openfile;
#endif
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
extern const colortype *colorstrings; extern const colortype *colorstrings;
@ -246,7 +230,6 @@ void do_cut_till_end(void);
void do_uncut_text(void); void do_uncut_text(void);
/* Public functions in files.c. */ /* Public functions in files.c. */
#ifdef ENABLE_MULTIBUFFER
openfilestruct *make_new_opennode(void); openfilestruct *make_new_opennode(void);
void splice_opennode(openfilestruct *begin, openfilestruct *newnode, void splice_opennode(openfilestruct *begin, openfilestruct *newnode,
openfilestruct *end); openfilestruct *end);
@ -255,24 +238,22 @@ void delete_opennode(openfilestruct *fileptr);
#ifdef DEBUG #ifdef DEBUG
void free_openfilestruct(openfilestruct *src); void free_openfilestruct(openfilestruct *src);
#endif #endif
void add_open_file(bool update); void make_new_buffer(void);
void load_open_file(void); void open_buffer(const char *filename);
void open_prevnext_file(bool next_file); #ifdef ENABLE_MULTIBUFFER
void open_prevfile_void(void); void switch_to_prevnext_buffer(bool next);
void open_nextfile_void(void); void switch_to_prev_buffer_void(void);
bool close_open_file(void); void switch_to_next_buffer_void(void);
bool close_buffer(void);
#endif #endif
void new_file(void);
filestruct *read_line(char *buf, filestruct *prevnode, bool filestruct *read_line(char *buf, filestruct *prevnode, bool
*first_line_ins, size_t buf_len); *first_line_ins, size_t buf_len);
void load_file(void);
void read_file(FILE *f, const char *filename); void read_file(FILE *f, const char *filename);
int open_file(const char *filename, bool newfie, FILE **f); int open_file(const char *filename, bool newfie, FILE **f);
char *get_next_filename(const char *name, const char *suffix); char *get_next_filename(const char *name, const char *suffix);
#ifndef NANO_SMALL #ifndef NANO_SMALL
void execute_command(const char *command); void execute_command(const char *command);
#endif #endif
void load_buffer(const char *name);
void do_insertfile( void do_insertfile(
#ifndef NANO_SMALL #ifndef NANO_SMALL
bool execute bool execute
@ -381,7 +362,7 @@ void die(const char *msg, ...);
void die_save_file(const char *die_filename); void die_save_file(const char *die_filename);
void check_die_too_small(void); void check_die_too_small(void);
void resize_variables(void); void resize_variables(void);
void global_init(bool save_cutbuffer); void resize_init(void);
void window_init(void); void window_init(void);
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
void mouse_init(void); void mouse_init(void);
@ -706,8 +687,8 @@ void do_replace_highlight(bool highlight, const char *word);
int check_linenumbers(const filestruct *fileptr); int check_linenumbers(const filestruct *fileptr);
#endif #endif
#ifdef DEBUG #ifdef DEBUG
void dump_buffer(const filestruct *inptr); void dump_filestruct(const filestruct *inptr);
void dump_buffer_reverse(void); void dump_filestruct_reverse(void);
#endif #endif
#ifdef NANO_EXTRA #ifdef NANO_EXTRA
void do_credits(void); void do_credits(void);

View File

@ -57,6 +57,7 @@ int regexp_init(const char *regexp)
); );
assert(!regexp_compiled); assert(!regexp_compiled);
if (rc != 0) { if (rc != 0) {
size_t len = regerror(rc, &search_regexp, NULL, 0); size_t len = regerror(rc, &search_regexp, NULL, 0);
char *str = charalloc(len); char *str = charalloc(len);
@ -100,7 +101,7 @@ void search_abort(void)
{ {
display_main_list(); display_main_list();
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (ISSET(MARK_ISSET)) if (openfile->mark_set)
edit_refresh(); edit_refresh();
#endif #endif
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
@ -192,13 +193,9 @@ int search_init(bool replacing, bool use_answer)
replacing ? replacing ?
#ifndef NANO_SMALL #ifndef NANO_SMALL
(ISSET(MARK_ISSET) ? _(" (to replace) in selection") : openfile->mark_set ? _(" (to replace) in selection") :
#endif #endif
_(" (to replace)") _(" (to replace)") : "",
#ifndef NANO_SMALL
)
#endif
: "",
buf); buf);
@ -246,8 +243,8 @@ int search_init(bool replacing, bool use_answer)
backupstring = mallocstrcpy(backupstring, answer); backupstring = mallocstrcpy(backupstring, answer);
return -2; /* Call the opposite search function. */ return -2; /* Call the opposite search function. */
case NANO_TOGOTOLINE_KEY: case NANO_TOGOTOLINE_KEY:
do_gotolinecolumn(current->lineno, placewewant + 1, do_gotolinecolumn(openfile->current->lineno,
TRUE, TRUE, FALSE); openfile->placewewant + 1, TRUE, TRUE, FALSE);
/* Put answer up on the statusbar and /* Put answer up on the statusbar and
* fall through. */ * fall through. */
default: default:
@ -293,13 +290,13 @@ bool findnextstr(bool can_display_wrap, bool wholeword, bool
no_sameline, const filestruct *begin, size_t beginx, const char no_sameline, const filestruct *begin, size_t beginx, const char
*needle, size_t *needle_len) *needle, size_t *needle_len)
{ {
filestruct *fileptr = current; filestruct *fileptr = openfile->current;
const char *rev_start = NULL, *found = NULL; const char *rev_start = NULL, *found = NULL;
size_t found_len; size_t found_len;
/* The length of the match we found. */ /* The length of the match we found. */
size_t current_x_find = 0; size_t current_x_find = 0;
/* The location of the match we found. */ /* The location of the match we found. */
ssize_t current_y_find = current_y; ssize_t current_y_find = openfile->current_y;
/* rev_start might end up 1 character before the start or after the /* rev_start might end up 1 character before the start or after the
* end of the line. This won't be a problem because strstrwrapper() * end of the line. This won't be a problem because strstrwrapper()
@ -308,9 +305,10 @@ bool findnextstr(bool can_display_wrap, bool wholeword, bool
* previous or next line. */ * previous or next line. */
rev_start = rev_start =
#ifndef NANO_SMALL #ifndef NANO_SMALL
ISSET(BACKWARDS_SEARCH) ? fileptr->data + (current_x - 1) : ISSET(BACKWARDS_SEARCH) ?
fileptr->data + (openfile->current_x - 1) :
#endif #endif
fileptr->data + (current_x + 1); fileptr->data + (openfile->current_x + 1);
/* Look for needle in searchstr. */ /* Look for needle in searchstr. */
while (TRUE) { while (TRUE) {
@ -345,7 +343,7 @@ bool findnextstr(bool can_display_wrap, bool wholeword, bool
* a match on the same line we started on and this potential * a match on the same line we started on and this potential
* match is on that line, continue searching. */ * match is on that line, continue searching. */
if ((!wholeword || found_whole) && (!no_sameline || if ((!wholeword || found_whole) && (!no_sameline ||
fileptr != current)) fileptr != openfile->current))
break; break;
} }
@ -375,11 +373,11 @@ bool findnextstr(bool can_display_wrap, bool wholeword, bool
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (ISSET(BACKWARDS_SEARCH)) { if (ISSET(BACKWARDS_SEARCH)) {
fileptr = filebot; fileptr = openfile->filebot;
current_y_find = editwinrows - 1; current_y_find = editwinrows - 1;
} else { } else {
#endif #endif
fileptr = fileage; fileptr = openfile->fileage;
current_y_find = 0; current_y_find = 0;
#ifndef NANO_SMALL #ifndef NANO_SMALL
} }
@ -417,11 +415,11 @@ bool findnextstr(bool can_display_wrap, bool wholeword, bool
return FALSE; return FALSE;
} }
/* Set globals now that we are sure we found something. */ /* We've definitely found something. */
current = fileptr; openfile->current = fileptr;
current_x = current_x_find; openfile->current_x = current_x_find;
current_y = current_y_find; openfile->current_y = current_y_find;
placewewant = xplustabs(); openfile->placewewant = xplustabs();
/* needle_len holds the length of needle. */ /* needle_len holds the length of needle. */
if (needle_len != NULL) if (needle_len != NULL)
@ -438,10 +436,11 @@ void findnextstr_wrap_reset(void)
/* Search for a string. */ /* Search for a string. */
void do_search(void) void do_search(void)
{ {
size_t old_pww = placewewant, fileptr_x = current_x; size_t old_pww = openfile->placewewant;
size_t fileptr_x = openfile->current_x;
int i; int i;
bool didfind; bool didfind;
filestruct *fileptr = current; filestruct *fileptr = openfile->current;
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
wrap_reset(); wrap_reset();
@ -476,12 +475,13 @@ void do_search(void)
#endif #endif
findnextstr_wrap_reset(); findnextstr_wrap_reset();
didfind = findnextstr(TRUE, FALSE, FALSE, current, current_x, didfind = findnextstr(TRUE, FALSE, FALSE, openfile->current,
answer, NULL); openfile->current_x, answer, NULL);
/* Check to see if there's only one occurrence of the string and /* Check to see if there's only one occurrence of the string and
* we're on it now. */ * we're on it now. */
if (fileptr == current && fileptr_x == current_x && didfind) { if (fileptr == openfile->current && fileptr_x ==
openfile->current_x && didfind) {
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* Do the search again, skipping over the current line, if we're /* Do the search again, skipping over the current line, if we're
* doing a bol and/or eol regex search ("^", "$", or "^$"), so * doing a bol and/or eol regex search ("^", "$", or "^$"), so
@ -490,9 +490,10 @@ void do_search(void)
* which case it's the only occurrence. */ * which case it's the only occurrence. */
if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp, if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp,
last_search)) { last_search)) {
didfind = findnextstr(TRUE, FALSE, TRUE, current, current_x, didfind = findnextstr(TRUE, FALSE, TRUE, openfile->current,
answer, NULL); openfile->current_x, answer, NULL);
if (fileptr == current && fileptr_x == current_x && !didfind) if (fileptr == openfile->current && fileptr_x ==
openfile->current_x && !didfind)
statusbar(_("This is the only occurrence")); statusbar(_("This is the only occurrence"));
} else { } else {
#endif #endif
@ -502,7 +503,7 @@ void do_search(void)
#endif #endif
} }
placewewant = xplustabs(); openfile->placewewant = xplustabs();
edit_redraw(fileptr, old_pww); edit_redraw(fileptr, old_pww);
search_abort(); search_abort();
} }
@ -511,9 +512,10 @@ void do_search(void)
/* Search for the next string without prompting. */ /* Search for the next string without prompting. */
void do_research(void) void do_research(void)
{ {
size_t old_pww = placewewant, fileptr_x = current_x; size_t old_pww = openfile->placewewant;
size_t fileptr_x = openfile->current_x;
bool didfind; bool didfind;
filestruct *fileptr = current; filestruct *fileptr = openfile->current;
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
wrap_reset(); wrap_reset();
@ -530,12 +532,13 @@ void do_research(void)
#endif #endif
findnextstr_wrap_reset(); findnextstr_wrap_reset();
didfind = findnextstr(TRUE, FALSE, FALSE, current, current_x, didfind = findnextstr(TRUE, FALSE, FALSE, openfile->current,
last_search, NULL); openfile->current_x, last_search, NULL);
/* Check to see if there's only one occurrence of the string and /* Check to see if there's only one occurrence of the string and
* we're on it now. */ * we're on it now. */
if (fileptr == current && fileptr_x == current_x && didfind) { if (fileptr == openfile->current && fileptr_x ==
openfile->current_x && didfind) {
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* Do the search again, skipping over the current line, if /* Do the search again, skipping over the current line, if
* we're doing a bol and/or eol regex search ("^", "$", or * we're doing a bol and/or eol regex search ("^", "$", or
@ -544,10 +547,11 @@ void do_research(void)
* found again, in which case it's the only occurrence. */ * found again, in which case it's the only occurrence. */
if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp, if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp,
last_search)) { last_search)) {
didfind = findnextstr(TRUE, FALSE, TRUE, current, didfind = findnextstr(TRUE, FALSE, TRUE,
current_x, answer, NULL); openfile->current, openfile->current_x, answer,
if (fileptr == current && fileptr_x == current_x && NULL);
!didfind) if (fileptr == openfile->current && fileptr_x ==
openfile->current_x && !didfind)
statusbar(_("This is the only occurrence")); statusbar(_("This is the only occurrence"));
} else { } else {
#endif #endif
@ -559,7 +563,7 @@ void do_research(void)
} else } else
statusbar(_("No current search pattern")); statusbar(_("No current search pattern"));
placewewant = xplustabs(); openfile->placewewant = xplustabs();
edit_redraw(fileptr, old_pww); edit_redraw(fileptr, old_pww);
search_abort(); search_abort();
} }
@ -579,18 +583,18 @@ int replace_regexp(char *string, bool create)
* subexpressions \1 to \9 in the replaced text). */ * subexpressions \1 to \9 in the replaced text). */
const char *c = last_replace; const char *c = last_replace;
size_t search_match_count = size_t search_match_count = regmatches[0].rm_eo -
regmatches[0].rm_eo - regmatches[0].rm_so; regmatches[0].rm_so;
size_t new_line_size = size_t new_line_size = strlen(openfile->current->data) + 1 -
strlen(current->data) + 1 - search_match_count; search_match_count;
/* Iterate through the replacement text to handle subexpression /* Iterate through the replacement text to handle subexpression
* replacement using \1, \2, \3, etc. */ * replacement using \1, \2, \3, etc. */
while (*c != '\0') { while (*c != '\0') {
int num = (int)(*(c + 1) - '0'); int num = (int)(*(c + 1) - '0');
if (*c != '\\' || num < 1 || num > 9 || if (*c != '\\' || num < 1 || num > 9 || num >
num > search_regexp.re_nsub) { search_regexp.re_nsub) {
if (create) if (create)
*string++ = *c; *string++ = *c;
c++; c++;
@ -607,8 +611,8 @@ int replace_regexp(char *string, bool create)
/* And if create is TRUE, append the result of the /* And if create is TRUE, append the result of the
* subexpression match to the new line. */ * subexpression match to the new line. */
if (create) { if (create) {
strncpy(string, current->data + current_x + strncpy(string, openfile->current->data +
regmatches[num].rm_so, i); openfile->current_x + regmatches[num].rm_so, i);
string += i; string += i;
} }
} }
@ -634,8 +638,8 @@ char *replace_line(const char *needle)
} else { } else {
#endif #endif
search_match_count = strlen(needle); search_match_count = strlen(needle);
new_line_size = strlen(current->data) - search_match_count + new_line_size = strlen(openfile->current->data) -
strlen(answer) + 1; search_match_count + strlen(answer) + 1;
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
} }
#endif #endif
@ -644,20 +648,21 @@ char *replace_line(const char *needle)
copy = charalloc(new_line_size); copy = charalloc(new_line_size);
/* The head of the original line. */ /* The head of the original line. */
strncpy(copy, current->data, current_x); strncpy(copy, openfile->current->data, openfile->current_x);
/* The replacement text. */ /* The replacement text. */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) if (ISSET(USE_REGEXP))
replace_regexp(copy + current_x, TRUE); replace_regexp(copy + openfile->current_x, TRUE);
else else
#endif #endif
strcpy(copy + current_x, answer); strcpy(copy + openfile->current_x, answer);
/* The tail of the original line. */ /* The tail of the original line. */
assert(current_x + search_match_count <= strlen(current->data)); assert(openfile->current_x + search_match_count <= strlen(openfile->current->data));
strcat(copy, current->data + current_x + search_match_count); strcat(copy, openfile->current->data + openfile->current_x +
search_match_count);
return copy; return copy;
} }
@ -682,8 +687,8 @@ ssize_t do_replace_loop(const char *needle, const filestruct
bool begin_line = FALSE, bol_or_eol = FALSE; bool begin_line = FALSE, bol_or_eol = FALSE;
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
bool old_mark_set = ISSET(MARK_ISSET); bool old_mark_set = openfile->mark_set;
filestruct *edittop_save = edittop, *top, *bot; filestruct *edittop_save = openfile->edittop, *top, *bot;
size_t top_x, bot_x; size_t top_x, bot_x;
bool right_side_up = FALSE; bool right_side_up = FALSE;
/* TRUE if (mark_beginbuf, mark_beginx) is the top of the mark, /* TRUE if (mark_beginbuf, mark_beginx) is the top of the mark,
@ -696,8 +701,8 @@ ssize_t do_replace_loop(const char *needle, const filestruct
mark_order((const filestruct **)&top, &top_x, mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, &right_side_up); (const filestruct **)&bot, &bot_x, &right_side_up);
filepart = partition_filestruct(top, top_x, bot, bot_x); filepart = partition_filestruct(top, top_x, bot, bot_x);
edittop = fileage; openfile->edittop = openfile->fileage;
UNSET(MARK_ISSET); openfile->mark_set = FALSE;
edit_refresh(); edit_refresh();
} }
#endif #endif
@ -724,13 +729,14 @@ ssize_t do_replace_loop(const char *needle, const filestruct
* beginning line already, and we're still on the beginning line * beginning line already, and we're still on the beginning line
* after the search, it means that we've wrapped around, so * after the search, it means that we've wrapped around, so
* we're done. */ * we're done. */
if (bol_or_eol && begin_line && current == real_current) if (bol_or_eol && begin_line && openfile->current ==
real_current)
break; break;
/* Otherwise, set the begin_line flag if we've found a match on /* Otherwise, set the begin_line flag if we've found a match on
* the beginning line, reset the bol_or_eol flag, and * the beginning line, reset the bol_or_eol flag, and
* continue. */ * continue. */
else { else {
if (current == real_current) if (openfile->current == real_current)
begin_line = TRUE; begin_line = TRUE;
bol_or_eol = FALSE; bol_or_eol = FALSE;
} }
@ -745,9 +751,9 @@ ssize_t do_replace_loop(const char *needle, const filestruct
if (!replaceall) { if (!replaceall) {
size_t xpt = xplustabs(); size_t xpt = xplustabs();
char *exp_word = display_string(current->data, xpt, char *exp_word = display_string(openfile->current->data,
strnlenpt(current->data, current_x + match_len) - xpt, xpt, strnlenpt(openfile->current->data,
FALSE); openfile->current_x + match_len) - xpt, FALSE);
curs_set(0); curs_set(0);
@ -785,19 +791,21 @@ ssize_t do_replace_loop(const char *needle, const filestruct
copy = replace_line(needle); copy = replace_line(needle);
length_change = strlen(copy) - strlen(current->data); length_change = strlen(copy) -
strlen(openfile->current->data);
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* If the mark was on and (mark_beginbuf, mark_begin_x) was /* If the mark was on and (mark_beginbuf, mark_begin_x) was
* the top of it, don't change mark_beginx. */ * the top of it, don't change mark_beginx. */
if (!old_mark_set || !right_side_up) { if (!old_mark_set || !right_side_up) {
/* Keep mark_beginx in sync with the text changes. */ /* Keep mark_beginx in sync with the text changes. */
if (current == mark_beginbuf && if (openfile->current == openfile->mark_beginbuf &&
mark_beginx > current_x) { openfile->mark_beginx > openfile->current_x) {
if (mark_beginx < current_x + match_len) if (openfile->mark_beginx < openfile->current_x +
mark_beginx = current_x; match_len)
openfile->mark_beginx = openfile->current_x;
else else
mark_beginx += length_change; openfile->mark_beginx += length_change;
} }
} }
@ -806,10 +814,12 @@ ssize_t do_replace_loop(const char *needle, const filestruct
if (!old_mark_set || right_side_up) { if (!old_mark_set || right_side_up) {
#endif #endif
/* Keep real_current_x in sync with the text changes. */ /* Keep real_current_x in sync with the text changes. */
if (current == real_current && if (openfile->current == real_current &&
current_x <= *real_current_x) { openfile->current_x <= *real_current_x) {
if (*real_current_x < current_x + match_len) if (*real_current_x <
*real_current_x = current_x + match_len; openfile->current_x + match_len)
*real_current_x = openfile->current_x +
match_len;
*real_current_x += length_change; *real_current_x += length_change;
} }
#ifndef NANO_SMALL #ifndef NANO_SMALL
@ -823,12 +833,12 @@ ssize_t do_replace_loop(const char *needle, const filestruct
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (!ISSET(BACKWARDS_SEARCH)) if (!ISSET(BACKWARDS_SEARCH))
#endif #endif
current_x += match_len + length_change - 1; openfile->current_x += match_len + length_change - 1;
/* Cleanup. */ /* Cleanup. */
totsize += length_change; openfile->totsize += length_change;
free(current->data); free(openfile->current->data);
current->data = copy; openfile->current->data = copy;
if (!replaceall) { if (!replaceall) {
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
@ -836,7 +846,7 @@ ssize_t do_replace_loop(const char *needle, const filestruct
edit_refresh(); edit_refresh();
else else
#endif #endif
update_line(current, current_x); update_line(openfile->current, openfile->current_x);
} }
set_modified(); set_modified();
@ -850,14 +860,14 @@ ssize_t do_replace_loop(const char *needle, const filestruct
* contains all the text again, set edittop back to what it was * contains all the text again, set edittop back to what it was
* before, turn the mark back on, and refresh the screen. */ * before, turn the mark back on, and refresh the screen. */
unpartition_filestruct(&filepart); unpartition_filestruct(&filepart);
edittop = edittop_save; openfile->edittop = edittop_save;
SET(MARK_ISSET); openfile->mark_set = TRUE;
edit_refresh(); edit_refresh();
} }
#endif #endif
/* If text has been added to the magicline, make a new magicline. */ /* If text has been added to the magicline, make a new magicline. */
if (filebot->data[0] != '\0') if (openfile->filebot->data[0] != '\0')
new_magicline(); new_magicline();
return numreplaced; return numreplaced;
@ -929,19 +939,19 @@ void do_replace(void)
last_replace = mallocstrcpy(last_replace, answer); last_replace = mallocstrcpy(last_replace, answer);
/* Save where we are. */ /* Save where we are. */
edittop_save = edittop; edittop_save = openfile->edittop;
begin = current; begin = openfile->current;
beginx = current_x; beginx = openfile->current_x;
pww_save = placewewant; pww_save = openfile->placewewant;
numreplaced = do_replace_loop(last_search, begin, &beginx, FALSE, numreplaced = do_replace_loop(last_search, begin, &beginx, FALSE,
NULL); NULL);
/* Restore where we were. */ /* Restore where we were. */
edittop = edittop_save; openfile->edittop = edittop_save;
current = begin; openfile->current = begin;
current_x = beginx; openfile->current_x = beginx;
placewewant = pww_save; openfile->placewewant = pww_save;
renumber_all(); renumber_all();
edit_refresh(); edit_refresh();
@ -997,17 +1007,18 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
} }
} else { } else {
if (line < 1) if (line < 1)
line = current->lineno; line = openfile->current->lineno;
if (column < 1) if (column < 1)
column = placewewant + 1; column = openfile->placewewant + 1;
} }
for (current = fileage; current->next != NULL && line > 1; line--) for (openfile->current = openfile->fileage;
current = current->next; openfile->current->next != NULL && line > 1; line--)
openfile->current = openfile->current->next;
current_x = actual_x(current->data, column - 1); openfile->current_x = actual_x(openfile->current->data, column - 1);
placewewant = column - 1; openfile->placewewant = column - 1;
/* If save_pos is TRUE, don't change the cursor position when /* If save_pos is TRUE, don't change the cursor position when
* updating the edit window. */ * updating the edit window. */
@ -1018,8 +1029,8 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
void do_gotolinecolumn_void(void) void do_gotolinecolumn_void(void)
{ {
do_gotolinecolumn(current->lineno, placewewant + 1, FALSE, TRUE, do_gotolinecolumn(openfile->current->lineno,
FALSE); openfile->placewewant + 1, FALSE, TRUE, FALSE);
} }
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER) #if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
@ -1028,12 +1039,12 @@ void do_gotopos(ssize_t line, size_t pos_x, ssize_t pos_y, size_t
{ {
/* Since do_gotolinecolumn() resets the x-coordinate but not the /* Since do_gotolinecolumn() resets the x-coordinate but not the
* y-coordinate, set the coordinates up this way. */ * y-coordinate, set the coordinates up this way. */
current_y = pos_y; openfile->current_y = pos_y;
do_gotolinecolumn(line, pos_x + 1, FALSE, FALSE, TRUE); do_gotolinecolumn(line, pos_x + 1, FALSE, FALSE, TRUE);
/* Set the rest of the coordinates up. */ /* Set the rest of the coordinates up. */
placewewant = pos_pww; openfile->placewewant = pos_pww;
update_line(current, pos_x); update_line(openfile->current, pos_x);
} }
#endif #endif
@ -1049,7 +1060,7 @@ void do_find_bracket(void)
bool backwards_search_set = ISSET(BACKWARDS_SEARCH); bool backwards_search_set = ISSET(BACKWARDS_SEARCH);
filestruct *current_save; filestruct *current_save;
cursor_ch = current->data[current_x]; cursor_ch = openfile->current->data[openfile->current_x];
pos = strchr(bracket_pat, cursor_ch); pos = strchr(bracket_pat, cursor_ch);
if (cursor_ch == '\0' || pos == NULL) { if (cursor_ch == '\0' || pos == NULL) {
@ -1062,9 +1073,9 @@ void do_find_bracket(void)
wanted_ch = wanted_ch =
bracket_pat[(strlen(bracket_pat) - 1) - (pos - bracket_pat)]; bracket_pat[(strlen(bracket_pat) - 1) - (pos - bracket_pat)];
current_save = current; current_save = openfile->current;
current_x_save = current_x; current_x_save = openfile->current_x;
pww_save = placewewant; pww_save = openfile->placewewant;
SET(USE_REGEXP); SET(USE_REGEXP);
/* Apparent near redundancy with regexp_pat[] here is needed. /* Apparent near redundancy with regexp_pat[] here is needed.
@ -1088,23 +1099,24 @@ void do_find_bracket(void)
findnextstr_wrap_reset(); findnextstr_wrap_reset();
while (TRUE) { while (TRUE) {
if (findnextstr(FALSE, FALSE, FALSE, current, current_x, if (findnextstr(FALSE, FALSE, FALSE, openfile->current,
regexp_pat, NULL)) { openfile->current_x, regexp_pat, NULL)) {
/* Found identical bracket. */ /* Found identical bracket. */
if (current->data[current_x] == cursor_ch) if (openfile->current->data[openfile->current_x] ==
cursor_ch)
count++; count++;
/* Found complementary bracket. */ /* Found complementary bracket. */
else if (--count == 0) { else if (--count == 0) {
placewewant = xplustabs(); openfile->placewewant = xplustabs();
edit_redraw(current_save, pww_save); edit_redraw(current_save, pww_save);
break; break;
} }
} else { } else {
/* Didn't find either a left or right bracket. */ /* Didn't find either a left or right bracket. */
statusbar(_("No matching bracket")); statusbar(_("No matching bracket"));
current = current_save; openfile->current = current_save;
current_x = current_x_save; openfile->current_x = current_x_save;
update_line(current, current_x); update_line(openfile->current, openfile->current_x);
break; break;
} }
} }

View File

@ -375,14 +375,14 @@ char *mallocstrassn(char *dest, char *src)
/* Append a new magicline to filebot. */ /* Append a new magicline to filebot. */
void new_magicline(void) void new_magicline(void)
{ {
filebot->next = (filestruct *)nmalloc(sizeof(filestruct)); openfile->filebot->next = (filestruct *)nmalloc(sizeof(filestruct));
filebot->next->data = mallocstrcpy(NULL, ""); openfile->filebot->next->data = mallocstrcpy(NULL, "");
filebot->next->prev = filebot; openfile->filebot->next->prev = openfile->filebot;
filebot->next->next = NULL; openfile->filebot->next->next = NULL;
filebot->next->lineno = filebot->lineno + 1; openfile->filebot->next->lineno = openfile->filebot->lineno + 1;
filebot = filebot->next; openfile->filebot = openfile->filebot->next;
totlines++; openfile->totlines++;
totsize++; openfile->totsize++;
} }
#ifndef NANO_SMALL #ifndef NANO_SMALL
@ -390,12 +390,13 @@ void new_magicline(void)
* only line in the file. */ * only line in the file. */
void remove_magicline(void) void remove_magicline(void)
{ {
if (filebot->data[0] == '\0' && filebot->prev != NULL) { if (openfile->filebot->data[0] == '\0' &&
filebot = filebot->prev; openfile->filebot->prev != NULL) {
free_filestruct(filebot->next); openfile->filebot = openfile->filebot->prev;
filebot->next = NULL; free_filestruct(openfile->filebot->next);
totlines--; openfile->filebot->next = NULL;
totsize--; openfile->totlines--;
openfile->totsize--;
} }
} }
@ -409,19 +410,20 @@ void mark_order(const filestruct **top, size_t *top_x, const filestruct
{ {
assert(top != NULL && top_x != NULL && bot != NULL && bot_x != NULL); assert(top != NULL && top_x != NULL && bot != NULL && bot_x != NULL);
if ((current->lineno == mark_beginbuf->lineno && current_x > if ((openfile->current->lineno == openfile->mark_beginbuf->lineno &&
mark_beginx) || current->lineno > mark_beginbuf->lineno) { openfile->current_x > openfile->mark_beginx) ||
*top = mark_beginbuf; openfile->current->lineno > openfile->mark_beginbuf->lineno) {
*top_x = mark_beginx; *top = openfile->mark_beginbuf;
*bot = current; *top_x = openfile->mark_beginx;
*bot_x = current_x; *bot = openfile->current;
*bot_x = openfile->current_x;
if (right_side_up != NULL) if (right_side_up != NULL)
*right_side_up = TRUE; *right_side_up = TRUE;
} else { } else {
*bot = mark_beginbuf; *bot = openfile->mark_beginbuf;
*bot_x = mark_beginx; *bot_x = openfile->mark_beginx;
*top = current; *top = openfile->current;
*top_x = current_x; *top_x = openfile->current_x;
if (right_side_up != NULL) if (right_side_up != NULL)
*right_side_up = FALSE; *right_side_up = FALSE;
} }

View File

@ -1688,7 +1688,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
/* If we're using restricted mode, the filename isn't blank, /* If we're using restricted mode, the filename isn't blank,
* and we're at the "Write File" prompt, disable text * and we're at the "Write File" prompt, disable text
* input. */ * input. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' || if (!ISSET(RESTRICTED) || openfile->filename[0] == '\0' ||
currshortcut != writefile_list) { currshortcut != writefile_list) {
kbinput_len++; kbinput_len++;
kbinput = (int *)nrealloc(kbinput, kbinput_len * kbinput = (int *)nrealloc(kbinput, kbinput_len *
@ -1748,24 +1748,24 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
/* If we're using restricted mode, the filename /* If we're using restricted mode, the filename
* isn't blank, and we're at the "Write File" * isn't blank, and we're at the "Write File"
* prompt, disable Backspace. */ * prompt, disable Backspace. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' || if (!ISSET(RESTRICTED) || openfile->filename[0] ==
currshortcut != writefile_list) '\0' || currshortcut != writefile_list)
do_statusbar_backspace(); do_statusbar_backspace();
break; break;
case NANO_DELETE_KEY: case NANO_DELETE_KEY:
/* If we're using restricted mode, the filename /* If we're using restricted mode, the filename
* isn't blank, and we're at the "Write File" * isn't blank, and we're at the "Write File"
* prompt, disable Delete. */ * prompt, disable Delete. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' || if (!ISSET(RESTRICTED) || openfile->filename[0] ==
currshortcut != writefile_list) '\0' || currshortcut != writefile_list)
do_statusbar_delete(); do_statusbar_delete();
break; break;
case NANO_CUT_KEY: case NANO_CUT_KEY:
/* If we're using restricted mode, the filename /* If we're using restricted mode, the filename
* isn't blank, and we're at the "Write File" * isn't blank, and we're at the "Write File"
* prompt, disable Cut. */ * prompt, disable Cut. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' || if (!ISSET(RESTRICTED) || openfile->filename[0] ==
currshortcut != writefile_list) '\0' || currshortcut != writefile_list)
do_statusbar_cut_text(); do_statusbar_cut_text();
break; break;
#ifndef NANO_SMALL #ifndef NANO_SMALL
@ -1782,7 +1782,8 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
/* If we're using restricted mode, the filename /* If we're using restricted mode, the filename
* isn't blank, and we're at the "Write File" * isn't blank, and we're at the "Write File"
* prompt, disable verbatim input. */ * prompt, disable verbatim input. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' || if (!ISSET(RESTRICTED) ||
openfile->filename[0] == '\0' ||
currshortcut != writefile_list) { currshortcut != writefile_list) {
bool got_enter; bool got_enter;
/* Whether we got the Enter key. */ /* Whether we got the Enter key. */
@ -2149,7 +2150,7 @@ void do_statusbar_output(char *output, size_t output_len, bool
* current_x. */ * current_x. */
size_t xplustabs(void) size_t xplustabs(void)
{ {
return strnlenpt(current->data, current_x); return strnlenpt(openfile->current->data, openfile->current_x);
} }
/* actual_x() gives the index in str of the character displayed at /* actual_x() gives the index in str of the character displayed at
@ -2751,7 +2752,7 @@ void titlebar(const char *path)
bool dots = FALSE; bool dots = FALSE;
/* Do we put an ellipsis before the path? */ /* Do we put an ellipsis before the path? */
assert(path != NULL || filename != NULL); assert(path != NULL || openfile->filename != NULL);
assert(COLS >= 0); assert(COLS >= 0);
wattron(topwin, A_REVERSE); wattron(topwin, A_REVERSE);
@ -2775,7 +2776,7 @@ void titlebar(const char *path)
waddstr(topwin, " "); waddstr(topwin, " ");
} }
if (ISSET(MODIFIED)) if (openfile->modified)
state = _("Modified"); state = _("Modified");
else if (ISSET(VIEW_MODE)) else if (ISSET(VIEW_MODE))
state = _("View"); state = _("View");
@ -2787,7 +2788,7 @@ void titlebar(const char *path)
statelen = strnlenpt(state, COLS); statelen = strnlenpt(state, COLS);
/* We need a space before state. */ /* We need a space before state. */
if ((ISSET(MODIFIED) || ISSET(VIEW_MODE)) && statelen < COLS) if ((openfile->modified || ISSET(VIEW_MODE)) && statelen < COLS)
statelen++; statelen++;
assert(space >= 0); assert(space >= 0);
@ -2800,7 +2801,7 @@ void titlebar(const char *path)
prefix = _("DIR:"); prefix = _("DIR:");
else else
#endif #endif
if (filename[0] == '\0') { if (openfile->filename[0] == '\0') {
prefix = _("New Buffer"); prefix = _("New Buffer");
newfie = TRUE; newfie = TRUE;
} else } else
@ -2815,7 +2816,7 @@ void titlebar(const char *path)
prefixlen++; prefixlen++;
if (path == NULL) if (path == NULL)
path = filename; path = openfile->filename;
if (space >= prefixlen + statelen) if (space >= prefixlen + statelen)
space -= prefixlen + statelen; space -= prefixlen + statelen;
else else
@ -2881,11 +2882,12 @@ void titlebar(const char *path)
wrefresh(edit); wrefresh(edit);
} }
/* If MODIFIED is not already set, set it and update the titlebar. */ /* Set the modified flag if it isn't already set, and then update the
* titlebar. */
void set_modified(void) void set_modified(void)
{ {
if (!ISSET(MODIFIED)) { if (!openfile->modified) {
SET(MODIFIED); openfile->modified = TRUE;
titlebar(NULL); titlebar(NULL);
} }
} }
@ -3061,15 +3063,16 @@ void reset_cursor(void)
{ {
/* If we haven't opened any files yet, put the cursor in the top /* If we haven't opened any files yet, put the cursor in the top
* left corner of the edit window and get out. */ * left corner of the edit window and get out. */
if (edittop == NULL || current == NULL) { if (openfile->edittop == NULL || openfile->current == NULL) {
wmove(edit, 0, 0); wmove(edit, 0, 0);
return; return;
} }
current_y = current->lineno - edittop->lineno; openfile->current_y = openfile->current->lineno -
if (current_y < editwinrows) { openfile->edittop->lineno;
if (openfile->current_y < editwinrows) {
size_t x = xplustabs(); size_t x = xplustabs();
wmove(edit, current_y, x - get_page_start(x)); wmove(edit, openfile->current_y, x - get_page_start(x));
} }
} }
@ -3335,13 +3338,12 @@ void edit_add(const filestruct *fileptr, const char *converted, int
#endif /* ENABLE_COLOR */ #endif /* ENABLE_COLOR */
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (ISSET(MARK_ISSET) if (openfile->mark_set && (fileptr->lineno <=
&& (fileptr->lineno <= mark_beginbuf->lineno openfile->mark_beginbuf->lineno || fileptr->lineno <=
|| fileptr->lineno <= current->lineno) openfile->current->lineno) && (fileptr->lineno >=
&& (fileptr->lineno >= mark_beginbuf->lineno openfile->mark_beginbuf->lineno || fileptr->lineno >=
|| fileptr->lineno >= current->lineno)) { openfile->current->lineno)) {
/* fileptr is at least partially selected. */ /* fileptr is at least partially selected. */
const filestruct *top; const filestruct *top;
/* Either current or mark_beginbuf, whichever is first. */ /* Either current or mark_beginbuf, whichever is first. */
size_t top_x; size_t top_x;
@ -3424,7 +3426,7 @@ void update_line(const filestruct *fileptr, size_t index)
assert(fileptr != NULL); assert(fileptr != NULL);
line = fileptr->lineno - edittop->lineno; line = fileptr->lineno - openfile->edittop->lineno;
/* We assume the line numbers are valid. Is that really true? */ /* We assume the line numbers are valid. Is that really true? */
assert(line < 0 || line == check_linenumbers(fileptr)); assert(line < 0 || line == check_linenumbers(fileptr));
@ -3437,7 +3439,8 @@ void update_line(const filestruct *fileptr, size_t index)
/* Next, convert variables that index the line to their equivalent /* Next, convert variables that index the line to their equivalent
* positions in the expanded line. */ * positions in the expanded line. */
index = (fileptr == current) ? strnlenpt(fileptr->data, index) : 0; index = (fileptr == openfile->current) ? strnlenpt(fileptr->data,
index) : 0;
page_start = get_page_start(index); page_start = get_page_start(index);
/* Expand the line, replacing tabs with spaces, and control /* Expand the line, replacing tabs with spaces, and control
@ -3461,9 +3464,10 @@ int need_horizontal_update(size_t old_pww)
{ {
return return
#ifndef NANO_SMALL #ifndef NANO_SMALL
ISSET(MARK_ISSET) || openfile->mark_set ||
#endif #endif
get_page_start(old_pww) != get_page_start(placewewant); get_page_start(old_pww) !=
get_page_start(openfile->placewewant);
} }
/* Return a nonzero value if we need an update after moving vertically. /* Return a nonzero value if we need an update after moving vertically.
@ -3473,9 +3477,10 @@ int need_vertical_update(size_t old_pww)
{ {
return return
#ifndef NANO_SMALL #ifndef NANO_SMALL
ISSET(MARK_ISSET) || openfile->mark_set ||
#endif #endif
get_page_start(old_pww) != get_page_start(placewewant); get_page_start(old_pww) !=
get_page_start(openfile->placewewant);
} }
/* Scroll the edit window in the given direction and the given number /* Scroll the edit window in the given direction and the given number
@ -3503,14 +3508,14 @@ void edit_scroll(updown direction, int nlines)
* how many lines we moved in scroll_rows. */ * how many lines we moved in scroll_rows. */
for (i = nlines; i > 0; i--) { for (i = nlines; i > 0; i--) {
if (direction == UP) { if (direction == UP) {
if (edittop->prev == NULL) if (openfile->edittop->prev == NULL)
break; break;
edittop = edittop->prev; openfile->edittop = openfile->edittop->prev;
scroll_rows--; scroll_rows--;
} else { } else {
if (edittop->next == NULL) if (openfile->edittop->next == NULL)
break; break;
edittop = edittop->next; openfile->edittop = openfile->edittop->next;
scroll_rows++; scroll_rows++;
} }
} }
@ -3521,7 +3526,7 @@ void edit_scroll(updown direction, int nlines)
wscrl(edit, scroll_rows); wscrl(edit, scroll_rows);
scrollok(edit, FALSE); scrollok(edit, FALSE);
foo = edittop; foo = openfile->edittop;
if (direction != UP) { if (direction != UP) {
int slines = editwinrows - nlines; int slines = editwinrows - nlines;
for (; slines > 0 && foo != NULL; slines--) for (; slines > 0 && foo != NULL; slines--)
@ -3552,10 +3557,11 @@ void edit_redraw(const filestruct *old_current, size_t old_pww)
/* If either old_current or current is offscreen, refresh the screen /* If either old_current or current is offscreen, refresh the screen
* and get out. */ * and get out. */
if (old_current->lineno < edittop->lineno || old_current->lineno >= if (old_current->lineno < openfile->edittop->lineno ||
edittop->lineno + editwinrows || current->lineno < old_current->lineno >= openfile->edittop->lineno +
edittop->lineno || current->lineno >= edittop->lineno + editwinrows || openfile->current->lineno <
editwinrows) { openfile->edittop->lineno || openfile->current->lineno >=
openfile->edittop->lineno + editwinrows) {
edit_refresh(); edit_refresh();
return; return;
} }
@ -3564,27 +3570,30 @@ void edit_redraw(const filestruct *old_current, size_t old_pww)
* and/or we're not on the same page as before. If the mark is on, * and/or we're not on the same page as before. If the mark is on,
* update all the lines between old_current and current too. */ * update all the lines between old_current and current too. */
foo = old_current; foo = old_current;
while (foo != current) { while (foo != openfile->current) {
if (do_refresh) if (do_refresh)
update_line(foo, 0); update_line(foo, 0);
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (!ISSET(MARK_ISSET)) if (!openfile->mark_set)
#endif #endif
break; break;
if (foo->lineno > current->lineno) #ifndef NANO_SMALL
if (foo->lineno > openfile->current->lineno)
foo = foo->prev; foo = foo->prev;
else else
foo = foo->next; foo = foo->next;
#endif
} }
if (do_refresh) if (do_refresh)
update_line(current, current_x); update_line(openfile->current, openfile->current_x);
} }
/* Refresh the screen without changing the position of lines. */ /* Refresh the screen without changing the position of lines. */
void edit_refresh(void) void edit_refresh(void)
{ {
if (current->lineno < edittop->lineno || if (openfile->current->lineno < openfile->edittop->lineno ||
current->lineno >= edittop->lineno + editwinrows) openfile->current->lineno >= openfile->edittop->lineno +
editwinrows)
/* Note that edit_update() changes edittop so that it's in range /* Note that edit_update() changes edittop so that it's in range
* of current. Thus, when it then calls edit_refresh(), there * of current. Thus, when it then calls edit_refresh(), there
* is no danger of getting an infinite loop. */ * is no danger of getting an infinite loop. */
@ -3595,14 +3604,15 @@ void edit_refresh(void)
CENTER); CENTER);
else { else {
int nlines = 0; int nlines = 0;
const filestruct *foo = edittop; const filestruct *foo = openfile->edittop;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "edit_refresh(): edittop->lineno = %ld\n", (long)edittop->lineno); fprintf(stderr, "edit_refresh(): edittop->lineno = %ld\n", (long)openfile->edittop->lineno);
#endif #endif
while (nlines < editwinrows) { while (nlines < editwinrows) {
update_line(foo, foo == current ? current_x : 0); update_line(foo, foo == openfile->current ?
openfile->current_x : 0);
nlines++; nlines++;
if (foo->next == NULL) if (foo->next == NULL)
break; break;
@ -3621,7 +3631,7 @@ void edit_refresh(void)
* the same place and move edittop to put it in range of current. */ * the same place and move edittop to put it in range of current. */
void edit_update(topmidnone location) void edit_update(topmidnone location)
{ {
filestruct *foo = current; filestruct *foo = openfile->current;
if (location != TOP) { if (location != TOP) {
/* If location is CENTER, we move edittop up (editwinrows / 2) /* If location is CENTER, we move edittop up (editwinrows / 2)
@ -3637,7 +3647,7 @@ void edit_update(topmidnone location)
if (location == CENTER) if (location == CENTER)
goal = editwinrows / 2; goal = editwinrows / 2;
else { else {
goal = current_y; goal = openfile->current_y;
/* Limit goal to (editwinrows - 1) lines maximum. */ /* Limit goal to (editwinrows - 1) lines maximum. */
if (goal > editwinrows - 1) if (goal > editwinrows - 1)
@ -3648,7 +3658,7 @@ void edit_update(topmidnone location)
foo = foo->prev; foo = foo->prev;
} }
edittop = foo; openfile->edittop = foo;
edit_refresh(); edit_refresh();
} }
@ -3800,22 +3810,22 @@ void do_cursorpos(bool constant)
char c; char c;
filestruct *f; filestruct *f;
size_t i, cur_xpt = xplustabs() + 1; size_t i, cur_xpt = xplustabs() + 1;
size_t cur_lenpt = strlenpt(current->data) + 1; size_t cur_lenpt = strlenpt(openfile->current->data) + 1;
int linepct, colpct, charpct; int linepct, colpct, charpct;
assert(current != NULL && fileage != NULL && totlines != 0); assert(openfile->current != NULL && openfile->fileage != NULL && openfile->totlines != 0);
c = current->data[current_x]; c = openfile->current->data[openfile->current_x];
f = current->next; f = openfile->current->next;
current->data[current_x] = '\0'; openfile->current->data[openfile->current_x] = '\0';
current->next = NULL; openfile->current->next = NULL;
get_totals(fileage, current, NULL, &i); get_totals(openfile->fileage, openfile->current, NULL, &i);
current->data[current_x] = c; openfile->current->data[openfile->current_x] = c;
current->next = f; openfile->current->next = f;
/* Check whether totsize is correct. If it isn't, there is a bug /* Check whether totsize is correct. If it isn't, there is a bug
* somewhere. */ * somewhere. */
assert(current != filebot || i == totsize); assert(openfile->current != openfile->filebot || i == openfile->totsize);
if (constant && disable_cursorpos) { if (constant && disable_cursorpos) {
disable_cursorpos = FALSE; disable_cursorpos = FALSE;
@ -3824,15 +3834,17 @@ void do_cursorpos(bool constant)
/* Display the current cursor position on the statusbar, and set /* Display the current cursor position on the statusbar, and set
* disable_cursorpos to FALSE. */ * disable_cursorpos to FALSE. */
linepct = 100 * current->lineno / totlines; linepct = 100 * openfile->current->lineno / openfile->totlines;
colpct = 100 * cur_xpt / cur_lenpt; colpct = 100 * cur_xpt / cur_lenpt;
charpct = (totsize == 0) ? 0 : 100 * i / totsize; charpct = (openfile->totsize == 0) ? 0 : 100 * i /
openfile->totsize;
statusbar( statusbar(
_("line %ld/%lu (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"), _("line %ld/%lu (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"),
(long)current->lineno, (unsigned long)totlines, linepct, (long)openfile->current->lineno,
(unsigned long)openfile->totlines, linepct,
(unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct, (unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct,
(unsigned long)i, (unsigned long)totsize, charpct); (unsigned long)i, (unsigned long)openfile->totsize, charpct);
disable_cursorpos = FALSE; disable_cursorpos = FALSE;
} }
@ -4045,7 +4057,8 @@ int check_linenumbers(const filestruct *fileptr)
int check_line = 0; int check_line = 0;
const filestruct *filetmp; const filestruct *filetmp;
for (filetmp = edittop; filetmp != fileptr; filetmp = filetmp->next) for (filetmp = openfile->edittop; filetmp != fileptr;
filetmp = filetmp->next)
check_line++; check_line++;
return check_line; return check_line;
@ -4054,9 +4067,9 @@ int check_linenumbers(const filestruct *fileptr)
#ifdef DEBUG #ifdef DEBUG
/* Dump the filestruct inptr to stderr. */ /* Dump the filestruct inptr to stderr. */
void dump_buffer(const filestruct *inptr) void dump_filestruct(const filestruct *inptr)
{ {
if (inptr == fileage) if (inptr == openfile->fileage)
fprintf(stderr, "Dumping file buffer to stderr...\n"); fprintf(stderr, "Dumping file buffer to stderr...\n");
else if (inptr == cutbuffer) else if (inptr == cutbuffer)
fprintf(stderr, "Dumping cutbuffer to stderr...\n"); fprintf(stderr, "Dumping cutbuffer to stderr...\n");
@ -4070,9 +4083,9 @@ void dump_buffer(const filestruct *inptr)
} }
/* Dump the main filestruct to stderr in reverse. */ /* Dump the main filestruct to stderr in reverse. */
void dump_buffer_reverse(void) void dump_filestruct_reverse(void)
{ {
const filestruct *fileptr = filebot; const filestruct *fileptr = openfile->filebot;
while (fileptr != NULL) { while (fileptr != NULL) {
fprintf(stderr, "(%ld) %s\n", (long)fileptr->lineno, fprintf(stderr, "(%ld) %s\n", (long)fileptr->lineno,