instead of several; and do some other minor refactoring of
related display functions to simplify them. New functions
mark_order() and display_string(); changes to actual_x(),
- strnlenpt(), blank_bottombars(), edit_add(), update_line(),
- statusbar(), and do_replace_highlight(). (David Benbennick)
- DLR: Add minor cosmetic tweaks, add missing NANO_SMALL #ifdef
- around the text for a backwards search in the refactored code,
- and enclose dump_buffer() and dump_buffer_reverse() in one
- ENABLE_DEBUG #ifdef instead of two.
+ strnlenpt(), blank_bottombars(), blank_edit(),
+ get_page_start(), edit_add(), update_line(), statusbar(), and
+ do_replace_highlight(). (David Benbennick) DLR: Add minor
+ cosmetic tweaks, add missing NANO_SMALL #ifdef around the text
+ for a backwards search in the refactored code, and enclose
+ dump_buffer() and dump_buffer_reverse() in one ENABLE_DEBUG
+ #ifdef instead of two.
- Convert memmove() function calls to charmove() macro calls, as
the former all work on char*'s. (DLR)
- files.c:
#ifndef NDEBUG
int check_linenumbers(const filestruct *fileptr);
#endif
-int get_page_start(int column);
+size_t get_page_start(size_t column);
void reset_cursor(void);
void add_marked_sameline(int begin, int end, filestruct *fileptr, int y,
int virt_cur_x, int this_page);
void blank_edit(void)
{
int i;
- for (i = 0; i <= editwinrows - 1; i++)
+ for (i = 0; i < editwinrows; i++)
mvwaddstr(edit, i, 0, hblank);
}
}
#endif
- /* nano scrolls horizontally within a line in chunks. This function
- * returns the column number of the first character displayed in the
- * window when the cursor is at the given column. */
-int get_page_start(int column)
+/* nano scrolls horizontally within a line in chunks. This function
+ * returns the column number of the first character displayed in the
+ * window when the cursor is at the given column. Note that
+ * 0 <= column - get_page_start(column) < COLS. */
+size_t get_page_start(size_t column)
{
- assert(COLS > 9);
- return column < COLS - 1 ? 0 : column - 7 - (column - 8) % (COLS - 9);
+ assert(COLS > 0);
+ if (column == 0 || column < COLS - 1)
+ return 0;
+ else if (COLS > 9)
+ return column - 7 - (column - 8) % (COLS - 9);
+ else if (COLS > 2)
+ return column - (COLS - 2);
+ else
+ return column - (COLS - 1);
+ /* The parentheses are necessary to avoid overflow. */
}
/* Resets current_y, based on the position of current, and puts the
/* 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 == current) ? strnlenpt(fileptr->data, index) : 0;
page_start = get_page_start(index);
/* Expand the line, replacing Tab by spaces, and control characters