1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 /*	from OpenSolaris "paren.c	1.5	05/06/02 SMI"	 SVr4.0 1.1		*/
17 
18 /*
19  * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
20  *
21  * Sccsid @(#)paren.c	1.4 (gritter) 10/29/05
22  */
23 
24 /*
25  * Changes Copyright (c) 2014 Carsten Kunze (carsten.kunze at arcor.de)
26  */
27 
28 # include "e.h"
29 #include "y.tab.h"
30 
31 extern YYSTYPE yyval;
32 
33 void
paren(int leftc,int p1,int rightc)34 paren(int leftc, int p1, int rightc) {
35 	int n, m, j;
36 #ifndef	NEQN
37 	float v, h1, b1;
38 #else	/* NEQN */
39 	int v, h1, b1;
40 #endif	/* NEQN */
41 	h1 = eht[p1]; b1 = ebase[p1];
42 	yyval.token = p1;
43 #ifndef NEQN
44 	lfont[yyval.token] = rfont[yyval.token] = 0;
45 	n = (h1 + EM(1.0, EFFPS(ps)) - 1) / EM(1.0, EFFPS(ps));
46 #else /* NEQN */
47 	n = max(b1+VERT(1), h1-b1-VERT(1)) / VERT(1);
48 #endif /* NEQN */
49 	if( n<2 ) n = 1;
50 	m = n-2;
51 	if (leftc=='{' || rightc == '}') {
52 		n = n%2 ? n : n+1;
53 		if( n<3 ) n=3;
54 		m = n-3;
55 	}
56 #ifndef NEQN
57 	eht[yyval.token] = VERT(EM(n, ps));
58 	ebase[yyval.token] = b1 + (eht[yyval.token]-h1)/2;
59 	v = b1 - h1/2 + VERT(EM(0.4, ps));
60 	printf(".ds %d \\|\\v'%gp'", yyval.token, v);
61 #else /* NEQN */
62 	eht[yyval.token] = VERT(2 * n);
63 	ebase[yyval.token] = (n)/2 * VERT(2);
64 	if (n%2 == 0)
65 		ebase[yyval.token] -= VERT(1);
66 	v = b1 - h1/2 + VERT(1);
67 	printf(".ds %d \\|\\v'%du'", yyval.token, v);
68 #endif /* NEQN */
69 	switch( leftc ) {
70 		case 'n':	/* nothing */
71 		case '\0':
72 			break;
73 		case 'f':	/* floor */
74 			if (n <= 1)
75 				printf("\\(lf");
76 			else
77 				brack(m, "\\(bv", "\\(bv", "\\(lf");
78 			break;
79 		case 'c':	/* ceiling */
80 			if (n <= 1)
81 				printf("\\(lc");
82 			else
83 				brack(m, "\\(lc", "\\(bv", "\\(bv");
84 			break;
85 		case '{':
86 			printf("\\b'\\(lt");
87 			for(j = 0; j < m; j += 2) printf("\\(bv");
88 			printf("\\(lk");
89 			for(j = 0; j < m; j += 2) printf("\\(bv");
90 			printf("\\(lb'");
91 			break;
92 		case '(':
93 			brack(m, "\\(lt", "\\(bv", "\\(lb");
94 			break;
95 		case '[':
96 			brack(m, "\\(lc", "\\(bv", "\\(lf");
97 			break;
98 		case '|':
99 			brack(m, "\\(bv", "\\(bv", "\\(bv");
100 			break;
101 		default:
102 			brack(m, (char *) &leftc, (char *) &leftc, (char *) &leftc);
103 			break;
104 		}
105 #ifndef	NEQN
106 	printf("\\v'%gp'\\*(%d", -v, p1);
107 #else	/* NEQN */
108 	printf("\\v'%du'\\*(%d", -v, p1);
109 #endif	/* NEQN */
110 	if( rightc ) {
111 #ifndef	NEQN
112 		printf("\\|\\v'%gp'", v);
113 #else	/* NEQN */
114 		printf("\\|\\v'%du'", v);
115 #endif	/* NEQN */
116 		switch( rightc ) {
117 			case 'f':	/* floor */
118 				if (n <= 1)
119 					printf("\\(rf");
120 				else
121 					brack(m, "\\(bv", "\\(bv", "\\(rf");
122 				break;
123 			case 'c':	/* ceiling */
124 				if (n <= 1)
125 					printf("\\(rc");
126 				else
127 					brack(m, "\\(rc", "\\(bv", "\\(bv");
128 				break;
129 			case '}':
130 				printf("\\b'\\(rt");
131 				for(j = 0; j< m; j += 2)printf("\\(bv");
132 				printf("\\(rk");
133 				for(j = 0; j< m; j += 2) printf("\\(bv");
134 				printf("\\(rb'");
135 				break;
136 			case ']':
137 				brack(m, "\\(rc", "\\(bv", "\\(rf");
138 				break;
139 			case ')':
140 				brack(m, "\\(rt", "\\(bv", "\\(rb");
141 				break;
142 			case '|':
143 				brack(m, "\\(bv", "\\(bv", "\\(bv");
144 				break;
145 			default:
146 				brack(m, (char *) &rightc, (char *) &rightc, (char *) &rightc);
147 				break;
148 		}
149 #ifndef	NEQN
150 		printf("\\v'%gp'", -v);
151 #else	/* NEQN */
152 		printf("\\v'%du'", -v);
153 #endif	/* NEQN */
154 	}
155 	printf("\n");
156 #ifndef	NEQN
157 	if(dbg)printf(".\tcurly: h=%g b=%g n=%d v=%g l=%c, r=%c\n",
158 		eht[yyval.token], ebase[yyval.token], n, v, leftc, rightc);
159 #else	/* NEQN */
160 	if(dbg)printf(".\tcurly: h=%d b=%d n=%d v=%d l=%c, r=%c\n",
161 		eht[yyval.token], ebase[yyval.token], n, v, leftc, rightc);
162 #endif	/* NEQN */
163 }
164 
165 void
brack(int m,char * t,char * c,char * b)166 brack(int m, char *t, char *c, char *b) {
167 	int j;
168 	printf("\\b'%s", t);
169 	for( j=0; j<m; j++)
170 		printf("%s", c);
171 	printf("%s'", b);
172 }
173