Annotation of researchv9/jtools/src/cip/readPic.c, revision 1.1.1.1

1.1       root        1: /*
                      2:   %Z%  %M%  version %I% %Q%of %H% %T%
                      3:   Last Delta:  %G% %U% to %P%
                      4: */
                      5: 
                      6: #include "cip.h"
                      7: #define CEOF -1
                      8: char c;
                      9: 
                     10: char *getText();
                     11: Point getPoint();
                     12: struct macro *findMacro();
                     13: 
                     14: extern struct macro *macroList;
                     15: extern Cursor hourglass;
                     16: extern int Xoffset;
                     17: extern int Yoffset;
                     18: 
                     19: struct thing *
                     20: readPic(fp,h) 
                     21: register FILE *fp; 
                     22: register struct thing *h;
                     23: {
                     24:   register struct thing *t, *l;
                     25:   struct macro *m;
                     26:   Rectangle r;
                     27:   register int num, i, a , b;
                     28:   Point *plist, p, q;
                     29:   register char *s, type;
                     30:   
                     31:   while ( c != CEOF) {
                     32:     t = TNULL;
                     33:     type = c;
                     34:     getChar(fp);
                     35:     switch(type) {
                     36:       case CEOF:
                     37:       case ' ':
                     38:       case '\n':
                     39:       case '\t': {
                     40:        break;
                     41:       }
                     42:       case 'm': {      /* moveto */
                     43:        p = getPoint(fp);
                     44:        break;
                     45:       }
                     46:       case 'e':        {       /* ellipse */
                     47:        p = getPoint(fp);
                     48:        if ((t = newEllipse(p)) == TNULL) {
                     49:          c = CEOF;             /* Terminate */
                     50:        }
                     51:        else {
                     52:          t->otherValues.ellipse.wid = (getInt(fp))<<1;
                     53:          t->otherValues.ellipse.ht = (getInt(fp))<<1;
                     54:        }
                     55:        break;
                     56:       }
                     57:       case 'c':        {       /* circle */
                     58:        p = getPoint(fp);
                     59:        if ((t = newCircle(p)) == TNULL) {
                     60:          c = CEOF;
                     61:        }
                     62:        else {
                     63:          t->otherValues.radius = getInt(fp);
                     64:        }
                     65:        break;
                     66:       }
                     67:       case 'a': {      /* arc */
                     68:        p = getPoint(fp);
                     69:        q = getPoint(fp);
                     70:        if ((t = newArc(q,getPoint(fp))) == TNULL) {
                     71:          c = CEOF;             /* Terminate */
                     72:        }
                     73:        else {
                     74:          t->origin = p;
                     75:        }
                     76:        break;
                     77:       }
                     78:       case 'l':        {       /* line */
                     79:        a=0;
                     80:        skipWhiteSpace(fp);
                     81:        if (c=='<') {
                     82:          a += startARROW;      
                     83:          getChar(fp);
                     84:        }
                     85:        if (c=='>') {
                     86:          a += endARROW;        
                     87:          getChar(fp);
                     88:        }
                     89:        if (c=='.' || c=='-') {
                     90:          b = (c=='.')? DOTTED : DASHED;
                     91:          getChar(fp);
                     92:          getInt(fp); /*size*/
                     93:        }
                     94:        else {
                     95:          b = SOLID;
                     96:        }
                     97:        num =  getInt(fp);
                     98:        q = getPoint(fp);
                     99:        for (i=1; i<num; i++) {
                    100:          p = getPoint(fp);
                    101:          if ((t = newLine(q,p)) == TNULL) {
                    102:            c = CEOF;           /* Terminate */
                    103:            break;
                    104:          }
                    105:          t->boorder = b;
                    106:          t->arrow = a;
                    107:          BoundingBox(t);
                    108:          draw(t,Pt(Xmin,YPIC));
                    109:          h = insert(t,h);
                    110:          q = p;
                    111:        }
                    112:        break;
                    113:       }
                    114:       case 'b':        {       /* box */
                    115:        if (c=='.' || c=='-') {
                    116:          a = (c=='.')? DOTTED : DASHED;
                    117:          getChar(fp);
                    118:          getInt(fp); /*size*/
                    119:        }
                    120:        else {
                    121:          a = SOLID;
                    122:        }
                    123:        p = getPoint(fp);
                    124:        q = getPoint(fp);
                    125:        if ((t = newBox(canon (p, q))) == TNULL) {
                    126:          c = CEOF;             /* terminate */
                    127:        }
                    128:        else {
                    129:          t->boorder = a;
                    130:        }
                    131:        break;
                    132:       }
                    133:       case 't': {      /* text */
                    134:        if (c!='c') {
                    135:          p = getPoint(fp);
                    136:          skipWhiteSpace(fp);
                    137:          type = c;
                    138:          getChar(fp);
                    139:          s = getText(fp,'\n');
                    140:          if ((t = newText(p,s)) == TNULL) {
                    141:            c = CEOF;           /* Terminate */
                    142:          }
                    143:          else {
                    144:            extractFontandPointSize(t);
                    145: 
                    146:            t->origin.y -= (fontheight(t->otherValues.text.f->f)>>1);
                    147:            BoundingBox(t);
                    148:            switch(type) {
                    149:              case 'C':
                    150:              case 'c': {
                    151:                t->otherValues.text.just = CENTER;
                    152:                break;
                    153:              }
                    154:              case 'L':
                    155:              case 'l': {
                    156:                t->otherValues.text.just = LEFTJUST;
                    157:                break;
                    158:              }
                    159:              case 'R':
                    160:              case 'r': {
                    161:                t->otherValues.text.just = RIGHTJUST;
                    162:                break;
                    163:              }
                    164:            }
                    165:          }
                    166:        }
                    167:        break;
                    168:       }
                    169:       case '~': {
                    170:        a = 0;
                    171:        skipWhiteSpace(fp);
                    172:        if (c=='<') {
                    173:          a += startARROW;      
                    174:          getChar(fp);
                    175:        }
                    176:        if (c=='>') {
                    177:          a += endARROW;        
                    178:          getChar(fp);
                    179:        }
                    180:        num = getInt(fp);
                    181:        plist= (Point *) getSpace((num+3)*sizeof(Point));
                    182:        if (plist==(Point *) NULL) {
                    183:          c = CEOF;             /* Terminate */
                    184:          break;
                    185:        }
                    186:        for (i=1; i<=num; i++) {
                    187:          plist[i]=getPoint(fp);
                    188:        }
                    189:        plist[num+1]=plist[num];
                    190:        if ((t = newSpline(num+1,num,plist)) == TNULL) {
                    191:          c = CEOF;
                    192:        }
                    193:        else {
                    194:          t->arrow = a;
                    195:        }
                    196:        break;
                    197:       }
                    198:       case '.': {
                    199:        switch (c) {
                    200:          case 'P': {
                    201:            cursswitch ((Word *)NULL);
                    202:            getBox (fp,h);      /* Get x and y offsets */
                    203:            cursswitch (&hourglass);
                    204:            break;
                    205:          }
                    206:          case 'U':
                    207:          case 'u': {
                    208:            /* start of macro */
                    209:            getChar(fp);
                    210:            skipWhiteSpace(fp);
                    211:            s = getText(fp,' ');
                    212:            flushLine(fp);
                    213:            l = readPic(fp,TNULL);
                    214:            r = macroBB(l);
                    215:            if ((m=findMacro(s))==(struct macro *)NULL) {
                    216:              if ((t=l)!=TNULL) {
                    217:                do {
                    218:                  makeRelative(t,r.origin);
                    219:                  t = t->next;
                    220:                } while (t != l);
                    221:              }
                    222:              m=recordMacro(l,rsubp(r,r.origin),NULL,NULL,s);
                    223:            }
                    224:            t = newMacro(r.origin,m);
                    225:            break;
                    226:          }
                    227:          case 'E':
                    228:          case 'e': {
                    229:            /* end of macro */
                    230:            flushLine(fp);
                    231:            return(h);
                    232:            break;
                    233:          }
                    234:          default: {
                    235:            flushLine(fp);
                    236:            break;
                    237:          }
                    238:        }
                    239:        break;
                    240:       }
                    241:       default: {
                    242:        flushLine(fp);
                    243:        break;
                    244:       }
                    245:     }
                    246:     if ((t != TNULL) && (t->type != LINE)) {
                    247:       BoundingBox(t);
                    248:       if (t->type != MACRO) {
                    249:        draw(t,Pt(Xmin,YPIC));
                    250:       }
                    251:       h = insert(t,h);
                    252:     }
                    253:   }
                    254:   return(h);
                    255: }
                    256: 
                    257: getBox (fp, h)
                    258: FILE *fp;
                    259: struct thing *h;
                    260: {
                    261:   int height, width;
                    262:   Rectangle r;
                    263:   Point offset;
                    264: 
                    265:   getChar(fp);
                    266:   getChar(fp);
                    267:   height = getInt (fp);
                    268:   width = getInt (fp);
                    269:   Yoffset = (YPicSize-height)>>1;
                    270:   Xoffset = (XPicSize-width)>>1;
                    271:   r.origin.x = Xoffset;
                    272:   r.origin.y = Yoffset;
                    273:   r.corner.x = Xoffset + width;
                    274:   r.corner.y = Yoffset + height;
                    275:   offset.x = Xmin;
                    276:   offset.y = YPIC;
                    277: 
                    278:   cursset (raddp(r,offset));
                    279:   xbox (raddp(r,offset));      /* Show the box on the screen */
                    280: 
                    281:   changeButtons (READbuttons);
                    282:   while (!button12 () || button3()) {
                    283:     wait (MOUSE);
                    284:   }
                    285:   if (button2 ()) {
                    286:     r = moveBox (r.origin, r, h, offset);
                    287:     Xoffset = r.origin.x;
                    288:     Yoffset = r.origin.y;
                    289:   }
                    290:   xbox (raddp(r,offset));      /* Remove the box */
                    291:   changeButtons (BLANKbuttons);
                    292: }
                    293: 
                    294: Point 
                    295: getPoint(f) 
                    296: FILE *f;
                    297: {
                    298:   Point p;
                    299: 
                    300:   p.x = getInt(f) + Xoffset;
                    301:   p.y = getInt(f) + Yoffset;
                    302:   return(p);
                    303: }
                    304: 
                    305: int 
                    306: getInt(f) 
                    307: FILE *f;
                    308: {
                    309:   register int i;
                    310: 
                    311:   skipWhiteSpace(f);
                    312:   i=0;
                    313:   while (c >= '0' && c<='9' ) {
                    314:     i = 10 * i + c - '0';
                    315:     getChar(f);
                    316:   } 
                    317:   return(i);
                    318: }
                    319: 
                    320: getChar(f) 
                    321: FILE *f;
                    322: {      
                    323:   c = getc(f);
                    324: }
                    325: 
                    326: skipWhiteSpace(f) 
                    327: FILE *f;
                    328: {
                    329:   while( c==' ' || c=='\t' ) getChar(f);
                    330: }
                    331: 
                    332: char *
                    333: getText(f,term) 
                    334: FILE *f; 
                    335: register char term;
                    336: {
                    337:   register char s[MAXTEXT]; 
                    338:   register char *ss, *t, *tt; 
                    339:   register int i;
                    340: 
                    341:   for (i=0; c != term; getChar(f)) {
                    342:     if (i < MAXTEXT) {
                    343:       s[i++]=c;
                    344:     }
                    345:   }
                    346:   s[i]=0;
                    347:   if ((t = (char *) getSpace(strlen(s)))==NULL) {
                    348:     return( 0 );       
                    349:   }
                    350:   for (ss = s, tt = t; *tt++ = *ss++;) {
                    351:   }
                    352:   getChar(f);
                    353:   return(t);
                    354: }
                    355: 
                    356: flushLine(f) 
                    357: FILE *f;
                    358: {
                    359:   while (c != '\n') {
                    360:     getChar(f);
                    361:   }
                    362:   getChar(f);
                    363: }
                    364: 
                    365: struct macro *
                    366: findMacro(s) 
                    367: register char *s;
                    368: {
                    369:   struct macro *m;
                    370: 
                    371:   for (m=macroList; ((m!=(struct macro *)NULL) &&
                    372:        (compare(s,m->name)==0)); m=m->next) ;
                    373:   return(m);
                    374: }
                    375: 
                    376: int 
                    377: compare(s1,s2) 
                    378: register char *s1, *s2;
                    379: {
                    380:   while ( *s1!='\0' && *s2!='\0' && *s1==*s2) {
                    381:     s1++; s2++;
                    382:   }
                    383:   return( (*s1=='\0' && *s2=='\0')?1:0 );
                    384: }
                    385: 
                    386: extractFontandPointSize(t) 
                    387: register struct thing *t;
                    388: {
                    389:   register short ps;
                    390:   register int f, i, j, len; 
                    391:   register char *s;
                    392: 
                    393:   s = t->otherValues.text.s;
                    394:   len = strlen(s);
                    395:   if (compare(&s[len-6],"\\f1\\s0") && s[0]=='\\' && s[1]=='f') {
                    396:     switch(s[2]) {
                    397:       case '1':
                    398:       case 'R': {
                    399:        f = ROMAN;
                    400:        break;  
                    401:       }
                    402:       case '2':
                    403:       case 'I': {
                    404:        f = ITALIC;
                    405:        break;  
                    406:       }
                    407:       case '3':
                    408:       case 'B': {
                    409:        f = BOLD;
                    410:        break;  
                    411:       }
                    412:       default: {
                    413:        f = ROMAN;
                    414:        break;
                    415:       }
                    416:     }
                    417:     ps = s[5] - '0';
                    418:     if (isdigit(s[6])) {
                    419:       ps = ps*10 + s[6] - '0';
                    420:       i = 7;           /* Skip over \f1\snn */
                    421:     }
                    422:     else {
                    423:       i = 6;           /* Skip over \f1\sn */
                    424:     }
                    425:     if (s[i] == '\\' && s[i+1] == '&') {
                    426:       i += 2;          /* Skip over \& */
                    427:     }
                    428:     for (j=0; i<len-6; ) {
                    429:       s[j++] = s[i++];
                    430:     }
                    431:     s[j] = '\0';
                    432:     t->otherValues.text.f = findFont(ps,f);
                    433:   }
                    434: }              

unix.superglobalmegacorp.com

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