screen: show an embedded newline in filenames as ^J instead of ^@

The byte 0x0A means 0x00 *only* when it is found in nano's internal
representation of a file's data, not when it occurs in a file name.

This fixes the second part of https://savannah.gnu.org/bugs/?49867.
master
Benno Schulenberg 2016-12-18 09:40:09 +01:00
parent dfff78dffe
commit eafae5d417
3 changed files with 15 additions and 19 deletions

View File

@ -225,10 +225,7 @@ bool is_word_mbchar(const char *c, bool allow_punct)
/* Return the visible representation of control character c. */ /* Return the visible representation of control character c. */
char control_rep(const signed char c) char control_rep(const signed char c)
{ {
/* An embedded newline is an encoded null. */ if (c == DEL_CODE)
if (c == '\n')
return '@';
else if (c == DEL_CODE)
return '?'; return '?';
else if (c == -97) else if (c == -97)
return '='; return '=';
@ -239,8 +236,12 @@ char control_rep(const signed char c)
} }
/* Return the visible representation of multibyte control character c. */ /* Return the visible representation of multibyte control character c. */
char control_mbrep(const char *c) char control_mbrep(const char *c, bool isdata)
{ {
/* An embedded newline is an encoded null *if* it is data. */
if (*c == '\n' && isdata)
return '@';
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8
if (use_utf8) { if (use_utf8) {
if ((unsigned char)c[0] < 128) if ((unsigned char)c[0] < 128)

View File

@ -207,7 +207,7 @@ bool is_cntrl_mbchar(const char *c);
bool is_punct_mbchar(const char *c); bool is_punct_mbchar(const char *c);
bool is_word_mbchar(const char *c, bool allow_punct); bool is_word_mbchar(const char *c, bool allow_punct);
char control_rep(const signed char c); char control_rep(const signed char c);
char control_mbrep(const char *c); char control_mbrep(const char *c, bool isdata);
int length_of_char(const char *c, int *width); int length_of_char(const char *c, int *width);
int mbwidth(const char *c); int mbwidth(const char *c);
int mb_cur_max(void); int mb_cur_max(void);

View File

@ -1803,11 +1803,11 @@ void check_statusblank(void)
* caller wants to display buf starting with column start_col, and * caller wants to display buf starting with column start_col, and
* extending for at most span columns. start_col is zero-based. span * extending for at most span columns. start_col is zero-based. span
* is one-based, so span == 0 means you get "" returned. The returned * is one-based, so span == 0 means you get "" returned. The returned
* string is dynamically allocated, and should be freed. If dollars is * string is dynamically allocated, and should be freed. If isdata is
* TRUE, the caller might put "$" at the beginning or end of the line if * TRUE, the caller might put "$" 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 start_col, size_t span, char *display_string(const char *buf, size_t start_col, size_t span,
bool dollars) 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. */
@ -1818,9 +1818,8 @@ char *display_string(const char *buf, size_t start_col, size_t span,
size_t index; size_t index;
/* Current position in converted. */ /* Current position in converted. */
/* If dollars is TRUE, make room for the "$" at the end of the /* If this is data, make room for the "$" at the end of the line. */
* line. */ if (isdata && !ISSET(SOFTWRAP) && strlenpt(buf) > start_col + span)
if (dollars && span > 0 && strlenpt(buf) > start_col + span)
span--; span--;
if (span == 0) if (span == 0)
@ -1841,12 +1840,12 @@ char *display_string(const char *buf, size_t start_col, size_t span,
buf += start_index; buf += start_index;
if (*buf != '\0' && *buf != '\t' && if (*buf != '\0' && *buf != '\t' &&
(column < start_col || (dollars && column > 0))) { (column < start_col || (isdata && column > 0))) {
/* We don't display the complete first character as it starts to /* We don't display the complete first character as it starts to
* the left of the screen. */ * the left of the screen. */
if (is_cntrl_mbchar(buf)) { if (is_cntrl_mbchar(buf)) {
if (column < start_col) { if (column < start_col) {
converted[index++] = control_mbrep(buf); converted[index++] = control_mbrep(buf, isdata);
start_col++; start_col++;
buf += parse_mbchar(buf, NULL, NULL); buf += parse_mbchar(buf, NULL, NULL);
} }
@ -1909,7 +1908,7 @@ char *display_string(const char *buf, size_t start_col, size_t span,
/* If buf contains a control character, represent it. */ /* If buf contains a control character, represent it. */
if (is_cntrl_mbchar(buf)) { if (is_cntrl_mbchar(buf)) {
converted[index++] = '^'; converted[index++] = '^';
converted[index++] = control_mbrep(buf); converted[index++] = control_mbrep(buf, isdata);
start_col += 2; start_col += 2;
buf += charlength; buf += charlength;
continue; continue;
@ -2743,15 +2742,11 @@ int update_line(filestruct *fileptr, size_t index)
/* Expand the line, replacing tabs with spaces, and control /* Expand the line, replacing tabs with spaces, and control
* characters with their displayed forms. */ * characters with their displayed forms. */
#ifdef NANO_TINY
converted = display_string(fileptr->data, page_start, editwincols, TRUE); converted = display_string(fileptr->data, page_start, editwincols, TRUE);
#else
converted = display_string(fileptr->data, page_start, editwincols, !ISSET(SOFTWRAP));
#ifdef DEBUG #ifdef DEBUG
if (ISSET(SOFTWRAP) && strlen(converted) >= editwincols - 2) if (ISSET(SOFTWRAP) && strlen(converted) >= editwincols - 2)
fprintf(stderr, "update_line(): converted(1) line = %s\n", converted); fprintf(stderr, "update_line(): converted(1) line = %s\n", converted);
#endif #endif
#endif /* !NANO_TINY */
/* Paint the line. */ /* Paint the line. */
edit_draw(fileptr, converted, line, page_start); edit_draw(fileptr, converted, line, page_start);
@ -2776,7 +2771,7 @@ int update_line(filestruct *fileptr, size_t index)
/* Expand the line, replacing tabs with spaces, and control /* Expand the line, replacing tabs with spaces, and control
* characters with their displayed forms. */ * characters with their displayed forms. */
converted = display_string(fileptr->data, index, editwincols, !ISSET(SOFTWRAP)); converted = display_string(fileptr->data, index, editwincols, TRUE);
#ifdef DEBUG #ifdef DEBUG
if (ISSET(SOFTWRAP) && strlen(converted) >= editwincols - 2) if (ISSET(SOFTWRAP) && strlen(converted) >= editwincols - 2)
fprintf(stderr, "update_line(): converted(2) line = %s\n", converted); fprintf(stderr, "update_line(): converted(2) line = %s\n", converted);