Annotation of researchv9/cmd/pic/blockgen.c, revision 1.1.1.1

1.1       root        1: #include       <stdio.h>
                      2: #include       "pic.h"
                      3: #include       "y.tab.h"
                      4: 
                      5: #define        NBRACK  20      /* depth of [...] */
                      6: #define        NBRACE  20      /* depth of {...} */
                      7: 
                      8: struct pushstack stack[NBRACK];
                      9: int    nstack  = 0;
                     10: struct pushstack bracestack[NBRACE];
                     11: int    nbstack = 0;
                     12: 
                     13: obj *leftthing(c)      /* called for {... or [... */
                     14:                        /* really ought to be separate functions */
                     15:        int c;
                     16: {
                     17:        obj *p;
                     18: 
                     19:        if (c == '[') {
                     20:                if (nstack >= NBRACK)
                     21:                        fatal("[...] nested too deep");
                     22:                stack[nstack].p_x = curx;
                     23:                stack[nstack].p_y = cury;
                     24:                stack[nstack].p_hvmode = hvmode;
                     25:                curx = cury = 0;
                     26:                stack[nstack].p_xmin = xmin;
                     27:                stack[nstack].p_xmax = xmax;
                     28:                stack[nstack].p_ymin = ymin;
                     29:                stack[nstack].p_ymax = ymax;
                     30:                nstack++;
                     31:                xmin = ymin = 30000;
                     32:                xmax = ymax = -30000;
                     33:                p = makenode(BLOCK, 7);
                     34:                p->o_val[4] = nobj;     /* 1st item within [...] */
                     35:                if (p->o_nobj != nobj-1)
                     36:                        fprintf(stderr, "nobjs wrong%d %d\n", p->o_nobj, nobj);
                     37:        } else {
                     38:                if (nbstack >= NBRACK)
                     39:                        fatal("{...} nested too deep");
                     40:                bracestack[nbstack].p_x = curx;
                     41:                bracestack[nbstack].p_y = cury;
                     42:                bracestack[nbstack].p_hvmode = hvmode;
                     43:                nbstack++;
                     44:                p = NULL;
                     45:        }
                     46:        return(p);
                     47: }
                     48: 
                     49: obj *rightthing(p, c)  /* called for ... ] or ... } */
                     50:        obj *p;
                     51: {
                     52:        obj *q;
                     53: 
                     54:        if (c == '}') {
                     55:                nbstack--;
                     56:                curx = bracestack[nbstack].p_x;
                     57:                cury = bracestack[nbstack].p_y;
                     58:                hvmode = bracestack[nbstack].p_hvmode;
                     59:                q = makenode(MOVE, 0);
                     60:                dprintf("M %g %g\n", curx, cury);
                     61:        } else {
                     62:                nstack--;
                     63:                curx = stack[nstack].p_x;
                     64:                cury = stack[nstack].p_y;
                     65:                hvmode = stack[nstack].p_hvmode;
                     66:                q = makenode(BLOCKEND, 7);
                     67:                q->o_val[4] = p->o_nobj + 1;    /* back pointer */
                     68:                p->o_val[5] = q->o_nobj - 1;    /* forward pointer */
                     69:                p->o_val[0] = xmin; p->o_val[1] = ymin;
                     70:                p->o_val[2] = xmax; p->o_val[3] = ymax;
                     71:                p->o_symtab = q->o_symtab = stack[nstack+1].p_symtab;
                     72:                xmin = stack[nstack].p_xmin;
                     73:                ymin = stack[nstack].p_ymin;
                     74:                xmax = stack[nstack].p_xmax;
                     75:                ymax = stack[nstack].p_ymax;
                     76:        }
                     77:        return(q);
                     78: }
                     79: 
                     80: obj *blockgen(p, type, q)      /* handles [...] */
                     81:        obj *p, *q;
                     82:        int type;
                     83: {
                     84:        int i, invis, at, ddtype, with;
                     85:        float ddval, h, w, xwith, ywith;
                     86:        float x0, y0, x1, y1, cx, cy;
                     87:        obj *ppos;
                     88:        Attr *ap;
                     89: 
                     90:        invis = at = 0;
                     91:        with = xwith = ywith = 0;
                     92:        ddtype = ddval = 0;
                     93:        w = p->o_val[2] - p->o_val[0];
                     94:        h = p->o_val[3] - p->o_val[1];
                     95:        cx = (p->o_val[2] + p->o_val[0]) / 2;   /* geom ctr of [] wrt local orogin */
                     96:        cy = (p->o_val[3] + p->o_val[1]) / 2;
                     97:        dprintf("cx,cy=%g,%g\n", cx, cy);
                     98:        for (i = 0; i < nattr; i++) {
                     99:                ap = &attr[i];
                    100:                switch (ap->a_type) {
                    101:                case HEIGHT:
                    102:                        h = ap->a_val.f;
                    103:                        break;
                    104:                case WIDTH:
                    105:                        w = ap->a_val.f;
                    106:                        break;
                    107:                case WITH:
                    108:                        with = ap->a_val.i;     /* corner */
                    109:                        break;
                    110:                case PLACE:     /* actually with position ... */
                    111:                        ppos = ap->a_val.o;
                    112:                        xwith = cx - ppos->o_x;
                    113:                        ywith = cy - ppos->o_y;
                    114:                        with = PLACE;
                    115:                        break;
                    116:                case AT:
                    117:                case FROM:
                    118:                        ppos = ap->a_val.o;
                    119:                        curx = ppos->o_x;
                    120:                        cury = ppos->o_y;
                    121:                        at++;
                    122:                        break;
                    123:                case INVIS:
                    124:                        invis = INVIS;
                    125:                        break;
                    126:                case TEXTATTR:
                    127:                        savetext(ap->a_sub, ap->a_val.p);
                    128:                        break;
                    129:                }
                    130:        }
                    131:        if (with) {
                    132:                switch (with) {
                    133:                case NORTH:     ywith = -h / 2; break;
                    134:                case SOUTH:     ywith = h / 2; break;
                    135:                case EAST:      xwith = -w / 2; break;
                    136:                case WEST:      xwith = w / 2; break;
                    137:                case NE:        xwith = -w / 2; ywith = -h / 2; break;
                    138:                case SE:        xwith = -w / 2; ywith = h / 2; break;
                    139:                case NW:        xwith = w / 2; ywith = -h / 2; break;
                    140:                case SW:        xwith = w / 2; ywith = h / 2; break;
                    141:                }
                    142:                curx += xwith;
                    143:                cury += ywith;
                    144:        }
                    145:        if (!at) {
                    146:                if (isright(hvmode))
                    147:                        curx += w / 2;
                    148:                else if (isleft(hvmode))
                    149:                        curx -= w / 2;
                    150:                else if (isup(hvmode))
                    151:                        cury += h / 2;
                    152:                else
                    153:                        cury -= h / 2;
                    154:        }
                    155:        x0 = curx - w / 2;
                    156:        y0 = cury - h / 2;
                    157:        x1 = curx + w / 2;
                    158:        y1 = cury + h / 2;
                    159:        extreme(x0, y0);
                    160:        extreme(x1, y1);
                    161:        p->o_x = curx;
                    162:        p->o_y = cury;
                    163:        p->o_nt1 = ntext1;
                    164:        p->o_nt2 = ntext;
                    165:        ntext1 = ntext;
                    166:        p->o_val[0] = w;
                    167:        p->o_val[1] = h;
                    168:        p->o_val[2] = cx;
                    169:        p->o_val[3] = cy;
                    170:        p->o_val[5] = q->o_nobj - 1;            /* last item in [...] */
                    171:        p->o_ddval = ddval;
                    172:        p->o_attr = invis;
                    173:        dprintf("[] %g %g %g %g at %g %g, h=%g, w=%g\n", x0, y0, x1, y1, curx, cury, h, w);
                    174:        if (isright(hvmode))
                    175:                curx = x1;
                    176:        else if (isleft(hvmode))
                    177:                curx = x0;
                    178:        else if (isup(hvmode))
                    179:                cury = y1;
                    180:        else
                    181:                cury = y0;
                    182:        for (i = 0; i <= 5; i++)
                    183:                q->o_val[i] = p->o_val[i];
                    184:        stack[nstack+1].p_symtab = NULL;        /* so won't be found again */
                    185:        blockadj(p);    /* fix up coords for enclosed blocks */
                    186:        return(p);
                    187: }
                    188: 
                    189: blockadj(p)    /* adjust coords in block starting at p */
                    190:        obj *p;
                    191: {
                    192:        obj *q;
                    193:        float dx, dy;
                    194:        int n, lev;
                    195: 
                    196:        dx = p->o_x - p->o_val[2];
                    197:        dy = p->o_y - p->o_val[3];
                    198:        n = p->o_nobj + 1;
                    199:        q = objlist[n];
                    200:        dprintf("into blockadj: dx,dy=%g,%g\n", dx, dy);
                    201:        for (lev = 1; lev > 0; n++) {
                    202:                p = objlist[n];
                    203:                if (p->o_type == BLOCK)
                    204:                        lev++;
                    205:                else if (p->o_type == BLOCKEND)
                    206:                        lev--;
                    207:                dprintf("blockadj: type=%d o_x,y=%g,%g;", p->o_type, p->o_x, p->o_y);
                    208:                p->o_x += dx;
                    209:                p->o_y += dy;
                    210:                dprintf(" becomes %g,%g\n", p->o_x, p->o_y);
                    211:                switch (p->o_type) {    /* other absolute coords */
                    212:                case LINE:
                    213:                case ARROW:
                    214:                case SPLINE:
                    215:                        p->o_val[0] += dx;
                    216:                        p->o_val[1] += dy;
                    217:                        break;
                    218:                case ARC:
                    219:                        p->o_val[0] += dx;
                    220:                        p->o_val[1] += dy;
                    221:                        p->o_val[2] += dx;
                    222:                        p->o_val[3] += dy;
                    223:                        break;
                    224:                }
                    225:        }
                    226: }

unix.superglobalmegacorp.com

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