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)
- nano.h:
- Readd MIN_EDITOR_COLS #define. (DLR)
- winio.c:
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 xplustabs(void);
+size_t actual_x(const char *s, size_t column);
+size_t strnlenpt(const char *s, size_t maxlen);
+size_t strlenpt(const char *s);
void new_magicline(void);
#ifndef NANO_SMALL
void remove_magicline(void);
void do_statusbar_verbatim_input(bool *got_enter);
size_t statusbar_xplustabs(void);
size_t get_statusbar_page_start(size_t start_col, size_t column);
-size_t xplustabs(void);
-size_t actual_x(const char *str, size_t xplus);
-size_t strnlenpt(const char *buf, size_t size);
-size_t strlenpt(const char *buf);
void blank_line(WINDOW *win, int y, int x, int n);
void blank_titlebar(void);
void blank_topbar(void);
return src;
}
+/* 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. */
+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. */
+size_t actual_x(const char *s, size_t column)
+{
+ size_t i = 0;
+ /* The position in s, returned. */
+ size_t len = 0;
+ /* The screen display width to s[i]. */
+
+ assert(s != NULL);
+
+ while (*s != '\0') {
+ int s_len = parse_mbchar(s, NULL, &len);
+
+ if (len > column)
+ break;
+
+ i += s_len;
+ s += s_len;
+ }
+
+ return i;
+}
+
+/* A strnlen() with tabs and multicolumn characters factored in, similar
+ * to xplustabs(). How many columns wide are the first maxlen characters
+ * of s? */
+size_t strnlenpt(const char *s, size_t maxlen)
+{
+ size_t len = 0;
+ /* The screen display width to s[i]. */
+
+ if (maxlen == 0)
+ return 0;
+
+ assert(s != NULL);
+
+ while (*s != '\0') {
+ int s_len = parse_mbchar(s, NULL, &len);
+
+ s += s_len;
+
+ if (maxlen <= s_len)
+ break;
+
+ maxlen -= s_len;
+ }
+
+ return len;
+}
+
+/* A strlen() with tabs and multicolumn characters factored in, similar
+ * to xplustabs(). How many columns wide is s? */
+size_t strlenpt(const char *s)
+{
+ return strnlenpt(s, (size_t)-1);
+}
+
/* Append a new magicline to filebot. */
void new_magicline(void)
{
start_col - 1);
}
-/* 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. */
-size_t xplustabs(void)
-{
- return strnlenpt(openfile->current->data, openfile->current_x);
-}
-
-/* actual_x() gives the index in str of the character displayed at
- * column xplus. That is, actual_x() is the largest value such that
- * strnlenpt(str, actual_x(str, xplus)) <= xplus. */
-size_t actual_x(const char *str, size_t xplus)
-{
- size_t i = 0;
- /* The position in str, returned. */
- size_t length = 0;
- /* The screen display width to str[i]. */
-
- assert(str != NULL);
-
- while (*str != '\0') {
- int str_len = parse_mbchar(str, NULL, &length);
-
- if (length > xplus)
- break;
-
- i += str_len;
- str += str_len;
- }
-
- return i;
-}
-
-/* A strlen() with tabs factored in, similar to xplustabs(). How many
- * columns wide are the first size characters of str? */
-size_t strnlenpt(const char *str, size_t size)
-{
- size_t length = 0;
- /* The screen display width to str[i]. */
-
- if (size == 0)
- return 0;
-
- assert(str != NULL);
-
- while (*str != '\0') {
- int str_len = parse_mbchar(str, NULL, &length);
-
- str += str_len;
-
- if (size <= str_len)
- break;
-
- size -= str_len;
- }
-
- return length;
-}
-
-/* How many columns wide is buf? */
-size_t strlenpt(const char *buf)
-{
- return strnlenpt(buf, (size_t)-1);
-}
-
/* Move to (x, y) in win, and display a line of n spaces with the
* current attributes. */
void blank_line(WINDOW *win, int y, int x, int n)