1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 31 #pragma ident "%Z%%M% %I% %E% SMI" 32 33 /* 34 * University Copyright- Copyright (c) 1982, 1986, 1988 35 * The Regents of the University of California 36 * All Rights Reserved 37 * 38 * University Acknowledgment- Portions of this document are derived from 39 * software developed by the University of California, Berkeley, and its 40 * contributors. 41 */ 42 43 #include "tdef.h" 44 #include "tw.h" 45 #include "ext.h" 46 #include <ctype.h> 47 48 /* 49 * n6.c -- width functions, sizes and fonts 50 */ 51 52 int bdtab[NFONT+1] ={ 0, 0, 0, 3, 3, 0, }; 53 int sbold = 0; 54 int fontlab[NFONT+1] = { 0, 'R', 'I', 'B', PAIR('B','I'), 'S', 0 }; 55 56 extern int nchtab; 57 58 width(j) 59 register tchar j; 60 { 61 register i, k; 62 63 if (j & (ZBIT|MOT)) { 64 if (iszbit(j)) 65 return(0); 66 if (isvmot(j)) 67 return(0); 68 k = absmot(j); 69 if (isnmot(j)) 70 k = -k; 71 return(k); 72 } 73 i = cbits(j); 74 if (i < ' ') { 75 if (i == '\b') 76 return(-widthp); 77 if (i == PRESC) 78 i = eschar; 79 else if (iscontrol(i)) 80 return(0); 81 } 82 if (i==ohc) 83 return(0); 84 #ifdef EUC 85 #ifdef NROFF 86 if (multi_locale) { 87 if ((j & MBMASK) || (j & CSMASK)) { 88 switch(j & MBMASK) { 89 case BYTE_CHR: 90 case LASTOFMB: 91 k = t.Char * csi_width[cs(j)]; 92 break; 93 default: 94 k = 0; 95 break; 96 } 97 widthp = k; 98 return(k); 99 } 100 } 101 i &= 0x1ff; 102 #endif /* NROFF */ 103 #endif /* EUC */ 104 i = trtab[i]; 105 if (i < 32) 106 return(0); 107 k = t.width[i] * t.Char; 108 widthp = k; 109 return(k); 110 } 111 112 113 tchar setch() 114 { 115 register j; 116 char temp[10]; 117 register char *s; 118 119 s = temp; 120 if ((*s++ = getach()) == 0 || (*s++ = getach()) == 0) 121 return(0); 122 *s = '\0'; 123 if ((j = findch(temp)) > 0) 124 return j | chbits; 125 else 126 return 0; 127 } 128 129 tchar setabs() /* set absolute char from \C'...' */ 130 { /* for now, a no-op */ 131 int i, n, nf; 132 133 getch(); 134 n = 0; 135 n = inumb(&n); 136 getch(); 137 if (nonumb) 138 return 0; 139 return n + nchtab + _SPECCHAR_ST; 140 } 141 142 findft(i) 143 register int i; 144 { 145 register k; 146 147 if ((k = i - '0') >= 0 && k <= nfonts && k < smnt) 148 return(k); 149 for (k = 0; fontlab[k] != i; k++) 150 if (k > nfonts) 151 return(-1); 152 return(k); 153 } 154 155 156 caseps() 157 { 158 } 159 160 161 mchbits() 162 { 163 chbits = 0; 164 setfbits(chbits, font); 165 sps = width(' ' | chbits); 166 } 167 168 169 setps() 170 { 171 register i, j; 172 173 i = cbits(getch()); 174 if (ischar(i) && isdigit(i)) { /* \sd or \sdd */ 175 i -= '0'; 176 if (i == 0) /* \s0 */ 177 ; 178 else if (i <= 3 && ischar(j = cbits(ch = getch())) && 179 isdigit(j)) { /* \sdd */ 180 ch = 0; 181 } 182 } else if (i == '(') { /* \s(dd */ 183 getch(); 184 getch(); 185 } else if (i == '+' || i == '-') { /* \s+, \s- */ 186 j = cbits(getch()); 187 if (ischar(j) && isdigit(j)) { /* \s+d, \s-d */ 188 ; 189 } else if (j == '(') { /* \s+(dd, \s-(dd */ 190 getch(); 191 getch(); 192 } 193 } 194 } 195 196 197 tchar setht() /* set character height from \H'...' */ 198 { 199 int n; 200 tchar c; 201 202 getch(); 203 n = inumb(&apts); 204 getch(); 205 return(0); 206 } 207 208 209 tchar setslant() /* set slant from \S'...' */ 210 { 211 int n; 212 tchar c; 213 214 getch(); 215 n = 0; 216 n = inumb(&n); 217 getch(); 218 return(0); 219 } 220 221 222 caseft() 223 { 224 skip(); 225 setfont(1); 226 } 227 228 229 setfont(a) 230 int a; 231 { 232 register i, j; 233 234 if (a) 235 i = getrq(); 236 else 237 i = getsn(); 238 if (!i || i == 'P') { 239 j = font1; 240 goto s0; 241 } 242 if (i == 'S' || i == '0') 243 return; 244 if ((j = findft(i, fontlab)) == -1) 245 return; 246 s0: 247 font1 = font; 248 font = j; 249 mchbits(); 250 } 251 252 253 setwd() 254 { 255 register base, wid; 256 register tchar i; 257 int delim, emsz, k; 258 int savhp, savapts, savapts1, savfont, savfont1, savpts, savpts1; 259 260 base = numtab[ST].val = numtab[ST].val = wid = numtab[CT].val = 0; 261 if (ismot(i = getch())) 262 return; 263 delim = cbits(i); 264 savhp = numtab[HP].val; 265 numtab[HP].val = 0; 266 savapts = apts; 267 savapts1 = apts1; 268 savfont = font; 269 savfont1 = font1; 270 savpts = pts; 271 savpts1 = pts1; 272 setwdf++; 273 while (cbits(i = getch()) != delim && !nlflg) { 274 k = width(i); 275 wid += k; 276 numtab[HP].val += k; 277 if (!ismot(i)) { 278 emsz = (INCH * pts + 36) / 72; 279 } else if (isvmot(i)) { 280 k = absmot(i); 281 if (isnmot(i)) 282 k = -k; 283 base -= k; 284 emsz = 0; 285 } else 286 continue; 287 if (base < numtab[SB].val) 288 numtab[SB].val = base; 289 if ((k = base + emsz) > numtab[ST].val) 290 numtab[ST].val = k; 291 } 292 setn1(wid, 0, (tchar) 0); 293 numtab[HP].val = savhp; 294 apts = savapts; 295 apts1 = savapts1; 296 font = savfont; 297 font1 = savfont1; 298 pts = savpts; 299 pts1 = savpts1; 300 mchbits(); 301 setwdf = 0; 302 } 303 304 305 tchar vmot() 306 { 307 dfact = lss; 308 vflag++; 309 return(mot()); 310 } 311 312 313 tchar hmot() 314 { 315 dfact = EM; 316 return(mot()); 317 } 318 319 320 tchar mot() 321 { 322 register int j, n; 323 register tchar i; 324 325 j = HOR; 326 getch(); /*eat delim*/ 327 if (n = atoi()) { 328 if (vflag) 329 j = VERT; 330 i = makem(quant(n, j)); 331 } else 332 i = 0; 333 getch(); 334 vflag = 0; 335 dfact = 1; 336 return(i); 337 } 338 339 340 tchar sethl(k) 341 int k; 342 { 343 register j; 344 tchar i; 345 346 j = t.Halfline; 347 if (k == 'u') 348 j = -j; 349 else if (k == 'r') 350 j = -2 * j; 351 vflag++; 352 i = makem(j); 353 vflag = 0; 354 return(i); 355 } 356 357 358 tchar makem(i) 359 int i; 360 { 361 register tchar j; 362 363 if ((j = i) < 0) 364 j = -j; 365 j |= MOT; 366 if (i < 0) 367 j |= NMOT; 368 if (vflag) 369 j |= VMOT; 370 return(j); 371 } 372 373 374 tchar getlg(i) 375 tchar i; 376 { 377 return(i); 378 } 379 380 381 caselg() 382 { 383 } 384 385 386 casefp() 387 { 388 register i, j; 389 390 skip(); 391 if ((i = cbits(getch()) - '0') < 0 || i > nfonts) 392 return; 393 if (skip() || !(j = getrq())) 394 return; 395 fontlab[i] = j; 396 } 397 398 399 casecs() 400 { 401 } 402 403 404 casebd() 405 { 406 register i, j, k; 407 408 k = 0; 409 bd0: 410 if (skip() || !(i = getrq()) || (j = findft(i)) == -1) { 411 if (k) 412 goto bd1; 413 else 414 return; 415 } 416 if (j == smnt) { 417 k = smnt; 418 goto bd0; 419 } 420 if (k) { 421 sbold = j; 422 j = k; 423 } 424 bd1: 425 skip(); 426 noscale++; 427 bdtab[j] = atoi(); 428 noscale = 0; 429 } 430 431 432 casevs() 433 { 434 register i; 435 436 skip(); 437 vflag++; 438 dfact = INCH; /*default scaling is points!*/ 439 dfactd = 72; 440 res = VERT; 441 i = inumb(&lss); 442 if (nonumb) 443 i = lss1; 444 if (i < VERT) 445 i = VERT; /* was VERT */ 446 lss1 = lss; 447 lss = i; 448 } 449 450 451 452 453 casess() 454 { 455 } 456 457 458 tchar xlss() 459 { 460 /* stores \x'...' into 461 * two successive tchars. 462 * the first contains HX, the second the value, 463 * encoded as a vertical motion. 464 * decoding is done in n2.c by pchar(). 465 */ 466 int i; 467 468 getch(); 469 dfact = lss; 470 i = quant(atoi(), VERT); 471 dfact = 1; 472 getch(); 473 if (i >= 0) 474 *pbp++ = MOT | VMOT | i; 475 else 476 *pbp++ = MOT | VMOT | NMOT | -i; 477 return(HX); 478 } 479