Annotation of researchv10no/cmd/eqn/shift.c, revision 1.1.1.1

1.1       root        1: #include "e.h"
                      2: #include "y.tab.h"
                      3: 
                      4: void subsup(int p1, int p2, int p3)
                      5: {
                      6:        if (p2 != 0 && p3 != 0)
                      7:                shift2(p1, p2, p3);
                      8:        else if (p2 != 0)
                      9:                bshiftb(p1, SUB, p2);
                     10:        else if (p3 != 0)
                     11:                bshiftb(p1, SUP, p3);
                     12: }
                     13: 
                     14: extern double Subbase, Supshift;
                     15: extern char *Sub1space, *Sup1space, *Sub2space;
                     16: extern char *SS1space, *SS2space;
                     17: 
                     18: void bshiftb(int p1, int dir, int p2)
                     19: {
                     20:        int subps, n;
                     21:        double shval, d1, h1, b1, h2, b2;
                     22:        char *sh1, *sh2;
                     23: 
                     24:        yyval = p1;
                     25:        h1 = eht[p1];
                     26:        b1 = ebase[p1];
                     27:        h2 = eht[p2];
                     28:        b2 = ebase[p2];
                     29:        subps = ps;
                     30:        ps += deltaps;
                     31:        sh1 = "";
                     32:        if (dir == SUB) {
                     33:                /* base .2m below bottom of main box */
                     34:                shval = b1 + EM(Subbase, ps);
                     35:                ebase[yyval] = shval + b2;
                     36:                eht[yyval] = max(h1-b1+shval+b2, h2);
                     37:                if (rfont[p1] == ITAL && lfont[p2] == ROM)
                     38:                        n = 2;          /* Sub1space */
                     39:                else
                     40:                        n = max(2, class[rclass[p1]][lclass[p2]]);
                     41:                sh1 = pad(n);
                     42:                rclass[p1] = OTHER;     /* OTHER leaves too much after sup */
                     43:        } else {        /* superscript */
                     44:                /* 4/10 up main box */
                     45:                d1 = EM(Subbase, subps);
                     46:                ebase[yyval] = b1;
                     47:                shval = -(Supshift * (h1-b1)) - b2;
                     48:                if (Supshift*(h1-b1) + h2 < h1-b1)      /* raise little super */
                     49:                        shval = -(h1-b1) + h2-b2 - d1;
                     50:                eht[yyval] = h1 + max(0, h2 - (1-Supshift)*(h1-b1));
                     51:                if (rclass[p1] == ILETF)
                     52:                        n = 4;
                     53:                else if (rfont[p1] == ITAL)
                     54:                        n = 2;          /* Sup1space */
                     55:                else
                     56:                        n = max(1, class[rclass[p1]][lclass[p2]]);
                     57:                sh1 = pad(n);
                     58:                rclass[p1] = rclass[p2];        /* OTHER leaves too much after sup */
                     59:        }
                     60:        dprintf(".\tS%d <- %d shift %g %d; b=%g, h=%g, ps=%d, subps=%d\n", 
                     61:                yyval, p1, shval, p2, ebase[yyval], eht[yyval], ps, subps);
                     62:        sh2 = Sub2space;        /* was Sub2space; */
                     63:        printf(".as %d \\v'%gm'%s%s\\*(%d%s%s\\v'%gm'\n", 
                     64:                yyval, REL(shval,ps), DPS(ps,subps), sh1, p2,
                     65:                DPS(subps,ps), sh2, REL(-shval,ps));
                     66:        rfont[p1] = 0;
                     67:        sfree(p2);
                     68: }
                     69: 
                     70: void shift2(int p1, int p2, int p3)
                     71: {
                     72:        int subps;
                     73:        double h1, h2, h3, b1, b2, b3, subsh, d2, supsh;
                     74:        int treg;
                     75:        char *sh2;
                     76: 
                     77:        treg = salloc();
                     78:        yyval = p1;
                     79:        subps = ps;     /* sub and sup at this size */
                     80:        ps += deltaps;  /* outer size */
                     81:        h1 = eht[p1]; b1 = ebase[p1];
                     82:        h2 = eht[p2]; b2 = ebase[p2];
                     83:        h3 = eht[p3]; b3 = ebase[p3];
                     84:        subsh = EM(Subbase, ps);
                     85:        if (b1 > b2 + subsh) /* move little sub down */
                     86:                subsh += b1;
                     87:        eht[yyval] = max(subsh+b2-b1+h1, h2);
                     88:        supsh = -Supshift*(h1-b1) - b3;
                     89:        d2 = EM(Subbase, subps);
                     90:        if (h3 < (1-Supshift)*(h1-b1))
                     91:                supsh = -(h1-b1) + (h3-b3) - d2;
                     92:        ebase[yyval] = subsh + b2 - b1;
                     93:        eht[yyval] = h1 + subsh+b2-b1 + max(0, h3-(1-Supshift)*(h1-b1));
                     94:        dprintf(".\tS%d <- %d sub %d sup %d, ps=%d, subps=%d, h=%g, b=%g\n",
                     95:                yyval, p1, p2, p3, ps, subps, eht[yyval], ebase[yyval]);
                     96:        if (rclass[p1] == ILETF)
                     97:                sh2 = "\\|\\|";
                     98:        else
                     99:                sh2 = SS2space;
                    100:        /*n = max(class[rclass[p1]][lclass[p2]], class[rclass[p1]][lclass[p3]]);
                    101:        /*sh2 = pad(max(2, n));
                    102:        */
                    103:        printf(".ds %d %s\\*(%d\n", p2, SS1space, p2);
                    104:        nrwid(p2, subps, p2);
                    105:        printf(".ds %d %s\\*(%d\n", p3, sh2, p3);
                    106:        nrwid(p3, subps, p3);
                    107:        printf(".nr %d \\n(%d\n", treg, p3);
                    108:        printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
                    109:        printf(".as %d %s\\v'%gm'\\*(%d\\v'%gm'\\h'-\\n(%du'\\\n", 
                    110:                p1, DPS(ps,subps), REL(subsh,subps), p2, REL(-subsh,subps), p2);
                    111:        printf("\\v'%gm'\\*(%d\\v'%gm'\\h'-\\n(%du+\\n(%du'%s%s\n", 
                    112:                REL(supsh,subps), p3, REL(-supsh,subps), p3, treg, DPS(subps,ps), Sub2space);
                    113:        if (rfont[p2] == ITAL)
                    114:                rfont[yyval] = 0;       /* lie */
                    115:        rclass[yyval] = rclass[p3];     /* was OTHER */
                    116:        sfree(p2); sfree(p3); sfree(treg);
                    117: }

unix.superglobalmegacorp.com

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