From 2b9d6a0e6c7b090d9bda9e959298039156e0aac9 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 1 Nov 2005 17:45:31 +0000 Subject: [PATCH] move get_page_start() from winio.c to utils.c too, and fix a few comments git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3066 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++-- src/proto.h | 2 +- src/utils.c | 20 +++++++++++++++++--- src/winio.c | 18 ++---------------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index afb744a1..08aa4aeb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,8 +15,9 @@ CVS code - that make use of a smaller number. Changes to window_init(), nanoget_repaint(), titlebar(), statusbar(), and get_page_start(). (DLR) - - Move xplustabs(), actual_x(), strnlenpt(), and strlenpt() from - winio.c to utils.c, as they're really utility functions. (DLR) + - Move get_page_start(), xplustabs(), actual_x(), strnlenpt(), + and strlenpt() from winio.c to utils.c, as they're really + utility functions. (DLR) - Move functions specific to the statusbar prompt to their own source file, and adjust related variables accordingly. New file prompt.c; changes to do_statusbar_input(), diff --git a/src/proto.h b/src/proto.h index 3ca6f77a..5322f3a7 100644 --- a/src/proto.h +++ b/src/proto.h @@ -604,6 +604,7 @@ void *nrealloc(void *ptr, size_t howmuch); char *mallocstrncpy(char *dest, const char *src, size_t n); char *mallocstrcpy(char *dest, const char *src); char *mallocstrassn(char *dest, char *src); +size_t get_page_start(size_t column); size_t xplustabs(void); size_t actual_x(const char *s, size_t column); size_t strnlenpt(const char *s, size_t maxlen); @@ -670,7 +671,6 @@ void set_modified(void); void statusbar(const char *msg, ...); void bottombars(const shortcut *s); void onekey(const char *keystroke, const char *desc, size_t len); -size_t get_page_start(size_t column); void reset_cursor(void); void edit_draw(const filestruct *fileptr, const char *converted, int line, size_t start); diff --git a/src/utils.c b/src/utils.c index ff97788b..169a908e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -395,6 +395,20 @@ char *mallocstrassn(char *dest, char *src) return src; } +/* nano scrolls horizontally within a line in chunks. Return the column + * number of the first character displayed in the edit 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) +{ + if (column == 0 || column < COLS - 1) + return 0; + else if (COLS > 9) + return column - 7 - (column - 7) % (COLS - 8); + else + return column - (COLS - 2); +} + /* Return the placewewant associated with current_x, i.e, the zero-based * column position of the cursor. The value will be no smaller than * current_x. */ @@ -403,9 +417,9 @@ size_t xplustabs(void) return strnlenpt(openfile->current->data, openfile->current_x); } -/* actual_x() gives the index in s of the character displayed at the - * given column. That is, actual_x() is the largest value such that - * strnlenpt(s, actual_x(s, column)) <= column. */ +/* Return the index in s of the character displayed at the given column, + * i.e, the largest value such that strnlenpt(s, actual_x(s, column)) <= + * column. */ size_t actual_x(const char *s, size_t column) { size_t i = 0; diff --git a/src/winio.c b/src/winio.c index 91abf7b6..b763b86d 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2185,22 +2185,8 @@ void onekey(const char *keystroke, const char *desc, size_t len) } } -/* nano scrolls horizontally within a line in chunks. This function - * returns the column number of the first character displayed in the - * edit 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) -{ - if (column == 0 || column < COLS - 1) - return 0; - else if (COLS > 9) - return column - 7 - (column - 7) % (COLS - 8); - else - return column - (COLS - 2); -} - -/* Resets current_y, based on the position of current, and puts the - * cursor in the edit window at (current_y, current_x). */ +/* Reset current_y, based on the position of current, and put the cursor + * in the edit window at (current_y, current_x). */ void reset_cursor(void) { /* If we haven't opened any files yet, put the cursor in the top -- 2.39.5