Annotation of researchv9/jtools/src/Jpic/blockgen.c, revision 1.1

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

unix.superglobalmegacorp.com

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