Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.10
 
1.11
 
MAIN:ragge:20060928111007
 
token.c
_>3434 
 3535 #include "cpp.h"
 3636 
<>37 -#ifndef ragge
3837 /* definition for include file info */
 3938 struct includ {
 4039         struct includ *next;
     
 !
4746         usch *buffer;
 4847         usch bbuf[NAMEMAX+CPPBUF+1];
 4948 } *ifiles;
<>50 -#endif
5149 
 5250 usch *yyp, *yystr, yybuf[CPPBUF];
 5351 
     
 !
5856 getbuf(usch *file)
 5957 {
 6058         struct includ *ic;
<>61 -
 62 -        ic = calloc(sizeof(struct includ), 1);
 63 -#if 0
6459         usch *ostr = stringbuf;
 6560 
<>66 -//printf("getbuf1: stringbuf %p\n", stringbuf);
6761         stringbuf = (usch *)ROUND((int)stringbuf);
<>68 -//printf("getbuf2: stringbuf %p\n", stringbuf);
6962         ic = (struct includ *)stringbuf;
 7063         stringbuf += sizeof(struct includ);
 7164         ic->ostr = ostr;
 7265 
<>73 -//printf("getbuf3: stringbuf %p\n", stringbuf);
 74 -#endif
7566         return ic;
 7667 }
 7768 
 7869 static void
 7970 putbuf(struct includ *ic)
 8071 {
<>81 -        free(ic);
 82 -#if 0
 83 -//printf("putbuf: stringbuf %p\n", stringbuf);
8472 if (stringbuf < (usch *)&ic[1])
<>85 -;//     printf("ERROR!!!\n");
  73+;
8674 else
 8775         stringbuf = ic->ostr;
<>88 -//printf("putbuf2: stringbuf %p\n", stringbuf);
 89 -#endif
9076 }
 9177 
 9278 static int
     
 !
9581         struct includ *ic;
 9682         int len;
 9783 
<>98 -        if (ifiles->curptr < ifiles->maxread) {
 99 -if (*ifiles->curptr == 0)
 100 -printf("c %d\n", *ifiles->curptr);
  84+        if (ifiles->curptr < ifiles->maxread)
10185                 return *ifiles->curptr++;
<>102 -}
  86+
10387         if (ifiles->infil < 0) {
 10488                 ic = ifiles;
 10589                 ifiles = ifiles->next;
     
 !
11599         return input();
 116100 }
 117101 
<>118 -#ifdef ragge
 119 -/*
 120 - * Get next character from input stream.  If the input buffer is empty,
 121 - * try to fill it up. If end of stream, return -1.
 122 - */
 123 -static int
 124 -inpch(struct includ *ic)
 125 -{
 126 -        int len;
 127 -
 128 -        if (ic->curptr < ic->maxread)
 129 -                return *ic->curptr++;
 130 -
 131 -        if ((len = read(ic->infil, ic->buffer, CPPBUF)) < 0)
 132 -                error("read error on file %s", ic->fname);
 133 -        if (len == 0)
 134 -                return -1;
 135 -        ic->curptr = ic->buffer;
 136 -        ic->maxread = ic->buffer + len;
 137 -        return inpch(ic);
 138 -}
 139 -/*
 140 - * Get next character from the current input stream.
 141 - * Also handles phase 1 and 2 in section 5.1.1.2 "Translation phases"
 142 - * in the C99 standard (trigraphs and \\n).
 143 - * Only newlines that are removed here are accounted for, and when found
 144 - * return GOTNL to tell that a \n must be printed out (to avoid line breaks
 145 - * in strings etc).
 146 - */
 147 -int
 148 -inch(struct includ *ic)
 149 -{
 150 -        int c;
 151 -
 152 -        if (ic->curptr < ic->maxread)
 153 -                c = *ic->curptr++;
 154 -        else
 155 -                c = inpch(ic);
 156 -
 157 -        if (c != '\\' && c != '?')
 158 -                return c; /* common case */
 159 -        /* first check for trigraphs */
 160 -        if (c == '?') {
 161 -                if ((c = inpch(ic)) != '?') {
 162 -                        unch(ic, c);
 163 -                        return '?';
 164 -                }
 165 -                switch (c = input()) {
 166 -                case '=': c = '#'; break;
 167 -                case '(': c = '['; break;
 168 -                case ')': c = ']'; break;
 169 -                case '<': c = '{'; break;
 170 -                case '>': c = '}'; break;
 171 -                case '/': c = '\\'; break;
 172 -                case '\'': c = '^'; break;
 173 -                case '!': c = '|'; break;
 174 -                case '-': c = '~'; break;
 175 -                default:
 176 -                        unch(ic, c);
 177 -                        unch(ic, '?');
 178 -                        return '?';
 179 -                }
 180 -        }
 181 -        /* search for \\n */
 182 -        if (c == '\\') {
 183 -                if ((c = inpch(ic)) != '\n') {
 184 -                        unch(ic, c);
 185 -                        return '\\';
 186 -                }
 187 -                ic->lineno++;
 188 -                c = GOTNL;
 189 -        }
 190 -        return c;
 191 -}
 192 -
 193 -void
 194 -unch(struct includ *ic, int c)
 195 -{
 196 -        *--ic->curptr = c;
 197 -}
 198 -
 199 -void
 200 -outch(int c)
 201 -{
 202 -        putc(c, obuf);
 203 -}
 204 -
 205 -#endif
 206 -
