xref: /onnv-gate/usr/src/cmd/eqn/paren.c (revision 364:f36290b8cb0b)
1*364Sceastha /*
2*364Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*364Sceastha  * Use is subject to license terms.
4*364Sceastha  */
5*364Sceastha 
60Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
70Sstevel@tonic-gate /*	  All Rights Reserved  	*/
80Sstevel@tonic-gate 
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
120Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate  */
14*364Sceastha 
15*364Sceastha #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*364Sceastha 
17*364Sceastha #include "e.h"
180Sstevel@tonic-gate 
19*364Sceastha extern int max();
20*364Sceastha 
21*364Sceastha void brack(int, char *, char *, char *);
220Sstevel@tonic-gate 
23*364Sceastha void
paren(int leftc,int p1,int rightc)24*364Sceastha paren(int leftc, int p1, int rightc)
25*364Sceastha {
260Sstevel@tonic-gate 	int n, m, h1, j, b1, v;
270Sstevel@tonic-gate 	h1 = eht[p1]; b1 = ebase[p1];
280Sstevel@tonic-gate 	yyval = p1;
290Sstevel@tonic-gate #ifndef NEQN
300Sstevel@tonic-gate 	lfont[yyval] = rfont[yyval] = 0;
310Sstevel@tonic-gate 	n = (h1 + EM(1.0, EFFPS(ps)) - 1) / EM(1.0, EFFPS(ps));
32*364Sceastha #else	/* NEQN */
330Sstevel@tonic-gate 	n = max(b1+VERT(1), h1-b1-VERT(1)) / VERT(1);
34*364Sceastha #endif	/* NEQN */
35*364Sceastha 	if (n < 2) n = 1;
360Sstevel@tonic-gate 	m = n-2;
37*364Sceastha 	if (leftc == '{' || rightc == '}') {
38*364Sceastha 		if ((n % 2) == 0) {
39*364Sceastha 			n++;
40*364Sceastha 		}
41*364Sceastha 		if (n < 3) n = 3;
420Sstevel@tonic-gate 		m = n-3;
430Sstevel@tonic-gate 	}
440Sstevel@tonic-gate #ifndef NEQN
450Sstevel@tonic-gate 	eht[yyval] = VERT(EM(n, ps));
460Sstevel@tonic-gate 	ebase[yyval] = b1 + (eht[yyval]-h1)/2;
470Sstevel@tonic-gate 	v = b1 - h1/2 + VERT(EM(0.4, ps));
48*364Sceastha #else	/* NEQN */
490Sstevel@tonic-gate 	eht[yyval] = VERT(2 * n);
500Sstevel@tonic-gate 	ebase[yyval] = (n)/2 * VERT(2);
510Sstevel@tonic-gate 	if (n%2 == 0)
520Sstevel@tonic-gate 		ebase[yyval] -= VERT(1);
530Sstevel@tonic-gate 	v = b1 - h1/2 + VERT(1);
54*364Sceastha #endif	/* NEQN */
550Sstevel@tonic-gate 	printf(".ds %d \\|\\v'%du'", yyval, v);
56*364Sceastha 	switch (leftc) {
570Sstevel@tonic-gate 		case 'n':	/* nothing */
580Sstevel@tonic-gate 		case '\0':
590Sstevel@tonic-gate 			break;
600Sstevel@tonic-gate 		case 'f':	/* floor */
610Sstevel@tonic-gate 			if (n <= 1)
620Sstevel@tonic-gate 				printf("\\(lf");
630Sstevel@tonic-gate 			else
640Sstevel@tonic-gate 				brack(m, "\\(bv", "\\(bv", "\\(lf");
650Sstevel@tonic-gate 			break;
660Sstevel@tonic-gate 		case 'c':	/* ceiling */
670Sstevel@tonic-gate 			if (n <= 1)
680Sstevel@tonic-gate 				printf("\\(lc");
690Sstevel@tonic-gate 			else
700Sstevel@tonic-gate 				brack(m, "\\(lc", "\\(bv", "\\(bv");
710Sstevel@tonic-gate 			break;
720Sstevel@tonic-gate 		case '{':
730Sstevel@tonic-gate 			printf("\\b'\\(lt");
74*364Sceastha 			for (j = 0; j < m; j += 2) printf("\\(bv");
750Sstevel@tonic-gate 			printf("\\(lk");
76*364Sceastha 			for (j = 0; j < m; j += 2) printf("\\(bv");
770Sstevel@tonic-gate 			printf("\\(lb'");
780Sstevel@tonic-gate 			break;
790Sstevel@tonic-gate 		case '(':
800Sstevel@tonic-gate 			brack(m, "\\(lt", "\\(bv", "\\(lb");
810Sstevel@tonic-gate 			break;
820Sstevel@tonic-gate 		case '[':
830Sstevel@tonic-gate 			brack(m, "\\(lc", "\\(bv", "\\(lf");
840Sstevel@tonic-gate 			break;
850Sstevel@tonic-gate 		case '|':
860Sstevel@tonic-gate 			brack(m, "\\(bv", "\\(bv", "\\(bv");
870Sstevel@tonic-gate 			break;
880Sstevel@tonic-gate 		default:
89*364Sceastha 			brack(m, (char *)&leftc, (char *)&leftc,
90*364Sceastha 			    (char *)&leftc);
910Sstevel@tonic-gate 			break;
920Sstevel@tonic-gate 		}
930Sstevel@tonic-gate 	printf("\\v'%du'\\*(%d", -v, p1);
94*364Sceastha 	if (rightc) {
950Sstevel@tonic-gate 		printf("\\|\\v'%du'", v);
96*364Sceastha 		switch (rightc) {
970Sstevel@tonic-gate 			case 'f':	/* floor */
980Sstevel@tonic-gate 				if (n <= 1)
990Sstevel@tonic-gate 					printf("\\(rf");
1000Sstevel@tonic-gate 				else
1010Sstevel@tonic-gate 					brack(m, "\\(bv", "\\(bv", "\\(rf");
1020Sstevel@tonic-gate 				break;
1030Sstevel@tonic-gate 			case 'c':	/* ceiling */
1040Sstevel@tonic-gate 				if (n <= 1)
1050Sstevel@tonic-gate 					printf("\\(rc");
1060Sstevel@tonic-gate 				else
1070Sstevel@tonic-gate 					brack(m, "\\(rc", "\\(bv", "\\(bv");
1080Sstevel@tonic-gate 				break;
1090Sstevel@tonic-gate 			case '}':
1100Sstevel@tonic-gate 				printf("\\b'\\(rt");
111*364Sceastha 				for (j = 0; j < m; j += 2) printf("\\(bv");
1120Sstevel@tonic-gate 				printf("\\(rk");
113*364Sceastha 				for (j = 0; j < m; j += 2) printf("\\(bv");
1140Sstevel@tonic-gate 				printf("\\(rb'");
1150Sstevel@tonic-gate 				break;
1160Sstevel@tonic-gate 			case ']':
1170Sstevel@tonic-gate 				brack(m, "\\(rc", "\\(bv", "\\(rf");
1180Sstevel@tonic-gate 				break;
1190Sstevel@tonic-gate 			case ')':
1200Sstevel@tonic-gate 				brack(m, "\\(rt", "\\(bv", "\\(rb");
1210Sstevel@tonic-gate 				break;
1220Sstevel@tonic-gate 			case '|':
1230Sstevel@tonic-gate 				brack(m, "\\(bv", "\\(bv", "\\(bv");
1240Sstevel@tonic-gate 				break;
1250Sstevel@tonic-gate 			default:
126*364Sceastha 				brack(m, (char *)&rightc, (char *)&rightc,
127*364Sceastha 				    (char *)&rightc);
1280Sstevel@tonic-gate 				break;
1290Sstevel@tonic-gate 		}
1300Sstevel@tonic-gate 		printf("\\v'%du'", -v);
1310Sstevel@tonic-gate 	}
1320Sstevel@tonic-gate 	printf("\n");
133*364Sceastha 	if (dbg)
134*364Sceastha 		printf(".\tcurly: h=%d b=%d n=%d v=%d l=%c, r=%c\n",
135*364Sceastha 		    eht[yyval], ebase[yyval], n, v, leftc, rightc);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
138*364Sceastha void
brack(int m,char * t,char * c,char * b)139*364Sceastha brack(int m, char *t, char *c, char *b)
140*364Sceastha {
1410Sstevel@tonic-gate 	int j;
1420Sstevel@tonic-gate 	printf("\\b'%s", t);
143*364Sceastha 	for (j = 0; j < m; j++)
1440Sstevel@tonic-gate 		printf("%s", c);
1450Sstevel@tonic-gate 	printf("%s'", b);
1460Sstevel@tonic-gate }
147