1*779fc935Sceastha /* 2*779fc935Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*779fc935Sceastha * Use is subject to license terms. 4*779fc935Sceastha */ 5*779fc935Sceastha 67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 77c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate /* 107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 137c478bd9Sstevel@tonic-gate */ 147c478bd9Sstevel@tonic-gate 15*779fc935Sceastha #pragma ident "%Z%%M% %I% %E% SMI" 167c478bd9Sstevel@tonic-gate 177c478bd9Sstevel@tonic-gate #include "e.h" 187c478bd9Sstevel@tonic-gate 19*779fc935Sceastha extern int max(); 20*779fc935Sceastha 21*779fc935Sceastha void brack(int, char *, char *, char *); 22*779fc935Sceastha 23*779fc935Sceastha void 24*779fc935Sceastha paren(int leftc, int p1, int rightc) 25*779fc935Sceastha { 267c478bd9Sstevel@tonic-gate int n, m, h1, j, b1, v; 277c478bd9Sstevel@tonic-gate h1 = eht[p1]; b1 = ebase[p1]; 287c478bd9Sstevel@tonic-gate yyval = p1; 297c478bd9Sstevel@tonic-gate #ifndef NEQN 307c478bd9Sstevel@tonic-gate lfont[yyval] = rfont[yyval] = 0; 317c478bd9Sstevel@tonic-gate n = (h1 + EM(1.0, EFFPS(ps)) - 1) / EM(1.0, EFFPS(ps)); 32*779fc935Sceastha #else /* NEQN */ 337c478bd9Sstevel@tonic-gate n = max(b1+VERT(1), h1-b1-VERT(1)) / VERT(1); 34*779fc935Sceastha #endif /* NEQN */ 357c478bd9Sstevel@tonic-gate if (n < 2) n = 1; 367c478bd9Sstevel@tonic-gate m = n-2; 377c478bd9Sstevel@tonic-gate if (leftc == '{' || rightc == '}') { 38*779fc935Sceastha if ((n % 2) == 0) { 39*779fc935Sceastha n++; 40*779fc935Sceastha } 417c478bd9Sstevel@tonic-gate if (n < 3) n = 3; 427c478bd9Sstevel@tonic-gate m = n-3; 437c478bd9Sstevel@tonic-gate } 447c478bd9Sstevel@tonic-gate #ifndef NEQN 457c478bd9Sstevel@tonic-gate eht[yyval] = VERT(EM(n, ps)); 467c478bd9Sstevel@tonic-gate ebase[yyval] = b1 + (eht[yyval]-h1)/2; 477c478bd9Sstevel@tonic-gate v = b1 - h1/2 + VERT(EM(0.4, ps)); 48*779fc935Sceastha #else /* NEQN */ 497c478bd9Sstevel@tonic-gate eht[yyval] = VERT(2 * n); 507c478bd9Sstevel@tonic-gate ebase[yyval] = (n)/2 * VERT(2); 517c478bd9Sstevel@tonic-gate if (n%2 == 0) 527c478bd9Sstevel@tonic-gate ebase[yyval] -= VERT(1); 537c478bd9Sstevel@tonic-gate v = b1 - h1/2 + VERT(1); 54*779fc935Sceastha #endif /* NEQN */ 557c478bd9Sstevel@tonic-gate printf(".ds %d \\|\\v'%du'", yyval, v); 567c478bd9Sstevel@tonic-gate switch (leftc) { 577c478bd9Sstevel@tonic-gate case 'n': /* nothing */ 587c478bd9Sstevel@tonic-gate case '\0': 597c478bd9Sstevel@tonic-gate break; 607c478bd9Sstevel@tonic-gate case 'f': /* floor */ 617c478bd9Sstevel@tonic-gate if (n <= 1) 627c478bd9Sstevel@tonic-gate printf("\\(lf"); 637c478bd9Sstevel@tonic-gate else 647c478bd9Sstevel@tonic-gate brack(m, "\\(bv", "\\(bv", "\\(lf"); 657c478bd9Sstevel@tonic-gate break; 667c478bd9Sstevel@tonic-gate case 'c': /* ceiling */ 677c478bd9Sstevel@tonic-gate if (n <= 1) 687c478bd9Sstevel@tonic-gate printf("\\(lc"); 697c478bd9Sstevel@tonic-gate else 707c478bd9Sstevel@tonic-gate brack(m, "\\(lc", "\\(bv", "\\(bv"); 717c478bd9Sstevel@tonic-gate break; 727c478bd9Sstevel@tonic-gate case '{': 737c478bd9Sstevel@tonic-gate printf("\\b'\\(lt"); 747c478bd9Sstevel@tonic-gate for (j = 0; j < m; j += 2) printf("\\(bv"); 757c478bd9Sstevel@tonic-gate printf("\\(lk"); 767c478bd9Sstevel@tonic-gate for (j = 0; j < m; j += 2) printf("\\(bv"); 777c478bd9Sstevel@tonic-gate printf("\\(lb'"); 787c478bd9Sstevel@tonic-gate break; 797c478bd9Sstevel@tonic-gate case '(': 807c478bd9Sstevel@tonic-gate brack(m, "\\(lt", "\\(bv", "\\(lb"); 817c478bd9Sstevel@tonic-gate break; 827c478bd9Sstevel@tonic-gate case '[': 837c478bd9Sstevel@tonic-gate brack(m, "\\(lc", "\\(bv", "\\(lf"); 847c478bd9Sstevel@tonic-gate break; 857c478bd9Sstevel@tonic-gate case '|': 867c478bd9Sstevel@tonic-gate brack(m, "\\(bv", "\\(bv", "\\(bv"); 877c478bd9Sstevel@tonic-gate break; 887c478bd9Sstevel@tonic-gate default: 89*779fc935Sceastha brack(m, (char *)&leftc, (char *)&leftc, 90*779fc935Sceastha (char *)&leftc); 917c478bd9Sstevel@tonic-gate break; 927c478bd9Sstevel@tonic-gate } 937c478bd9Sstevel@tonic-gate printf("\\v'%du'\\*(%d", -v, p1); 947c478bd9Sstevel@tonic-gate if (rightc) { 957c478bd9Sstevel@tonic-gate printf("\\|\\v'%du'", v); 967c478bd9Sstevel@tonic-gate switch (rightc) { 977c478bd9Sstevel@tonic-gate case 'f': /* floor */ 987c478bd9Sstevel@tonic-gate if (n <= 1) 997c478bd9Sstevel@tonic-gate printf("\\(rf"); 1007c478bd9Sstevel@tonic-gate else 1017c478bd9Sstevel@tonic-gate brack(m, "\\(bv", "\\(bv", "\\(rf"); 1027c478bd9Sstevel@tonic-gate break; 1037c478bd9Sstevel@tonic-gate case 'c': /* ceiling */ 1047c478bd9Sstevel@tonic-gate if (n <= 1) 1057c478bd9Sstevel@tonic-gate printf("\\(rc"); 1067c478bd9Sstevel@tonic-gate else 1077c478bd9Sstevel@tonic-gate brack(m, "\\(rc", "\\(bv", "\\(bv"); 1087c478bd9Sstevel@tonic-gate break; 1097c478bd9Sstevel@tonic-gate case '}': 1107c478bd9Sstevel@tonic-gate printf("\\b'\\(rt"); 1117c478bd9Sstevel@tonic-gate for (j = 0; j < m; j += 2) printf("\\(bv"); 1127c478bd9Sstevel@tonic-gate printf("\\(rk"); 1137c478bd9Sstevel@tonic-gate for (j = 0; j < m; j += 2) printf("\\(bv"); 1147c478bd9Sstevel@tonic-gate printf("\\(rb'"); 1157c478bd9Sstevel@tonic-gate break; 1167c478bd9Sstevel@tonic-gate case ']': 1177c478bd9Sstevel@tonic-gate brack(m, "\\(rc", "\\(bv", "\\(rf"); 1187c478bd9Sstevel@tonic-gate break; 1197c478bd9Sstevel@tonic-gate case ')': 1207c478bd9Sstevel@tonic-gate brack(m, "\\(rt", "\\(bv", "\\(rb"); 1217c478bd9Sstevel@tonic-gate break; 1227c478bd9Sstevel@tonic-gate case '|': 1237c478bd9Sstevel@tonic-gate brack(m, "\\(bv", "\\(bv", "\\(bv"); 1247c478bd9Sstevel@tonic-gate break; 1257c478bd9Sstevel@tonic-gate default: 126*779fc935Sceastha brack(m, (char *)&rightc, (char *)&rightc, 127*779fc935Sceastha (char *)&rightc); 1287c478bd9Sstevel@tonic-gate break; 1297c478bd9Sstevel@tonic-gate } 1307c478bd9Sstevel@tonic-gate printf("\\v'%du'", -v); 1317c478bd9Sstevel@tonic-gate } 1327c478bd9Sstevel@tonic-gate printf("\n"); 133*779fc935Sceastha if (dbg) 134*779fc935Sceastha printf(".\tcurly: h=%d b=%d n=%d v=%d l=%c, r=%c\n", 1357c478bd9Sstevel@tonic-gate eht[yyval], ebase[yyval], n, v, leftc, rightc); 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate 138*779fc935Sceastha void 139*779fc935Sceastha brack(int m, char *t, char *c, char *b) 140*779fc935Sceastha { 1417c478bd9Sstevel@tonic-gate int j; 1427c478bd9Sstevel@tonic-gate printf("\\b'%s", t); 1437c478bd9Sstevel@tonic-gate for (j = 0; j < m; j++) 1447c478bd9Sstevel@tonic-gate printf("%s", c); 1457c478bd9Sstevel@tonic-gate printf("%s'", b); 1467c478bd9Sstevel@tonic-gate } 147