From 9708e5fed9eb27329ca7cc95914c7b2f12e60c56 Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 11 Dec 2025 13:51:58 +0100 Subject: -trigraphs option --- c/lex.c | 6 +++--- main.c | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/c/lex.c b/c/lex.c index b00d282..6a043e7 100644 --- a/c/lex.c +++ b/c/lex.c @@ -85,7 +85,6 @@ ident: static void fillchrbuf(struct lexer *lx) { - bool trigraph = ccopt.trigraph; const uchar *p = lx->dat + lx->idx; int i = lx->chrbuf0, idx = lx->idx, c; int rem = arraylength(lx->chrbuf) - i; @@ -101,14 +100,15 @@ fillchrbuf(struct lexer *lx) for (; i < arraylength(lx->chrbuf); ++i) { int n; - while (!memcmp(p, "\\\n", n = 2) || (trigraph && !memcmp(p, "\?\?/\n", n = 4))) { + /* skip backslash-newline */ + while ((n = 2, (p[0] == '\\') & (p[1] == '\n')) || (ccopt.trigraph && !memcmp(p, "\?\?/\n", n = 4))) { idx += n; p += n; addfileline(lx->fileid, idx); } if (idx >= lx->ndat) { c = TKEOF; - } else if (trigraph && ((p[0] == '?') & (p[1] == '?'))) { + } else if (ccopt.trigraph && ((p[0] == '?') & (p[1] == '?'))) { switch (p[2]) { case '=': c = '#'; break; case '(': c = '['; break; diff --git a/main.c b/main.c index 3833d85..ec3052f 100644 --- a/main.c +++ b/main.c @@ -136,6 +136,8 @@ optparse(char **args) else goto Bad; } else if (!strcmp(arg, "pedantic")) { ccopt.pedant = 1; + } else if (!strcmp(arg, "trigraphs")) { + ccopt.trigraph = 1; } else if (*arg == 'd' && arg[1]) { /* see common.h§struct option */ while (*++arg) switch (*arg | 32) { -- cgit v1.2.3