1
1

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
Этот коммит содержится в:
David Lawrence Ramsey 2005-07-08 20:09:16 +00:00
родитель 64661ac140
Коммит 6ad59cd29b
12 изменённых файлов: 1163 добавлений и 1304 удалений

Просмотреть файл

@ -7,6 +7,17 @@ CVS code -
backup_lines(). (DLR)
- Reorder some functions 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:
shortcut_init()
- Simplify wording of nano_gotoline_msg. (Jordi)

Просмотреть файл

@ -110,7 +110,7 @@ void update_color(void)
for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
/* 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;
if (colorstrings != NULL)

Просмотреть файл

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

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -43,24 +43,9 @@ unsigned long flags = 0; /* Our flag containing many options */
WINDOW *topwin; /* Top buffer */
WINDOW *edit; /* The file portion of the editor */
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
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 */
#ifndef DISABLE_JUSTIFY
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
file struct */
#ifdef ENABLE_MULTIBUFFER
openfilestruct *openfile = NULL;
/* The list of open file buffers */
#endif
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
char *whitespace = NULL; /* Characters used when displaying
@ -102,12 +85,6 @@ char *backup_dir = NULL; /* Backup directory. */
#endif
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
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 */
#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
char *operating_dir = NULL; /* Operating directory, which we can't */
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");
#endif
#ifdef ENABLE_MULTIBUFFER
const char *nano_openprev_msg =
const char *nano_prevfile_msg =
N_("Switch to the previous file buffer");
const char *nano_opennext_msg =
const char *nano_nextfile_msg =
N_("Switch to the next file buffer");
#endif
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 */
sc_init_one(&main_list, NANO_EXIT_KEY,
#ifdef ENABLE_MULTIBUFFER
openfile != NULL && openfile != openfile->next ? N_("Close") :
openfile != NULL && openfile != openfile->next ?
N_("Close") :
#endif
exit_msg, IFHELP(nano_exit_msg, NANO_NO_KEY), NANO_EXIT_FKEY,
NANO_NO_KEY, VIEW, do_exit);
@ -590,12 +561,12 @@ void shortcut_init(bool unjustify)
#ifdef ENABLE_MULTIBUFFER
sc_init_one(&main_list, NANO_NO_KEY, N_("Previous File"),
IFHELP(nano_openprev_msg, NANO_OPENPREV_KEY), NANO_NO_KEY,
NANO_OPENPREV_ALTKEY, VIEW, open_prevfile_void);
IFHELP(nano_prevfile_msg, NANO_PREVFILE_KEY), NANO_NO_KEY,
NANO_PREVFILE_ALTKEY, VIEW, switch_to_prev_buffer_void);
sc_init_one(&main_list, NANO_NO_KEY, N_("Next File"),
IFHELP(nano_opennext_msg, NANO_OPENNEXT_KEY), NANO_NO_KEY,
NANO_OPENNEXT_ALTKEY, VIEW, open_nextfile_void);
IFHELP(nano_nextfile_msg, NANO_NEXTFILE_KEY), NANO_NO_KEY,
NANO_NEXTFILE_ALTKEY, VIEW, switch_to_next_buffer_void);
#endif
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)
free(help_text);
#endif
if (filename != NULL)
free(filename);
if (answer != NULL)
free(answer);
if (cutbuffer != NULL)
@ -1240,19 +1209,9 @@ void thanks_for_all_the_fish(void)
free(t);
}
#endif
#ifdef ENABLE_MULTIBUFFER
/* Free the memory associated with each open file buffer. */
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;
if (openfile != NULL)
free_openfilestruct(openfile);
}
#else
if (fileage != NULL)
free_filestruct(fileage);
#endif
#ifdef ENABLE_COLOR
if (syntaxstr != NULL)
free(syntaxstr);

Просмотреть файл

