1: /* parse.c
   2:  *
   3:  * Copyright (c) 1984, 1985 Xerox Corp.
   4:  *
   5:  *  Items are left on the stack when execution finishes.
   6:  *
   7:  *  pop() can be used to remove items from the stack.
   8:  *  Please remember to free() any item you pop off the stack.
   9:  *
  10:  *
  11:  * HISTORY
  12:  *
  13:  * K. Knox, 28-Mar-85 18:26:50, Created first version.
  14:  *
  15:  */
  16: 
  17: #include <stdio.h>
  18: #include <iptokens.h>
  19: 
  20: FILE *fp;
  21: long filepos = 0;
  22: 
  23: 
  24: #define len_IP_header 40
  25: 
  26: #define token_id          0340
  27: #define token_mask        0037
  28: #define token_short_op    0200
  29: #define token_long_op     0240
  30: #define token_short_seq   0300
  31: #define token_long_seq    0340
  32: 
  33: parse(fpin)
  34:   FILE *fpin;
  35:   {
  36:   /* variables */
  37:   int c, len;
  38:   char  string[len_IP_header+1],
  39:        *ptr;
  40:   int last = 0;
  41:   int seq,
  42:       hlen;
  43: 
  44:   /* Get the header. */
  45:   fp = fpin;
  46: 
  47:   /* get the header */
  48:   for (hlen = 0, ptr = string; hlen < len_IP_header; hlen++)
  49:     if ( (*ptr++ = getc(fp)) == ' ' )
  50:     break;
  51: 
  52:   *ptr = '\0';
  53: 
  54:   header(string);
  55: 
  56:   /* Analyze every token in the file. */
  57:   while ((c = getc(fp)) != EOF)
  58:     {
  59:     filepos = ftell(fp)-1;
  60:     switch (c & token_id)
  61:       {
  62:       case token_short_op:        /* Only allowed short op is "nop". */
  63:         len = c & token_mask;
  64:         operator(len);
  65:     last = 0;
  66:         break;
  67:       case token_long_op:
  68:         len = getc(fp)+((c & token_mask) << 8);
  69:         if (operator(len)) return;      /* Quit when you hit endBlock. */
  70:     last = 0;
  71:         break;
  72:       case token_short_seq:
  73:         len = getc(fp);
  74:     seq = c & token_mask;
  75:         sequence(seq, len, last);
  76:     if (seq != sequenceContinued) last = seq;
  77:         break;
  78:       case token_long_seq:
  79:         len = getc(fp) << 16;
  80:         len = len+(getc(fp) << 8);
  81:         len = len+getc(fp);
  82:     seq = c & token_mask;
  83:         sequence(seq, len, last);
  84:     if (seq != sequenceContinued) last = seq;
  85:         break;
  86:       default:
  87:         shortnum((c << 8)+getc(fp)-INTEGER_ZERO);
  88:     last = 0;
  89:         break;
  90:       }
  91:     }
  92:   /* Shouldn't get here if file ends properly! */
  93:   fprintf(stderr, "(%d) Unexpected EOF\n", filepos);
  94:   exit(2);
  95:   }
  96: 
  97: 
  98: #ifndef debug
  99: operator(op)
 100:   int op;
 101:   {
 102:   switch (op)
 103:     {
 104:     case OP_makevec:                 op_makevec();                break;
 105:     case OP_makeveclu:               op_makeveclu();             break;
 106:     case OP_rotate:                  op_rotate();                 break;
 107:     case OP_scale:                   op_scale();                  break;
 108:     case OP_scale2:                  op_scale2();                 break;
 109:     case OP_concat:                  op_concat();                 break;
 110:     case OP_beginBlock:              op_beginblock();             break;
 111:     case OP_endBlock:                op_endblock();               return(1);
 112:     case OP_beginBody:           op_beginbody();          break;
 113:     case OP_endBody:             op_endbody();        break;
 114:     default:                         op_unknown(op);              break;
 115:     }
 116:   return (0);
 117:   }
 118: 
 119: sequence(type, len, last)
 120:   int type, len, last;
 121:   {
 122:   switch (type)
 123:     {
 124:     case sequenceComment:               seq_comment(len);           break;
 125:     case sequenceIdentifier:            seq_identifier(len);        break;
 126:     case sequenceInteger:               seq_integer(len);           break;
 127:     case sequenceLargeVector:           seq_largevector(len);       break;
 128:     case sequenceRational:              seq_rational(len);          break;
 129:     case sequenceString:                seq_string(len);            break;
 130:     default:                            seq_unknown(type, len);     break;
 131:     }
 132:   }
 133: 
 134: #else
 135: operator(op)
 136:   int op;
 137:   {
 138:   switch (op)
 139:     {
 140:     case OP_makevec:
 141:       fprintf(stderr, "op_makevec\n");
 142:       op_makevec();
 143:       break;
 144:     case OP_do:
 145:       fprintf(stderr, "op_do\n");
 146:       op_do();
 147:       break;
 148:     case OP_pop:
 149:       fprintf(stderr, "op_pop\n");
 150:       op_pop();
 151:       break;
 152:     case OP_copy:
 153:       fprintf(stderr, "op_copy\n");
 154:       op_copy();
 155:       break;
 156:     case OP_dup:
 157:       fprintf(stderr, "op_dup\n");
 158:       op_dup();
 159:       break;
 160:     case OP_roll:
 161:       fprintf(stderr, "op_roll\n");
 162:       op_roll();
 163:       break;
 164:     case OP_exch:
 165:       fprintf(stderr, "op_exch\n");
 166:       op_exch();
 167:       break;
 168:     case OP_nop:
 169:       fprintf(stderr, "op_nop\n");
 170:       op_nop();
 171:       break;
 172:     case OP_translate:
 173:       fprintf(stderr, "op_translate\n");
 174:       op_translate();
 175:       break;
 176:     case OP_rotate:
 177:       fprintf(stderr, "op_rotate\n");
 178:       op_rotate();
 179:       break;
 180:     case OP_scale:
 181:       fprintf(stderr, "op_scale\n");
 182:       op_scale();
 183:       break;
 184:     case OP_scale2:
 185:       fprintf(stderr, "op_scale2\n");
 186:       op_scale2();
 187:       break;
 188:     case OP_concat:
 189:       fprintf(stderr, "op_concat\n");
 190:       op_concat();
 191:       break;
 192:     case OP_makepixelarray:
 193:       fprintf(stderr, "op_makepixelarray\n");
 194:       op_makepixelarray();
 195:       break;
 196:     case OP_extractpixelarray:
 197:       fprintf(stderr, "op_extractpixelarray\n");
 198:       op_extractpixelarray();
 199:       break;
 200:     case OP_finddecompressor:
 201:       fprintf(stderr, "op_finddecompressor\n");
 202:       op_finddecompressor();
 203:       break;
 204:     case OP_makegray:
 205:       fprintf(stderr, "op_makegray\n");
 206:       op_makegray();
 207:       break;
 208:     case OP_findcolor:
 209:       fprintf(stderr, "op_findcolor\n");
 210:       op_findcolor();
 211:       break;
 212:     case OP_findcoloroperator:
 213:       fprintf(stderr, "op_findcoloroperator\n");
 214:       op_findcoloroperator();
 215:       break;
 216:     case OP_findcolormodeloperator:
 217:       fprintf(stderr, "op_findcolormodeloperator\n");
 218:       op_findcolormodeloperator();
 219:       break;
 220:     case OP_beginBlock:
 221:       fprintf(stderr, "op_beginblock\n");
 222:       op_beginblock();
 223:       break;
 224:     case OP_endBlock:
 225:       fprintf(stderr, "op_endblock\n");
 226:       op_endblock();
 227:       return(1);
 228:     case OP_beginBody:           ;                break;
 229:     case OP_endBody:             ;                break;
 230:     default:
 231:       fprintf(stderr, "op_unknown\n");
 232:       op_unknown(op);
 233:       break;
 234:     }
 235:   return (0);
 236:   }
 237: 
 238: sequence(type, len, last)
 239:   int type, len, last;
 240:   {
 241:   switch (type)
 242:     {
 243:     case sequenceAdaptivePixelVector:
 244:       fprintf(stderr, "seq_adaptivepixel\n");
 245:       seq_adaptivepixel(len);
 246:       break;
 247:     case sequenceComment:
 248:       fprintf(stderr, "seq_comment\n");
 249:       seq_comment(len);
 250:       break;
 251:     case sequenceCompressedPixelVector:
 252:       fprintf(stderr, "seq_compressedpixel\n");
 253:       seq_compressedpixel(len);
 254:       break;
 255:     case sequenceContinued:
 256:       fprintf(stderr, "seq_continued\n");
 257:       break;
 258:     case sequenceIdentifier:
 259:       fprintf(stderr, "seq_identifier\n");
 260:       seq_identifier(len);
 261:       break;
 262:     case sequenceInsertFile:
 263:       fprintf(stderr, "seq_insertfile\n");
 264:       seq_insertfile(len);
 265:       break;
 266:     case sequenceInteger:
 267:       fprintf(stderr, "seq_integer\n");
 268:       seq_integer(len);
 269:       break;
 270:     case sequenceLargeVector:
 271:       fprintf(stderr, "seq_largevector\n");
 272:       seq_largevector(len);
 273:       break;
 274:     case sequencePackedPixelVector:
 275:       fprintf(stderr, "seq_packedpixel\n");
 276:       seq_packedpixel(len);
 277:       break;
 278:     case sequenceRational:
 279:       fprintf(stderr, "seq_rational\n");
 280:       seq_rational(len);
 281:       break;
 282:     case sequenceString:
 283:       fprintf(stderr, "seq_string\n");
 284:       seq_string(len);
 285:       break;
 286:     default:
 287:       fprintf(stderr, "seq_unknown\n");
 288:       seq_unknown(type, len);
 289:       break;
 290:     }
 291:   }
 292: 
 293: #endif

Defined functions

operator defined in line 135; used 2 times
parse defined in line 33; used 1 times
sequence defined in line 238; used 2 times

Defined variables

Defined macros

len_IP_header defined in line 24; used 2 times
token_id defined in line 26; used 1 times
  • in line 60
token_long_op defined in line 29; never used
token_long_seq defined in line 31; never used
token_mask defined in line 27; used 4 times
token_short_op defined in line 28; never used
token_short_seq defined in line 30; never used
Last modified: 1986-01-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1135
Valid CSS Valid XHTML 1.0 Strict