1 /* $MirOS: src/usr.bin/oldroff/neqn/paren.c,v 1.2 2008/11/08 23:04:37 tg Exp $ */
2
3 /*-
4 * Copyright (c) 1979, 1980, 1981, 1986, 1988, 1990, 1991, 1992
5 * The Regents of the University of California.
6 * Copyright (C) Caldera International Inc. 2001-2002.
7 * Copyright (c) 2003, 2004
8 * Thorsten "mirabilos" Glaser <tg@mirbsd.org>
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms,
12 * with or without modification, are permitted provided
13 * that the following conditions are met:
14 *
15 * Redistributions of source code and documentation must retain
16 * the above copyright notice, this list of conditions and the
17 * following disclaimer. Redistributions in binary form must
18 * reproduce the above copyright notice, this list of conditions
19 * and the following disclaimer in the documentation and/or other
20 * materials provided with the distribution.
21 *
22 * All advertising materials mentioning features or use of this
23 * software must display the following acknowledgement:
24 * This product includes software developed or owned by
25 * Caldera International, Inc.
26 *
27 * Neither the name of Caldera International, Inc. nor the names
28 * of other contributors may be used to endorse or promote products
29 * derived from this software without specific prior written permission.
30 *
31 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
32 * INTERNATIONAL, INC. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
33 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
36 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
39 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
41 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44
45 #ifndef lint
46 static char sccsid[] = "@(#)paren.c 4.4 (Berkeley) 4/17/91";
47 #endif
48
49 # include "e.h"
50
paren(leftc,p1,rightc)51 paren(leftc, p1, rightc) int p1, leftc, rightc; {
52 int n, m, h1, j, b1, v;
53 h1 = eht[p1]; b1 = ebase[p1];
54 yyval = p1;
55 #ifndef NEQN
56 lfont[yyval] = rfont[yyval] = 0;
57 n = (h1+(6*EFFPS(ps)-1))/(6*EFFPS(ps));
58 #else
59 n = max(b1+VERT(1), h1-b1-VERT(1)) / VERT(1);
60 #endif
61 if( n<2 ) n = 1;
62 m = n-2;
63 if (leftc=='{' || rightc == '}') {
64 n = n%2 ? n : ++n;
65 if( n<3 ) n=3;
66 m = n-3;
67 }
68 #ifndef NEQN
69 eht[yyval] = VERT(6 * ps * n);
70 ebase[yyval] = b1 + (eht[yyval]-h1)/2;
71 v = b1 - h1/2 + VERT( (ps*6*4)/10 );
72 #else
73 eht[yyval] = VERT(2 * n);
74 ebase[yyval] = (n)/2 * VERT(2);
75 if (n%2 == 0)
76 ebase[yyval] -= VERT(1);
77 v = b1 - h1/2 + VERT(1);
78 #endif
79 printf(".ds %d \\|\\v'%du'", yyval, v);
80 switch( leftc ) {
81 case 'n': /* nothing */
82 case '\0':
83 break;
84 case 'f': /* floor */
85 if (n <= 1)
86 printf("\\(lf");
87 else
88 brack(m, "\\(bv", "\\(bv", "\\(lf");
89 break;
90 case 'c': /* ceiling */
91 if (n <= 1)
92 printf("\\(lc");
93 else
94 brack(m, "\\(lc", "\\(bv", "\\(bv");
95 break;
96 case '{':
97 printf("\\b'\\(lt");
98 for(j = 0; j < m; j += 2) printf("\\(bv");
99 printf("\\(lk");
100 for(j = 0; j < m; j += 2) printf("\\(bv");
101 printf("\\(lb'");
102 break;
103 case '(':
104 brack(m, "\\(lt", "\\(bv", "\\(lb");
105 break;
106 case '[':
107 brack(m, "\\(lc", "\\(bv", "\\(lf");
108 break;
109 case '|':
110 brack(m, "|", "|", "|");
111 break;
112 default:
113 brack(m, (char *) &leftc, (char *) &leftc, (char *) &leftc);
114 break;
115 }
116 printf("\\v'%du'\\*(%d", -v, p1);
117 if( rightc ) {
118 printf("\\|\\v'%du'", v);
119 switch( rightc ) {
120 case 'f': /* floor */
121 if (n <= 1)
122 printf("\\(rf");
123 else
124 brack(m, "\\(bv", "\\(bv", "\\(rf");
125 break;
126 case 'c': /* ceiling */
127 if (n <= 1)
128 printf("\\(rc");
129 else
130 brack(m, "\\(rc", "\\(bv", "\\(bv");
131 break;
132 case '}':
133 printf("\\b'\\(rt");
134 for(j = 0; j< m; j += 2)printf("\\(bv");
135 printf("\\(rk");
136 for(j = 0; j< m; j += 2) printf("\\(bv");
137 printf("\\(rb'");
138 break;
139 case ']':
140 brack(m, "\\(rc", "\\(bv", "\\(rf");
141 break;
142 case ')':
143 brack(m, "\\(rt", "\\(bv", "\\(rb");
144 break;
145 case '|':
146 brack(m, "|", "|", "|");
147 break;
148 default:
149 brack(m, (char *) &rightc, (char *) &rightc, (char *) &rightc);
150 break;
151 }
152 printf("\\v'%du'", -v);
153 }
154 printf("\n");
155 if(dbg)printf(".\tcurly: h=%d b=%d n=%d v=%d l=%c, r=%c\n",
156 eht[yyval], ebase[yyval], n, v, leftc, rightc);
157 }
158
brack(m,t,c,b)159 brack(m, t, c, b) int m; char *t, *c, *b; {
160 int j;
161 printf("\\b'%s", t);
162 for( j=0; j<m; j++)
163 printf("%s", c);
164 printf("%s'", b);
165 }
166