From 520a90c8d9d46e8d0d1ac39a5ac1645284ab7001 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Mon, 25 Jul 2005 21:23:11 +0000 Subject: [PATCH] since the total number of lines in a file is the same as the number of its last line when all its lines are numbered properly, use that in place of openfile->totlines, and eliminate references to openfile->totlines git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2933 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 8 ++++++++ src/files.c | 3 --- src/nano.c | 6 ------ src/nano.h | 5 ++--- src/text.c | 37 +++++++++++++++---------------------- src/utils.c | 2 -- src/winio.c | 9 +++++---- 7 files changed, 30 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9a87febd..63743ae3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -100,6 +100,14 @@ CVS code - inpar(), backup_lines(), find_paragraph(), do_justify(), do_justify_void(), do_full_justify(), and do_word_count() (all moved to text.c). (DLR) + - Since the total number of lines in a file is the same as the + number of its last line when all its lines are numbered + properly, use that in place of openfile->totlines, and + eliminate references to openfile->totlines. Changes to + initialize_buffer_text(), read_file(), move_to_filestruct(), + copy_from_filestruct(), do_delete(), do_enter(), do_wrap(), + do_justify(), do_alt_speller(), do_wordlinechar_count(), + new_magicline(), remove_magicline(), and do_cursorpos(). (DLR) - color.c: - Remove unneeded string.h and fcntl.h includes. (DLR) - chars.c: diff --git a/src/files.c b/src/files.c index 51c3251c..949b121c 100644 --- a/src/files.c +++ b/src/files.c @@ -97,7 +97,6 @@ void initialize_buffer_text(void) openfile->edittop = openfile->fileage; openfile->current = openfile->fileage; - openfile->totlines = 1; openfile->totsize = 0; } @@ -488,8 +487,6 @@ void read_file(FILE *f, const char *filename) #endif statusbar(P_("Read %lu line", "Read %lu lines", (unsigned long)num_lines), (unsigned long)num_lines); - - openfile->totlines += num_lines; } /* Open the file (and decide if it exists). If newfie is TRUE, display diff --git a/src/nano.c b/src/nano.c index 376aa0e4..7b0e28e4 100644 --- a/src/nano.c +++ b/src/nano.c @@ -382,9 +382,6 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot, if (openfile->filebot->data[0] != '\0') new_magicline(); - - /* Set totlines to the new number of lines in the file. */ - openfile->totlines = openfile->filebot->lineno; } /* Copy all the text from the filestruct beginning with file_top and @@ -443,9 +440,6 @@ void copy_from_filestruct(filestruct *file_top, filestruct *file_bot) if (openfile->filebot->data[0] != '\0') new_magicline(); - - /* Set totlines to the new number of lines in the file. */ - openfile->totlines = openfile->filebot->lineno; } /* Create a new openfilestruct node. */ diff --git a/src/nano.h b/src/nano.h index bc0ad56c..e250b3dc 100644 --- a/src/nano.h +++ b/src/nano.h @@ -215,9 +215,8 @@ typedef struct openfilestruct { filestruct *filebot; /* Current file's last line. */ filestruct *edittop; /* Current top of edit window. */ filestruct *current; /* Current file's line. */ - size_t totlines; /* Current file's total number of - * lines. */ - size_t totsize; /* Current file's total size. */ + size_t totsize; /* Current file's total number of + * characters. */ size_t current_x; /* Current file's x-coordinate * position. */ size_t placewewant; /* Current file's place we want. */ diff --git a/src/text.c b/src/text.c index f5f128f9..0edca63f 100644 --- a/src/text.c +++ b/src/text.c @@ -127,7 +127,6 @@ void do_delete(void) unlink_node(foo); delete_node(foo); renumber(openfile->current); - openfile->totlines--; openfile->totsize--; #ifndef DISABLE_WRAPPING wrap_reset(); @@ -237,7 +236,6 @@ void do_enter(void) edit_refresh(); - openfile->totlines++; openfile->totsize++; set_modified(); openfile->placewewant = xplustabs(); @@ -505,7 +503,6 @@ bool do_wrap(filestruct *line) openfile->current->next->data = new_line; - openfile->totlines++; openfile->totsize++; } @@ -1094,8 +1091,8 @@ void do_justify(bool full_justify) /* Will be the line containing the newline after the last line * of the result. Also for restoring after unjustify. */ - /* We save these variables to be restored if the user unjustifies. - * Note that we don't need to save totlines. */ + /* We save these variables to be restored if the user + * unjustifies. */ size_t current_x_save = openfile->current_x; size_t pww_save = openfile->placewewant; ssize_t current_y_save = openfile->current_y; @@ -1258,7 +1255,6 @@ void do_justify(bool full_justify) i--; par_len--; - openfile->totlines--; openfile->totsize--; } @@ -1317,7 +1313,6 @@ void do_justify(bool full_justify) openfile->current->data + break_pos); par_len++; - openfile->totlines++; openfile->totsize += indent_len + 1; #ifndef NANO_SMALL @@ -1357,10 +1352,10 @@ void do_justify(bool full_justify) } /* We are now done justifying the paragraph or the file, so clean - * up. totlines, totsize, and current_y have been maintained above. - * Set last_par_line to the new end of the paragraph, update - * fileage, and renumber since edit_refresh() needs the line numbers - * to be right (but only do the last two if we actually justified + * up. totsize, and current_y have been maintained above. Set + * last_par_line to the new end of the paragraph, update 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 = openfile->current; if (first_par_line != NULL) { @@ -1425,7 +1420,6 @@ void do_justify(bool full_justify) /* Restore variables from before the justify. */ openfile->totsize = totsize_save; - openfile->totlines = openfile->filebot->lineno; #ifndef NANO_SMALL if (openfile->mark_set) { openfile->mark_begin = mark_begin_save; @@ -1969,12 +1963,10 @@ const char *do_alt_speller(char *tempfile_name) unpartition_filestruct(&filepart); /* Renumber starting with the beginning line of the old - * partition. Also set totlines to the new number of lines in - * the file, add the number of characters in the spell-checked - * marked text to the saved value of totsize, and then make that - * saved value the actual value. */ + * partition. Also add the number of characters in the + * spell-checked marked text to the saved value of totsize, and + * then make that saved value the actual value. */ renumber(top_save); - openfile->totlines = openfile->filebot->lineno; totsize_save += openfile->totsize; openfile->totsize = totsize_save; @@ -2049,7 +2041,8 @@ void do_spell(void) #ifndef NANO_SMALL void do_wordlinechar_count(void) { - size_t words = 0, lines = 0, chars = 0; + size_t words = 0, chars = 0; + ssize_t lines = 0; size_t current_x_save = openfile->current_x; size_t pww_save = openfile->placewewant; filestruct *current_save = openfile->current; @@ -2104,7 +2097,7 @@ void do_wordlinechar_count(void) unpartition_filestruct(&filepart); openfile->mark_set = TRUE; } else { - lines = openfile->totlines; + lines = openfile->filebot->lineno; chars = openfile->totsize; } @@ -2115,8 +2108,8 @@ void do_wordlinechar_count(void) /* Display the total word, line, and character counts on the * statusbar. */ - statusbar("%sWords: %lu Lines: %lu Chars: %lu", old_mark_set ? - _("(In Selection) ") : "", (unsigned long)words, - (unsigned long)lines, (unsigned long)chars); + statusbar("%sWords: %lu Lines: %ld Chars: %lu", old_mark_set ? + _("(In Selection) ") : "", (unsigned long)words, (long)lines, + (unsigned long)chars); } #endif /* !NANO_SMALL */ diff --git a/src/utils.c b/src/utils.c index 3313b532..ca8106b9 100644 --- a/src/utils.c +++ b/src/utils.c @@ -404,7 +404,6 @@ void new_magicline(void) openfile->filebot->next->next = NULL; openfile->filebot->next->lineno = openfile->filebot->lineno + 1; openfile->filebot = openfile->filebot->next; - openfile->totlines++; openfile->totsize++; } @@ -418,7 +417,6 @@ void remove_magicline(void) openfile->filebot = openfile->filebot->prev; free_filestruct(openfile->filebot->next); openfile->filebot->next = NULL; - openfile->totlines--; openfile->totsize--; } } diff --git a/src/winio.c b/src/winio.c index 0e54aaf1..6a130135 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3839,7 +3839,7 @@ void do_cursorpos(bool constant) size_t cur_lenpt = strlenpt(openfile->current->data) + 1; int linepct, colpct, charpct; - assert(openfile->current != NULL && openfile->fileage != NULL && openfile->totlines != 0); + assert(openfile->current != NULL && openfile->fileage != NULL); c = openfile->current->data[openfile->current_x]; f = openfile->current->next; @@ -3860,15 +3860,16 @@ void do_cursorpos(bool constant) /* Display the current cursor position on the statusbar, and set * disable_cursorpos to FALSE. */ - linepct = 100 * openfile->current->lineno / openfile->totlines; + linepct = 100 * openfile->current->lineno / + openfile->filebot->lineno; colpct = 100 * cur_xpt / cur_lenpt; charpct = (openfile->totsize == 0) ? 0 : 100 * i / openfile->totsize; statusbar( - _("line %ld/%lu (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"), + _("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"), (long)openfile->current->lineno, - (unsigned long)openfile->totlines, linepct, + (long)openfile->filebot->lineno, linepct, (unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct, (unsigned long)i, (unsigned long)openfile->totsize, charpct); -- 2.39.5