commit 33ec807cd164b58b7f72b10b39d9a764d4f0dfbb
parent c658ae635e32617d0be8ff8af850f7e074f4bdc0
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Sat, 11 Apr 2026 19:15:30 +0200
cc1: Translate mb in wide strings
C17 mandates to do this translation, and even when it was not
mandated it was a good idea that meakes wide char more usable.
Diffstat:
3 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/src/cmd/scc-cc/cc1/lex.c b/src/cmd/scc-cc/cc1/lex.c
@@ -712,7 +712,7 @@ decode(int multi)
static int
character(void)
{
- int i, multi = 0;
+ int i, multi = NOMULTICHAR;
Rune r;
Type *tp;
Symbol *sym;
@@ -721,7 +721,7 @@ character(void)
tp = chartype;
if (*input->p == 'L') {
- multi = 1;
+ multi = MULTICHAR;
input->p++;
tp = wchartype;
}
@@ -766,17 +766,14 @@ rstring(void)
Rune c, buff[STRINGSIZ+1], *bp = buff;
for (++input->p; ; ++input->p) {
- c = *(unsigned char *) input->p;
-
- switch (c) {
+ switch (*input->p) {
case '\0':
errorp("missing terminating '\"' character");
case '"':
goto end_loop;
- case '\\':
- c = escape(MULTICHAR);
}
+ c = decode(MULTICHAR);
if (input->p - beg == STRINGSIZ + 1) {
/* too long, ignore everything until next quote */
for (++input->p; *input->p != '"'; ++input->p) {
@@ -810,17 +807,14 @@ sstring(void)
char buff[STRINGSIZ+1], *bp = buff, *beg = input->p;
for (++input->p; ; ++input->p) {
- c = *input->p;
-
- switch (c) {
+ switch (*input->p) {
case '\0':
errorp("missing terminating '\"' character");
case '"':
goto end_loop;
- case '\\':
- c = escape(NOMULTICHAR);
}
+ c = decode(NOMULTICHAR);
if (input->p - beg == STRINGSIZ + 1) {
/* too long, ignore everything until next quote */
for (++input->p; *input->p != '"'; ++input->p) {
diff --git a/tests/cc/execute/0267-wchar.c b/tests/cc/execute/0267-wchar.c
@@ -0,0 +1,15 @@
+#include <wchar.h>
+
+int
+main()
+{
+ wchar_t ws[] = L"aáb";
+
+ if (ws[0] != 'a')
+ return 1;
+ if (ws[1] != L'\u00e1')
+ return 2;
+ if (ws[2] != 'b')
+ return 3;
+ return 0;
+}
diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst
@@ -257,3 +257,4 @@
0264-wchar.c
0265-wchar.c
0266-wchar.c
+0267-wchar.c