1: #
   2: /*
   3:  * pi - Pascal interpreter code translator
   4:  *
   5:  * Charles Haley, Bill Joy UCB
   6:  * Version 1.2 January 1979
   7:  *
   8:  *
   9:  * pxp - Pascal execution profiler
  10:  *
  11:  * Bill Joy UCB
  12:  * Version 1.2 January 1979
  13:  */
  14: 
  15: #include "0.h"
  16: #include "yy.h"
  17: 
  18: #ifdef PXP
  19: int yytokcnt;
  20: #endif
  21: 
  22: /*
  23:  * Getchar returns the next
  24:  * character from the current
  25:  * input line or -1 on end-of-file.
  26:  * It also maintains yycol for use in
  27:  * printing error messages.
  28:  */
  29: getchar()
  30: {
  31:     register i, c;
  32: 
  33:     if (*bufp == '\n') {
  34: #ifdef PXP
  35:         yytokcnt = 0;
  36: #endif
  37:         if (getline() < 0)
  38:             return (-1);
  39:     }
  40:     c = *++bufp;
  41:     if (c == '\t')
  42:         yycol = ((yycol + 8) & ~7);
  43:     else
  44:         yycol++;
  45:     return (c);
  46: }
  47: 
  48: /*
  49:  * Definitions of the structures used for the
  50:  * include facility.  The variable "ibp" points
  51:  * to the getc buffer of the current input file.
  52:  * There are "inclev + 1" current include files,
  53:  * and information in saved in the incs stack
  54:  * whenever a new level of include nesting occurs.
  55:  *
  56:  * Ibp in the incs structure saves the pointer
  57:  * to the previous levels input buffer;
  58:  * filename saves the previous file name;
  59:  * Printed saves whether the previous file name
  60:  * had been printed before this nesting occurred;
  61:  * and yyline is the line we were on on the previous file.
  62:  */
  63: int *ibp = ibuf;
  64: 
  65: #define MAXINC  10
  66: 
  67: struct inc {
  68:     int *ibp;
  69:     char    *filename;
  70:     int Printed;
  71:     int yyline;
  72:     int yyLinpt;
  73: } incs[MAXINC];
  74: 
  75: extern  char printed;
  76: 
  77: int inclev  = -1;
  78: 
  79: #ifdef PXP
  80: /*
  81:  * These initializations survive only if
  82:  * pxp is asked to pretty print one file.
  83:  * Otherwise they are destroyed by the initial
  84:  * call to getline.
  85:  */
  86: char    charbuf[CBSIZE] = " program x(output);\n";
  87: int yycol = 8;
  88: char    *bufp = charbuf;
  89: 
  90: #endif
  91: /*
  92:  * YyLinpt is the seek pointer to the beginning of the
  93:  * next line in the file.
  94:  */
  95: int yyLinpt;
  96: 
  97: /*
  98:  * Getline places the next line
  99:  * from the input stream in the
 100:  * line buffer, returning -1 at YEOF.
 101:  */
 102: getline()
 103: {
 104:     register char *cp;
 105:     register CHAR c;
 106: #ifdef PXP
 107:     static char ateof;
 108: #endif
 109:     register int *ib;
 110:     int i;
 111: 
 112:     if (opt('l') && yyprtd == 0)
 113:         yyoutline();
 114:     yyprtd = 0;
 115: top:
 116:     yylinpt = yyLinpt;
 117:     yyline++;
 118:     yyseqid++;
 119:     cp = charbuf;
 120:     ib = ibp;
 121:     i = sizeof charbuf - 1;
 122:     for (;;) {
 123:         c = getc(ib);
 124:         if (c == -1) {
 125:             if (uninclud())
 126:                 goto top;
 127: #ifdef PXP
 128:             if (ateof == 0 && bracket) {
 129:                 strcpy(charbuf, "begin end.\n");
 130:                 ateof = 1;
 131:                 goto out;
 132:             }
 133: #endif
 134:             bufp = "\n";
 135:             yyline--;
 136:             yyseqid--;
 137:             yyprtd = 1;
 138:             return (-1);
 139:         }
 140:         *cp++ = c;
 141:         if (c == '\n')
 142:             break;
 143:         if (--i == 0) {
 144:             line = yyline;
 145:             error("Input line too long - QUIT");
 146:             pexit(DIED);
 147:         }
 148:     }
 149:     *cp = 0;
 150:     yyLinpt = yylinpt + cp - charbuf;
 151:     if (includ())
 152:         goto top;
 153: #ifdef PXP
 154:     if (cp == &charbuf[1])
 155:         commnl();
 156:     else if (cp == &charbuf[2])
 157:         switch (charbuf[0]) {
 158:             case ' ':
 159:                 commnlbl();
 160:                 break;
 161:             case '\f':
 162:                 commform();
 163:         }
 164: #endif
 165:     if (opt('u'))
 166:         setuflg();
 167: out:
 168:     bufp = charbuf - 1;
 169:     yycol = 8;
 170:     return (1);
 171: }
 172: 
 173: /*
 174:  * Check an input line to see if it is a "#include" pseudo-statement.
 175:  * We allow arbitrary blanks in the line and the file name
 176:  * may be delimited by either 's or "s.  A single semicolon
 177:  * may be placed after the name, but nothing else is allowed
 178:  */
 179: includ()
 180: {
 181:     register char *cp, *dp;
 182:     char ch;
 183:     register struct inc *ip;
 184: 
 185:     cp = charbuf;
 186:     if (*cp++ != '#')
 187:         return (0);
 188:     cp = skipbl(cp);
 189:     for (dp = "include"; *dp; dp++)
 190:         if (*dp != *cp++)
 191:             return (0);
 192:     line = yyline;
 193:     cp = skipbl(cp);
 194:     ch = *cp++;
 195:     if (ch != '\'' && ch != '"') {
 196:         /*
 197: 		 * This should be a yerror flagging the place
 198: 		 * but its not worth figuring out the column.
 199: 		 */
 200:         line = yyline;
 201:         error("Include syntax error - expected ' or \" not found - QUIT");
 202:         pexit(DIED);
 203:     }
 204:     for (dp = cp; *dp != ch; dp++)
 205:         if (*dp == 0) {
 206:             line = yyline;
 207:             error("Missing closing %c for include file name - QUIT", ch);
 208:             pexit(DIED);
 209:         }
 210:     *dp++ = 0;
 211: /*
 212: 	if (*dp == ';')
 213: 		dp++;
 214: 	dp = skipbl(dp);
 215: 	if (*dp != '\n') {
 216: 		line = yyline;
 217: 		error("Garbage after filename in include");
 218: 		pexit(DIED);
 219: 	}
 220: */
 221:     if (!dotted(cp, 'i')) {
 222:         line = yyline;
 223:         error("Include filename must end in .i");
 224:     }
 225: #ifdef PXP
 226:     commincl(cp, ch);
 227:     if (noinclude)
 228:         return (1);
 229: #endif
 230:     inclev++;
 231:     if (inclev > MAXINC) {
 232:         line = yyline;
 233:         error("Absurdly deep include nesting - QUIT");
 234:         pexit(DIED);
 235:     }
 236:     ip = &incs[inclev];
 237:     ip->filename = filename;
 238:     filename = savestr(cp);
 239:     cp = alloc(518);
 240:     if (cp == -1) {
 241:         error("Ran out of memory (include)");
 242:         pexit(DIED);
 243:     }
 244:     if (fopen(filename, cp) < 0) {
 245:         perror(filename);
 246:         pexit(DIED);
 247:     }
 248:     if (inpflist(filename)) {
 249: #ifdef PI
 250:         opush('l');
 251: #endif
 252: #ifdef PXP
 253:         opush('z');
 254: #endif
 255:     }
 256:     ip->Printed = printed;
 257:     printed = 0;
 258:     ip->yyline = yyline;
 259:     yyline = 0;
 260:     ip->yyLinpt = yyLinpt;
 261:     yyLinpt = 0;
 262:     ip->ibp = ibp;
 263:     ibp = cp;
 264:     return (1);
 265: }
 266: 
 267: skipbl(ocp)
 268:     char *ocp;
 269: {
 270:     register char *cp;
 271: 
 272:     cp = ocp;
 273:     while (*cp == ' ' || *cp == '\t')
 274:         cp++;
 275:     return (cp);
 276: }
 277: 
 278: 
 279: /*
 280:  * At the end of an include,
 281:  * close the file, free the input buffer,
 282:  * and restore the environment before
 283:  * the "push", including the value of
 284:  * the z option for pxp and the l option for pi.
 285:  */
 286: uninclud()
 287: {
 288:     register struct inc *ip;
 289: 
 290:     if (inclev < 0)
 291:         return (0);
 292:     close(ibp[0]);
 293:     free(ibp);
 294:     ip = &incs[inclev];
 295:     ibp = ip->ibp;
 296:     yyline = ip->yyline;
 297:     if (inpflist(filename)) {
 298: #ifdef PI
 299:         opop('l');
 300: #endif
 301: #ifdef PXP
 302:         opop('z');
 303: #endif
 304:     }
 305:     filename = ip->filename;
 306:     yyLinpt = ip->yyLinpt;
 307:     /*
 308: 	 * If we printed out the nested name,
 309: 	 * then we should print all covered names again.
 310: 	 * If we didn't print out the nested name
 311: 	 * we print the uncovered name only if it
 312: 	 * has not been printed before (unstack).
 313: 	 */
 314:     if (printed) {
 315:         printed = 0;
 316:         while (ip >= incs) {
 317:             ip->Printed = 0;
 318:             ip--;
 319:         }
 320:     } else
 321:         printed = ip->Printed;
 322:     inclev--;
 323:     return (1);
 324: }

Defined functions

getchar defined in line 29; used 25 times
getline defined in line 102; used 2 times
includ defined in line 179; used 1 times
skipbl defined in line 267; used 2 times
uninclud defined in line 286; used 1 times

Defined variables

bufp defined in line 88; used 4 times
charbuf defined in line 86; used 10 times
ibp defined in line 63; used 9 times
inclev defined in line 77; used 6 times
incs defined in line 73; used 3 times
yyLinpt defined in line 95; used 8 times
yycol defined in line 87; used 4 times
yytokcnt defined in line 19; used 1 times
  • in line 35

Defined struct's

inc defined in line 67; used 4 times

Defined macros

MAXINC defined in line 65; used 2 times
Last modified: 1986-06-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3083
Valid CSS Valid XHTML 1.0 Strict