date and time created 83/08/05 13:34:37 by sam
[unix-history] / usr / src / old / eqn / common_source / shift.c
CommitLineData
6f1a2a65 1/* shift.c 4.2 83/02/12 */
247cb223
BS
2
3# include "e.h"
4#include "e.def"
5
6bshiftb(p1, dir, p2) int p1, dir, p2; {
6f1a2a65
BS
7 int shval, d1, h1, b1, h2, b2;
8#ifndef NEQN
9 int diffps, effps, effps2;
247cb223 10 char *sh1, *sh2;
6f1a2a65 11#endif NEQN
247cb223
BS
12
13 yyval = p1;
14 h1 = eht[p1];
15 b1 = ebase[p1];
16 h2 = eht[p2];
17 b2 = ebase[p2];
6f1a2a65 18#ifndef NEQN
247cb223
BS
19 effps = EFFPS(ps);
20 effps2 = EFFPS(ps+deltaps);
21 diffps = deltaps;
22 sh1 = sh2 = "";
6f1a2a65
BS
23#endif NEQN
24 if( dir == SUB ) { /* subscript */
25#ifndef NEQN
247cb223
BS
26 /* top 1/2m above bottom of main box */
27 d1 = VERT( (effps2*6)/2 );
6f1a2a65
BS
28#else NEQN
29 d1 = VERT(1);
30#endif NEQN
247cb223
BS
31 shval = - d1 + h2 - b2;
32 if( d1+b1 > h2 ) /* move little sub down */
33 shval = b1-b2;
34 ebase[yyval] = b1 + max(0, h2-b1-d1);
35 eht[yyval] = h1 + max(0, h2-b1-d1);
6f1a2a65 36#ifndef NEQN
247cb223
BS
37 if (rfont[p1] == ITAL && lfont[p2] == ROM)
38 sh1 = "\\|";
39 if (rfont[p2] == ITAL)
40 sh2 = "\\|";
6f1a2a65 41#endif NEQN
247cb223 42 } else { /* superscript */
6f1a2a65 43#ifndef NEQN
247cb223
BS
44 /* 4/10 up main box */
45 d1 = VERT( (effps*6*2)/10 );
6f1a2a65
BS
46#else NEQN
47 d1 = VERT(1);
48#endif NEQN
247cb223 49 ebase[yyval] = b1;
6f1a2a65 50#ifndef NEQN
247cb223
BS
51 shval = -VERT( (4 * (h1-b1)) / 10 ) - b2;
52 if( VERT(4*(h1-b1)/10) + h2 < h1-b1 ) /* raise little super */
6f1a2a65
BS
53#else NEQN
54 shval = -VERT(1) - b2;
55 if( VERT(1) + h2 < h1-b1 ) /* raise little super */
56#endif NEQN
247cb223 57 shval = -(h1-b1) + h2-b2 - d1;
6f1a2a65 58#ifndef NEQN
247cb223
BS
59 eht[yyval] = h1 + max(0, h2-VERT((6*(h1-b1))/10));
60 if (rfont[p1] == ITAL)
61 sh1 = "\\|";
62 if (rfont[p2] == ITAL)
63 sh2 = "\\|";
6f1a2a65
BS
64#else NEQN
65 eht[yyval] = h1 + max(0, h2 - VERT(1));
66#endif NEQN
247cb223
BS
67 }
68 if(dbg)printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; b=%d, h=%d\n",
69 yyval, p1, shval, p2, -shval, ebase[yyval], eht[yyval]);
6f1a2a65 70#ifndef NEQN
247cb223
BS
71 printf(".as %d \\v'%du'\\s-%d%s\\*(%d\\s+%d%s\\v'%du'\n",
72 yyval, shval, diffps, sh1, p2, diffps, sh2, -shval);
73 ps += deltaps;
74 if (rfont[p2] == ITAL)
75 rfont[p1] = 0;
76 else
77 rfont[p1] = rfont[p2];
6f1a2a65
BS
78#else NEQN
79 printf(".as %d \\v'%du'\\*(%d\\v'%du'\n",
80 yyval, shval, p2, -shval);
81#endif NEQN
247cb223
BS
82 ofree(p2);
83}
84
85shift(p1) int p1; {
86 ps -= deltaps;
87 yyval = p1;
88 if(dbg)printf(".\tshift: %d;ps=%d\n", yyval, ps);
89}
90
91shift2(p1, p2, p3) int p1, p2, p3; {
6f1a2a65
BS
92 int effps, h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh, treg;
93#ifndef NEQN
94 int effps2;
95#endif NEQN
96
247cb223
BS
97 treg = oalloc();
98 yyval = p1;
99 if(dbg)printf(".\tshift2 s%d <- %d %d %d\n", yyval, p1, p2, p3);
100 effps = EFFPS(ps+deltaps);
6f1a2a65 101#ifndef NEQN
247cb223
BS
102 eht[p3] = h3 = VERT( (eht[p3] * effps) / EFFPS(ps) );
103 ps += deltaps;
104 effps2 = EFFPS(ps+deltaps);
6f1a2a65 105#endif NEQN
247cb223
BS
106 h1 = eht[p1]; b1 = ebase[p1];
107 h2 = eht[p2]; b2 = ebase[p2];
6f1a2a65 108#ifndef NEQN
247cb223
BS
109 b3 = ebase[p3];
110 d1 = VERT( (effps2*6)/2 );
6f1a2a65
BS
111#else NEQN
112 h3 = eht[p3]; b3 = ebase[p3];
113 d1 = VERT(1);
114#endif NEQN
247cb223
BS
115 subsh = -d1+h2-b2;
116 if( d1+b1 > h2 ) /* move little sub down */
117 subsh = b1-b2;
6f1a2a65 118#ifndef NEQN
247cb223
BS
119 supsh = -VERT( (4*(h1-b1))/10 ) - b3;
120 d2 = VERT( (effps*6*2)/10 );
121 if( VERT(4*(h1-b1)/10)+h3 < h1-b1 )
6f1a2a65
BS
122#else NEQN
123 supsh = - VERT(1) - b3;
124 d2 = VERT(1);
125 if( VERT(1)+h3 < h1-b1 )
126#endif NEQN
247cb223 127 supsh = -(h1-b1) + (h3-b3) - d2;
6f1a2a65 128#ifndef NEQN
247cb223 129 eht[yyval] = h1 + max(0, h3-VERT( (6*(h1-b1))/10 )) + max(0, h2-b1-d1);
6f1a2a65
BS
130#else NEQN
131 eht[yyval] = h1 + max(0, h3-VERT(1)) + max(0, h2-b1-d1);
132#endif NEQN
247cb223 133 ebase[yyval] = b1+max(0, h2-b1-d1);
6f1a2a65 134#ifndef NEQN
247cb223
BS
135 if (rfont[p1] == ITAL && lfont[p2] == ROM)
136 printf(".ds %d \\|\\*(%d\n", p2, p2);
137 if (rfont[p2] == ITAL)
138 printf(".as %d \\|\n", p2);
6f1a2a65 139#endif NEQN
247cb223 140 nrwid(p2, effps, p2);
6f1a2a65 141#ifndef NEQN
247cb223
BS
142 if (rfont[p1] == ITAL && lfont[p3] == ROM)
143 printf(".ds %d \\|\\|\\*(%d\n", p3, p3);
144 else
145 printf(".ds %d \\|\\*(%d\n", p3, p3);
6f1a2a65 146#endif NEQN
247cb223
BS
147 nrwid(p3, effps, p3);
148 printf(".nr %d \\n(%d\n", treg, p3);
149 printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2);
6f1a2a65 150#ifndef NEQN
247cb223
BS
151 printf(".as %d \\v'%du'\\s%d\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
152 p1, subsh, effps, p2, p2, -subsh+supsh);
153 printf("\\s%d\\*(%d\\h'-\\n(%du+\\n(%du'\\s%d\\v'%du'\n",
154 effps, p3, p3, treg, effps2, -supsh);
6f1a2a65
BS
155#else NEQN
156 printf(".as %d \\v'%du'\\*(%d\\h'-\\n(%du'\\v'%du'\\\n",
157 p1, subsh, p2, p2, -subsh+supsh);
158 printf("\\*(%d\\h'-\\n(%du+\\n(%du'\\v'%du'\n",
159 p3, p3, treg, -supsh);
160#endif NEQN
247cb223 161 ps += deltaps;
6f1a2a65 162#ifndef NEQN
247cb223
BS
163 if (rfont[p2] == ITAL)
164 rfont[yyval] = 0; /* lie */
6f1a2a65 165#endif NEQN
247cb223
BS
166 ofree(p2); ofree(p3); ofree(treg);
167}