@ -32,74 +32,75 @@
void do_first_line(void)
{
size_t pww_save = placewewant;
current = fileage;
placewewant = 0;
current_x = 0;
if (edittop != fileage || need_vertical_update(pww_save))
size_t pww_save = openfile->placewewant;
openfile->current = openfile->fileage;
openfile->placewewant = 0;
openfile->current_x = 0;
if (openfile->edittop != openfile->fileage ||
need_vertical_update(pww_save))
edit_update(TOP);
}
void do_last_line(void)
{
size_t pww_save = placewewant;
current = filebot;
placewewant = 0;
current_x = 0;
if (edittop->lineno + (editwinrows / 2) != filebot->lineno ||
need_vertical_update(pww_save))
size_t pww_save = openfile->placewewant;
openfile->current = openfile->filebot;
openfile->placewewant = 0;
openfile->current_x = 0;
if (openfile->edittop->lineno + (editwinrows / 2) !=
openfile->filebot->lineno || need_vertical_update(pww_save))
edit_update(CENTER);
}
void do_home(void)
{
size_t pww_save = placewewant;
size_t pww_save = openfile->placewewant;
#ifndef NANO_SMALL
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 ||
current->data[current_x] == '\0')
current_x = 0;
if (openfile->current_x == current_x_save ||
openfile->current->data[openfile->current_x] == '\0')
openfile->current_x = 0;
placewewant = xplustabs();
openfile->placewewant = xplustabs();
} else {
#endif
current_x = 0;
placewewant = 0;
openfile->current_x = 0;
openfile->placewewant = 0;
#ifndef NANO_SMALL
}
#endif
check_statusblank();
if (need_horizontal_update(pww_save))
update_line(current, current_x);
update_line(openfile->current, openfile->current_x);
}
void do_end(void)
{
size_t pww_save = placewewant;
current_x = strlen(current->data);
placewewant = xplustabs();
size_t pww_save = openfile->placewewant;
openfile->current_x = strlen(openfile->current->data);
openfile->placewewant = xplustabs();
check_statusblank();
if (need_horizontal_update(pww_save))
update_line(current, current_x);
update_line(openfile->current, openfile->current_x);
}
void do_page_up(void)
{
size_t pww_save = placewewant;
const filestruct *current_save = current;
size_t pww_save = openfile->placewewant;
const filestruct *current_save = openfile->current;
#ifndef DISABLE_WRAPPING
wrap_reset();
#endif
/* If the first line of the file is onscreen, move current up there
* and put the cursor at the beginning of the line. */
if (edittop == fileage) {
current = fileage;
placewewant = 0;
if (openfile->edittop == openfile->fileage) {
openfile->current = openfile->fileage;
openfile->placewewant = 0;
} else {
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
* page of text left, move the current line of the edit window
* up a page. */
if (ISSET(SMOOTH_SCROLL) && current->lineno > editwinrows - 2) {
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno >
editwinrows - 2) {
int 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
* one page of text left, put the cursor at the beginning of the
* top line of the edit window, as Pico does. */
else {
#endif
current = edittop;
placewewant = 0;
openfile->current = openfile->edittop;
openfile->placewewant = 0;
#ifndef NANO_SMALL
}
#endif
}
/* 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. */
edit_redraw(current_save, pww_save);
@ -135,17 +138,18 @@ void do_page_up(void)
void do_page_down(void)
{
size_t pww_save = placewewant;
const filestruct *current_save = current;
size_t pww_save = openfile->placewewant;
const filestruct *current_save = openfile->current;
#ifndef DISABLE_WRAPPING
wrap_reset();
#endif
/* If the last line of the file is onscreen, move current down
* there and put the cursor at the beginning of the line. */
if (edittop->lineno + editwinrows > filebot->lineno) {
current = filebot;
placewewant = 0;
if (openfile->edittop->lineno + editwinrows >
openfile->filebot->lineno) {
openfile->current = openfile->filebot;
openfile->placewewant = 0;
} else {
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
* page of text left, move the current line of the edit window
* down a page. */
if (ISSET(SMOOTH_SCROLL) && current->lineno + editwinrows - 2 <=
filebot->lineno) {
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno +
editwinrows - 2 <= openfile->filebot->lineno) {
int 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
* one page of text left, put the cursor at the beginning of the
* top line of the edit window, as Pico does. */
else {
#endif
current = edittop;
placewewant = 0;
openfile->current = openfile->edittop;
openfile->placewewant = 0;
#ifndef NANO_SMALL
}
#endif
}
/* 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. */
edit_redraw(current_save, pww_save);
@ -187,18 +192,19 @@ void do_up(void)
#endif
check_statusblank();
if (current->prev == NULL)
if (openfile->current->prev == NULL)
return;
assert(current_y == current->lineno - edittop->lineno);
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
current = current->prev;
current_x = actual_x(current->data, placewewant);
openfile->current = openfile->current->prev;
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 in smooth scrolling mode, or up half a page if we're
* not. */
if (current_y == 0)
if (openfile->current_y == 0)
edit_scroll(UP,
#ifndef NANO_SMALL
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
* drawn. */
if (need_vertical_update(0))
update_line(current->next, 0);
update_line(current, current_x);
update_line(openfile->current->next, 0);
update_line(openfile->current, openfile->current_x);
}
void do_down(void)
@ -221,18 +227,19 @@ void do_down(void)
#endif
check_statusblank();
if (current->next == NULL)
if (openfile->current->next == NULL)
return;
assert(current_y == current->lineno - edittop->lineno);
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
current = current->next;
current_x = actual_x(current->data, placewewant);
openfile->current = openfile->current->next;
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 in smooth scrolling mode, or down half a page if we're
* not. */
if (current_y == editwinrows - 1)
if (openfile->current_y == editwinrows - 1)
edit_scroll(DOWN,
#ifndef NANO_SMALL
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
* drawn. */
if (need_vertical_update(0))
update_line(current->prev, 0);
update_line(current, current_x);
update_line(openfile->current->prev, 0);
update_line(openfile->current, openfile->current_x);
}
void do_left(bool allow_update)
{
size_t pww_save = placewewant;
if (current_x > 0)
current_x = move_mbleft(current->data, current_x);
else if (current != fileage) {
size_t pww_save = openfile->placewewant;
if (openfile->current_x > 0)
openfile->current_x = move_mbleft(openfile->current->data,
openfile->current_x);
else if (openfile->current != openfile->fileage) {
do_up();
current_x = strlen(current->data);
openfile->current_x = strlen(openfile->current->data);
}
placewewant = xplustabs();
openfile->placewewant = xplustabs();
check_statusblank();
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)
@ -270,19 +279,20 @@ void do_left_void(void)
void do_right(bool allow_update)
{
size_t pww_save = placewewant;
assert(current_x <= strlen(current->data));
size_t pww_save = openfile->placewewant;
assert(openfile->current_x <= strlen(openfile->current->data));
if (current->data[current_x] != '\0')
current_x = move_mbright(current->data, current_x);
else if (current->next != NULL) {
if (openfile->current->data[openfile->current_x] != '\0')
openfile->current_x = move_mbright(openfile->current->data,
openfile->current_x);
else if (openfile->current->next != NULL) {
do_down();
current_x = 0;
openfile->current_x = 0;
}
placewewant = xplustabs();
openfile->placewewant = xplustabs();
check_statusblank();
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)

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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,
* and we're at the "Write File" prompt, disable text
* input. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' ||
if (!ISSET(RESTRICTED) || openfile->filename[0] == '\0' ||
currshortcut != writefile_list) {
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
* isn't blank, and we're at the "Write File"
* prompt, disable Backspace. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' ||
currshortcut != writefile_list)
if (!ISSET(RESTRICTED) || openfile->filename[0] ==
'\0' || currshortcut != writefile_list)
do_statusbar_backspace();
break;
case NANO_DELETE_KEY:
/* If we're using restricted mode, the filename
* isn't blank, and we're at the "Write File"
* prompt, disable Delete. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' ||
currshortcut != writefile_list)
if (!ISSET(RESTRICTED) || openfile->filename[0] ==
'\0' || currshortcut != writefile_list)
do_statusbar_delete();
break;
case NANO_CUT_KEY:
/* If we're using restricted mode, the filename
* isn't blank, and we're at the "Write File"
* prompt, disable Cut. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' ||
currshortcut != writefile_list)
if (!ISSET(RESTRICTED) || openfile->filename[0] ==
'\0' || currshortcut != writefile_list)
do_statusbar_cut_text();
break;
#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
* isn't blank, and we're at the "Write File"
* prompt, disable verbatim input. */
if (!ISSET(RESTRICTED) || filename[0] == '\0' ||
if (!ISSET(RESTRICTED) ||
openfile->filename[0] == '\0' ||
currshortcut != writefile_list) {
bool got_enter;
/* Whether we got the Enter key. */
@ -2149,7 +2150,7 @@ void do_statusbar_output(char *output, size_t output_len, bool
* current_x. */
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
@ -2751,7 +2752,7 @@ void titlebar(const char *path)
bool dots = FALSE;
/* Do we put an ellipsis before the path? */
assert(path != NULL || filename != NULL);
assert(path != NULL || openfile->filename != NULL);
assert(COLS >= 0);
wattron(topwin, A_REVERSE);
@ -2775,7 +2776,7 @@ void titlebar(const char *path)
waddstr(topwin, " ");
}
if (ISSET(MODIFIED))
if (openfile->modified)
state = _("Modified");
else if (ISSET(VIEW_MODE))
state = _("View");
@ -2787,7 +2788,7 @@ void titlebar(const char *path)
statelen = strnlenpt(state, COLS);
/* We need a space before state. */
if ((ISSET(MODIFIED) || ISSET(VIEW_MODE)) && statelen < COLS)
if ((openfile->modified || ISSET(VIEW_MODE)) && statelen < COLS)
statelen++;
assert(space >= 0);
@ -2800,7 +2801,7 @@ void titlebar(const char *path)
prefix = _("DIR:");
else
#endif
if (filename[0] == '\0') {
if (openfile->filename[0] == '\0') {
prefix = _("New Buffer");
newfie = TRUE;
} else
@ -2815,7 +2816,7 @@ void titlebar(const char *path)
prefixlen++;
if (path == NULL)
path = filename;
path = openfile->filename;
if (space >= prefixlen + statelen)
space -= prefixlen + statelen;
else
@ -2881,11 +2882,12 @@ void titlebar(const char *path)
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)
{
if (!ISSET(MODIFIED)) {
SET(MODIFIED);
if (!openfile->modified) {
openfile->modified = TRUE;
titlebar(NULL);
}
}
@ -3061,15 +3063,16 @@ void reset_cursor(void)
{
/* If we haven't opened any files yet, put the cursor in the top
* 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);
return;
}
current_y = current->lineno - edittop->lineno;
if (current_y < editwinrows) {
openfile->current_y = openfile->current->lineno -
openfile->edittop->lineno;
if (openfile->current_y < editwinrows) {
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 */
#ifndef NANO_SMALL
if (ISSET(MARK_ISSET)
&& (fileptr->lineno <= mark_beginbuf->lineno
|| fileptr->lineno <= current->lineno)
&& (fileptr->lineno >= mark_beginbuf->lineno
|| fileptr->lineno >= current->lineno)) {
if (openfile->mark_set && (fileptr->lineno <=
openfile->mark_beginbuf->lineno || fileptr->lineno <=
openfile->current->lineno) && (fileptr->lineno >=
openfile->mark_beginbuf->lineno || fileptr->lineno >=
openfile->current->lineno)) {
/* fileptr is at least partially selected. */
const filestruct *top;
/* Either current or mark_beginbuf, whichever is first. */
size_t top_x;
@ -3424,7 +3426,7 @@ void update_line(const filestruct *fileptr, size_t index)
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? */
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
* 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);
/* Expand the line, replacing tabs with spaces, and control
@ -3461,9 +3464,10 @@ int need_horizontal_update(size_t old_pww)
{
return
#ifndef NANO_SMALL
ISSET(MARK_ISSET) ||
openfile->mark_set ||
#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.
@ -3473,9 +3477,10 @@ int need_vertical_update(size_t old_pww)
{
return
#ifndef NANO_SMALL
ISSET(MARK_ISSET) ||
openfile->mark_set ||
#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
@ -3503,14 +3508,14 @@ void edit_scroll(updown direction, int nlines)
* how many lines we moved in scroll_rows. */
for (i = nlines; i > 0; i--) {
if (direction == UP) {
if (edittop->prev == NULL)
if (openfile->edittop->prev == NULL)
break;
edittop = edittop->prev;
openfile->edittop = openfile->edittop->prev;
scroll_rows--;
} else {
if (edittop->next == NULL)
if (openfile->edittop->next == NULL)
break;
edittop = edittop->next;
openfile->edittop = openfile->edittop->next;
scroll_rows++;
}
}
@ -3521,7 +3526,7 @@ void edit_scroll(updown direction, int nlines)
wscrl(edit, scroll_rows);
scrollok(edit, FALSE);
foo = edittop;
foo = openfile->edittop;
if (direction != UP) {
int slines = editwinrows - nlines;
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
* and get out. */
if (old_current->lineno < edittop->lineno || old_current->lineno >=
edittop->lineno + editwinrows || current->lineno <
edittop->lineno || current->lineno >= edittop->lineno +
editwinrows) {
if (old_current->lineno < openfile->edittop->lineno ||
old_current->lineno >= openfile->edittop->lineno +
editwinrows || openfile->current->lineno <
openfile->edittop->lineno || openfile->current->lineno >=
openfile->edittop->lineno + editwinrows) {
edit_refresh();
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,
* update all the lines between old_current and current too. */
foo = old_current;
while (foo != current) {
while (foo != openfile->current) {
if (do_refresh)
update_line(foo, 0);
#ifndef NANO_SMALL
if (!ISSET(MARK_ISSET))
if (!openfile->mark_set)
#endif
break;
if (foo->lineno > current->lineno)
#ifndef NANO_SMALL
if (foo->lineno > openfile->current->lineno)
foo = foo->prev;
else
foo = foo->next;
#endif
}
if (do_refresh)
update_line(current, current_x);
update_line(openfile->current, openfile->current_x);
}
/* Refresh the screen without changing the position of lines. */
void edit_refresh(void)
{
if (current->lineno < edittop->lineno ||
current->lineno >= edittop->lineno + editwinrows)
if (openfile->current->lineno < openfile->edittop->lineno ||
openfile->current->lineno >= openfile->edittop->lineno +
editwinrows)
/* Note that edit_update() changes edittop so that it's in range
* of current. Thus, when it then calls edit_refresh(), there
* is no danger of getting an infinite loop. */
@ -3595,14 +3604,15 @@ void edit_refresh(void)
CENTER);
else {
int nlines = 0;
const filestruct *foo = edittop;
const filestruct *foo = openfile->edittop;
#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
while (nlines < editwinrows) {
update_line(foo, foo == current ? current_x : 0);
update_line(foo, foo == openfile->current ?
openfile->current_x : 0);
nlines++;
if (foo->next == NULL)
break;
@ -3621,7 +3631,7 @@ void edit_refresh(void)
* the same place and move edittop to put it in range of current. */
void edit_update(topmidnone location)
{
filestruct *foo = current;
filestruct *foo = openfile->current;
if (location != TOP) {
/* If location is CENTER, we move edittop up (editwinrows / 2)
@ -3637,7 +3647,7 @@ void edit_update(topmidnone location)
if (location == CENTER)
goal = editwinrows / 2;
else {
goal = current_y;
goal = openfile->current_y;
/* Limit goal to (editwinrows - 1) lines maximum. */
if (goal > editwinrows - 1)
@ -3648,7 +3658,7 @@ void edit_update(topmidnone location)
foo = foo->prev;
}
edittop = foo;
openfile->edittop = foo;
edit_refresh();
}
@ -3800,22 +3810,22 @@ void do_cursorpos(bool constant)
char c;
filestruct *f;
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;
assert(current != NULL && fileage != NULL && totlines != 0);
assert(openfile->current != NULL && openfile->fileage != NULL && openfile->totlines != 0);
c = current->data[current_x];
f = current->next;
current->data[current_x] = '\0';
current->next = NULL;
get_totals(fileage, current, NULL, &i);
current->data[current_x] = c;
current->next = f;
c = openfile->current->data[openfile->current_x];
f = openfile->current->next;
openfile->current->data[openfile->current_x] = '\0';
openfile->current->next = NULL;
get_totals(openfile->fileage, openfile->current, NULL, &i);
openfile->current->data[openfile->current_x] = c;
openfile->current->next = f;
/* Check whether totsize is correct. If it isn't, there is a bug
* somewhere. */
assert(current != filebot || i == totsize);
assert(openfile->current != openfile->filebot || i == openfile->totsize);
if (constant && disable_cursorpos) {
disable_cursorpos = FALSE;
@ -3824,15 +3834,17 @@ void do_cursorpos(bool constant)
/* Display the current cursor position on the statusbar, and set
* disable_cursorpos to FALSE. */
linepct = 100 * current->lineno / totlines;
linepct = 100 * openfile->current->lineno / openfile->totlines;
colpct = 100 * cur_xpt / cur_lenpt;
charpct = (totsize == 0) ? 0 : 100 * i / totsize;
charpct = (openfile->totsize == 0) ? 0 : 100 * i /
openfile->totsize;
statusbar(
_("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)i, (unsigned long)totsize, charpct);
(unsigned long)i, (unsigned long)openfile->totsize, charpct);
disable_cursorpos = FALSE;
}
@ -4045,7 +4057,8 @@ int check_linenumbers(const filestruct *fileptr)
int check_line = 0;
const filestruct *filetmp;
for (filetmp = edittop; filetmp != fileptr; filetmp = filetmp->next)
for (filetmp = openfile->edittop; filetmp != fileptr;
filetmp = filetmp->next)
check_line++;
return check_line;
@ -4054,9 +4067,9 @@ int check_linenumbers(const filestruct *fileptr)
#ifdef DEBUG
/* 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");
else if (inptr == cutbuffer)
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. */
void dump_buffer_reverse(void)
void dump_filestruct_reverse(void)
{
const filestruct *fileptr = filebot;
const filestruct *fileptr = openfile->filebot;
while (fileptr != NULL) {
fprintf(stderr, "(%ld) %s\n", (long)fileptr->lineno,