xref: /netbsd-src/external/bsd/pcc/dist/pcc/cc/cpp/stuff/stdio2.diff (revision 411dcbec990c8aa9c57d3bd2f4bcacadec0b1ab5)
1Index: cpp.c
2===================================================================
3RCS file: /cvsroot/pcc/cc/cpp/cpp.c,v
4retrieving revision 1.201
5diff -u -p -r1.201 cpp.c
6--- cpp.c	28 Nov 2014 19:31:57 -0000	1.201
7+++ cpp.c	5 Dec 2014 10:39:09 -0000
8@@ -1264,7 +1264,7 @@ delwarn(void)
9 		} else if (c == EBLOCK) {
10 			sss();
11 		} else if (c == '\n') {
12-			fputc(cinput(), stdout);
13+			putch(cinput());
14 		} else
15 			savstr(yytext);
16 	}
17@@ -1392,7 +1392,7 @@ upp:		sbp = stringbuf;
18 	/* Found one, output \n to be in sync */
19 	for (; *sbp; sbp++) {
20 		if (*sbp == '\n')
21-			fputc('\n', stdout), ifiles->lineno++;
22+			putch('\n'), ifiles->lineno++;
23 	}
24
25 	/* fetch arguments */
26@@ -1545,7 +1545,7 @@ chkdir(void)
27 		while ((ch = cinput()) != '\n')
28 			;
29 		ifiles->lineno++;
30-		fputc('\n', stdout);
31+		putch('\n');
32 	}
33 }
34
35@@ -1580,7 +1580,7 @@ readargs(struct symtab *sp, const usch *
36 		while ((c = sloscan()) == WSPACE || c == '\n')
37 			if (c == '\n') {
38 				ifiles->lineno++;
39-				fputc(cinput(), stdout);
40+				putch(cinput());
41 				chkdir();
42 			}
43 		for (;;) {
44@@ -1601,7 +1601,7 @@ readargs(struct symtab *sp, const usch *
45 			savstr(yytext);
46 oho:			while ((c = sloscan()) == '\n') {
47 				ifiles->lineno++;
48-				fputc(cinput(), stdout);
49+				putch(cinput());
50 				chkdir();
51 				savch(' ');
52 			}
53@@ -1978,6 +1978,24 @@ unpstr(const usch *c)
54 	}
55 }
56
57+void
58+putch(int ch)
59+{
60+	if (Mflag == 0)
61+		fputc(ch, stdout);
62+}
63+
64+void
65+putstr(const usch *s)
66+{
67+	for (; *s; s++) {
68+		if (*s == PHOLD)
69+			continue;
70+		if (Mflag == 0)
71+			fputc(*s, stdout);
72+	}
73+}
74+
75 /*
76  * convert a number to an ascii string. Store it on the heap.
77  */
78Index: cpp.h
79===================================================================
80RCS file: /cvsroot/pcc/cc/cpp/cpp.h,v
81retrieving revision 1.73
82diff -u -p -r1.73 cpp.h
83--- cpp.h	28 Nov 2014 19:30:35 -0000	1.73
84+++ cpp.h	5 Dec 2014 10:39:10 -0000
85@@ -176,6 +176,8 @@ int yyparse(void);
86 void unpstr(const usch *);
87 usch *savstr(const usch *str);
88 void savch(int c);
89+void putch(int);
90+void putstr(const usch *s);
91 usch *sheap(const char *fmt, ...);
92 void warning(const char *fmt, ...);
93 void error(const char *fmt, ...);
94Index: token.c
95===================================================================
96RCS file: /cvsroot/pcc/cc/cpp/token.c,v
97retrieving revision 1.120
98diff -u -p -r1.120 token.c
99--- token.c	19 Oct 2014 17:40:36 -0000	1.120
100+++ token.c	5 Dec 2014 10:39:14 -0000
101@@ -65,7 +65,7 @@ static void undefstmt(void);
102 static void pragmastmt(void);
103 static void elifstmt(void);
104
105-#define	PUTCH(ch) if (!flslvl) fputc(ch, stdout)
106+#define	PUTCH(ch) if (!flslvl) putch(ch)
107 /* protection against recursion in #include */
108 #define MAX_INCLEVEL	100
109 static int inclevel;
110@@ -312,7 +312,7 @@ eatcmnt(void)
111 		ch = inch();
112 		if (ch == '\n') {
113 			ifiles->lineno++;
114-			fputc('\n', stdout);
115+			putch('\n');
116 			continue;
117 		}
118 		if (ch == -1)
119@@ -374,10 +374,10 @@ xloop:		if (ch == -1)
120 		case '/': /* Comments */
121 			if ((ch = inch()) == '/') {
122 				if (!flslvl) {
123-cppcmt:					fputc(Cflag ? ch : ' ', stdout);
124+cppcmt:					putch(Cflag ? ch : ' ');
125 				}
126 				do {
127-					if (Cflag && !flslvl) fputc(ch, stdout);
128+					if (Cflag && !flslvl) putch(ch);
129 					ch = inch();
130 					if (ch == -1)
131 						goto eof;
132@@ -387,7 +387,7 @@ cppcmt:					fputc(Cflag ? ch : ' ', stdo
133 				if (eatcmnt() == -1)
134 					goto eof;
135 			} else {
136-				if (!flslvl) fputc('/', stdout);
137+				PUTCH('/');
138 				goto xloop;
139 			}
140 			break;
141@@ -397,7 +397,7 @@ cppcmt:					fputc(Cflag ? ch : ' ', stdo
142 			ifiles->lineno += i;
143 			ifiles->escln = 0;
144 			while (i-- > 0)
145-				fputc('\n', stdout);
146+				putch('\n');
147 run:			for(;;) {
148 				ch = inch();
149 				if (ch == '/') {
150@@ -414,7 +414,7 @@ run:			for(;;) {
151 				}
152 				if (ch != ' ' && ch != '\t')
153 					break;
154-				if (!flslvl) fputc(ch, stdout);
155+				PUTCH(ch);
156 			}
157 			if (ch == '#') {
158 				ppdir();
159@@ -539,9 +539,9 @@ con:			PUTCH(ch);
160 			if (flslvl == 0) {
161 				cp = stringbuf;
162 				if ((nl = lookup(yytext, FIND)) && kfind(nl))
163-					printf("%s", stringbuf);
164+					putstr(stringbuf);
165 				else
166-					printf("%s", (char *)yytext);
167+					putstr((usch *)yytext);
168 				stringbuf = cp;
169 			}
170 			if (ch == -1)
171@@ -561,7 +561,7 @@ con:			PUTCH(ch);
172 	}
173
174 eof:	warning("unexpected EOF");
175-	fputc('\n', stdout);
176+	putch('\n');
177 }
178
179 int
180@@ -669,7 +669,7 @@ chlit:
181 				if (c == -1)
182 					return 0;
183 				if (c == '\n')
184-					fputc(c, stdout), ifiles->lineno++;
185+					putch(c), ifiles->lineno++;
186 				else if (c == EBLOCK) {
187 					(void)inch();
188 					(void)inch();
189@@ -1006,6 +1006,8 @@ pushfile(const usch *file, const usch *f
190 void
191 prtline(void)
192 {
193+	usch *sb = stringbuf;
194+
195 	if (Mflag) {
196 		if (dMflag)
197 			return; /* no output */
198@@ -1017,11 +1019,13 @@ prtline(void)
199 				printf("%s:\n", ifiles->fname);
200 		}
201 	} else if (!Pflag) {
202-		printf("\n# %d \"%s\"", ifiles->lineno, ifiles->fname);
203+		sheap("\n# %d \"%s\"", ifiles->lineno, ifiles->fname);
204 		if (ifiles->idx == SYSINC)
205-			printf(" 3");
206-		printf("\n");
207+			sheap(" 3");
208+		sheap("\n");
209+		putstr(sb);
210 	}
211+	stringbuf = sb;
212 }
213
214 void
215@@ -1341,7 +1345,7 @@ pragmastmt(void)
216 	sb = stringbuf;
217 	savstr((const usch *)"\n#pragma ");
218 	savln();
219-	printf("%s", ((char *)sb));
220+	putstr(sb);
221 	prtline();
222 	stringbuf = sb;
223 }
224@@ -1413,7 +1417,7 @@ redo:	while ((ch = inch()) == ' ' || ch
225 						goto redo;
226 					unch(ch);
227 				} else if (ch == '\n') {
228-					fputc('\n', stdout);
229+					putch('\n');
230 					ifiles->lineno++;
231 				}
232 			}
233