tweaks: swap the names of two variables, to make more sense

An iterator should not be called "start_col", because it is only the
starting column at the very beginning.

Also, start_col (after the rename) can never be /larger/ than column.
master
Benno Schulenberg 2017-04-28 14:05:07 +02:00
parent 03ecbf3d55
commit 1f55c8819b
2 changed files with 30 additions and 35 deletions

View File

@ -638,8 +638,7 @@ void blank_edit(void);
void blank_statusbar(void); void blank_statusbar(void);
void blank_bottombars(void); void blank_bottombars(void);
void check_statusblank(void); void check_statusblank(void);
char *display_string(const char *buf, size_t start_col, size_t span, char *display_string(const char *buf, size_t column, size_t span, bool isdata);
bool dollars);
void titlebar(const char *path); void titlebar(const char *path);
extern void set_modified(void); extern void set_modified(void);
void statusbar(const char *msg); void statusbar(const char *msg);

View File

@ -1805,31 +1805,29 @@ void check_statusblank(void)
edit_refresh(); edit_refresh();
} }
/* Convert buf into a string that can be displayed on screen. The /* Convert buf into a string that can be displayed on screen. The caller
* caller wants to display buf starting with column start_col, and * wants to display buf starting with the given column, and extending for
* extending for at most span columns. start_col is zero-based. span * at most span columns. column is zero-based, and span is one-based, so
* is one-based, so span == 0 means you get "" returned. The returned * span == 0 means you get "" returned. The returned string is dynamically
* string is dynamically allocated, and should be freed. If isdata is * allocated, and should be freed. If isdata is TRUE, the caller might put
* TRUE, the caller might put "$" at the beginning or end of the line if * "$" at the beginning or end of the line if it's too long. */
* it's too long. */ char *display_string(const char *buf, size_t column, size_t span, bool isdata)
char *display_string(const char *buf, size_t start_col, size_t span,
bool isdata)
{ {
size_t start_index; size_t start_index;
/* Index in buf of the first character shown. */ /* Index in buf of the first character shown. */
size_t column; size_t start_col;
/* Screen column that start_index corresponds to. */ /* Screen column that start_index corresponds to. */
char *converted; char *converted;
/* The string we return. */ /* The expanded string we will return. */
size_t index; size_t index;
/* Current position in converted. */ /* Current position in converted. */
size_t beyond = start_col + span; size_t beyond = column + span;
/* The column number just beyond the last shown character. */ /* The column number just beyond the last shown character. */
start_index = actual_x(buf, start_col); start_index = actual_x(buf, column);
column = strnlenpt(buf, start_index); start_col = strnlenpt(buf, start_index);
assert(column <= start_col); assert(start_col <= column);
index = 0; index = 0;
#ifdef USING_OLD_NCURSES #ifdef USING_OLD_NCURSES
@ -1842,32 +1840,31 @@ char *display_string(const char *buf, size_t start_col, size_t span,
/* If the first character starts before the left edge, or would be /* If the first character starts before the left edge, or would be
* overwritten by a "$" token, then show placeholders instead. */ * overwritten by a "$" token, then show placeholders instead. */
if (*buf != '\0' && *buf != '\t' && (column < start_col || if (*buf != '\0' && *buf != '\t' && (start_col < column ||
(column > 0 && isdata && !ISSET(SOFTWRAP)))) { (start_col > 0 && isdata && !ISSET(SOFTWRAP)))) {
if (is_cntrl_mbchar(buf)) { if (is_cntrl_mbchar(buf)) {
if (column < start_col) { if (start_col < column) {
converted[index++] = control_mbrep(buf, isdata); converted[index++] = control_mbrep(buf, isdata);
start_col++; column++;
buf += parse_mbchar(buf, NULL, NULL); buf += parse_mbchar(buf, NULL, NULL);
} }
} }
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8
else if (mbwidth(buf) == 2) { else if (mbwidth(buf) == 2) {
if (column >= start_col) { if (start_col == column) {
converted[index++] = ' '; converted[index++] = ' ';
start_col++; column++;
} }
/* Display the right half of a two-column character as '<'. */ /* Display the right half of a two-column character as '<'. */
converted[index++] = '<'; converted[index++] = '<';
start_col++; column++;
buf += parse_mbchar(buf, NULL, NULL); buf += parse_mbchar(buf, NULL, NULL);
} }
#endif #endif
} }
while (*buf != '\0' && start_col < beyond) { while (*buf != '\0' && column < beyond) {
int charlength, charwidth = 1; int charlength, charwidth = 1;
if (*buf == ' ') { if (*buf == ' ') {
@ -1881,7 +1878,7 @@ char *display_string(const char *buf, size_t start_col, size_t span,
} else } else
#endif #endif
converted[index++] = ' '; converted[index++] = ' ';
start_col++; column++;
buf++; buf++;
continue; continue;
} else if (*buf == '\t') { } else if (*buf == '\t') {
@ -1895,11 +1892,11 @@ char *display_string(const char *buf, size_t start_col, size_t span,
} else } else
#endif #endif
converted[index++] = ' '; converted[index++] = ' ';
start_col++; column++;
/* Fill the tab up with the required number of spaces. */ /* Fill the tab up with the required number of spaces. */
while (start_col % tabsize != 0) { while (column % tabsize != 0) {
converted[index++] = ' '; converted[index++] = ' ';
start_col++; column++;
} }
buf++; buf++;
continue; continue;
@ -1911,7 +1908,7 @@ char *display_string(const char *buf, size_t start_col, size_t span,
if (is_cntrl_mbchar(buf)) { if (is_cntrl_mbchar(buf)) {
converted[index++] = '^'; converted[index++] = '^';
converted[index++] = control_mbrep(buf, isdata); converted[index++] = control_mbrep(buf, isdata);
start_col += 2; column += 2;
buf += charlength; buf += charlength;
continue; continue;
} }
@ -1921,7 +1918,7 @@ char *display_string(const char *buf, size_t start_col, size_t span,
for (; charlength > 0; charlength--) for (; charlength > 0; charlength--)
converted[index++] = *(buf++); converted[index++] = *(buf++);
start_col += charwidth; column += charwidth;
#ifdef USING_OLD_NCURSES #ifdef USING_OLD_NCURSES
if (charwidth > 1) if (charwidth > 1)
seen_wide = TRUE; seen_wide = TRUE;
@ -1933,8 +1930,7 @@ char *display_string(const char *buf, size_t start_col, size_t span,
converted[index++] = '\xEF'; converted[index++] = '\xEF';
converted[index++] = '\xBF'; converted[index++] = '\xBF';
converted[index++] = '\xBD'; converted[index++] = '\xBD';
column++;
start_col += 1;
buf++; buf++;
/* For invalid codepoints, skip extra bytes. */ /* For invalid codepoints, skip extra bytes. */
@ -1943,7 +1939,7 @@ char *display_string(const char *buf, size_t start_col, size_t span,
} }
/* If there is more text than can be shown, make room for the $ or >. */ /* If there is more text than can be shown, make room for the $ or >. */
if (*buf != '\0' && (start_col > beyond || (isdata && !ISSET(SOFTWRAP)))) { if (*buf != '\0' && (column > beyond || (isdata && !ISSET(SOFTWRAP)))) {
index = move_mbleft(converted, index); index = move_mbleft(converted, index);
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8