From 4b52fc6eea9a478cb3dd42dcd32c92838df39734 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 8 Jan 2018 13:46:17 -0800 Subject: [PATCH] altos/scheme: Allow unicode in lexer This just passes any bytes with the high bit set through the system so programs can include UTF-8 in strings and symbols. What the heck. Signed-off-by: Keith Packard --- src/scheme/ao_scheme_read.c | 5 +++-- src/scheme/ao_scheme_string.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/scheme/ao_scheme_read.c b/src/scheme/ao_scheme_read.c index f9630d39..3575ff3f 100644 --- a/src/scheme/ao_scheme_read.c +++ b/src/scheme/ao_scheme_read.c @@ -186,8 +186,9 @@ lexc(FILE *in) c = 0; lex_class = ENDOFFILE; } else { - c &= 0x7f; - lex_class = lex_classes[c]; + lex_class = PRINTABLE; + if (c <= 0x7f) + lex_class = lex_classes[c]; } } while (lex_class & IGNORE); return c; diff --git a/src/scheme/ao_scheme_string.c b/src/scheme/ao_scheme_string.c index c49e1e32..2c6d0960 100644 --- a/src/scheme/ao_scheme_string.c +++ b/src/scheme/ao_scheme_string.c @@ -47,6 +47,8 @@ ao_scheme_string_alloc(int len) { struct ao_scheme_string *s; + if (len < 0) + return NULL; s = ao_scheme_alloc(len + 2); if (!s) return NULL; @@ -182,8 +184,8 @@ ao_scheme_string_write(FILE *out, ao_poly p, bool write) fputs("\\\\", out); break; default: - if (c < ' ') - fprintf(out, "\\%03o", c); + if ((uint8_t) c < ' ') + fprintf(out, "\\%03o", (uint8_t) c); else putc(c, out); break; -- 2.30.2