Annotation of 43BSD/contrib/dipress/src/bin/ipmetrics/execute.c, revision 1.1

1.1     ! root        1: /* execute.c
        !             2:  *
        !             3:  * Copyright (c) 1984, 1985 Xerox Corp.
        !             4:  *
        !             5:  *  Define the functions used in parse.c.
        !             6:  *
        !             7:  * Execute the RES file and leave the correct parameters on the stack.
        !             8:  *
        !             9:  * HISTORY
        !            10:  *
        !            11:  * K. Knox,  1-Apr-85 23:45:46, Created first version.
        !            12:  * K. Knox, 13-May-85 10:25:25, Fixed bugs in calls to maketransformation.
        !            13:  * K. Knox, 13-May-85 10:25:25, Fixed bug in angle calculation in op_rotate.
        !            14:  *
        !            15:  */
        !            16: 
        !            17: #include <math.h>
        !            18: #include <stdio.h>
        !            19: #include <iptokens.h>
        !            20: #include "stack.h"
        !            21: 
        !            22: #define RES_header "Interpress/Xerox/2.1/RasterEncoding/1.0 "
        !            23: #define len_RES_header 40
        !            24: 
        !            25: #define err0 "(%d) execute: Bad IP header, got %s\n"
        !            26: #define err1 "(%d) execute: roll moveFirst > depth, %d > %d!\n"
        !            27: #define err2 "(%d) execute: unknown operator subtype, got %d!\n"
        !            28: #define err3 "(%d) execute: unknown operator, type=%d!\n"
        !            29: #define err4 "(%d) execute: unknown sequence, type=%d, length=%d!\n"
        !            30: #define err5 "(%d) execute: sequenceInsertFile not implemented!\n"
        !            31: 
        !            32: 
        !            33: /* Defined elsewhere. */
        !            34: extern unsigned char **malloc();
        !            35: extern long filepos;
        !            36: extern FILE *fp;
        !            37: 
        !            38: /* Defined in this module. */
        !            39: extern unsigned char *popidentifier();
        !            40: extern double popdouble();
        !            41: 
        !            42: 
        !            43: /*
        !            44:  * Public procedures defined for "parse" module.
        !            45:  *
        !            46:  */
        !            47: 
        !            48: header(string)
        !            49:   {
        !            50:   if (strncmp(string, RES_header, 10) != 0) error(err0, filepos, string);
        !            51:   }
        !            52: 
        !            53: op_makevec()
        !            54:   {
        !            55:   int n, depth;
        !            56:   unsigned char *ptr, **array;
        !            57:   depth = popint();
        !            58:   array = malloc((depth+1)*sizeof(unsigned char *));   /* null terminated array */
        !            59:   for (n=0; n < depth; n++) array[depth-n-1] = pop(0);
        !            60:   array[depth] = (unsigned char *) 0;
        !            61:   ptr = makevector(array, type_vector, subtype_general);
        !            62:   for (n=0; n < depth; n++) free(array[n]);
        !            63:   free(array);
        !            64:   push(ptr);
        !            65:   }
        !            66: 
        !            67: op_makeveclu()
        !            68:   {
        !            69:   int n, depth,
        !            70:       upper,
        !            71:       lower;
        !            72:   unsigned char *ptr, **array;
        !            73: 
        !            74:   upper = popint();
        !            75:   lower = popint();
        !            76:   depth = upper - lower + 1;
        !            77:   array = malloc((depth+1)*sizeof(unsigned char *));   /* null terminated array */
        !            78:   for (n=0; n < depth; n++)
        !            79:        array[depth-n-1] = pop(0);
        !            80: 
        !            81:   array[depth] = (unsigned char *) 0;
        !            82:   ptr = makevector(array, type_vector, subtype_general);
        !            83:   /* set uppper and lower bounds */
        !            84: 
        !            85:   for (n=0; n < depth; n++)
        !            86:        free(array[n]);
        !            87: 
        !            88:   free(array);
        !            89:   push(ptr);
        !            90:   }
        !            91: 
        !            92: op_rotate()
        !            93:   {
        !            94:   double angle, cosA, sinA, pi;
        !            95:   unsigned char *ptr;
        !            96:   angle = popdouble();
        !            97:   angle = 3.1415926*angle/180.;
        !            98:   cosA = cos(angle);
        !            99:   sinA = sin(angle);
        !           100:   ptr = maketransformation(cosA, -sinA, 0.0, sinA, cosA, 0.0);
        !           101:   push(ptr);
        !           102:   }
        !           103: 
        !           104: op_scale()
        !           105:   {
        !           106:   unsigned char *ptr;
        !           107:   double s;
        !           108:   s = popdouble();
        !           109:   ptr = maketransformation(s, 0.0, 0.0, 0.0, s, 0.0);
        !           110:   push(ptr);
        !           111:   }
        !           112: 
        !           113: op_scale2()
        !           114:   {
        !           115:   unsigned char *ptr;
        !           116:   double sx, sy;
        !           117:   sy = popdouble();
        !           118:   sx = popdouble();
        !           119:   ptr = maketransformation(sx, 0.0, 0.0, 0.0, sy, 0.0);
        !           120:   push(ptr);
        !           121:   }
        !           122: 
        !           123: op_concat()
        !           124:   {
        !           125:   double a, b, c, d, e, f;
        !           126:   unsigned char *ptr, *nptr, *mptr;
        !           127:   double *m, *n;
        !           128:   nptr = pop(type_transformation, 0);
        !           129:   mptr = pop(type_transformation, 0);
        !           130:   n = gettransformation(nptr);
        !           131:   m = gettransformation(mptr);
        !           132:   a = m[0]*n[0]+m[3]*n[1];
        !           133:   b = m[1]*n[0]+m[4]*n[1];
        !           134:   c = m[2]*n[0]+m[5]*n[1]+n[2];
        !           135:   d = m[0]*n[3]+m[3]*n[4];
        !           136:   e = m[1]*n[3]+m[4]*n[4];
        !           137:   f = m[2]*n[3]+m[5]*n[4]+n[5];
        !           138:   ptr = maketransformation(a, b, c, d, e, f);
        !           139:   free(mptr);
        !           140:   free(nptr);
        !           141:   free(m);
        !           142:   free(n);
        !           143:   push(ptr);
        !           144:   }
        !           145: 
        !           146: op_beginblock()
        !           147:   {
        !           148:   }
        !           149: 
        !           150: op_endblock()
        !           151:   {
        !           152:   }
        !           153: 
        !           154: op_beginbody()
        !           155:   {
        !           156:   }
        !           157: 
        !           158: op_endbody()
        !           159:   {
        !           160:   }
        !           161: 
        !           162: op_unknown(op)
        !           163:   int op;
        !           164:   {
        !           165:   error(err3, filepos, op);
        !           166:   }
        !           167: 
        !           168: seq_comment(nbytes)
        !           169:   int nbytes;
        !           170:   {
        !           171:   fseek(fp, (long) nbytes, 1);
        !           172:   }
        !           173: 
        !           174: seq_largevector(nbytes)
        !           175:   int nbytes;
        !           176:   {
        !           177:   int b;
        !           178:   long bytepos, bytelength;
        !           179:   unsigned char *ptr, **array;
        !           180:   b = getc(fp) & 0377;    /* read the number of bytes/integer. */
        !           181:   bytepos = ftell(fp);
        !           182:   bytelength = nbytes-1;
        !           183:   array = malloc(2*sizeof(unsigned char *));
        !           184:   array[0] = makeintegers(b, bytepos, bytelength);
        !           185:   array[1] = (unsigned char *) 0;
        !           186:   ptr = makevector(array, type_vector, subtype_integers);
        !           187:   fseek(fp, bytelength, 1);
        !           188:   free(array[0]);
        !           189:   free(array);
        !           190:   push(ptr);
        !           191:   }
        !           192: 
        !           193: seq_identifier(nbytes)
        !           194:   int nbytes;
        !           195:   {
        !           196:   pushstring(nbytes, subtype_identifier);
        !           197:   }
        !           198: 
        !           199: seq_string(nbytes)
        !           200:   int nbytes;
        !           201:   {
        !           202:   pushstring(nbytes, subtype_string);
        !           203:   }
        !           204: 
        !           205: seq_unknown(type, nbytes)
        !           206:   int type, nbytes;
        !           207:   {
        !           208:   error(err4, filepos, type, nbytes);
        !           209:   }
        !           210:  
        !           211: seq_integer(nbytes)
        !           212:   int nbytes;
        !           213:   {
        !           214:   pushinteger(nbytes, subtype_integer);
        !           215:   }
        !           216: 
        !           217: seq_rational(nbytes)
        !           218:   int nbytes;
        !           219:   {
        !           220:   pushinteger(nbytes, subtype_rational);
        !           221:   }
        !           222: 
        !           223: shortnum(number)
        !           224:   int number;
        !           225:   {
        !           226:   unsigned char value[2];
        !           227:   unsigned char *ptr;
        !           228:   value[0] = (number >> 8) & 0377;
        !           229:   value[1] = number & 0377;
        !           230:   ptr = makenumber(2, value, subtype_integer);
        !           231:   push(ptr);
        !           232:   }
        !           233: 
        !           234: 
        !           235: /*
        !           236:  * Private procedures to this module.
        !           237:  *
        !           238:  */
        !           239: 
        !           240: static pushinteger(nbytes, subtype)
        !           241:   int nbytes, subtype;
        !           242:   {
        !           243:   int n;
        !           244:   unsigned char *ptr;
        !           245:   unsigned char *array;
        !           246:   array = (unsigned char *) malloc(nbytes);
        !           247:   for (n=0; n < nbytes; n++) array[n] = getc(fp) & 0377;
        !           248:   ptr = makenumber(nbytes, array, subtype);
        !           249:   free(array);
        !           250:   push(ptr);
        !           251:   }
        !           252: 
        !           253: static pushstring(nbytes, subtype)
        !           254:   int nbytes, subtype;
        !           255:   {
        !           256:   int n;
        !           257:   unsigned char *ptr;
        !           258:   char *string;
        !           259:   string = (char *) malloc(nbytes+1);
        !           260:   for (n=0; n < nbytes; n++) string[n] = getc(fp) & 0377;
        !           261:   string[nbytes] = (char) 0;
        !           262:   ptr = makestring(string, subtype);
        !           263:   free(string);
        !           264:   push(ptr);
        !           265:   }
        !           266: 
        !           267: static popint()
        !           268:   {
        !           269:   int result;
        !           270:   unsigned char *ptr;
        !           271:   ptr = pop(type_number, 0);
        !           272:   result = getint(ptr);
        !           273:   free(ptr);
        !           274:   return(result);
        !           275:   }
        !           276:  
        !           277: static double popdouble()
        !           278:   {
        !           279:   double result;
        !           280:   unsigned char *ptr;
        !           281:   ptr = pop(type_number, 0);
        !           282:   result = getdouble(ptr);
        !           283:   free(ptr);
        !           284:   return(result);
        !           285:   }
        !           286:  
        !           287: static unsigned char *popidentifier(prefix)
        !           288:   char *prefix;   /* should end with '/' character */
        !           289:   {
        !           290:   unsigned char *ptr, *composite;
        !           291:   ptr = pop(type_vector, subtype_general);
        !           292:   composite = makeidentifier(ptr, prefix);
        !           293:   free(ptr);
        !           294:   return(composite);
        !           295:   }
        !           296: 
        !           297: static extendnumber(nbytes)
        !           298:   int nbytes;
        !           299:   {
        !           300:   int n, len;
        !           301:   unsigned char *number, *newnumber;
        !           302:   unsigned char *ptr, *newptr;
        !           303:   ptr = pop(type_number, subtype_integer | subtype_rational);
        !           304:   number = getnumber(ptr);
        !           305:   len = getnumlen(ptr);
        !           306:   newnumber = (unsigned char *) malloc(len+nbytes);
        !           307:   for (n=0; n < len; n++) newnumber[n] = number[n];
        !           308:   for (n=0; n < nbytes; n++) newnumber[n+len] = getc(fp) & 0377;
        !           309:   newptr = makenumber(len+nbytes, newnumber, getsubtype(ptr));
        !           310:   free(ptr);
        !           311:   free(newnumber);
        !           312:   push(newptr);
        !           313:   }
        !           314: 
        !           315: static extendstring(nbytes)
        !           316:   int nbytes;
        !           317:   {
        !           318:   int n, len;
        !           319:   char *string, *newstring;
        !           320:   unsigned char *ptr, *newptr;
        !           321:   ptr = pop(type_string, subtype_identifier | subtype_string);
        !           322:   string = getstring(ptr, 0);
        !           323:   len = strlen(string);
        !           324:   newstring = (char *) malloc(len+nbytes+1);
        !           325:   strcpy(newstring, string);
        !           326:   for (n=0; n < nbytes; n++) newstring[n+len] = getc(fp) & 0377;
        !           327:   newstring[len+nbytes] = (char) 0;
        !           328:   newptr = makestring(newstring, getsubtype(ptr));
        !           329:   free(ptr);
        !           330:   free(newstring);
        !           331:   push(newptr);
        !           332:   }
        !           333: 
        !           334: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.