Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.5
 
1.6
 
MAIN:ragge:20050511193259
 
token.c
_>4242 #ifdef NEWBUF
 4343         int infil;
 4444         usch *curptr;
<>45 -        int curlen;
  45+        usch *maxread;
4646         usch *ostr;
<>47 -        usch buffer[CPPBUF];
  47+        usch *buffer;
  48+        usch bbuf[NAMEMAX+CPPBUF+1];
4849 #else
 4950         FILE *ifil;
 5051 #endif
<>51 -} *ifiles, *freebufs;
  52+} *ifiles;
5253 
 5354 usch *yyp, yystr[CPPBUF];
 5455 
     
 !
6061 getbuf(usch *file)
 6162 {
 6263         struct includ *ic;
<> 64+        usch *ostr = stringbuf;
6365 
<>64 -        if (freebufs) {
 65 -                /* Have buffer for use already */
 66 -                ic = freebufs;
 67 -                freebufs = freebufs->next;
 68 -                ic->ostr = NULL;
 69 -        } else {
 70 -                stringbuf = (usch *)ROUND((int)stringbuf);
 71 -                ic = (struct includ *)stringbuf;
 72 -                stringbuf += sizeof(struct includ);
 73 -                ic->ostr = stringbuf;
 74 -        }
 75 -        if (file) {
 76 -                ic->fname = savstr(file); /* XXX - will loose space */
 77 -                savch('\0');
 78 -        }
 79 -        if (ic->ostr)
 80 -                ic->ostr = stringbuf;
  66+//printf("getbuf1: stringbuf %p\n", stringbuf);
  67+        stringbuf = (usch *)ROUND((int)stringbuf);
  68+//printf("getbuf2: stringbuf %p\n", stringbuf);
  69+        ic = (struct includ *)stringbuf;
  70+        stringbuf += sizeof(struct includ);
  71+        ic->ostr = ostr;
  72+
  73+//printf("getbuf3: stringbuf %p\n", stringbuf);
8174         return ic;
 8275 }
 8376 
 8477 static void
 8578 putbuf(struct includ *ic)
 8679 {
<>87 -        if (ic->ostr == stringbuf) {
 88 -                /* no new macros, free this buffer */
 89 -                stringbuf = (usch *)ic;
 90 -        } else {
 91 -                ic->next = freebufs;
 92 -                freebufs = ic;
 93 -        }
  80+//printf("putbuf: stringbuf %p\n", stringbuf);
  81+if (stringbuf < (usch *)&ic[1])
  82+;//     printf("ERROR!!!\n");
  83+else
  84+        stringbuf = ic->ostr;
  85+//printf("putbuf2: stringbuf %p\n", stringbuf);
9486 }
 9587 
 9688 static int
 9789 input(void)
 9890 {
 9991         struct includ *ic;
<> 92+        int len;
10093 
<>101 -        if (ifiles->curptr < ifiles->buffer+ifiles->curlen)
  94+        if (ifiles->curptr < ifiles->maxread) {
  95+//printf("c %d\n", *ifiles->curptr);
10296                 return *ifiles->curptr++;
<> 97+}
10398         if (ifiles->infil < 0) {
 10499                 ic = ifiles;
 105100                 ifiles = ifiles->next;
 106101                 putbuf(ic);
 107102                 return input();
 108103         }
<>109 -        if ((ifiles->curlen = read(ifiles->infil, ifiles->buffer, CPPBUF)) < 0)
  104+        if ((len = read(ifiles->infil, ifiles->buffer, CPPBUF)) < 0)
110105                 error("read error on file %s", ifiles->fname);
<>111 -        if (ifiles->curlen == 0)
  106+        if (len == 0)
112107                 return -1;
 113108         ifiles->curptr = ifiles->buffer;
<> 109+        ifiles->maxread = ifiles->buffer + len;
114110         return input();
 115111 }
 116112 
     
 !
