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)
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)
* 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();
}
}
(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
* 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 */
/* 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();
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. */
set_modified();
#ifdef DEBUG
- dump_buffer(cutbuffer);
+ dump_filestruct(cutbuffer);
#endif
}
/* 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 */
/* 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();
/* 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
}
#include <assert.h>
#include "proto.h"
-static file_format fmt = NIX_FILE;
- /* The format of the current file. */
-
-#ifdef ENABLE_MULTIBUFFER
/* Create a new openfilestruct node. */
openfilestruct *make_new_opennode(void)
{
}
#endif
-/* Add/update an entry to the openfile openfilestruct. If update is
- * FALSE, a new entry is created; otherwise, the current entry is
- * updated. */
-void add_open_file(bool update)
+/* Add an entry to the openfile openfilestruct. This should only be
+ * called from open_buffer(). */
+void make_new_buffer(void)
{
- if (update && openfile == NULL)
- return;
-
- /* If there are no entries in openfile, make the first one. */
+ /* If there are no entries in openfile, make the first one and
+ * move to it. */
if (openfile == NULL) {
openfile = make_new_opennode();
splice_opennode(openfile, openfile, openfile);
- /* Otherwise, if we're not updating, make a new entry for
- * openfile and splice it in after the current entry. */
- } else if (!update) {
+ /* Otherwise, make a new entry for openfile, splice it in after
+ * the current entry, and move to it. */
+ } else {
splice_opennode(openfile, make_new_opennode(), openfile->next);
openfile = openfile->next;
}
- /* Save the current filename. */
- openfile->filename = mallocstrcpy(openfile->filename, filename);
-
-#ifndef NANO_SMALL
- /* Save the current file's stat. */
- openfile->originalfilestat = originalfilestat;
-#endif
-
- /* Save the current file buffer. */
- openfile->fileage = fileage;
- openfile->filebot = filebot;
+ openfile->filename = mallocstrcpy(NULL, "");
- /* Save the current top of the edit window. */
- openfile->edittop = edittop;
+ openfile->fileage = make_new_node(NULL);
+ openfile->fileage->data = mallocstrcpy(NULL, "");
- /* Save the current line. */
- openfile->current = current;
+ openfile->filebot = openfile->fileage;
+ openfile->edittop = openfile->fileage;
+ openfile->current = openfile->fileage;
- /* Save the current cursor position. */
- openfile->current_x = current_x;
+ openfile->current_x = 0;
+ openfile->current_y = 0;
+ openfile->placewewant = 0;
- /* Save the current place we want. */
- openfile->placewewant = placewewant;
-
- /* Save the current total number of lines. */
- openfile->totlines = totlines;
-
- /* Save the current total size. */
- openfile->totsize = totsize;
-
- /* Start with no flags saved. */
- openfile->flags = 0;
+#ifndef NANO_SMALL
+ openfile->mark_beginbuf = NULL;
+ openfile->mark_beginx = 0;
+#endif
- /* Save the current modification status. */
- if (ISSET(MODIFIED))
- openfile->flags |= MODIFIED;
+ openfile->totlines = 1;
+ openfile->totsize = 0;
+ openfile->modified = FALSE;
#ifndef NANO_SMALL
- /* Save the current marking status and mark, if applicable. */
- if (ISSET(MARK_ISSET)) {
- openfile->flags |= MARK_ISSET;
- openfile->mark_beginbuf = mark_beginbuf;
- openfile->mark_beginx = mark_beginx;
- }
+ openfile->mark_set = FALSE;
- /* Save the current file format. */
- openfile->fmt = fmt;
-#endif
+ openfile->fmt = NIX_FILE;
-#ifdef DEBUG
- fprintf(stderr, "filename is %s\n", openfile->filename);
+ memset(&openfile->originalfilestat, 0, sizeof(struct stat));
#endif
}
-/* Read the current entry in the openfile structure and set up the
- * currently open file buffer using that entry's information. */
-void load_open_file(void)
+/* filename is a file to open. We make a new buffer, if necessary, and
+ * then open and read the file. */
+void open_buffer(const char *filename)
{
- assert(openfile != NULL);
-
- /* Restore the current filename. */
- filename = mallocstrcpy(filename, openfile->filename);
-
-#ifndef NANO_SMALL
- /* Restore the current file's stat. */
- originalfilestat = openfile->originalfilestat;
+ bool new_buffer = (openfile == NULL
+#ifdef ENABLE_MULTIBUFFER
+ || ISSET(MULTIBUFFER)
#endif
+ );
+ /* Whether we load into this buffer or a new one. */
+ FILE *f;
+ int rc;
+ /* rc == -2 means that we have a new file. -1 means that the
+ * open() failed. 0 means that the open() succeeded. */
- /* Restore the current file buffer. */
- fileage = openfile->fileage;
- filebot = openfile->filebot;
-
- /* Restore the current top of the edit window. */
- edittop = openfile->edittop;
-
- /* Restore the current line. */
- current = openfile->current;
-
- /* Restore the current cursor position. */
- current_x = openfile->current_x;
-
- /* Restore the current place we want. */
- placewewant = openfile->placewewant;
+#ifndef DISABLE_OPERATINGDIR
+ if (check_operating_dir(filename, FALSE)) {
+ statusbar(_("Can't insert file from outside of %s"),
+ operating_dir);
+ return;
+ }
+#endif
- /* Restore the current total number of lines. */
- totlines = openfile->totlines;
+ /* If we're loading into a new buffer, add a new openfile entry. */
+ if (new_buffer)
+ make_new_buffer();
- /* Restore the current total size. */
- totsize = openfile->totsize;
+ /* Open the file. */
+ rc = open_file(filename, new_buffer, &f);
- /* Restore the current modification status. */
- if (openfile->flags & MODIFIED)
- SET(MODIFIED);
- else
- UNSET(MODIFIED);
+ /* If we have a file and we're loading into a new buffer, update the
+ * filename. */
+ if (rc != -1 && new_buffer)
+ openfile->filename = mallocstrcpy(openfile->filename, filename);
+ /* If we have a non-new file, read it in and update its stat, if
+ * applicable. */
+ if (rc == 0) {
+ read_file(f, filename);
#ifndef NANO_SMALL
- /* Restore the current marking status and mark, if applicable. */
- if (openfile->flags & MARK_ISSET) {
- mark_beginbuf = openfile->mark_beginbuf;
- mark_beginx = openfile->mark_beginx;
- SET(MARK_ISSET);
- } else
- UNSET(MARK_ISSET);
-
- /* Restore the current file format. */
- fmt = openfile->fmt;
+ stat(filename, &openfile->originalfilestat);
#endif
+ }
+
+ /* If we have a file, move back to the first line of it if we're
+ * loading into a new buffer. Then update the titlebar, the colors
+ * (if applicable), and the edit window. */
+ if (rc != -1) {
+ if (new_buffer)
+ openfile->current = openfile->fileage;
+ titlebar(NULL);
#ifdef ENABLE_COLOR
- update_color();
+ update_color();
#endif
- edit_refresh();
-
- /* Update the titlebar. */
- titlebar(NULL);
+ edit_refresh();
+ }
}
-/* Open either the next or previous file buffer. */
-void open_prevnext_file(bool next_file)
+#ifdef ENABLE_MULTIBUFFER
+/* Switch to the next file buffer if next_buf is TRUE. Otherwise,
+ * switch to the previous file buffer. */
+void switch_to_prevnext_buffer(bool next_buf)
{
assert(openfile != NULL);
- add_open_file(TRUE);
-
/* If only one file buffer is open, indicate it on the statusbar and
* get out. */
if (openfile == openfile->next) {
}
/* Switch to the next or previous file, depending on the value of
- * next. */
- openfile = next_file ? openfile->next : openfile->prev;
+ * next_buf. */
+ openfile = next_buf ? openfile->next : openfile->prev;
#ifdef DEBUG
fprintf(stderr, "filename is %s\n", openfile->filename);
#endif
- /* Load the file we switched to. */
- load_open_file();
-
- /* And indicate the switch on the statusbar. */
+ /* Indicate the switch on the statusbar. */
statusbar(_("Switched to %s"),
((openfile->filename[0] == '\0') ? _("New Buffer") :
openfile->filename));
#ifdef DEBUG
- dump_buffer(current);
+ dump_filestruct(openfile->current);
#endif
}
-/* Open the previous entry in the openfile structure. This function
- * is used by the shortcut list. */
-void open_prevfile_void(void)
+/* Switch to the previous entry in the openfile structure. This
+ * function is used by the shortcut list. */
+void switch_to_prev_buffer_void(void)
{
- open_prevnext_file(FALSE);
+ switch_to_prevnext_buffer(FALSE);
}
-/* Open the next entry in the openfile structure. This function is
- * used by the shortcut list. */
-void open_nextfile_void(void)
+/* Switch to the next entry in the openfile structure. This function
+ * is used by the shortcut list. */
+void switch_to_next_buffer_void(void)
{
- open_prevnext_file(TRUE);
+ switch_to_prevnext_buffer(TRUE);
}
-/* Delete an entry from the openfile filestruct. After deletion of an
- * entry, the next entry is opened. Return TRUE on success or FALSE if
- * there are no more open file buffers. */
-bool close_open_file(void)
+/* Delete an entry from the openfile filestruct, and open the one
+ * after it. Return TRUE on success, or FALSE if there are no more open
+ * file buffers. */
+bool close_buffer(void)
{
assert(openfile != NULL);
if (openfile == openfile->next)
return FALSE;
- /* Open the next file. */
- open_nextfile_void();
+ /* Switch to the next file. */
+ switch_to_next_buffer_void();
/* Close the file we had open before. */
unlink_opennode(openfile->prev);
- /* Reinitialize the shortcut list. */
- shortcut_init(FALSE);
display_main_list();
return TRUE;
}
#endif /* ENABLE_MULTIBUFFER */
-/* What happens when there is no file to open? aiee! */
-void new_file(void)
-{
- fileage = make_new_node(NULL);
- fileage->data = mallocstrcpy(NULL, "");
- filebot = fileage;
- edittop = fileage;
- current = fileage;
- current_x = 0;
- totlines = 1;
- totsize = 0;
-
-#ifdef ENABLE_COLOR
- update_color();
- if (!ISSET(NO_COLOR_SYNTAX))
- edit_refresh();
-#endif
-}
-
/* We make a new line of text from buf. buf is length buf_len. If
* first_line_ins is TRUE, then we put the new line at the top of the
* file. Otherwise, we assume prevnode is the last line of the file,
fileptr->data[buf_len - 1] = '\0';
#endif
- if (*first_line_ins == TRUE || fileage == NULL) {
+ if (*first_line_ins == TRUE || openfile->fileage == NULL) {
/* Special case: We're inserting with the cursor on the first
* line. */
fileptr->prev = NULL;
- fileptr->next = fileage;
+ fileptr->next = openfile->fileage;
fileptr->lineno = 1;
if (*first_line_ins == TRUE) {
*first_line_ins = FALSE;
/* If we're inserting into the first line of the file, then
* we want to make sure that our edit buffer stays on the
* first line and that fileage stays up to date. */
- edittop = fileptr;
+ openfile->edittop = fileptr;
} else
- filebot = fileptr;
- fileage = fileptr;
+ openfile->filebot = fileptr;
+ openfile->fileage = fileptr;
} else {
assert(prevnode != NULL);
return fileptr;
}
-/* Load a file into the edit buffer. This takes data from the file
- * struct. */
-void load_file(void)
-{
- current = fileage;
-
-#ifdef ENABLE_MULTIBUFFER
- /* Add a new entry to the openfile structure. */
- add_open_file(FALSE);
-
- /* Reinitialize the shortcut list. */
- shortcut_init(FALSE);
-#endif
-}
-
void read_file(FILE *f, const char *filename)
{
size_t num_lines = 0;
/* The current input character. */
char *buf;
/* The buffer where we store chunks of the file. */
- filestruct *fileptr = current;
+ filestruct *fileptr = openfile->current;
/* The current line of the file. */
bool first_line_ins = FALSE;
/* Whether we're inserting with the cursor on the first line. */
buf = charalloc(bufx);
buf[0] = '\0';
- if (current != NULL) {
- if (current == fileage)
+ if (openfile->current != NULL) {
+ if (openfile->current == openfile->fileage)
first_line_ins = TRUE;
else
- fileptr = current->prev;
+ fileptr = openfile->current->prev;
}
/* For the assertion in read_line(), it must be true that if current
* is NULL, then so is fileage. */
- assert(current != NULL || fileage == NULL);
+ assert(openfile->current != NULL || openfile->fileage == NULL);
#ifndef NANO_SMALL
/* We don't know which file format we have yet, so assume it's a
* *nix file for now. */
- fmt = NIX_FILE;
+ openfile->fmt = NIX_FILE;
#endif
/* Read the entire file into the file struct. */
free(buf);
- /* If we didn't get a file and we don't already have one, make a new
- * file. */
+ /* If we didn't get a file and we don't already have one, load a
+ * blank buffer. */
if (fileptr == NULL)
- new_file();
+ open_buffer("");
/* Did we try to insert a file of 0 bytes? */
if (num_lines != 0) {
- if (current != NULL) {
- fileptr->next = current;
- current->prev = fileptr;
- renumber(current);
- current_x = 0;
- placewewant = 0;
+ if (openfile->current != NULL) {
+ fileptr->next = openfile->current;
+ openfile->current->prev = fileptr;
+ renumber(openfile->current);
+ openfile->current_x = 0;
+ openfile->placewewant = 0;
} else if (fileptr->next == NULL) {
- filebot = fileptr;
+ openfile->filebot = fileptr;
new_magicline();
- totsize--;
+ openfile->totsize--;
}
}
- get_totals(fileage, filebot, NULL, &num_chars);
- totsize += num_chars;
+ get_totals(openfile->fileage, openfile->filebot, NULL, &num_chars);
+ openfile->totsize += num_chars;
#ifndef NANO_SMALL
if (format == 3)
"Read %lu lines (Converted from DOS and Mac format)",
(unsigned long)num_lines), (unsigned long)num_lines);
else if (format == 2) {
- fmt = MAC_FILE;
+ openfile->fmt = MAC_FILE;
statusbar(P_("Read %lu line (Converted from Mac format)",
"Read %lu lines (Converted from Mac format)",
(unsigned long)num_lines), (unsigned long)num_lines);
} else if (format == 1) {
- fmt = DOS_FILE;
+ openfile->fmt = DOS_FILE;
statusbar(P_("Read %lu line (Converted from DOS format)",
"Read %lu lines (Converted from DOS format)",
(unsigned long)num_lines), (unsigned long)num_lines);
statusbar(P_("Read %lu line", "Read %lu lines",
(unsigned long)num_lines), (unsigned long)num_lines);
- totlines += num_lines;
+ openfile->totlines += num_lines;
}
/* Open the file (and decide if it exists). If newfie is TRUE, display
} else if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) ||
S_ISBLK(fileinfo.st_mode)) {
/* Don't open character or block files. Sorry, /dev/sndstat! */
- statusbar(S_ISDIR(fileinfo.st_mode) ? _("\"%s\" is a directory")
- : _("File \"%s\" is a device file"), filename);
+ statusbar(S_ISDIR(fileinfo.st_mode) ?
+ _("\"%s\" is a directory") :
+ _("File \"%s\" is a device file"), filename);
return -1;
} else if ((fd = open(filename, O_RDONLY)) == -1) {
statusbar(_("Error reading %s: %s"), filename, strerror(errno));
void execute_command(const char *command)
{
#ifdef ENABLE_MULTIBUFFER
- if (ISSET(MULTIBUFFER)) {
- /* Update the current entry in the openfile structure. */
- add_open_file(TRUE);
- new_file();
- UNSET(MODIFIED);
- UNSET(MARK_ISSET);
- }
-#endif /* ENABLE_MULTIBUFFER */
- open_pipe(command);
-#ifdef ENABLE_MULTIBUFFER
- /* Add this new entry to the openfile structure. */
if (ISSET(MULTIBUFFER))
- load_file();
-#endif /* ENABLE_MULTIBUFFER */
-}
-#endif /* !NANO_SMALL */
-
-/* name is a file name to open. We make a new buffer if necessary, then
- * open and read the file. */
-void load_buffer(const char *name)
-{
- bool new_buffer = (fileage == NULL
-#ifdef ENABLE_MULTIBUFFER
- || ISSET(MULTIBUFFER)
-#endif
- );
- /* new_buffer says whether we load into this buffer or a new
- * one. If new_buffer is TRUE, we display "New File" if the
- * file is not found, and if it is found we set filename and add
- * a new openfile entry. */
- FILE *f;
- int rc;
- /* rc == -2 means that the statusbar displayed "New File". -1
- * means that the open failed. 0 means success. */
-
-#ifndef DISABLE_OPERATINGDIR
- if (check_operating_dir(name, FALSE)) {
- statusbar(_("Can't insert file from outside of %s"),
- operating_dir);
- return;
- }
-#endif
-
-#ifdef ENABLE_MULTIBUFFER
- /* Update the current entry in the openfile structure. */
- add_open_file(TRUE);
+ /* Add a new entry to the openfile structure. */
+ open_buffer("");
#endif
- rc = open_file(name, new_buffer, &f);
-
-#ifdef ENABLE_MULTIBUFFER
- if (rc != -1 && ISSET(MULTIBUFFER)) {
- UNSET(MODIFIED);
-#ifndef NANO_SMALL
- UNSET(MARK_ISSET);
-#endif
- }
-#endif
-
- if (rc != -1 && new_buffer) {
- filename = mallocstrcpy(filename, name);
- new_file();
- }
-
- if (rc == 0) {
- file_format fmt_save = fmt;
-
- read_file(f, filename);
-
- /* If we're not loading into a new buffer, preserve the file
- * format. */
- if (!new_buffer)
- fmt = fmt_save;
-
-#ifndef NANO_SMALL
- stat(filename, &originalfilestat);
-#endif
- }
-
- /* Add this new entry to the openfile structure if we have
- * multibuffer support, or to the main filestruct if we don't. */
- if (rc != -1 && new_buffer)
- load_file();
+ open_pipe(command);
}
+#endif /* !NANO_SMALL */
void do_insertfile(
#ifndef NANO_SMALL
const char *msg;
char *ans = mallocstrcpy(NULL, "");
/* The last answer the user typed on the statusbar. */
- filestruct *edittop_save = edittop;
- ssize_t current_y_save = current_y;
+ filestruct *edittop_save = openfile->edittop;
+ ssize_t current_y_save = openfile->current_y;
bool at_edittop = FALSE;
/* Whether we're at the top of the edit window. */
while (TRUE) {
#ifndef NANO_SMALL
if (execute) {
+ msg =
#ifdef ENABLE_MULTIBUFFER
- if (ISSET(MULTIBUFFER))
- msg = N_("Command to execute in new buffer [from %s] ");
- else
+ ISSET(MULTIBUFFER) ?
+ N_("Command to execute in new buffer [from %s] ") :
#endif
- msg = N_("Command to execute [from %s] ");
+ N_("Command to execute [from %s] ");
} else {
#endif
+ msg =
#ifdef ENABLE_MULTIBUFFER
- if (ISSET(MULTIBUFFER)) {
- msg = N_("File to insert into new buffer [from %s] ");
- } else
+ ISSET(MULTIBUFFER) ?
+ N_("File to insert into new buffer [from %s] ") :
#endif
- msg = N_("File to insert [from %s] ");
+ N_("File to insert [from %s] ");
#ifndef NANO_SMALL
}
#endif
statusbar(_("Cancelled"));
break;
} else {
- size_t pww_save = placewewant;
+ size_t pww_save = openfile->placewewant;
ans = mallocstrcpy(ans, answer);
* looks like a new buffer, and keep track of whether
* the top of the partition is the top of the edit
* window. */
- filepart = partition_filestruct(current, current_x,
- current, current_x);
- at_edittop = (fileage == edittop);
+ filepart = partition_filestruct(openfile->current,
+ openfile->current_x, openfile->current,
+ openfile->current_x);
+ at_edittop =
+ (openfile->fileage == openfile->edittop);
#ifdef ENABLE_MULTIBUFFER
}
#endif
#endif
answer = mallocstrassn(answer,
real_dir_from_tilde(answer));
- load_buffer(answer);
+ open_buffer(answer);
#ifndef NANO_SMALL
}
#endif
if (!ISSET(MULTIBUFFER))
#endif
{
- filestruct *top_save = fileage;
+ filestruct *top_save = openfile->fileage;
/* If we didn't insert into a new buffer, and we were at
* the top of the edit window before, set the saved
* and update the current y-coordinate to account for
* the number of lines inserted. */
if (at_edittop)
- edittop_save = fileage;
- current_y += current_y_save;
+ edittop_save = openfile->fileage;
+ openfile->current_y += current_y_save;
/* If we didn't insert into a new buffer, unpartition
* the filestruct so that it contains all the text
renumber(top_save);
/* Set edittop back to what it was before. */
- edittop = edittop_save;
+ openfile->edittop = edittop_save;
}
#ifdef ENABLE_MULTIBUFFER
- if (ISSET(MULTIBUFFER)) {
+ if (ISSET(MULTIBUFFER))
/* Update the titlebar. */
titlebar(NULL);
-
- /* Reinitialize the shortcut list. */
- shortcut_init(FALSE);
- } else {
+ else {
#endif
/* Mark the file as modified. */
set_modified();
/* Restore the old place we want. */
- placewewant = pww_save;
+ openfile->placewewant = pww_save;
#ifdef ENABLE_MULTIBUFFER
}
#endif
whereami2 = strstr(full_operating_dir, fullpath);
/* If both searches failed, we're outside the operating directory.
- * Otherwise, check the search results; if the full operating
+ * Otherwise, check the search results. If the full operating
* directory path is not at the beginning of the full current path
* (for normal usage) and vice versa (for tab completion, if we're
* allowing it), we're outside the operating directory. */
#endif
/* Read from inn, write to out. We assume inn is opened for reading,
- * and out for writing. We return 0 on success, -1 on read error, -2 on
- * write error. */
+ * and out for writing. We return 0 on success, -1 on read error, or -2
+ * on write error. */
int copy_file(FILE *inn, FILE *out)
{
char buf[BUFSIZ];
/* Write a file out. If f_open isn't NULL, we assume that it is a
* stream associated with the file, and we don't try to open it
* ourselves. If tmp is TRUE, we set the umask to disallow anyone else
- * from accessing the file, we don't set the global variable filename to
- * its name, and we don't print out how many lines we wrote on the
- * statusbar.
+ * from accessing the file, we don't set the filename to its name, and
+ * we don't print out how many lines we wrote on the statusbar.
*
* tmp means we are writing a temporary file in a secure fashion. We
* use it when spell checking or dumping the file on an error.
/* Instead of returning in this function, you should always
* merely set retval and then goto cleanup_and_exit. */
size_t lineswritten = 0;
- const filestruct *fileptr = fileage;
+ const filestruct *fileptr = openfile->fileage;
int fd;
/* The file descriptor we use. */
mode_t original_umask = 0;
struct stat st;
/* The status fields filled in by stat(). */
bool anyexists;
- /* The result of lstat(). Same as realexists unless name is a
- * link. */
+ /* The result of lstat(). The same as realexists, unless name
+ * is a link. */
struct stat lst;
/* The status fields filled in by lstat(). */
char *realname;
* aren't appending, prepending, or writing a selection, we backup
* only if the file has not been modified by someone else since nano
* opened it. */
- if (ISSET(BACKUP_FILE) && !tmp && realexists &&
- (append != 0 || ISSET(MARK_ISSET) ||
- originalfilestat.st_mtime == st.st_mtime)) {
+ if (ISSET(BACKUP_FILE) && !tmp && realexists && ((append != 0 ||
+ openfile->mark_set) || openfile->originalfilestat.st_mtime ==
+ st.st_mtime)) {
FILE *backup_file;
char *backupname;
struct utimbuf filetime;
int copy_status;
/* Save the original file's access and modification times. */
- filetime.actime = originalfilestat.st_atime;
- filetime.modtime = originalfilestat.st_mtime;
+ filetime.actime = openfile->originalfilestat.st_atime;
+ filetime.modtime = openfile->originalfilestat.st_mtime;
if (f_open == NULL) {
/* Open the original file to copy to the backup. */
* we write. */
backup_file = fopen(backupname, "wb");
- if (backup_file == NULL ||
- chmod(backupname, originalfilestat.st_mode) == -1) {
+ if (backup_file == NULL || chmod(backupname,
+ openfile->originalfilestat.st_mode) == -1) {
statusbar(_("Error writing %s: %s"), backupname,
strerror(errno));
free(backupname);
copy_status = copy_file(f, backup_file);
/* And set metadata. */
- if (copy_status != 0 ||
- chown(backupname, originalfilestat.st_uid,
- originalfilestat.st_gid) == -1 ||
+ if (copy_status != 0 || chown(backupname,
+ openfile->originalfilestat.st_uid,
+ openfile->originalfilestat.st_gid) == -1 ||
utime(backupname, &filetime) == -1) {
free(backupname);
if (copy_status == -1)
/* There might not be a magicline. There won't be when writing out
* a selection. */
- assert(fileage != NULL && filebot != NULL);
+ assert(openfile->fileage != NULL && openfile->filebot != NULL);
- while (fileptr != filebot) {
+ while (fileptr != openfile->filebot) {
size_t data_len = strlen(fileptr->data), size;
/* Newlines to nulls, just before we write to disk. */
}
#ifndef NANO_SMALL
- if (fmt == DOS_FILE || fmt == MAC_FILE) {
+ if (openfile->fmt == DOS_FILE || openfile->fmt == MAC_FILE) {
if (putc('\r', f) == EOF) {
statusbar(_("Error writing %s: %s"), realname,
strerror(errno));
}
}
- if (fmt != MAC_FILE) {
+ if (openfile->fmt != MAC_FILE) {
#endif
if (putc('\n', f) == EOF) {
statusbar(_("Error writing %s: %s"), realname,
if (!tmp && append == 0) {
if (!nonamechange) {
- filename = mallocstrcpy(filename, realname);
+ openfile->filename = mallocstrcpy(openfile->filename,
+ realname);
#ifdef ENABLE_COLOR
update_color();
if (!ISSET(NO_COLOR_SYNTAX))
#ifndef NANO_SMALL
/* Update originalfilestat to reference the file as it is now. */
- stat(filename, &originalfilestat);
+ stat(realname, &openfile->originalfilestat);
#endif
statusbar(P_("Wrote %lu line", "Wrote %lu lines",
(unsigned long)lineswritten),
(unsigned long)lineswritten);
- UNSET(MODIFIED);
+ openfile->modified = FALSE;
titlebar(NULL);
}
int write_marked(const char *name, FILE *f_open, bool tmp, int append)
{
int retval = -1;
- bool old_modified = ISSET(MODIFIED);
- /* write_file() unsets the MODIFIED flag. */
+ bool old_modified = openfile->modified;
+ /* write_file() unsets the modified flag. */
bool added_magicline;
/* Whether we added a magicline after filebot. */
filestruct *top, *bot;
/* If the line at filebot is blank, treat it as the magicline and
* hence the end of the file. Otherwise, add a magicline and treat
* it as the end of the file. */
- added_magicline = (filebot->data[0] != '\0');
+ added_magicline = (openfile->filebot->data[0] != '\0');
if (added_magicline)
new_magicline();
char *ans;
/* The last answer the user typed on the statusbar. */
#ifdef NANO_EXTRA
- static bool did_cred = FALSE;
+ static bool did_credits = FALSE;
#endif
currshortcut = writefile_list;
- if (exiting && filename[0] != '\0' && ISSET(TEMP_FILE)) {
- retval = write_file(filename, NULL, FALSE, 0, FALSE);
+ if (exiting && openfile->filename[0] != '\0' && ISSET(TEMP_FILE)) {
+ retval = write_file(openfile->filename, NULL, FALSE, 0,
+ FALSE);
/* Write succeeded. */
if (retval == 0)
return retval;
}
+ ans = mallocstrcpy(NULL,
#ifndef NANO_SMALL
- if (ISSET(MARK_ISSET) && !exiting)
- ans = mallocstrcpy(NULL, "");
- else
+ (openfile->mark_set && !exiting) ? "" :
#endif
- ans = mallocstrcpy(NULL, filename);
+ openfile->filename);
while (TRUE) {
const char *msg;
#ifndef NANO_SMALL
const char *formatstr, *backupstr;
- if (fmt == DOS_FILE)
- formatstr = N_(" [DOS Format]");
- else if (fmt == MAC_FILE)
- formatstr = N_(" [Mac Format]");
- else
- formatstr = "";
+ formatstr = (openfile->fmt == DOS_FILE) ?
+ N_(" [DOS Format]") : (openfile->fmt == MAC_FILE) ?
+ N_(" [Mac Format]") : "";
+
+ backupstr = ISSET(BACKUP_FILE) ? N_(" [Backup]") : "";
- if (ISSET(BACKUP_FILE))
- backupstr = N_(" [Backup]");
+ if (openfile->mark_set && !exiting)
+ msg = (append == 2) ? N_("Prepend Selection to File") :
+ (append == 1) ? N_("Append Selection to File") :
+ N_("Write Selection to File");
else
- backupstr = "";
-
- /* Be nice to the translation folks. */
- if (ISSET(MARK_ISSET) && !exiting) {
- if (append == 2)
- msg = N_("Prepend Selection to File");
- else if (append == 1)
- msg = N_("Append Selection to File");
- else
- msg = N_("Write Selection to File");
- } else
#endif /* !NANO_SMALL */
- if (append == 2)
- msg = N_("File Name to Prepend to");
- else if (append == 1)
- msg = N_("File Name to Append to");
- else
- msg = N_("File Name to Write");
+ msg = (append == 2) ? N_("File Name to Prepend to") :
+ (append == 1) ? N_("File Name to Append to") :
+ N_("File Name to Write");
/* If we're using restricted mode, the filename isn't blank,
* and we're at the "Write File" prompt, disable tab
* completion. */
- i = statusq(!ISSET(RESTRICTED) || filename[0] == '\0',
- writefile_list, ans,
+ i = statusq(!ISSET(RESTRICTED) ||
+ openfile->filename[0] == '\0', writefile_list, ans,
#ifndef NANO_SMALL
NULL, "%s%s%s", _(msg), formatstr, backupstr
#else
if (tmp == NULL)
continue;
+
free(answer);
answer = tmp;
#endif /* !DISABLE_BROWSER */
#ifndef NANO_SMALL
if (i == TOGGLE_DOS_KEY) {
- fmt = (fmt == DOS_FILE) ? NIX_FILE : DOS_FILE;
+ openfile->fmt = (openfile->fmt == DOS_FILE) ? NIX_FILE :
+ DOS_FILE;
continue;
} else if (i == TOGGLE_MAC_KEY) {
- fmt = (fmt == MAC_FILE) ? NIX_FILE : MAC_FILE;
+ openfile->fmt = (openfile->fmt == MAC_FILE) ? NIX_FILE :
+ MAC_FILE;
continue;
} else if (i == TOGGLE_BACKUP_KEY) {
TOGGLE(BACKUP_FILE);
#ifdef NANO_EXTRA
if (exiting && !ISSET(TEMP_FILE) &&
- strcasecmp(answer, "zzy") == 0 && !did_cred) {
+ strcasecmp(answer, "zzy") == 0 && !did_credits) {
do_credits();
- did_cred = TRUE;
+ did_credits = TRUE;
retval = -1;
break;
}
#endif
- if (append == 0 && strcmp(answer, filename) != 0) {
+ if (append == 0 && strcmp(answer,
+ openfile->filename) != 0) {
struct stat st;
if (!stat(answer, &st)) {
if (i == 0 || i == -1)
continue;
/* If we're using restricted mode, we aren't allowed to
- * change the name of a file once it has one because
+ * change the name of a file once it has one, because
* that would allow reading from or writing to files not
* specified on the command line. In this case, don't
* bother showing the "Different Name" prompt. */
- } else if (!ISSET(RESTRICTED) && filename[0] != '\0'
+ } else if (!ISSET(RESTRICTED) &&
+ openfile->filename[0] != '\0'
#ifndef NANO_SMALL
- && (exiting || !ISSET(MARK_ISSET))
+ && (exiting || !openfile->mark_set)
#endif
) {
i = do_yesno(FALSE,
* a separate file. If we're using restricted mode, this is
* disabled since it allows reading from or writing to files
* not specified on the command line. */
- if (!ISSET(RESTRICTED) && !exiting && ISSET(MARK_ISSET))
+ if (!ISSET(RESTRICTED) && !exiting && openfile->mark_set)
retval = write_marked(answer, NULL, FALSE, append);
else
#endif /* !NANO_SMALL */
retval = write_file(answer, NULL, FALSE, append, FALSE);
-#ifdef ENABLE_MULTIBUFFER
- /* If we're not about to exit, update the current entry in
- * the openfile structure. */
- if (!exiting)
- add_open_file(TRUE);
-#endif
-
break;
}
} /* while (TRUE) */
{
char *dirtmp = NULL;
- if (buf == NULL)
- return NULL;
+ assert(buf != NULL);
if (buf[0] == '~') {
size_t i;
char **cwd_tab_completion(const char *buf, size_t *num_matches, size_t
buflen)
{
- char *dirname = mallocstrcpy(NULL, buf);
- char *filename;
+ char *dirname = mallocstrcpy(NULL, buf), *filename;
#ifndef DISABLE_OPERATINGDIR
size_t dirnamelen;
#endif
filenamelen = strlen(filename);
while ((nextdir = readdir(dir)) != NULL) {
-
#ifdef DEBUG
fprintf(stderr, "Comparing \'%s\'\n", nextdir->d_name);
#endif
++(*num_matches);
}
}
+
closedir(dir);
free(dirname);
free(filename);
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 */
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
#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(). */
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 */
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");
/* 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);
#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"),
if (help_text != NULL)
free(help_text);
#endif
- if (filename != NULL)
- free(filename);
if (answer != NULL)
free(answer);
if (cutbuffer != NULL)
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);
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);
/* 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);
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);
/* 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);
#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 :
* 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)
#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 :
* 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)
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)
return head;
}
-/* Frees a filestruct. */
+/* Free a filestruct. */
void free_filestruct(filestruct *src)
{
assert(src != NULL);
delete_node(src);
}
+/* Renumber all entries in the main filestruct. */
void renumber_all(void)
{
filestruct *temp;
ssize_t line = 1;
- assert(fileage == NULL || fileage != fileage->next);
+ assert(openfile->fileage == NULL || openfile->fileage != openfile->fileage->next);
- for (temp = fileage; temp != NULL; temp = temp->next)
+ for (temp = openfile->fileage; temp != NULL; temp = temp->next)
temp->lineno = line++;
}
+/* Renumbers all entries in the main filestruct, starting with
+ * fileptr. */
void renumber(filestruct *fileptr)
{
- if (fileptr == NULL || fileptr->prev == NULL || fileptr == fileage)
+ if (fileptr == NULL || fileptr->prev == NULL || fileptr == openfile->fileage)
renumber_all();
else {
ssize_t line = fileptr->prev->lineno;
{
partition *p;
- assert(top != NULL && bot != NULL && fileage != NULL && filebot != NULL);
+ assert(top != NULL && bot != NULL && openfile->fileage != NULL && openfile->filebot != NULL);
/* Initialize the partition. */
p = (partition *)nmalloc(sizeof(partition));
/* If the top and bottom of the partition are different from the top
* and bottom of the filestruct, save the latter and then set them
* to top and bot. */
- if (top != fileage) {
- p->fileage = fileage;
- fileage = top;
+ if (top != openfile->fileage) {
+ p->fileage = openfile->fileage;
+ openfile->fileage = top;
} else
p->fileage = NULL;
- if (bot != filebot) {
- p->filebot = filebot;
- filebot = bot;
+ if (bot != openfile->filebot) {
+ p->filebot = openfile->filebot;
+ openfile->filebot = bot;
} else
p->filebot = NULL;
{
char *tmp;
- assert(p != NULL && fileage != NULL && filebot != NULL);
+ assert(p != NULL && openfile->fileage != NULL && openfile->filebot != NULL);
/* Reattach the line above the top of the partition, and restore the
* text before top_x from top_data. Free top_data when we're done
* with it. */
- tmp = mallocstrcpy(NULL, fileage->data);
- fileage->prev = (*p)->top_prev;
- if (fileage->prev != NULL)
- fileage->prev->next = fileage;
- fileage->data = charealloc(fileage->data, strlen((*p)->top_data) +
- strlen(fileage->data) + 1);
- strcpy(fileage->data, (*p)->top_data);
+ tmp = mallocstrcpy(NULL, openfile->fileage->data);
+ openfile->fileage->prev = (*p)->top_prev;
+ if (openfile->fileage->prev != NULL)
+ openfile->fileage->prev->next = openfile->fileage;
+ openfile->fileage->data = charealloc(openfile->fileage->data,
+ strlen((*p)->top_data) + strlen(openfile->fileage->data) + 1);
+ strcpy(openfile->fileage->data, (*p)->top_data);
free((*p)->top_data);
- strcat(fileage->data, tmp);
+ strcat(openfile->fileage->data, tmp);
free(tmp);
/* Reattach the line below the bottom of the partition, and restore
* the text after bot_x from bot_data. Free bot_data when we're
* done with it. */
- filebot->next = (*p)->bot_next;
- if (filebot->next != NULL)
- filebot->next->prev = filebot;
- filebot->data = charealloc(filebot->data, strlen(filebot->data) +
- strlen((*p)->bot_data) + 1);
- strcat(filebot->data, (*p)->bot_data);
+ openfile->filebot->next = (*p)->bot_next;
+ if (openfile->filebot->next != NULL)
+ openfile->filebot->next->prev = openfile->filebot;
+ openfile->filebot->data = charealloc(openfile->filebot->data,
+ strlen(openfile->filebot->data) + strlen((*p)->bot_data) + 1);
+ strcat(openfile->filebot->data, (*p)->bot_data);
free((*p)->bot_data);
/* Restore the top and bottom of the filestruct, if they were
* different from the top and bottom of the partition. */
if ((*p)->fileage != NULL)
- fileage = (*p)->fileage;
+ openfile->fileage = (*p)->fileage;
if ((*p)->filebot != NULL)
- filebot = (*p)->filebot;
+ openfile->filebot = (*p)->filebot;
/* Uninitialize the partition. */
free(*p);
* the partition is the top of the edit window, and keep track of
* whether the mark begins inside the partition. */
filepart = partition_filestruct(top, top_x, bot, bot_x);
- at_edittop = (fileage == edittop);
+ at_edittop = (openfile->fileage == openfile->edittop);
#ifndef NANO_SMALL
- if (ISSET(MARK_ISSET))
- mark_inside = (mark_beginbuf->lineno >= fileage->lineno &&
- mark_beginbuf->lineno <= filebot->lineno &&
- (mark_beginbuf != fileage || mark_beginx >= top_x) &&
- (mark_beginbuf != filebot || mark_beginx <= bot_x));
+ if (openfile->mark_set)
+ mark_inside = (openfile->mark_beginbuf->lineno >=
+ openfile->fileage->lineno &&
+ openfile->mark_beginbuf->lineno <=
+ openfile->filebot->lineno &&
+ (openfile->mark_beginbuf != openfile->fileage ||
+ openfile->mark_beginx >= top_x) &&
+ (openfile->mark_beginbuf != openfile->filebot ||
+ openfile->mark_beginx <= bot_x));
#endif
/* Get the number of characters in the text, and subtract it from
* totsize. */
get_totals(top, bot, NULL, &part_totsize);
- totsize -= part_totsize;
+ openfile->totsize -= part_totsize;
if (*file_top == NULL) {
/* If file_top is empty, just move all the text directly into
* it. This is equivalent to tacking the text in top onto the
* (lack of) text at the end of file_top. */
- *file_top = fileage;
- *file_bot = filebot;
+ *file_top = openfile->fileage;
+ *file_bot = openfile->filebot;
} else {
/* Otherwise, tack the text in top onto the text at the end of
* file_bot. */
(*file_bot)->data = charealloc((*file_bot)->data,
- strlen((*file_bot)->data) + strlen(fileage->data) + 1);
- strcat((*file_bot)->data, fileage->data);
+ strlen((*file_bot)->data) +
+ strlen(openfile->fileage->data) + 1);
+ strcat((*file_bot)->data, openfile->fileage->data);
/* Attach the line after top to the line after file_bot. Then,
* if there's more than one line after top, move file_bot down
* to bot. */
- (*file_bot)->next = fileage->next;
+ (*file_bot)->next = openfile->fileage->next;
if ((*file_bot)->next != NULL) {
(*file_bot)->next->prev = *file_bot;
- *file_bot = filebot;
+ *file_bot = openfile->filebot;
}
}
* edittop to where the text used to start. If the mark began
* inside the partition, set the beginning of the mark to where the
* text used to start. */
- fileage = (filestruct *)nmalloc(sizeof(filestruct));
- fileage->data = mallocstrcpy(NULL, "");
- filebot = fileage;
+ openfile->fileage = (filestruct *)nmalloc(sizeof(filestruct));
+ openfile->fileage->data = mallocstrcpy(NULL, "");
+ openfile->filebot = openfile->fileage;
if (at_edittop)
- edittop = fileage;
+ openfile->edittop = openfile->fileage;
#ifndef NANO_SMALL
if (mark_inside) {
- mark_beginbuf = fileage;
- mark_beginx = top_x;
+ openfile->mark_beginbuf = openfile->fileage;
+ openfile->mark_beginx = top_x;
}
#endif
/* Restore the current line and cursor position. */
- current = fileage;
- current_x = top_x;
+ openfile->current = openfile->fileage;
+ openfile->current_x = top_x;
- top_save = fileage;
+ top_save = openfile->fileage;
/* Unpartition the filestruct so that it contains all the text
* again, minus the saved text. */
* partition. */
renumber(top_save);
- if (filebot->data[0] != '\0')
+ if (openfile->filebot->data[0] != '\0')
new_magicline();
/* Set totlines to the new number of lines in the file. */
- totlines = filebot->lineno;
+ openfile->totlines = openfile->filebot->lineno;
}
/* Copy all the text from the filestruct beginning with file_top and
/* Partition the filestruct so that it contains no text, and keep
* track of whether the top of the partition is the top of the edit
* window. */
- filepart = partition_filestruct(current, current_x, current,
- current_x);
- at_edittop = (fileage == edittop);
+ filepart = partition_filestruct(openfile->current,
+ openfile->current_x, openfile->current, openfile->current_x);
+ at_edittop = (openfile->fileage == openfile->edittop);
/* Put the top and bottom of the filestruct at copies of file_top
* and file_bot. */
- fileage = copy_filestruct(file_top);
- filebot = fileage;
- while (filebot->next != NULL)
- filebot = filebot->next;
+ openfile->fileage = copy_filestruct(file_top);
+ openfile->filebot = openfile->fileage;
+ while (openfile->filebot->next != NULL)
+ openfile->filebot = openfile->filebot->next;
/* Restore the current line and cursor position. */
- current = filebot;
- current_x = strlen(filebot->data);
- if (fileage == filebot)
- current_x += strlen(filepart->top_data);
+ openfile->current = openfile->filebot;
+ openfile->current_x = strlen(openfile->filebot->data);
+ if (openfile->fileage == openfile->filebot)
+ openfile->current_x += strlen(filepart->top_data);
/* Get the number of lines and the number of characters in the saved
* text, and add the latter to totsize. */
- get_totals(fileage, filebot, &part_totlines, &part_totsize);
- totsize += part_totsize;
+ get_totals(openfile->fileage, openfile->filebot, &part_totlines,
+ &part_totsize);
+ openfile->totsize += part_totsize;
/* If the top of the partition was the top of the edit window, set
* edittop to where the saved text now starts, and update the
* has, less one since the first line will be tacked onto the
* current line. */
if (at_edittop)
- edittop = fileage;
- current_y += part_totlines - 1;
+ openfile->edittop = openfile->fileage;
+ openfile->current_y += part_totlines - 1;
- top_save = fileage;
+ top_save = openfile->fileage;
/* Unpartition the filestruct so that it contains all the text
* again, minus the saved text. */
* partition. */
renumber(top_save);
- if (filebot->data[0] != '\0')
+ if (openfile->filebot->data[0] != '\0')
new_magicline();
/* Set totlines to the new number of lines in the file. */
- totlines = filebot->lineno;
+ openfile->totlines = openfile->filebot->lineno;
}
void print_view_warning(void)
va_end(ap);
/* Save the current file buffer if it's been modified. */
- if (ISSET(MODIFIED)) {
+ if (openfile->modified) {
/* If we've partitioned the filestruct, unpartition it now. */
if (filepart != NULL)
unpartition_filestruct(&filepart);
- die_save_file(filename);
+ die_save_file(openfile->filename);
}
#ifdef ENABLE_MULTIBUFFER
openfile = openfile->next;
/* Save the current file buffer if it's been modified. */
- if (openfile->flags & MODIFIED) {
- /* Set fileage and filebot to match the current file
- * buffer, and then write it to disk. */
- fileage = openfile->fileage;
- filebot = openfile->filebot;
+ if (openfile->modified)
die_save_file(openfile->filename);
- }
}
}
#endif
hblank[COLS] = '\0';
}
-/* Initialize global variables -- no better way for now. If
- * save_cutbuffer is TRUE, don't set cutbuffer to NULL. */
-void global_init(bool save_cutbuffer)
+/* Initialize the resize variables. */
+void resize_init(void)
{
check_die_too_small();
resize_variables();
-
- fileage = NULL;
- edittop = NULL;
- current = NULL;
- if (!save_cutbuffer)
- cutbuffer = NULL;
- current_x = 0;
- placewewant = 0;
- current_y = 0;
- totlines = 0;
- totsize = 0;
}
void window_init(void)
void do_backspace(void)
{
- if (current != fileage || current_x > 0) {
+ if (openfile->current != openfile->fileage ||
+ openfile->current_x > 0) {
do_left(FALSE);
do_delete();
}
/* Do we have to call edit_refresh(), or can we get away with
* update_line()? */
- assert(current != NULL && current->data != NULL && current_x <= strlen(current->data));
+ assert(openfile->current != NULL && openfile->current->data != NULL && openfile->current_x <= strlen(openfile->current->data));
- placewewant = xplustabs();
+ openfile->placewewant = xplustabs();
- if (current->data[current_x] != '\0') {
- int char_buf_len = parse_mbchar(current->data + current_x, NULL,
- NULL, NULL);
- size_t line_len = strlen(current->data + current_x);
+ if (openfile->current->data[openfile->current_x] != '\0') {
+ int char_buf_len = parse_mbchar(openfile->current->data +
+ openfile->current_x, NULL, NULL, NULL);
+ size_t line_len = strlen(openfile->current->data +
+ openfile->current_x);
- assert(current_x < strlen(current->data));
+ assert(openfile->current_x < strlen(openfile->current->data));
/* Let's get dangerous. */
- charmove(¤t->data[current_x],
- ¤t->data[current_x + char_buf_len],
- line_len - char_buf_len + 1);
+ charmove(&openfile->current->data[openfile->current_x],
+ &openfile->current->data[openfile->current_x +
+ char_buf_len], line_len - char_buf_len + 1);
- null_at(¤t->data, current_x + line_len - char_buf_len);
+ null_at(&openfile->current->data, openfile->current_x +
+ line_len - char_buf_len);
#ifndef NANO_SMALL
- if (current_x < mark_beginx && mark_beginbuf == current)
- mark_beginx -= char_buf_len;
-#endif
- totsize--;
- } else if (current != filebot && (current->next != filebot ||
- current->data[0] == '\0')) {
+ if (openfile->mark_set && openfile->current_x <
+ openfile->mark_beginx && openfile->mark_beginbuf ==
+ openfile->current)
+ openfile->mark_beginx -= char_buf_len;
+#endif
+ openfile->totsize--;
+ } else if (openfile->current != openfile->filebot &&
+ (openfile->current->next != openfile->filebot ||
+ openfile->current->data[0] == '\0')) {
/* We can delete the line before filebot only if it is blank: it
* becomes the new magicline then. */
- filestruct *foo = current->next;
+ filestruct *foo = openfile->current->next;
- assert(current_x == strlen(current->data));
+ assert(openfile->current_x == strlen(openfile->current->data));
/* If we're deleting at the end of a line, we need to call
* edit_refresh(). */
- if (current->data[current_x] == '\0')
+ if (openfile->current->data[openfile->current_x] == '\0')
do_refresh = TRUE;
- current->data = charealloc(current->data,
- current_x + strlen(foo->data) + 1);
- strcpy(current->data + current_x, foo->data);
+ openfile->current->data = charealloc(openfile->current->data,
+ openfile->current_x + strlen(foo->data) + 1);
+ strcpy(openfile->current->data + openfile->current_x,
+ foo->data);
#ifndef NANO_SMALL
- if (mark_beginbuf == current->next) {
- mark_beginx += current_x;
- mark_beginbuf = current;
+ if (openfile->mark_set && openfile->mark_beginbuf ==
+ openfile->current->next) {
+ openfile->mark_beginx += openfile->current_x;
+ openfile->mark_beginbuf = openfile->current;
}
#endif
- if (filebot == foo)
- filebot = current;
+ if (openfile->filebot == foo)
+ openfile->filebot = openfile->current;
unlink_node(foo);
delete_node(foo);
- renumber(current);
- totlines--;
- totsize--;
+ renumber(openfile->current);
+ openfile->totlines--;
+ openfile->totsize--;
#ifndef DISABLE_WRAPPING
wrap_reset();
#endif
if (do_refresh)
edit_refresh();
else
- update_line(current, current_x);
+ update_line(openfile->current, openfile->current_x);
}
void do_tab(void)
#ifndef NANO_SMALL
if (ISSET(TABS_TO_SPACES)) {
char *output;
- size_t output_len = 0, new_pww = placewewant;
+ size_t output_len = 0, new_pww = openfile->placewewant;
do {
new_pww++;
/* Someone hits Return *gasp!* */
void do_enter(void)
{
- filestruct *newnode = make_new_node(current);
+ filestruct *newnode = make_new_node(openfile->current);
size_t extra = 0;
- assert(current != NULL && current->data != NULL);
+ assert(openfile->current != NULL && openfile->current->data != NULL);
#ifndef NANO_SMALL
/* Do auto-indenting, like the neolithic Turbo Pascal editor. */
/* If we are breaking the line in the indentation, the new
* indentation should have only current_x characters, and
* current_x should not change. */
- extra = indent_length(current->data);
- if (extra > current_x)
- extra = current_x;
+ extra = indent_length(openfile->current->data);
+ if (extra > openfile->current_x)
+ extra = openfile->current_x;
}
#endif
- newnode->data = charalloc(strlen(current->data + current_x) +
- extra + 1);
- strcpy(&newnode->data[extra], current->data + current_x);
+ newnode->data = charalloc(strlen(openfile->current->data +
+ openfile->current_x) + extra + 1);
+ strcpy(&newnode->data[extra], openfile->current->data +
+ openfile->current_x);
#ifndef NANO_SMALL
if (ISSET(AUTOINDENT)) {
- strncpy(newnode->data, current->data, extra);
- totsize += mbstrlen(newnode->data);
+ strncpy(newnode->data, openfile->current->data, extra);
+ openfile->totsize += mbstrlen(newnode->data);
}
#endif
- null_at(¤t->data, current_x);
+ null_at(&openfile->current->data, openfile->current_x);
#ifndef NANO_SMALL
- if (current == mark_beginbuf && current_x < mark_beginx) {
- mark_beginbuf = newnode;
- mark_beginx += extra - current_x;
+ if (openfile->mark_set && openfile->current ==
+ openfile->mark_beginbuf && openfile->current_x <
+ openfile->mark_beginx) {
+ openfile->mark_beginbuf = newnode;
+ openfile->mark_beginx += extra - openfile->current_x;
}
#endif
- current_x = extra;
+ openfile->current_x = extra;
- if (current == filebot)
- filebot = newnode;
- splice_node(current, newnode, current->next);
+ if (openfile->current == openfile->filebot)
+ openfile->filebot = newnode;
+ splice_node(openfile->current, newnode,
+ openfile->current->next);
- renumber(current);
- current = newnode;
+ renumber(openfile->current);
+ openfile->current = newnode;
edit_refresh();
- totlines++;
- totsize++;
+ openfile->totlines++;
+ openfile->totsize++;
set_modified();
- placewewant = xplustabs();
+ openfile->placewewant = xplustabs();
}
#ifndef NANO_SMALL
* and FALSE otherwise. */
bool do_next_word(bool allow_punct, bool allow_update)
{
- size_t pww_save = placewewant;
- const filestruct *current_save = current;
+ size_t pww_save = openfile->placewewant;
+ const filestruct *current_save = openfile->current;
char *char_mb;
int char_mb_len;
bool end_line = FALSE, started_on_word = FALSE;
- assert(current != NULL && current->data != NULL);
+ assert(openfile->current != NULL && openfile->current->data != NULL);
char_mb = charalloc(mb_cur_max());
/* Move forward until we find the character after the last letter of
* the current word. */
while (!end_line) {
- char_mb_len = parse_mbchar(current->data + current_x, char_mb,
- NULL, NULL);
+ char_mb_len = parse_mbchar(openfile->current->data +
+ openfile->current_x, char_mb, NULL, NULL);
/* If we've found it, stop moving forward through the current
* line. */
* started_on_word to TRUE. */
started_on_word = TRUE;
- if (current->data[current_x] == '\0')
+ if (openfile->current->data[openfile->current_x] == '\0')
end_line = TRUE;
else
- current_x += char_mb_len;
+ openfile->current_x += char_mb_len;
}
/* Move forward until we find the first letter of the next word. */
- if (current->data[current_x] == '\0')
+ if (openfile->current->data[openfile->current_x] == '\0')
end_line = TRUE;
else
- current_x += char_mb_len;
+ openfile->current_x += char_mb_len;
- for (; current != NULL; current = current->next) {
+ for (; openfile->current != NULL;
+ openfile->current = openfile->current->next) {
while (!end_line) {
- char_mb_len = parse_mbchar(current->data + current_x,
- char_mb, NULL, NULL);
+ char_mb_len = parse_mbchar(openfile->current->data +
+ openfile->current_x, char_mb, NULL, NULL);
/* If we've found it, stop moving forward through the
* current line. */
if (is_word_mbchar(char_mb, allow_punct))
break;
- if (current->data[current_x] == '\0')
+ if (openfile->current->data[openfile->current_x] == '\0')
end_line = TRUE;
else
- current_x += char_mb_len;
+ openfile->current_x += char_mb_len;
}
/* If we've found it, stop moving forward to the beginnings of
if (!end_line)
break;
- if (current->next != NULL) {
+ if (openfile->current->next != NULL) {
end_line = FALSE;
- current_x = 0;
+ openfile->current_x = 0;
}
}
/* If we haven't found it, leave the cursor at the end of the
* file. */
- if (current == NULL)
- current = filebot;
+ if (openfile->current == NULL)
+ openfile->current = openfile->filebot;
- placewewant = xplustabs();
+ openfile->placewewant = xplustabs();
/* If allow_update is TRUE, update the screen. */
if (allow_update)
* word, and FALSE otherwise. */
bool do_prev_word(bool allow_punct, bool allow_update)
{
- size_t pww_save = placewewant;
- const filestruct *current_save = current;
+ size_t pww_save = openfile->placewewant;
+ const filestruct *current_save = openfile->current;
char *char_mb;
int char_mb_len;
bool begin_line = FALSE, started_on_word = FALSE;
- assert(current != NULL && current->data != NULL);
+ assert(openfile->current != NULL && openfile->current->data != NULL);
char_mb = charalloc(mb_cur_max());
/* Move backward until we find the character before the first letter
* of the current word. */
while (!begin_line) {
- char_mb_len = parse_mbchar(current->data + current_x, char_mb,
- NULL, NULL);
+ char_mb_len = parse_mbchar(openfile->current->data +
+ openfile->current_x, char_mb, NULL, NULL);
/* If we've found it, stop moving backward through the current
* line. */
* started_on_word to TRUE. */
started_on_word = TRUE;
- if (current_x == 0)
+ if (openfile->current_x == 0)
begin_line = TRUE;
else
- current_x = move_mbleft(current->data, current_x);
+ openfile->current_x = move_mbleft(openfile->current->data,
+ openfile->current_x);
}
/* Move backward until we find the last letter of the previous
* word. */
- if (current_x == 0)
+ if (openfile->current_x == 0)
begin_line = TRUE;
else
- current_x = move_mbleft(current->data, current_x);
+ openfile->current_x = move_mbleft(openfile->current->data,
+ openfile->current_x);
- for (; current != NULL; current = current->prev) {
+ for (; openfile->current != NULL;
+ openfile->current = openfile->current->prev) {
while (!begin_line) {
- char_mb_len = parse_mbchar(current->data + current_x,
- char_mb, NULL, NULL);
+ char_mb_len = parse_mbchar(openfile->current->data +
+ openfile->current_x, char_mb, NULL, NULL);
/* If we've found it, stop moving backward through the
* current line. */
if (is_word_mbchar(char_mb, allow_punct))
break;
- if (current_x == 0)
+ if (openfile->current_x == 0)
begin_line = TRUE;
else
- current_x = move_mbleft(current->data, current_x);
+ openfile->current_x =
+ move_mbleft(openfile->current->data,
+ openfile->current_x);
}
/* If we've found it, stop moving backward to the ends of
if (!begin_line)
break;
- if (current->prev != NULL) {
+ if (openfile->current->prev != NULL) {
begin_line = FALSE;
- current_x = strlen(current->prev->data);
+ openfile->current_x = strlen(openfile->current->prev->data);
}
}
/* If we haven't found it, leave the cursor at the beginning of the
* file. */
- if (current == NULL)
- current = fileage;
+ if (openfile->current == NULL)
+ openfile->current = openfile->fileage;
/* If we've found it, move backward until we find the character
* before the first letter of the previous word. */
else if (!begin_line) {
- if (current_x == 0)
+ if (openfile->current_x == 0)
begin_line = TRUE;
else
- current_x = move_mbleft(current->data, current_x);
+ openfile->current_x = move_mbleft(openfile->current->data,
+ openfile->current_x);
while (!begin_line) {
- char_mb_len = parse_mbchar(current->data + current_x,
- char_mb, NULL, NULL);
+ char_mb_len =
+ parse_mbchar(openfile->current->data +
+ openfile->current_x, char_mb, NULL, NULL);
/* If we've found it, stop moving backward through the
* current line. */
if (!is_word_mbchar(char_mb, allow_punct))
break;
- if (current_x == 0)
+ if (openfile->current_x == 0)
begin_line = TRUE;
else
- current_x = move_mbleft(current->data, current_x);
+ openfile->current_x =
+ move_mbleft(openfile->current->data,
+ openfile->current_x);
}
/* If we've found it, move forward to the first letter of the
* previous word. */
if (!begin_line)
- current_x += char_mb_len;
+ openfile->current_x += char_mb_len;
}
free(char_mb);
- placewewant = xplustabs();
+ openfile->placewewant = xplustabs();
/* If allow_update is TRUE, update the screen. */
if (allow_update)
void do_word_count(void)
{
- size_t words = 0;
- size_t current_x_save = current_x, pww_save = placewewant;
- filestruct *current_save = current;
- bool old_mark_set = ISSET(MARK_ISSET);
+ size_t words = 0, current_x_save = openfile->current_x;
+ size_t pww_save = openfile->placewewant;
+ filestruct *current_save = openfile->current;
+ bool old_mark_set = openfile->mark_set;
bool added_magicline = FALSE;
/* Whether we added a magicline after filebot. */
filestruct *top, *bot;
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, NULL);
filepart = partition_filestruct(top, top_x, bot, bot_x);
- if ((added_magicline = (filebot->data[0] != '\0')))
+ if ((added_magicline = (openfile->filebot->data[0] != '\0')))
new_magicline();
- UNSET(MARK_ISSET);
+ openfile->mark_set = FALSE;
}
/* Start at the top of the file. */
- current = fileage;
- current_x = 0;
- placewewant = 0;
+ openfile->current = openfile->fileage;
+ openfile->current_x = 0;
+ openfile->placewewant = 0;
/* Keep moving to the next word (counting punctuation characters as
* part of a word so that we match the output of "wc -w"), without
* updating the screen, until we reach the end of the file,
* incrementing the total word count whenever we're on a word just
* before moving. */
- while (current != filebot || current_x != 0) {
+ while (openfile->current != openfile->filebot ||
+ openfile->current_x != 0) {
if (do_next_word(TRUE, FALSE))
words++;
}
/* Unpartition the filestruct so that it contains all the text
* again, and turn the mark back on. */
unpartition_filestruct(&filepart);
- SET(MARK_ISSET);
+ openfile->mark_set = TRUE;
}
/* Restore where we were. */
- current = current_save;
- current_x = current_x_save;
- placewewant = pww_save;
+ openfile->current = current_save;
+ openfile->current_x = current_x_save;
+ openfile->placewewant = pww_save;
/* Display the total word count on the statusbar. */
statusbar("%s: %lu", old_mark_set ? _("Word Count in Selection") :
void do_mark(void)
{
- TOGGLE(MARK_ISSET);
- if (ISSET(MARK_ISSET)) {
+ openfile->mark_set = openfile->mark_set ? FALSE : TRUE;
+ if (openfile->mark_set) {
statusbar(_("Mark Set"));
- mark_beginbuf = current;
- mark_beginx = current_x;
+ openfile->mark_beginbuf = openfile->current;
+ openfile->mark_beginx = openfile->current_x;
} else {
statusbar(_("Mark UNset"));
+ openfile->mark_beginbuf = NULL;
+ openfile->mark_beginx = 0;
edit_refresh();
}
}
line->data[line_len] = '\0';
after_break = line->data + wrap_loc;
after_break_len++;
- totsize++;
+ openfile->totsize++;
}
next_line = line->next->data;
/* Otherwise, it will come from this line, in which case
* we should increase new_line_len to make room for it. */
new_line_len += indent_len;
- totsize += mbstrnlen(indent_string, indent_len);
+ openfile->totsize += mbstrnlen(indent_string, indent_len);
}
}
#endif
} else {
/* Otherwise, make a new line and copy the text after where we
* broke this line to the beginning of the new line. */
- splice_node(current, make_new_node(current), current->next);
+ splice_node(openfile->current, make_new_node(openfile->current),
+ openfile->current->next);
- current->next->data = new_line;
+ openfile->current->next->data = new_line;
- totlines++;
- totsize++;
+ openfile->totlines++;
+ openfile->totsize++;
}
/* Step 3, clean up. Reposition the cursor and mark, and do some
/* If the cursor was after the break point, we must move it. We
* also clear the same_line_wrap flag in this case. */
- if (current_x > wrap_loc) {
+ if (openfile->current_x > wrap_loc) {
same_line_wrap = FALSE;
- current = current->next;
- current_x -= wrap_loc
+ openfile->current = openfile->current->next;
+ openfile->current_x -= wrap_loc
#ifndef NANO_SMALL
- indent_len
#endif
;
- placewewant = xplustabs();
+ openfile->placewewant = xplustabs();
}
#ifndef NANO_SMALL
/* If the mark was on this line after the wrap point, we move it
* down. If it was on the next line and we wrapped onto that line,
* we move it right. */
- if (mark_beginbuf == line && mark_beginx > wrap_loc) {
- mark_beginbuf = line->next;
- mark_beginx -= wrap_loc - indent_len + 1;
- } else if (wrapping && mark_beginbuf == line->next)
- mark_beginx += after_break_len;
+ if (openfile->mark_set && openfile->mark_beginbuf == line &&
+ openfile->mark_beginx > wrap_loc) {
+ openfile->mark_beginbuf = line->next;
+ openfile->mark_beginx -= wrap_loc - indent_len + 1;
+ } else if (wrapping && openfile->mark_beginbuf == line->next)
+ openfile->mark_beginx += after_break_len;
#endif
return TRUE;
bool do_int_spell_fix(const char *word)
{
char *save_search, *save_replace;
- size_t match_len;
- size_t current_x_save = current_x, pww_save = placewewant;
- filestruct *edittop_save = edittop, *current_save = current;
+ size_t match_len, current_x_save = openfile->current_x;
+ size_t pww_save = openfile->placewewant;
+ filestruct *edittop_save = openfile->edittop;
+ filestruct *current_save = openfile->current;
/* Save where we are. */
bool canceled = FALSE;
/* The return value. */
bool regexp_set = ISSET(USE_REGEXP);
#endif
#ifndef NANO_SMALL
- bool old_mark_set = ISSET(MARK_ISSET);
+ bool old_mark_set = openfile->mark_set;
bool added_magicline = FALSE;
/* Whether we added a magicline after filebot. */
bool right_side_up = FALSE;
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, &right_side_up);
filepart = partition_filestruct(top, top_x, bot, bot_x);
- added_magicline = (filebot->data[0] != '\0');
- UNSET(MARK_ISSET);
+ added_magicline = (openfile->filebot->data[0] != '\0');
+ openfile->mark_set = FALSE;
}
#endif
/* Start from the top of the file. */
- edittop = fileage;
- current = fileage;
- current_x = (size_t)-1;
- placewewant = 0;
+ openfile->edittop = openfile->fileage;
+ openfile->current = openfile->fileage;
+ openfile->current_x = (size_t)-1;
+ openfile->placewewant = 0;
/* Find the first whole-word occurrence of word. */
findnextstr_wrap_reset();
- while (findnextstr(TRUE, TRUE, FALSE, fileage, 0, word,
+ while (findnextstr(TRUE, TRUE, FALSE, openfile->fileage, 0, word,
&match_len)) {
- if (is_whole_word(current_x, current->data, word)) {
+ if (is_whole_word(openfile->current_x, openfile->current->data,
+ word)) {
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);
edit_refresh();
free(exp_word);
if (!canceled && strcmp(word, answer) != 0) {
- current_x--;
- do_replace_loop(word, current, ¤t_x, TRUE,
- &canceled);
+ openfile->current_x--;
+ do_replace_loop(word, openfile->current,
+ &openfile->current_x, TRUE, &canceled);
}
break;
/* Put the beginning and the end of the mark at the beginning
* and the end of the spell-checked text. */
- if (fileage == filebot)
+ if (openfile->fileage == openfile->filebot)
bot_x += top_x;
if (right_side_up) {
- mark_beginx = top_x;
+ openfile->mark_beginx = top_x;
current_x_save = bot_x;
} else {
current_x_save = top_x;
- mark_beginx = bot_x;
+ openfile->mark_beginx = bot_x;
}
/* Unpartition the filestruct so that it contains all the text
* again, and turn the mark back on. */
unpartition_filestruct(&filepart);
- SET(MARK_ISSET);
+ openfile->mark_set = TRUE;
}
#endif
last_replace = save_replace;
/* Restore where we were. */
- edittop = edittop_save;
- current = current_save;
- current_x = current_x_save;
- placewewant = pww_save;
+ openfile->edittop = edittop_save;
+ openfile->current = current_save;
+ openfile->current_x = current_x_save;
+ openfile->placewewant = pww_save;
/* Restore case sensitivity setting. */
if (!case_sens_set)
const char *do_alt_speller(char *tempfile_name)
{
int alt_spell_status;
- size_t current_x_save = current_x, pww_save = placewewant;
- ssize_t current_y_save = current_y, lineno_save = current->lineno;
+ size_t current_x_save = openfile->current_x;
+ size_t pww_save = openfile->placewewant;
+ ssize_t current_y_save = openfile->current_y;
+ ssize_t lineno_save = openfile->current->lineno;
pid_t pid_spell;
char *ptr;
static int arglen = 3;
static char **spellargs = NULL;
FILE *f;
#ifndef NANO_SMALL
- bool old_mark_set = ISSET(MARK_ISSET);
+ bool old_mark_set = openfile->mark_set;
bool added_magicline = FALSE;
/* Whether we added a magicline after filebot. */
bool right_side_up = FALSE;
* the alternate spell command. The line that mark_beginbuf
* points to will be freed, so we save the line number and
* restore afterwards. */
- size_t totsize_save = totsize;
+ size_t totsize_save = openfile->totsize;
/* Our saved value of totsize, used when we spell-check a marked
* selection. */
if (old_mark_set) {
/* If the mark is on, save the number of the line it starts on,
* and then turn the mark off. */
- mbb_lineno_save = mark_beginbuf->lineno;
- UNSET(MARK_ISSET);
+ mbb_lineno_save = openfile->mark_beginbuf->lineno;
+ openfile->mark_set = FALSE;
}
#endif
#ifndef NANO_SMALL
/* Turn the mark back on if it was on before. */
- if (old_mark_set)
- SET(MARK_ISSET);
+ openfile->mark_set = old_mark_set;
#endif
altspell_error =
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, &right_side_up);
filepart = partition_filestruct(top, top_x, bot, bot_x);
- added_magicline = (filebot->data[0] != '\0');
+ added_magicline = (openfile->filebot->data[0] != '\0');
/* Get the number of characters in the marked text, and subtract
* it from the saved value of totsize. Note that we don't need
#endif
/* Reinitialize the filestruct. */
- free_filestruct(fileage);
- global_init(TRUE);
+ free_filestruct(openfile->fileage);
- /* Reload the temp file. Do what load_buffer() would do, except for
+ /* Reinitialize the resize variables. */
+ resize_init();
+
+ /* Reload the temp file. Do what open_buffer() would do, except for
* making a new buffer for the temp file if multibuffer support is
* available. */
open_file(tempfile_name, FALSE, &f);
read_file(f, tempfile_name);
- current = fileage;
+ openfile->current = openfile->fileage;
#ifndef NANO_SMALL
if (old_mark_set) {
- filestruct *top_save = fileage;
+ filestruct *top_save = openfile->fileage;
/* If the mark was on and we added a magicline, remove it
* now. */
/* Put the beginning and the end of the mark at the beginning
* and the end of the spell-checked text. */
- if (fileage == filebot)
+ if (openfile->fileage == openfile->filebot)
bot_x += top_x;
if (right_side_up) {
- mark_beginx = top_x;
+ openfile->mark_beginx = top_x;
current_x_save = bot_x;
} else {
current_x_save = top_x;
- mark_beginx = bot_x;
+ openfile->mark_beginx = bot_x;
}
/* Unpartition the filestruct so that it contains all the text
* marked text to the saved value of totsize, and then make that
* saved value the actual value. */
renumber(top_save);
- totlines = filebot->lineno;
- totsize_save += totsize;
- totsize = totsize_save;
+ openfile->totlines = openfile->filebot->lineno;
+ totsize_save += openfile->totsize;
+ openfile->totsize = totsize_save;
/* Assign mark_beginbuf to the line where the mark began
* before. */
- do_gotopos(mbb_lineno_save, mark_beginx, current_y_save, 0);
- mark_beginbuf = current;
+ do_gotopos(mbb_lineno_save, openfile->mark_beginx,
+ current_y_save, 0);
+ openfile->mark_beginbuf = openfile->current;
/* Assign mark_beginx to the location in mark_beginbuf where the
* mark began before, adjusted for any shortening of the
* line. */
- mark_beginx = current_x;
+ openfile->mark_beginx = openfile->current_x;
/* Turn the mark back on. */
- SET(MARK_ISSET);
+ openfile->mark_set = TRUE;
}
#endif
- /* Go back to the old position, mark the file as modified, and
- * update the titlebar. */
+ /* Go back to the old position, and mark the file as modified. */
do_gotopos(lineno_save, current_x_save, current_y_save, pww_save);
- SET(MODIFIED);
- titlebar(NULL);
+ set_modified();
return NULL;
}
}
#ifndef NANO_SMALL
- if (ISSET(MARK_ISSET))
+ if (openfile->mark_set)
i = write_marked(temp, temp_file, TRUE, FALSE);
else
#endif
return;
}
-#ifdef ENABLE_MULTIBUFFER
- /* Update the current openfile entry before spell-checking, in
- * case any problems occur. */
- add_open_file(TRUE);
-#endif
-
spell_msg = (alt_speller != NULL) ? do_alt_speller(temp) :
do_int_speller(temp);
unlink(temp);
#ifndef NANO_SMALL
/* Keep track of the change in the current line. */
- if (mark_beginbuf == paragraph &&
- mark_beginx >= end - paragraph->data)
+ if (openfile->mark_set && openfile->mark_beginbuf ==
+ paragraph && openfile->mark_beginx >= end -
+ paragraph->data)
mark_shift += end_len;
#endif
}
#ifndef NANO_SMALL
/* Keep track of the change in the current line. */
- if (mark_beginbuf == paragraph &&
- mark_beginx >= end - paragraph->data)
+ if (openfile->mark_set && openfile->mark_beginbuf ==
+ paragraph && openfile->mark_beginx >= end -
+ paragraph->data)
mark_shift += end_len;
#endif
}
}
if (shift > 0) {
- totsize -= shift;
+ openfile->totsize -= shift;
null_at(&new_paragraph_data, new_end - new_paragraph_data);
free(paragraph->data);
paragraph->data = new_paragraph_data;
#ifndef NANO_SMALL
/* Adjust the mark coordinates to compensate for the change in
* the current line. */
- if (mark_beginbuf == paragraph) {
- mark_beginx -= mark_shift;
- if (mark_beginx > new_end - new_paragraph_data)
- mark_beginx = new_end - new_paragraph_data;
+ if (openfile->mark_set && openfile->mark_beginbuf ==
+ paragraph) {
+ openfile->mark_beginx -= mark_shift;
+ if (openfile->mark_beginx > new_end - new_paragraph_data)
+ openfile->mark_beginx = new_end - new_paragraph_data;
}
#endif
} else
* line. */
void do_para_begin(bool allow_update)
{
- const filestruct *current_save = current;
- const size_t pww_save = placewewant;
+ const filestruct *current_save = openfile->current;
+ const size_t pww_save = openfile->placewewant;
- current_x = 0;
- placewewant = 0;
+ openfile->current_x = 0;
+ openfile->placewewant = 0;
- if (current->prev != NULL) {
+ if (openfile->current->prev != NULL) {
do {
- current = current->prev;
- current_y--;
- } while (!begpar(current));
+ openfile->current = openfile->current->prev;
+ openfile->current_y--;
+ } while (!begpar(openfile->current));
}
if (allow_update)
* down to the end of a paragraph, then one line farther. */
void do_para_end(bool allow_update)
{
- const filestruct *const current_save = current;
- const size_t pww_save = placewewant;
+ const filestruct *const current_save = openfile->current;
+ const size_t pww_save = openfile->placewewant;
- current_x = 0;
- placewewant = 0;
+ openfile->current_x = 0;
+ openfile->placewewant = 0;
- while (current->next != NULL && !inpar(current))
- current = current->next;
+ while (openfile->current->next != NULL && !inpar(openfile->current))
+ openfile->current = openfile->current->next;
- while (current->next != NULL && inpar(current->next) &&
- !begpar(current->next)) {
- current = current->next;
- current_y++;
+ while (openfile->current->next != NULL &&
+ inpar(openfile->current->next) &&
+ !begpar(openfile->current->next)) {
+ openfile->current = openfile->current->next;
+ openfile->current_y++;
}
- if (current->next != NULL)
- current = current->next;
+ if (openfile->current->next != NULL)
+ openfile->current = openfile->current->next;
if (allow_update)
edit_redraw(current_save, pww_save);
/* The bottom of the paragraph we're backing up. */
size_t i;
/* Generic loop variable. */
- size_t current_x_save = current_x;
+ size_t current_x_save = openfile->current_x;
ssize_t fl_lineno_save = first_line->lineno;
- ssize_t edittop_lineno_save = edittop->lineno;
- ssize_t current_lineno_save = current->lineno;
+ ssize_t edittop_lineno_save = openfile->edittop->lineno;
+ ssize_t current_lineno_save = openfile->current->lineno;
#ifndef NANO_SMALL
- bool old_mark_set = ISSET(MARK_ISSET);
+ bool old_mark_set = openfile->mark_set;
ssize_t mbb_lineno_save = 0;
size_t mark_beginx_save = 0;
if (old_mark_set) {
- mbb_lineno_save = mark_beginbuf->lineno;
- mark_beginx_save = mark_beginx;
+ mbb_lineno_save = openfile->mark_beginbuf->lineno;
+ mark_beginx_save = openfile->mark_beginx;
}
#endif
* line, putting first_line, edittop, current, and mark_beginbuf at
* the same lines in the copied paragraph that they had in the
* original paragraph. */
- top = current->prev;
+ top = openfile->current->prev;
for (i = par_len; i > 0; i--) {
if (top->lineno == fl_lineno_save)
first_line = top;
if (top->lineno == edittop_lineno_save)
- edittop = top;
+ openfile->edittop = top;
if (top->lineno == current_lineno_save)
- current = top;
+ openfile->current = top;
#ifndef NANO_SMALL
if (old_mark_set && top->lineno == mbb_lineno_save) {
- mark_beginbuf = top;
- mark_beginx = mark_beginx_save;
+ openfile->mark_beginbuf = top;
+ openfile->mark_beginx = mark_beginx_save;
}
#endif
top = top->prev;
/* Put current_x at the same place in the copied paragraph that it
* had in the original paragraph. */
- current_x = current_x_save;
+ openfile->current_x = current_x_save;
set_modified();
}
#endif
- assert(current != NULL);
+ assert(openfile->current != NULL);
/* Move back to the beginning of the current line. */
- current_x = 0;
- placewewant = 0;
+ openfile->current_x = 0;
+ openfile->placewewant = 0;
/* Find the first line of the current or next paragraph. First, if
* the current line isn't in a paragraph, move forward to the line
* move back to the last line of the paragraph. If the current line
* is in a paragraph and it isn't the first line of that paragraph,
* move back to the first line. */
- if (!inpar(current)) {
- current_save = current;
+ if (!inpar(openfile->current)) {
+ current_save = openfile->current;
do_para_end(FALSE);
- if (current == current_save || !inpar(current->prev))
+ if (openfile->current == current_save ||
+ !inpar(openfile->current->prev))
return FALSE;
- if (current->prev != NULL)
- current = current->prev;
+ if (openfile->current->prev != NULL)
+ openfile->current = openfile->current->prev;
}
- if (!begpar(current))
+ if (!begpar(openfile->current))
do_para_begin(FALSE);
/* Now current is the first line of the paragraph. Set quote_len to
* the quotation length of that line, and set par_len to the number
* of lines in this paragraph. */
- quote_len = quote_length(current->data);
- current_save = current;
- current_y_save = current_y;
+ quote_len = quote_length(openfile->current->data);
+ current_save = openfile->current;
+ current_y_save = openfile->current_y;
do_para_end(FALSE);
- par_len = current->lineno - current_save->lineno;
- current = current_save;
- current_y = current_y_save;
+ par_len = openfile->current->lineno - current_save->lineno;
+ openfile->current = current_save;
+ openfile->current_y = current_y_save;
/* Save the values of quote_len and par_len. */
assert(quote != NULL && par != NULL);
/* Will be the line containing the newline after the last line
* of the result. Also for restoring after unjustify. */
- /* We save these global variables to be restored if the user
- * unjustifies. Note that we don't need to save totlines. */
- size_t current_x_save = current_x, pww_save = placewewant;
- ssize_t current_y_save = current_y;
- unsigned long flags_save = flags;
- size_t totsize_save = totsize;
- filestruct *edittop_save = edittop, *current_save = current;
+ /* We save these variables to be restored if the user unjustifies.
+ * Note that we don't need to save totlines. */
+ size_t current_x_save = openfile->current_x;
+ size_t pww_save = openfile->placewewant;
+ ssize_t current_y_save = openfile->current_y;
+ bool modified_save = openfile->modified;
+ size_t totsize_save = openfile->totsize;
+ filestruct *edittop_save = openfile->edittop;
+ filestruct *current_save = openfile->current;
#ifndef NANO_SMALL
- filestruct *mark_beginbuf_save = mark_beginbuf;
- size_t mark_beginx_save = mark_beginx;
+ filestruct *mark_beginbuf_save = openfile->mark_beginbuf;
+ size_t mark_beginx_save = openfile->mark_beginx;
#endif
int kbinput;
bool meta_key, func_key, s_or_t, ran_func, finished;
/* If we're justifying the entire file, start at the beginning. */
if (full_justify)
- current = fileage;
+ openfile->current = openfile->fileage;
- last_par_line = current;
+ last_par_line = openfile->current;
while (TRUE) {
size_t i;
* justify, so refresh the screen and get out. */
if (!find_paragraph("e_len, &par_len)) {
if (full_justify && first_par_line != NULL &&
- first_par_line != filebot) {
- last_par_line = filebot;
+ first_par_line != openfile->filebot) {
+ last_par_line = openfile->filebot;
break;
} else {
edit_refresh();
/* If we haven't already done it, copy the original paragraph(s)
* to the justify buffer. */
if (first_par_line == NULL)
- first_par_line = backup_lines(current, full_justify ?
- filebot->lineno - current->lineno : par_len, quote_len);
+ first_par_line = backup_lines(openfile->current,
+ full_justify ? openfile->filebot->lineno -
+ openfile->current->lineno : par_len, quote_len);
/* Initialize indent_string to a blank string. */
indent_string = mallocstrcpy(NULL, "");
* indent_string. If all the indentations are the same, save
* the indentation of the first line in indent_string. */
{
- const filestruct *indent_line = current;
+ const filestruct *indent_line = openfile->current;
bool past_first_line = FALSE;
for (i = 0; i < par_len; i++) {
break;
}
- if (indent_line == current)
+ if (indent_line == openfile->current)
past_first_line = TRUE;
indent_line = indent_line->next;
/* Now tack all the lines of the paragraph together, skipping
* the quoting and indentation on all lines after the first. */
for (i = 0; i < par_len - 1; i++) {
- filestruct *next_line = current->next;
- size_t line_len = strlen(current->data);
- size_t next_line_len = strlen(current->next->data);
+ filestruct *next_line = openfile->current->next;
+ size_t line_len = strlen(openfile->current->data);
+ size_t next_line_len =
+ strlen(openfile->current->next->data);
- indent_len = quote_len + indent_length(current->next->data +
+ indent_len = quote_len +
+ indent_length(openfile->current->next->data +
quote_len);
next_line_len -= indent_len;
- totsize -= indent_len;
+ openfile->totsize -= indent_len;
/* We're just about to tack the next line onto this one. If
* this line isn't empty, make sure it ends in a space. */
- if (line_len > 0 && current->data[line_len - 1] != ' ') {
+ if (line_len > 0 &&
+ openfile->current->data[line_len - 1] != ' ') {
line_len++;
- current->data = charealloc(current->data, line_len + 1);
- current->data[line_len - 1] = ' ';
- current->data[line_len] = '\0';
- totsize++;
+ openfile->current->data =
+ charealloc(openfile->current->data,
+ line_len + 1);
+ openfile->current->data[line_len - 1] = ' ';
+ openfile->current->data[line_len] = '\0';
+ openfile->totsize++;
}
- current->data = charealloc(current->data, line_len +
+ openfile->current->data =
+ charealloc(openfile->current->data, line_len +
next_line_len + 1);
- strcat(current->data, next_line->data + indent_len);
+ strcat(openfile->current->data, next_line->data +
+ indent_len);
/* Don't destroy edittop! */
- if (edittop == next_line)
- edittop = current;
+ if (openfile->edittop == next_line)
+ openfile->edittop = openfile->current;
#ifndef NANO_SMALL
/* Adjust the mark coordinates to compensate for the change
* in the next line. */
- if (mark_beginbuf == next_line) {
- mark_beginbuf = current;
- mark_beginx += line_len - indent_len;
+ if (openfile->mark_set && openfile->mark_beginbuf ==
+ next_line) {
+ openfile->mark_beginbuf = openfile->current;
+ openfile->mark_beginx += line_len - indent_len;
}
#endif
i--;
par_len--;
- totlines--;
- totsize--;
+ openfile->totlines--;
+ openfile->totsize--;
}
/* Call justify_format() on the paragraph, which will remove
* excess spaces from it and change all blank characters to
* spaces. */
- justify_format(current, quote_len +
- indent_length(current->data + quote_len));
+ justify_format(openfile->current, quote_len +
+ indent_length(openfile->current->data + quote_len));
- while (par_len > 0 && strlenpt(current->data) > fill) {
- size_t line_len = strlen(current->data);
+ while (par_len > 0 &&
+ strlenpt(openfile->current->data) > fill) {
+ size_t line_len = strlen(openfile->current->data);
indent_len = strlen(indent_string);
/* If this line is too long, try to wrap it to the next line
* to make it short enough. */
- break_pos = break_line(current->data + indent_len,
- fill - strnlenpt(current->data, indent_len), FALSE);
+ break_pos =
+ break_line(openfile->current->data + indent_len, fill -
+ strnlenpt(openfile->current->data, indent_len), FALSE);
/* We can't break the line, or don't need to, so get out. */
if (break_pos == -1 || break_pos + indent_len == line_len)
/* Make a new line, and copy the text after where we're
* going to break this line to the beginning of the new
* line. */
- splice_node(current, make_new_node(current), current->next);
+ splice_node(openfile->current,
+ make_new_node(openfile->current),
+ openfile->current->next);
/* If this paragraph is non-quoted, and autoindent isn't
* turned on, set the indentation length to zero so that the
/* Copy the text after where we're going to break the
* current line to the next line. */
- current->next->data = charalloc(indent_len + 1 + line_len -
- break_pos);
- strncpy(current->next->data, indent_string, indent_len);
- strcpy(current->next->data + indent_len, current->data +
- break_pos);
+ openfile->current->next->data = charalloc(indent_len + 1 +
+ line_len - break_pos);
+ strncpy(openfile->current->next->data, indent_string,
+ indent_len);
+ strcpy(openfile->current->next->data + indent_len,
+ openfile->current->data + break_pos);
par_len++;
- totlines++;
- totsize += indent_len + 1;
+ openfile->totlines++;
+ openfile->totsize += indent_len + 1;
#ifndef NANO_SMALL
/* Adjust the mark coordinates to compensate for the change
* in the current line. */
- if (mark_beginbuf == current && mark_beginx > break_pos) {
- mark_beginbuf = current->next;
- mark_beginx -= break_pos - indent_len;
+ if (openfile->mark_set && openfile->mark_beginbuf ==
+ openfile->current && openfile->mark_beginx >
+ break_pos) {
+ openfile->mark_beginbuf = openfile->current->next;
+ openfile->mark_beginx -= break_pos - indent_len;
}
#endif
/* Break the current line. */
- null_at(¤t->data, break_pos);
+ null_at(&openfile->current->data, break_pos);
/* Go to the next line. */
par_len--;
- current_y++;
- current = current->next;
+ openfile->current_y++;
+ openfile->current = openfile->current->next;
}
/* We're done breaking lines, so we don't need indent_string
/* Go to the next line, the line after the last line of the
* paragraph. */
- current_y++;
- current = current->next;
+ openfile->current_y++;
+ openfile->current = openfile->current->next;
/* We've just justified a paragraph. If we're not justifying the
* entire file, break out of the loop. Otherwise, continue the
* fileage, and renumber() since edit_refresh() needs the line
* numbers to be right (but only do the last two if we actually
* justified something). */
- last_par_line = current;
+ last_par_line = openfile->current;
if (first_par_line != NULL) {
if (first_par_line->prev == NULL)
- fileage = first_par_line;
+ openfile->fileage = first_par_line;
renumber(first_par_line);
}
if (!meta_key && !func_key && s_or_t &&
kbinput == NANO_UNJUSTIFY_KEY) {
/* Restore the justify we just did (ungrateful user!). */
- current = current_save;
- current_x = current_x_save;
- placewewant = pww_save;
- current_y = current_y_save;
- edittop = edittop_save;
+ openfile->current = current_save;
+ openfile->current_x = current_x_save;
+ openfile->placewewant = pww_save;
+ openfile->current_y = current_y_save;
+ openfile->edittop = edittop_save;
/* Splice the justify buffer back into the file, but only if we
* actually justified something. */
/* Remove the text of the justified paragraph, and
* put the text in the justify buffer in its place. */
- free_filestruct(fileage);
- fileage = jusbuffer;
- filebot = jusbottom;
+ free_filestruct(openfile->fileage);
+ openfile->fileage = jusbuffer;
+ openfile->filebot = jusbottom;
- bot_save = filebot;
+ bot_save = openfile->filebot;
/* Unpartition the filestruct so that it contains all the
* text again. Note that the justified paragraph has been
if (bot_save->next != NULL)
renumber(bot_save->next);
- /* Restore global variables from before the justify. */
- totsize = totsize_save;
- totlines = filebot->lineno;
+ /* Restore variables from before the justify. */
+ openfile->totsize = totsize_save;
+ openfile->totlines = openfile->filebot->lineno;
#ifndef NANO_SMALL
- mark_beginbuf = mark_beginbuf_save;
- mark_beginx = mark_beginx_save;
+ if (openfile->mark_set) {
+ openfile->mark_beginbuf = mark_beginbuf_save;
+ openfile->mark_beginx = mark_beginx_save;
+ }
#endif
- flags = flags_save;
+ openfile->modified = modified_save;
/* Clear the justify buffer. */
jusbuffer = NULL;
- if (!ISSET(MODIFIED))
+ if (!openfile->modified)
titlebar(NULL);
edit_refresh();
}
{
int i;
- if (!ISSET(MODIFIED))
+ if (!openfile->modified)
i = 0; /* Pretend the user chose not to save. */
else if (ISSET(TEMP_FILE))
i = 1;
_("Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? "));
#ifdef DEBUG
- dump_buffer(fileage);
+ dump_filestruct(openfile->fileage);
#endif
if (i == 0 || (i == 1 && do_writeout(TRUE) == 0)) {
#ifdef ENABLE_MULTIBUFFER
/* Exit only if there are no more open file buffers. */
- if (!close_open_file())
+ if (!close_buffer())
#endif
finish();
} else if (i != 1)
COLS = win.ws_col;
LINES = win.ws_row;
- check_die_too_small();
- resize_variables();
+ resize_init();
/* If we've partitioned the filestruct, unpartition it now. */
if (filepart != NULL)
/* Subtract out the size of topwin. */
mouse_y -= 2 - no_more_space();
- sameline = (mouse_y == current_y);
+ sameline = (mouse_y == openfile->current_y);
/* Move to where the click occurred. */
- for (; current_y < mouse_y && current->next != NULL;
- current_y++)
- current = current->next;
- for (; current_y > mouse_y && current->prev != NULL;
- current_y--)
- current = current->prev;
-
- xcur = actual_x(current->data,
+ for (; openfile->current_y < mouse_y &&
+ openfile->current->next != NULL; openfile->current_y++)
+ openfile->current = openfile->current->next;
+ for (; openfile->current_y > mouse_y &&
+ openfile->current->prev != NULL; openfile->current_y--)
+ openfile->current = openfile->current->prev;
+
+ xcur = actual_x(openfile->current->data,
get_page_start(xplustabs()) + mouse_x);
#ifndef NANO_SMALL
/* Clicking where the cursor is toggles the mark, as does
* clicking beyond the line length with the cursor at the
* end of the line. */
- if (sameline && xcur == current_x) {
+ if (sameline && xcur == openfile->current_x) {
if (ISSET(VIEW_MODE)) {
print_view_warning();
return retval;
}
#endif
- current_x = xcur;
- placewewant = xplustabs();
+ openfile->current_x = xcur;
+ openfile->placewewant = xplustabs();
edit_refresh();
}
}
char *char_buf = charalloc(mb_cur_max());
int char_buf_len;
- assert(current != NULL && current->data != NULL);
+ assert(openfile->current != NULL && openfile->current->data != NULL);
- current_len = strlen(current->data);
+ current_len = strlen(openfile->current->data);
/* Turn off constant cursor position display. */
UNSET(CONST_UPDATE);
/* When a character is inserted on the current magicline, it
* means we need a new one! */
- if (filebot == current)
+ if (openfile->filebot == openfile->current)
new_magicline();
/* More dangerousness fun =) */
- current->data = charealloc(current->data,
+ openfile->current->data = charealloc(openfile->current->data,
current_len + (char_buf_len * 2));
- assert(current_x <= current_len);
+ assert(openfile->current_x <= current_len);
- charmove(¤t->data[current_x + char_buf_len],
- ¤t->data[current_x],
- current_len - current_x + char_buf_len);
- strncpy(¤t->data[current_x], char_buf, char_buf_len);
+ charmove(&openfile->current->data[openfile->current_x +
+ char_buf_len],
+ &openfile->current->data[openfile->current_x],
+ current_len - openfile->current_x + char_buf_len);
+ strncpy(&openfile->current->data[openfile->current_x], char_buf,
+ char_buf_len);
current_len += char_buf_len;
- totsize++;
+ openfile->totsize++;
set_modified();
#ifndef NANO_SMALL
/* Note that current_x has not yet been incremented. */
- if (current == mark_beginbuf && current_x < mark_beginx)
- mark_beginx += char_buf_len;
+ if (openfile->mark_set && openfile->current ==
+ openfile->mark_beginbuf && openfile->current_x <
+ openfile->mark_beginx)
+ openfile->mark_beginx += char_buf_len;
#endif
do_right(FALSE);
if (!ISSET(NO_WRAP)) {
bool do_refresh_save = do_refresh;
- do_refresh = do_wrap(current);
+ do_refresh = do_wrap(openfile->current);
/* If we needed to call edit_refresh() before this, we'll
* still need to after this. */
if (do_refresh)
edit_refresh();
else
- update_line(current, current_x);
+ update_line(openfile->current, openfile->current_x);
}
int main(int argc, char **argv)
/* Turn the cursor on for sure. */
curs_set(1);
- /* Set up the global variables and the shortcuts. */
- global_init(FALSE);
+ /* Set up the resize variables and the shortcuts. */
+ resize_init();
shortcut_init(FALSE);
/* Set up the signal handlers. */
icol == 1)
parse_line_column(&argv[i][1], &iline, &icol);
else {
- load_buffer(argv[i]);
+ open_buffer(argv[i]);
if (iline > 1 || icol > 1) {
do_gotolinecolumn(iline, icol, FALSE, FALSE, FALSE);
* buffer or a new buffer, depending on whether multibuffer mode is
* enabled. */
if (optind < argc)
- load_buffer(argv[optind]);
+ open_buffer(argv[optind]);
/* We didn't open any files if all the command line arguments were
* invalid files like directories or if there were no command line
* arguments given. In this case, we have to load a blank buffer.
* Also, we unset view mode to allow editing. */
- if (filename == NULL) {
- filename = mallocstrcpy(NULL, "");
- new_file();
+ if (openfile == NULL) {
+ open_buffer("");
UNSET(VIEW_MODE);
-
- /* Add this new entry to the openfile structure if we have
- * multibuffer support, or to the main filestruct if we
- * don't. */
- load_file();
}
#ifdef ENABLE_MULTIBUFFER
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
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;
/* 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
#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
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;
#endif
extern WINDOW *topwin, *edit, *bottomwin;
-extern char *filename;
-extern struct stat originalfilestat;
extern char *answer;
extern char *hblank;
#ifndef DISABLE_HELP
#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;
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);
#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
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);
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);
);
assert(!regexp_compiled);
+
if (rc != 0) {
size_t len = regerror(rc, &search_regexp, NULL, 0);
char *str = charalloc(len);
{
display_main_list();
#ifndef NANO_SMALL
- if (ISSET(MARK_ISSET))
+ if (openfile->mark_set)
edit_refresh();
#endif
#ifdef HAVE_REGEX_H
replacing ?
#ifndef NANO_SMALL
- (ISSET(MARK_ISSET) ? _(" (to replace) in selection") :
-#endif
- _(" (to replace)")
-#ifndef NANO_SMALL
- )
+ openfile->mark_set ? _(" (to replace) in selection") :
#endif
- : "",
+ _(" (to replace)") : "",
buf);
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:
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()
* 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) {
* 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;
}
#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
}
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)
/* 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();
#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
* 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
#endif
}
- placewewant = xplustabs();
+ openfile->placewewant = xplustabs();
edit_redraw(fileptr, old_pww);
search_abort();
}
/* 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();
#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
* 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
} else
statusbar(_("No current search pattern"));
- placewewant = xplustabs();
+ openfile->placewewant = xplustabs();
edit_redraw(fileptr, old_pww);
search_abort();
}
* 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++;
/* 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;
}
}
} 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
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;
}
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,
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
* 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;
}
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);
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;
}
}
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
#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
edit_refresh();
else
#endif
- update_line(current, current_x);
+ update_line(openfile->current, openfile->current_x);
}
set_modified();
* 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;
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();
}
} 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. */
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)
{
/* 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
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) {
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.
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;
}
}
/* 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
* 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--;
}
}
{
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;
}
/* 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 *
/* 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
/* 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. */
* 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
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);
waddstr(topwin, " ");
}
- if (ISSET(MODIFIED))
+ if (openfile->modified)
state = _("Modified");
else if (ISSET(VIEW_MODE))
state = _("View");
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);
prefix = _("DIR:");
else
#endif
- if (filename[0] == '\0') {
+ if (openfile->filename[0] == '\0') {
prefix = _("New Buffer");
newfie = TRUE;
} else
prefixlen++;
if (path == NULL)
- path = filename;
+ path = openfile->filename;
if (space >= prefixlen + statelen)
space -= prefixlen + statelen;
else
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);
}
}
{
/* 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));
}
}
#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;
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));
/* 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
{
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.
{
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
* 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++;
}
}
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--)
/* 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;
}
* 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. */
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;
* 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)
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)
foo = foo->prev;
}
- edittop = foo;
+ openfile->edittop = foo;
edit_refresh();
}
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;
/* 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;
}
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;
#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");
}
/* 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,