207102 static void
 208103 unput(int c)
 209104 {
 210105         struct includ *ic;
 211106 
<>212 -if (c == 0) {
 213 -printf("no;;\n");
 214 -}
 215 -
216107         if (ifiles->curptr > ifiles->bbuf) {
 217108                 *--ifiles->curptr = c;
 218109         } else {
     
 !
226117                 ifiles = ic;
 227118                 *--ifiles->curptr = c;
 228119         }
<>229 -//printf("unput %d\n", c);
230120 }
 231121 
 232122 #define UNPUT(c) *--ifiles->curptr = c
<>233 -#define ADJUST(x) { \
 234 -        if (x > (ifiles->maxread-ifiles->curptr)) { \
 235 -                memcpy(
236123 
 237124 static int
 238125 slofgetc(void)
     
 !
295182         case '\'': /* charcon */
 296183         case '"': /* string */
 297184 chstr:          oc = c;
<>298 -                do {
 299 -                        *yyp++ = c;
 300 -                        if (c == '\\')
 301 -                                *yyp++ = slofgetc();
 302 -                } while ((c = slofgetc()) != EOF && c != oc);
 303 -                *yyp++ = c; *yyp = 0;
  185+                if (slow == 0) {
  186+                        do {
  187+                                putch(c);
  188+                                if (c == '\\')
  189+                                        putch(slofgetc());
  190+                        } while ((c = slofgetc()) != EOF && c != oc);
  191+                        if (c == oc)
  192+                                putch(c);
  193+                        goto fast;
  194+                } else {
  195+                        do {
  196+                                *yyp++ = c;
  197+                                if (c == '\\')
  198+                                        *yyp++ = slofgetc();
  199+                        } while ((c = slofgetc()) != EOF && c != oc);
  200+                        *yyp++ = c; *yyp = 0;
  201+                }
304202                 rval = oc == '"' ? STRING : CHARCON;
 305203                 break;
 306204 
     
 !
352250                 ONEMORE();
 353251                 if (isdigit(c))
 354252                         goto F;
<> 253+                if (!slow) {
  254+                        UNPUT(c);
  255+                        putch('.');
  256+                        goto fast;
  257+                }
355258                 if (c == '.') {
 356259                         ONEMORE();
 357260                         if (c == '.') {
     
 !
377280                         putch('\n');
 378281                         goto fast;
 379282                 }
<> 283+                if (!slow) {
  284+                        putch('\\');
  285+                        goto again;
  286+                }
380287                 UNPUT(c);
 381288                 *yyp++ = '\\'; *yyp = 0;
 382289                 rval = '\\';
     
 !
385292         case '\n':
 386293                 wasnl = 1;
 387294                 ifiles->lineno++;
<>388 -                *yyp++ = '\n'; *yyp = 0;
389295                 rval = NL;
<>390 -                break;
  296+                if (slow)
  297+                        break;
  298+                if (flslvl == 0) {
  299+                        if (curline() == 1)
  300+                                prtline();
  301+                        else
  302+                                putch('\n');
  303+                }
  304+                goto fast;
391305 
 392306         case '#':
 393307                 if (wasnl) {
 394308                         wasnl = 0;
 395309                         rval = CONTROL;
 396310                         break;
 397311                 }
<> 312+                if (!slow) {
  313+                        putch('#');
  314+                        goto fast;
  315+                }
398316                 *yyp++ = c;
 399317                 c = input();
 400318                 if (c == '#') {
     
 !
481399         default:
 482400                 if (isalpha(c) || c == '_')
 483401                         goto gotid;
<> 402+                if (!slow && c > 5) {
  403+                        putch(c);
  404+                        goto fast;
  405+                }
484406                 yystr[0] = c; yystr[1] = 0;
 485407                 rval = c;
 486408                 break;
     
 !
499421         struct includ ibuf;
 500422         struct includ *old;
 501423         struct includ *ic;
<>502 -        int otrulvl = trulvl, oflslvl = flslvl;
503424 
 504425         ic = &ibuf;
<>505 -        memset(ic, 0, sizeof(struct includ));
506426         old = ifiles;
<>507 -//printf("ifiles %p ic %p\n", ifiles, ic);
508427 
<> 428+        slow = 0;
509429         if (file != NULL) {
 510430                 if ((ic->infil = open(file, O_RDONLY)) < 0)
 511431                         return -1;
     
 !
521441         ic->maxread = ic->curptr;
 522442         unput('\n');
 523443 
<>524 -#ifdef ragge
 525 -        scanover(ic);
 526 -#else
527444         mainscan();
<>528 -#endif
529445 
<>530 -        if (trulvl != otrulvl || flslvl != oflslvl)
  446+        if (trulvl || flslvl)
531447                 error("unterminated conditional");
 532448 
 533449         ifiles = old;
<>534 -//printf("ifiles2 %p\n", ifiles);
<_535450         close(ic->infil);
 536451         return 0;
 537452 }
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-10-31 15:18 +0100