119115 {
 120116         struct includ *ic;
 121117 
<>122 -        if (ifiles->curptr > ifiles->buffer) {
  118+if (c == 0) {
  119+printf("no;;\n");
  120+}
  121+
  122+        if (ifiles->curptr > ifiles->bbuf) {
123123                 *--ifiles->curptr = c;
 124124         } else {
 125125                 ic = getbuf(NULL);
 126126                 ic->fname = ifiles->fname;
 127127                 ic->lineno = ifiles->lineno;
 128128                 ic->infil = -1;
<>129 -                ic->curlen = CPPBUF;
 130 -                ic->curptr = ic->buffer+CPPBUF;
  129+                ic->curptr = &ic->bbuf[NAMEMAX+CPPBUF+1];
  130+                ic->maxread = ic->curptr;
131131                 ic->next = ifiles;
 132132                 ifiles = ic;
 133133                 *--ifiles->curptr = c;
 134134         }
<> 135+//printf("unput %d\n", c);
135136 }
 136137 #else
 137138 #define input() fgetc(ifiles->ifil)
     
 !
191192 #define ONEMORE()       { *yyp++ = c; c = slofgetc(); }
 192193 again:  switch (c) {
 193194         case -1:
<> 195+#ifdef NEWBUF
  196+                rval = 0;
  197+#else
194198                 rval = yywrap() ? 0 : yylex();
<> 199+#endif
195200                 break;
 196201 
 197202         case '\'': /* charcon */
     
 !
392397         return rval;
 393398 }
 394399 
<>395 -#ifdef NEW_READFILE
  400+#ifdef NEWBUF
396401 /*
<>397 - * A new file included.  Read buffers are allocated on the stack and
 398 - * all subroutines are called from hereThis function will be called
 399 - * recursive when multiple files are included.
  402+ * A new file included.
  403+ * If ifiles == NULL, this is the first file and already opened (stdin).
  404+ * Return 0 on success, -1 on failure to open file.
400405  */
 401406 int
 402407 pushfile(char *file)
 403408 {
<>404 -        struct includ incl, *ic = &incl;
  409+        struct includ ibuf;
  410+        struct includ *old;
  411+        struct includ *ic;
405412 
<>406 -        ic->lineno = 1;
 407 -        if (ifiles != NULL) { /* not if first file */
  413+        ic = &ibuf;
  414+        old = ifiles;
  415+
  416+        if (file != NULL) {
408417                 if ((ic->infil = open(file, O_RDONLY)) < 0)
 409418                         return -1;
<>410 -        } else
 411 -                ic->infil = 0; /* STDIN_FILENO */
 412 -
 413 -        ic->fname = savstr(file); /* XXX - will loose space */
 414 -        savch('\0');
  419+                ic->fname = file;
  420+        } else {
  421+                ic->infil = 0;
  422+                ic->fname = "<stdin>";
  423+        }
  424+        ic->buffer = ic->bbuf+NAMEMAX;
415425         ic->curptr = ic->buffer;
<>416 -        ic->next = ifiles;
417426         ifiles = ic;
<> 427+        ic->lineno = 0;
  428+        ic->maxread = ic->curptr;
  429+        unput('\n');
418430 
<>419 -        while ((c = qscan()) != 0) {
 420 -                switch (c) {
 421 -                case CONTROL:
 422 -                        control();
 423 -                        break;
  431+        mainscan();
424432 
<>425 -                
  433+        if (trulvl || flslvl)
  434+                error("unterminated conditional");
426435 
<>427 -
 428 -
  436+        ifiles = old;
  437+        close(ic->infil);
  438+        return 0;
429439 }
 430440 #else
<> 441+
431442 /*
 432443  * A new file included.
 433444  * If ifiles == NULL, this is the first file and already opened (stdin).
     
 !
438449 {
 439450         struct includ *ic;
 440451 
<>441 -#ifdef NEWBUF
 442 -        ic = getbuf(file);
 443 -#else
444452         ic = malloc(sizeof(struct includ));
 445453         ic->fname = strdup(file);
<>446 -#endif
447454         if (ifiles != NULL) {
<>448 -#ifdef NEWBUF
 449 -                if ((ic->infil = open(file, O_RDONLY)) < 0)
 450 -                        return -1;
 451 -#else
452455                 if ((ic->ifil = fopen(file, "r")) == NULL)
 453456                         return -1;
<>454 -#endif
455457         } else
<>456 -#ifdef NEWBUF
 457 -                ic->infil = 0;
 458 -#else
459458                 ic->ifil = stdin;
<>460 -#endif
 461 -#ifdef NEWBUF
 462 -        ic->curptr = ic->buffer;
 463 -#endif
464459         ic->next = ifiles;
 465460         ifiles = ic;
 466461         ic->lineno = 0;
 467462         unput('\n');
 468463 
 469464         return 0;
 470465 }
<>471 -#endif
472466 
 473467 /*
 474468  * End of included file (or everything).
     
 !
480474 
 481475         ic = ifiles;
 482476         ifiles = ifiles->next;
<>483 -#ifdef NEWBUF
 484 -        close(ic->infil);
 485 -        putbuf(ic);
 486 -#else
487477         fclose(ic->ifil);
 488478         free(ic->fname);
 489479         free(ic);
<>490 -#endif
491480         prtline();
 492481 }
<> 482+#endif
493483 
 494484 /*
 495485  * Print current position to output file.
     
 !
508498         unput(c);
 509499 }
 510500 
<> 501+#ifndef NEWBUF
511502 int
 512503 yywrap()
 513504 {
     
 !
516507         popfile();
 517508         return 0;
 518509 }
<> 510+#endif
519511 
 520512 void
 521513 setline(int line)
     
 !
528520 setfile(char *name)
 529521 {
 530522         if (ifiles)
<>531 -                free(ifiles->fname), ifiles->fname = strdup(name);
  523+                ifiles->fname = strdup(name);
<_532524 }
 533525 
 534526 int
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-09-17 05:33 +0200