From 9c984e8e63de67bbd00b1841edfaf4bcdf704e7f Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 8 Nov 2005 19:15:58 +0000 Subject: [PATCH] in do_alt_speller(), move the code that replaces the text of the current file with the text of the spell-checked file into its own function, replace_buffer() git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3109 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/files.c | 33 +++++++++++++++++++++++++++++++++ src/proto.h | 3 +++ src/text.c | 15 +++------------ 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index a41b98d2..12da530c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -94,6 +94,11 @@ CVS code - - rcfile.c: do_rcfile() - Remove unneeded assert. (DLR) +- text.c: + do_alt_speller() + - Move the code that replaces the text of the current file with + the text of the spell-checked file into its own function, + replace_buffer(). (DLR) - winio.c: nanoget_repaint() - Rename parameter inputbuf to buf, for consistency. (DLR) diff --git a/src/files.c b/src/files.c index 09f665b2..99f64e82 100644 --- a/src/files.c +++ b/src/files.c @@ -168,6 +168,39 @@ void open_buffer(const char *filename) #endif } +#ifndef DISABLE_SPELLER +/* If it's not "", filename is a file to open. We blow away the text of + * the current buffer, and then open and read the file, if + * applicable. Note that we skip the operating directory test when + * doing this. */ +void replace_buffer(const char *filename) +{ + 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. */ + + assert(filename != NULL); + + /* If the filename isn't blank, open the file. Otherwise, treat it + * as a new file. */ + rc = (filename[0] != '\0') ? open_file(filename, TRUE, &f) : -2; + + /* Reinitialize the text of the current buffer. */ + free_filestruct(openfile->fileage); + initialize_buffer_text(); + + /* If we have a non-new file, read it in. */ + if (rc == 0) + read_file(f, filename); + + /* Move back to the beginning of the first line of the buffer. */ + openfile->current = openfile->fileage; + openfile->current_x = 0; + openfile->placewewant = 0; +} +#endif /* !DISABLE_SPELLER */ + /* Update the screen to account for the current buffer. */ void display_buffer(void) { diff --git a/src/proto.h b/src/proto.h index 7a4ff7db..9c3f3633 100644 --- a/src/proto.h +++ b/src/proto.h @@ -235,6 +235,9 @@ void make_new_buffer(void); void initialize_buffer(void); void initialize_buffer_text(void); void open_buffer(const char *filename); +#ifndef DISABLE_SPELLER +void replace_buffer(const char *filename); +#endif void display_buffer(void); #ifdef ENABLE_MULTIBUFFER void switch_to_prevnext_buffer(bool next); diff --git a/src/text.c b/src/text.c index 5cd4f77e..429b07f5 100644 --- a/src/text.c +++ b/src/text.c @@ -1836,7 +1836,6 @@ const char *do_alt_speller(char *tempfile_name) char *ptr; static int arglen = 3; static char **spellargs = NULL; - FILE *f; #ifndef NANO_SMALL bool old_mark_set = openfile->mark_set; bool added_magicline = FALSE; @@ -1951,17 +1950,9 @@ const char *do_alt_speller(char *tempfile_name) } #endif - /* Reinitialize the text of the current buffer. */ - free_filestruct(openfile->fileage); - initialize_buffer_text(); - - /* Reload the temp file. Open it, read it into the current buffer, - * and move back to the beginning of the first line of the - * buffer. */ - open_file(tempfile_name, FALSE, &f); - read_file(f, tempfile_name); - openfile->current = openfile->fileage; - openfile->current_x = 0; + /* Replace the text of the current buffer with the spell-checked + * text. */ + replace_buffer(tempfile_name); #ifndef NANO_SMALL if (old_mark_set) { -- 2.39.5