shithub: riscv

Download patch

ref: ae2bb7f3eaea334bb28f4c388fdee9e370dd5a82
parent: 73862cb9cf6058273c3ce9c025bde55433306265
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Sep 25 21:21:54 EDT 2023

cpp: remove trigraphs

even WG14 dropped support for them.

--- a/sys/src/cmd/cpp/cpp.h
+++ b/sys/src/cmd/cpp/cpp.h
@@ -106,7 +106,6 @@
 void	dofree(void *);
 void	error(enum errtype, char *, ...);
 void	flushout(void);
-int	trigraph(Source *);
 int	foldline(Source *);
 Nlist	*lookup(Token *, int);
 void	control(Tokenrow *);
--- a/sys/src/cmd/cpp/lex.c
+++ b/sys/src/cmd/cpp/lex.c
@@ -272,7 +272,7 @@
 			}
 		}
 	}
-	/* install special cases for ? (trigraphs),  \ (splicing), runes */
+	/* install special cases for \ (splicing), runes */
 	for (i=0; i<MAXSTATE; i++) {
 		for (j=0; j<0xFF; j++)
 			if (j=='?' || j=='\\' || UTF2(j) || UTF3(j) || UTF4(j)) {
@@ -362,13 +362,6 @@
 				}
 				state &= ~QBSBIT;
 				s->inp = ip;
-				if (c=='?') { 	/* check trigraph */
-					if (trigraph(s)) {
-						state = oldstate;
-						continue;
-					}
-					goto reswitch;
-				}
 				if (c=='\\') { /* line-folding */
 					if (foldline(s)) {
 						s->lineinc++;
@@ -444,43 +437,6 @@
 		tp->len = ip - tp->t;
 		tp++;
 	}
-}
-
-/* have seen ?; handle the trigraph it starts (if any) else 0 */
-int
-trigraph(Source *s)
-{
-	int c;
-
-	if (s->inp[1]!='?')
-		return 0;
-	c = 0;
-	switch(s->inp[2]) {
-	case '=':
-		c = '#'; break;
-	case '(':
-		c = '['; break;
-	case '/':
-		c = '\\'; break;
-	case ')':
-		c = ']'; break;
-	case '\'':
-		c = '^'; break;
-	case '<':
-		c = '{'; break;
-	case '!':
-		c = '|'; break;
-	case '>':
-		c = '}'; break;
-	case '-':
-		c = '~'; break;
-	}
-	if (c) {
-		*s->inp = c;
-		memmove(s->inp+1, s->inp+3, s->inl-s->inp+2);
-		s->inl -= 2;
-	}
-	return c;
 }
 
 int