fix get_totals() so it properly handles NULL parameters, and restore

totlines after marked spell-check the way the justify routine does
instead of saving it and readding it later


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2118 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-11-22 16:04:18 +00:00
parent 74d87073f0
commit 3f35864b10
2 changed files with 25 additions and 25 deletions

View File

@ -1885,9 +1885,6 @@ const char *do_alt_speller(char *tempfile_name)
* the alternate spell command. The line that mark_beginbuf * the alternate spell command. The line that mark_beginbuf
* points to will be freed, so we save the line number and * points to will be freed, so we save the line number and
* restore afterwards. */ * restore afterwards. */
int old_totlines = totlines;
/* Our saved value of totlines, used when we spell-check a
* marked selection. */
long old_totsize = totsize; long old_totsize = totsize;
/* Our saved value of totsize, used when we spell-check a marked /* Our saved value of totsize, used when we spell-check a marked
* selection. */ * selection. */
@ -1949,7 +1946,6 @@ const char *do_alt_speller(char *tempfile_name)
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (old_mark_set) { if (old_mark_set) {
int part_totlines;
long part_totsize; long part_totsize;
/* If the mark was on, partition the filestruct so that it /* If the mark was on, partition the filestruct so that it
@ -1961,11 +1957,10 @@ const char *do_alt_speller(char *tempfile_name)
filepart = partition_filestruct(top, top_x, bot, bot_x); filepart = partition_filestruct(top, top_x, bot, bot_x);
added_magicline = (filebot->data[0] != '\0'); added_magicline = (filebot->data[0] != '\0');
/* Get the number of lines and the number of characters in the /* Get the number of characters in the marked text, and subtract
* marked text, and subtract them from the saved values of * it from the saved value of totsize. Note that we don't need
* totlines and totsize. */ * to save totlines. */
get_totals(top, bot, &part_totlines, &part_totsize); get_totals(top, bot, NULL, &part_totsize);
old_totlines -= part_totlines;
old_totsize -= part_totsize; old_totsize -= part_totsize;
} }
#endif #endif
@ -2009,14 +2004,13 @@ const char *do_alt_speller(char *tempfile_name)
unpartition_filestruct(&filepart); unpartition_filestruct(&filepart);
/* Renumber starting with the beginning line of the old /* Renumber starting with the beginning line of the old
* partition. Also add the number of lines and characters in * partition. Also set totlines to the new number of lines in
* the spell-checked marked text to the saved values of totlines * the file, add the number of characters in the spell-checked
* and totsize, and then make those saved values the actual * marked text to the saved value of totsize, and then make that
* values. */ * saved value the actual value. */
renumber(top_save); renumber(top_save);
old_totlines += totlines; totlines = filebot->lineno;
old_totsize += totsize; old_totsize += totsize;
totlines = old_totlines;
totsize = old_totsize; totsize = old_totsize;
/* Assign mark_beginbuf to the line where the mark began /* Assign mark_beginbuf to the line where the mark began

View File

@ -471,22 +471,27 @@ void get_totals(const filestruct *begin, const filestruct *end, int
/* Go through the lines from begin to end->prev, if we can. */ /* Go through the lines from begin to end->prev, if we can. */
for (f = begin; f != NULL && f != end; f = f->next) { for (f = begin; f != NULL && f != end; f = f->next) {
/* Count this line. */ /* Count this line. */
if (lines != NULL)
(*lines)++; (*lines)++;
/* Count the number of characters on this line. */ /* Count the number of characters on this line. */
if (size != NULL) {
*size += strlen(f->data); *size += strlen(f->data);
/* Count the newline if we have one. */ /* Count the newline if we have one. */
if (f->next != NULL) if (f->next != NULL)
(*size)++; (*size)++;
} }
}
/* Go through the line at end, if we can. */ /* Go through the line at end, if we can. */
if (f != NULL) { if (f != NULL) {
/* Count this line. */ /* Count this line. */
if (lines != NULL)
(*lines)++; (*lines)++;
/* Count the number of characters on this line. */ /* Count the number of characters on this line. */
if (size != NULL) {
*size += strlen(f->data); *size += strlen(f->data);
/* Count the newline if we have one. */ /* Count the newline if we have one. */
@ -494,6 +499,7 @@ void get_totals(const filestruct *begin, const filestruct *end, int
(*size)++; (*size)++;
} }
} }
}
/* Set top_x and bot_x to the top and bottom x-coordinates of the mark, /* Set top_x and bot_x to the top and bottom x-coordinates of the mark,
* respectively, based on the locations of top and bot. If * respectively, based on the locations of top and bot. If