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