[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH 2/5] chars: the representation of a control characte
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH 2/5] chars: the representation of a control character is always two bytes |
Date: |
Sun, 5 Jun 2016 09:46:18 +0200 |
Any control character is represented by a ^ plus an ASCII character.
---
src/chars.c | 19 ++++++-------------
src/proto.h | 2 +-
src/winio.c | 31 +++++--------------------------
3 files changed, 12 insertions(+), 40 deletions(-)
diff --git a/src/chars.c b/src/chars.c
index d59c73c..048c816 100644
--- a/src/chars.c
+++ b/src/chars.c
@@ -253,27 +253,20 @@ wchar_t control_wrep(wchar_t wc)
}
#endif
-/* c is a multibyte control character. It displays as ^@, ^?, or ^[ch],
- * where ch is (c + 64). We return that single-byte character. */
-char *control_mbrep(const char *c, char *crep, int *crep_len)
+/* Return the visible representation of multibyte control character c. */
+char control_mbrep(const char *c)
{
- assert(c != NULL && crep != NULL && crep_len != NULL);
+ assert(c != NULL);
#ifdef ENABLE_UTF8
if (use_utf8) {
if (0 <= c[0] && c[0] <= 127)
- *crep = control_rep(c[0]);
+ return control_rep(c[0]);
else
- *crep = control_rep(c[1]);
- *crep_len = 1;
+ return control_rep(c[1]);
} else
#endif
- {
- *crep_len = 1;
- *crep = control_rep(*c);
- }
-
- return crep;
+ return control_rep(*c);
}
/* c is a multibyte non-control character. We return that multibyte
diff --git a/src/proto.h b/src/proto.h
index cf2b4ad..0b34e6a 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -193,7 +193,7 @@ char control_rep(char c);
#ifdef ENABLE_UTF8
wchar_t control_wrep(wchar_t wc);
#endif
-char *control_mbrep(const char *c, char *crep, int *crep_len);
+char control_mbrep(const char *c);
char *mbrep(const char *c, char *crep, int *crep_len);
int mbwidth(const char *c);
int mb_cur_max(void);
diff --git a/src/winio.c b/src/winio.c
index 5a6892d..f5078db 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1792,18 +1792,8 @@ char *display_string(const char *buf, size_t start_col,
size_t len, bool
if (is_cntrl_mbchar(buf_mb)) {
if (column < start_col) {
- char *character = charalloc(mb_cur_max());
- int charlen, i;
-
- character = control_mbrep(buf_mb, character, &charlen);
-
- for (i = 0; i < charlen; i++)
- converted[index++] = character[i];
-
- start_col += mbwidth(character);
-
- free(character);
-
+ converted[index++] = control_mbrep(buf_mb);
+ start_col++;
start_index += buf_mb_len;
}
}
@@ -1865,22 +1855,11 @@ char *display_string(const char *buf, size_t start_col,
size_t len, bool
converted[index++] = ' ';
start_col++;
}
- /* If buf contains a control character, interpret it. */
+ /* If buf contains a control character, represent it. */
} else if (is_cntrl_mbchar(buf_mb)) {
- char *character = charalloc(mb_cur_max());
- int charlen, i;
-
converted[index++] = '^';
- start_col++;
-
- character = control_mbrep(buf_mb, character, &charlen);
-
- for (i = 0; i < charlen; i++)
- converted[index++] = character[i];
-
- start_col += mbwidth(character);
-
- free(character);
+ converted[index++] = control_mbrep(buf_mb);
+ start_col += 2;
/* If buf contains a non-control character, interpret it. If buf
* contains an invalid multibyte sequence, display it as such. */
} else {
--
2.8.1