Annotation of researchv10no/cmd/picasso/blockgen.c, revision 1.1

1.1     ! root        1: /*     Copyright (c) 1988 AT&T */
        !             2: /*       All Rights Reserved   */
        !             3: 
        !             4: /*     THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T     */
        !             5: /*     The copyright notice above does not evidence any        */
        !             6: /*     actual or intended publication of such source code.     */
        !             7: 
        !             8: /*     @(#)picasso:blockgen.c  1.0     */
        !             9: #include       "picasso.h"
        !            10: #include       "y.tab.h"
        !            11: 
        !            12: #define        NBRACK  20      /* depth of [...] */
        !            13: #define        NBRACE  20      /* depth of {...} */
        !            14: 
        !            15: struct pushstack stack[NBRACK];
        !            16: int    nstack  = 0;
        !            17: struct pushstack bracestack[NBRACE];
        !            18: int    nbstack = 0;
        !            19: obj    *cur_block = (obj *)0;
        !            20: 
        !            21: obj *leftthing(c)      /* called for {... or [... */
        !            22:                        /* really ought to be separate functions */
        !            23:        int c;
        !            24: {
        !            25:        obj *p;
        !            26: 
        !            27:        if (c == '[') {
        !            28:                if (nstack >= NBRACK)
        !            29:                        fatal("[...] nested too deep");
        !            30:                stack[nstack].p_x = curx;
        !            31:                stack[nstack].p_y = cury;
        !            32:                stack[nstack].p_hvmode = hvmode;
        !            33:                stack[nstack].p_xmin = Gbox[0];
        !            34:                stack[nstack].p_ymin = Gbox[1];
        !            35:                stack[nstack].p_xmax = Gbox[2];
        !            36:                stack[nstack].p_ymax = Gbox[3];
        !            37:                nstack++;
        !            38:                Gbox[0] = Gbox[1] = 32767;
        !            39:                Gbox[2] = Gbox[3] = -32767;
        !            40:                p = makenode(BLOCK, N_VAL+2, (int)getfval("curlayer"));
        !            41:                curx = cury = 0;
        !            42:                cur_block = p;
        !            43:        } else {
        !            44:                if (nbstack >= NBRACK)
        !            45:                        fatal("{...} nested too deep");
        !            46:                bracestack[nbstack].p_x = curx;
        !            47:                bracestack[nbstack].p_y = cury;
        !            48:                bracestack[nbstack].p_hvmode = hvmode;
        !            49:                nbstack++;
        !            50:                p = NULL;
        !            51:        }
        !            52:        return(p);
        !            53: }
        !            54: 
        !            55: obj *rightthing(p, c)  /* called for ... ] or ... } */
        !            56:        obj *p;
        !            57: {
        !            58:        obj *q;
        !            59: 
        !            60:        if (c == '}') {
        !            61:                nbstack--;
        !            62:                curx = bracestack[nbstack].p_x;
        !            63:                cury = bracestack[nbstack].p_y;
        !            64:                hvmode = bracestack[nbstack].p_hvmode;
        !            65:                q = makenode(MOVE, 0, 0);
        !            66:        } else {
        !            67:                nstack--;
        !            68:                hvmode = stack[nstack].p_hvmode;
        !            69:                q = makenode(BLOCKEND, 0, p->o_layer);
        !            70:                cur_block = p->o_parent;
        !            71:                curx = stack[nstack].p_x;
        !            72:                cury = stack[nstack].p_y;
        !            73:                p->o_val[N_VAL+0].o = q;
        !            74:                p->o_val[N_VAL+1].s = stack[nstack+1].p_symtab;
        !            75:                p->o_x   = (Gbox[2]+Gbox[0])/2;
        !            76:                p->o_wid = (Gbox[2]-Gbox[0]);
        !            77:                if (p->o_wid < 0)               p->o_wid = 0;
        !            78:                p->o_y   = (Gbox[3]+Gbox[1])/2;
        !            79:                p->o_ht  = (Gbox[3]-Gbox[1]);
        !            80:                if (p->o_ht < 0)                p->o_ht = 0;
        !            81:                Gbox[0] = stack[nstack].p_xmin;
        !            82:                Gbox[1] = stack[nstack].p_ymin;
        !            83:                Gbox[2] = stack[nstack].p_xmax;
        !            84:                Gbox[3] = stack[nstack].p_ymax;
        !            85:        }
        !            86:        return(q);
        !            87: }
        !            88: 
        !            89: obj *blockgen(p)       /* handles [...] */
        !            90:        obj *p;
        !            91: {
        !            92:        float   h, w, xwith, ywith;
        !            93:        float   ctrx, ctry, x0, y0, x1, y1;
        !            94:        int     i, at, with;
        !            95:        obj     *ppos;
        !            96:        Attr    *ap;
        !            97: 
        !            98:        at = with = xwith = ywith = 0;
        !            99:        if (ntext > ntext1)
        !           100:                set_text();
        !           101:        ctrx = curx + p->o_x;
        !           102:        ctry = cury + p->o_y;
        !           103:        w  = p->o_wid;
        !           104:        h  = p->o_ht;
        !           105:        for (i = 0; i < nattr; i++) {
        !           106:                ap = &attr[i];
        !           107:                switch (ap->a_type) {
        !           108:                case HEIGHT:
        !           109:                        h = ap->a_val.f;
        !           110:                        break;
        !           111:                case WIDTH:
        !           112:                        w = ap->a_val.f;
        !           113:                        break;
        !           114:                case WITH:
        !           115:                        with = ap->a_val.i;     /* corner */
        !           116:                        break;
        !           117:                case PLACE:     /* actually with position ... */
        !           118:                        ppos = ap->a_val.o;
        !           119:                        xwith = p->o_x - Xformx(ppos, 1, ppos->o_x, ppos->o_y);
        !           120:                        ywith = p->o_y - Xformy(ppos, 0, ppos->o_x, ppos->o_y);
        !           121:                        with = PLACE;
        !           122:                        break;
        !           123:                case AT:
        !           124:                case FROM:
        !           125:                        ppos = ap->a_val.o;
        !           126:                        ctrx = Xformx(ppos, 1, ppos->o_x, ppos->o_y);
        !           127:                        ctry = Xformy(ppos, 0, ppos->o_x, ppos->o_y);
        !           128:                        at++;
        !           129:                        break;
        !           130:                case LAYER:
        !           131:                        if ((p->o_layer = (int)ap->a_val.f) > top_layer)
        !           132:                                top_layer = p->o_layer;
        !           133:                        break;
        !           134:                case FONT:
        !           135:                        reset_font((double)ap->a_val.f);
        !           136:                        break;
        !           137:                case SIZE:
        !           138:                        reset_size(ap->a_sub, (double)ap->a_val.f);
        !           139:                        break;
        !           140:                case SPACE:
        !           141:                        reset_space(ap->a_sub, (double)ap->a_val.f);
        !           142:                        break;
        !           143:                case TEXTATTR:
        !           144:                        savetext(ap->a_sub, ap->a_val.p);
        !           145:                        break;
        !           146:                case TCOLOR:
        !           147:                        p->o_text = checkcolor((double)ap->a_val.f);
        !           148:                        break;
        !           149:                }
        !           150:        }
        !           151:        if (!at && !with)
        !           152:                with = isright(hvmode) ? WEST : isleft(hvmode) ? EAST :
        !           153:                                isup(hvmode) ? SOUTH : NORTH;
        !           154:        if (with) {
        !           155:                switch (with) {
        !           156:                case NORTH:     ywith = -h/2;                   break;
        !           157:                case SOUTH:     ywith =  h/2;                   break;
        !           158:                case EAST:      xwith = -w/2;                   break;
        !           159:                case WEST:      xwith =  w/2;                   break;
        !           160:                case NE:        xwith = -w/2;   ywith = -h/2;   break;
        !           161:                case SE:        xwith = -w/2;   ywith =  h/2;   break;
        !           162:                case NW:        xwith =  w/2;   ywith = -h/2;   break;
        !           163:                case SW:        xwith =  w/2;   ywith =  h/2;   break;
        !           164:                }
        !           165:                ctrx += xwith;
        !           166:                ctry += ywith;
        !           167:        }
        !           168:        x0 = ctrx - w / 2;
        !           169:        x1 = ctrx + w / 2;
        !           170:        y0 = ctry - h / 2;
        !           171:        y1 = ctry + h / 2;
        !           172:        p->o_nt1 = ntext1;
        !           173:        p->o_nt2 = ntext;
        !           174:        if (ntext > ntext1) {
        !           175:                ntext1 = ntext;
        !           176:                checktextcolor(p);
        !           177:        }
        !           178:        translate(p, ctrx - p->o_x, ctry - p->o_y);
        !           179:        text_bounds(p);
        !           180:        if (isright(hvmode))
        !           181:                curx = x1;
        !           182:        else if (isleft(hvmode))
        !           183:                curx = x0;
        !           184:        else if (isup(hvmode))
        !           185:                cury = y1;
        !           186:        else
        !           187:                cury = y0;
        !           188:        stack[nstack+1].p_symtab = NULL;        /* so won't be found again */
        !           189:        return(p);
        !           190: }

unix.superglobalmegacorp.com

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