xref: /onnv-gate/usr/src/cmd/eqn/paren.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
3*0Sstevel@tonic-gate 
4*0Sstevel@tonic-gate 
5*0Sstevel@tonic-gate /*
6*0Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
7*0Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
8*0Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate /*
12*0Sstevel@tonic-gate  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13*0Sstevel@tonic-gate  * All Rights Reserved.
14*0Sstevel@tonic-gate  */
15*0Sstevel@tonic-gate 
16*0Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate # include "e.h"
19*0Sstevel@tonic-gate 
20*0Sstevel@tonic-gate paren(leftc, p1, rightc) int p1, leftc, rightc; {
21*0Sstevel@tonic-gate 	int n, m, h1, j, b1, v;
22*0Sstevel@tonic-gate 	h1 = eht[p1]; b1 = ebase[p1];
23*0Sstevel@tonic-gate 	yyval = p1;
24*0Sstevel@tonic-gate #ifndef NEQN
25*0Sstevel@tonic-gate 	lfont[yyval] = rfont[yyval] = 0;
26*0Sstevel@tonic-gate 	n = (h1 + EM(1.0, EFFPS(ps)) - 1) / EM(1.0, EFFPS(ps));
27*0Sstevel@tonic-gate #else NEQN
28*0Sstevel@tonic-gate 	n = max(b1+VERT(1), h1-b1-VERT(1)) / VERT(1);
29*0Sstevel@tonic-gate #endif NEQN
30*0Sstevel@tonic-gate 	if( n<2 ) n = 1;
31*0Sstevel@tonic-gate 	m = n-2;
32*0Sstevel@tonic-gate 	if (leftc=='{' || rightc == '}') {
33*0Sstevel@tonic-gate 		n = n%2 ? n : ++n;
34*0Sstevel@tonic-gate 		if( n<3 ) n=3;
35*0Sstevel@tonic-gate 		m = n-3;
36*0Sstevel@tonic-gate 	}
37*0Sstevel@tonic-gate #ifndef NEQN
38*0Sstevel@tonic-gate 	eht[yyval] = VERT(EM(n, ps));
39*0Sstevel@tonic-gate 	ebase[yyval] = b1 + (eht[yyval]-h1)/2;
40*0Sstevel@tonic-gate 	v = b1 - h1/2 + VERT(EM(0.4, ps));
41*0Sstevel@tonic-gate #else NEQN
42*0Sstevel@tonic-gate 	eht[yyval] = VERT(2 * n);
43*0Sstevel@tonic-gate 	ebase[yyval] = (n)/2 * VERT(2);
44*0Sstevel@tonic-gate 	if (n%2 == 0)
45*0Sstevel@tonic-gate 		ebase[yyval] -= VERT(1);
46*0Sstevel@tonic-gate 	v = b1 - h1/2 + VERT(1);
47*0Sstevel@tonic-gate #endif NEQN
48*0Sstevel@tonic-gate 	printf(".ds %d \\|\\v'%du'", yyval, v);
49*0Sstevel@tonic-gate 	switch( leftc ) {
50*0Sstevel@tonic-gate 		case 'n':	/* nothing */
51*0Sstevel@tonic-gate 		case '\0':
52*0Sstevel@tonic-gate 			break;
53*0Sstevel@tonic-gate 		case 'f':	/* floor */
54*0Sstevel@tonic-gate 			if (n <= 1)
55*0Sstevel@tonic-gate 				printf("\\(lf");
56*0Sstevel@tonic-gate 			else
57*0Sstevel@tonic-gate 				brack(m, "\\(bv", "\\(bv", "\\(lf");
58*0Sstevel@tonic-gate 			break;
59*0Sstevel@tonic-gate 		case 'c':	/* ceiling */
60*0Sstevel@tonic-gate 			if (n <= 1)
61*0Sstevel@tonic-gate 				printf("\\(lc");
62*0Sstevel@tonic-gate 			else
63*0Sstevel@tonic-gate 				brack(m, "\\(lc", "\\(bv", "\\(bv");
64*0Sstevel@tonic-gate 			break;
65*0Sstevel@tonic-gate 		case '{':
66*0Sstevel@tonic-gate 			printf("\\b'\\(lt");
67*0Sstevel@tonic-gate 			for(j = 0; j < m; j += 2) printf("\\(bv");
68*0Sstevel@tonic-gate 			printf("\\(lk");
69*0Sstevel@tonic-gate 			for(j = 0; j < m; j += 2) printf("\\(bv");
70*0Sstevel@tonic-gate 			printf("\\(lb'");
71*0Sstevel@tonic-gate 			break;
72*0Sstevel@tonic-gate 		case '(':
73*0Sstevel@tonic-gate 			brack(m, "\\(lt", "\\(bv", "\\(lb");
74*0Sstevel@tonic-gate 			break;
75*0Sstevel@tonic-gate 		case '[':
76*0Sstevel@tonic-gate 			brack(m, "\\(lc", "\\(bv", "\\(lf");
77*0Sstevel@tonic-gate 			break;
78*0Sstevel@tonic-gate 		case '|':
79*0Sstevel@tonic-gate 			brack(m, "\\(bv", "\\(bv", "\\(bv");
80*0Sstevel@tonic-gate 			break;
81*0Sstevel@tonic-gate 		default:
82*0Sstevel@tonic-gate 			brack(m, (char *) &leftc, (char *) &leftc, (char *) &leftc);
83*0Sstevel@tonic-gate 			break;
84*0Sstevel@tonic-gate 		}
85*0Sstevel@tonic-gate 	printf("\\v'%du'\\*(%d", -v, p1);
86*0Sstevel@tonic-gate 	if( rightc ) {
87*0Sstevel@tonic-gate 		printf("\\|\\v'%du'", v);
88*0Sstevel@tonic-gate 		switch( rightc ) {
89*0Sstevel@tonic-gate 			case 'f':	/* floor */
90*0Sstevel@tonic-gate 				if (n <= 1)
91*0Sstevel@tonic-gate 					printf("\\(rf");
92*0Sstevel@tonic-gate 				else
93*0Sstevel@tonic-gate 					brack(m, "\\(bv", "\\(bv", "\\(rf");
94*0Sstevel@tonic-gate 				break;
95*0Sstevel@tonic-gate 			case 'c':	/* ceiling */
96*0Sstevel@tonic-gate 				if (n <= 1)
97*0Sstevel@tonic-gate 					printf("\\(rc");
98*0Sstevel@tonic-gate 				else
99*0Sstevel@tonic-gate 					brack(m, "\\(rc", "\\(bv", "\\(bv");
100*0Sstevel@tonic-gate 				break;
101*0Sstevel@tonic-gate 			case '}':
102*0Sstevel@tonic-gate 				printf("\\b'\\(rt");
103*0Sstevel@tonic-gate 				for(j = 0; j< m; j += 2)printf("\\(bv");
104*0Sstevel@tonic-gate 				printf("\\(rk");
105*0Sstevel@tonic-gate 				for(j = 0; j< m; j += 2) printf("\\(bv");
106*0Sstevel@tonic-gate 				printf("\\(rb'");
107*0Sstevel@tonic-gate 				break;
108*0Sstevel@tonic-gate 			case ']':
109*0Sstevel@tonic-gate 				brack(m, "\\(rc", "\\(bv", "\\(rf");
110*0Sstevel@tonic-gate 				break;
111*0Sstevel@tonic-gate 			case ')':
112*0Sstevel@tonic-gate 				brack(m, "\\(rt", "\\(bv", "\\(rb");
113*0Sstevel@tonic-gate 				break;
114*0Sstevel@tonic-gate 			case '|':
115*0Sstevel@tonic-gate 				brack(m, "\\(bv", "\\(bv", "\\(bv");
116*0Sstevel@tonic-gate 				break;
117*0Sstevel@tonic-gate 			default:
118*0Sstevel@tonic-gate 				brack(m, (char *) &rightc, (char *) &rightc, (char *) &rightc);
119*0Sstevel@tonic-gate 				break;
120*0Sstevel@tonic-gate 		}
121*0Sstevel@tonic-gate 		printf("\\v'%du'", -v);
122*0Sstevel@tonic-gate 	}
123*0Sstevel@tonic-gate 	printf("\n");
124*0Sstevel@tonic-gate 	if(dbg)printf(".\tcurly: h=%d b=%d n=%d v=%d l=%c, r=%c\n",
125*0Sstevel@tonic-gate 		eht[yyval], ebase[yyval], n, v, leftc, rightc);
126*0Sstevel@tonic-gate }
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate brack(m, t, c, b) int m; char *t, *c, *b; {
129*0Sstevel@tonic-gate 	int j;
130*0Sstevel@tonic-gate 	printf("\\b'%s", t);
131*0Sstevel@tonic-gate 	for( j=0; j<m; j++)
132*0Sstevel@tonic-gate 		printf("%s", c);
133*0Sstevel@tonic-gate 	printf("%s'", b);
134*0Sstevel@tonic-gate }
135