1Index: cpp.c 2=================================================================== 3RCS file: /cvsroot/pcc/cc/cpp/cpp.c,v 4retrieving revision 1.196 5retrieving revision 1.197 6diff -u -p -u -r1.196 -r1.197 7--- cpp.c 18 Oct 2014 15:02:03 -0000 1.196 8+++ cpp.c 19 Oct 2014 17:40:36 -0000 1.197 9@@ -1,4 +1,4 @@ 10-/* Id: cpp.c,v 1.196 2014/10/18 15:02:03 ragge Exp */ 11-/* $NetBSD: stdio.diff,v 1.1.1.1 2016/02/09 20:28:45 plunky Exp $ */ 12+/* Id: cpp.c,v 1.197 2014/10/19 17:40:36 ragge Exp */ 13+/* $NetBSD: stdio.diff,v 1.1.1.1 2016/02/09 20:28:45 plunky Exp $ */ 14 15 /* 16 * Copyright (c) 2004,2010 Anders Magnusson (ragge@ludd.luth.se). 17@@ -74,15 +74,13 @@ static void prrep(const usch *s); 18 #define IMP(x) 19 #endif 20 21-int ofd; 22-usch outbuf[CPPBUF], lastoch; 23-int obufp, istty; 24 int Aflag, Cflag, Eflag, Mflag, dMflag, Pflag, MPflag, MMDflag; 25 usch *Mfile, *MPfile, *Mxfile; 26 struct initar *initar; 27 int readmac; 28 int defining; 29 int warnings; 30+FILE *of; 31 32 /* include dirs */ 33 struct incs { 34@@ -141,7 +139,6 @@ int bidx; /* Top of bptr stack */ 35 static int readargs(struct symtab *sp, const usch **args); 36 static void exparg(int); 37 static void subarg(struct symtab *sp, const usch **args, int); 38-static void flbuf(void); 39 static void usage(void); 40 static usch *xstrdup(const usch *str); 41 static void addidir(char *idir, struct incs **ww); 42@@ -324,11 +321,10 @@ main(int argc, char **argv) 43 } 44 45 if (argc == 2) { 46- if ((ofd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) 47+ if ((of = freopen(argv[1], "w", stdout)) == NULL) 48 error("Can't creat %s", argv[1]); 49 } else 50- ofd = 1; /* stdout */ 51- istty = isatty(ofd); 52+ of = stdout; 53 54 if (argc && strcmp(argv[0], "-")) { 55 fn1 = fn2 = (usch *)argv[0]; 56@@ -339,8 +335,7 @@ main(int argc, char **argv) 57 if (pushfile(fn1, fn2, 0, NULL)) 58 error("cannot open %s", argv[0]); 59 60- flbuf(); 61- close(ofd); 62+ fclose(of); 63 #ifdef TIMING 64 (void)gettimeofday(&t2, NULL); 65 t2.tv_sec -= t1.tv_sec; 66@@ -1054,21 +1049,15 @@ void 67 warning(const char *fmt, ...) 68 { 69 va_list ap; 70- usch *sb; 71 72- flbuf(); 73- savch(0); 74- 75- sb = stringbuf; 76 if (ifiles != NULL) 77- sheap("%s:%d: warning: ", ifiles->fname, ifiles->lineno); 78+ fprintf(stderr, "%s:%d: warning: ", 79+ ifiles->fname, ifiles->lineno); 80 81 va_start(ap,fmt); 82- vsheap(fmt, ap); 83+ vfprintf(stderr, fmt, ap); 84 va_end(ap); 85- savch('\n'); 86- xwrite(2, sb, stringbuf - sb); 87- stringbuf = sb; 88+ fputc('\n', stderr); 89 90 warnings++; 91 } 92@@ -1077,22 +1066,15 @@ void 93 error(const char *fmt, ...) 94 { 95 va_list ap; 96- usch *sb; 97 98- flbuf(); 99- savch(0); 100- 101- sb = stringbuf; 102 if (ifiles != NULL) 103- sheap("%s:%d: error: ", ifiles->fname, ifiles->lineno); 104+ fprintf(stderr, "%s:%d: error: ", 105+ ifiles->fname, ifiles->lineno); 106 107 va_start(ap, fmt); 108- vsheap(fmt, ap); 109+ vfprintf(stderr, fmt, ap); 110 va_end(ap); 111- savch('\n'); 112- xwrite(2, sb, stringbuf - sb); 113- stringbuf = sb; 114- 115+ fputc('\n', stderr); 116 exit(1); 117 } 118 119@@ -1287,7 +1269,7 @@ delwarn(void) 120 } else if (c == EBLOCK) { 121 sss(); 122 } else if (c == '\n') { 123- putch(cinput()); 124+ fputc(cinput(), stdout); 125 } else 126 savstr(yytext); 127 } 128@@ -1310,7 +1292,7 @@ kfind(struct symtab *sp) 129 struct symtab *nl; 130 const usch *argary[MAXARGS+1], *cbp; 131 usch *sbp; 132- int c, o, chkf; 133+ int c, o; 134 135 DPRINT(("%d:enter kfind(%s)\n",0,sp->namep)); 136 IMP("KFIND"); 137@@ -1331,11 +1313,6 @@ kfind(struct symtab *sp) 138 exparg(1); 139 140 upp: sbp = stringbuf; 141- chkf = 1; 142- if (obufp != 0) 143- lastoch = outbuf[obufp-1]; 144- if (iswsnl(lastoch)) 145- chkf = 0; 146 if (Cflag) 147 readmac++; 148 while ((c = sloscan()) != WARN) { 149@@ -1391,12 +1368,9 @@ upp: sbp = stringbuf; 150 break; 151 152 default: 153- if (chkf && c < 127) 154- putch(' '); 155 savstr(yytext); 156 break; 157 } 158- chkf = 0; 159 } 160 if (Cflag) 161 readmac--; 162@@ -1423,7 +1397,7 @@ upp: sbp = stringbuf; 163 /* Found one, output \n to be in sync */ 164 for (; *sbp; sbp++) { 165 if (*sbp == '\n') 166- putch('\n'), ifiles->lineno++; 167+ fputc('\n', stdout), ifiles->lineno++; 168 } 169 170 /* fetch arguments */ 171@@ -1576,7 +1550,7 @@ chkdir(void) 172 while ((ch = cinput()) != '\n') 173 ; 174 ifiles->lineno++; 175- putch('\n'); 176+ fputc('\n', stdout); 177 } 178 } 179 180@@ -1611,7 +1585,7 @@ readargs(struct symtab *sp, const usch * 181 while ((c = sloscan()) == WSPACE || c == '\n') 182 if (c == '\n') { 183 ifiles->lineno++; 184- putch(cinput()); 185+ fputc(cinput(), stdout); 186 chkdir(); 187 } 188 for (;;) { 189@@ -1632,7 +1606,7 @@ readargs(struct symtab *sp, const usch * 190 savstr(yytext); 191 oho: while ((c = sloscan()) == '\n') { 192 ifiles->lineno++; 193- putch(cinput()); 194+ fputc(cinput(), stdout); 195 chkdir(); 196 savch(' '); 197 } 198@@ -2010,37 +1984,6 @@ unpstr(const usch *c) 199 } 200 } 201 202-static void 203-flbuf(void) 204-{ 205- if (obufp == 0) 206- return; 207- if (Mflag == 0) 208- xwrite(ofd, outbuf, obufp); 209- lastoch = outbuf[obufp-1]; 210- obufp = 0; 211-} 212- 213-void 214-putch(int ch) 215-{ 216- outbuf[obufp++] = (usch)ch; 217- if (obufp == CPPBUF || (istty && ch == '\n')) 218- flbuf(); 219-} 220- 221-void 222-putstr(const usch *s) 223-{ 224- for (; *s; s++) { 225- if (*s == PHOLD) 226- continue; 227- outbuf[obufp++] = *s; 228- if (obufp == CPPBUF || (istty && *s == '\n')) 229- flbuf(); 230- } 231-} 232- 233 /* 234 * convert a number to an ascii string. Store it on the heap. 235 */ 236Index: cpp.h 237=================================================================== 238RCS file: /cvsroot/pcc/cc/cpp/cpp.h,v 239retrieving revision 1.70 240retrieving revision 1.71 241diff -u -p -u -r1.70 -r1.71 242--- cpp.h 18 Oct 2014 15:02:03 -0000 1.70 243+++ cpp.h 19 Oct 2014 17:40:36 -0000 1.71 244@@ -1,4 +1,4 @@ 245-/* Id: cpp.h,v 1.70 2014/10/18 15:02:03 ragge Exp */ 246-/* $NetBSD: stdio.diff,v 1.1.1.1 2016/02/09 20:28:45 plunky Exp $ */ 247+/* Id: cpp.h,v 1.71 2014/10/19 17:40:36 ragge Exp */ 248+/* $NetBSD: stdio.diff,v 1.1.1.1 2016/02/09 20:28:45 plunky Exp $ */ 249 250 /* 251 * Copyright (c) 2004,2010 Anders Magnusson (ragge@ludd.luth.se). 252@@ -39,8 +39,8 @@ extern int dflag; 253 extern int tflag, Aflag, Cflag, Pflag; 254 extern int Mflag, dMflag, MPflag, MMDflag; 255 extern usch *Mfile, *MPfile; 256-extern int ofd; 257 extern int defining; 258+extern FILE *of; 259 260 /* args for lookup() */ 261 #define FIND 0 262Index: token.c 263=================================================================== 264RCS file: /cvsroot/pcc/cc/cpp/token.c,v 265retrieving revision 1.119 266retrieving revision 1.120 267diff -u -p -u -r1.119 -r1.120 268--- token.c 18 Oct 2014 15:02:03 -0000 1.119 269+++ token.c 19 Oct 2014 17:40:36 -0000 1.120 270@@ -1,4 +1,4 @@ 271-/* Id: token.c,v 1.119 2014/10/18 15:02:03 ragge Exp */ 272-/* $NetBSD: stdio.diff,v 1.1.1.1 2016/02/09 20:28:45 plunky Exp $ */ 273+/* Id: token.c,v 1.120 2014/10/19 17:40:36 ragge Exp */ 274+/* $NetBSD: stdio.diff,v 1.1.1.1 2016/02/09 20:28:45 plunky Exp $ */ 275 276 /* 277 * Copyright (c) 2004,2009 Anders Magnusson. All rights reserved. 278@@ -65,7 +65,7 @@ static void undefstmt(void); 279 static void pragmastmt(void); 280 static void elifstmt(void); 281 282-#define PUTCH(ch) if (!flslvl) putch(ch) 283+#define PUTCH(ch) if (!flslvl) fputc(ch, stdout) 284 /* protection against recursion in #include */ 285 #define MAX_INCLEVEL 100 286 static int inclevel; 287@@ -312,7 +312,7 @@ eatcmnt(void) 288 ch = inch(); 289 if (ch == '\n') { 290 ifiles->lineno++; 291- putch('\n'); 292+ fputc('\n', stdout); 293 continue; 294 } 295 if (ch == -1) 296@@ -373,9 +373,11 @@ xloop: if (ch == -1) 297 298 case '/': /* Comments */ 299 if ((ch = inch()) == '/') { 300-cppcmt: if (Cflag) { PUTCH(ch); } else { PUTCH(' '); } 301+ if (!flslvl) { 302+cppcmt: fputc(Cflag ? ch : ' ', stdout); 303+ } 304 do { 305- if (Cflag) PUTCH(ch); 306+ if (Cflag && !flslvl) fputc(ch, stdout); 307 ch = inch(); 308 if (ch == -1) 309 goto eof; 310@@ -385,7 +387,7 @@ cppcmt: if (Cflag) { PUTCH(ch); } els 311 if (eatcmnt() == -1) 312 goto eof; 313 } else { 314- PUTCH('/'); 315+ if (!flslvl) fputc('/', stdout); 316 goto xloop; 317 } 318 break; 319@@ -395,7 +397,7 @@ cppcmt: if (Cflag) { PUTCH(ch); } els 320 ifiles->lineno += i; 321 ifiles->escln = 0; 322 while (i-- > 0) 323- putch('\n'); 324+ fputc('\n', stdout); 325 run: for(;;) { 326 ch = inch(); 327 if (ch == '/') { 328@@ -412,7 +414,7 @@ run: for(;;) { 329 } 330 if (ch != ' ' && ch != '\t') 331 break; 332- PUTCH(ch); 333+ if (!flslvl) fputc(ch, stdout); 334 } 335 if (ch == '#') { 336 ppdir(); 337@@ -537,9 +539,9 @@ con: PUTCH(ch); 338 if (flslvl == 0) { 339 cp = stringbuf; 340 if ((nl = lookup(yytext, FIND)) && kfind(nl)) 341- putstr(stringbuf); 342+ printf("%s", stringbuf); 343 else 344- putstr(yytext); 345+ printf("%s", (char *)yytext); 346 stringbuf = cp; 347 } 348 if (ch == -1) 349@@ -559,7 +561,7 @@ con: PUTCH(ch); 350 } 351 352 eof: warning("unexpected EOF"); 353- putch('\n'); 354+ fputc('\n', stdout); 355 } 356 357 int 358@@ -667,7 +669,7 @@ chlit: 359 if (c == -1) 360 return 0; 361 if (c == '\n') 362- putch(c), ifiles->lineno++; 363+ fputc(c, stdout), ifiles->lineno++; 364 else if (c == EBLOCK) { 365 (void)inch(); 366 (void)inch(); 367@@ -976,7 +978,7 @@ pushfile(const usch *file, const usch *f 368 prinit(initar, ic); 369 initar = NULL; 370 if (dMflag) 371- xwrite(ofd, ic->buffer, strlen((char *)ic->buffer)); 372+ printf("%s", (char *)ic->buffer); 373 fastscan(); 374 prtline(); 375 ic->infil = oin; 376@@ -1004,27 +1006,22 @@ pushfile(const usch *file, const usch *f 377 void 378 prtline(void) 379 { 380- usch *sb = stringbuf; 381- 382 if (Mflag) { 383 if (dMflag) 384 return; /* no output */ 385 if (ifiles->lineno == 1 && 386 (MMDflag == 0 || ifiles->idx != SYSINC)) { 387- sheap("%s: %s\n", Mfile, ifiles->fname); 388+ printf("%s: %s\n", Mfile, ifiles->fname); 389 if (MPflag && 390 strcmp((const char *)ifiles->fname, (char *)MPfile)) 391- sheap("%s:\n", ifiles->fname); 392- xwrite(ofd, sb, stringbuf - sb); 393+ printf("%s:\n", ifiles->fname); 394 } 395 } else if (!Pflag) { 396- sheap("\n# %d \"%s\"", ifiles->lineno, ifiles->fname); 397+ printf("\n# %d \"%s\"", ifiles->lineno, ifiles->fname); 398 if (ifiles->idx == SYSINC) 399- sheap(" 3"); 400- sheap("\n"); 401- putstr(sb); 402+ printf(" 3"); 403+ printf("\n"); 404 } 405- stringbuf = sb; 406 } 407 408 void 409@@ -1344,7 +1341,7 @@ pragmastmt(void) 410 sb = stringbuf; 411 savstr((const usch *)"\n#pragma "); 412 savln(); 413- putstr(sb); 414+ printf("%s", ((char *)sb)); 415 prtline(); 416 stringbuf = sb; 417 } 418@@ -1416,7 +1413,7 @@ redo: while ((ch = inch()) == ' ' || ch 419 goto redo; 420 unch(ch); 421 } else if (ch == '\n') { 422- putch('\n'); 423+ fputc('\n', stdout); 424 ifiles->lineno++; 425 } 426 } 427