Print this page
cpp: just use fwrite() for writing

Split Close
Expand all
Collapse all
          --- old/cpp/cpp.c
          +++ new/cpp/cpp.c
↓ open down ↓ 199 lines elided ↑ open up ↑
 200  200  static  char *endbuf[MAXFRE];
 201  201  
 202  202  static  int plvl;       /* parenthesis level during scan for macro actuals */
 203  203  static  int maclin;     /* line number of macro call requiring actuals */
 204  204  static  char *macfil;   /* file name of macro call requiring actuals */
 205  205  static  char *macnam;   /* name of macro requiring actuals */
 206  206  static  int maclvl;     /* # calls since last decrease in nesting level */
 207  207  static  char *macforw;  /* ptr which must be exceeded to decrease nesting lvl */
 208  208  static  int macdam;     /* offset to macforw due to buffer shifting */
 209  209  
 210      -#if tgp
 211      -int tgpscan;    /* flag for dump(); */
 212      -#endif
 213      -
 214  210  static  int     inctop[MAXINC];
 215  211  static  char    *fnames[MAXINC];
 216  212  static  char    *dirnams[MAXINC];       /* actual directory of #include files */
 217  213  static  int     fins[MAXINC];
 218  214  static  int     lineno[MAXINC];
 219  215  
 220  216  /*
 221  217   * We need:
 222  218   *      "" include dir as dirs[0] +
 223  219   *      MAXIDIRS +
↓ open down ↓ 135 lines elided ↑ open up ↑
 359  355   * buffers which are "live"; the side buffers instack[0 : inctop[ifno]]
 360  356   * are dormant, waiting for end-of-file on the current file.
 361  357   *
 362  358   * space for side buffers is obtained from 'savch' and is never returned.
 363  359   * bufstack[0:fretop-1] holds addresses of side buffers which
 364  360   * are available for use.
 365  361   */
 366  362  
 367  363  static void
 368  364  dump() {
 369      -/*
 370      - * write part of buffer which lies between  outp  and  inp .
 371      - * this should be a direct call to 'write', but the system slows to a crawl
 372      - * if it has to do an unaligned copy.  thus we buffer.  this silly loop
 373      - * is 15% of the total time, thus even the 'putc' macro is too slow.
 374      - */
 375  365          register char *p1;
 376      -#if tgp
 377      -        register char *p2;
 378      -#endif
 379      -        register FILE *f;
 380  366          if ((p1=outp)==inp || flslvl!=0) return;
 381      -#if tgp
 382      -#define MAXOUT 80
 383      -        if (!tgpscan) {
 384      -                /* scan again to insure <= MAXOUT chars between linefeeds */
 385      -                register char c,*pblank; char savc,stopc,brk;
 386      -                tgpscan=1; brk=stopc=pblank=0; p2=inp; savc= *p2; *p2='\0';
 387      -                while (c= *p1++) {
 388      -                        if (c=='\\') c= *p1++;
 389      -                        if (stopc==c) stopc=0;
 390      -                        else if (c=='"' || c=='\'') stopc=c;
 391      -                        if (p1-outp>MAXOUT && pblank!=0) {
 392      -                                *pblank++='\n';
 393      -                                inp=pblank;
 394      -                                dump();
 395      -                                brk=1;
 396      -                                pblank=0;
 397      -                        }
 398      -                        if (c==' ' && stopc==0) pblank=p1-1;
 399      -                }
 400      -                if (brk) sayline(NOINCLUDE);
 401      -                *p2=savc; inp=p2; p1=outp; tgpscan=0;
 402      -        }
 403      -#endif
 404      -        f=fout;
 405      -        while (p1<inp)
 406      -                putc(*p1++,f);
      367 +        fwrite(p1, inp - p1, 1, fout);
 407  368          outp=p1;
 408  369  }
 409  370  
 410  371  static char *
 411  372  refill(p) register char *p; {
 412  373  /*
 413  374   * dump buffer.  save chars from inp to p.  read into buffer at pbuf,
 414  375   * contiguous with p.  update pointers, return new p.
 415  376   */
 416  377          register char *np,*op; register int ninbuf;
↓ open down ↓ 587 lines elided ↑ open up ↑
1004  965  
1005  966                  if (elslvl==trulvl+flslvl) 
1006  967                          pperror("Too many #else's"); 
1007  968                  elslvl=trulvl+flslvl; 
1008  969  
1009  970          } else if (np==udfloc) {/* undefine */
1010  971                  if (flslvl==0) {
1011  972                          ++flslvl; p=skipbl(p); slookup(inp,p,DROP); --flslvl;
1012  973                  }
1013  974          } else if (np==ifloc) {/* if */
1014      -#if tgp
1015      -                pperror(" IF not implemented, true assumed", 0);
1016      -                if (flslvl==0) ++trulvl; else ++flslvl;
1017      -#else
1018  975                  newp=p;
1019  976                  if (flslvl==0 && yyparse()) ++trulvl; else ++flslvl;
1020  977                  p=newp;
1021      -#endif
1022  978          } else if (np == idtloc) {              /* ident */
1023  979                  if (pflag == 0)
1024  980                          while (*inp != '\n')    /* pass text */
1025  981                                  p = cotoken(p);
1026  982          } else if (np == pragmaloc) {           /* pragma */
1027  983                  while (*inp != '\n')            /* pass text */
1028  984                          p = cotoken(p);
1029  985  #ifdef EXIT_ON_ERROR
1030  986          } else if (np == errorloc) {            /* error */
1031  987                  if (trulvl > 0) {
↓ open down ↓ 585 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX