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 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 #ifdef EUC 41 #ifdef NROFF 42 #include <stdlib.h> 43 #include <widec.h> 44 #include <limits.h> 45 #endif /* NROFF */ 46 #endif /* EUC */ 47 #include "tdef.h" 48 #ifdef NROFF 49 #include "tw.h" 50 #endif 51 #ifdef NROFF 52 #define GETCH gettch 53 tchar gettch(); 54 #endif 55 #ifndef NROFF 56 #define GETCH getch 57 #endif 58 59 /* 60 * troff7.c 61 * 62 * text 63 */ 64 65 #include <ctype.h> 66 #ifdef EUC 67 #ifdef NROFF 68 #include <wctype.h> 69 #endif /* NROFF */ 70 #endif /* EUC */ 71 #include "ext.h" 72 #ifdef EUC 73 #ifdef NROFF 74 char mbbuf2[MB_LEN_MAX + 1]; 75 char *mbbuf2p = mbbuf2; 76 tchar mtbuf[MB_LEN_MAX + 1]; 77 tchar *mtbufp; 78 int pendmb = 0; 79 wchar_t cwc, owc, wceoll; 80 #endif /* NROFF */ 81 #endif /* EUC */ 82 int brflg; 83 84 int 85 tbreak() 86 { 87 int pad, k; 88 tchar *i, j; 89 int resol = 0; 90 #ifdef EUC 91 #ifdef NROFF 92 tchar l; 93 #endif /* NROFF */ 94 #endif /* EUC */ 95 96 trap = 0; 97 if (nb) 98 return (0); 99 if (dip == d && numtab[NL].val == -1) { 100 newline(1); 101 return (0); 102 } 103 if (!nc) { 104 setnel(); 105 if (!wch) 106 return (0); 107 if (pendw) 108 getword(1); 109 movword(); 110 } else if (pendw && !brflg) { 111 getword(1); 112 movword(); 113 } 114 *linep = dip->nls = 0; 115 #ifdef NROFF 116 if (dip == d) 117 horiz(po); 118 #endif 119 if (lnmod) 120 donum(); 121 lastl = ne; 122 if (brflg != 1) { 123 totout = 0; 124 } else if (ad) { 125 if ((lastl = ll - un) < ne) 126 lastl = ne; 127 } 128 if (admod && ad && (brflg != 2)) { 129 lastl = ne; 130 adsp = adrem = 0; 131 if (admod == 1) 132 un += quant(nel / 2, HOR); 133 else if (admod == 2) 134 un += nel; 135 } 136 totout++; 137 brflg = 0; 138 if (lastl + un > dip->maxl) 139 dip->maxl = lastl + un; 140 horiz(un); 141 #ifdef NROFF 142 if (adrem % t.Adj) 143 resol = t.Hor; 144 else 145 resol = t.Adj; 146 #else 147 resol = HOR; 148 #endif 149 adrem = (adrem / resol) * resol; 150 for (i = line; nc > 0; ) { 151 #ifndef EUC 152 if ((cbits(j = *i++)) == ' ') { 153 #else 154 #ifndef NROFF 155 if ((cbits(j = *i++)) == ' ') { 156 #else 157 if ((cbits(j = *i++) & ~MBMASK) == ' ') { 158 #endif /* NROFF */ 159 #endif /* EUC */ 160 pad = 0; 161 do { 162 pad += width(j); 163 nc--; 164 #ifndef EUC 165 } while ((cbits(j = *i++)) == ' '); 166 #else 167 #ifndef NROFF 168 } while ((cbits(j = *i++)) == ' '); 169 #else 170 } while ((cbits(j = *i++) & ~MBMASK) == ' '); 171 #endif /* NROFF */ 172 #endif /* EUC */ 173 i--; 174 pad += adsp; 175 --nwd; 176 if (adrem) { 177 if (adrem < 0) { 178 pad -= resol; 179 adrem += resol; 180 } else if ((totout & 01) || adrem / resol >= nwd) { 181 pad += resol; 182 adrem -= resol; 183 } 184 } 185 pchar((tchar) WORDSP); 186 horiz(pad); 187 } else { 188 pchar(j); 189 nc--; 190 } 191 } 192 if (ic) { 193 if ((k = ll - un - lastl + ics) > 0) 194 horiz(k); 195 pchar(ic); 196 } 197 if (icf) 198 icf++; 199 else 200 ic = 0; 201 ne = nwd = 0; 202 un = in; 203 setnel(); 204 newline(0); 205 if (dip != d) { 206 if (dip->dnl > dip->hnl) 207 dip->hnl = dip->dnl; 208 } else { 209 if (numtab[NL].val > dip->hnl) 210 dip->hnl = numtab[NL].val; 211 } 212 for (k = ls - 1; k > 0 && !trap; k--) 213 newline(0); 214 spread = 0; 215 216 return (0); 217 } 218 219 int 220 donum() 221 { 222 int i, nw; 223 extern int pchar(); 224 225 nrbits = nmbits; 226 nw = width('1' | nrbits); 227 if (nn) { 228 nn--; 229 goto d1; 230 } 231 if (numtab[LN].val % ndf) { 232 numtab[LN].val++; 233 d1: 234 un += nw * (3 + nms + ni); 235 return (0); 236 } 237 i = 0; 238 if (numtab[LN].val < 100) 239 i++; 240 if (numtab[LN].val < 10) 241 i++; 242 horiz(nw * (ni + i)); 243 nform = 0; 244 fnumb(numtab[LN].val, pchar); 245 un += nw * nms; 246 numtab[LN].val++; 247 248 return (0); 249 } 250 251 extern int logf; 252 253 int 254 text() 255 { 256 tchar i; 257 static int spcnt; 258 259 nflush++; 260 numtab[HP].val = 0; 261 if ((dip == d) && (numtab[NL].val == -1)) { 262 newline(1); 263 return (0); 264 } 265 setnel(); 266 if (ce || !fi) { 267 nofill(); 268 return (0); 269 } 270 if (pendw) 271 goto t4; 272 if (pendt) 273 if (spcnt) 274 goto t2; 275 else 276 goto t3; 277 pendt++; 278 if (spcnt) 279 goto t2; 280 while ((cbits(i = GETCH())) == ' ') { 281 spcnt++; 282 numtab[HP].val += sps; 283 widthp = sps; 284 } 285 if (nlflg) { 286 t1: 287 nflush = pendt = ch = spcnt = 0; 288 callsp(); 289 return (0); 290 } 291 ch = i; 292 if (spcnt) { 293 t2: 294 tbreak(); 295 if (nc || wch) 296 goto rtn; 297 un += spcnt * sps; 298 spcnt = 0; 299 setnel(); 300 if (trap) 301 goto rtn; 302 if (nlflg) 303 goto t1; 304 } 305 t3: 306 if (spread) 307 goto t5; 308 if (pendw || !wch) 309 t4: 310 if (getword(0)) 311 goto t6; 312 if (!movword()) 313 goto t3; 314 t5: 315 if (nlflg) 316 pendt = 0; 317 adsp = adrem = 0; 318 if (ad) { 319 if (nwd == 1) 320 adsp = nel; 321 else 322 adsp = nel / (nwd - 1); 323 adsp = (adsp / HOR) * HOR; 324 adrem = nel - adsp*(nwd-1); 325 } 326 brflg = 1; 327 tbreak(); 328 spread = 0; 329 if (!trap) 330 goto t3; 331 if (!nlflg) 332 goto rtn; 333 t6: 334 pendt = 0; 335 ckul(); 336 rtn: 337 nflush = 0; 338 339 return (0); 340 } 341 342 343 int 344 nofill() 345 { 346 int j; 347 tchar i; 348 349 if (!pendnf) { 350 over = 0; 351 tbreak(); 352 if (trap) 353 goto rtn; 354 if (nlflg) { 355 ch = nflush = 0; 356 callsp(); 357 return (0); 358 } 359 adsp = adrem = 0; 360 nwd = 10000; 361 } 362 while ((j = (cbits(i = GETCH()))) != '\n') { 363 if (j == ohc) 364 continue; 365 if (j == CONT) { 366 pendnf++; 367 nflush = 0; 368 flushi(); 369 ckul(); 370 return (0); 371 } 372 j = width(i); 373 widthp = j; 374 numtab[HP].val += j; 375 storeline(i, j); 376 } 377 if (ce) { 378 ce--; 379 if ((i = quant(nel / 2, HOR)) > 0) 380 un += i; 381 } 382 if (!nc) 383 storeline((tchar)FILLER, 0); 384 brflg = 2; 385 tbreak(); 386 ckul(); 387 rtn: 388 pendnf = nflush = 0; 389 390 return (0); 391 } 392 393 394 int 395 callsp() 396 { 397 int i; 398 399 if (flss) 400 i = flss; 401 else 402 i = lss; 403 flss = 0; 404 casesp(i); 405 406 return (0); 407 } 408 409 410 int 411 ckul() 412 { 413 if (ul && (--ul == 0)) { 414 cu = 0; 415 font = sfont; 416 mchbits(); 417 } 418 if (it && (--it == 0) && itmac) 419 control(itmac, 0); 420 421 return (0); 422 } 423 424 425 int 426 storeline(c, w) 427 tchar c; 428 { 429 if (linep >= line + lnsize - 1) { 430 if (!over) { 431 flusho(); 432 errprint(gettext("Line overflow.")); 433 over++; 434 c = LEFTHAND; 435 w = -1; 436 goto s1; 437 } 438 return (0); 439 } 440 s1: 441 if (w == -1) 442 w = width(c); 443 ne += w; 444 nel -= w; 445 *linep++ = c; 446 nc++; 447 448 return (0); 449 } 450 451 452 int 453 newline(a) 454 int a; 455 { 456 int i, j, nlss; 457 int opn; 458 459 if (a) 460 goto nl1; 461 if (dip != d) { 462 j = lss; 463 pchar1((tchar)FLSS); 464 if (flss) 465 lss = flss; 466 i = lss + dip->blss; 467 dip->dnl += i; 468 pchar1((tchar)i); 469 pchar1((tchar)'\n'); 470 lss = j; 471 dip->blss = flss = 0; 472 if (dip->alss) { 473 pchar1((tchar)FLSS); 474 pchar1((tchar)dip->alss); 475 pchar1((tchar)'\n'); 476 dip->dnl += dip->alss; 477 dip->alss = 0; 478 } 479 if (dip->ditrap && !dip->ditf && dip->dnl >= dip->ditrap && dip->dimac) 480 if (control(dip->dimac, 0)) { 481 trap++; 482 dip->ditf++; 483 } 484 return (0); 485 } 486 j = lss; 487 if (flss) 488 lss = flss; 489 nlss = dip->alss + dip->blss + lss; 490 numtab[NL].val += nlss; 491 #ifndef NROFF 492 if (ascii) { 493 dip->alss = dip->blss = 0; 494 } 495 #endif 496 pchar1((tchar)'\n'); 497 flss = 0; 498 lss = j; 499 if (numtab[NL].val < pl) 500 goto nl2; 501 nl1: 502 ejf = dip->hnl = numtab[NL].val = 0; 503 ejl = frame; 504 if (donef) { 505 if ((!nc && !wch) || ndone) 506 done1(0); 507 ndone++; 508 donef = 0; 509 if (frame == stk) 510 nflush++; 511 } 512 opn = numtab[PN].val; 513 numtab[PN].val++; 514 if (npnflg) { 515 numtab[PN].val = npn; 516 npn = npnflg = 0; 517 } 518 nlpn: 519 if (numtab[PN].val == pfrom) { 520 print++; 521 pfrom = -1; 522 } else if (opn == pto) { 523 print = 0; 524 opn = -1; 525 chkpn(); 526 goto nlpn; 527 } 528 if (print) 529 newpage(numtab[PN].val); /* supposedly in a clean state so can pause */ 530 if (stop && print) { 531 dpn++; 532 if (dpn >= stop) { 533 dpn = 0; 534 dostop(); 535 } 536 } 537 nl2: 538 trap = 0; 539 if (numtab[NL].val == 0) { 540 if ((j = findn(0)) != NTRAP) 541 trap = control(mlist[j], 0); 542 } else if ((i = findt(numtab[NL].val - nlss)) <= nlss) { 543 if ((j = findn1(numtab[NL].val - nlss + i)) == NTRAP) { 544 flusho(); 545 errprint(gettext("Trap botch.")); 546 done2(-5); 547 } 548 trap = control(mlist[j], 0); 549 } 550 551 return (0); 552 } 553 554 555 int 556 findn1(a) 557 int a; 558 { 559 int i, j; 560 561 for (i = 0; i < NTRAP; i++) { 562 if (mlist[i]) { 563 if ((j = nlist[i]) < 0) 564 j += pl; 565 if (j == a) 566 break; 567 } 568 } 569 return(i); 570 } 571 572 int 573 chkpn() 574 { 575 pto = *(pnp++); 576 pfrom = pto>=0 ? pto : -pto; 577 if (pto == -32767) { 578 flusho(); 579 done1(0); 580 } 581 if (pto < 0) { 582 pto = -pto; 583 print++; 584 pfrom = 0; 585 } 586 587 return (0); 588 } 589 590 591 int 592 findt(a) 593 int a; 594 { 595 int i, j, k; 596 597 k = 32767; 598 if (dip != d) { 599 if (dip->dimac && (i = dip->ditrap - a) > 0) 600 k = i; 601 return(k); 602 } 603 for (i = 0; i < NTRAP; i++) { 604 if (mlist[i]) { 605 if ((j = nlist[i]) < 0) 606 j += pl; 607 if ((j -= a) <= 0) 608 continue; 609 if (j < k) 610 k = j; 611 } 612 } 613 i = pl - a; 614 if (k > i) 615 k = i; 616 return(k); 617 } 618 619 620 int 621 findt1() 622 { 623 int i; 624 625 if (dip != d) 626 i = dip->dnl; 627 else 628 i = numtab[NL].val; 629 return(findt(i)); 630 } 631 632 633 int 634 eject(a) 635 struct s *a; 636 { 637 int savlss; 638 639 if (dip != d) 640 return (0); 641 ejf++; 642 if (a) 643 ejl = a; 644 else 645 ejl = frame; 646 if (trap) 647 return (0); 648 e1: 649 savlss = lss; 650 lss = findt(numtab[NL].val); 651 newline(0); 652 lss = savlss; 653 if (numtab[NL].val && !trap) 654 goto e1; 655 656 return (0); 657 } 658 659 660 int 661 movword() 662 { 663 int w; 664 tchar i, *wp; 665 int savwch, hys; 666 667 over = 0; 668 wp = wordp; 669 if (!nwd) { 670 #ifndef EUC 671 while (cbits(i = *wp++) == ' ') { 672 #else 673 #ifndef NROFF 674 while (cbits(i = *wp++) == ' ') { 675 #else 676 while ((cbits(i = *wp++) & ~MBMASK) == ' ') { 677 #endif /* NROFF */ 678 #endif /* EUC */ 679 wch--; 680 wne -= sps; 681 } 682 wp--; 683 } 684 if (wne > nel && !hyoff && hyf && (!nwd || nel > 3 * sps) && 685 (!(hyf & 02) || (findt1() > lss))) 686 hyphen(wp); 687 savwch = wch; 688 hyp = hyptr; 689 nhyp = 0; 690 while (*hyp && *hyp <= wp) 691 hyp++; 692 while (wch) { 693 if (hyoff != 1 && *hyp == wp) { 694 hyp++; 695 if (!wdstart || (wp > wdstart + 1 && wp < wdend && 696 (!(hyf & 04) || wp < wdend - 1) && /* 04 => last 2 */ 697 (!(hyf & 010) || wp > wdstart + 2))) { /* 010 => 1st 2 */ 698 nhyp++; 699 storeline((tchar)IMP, 0); 700 } 701 } 702 i = *wp++; 703 w = width(i); 704 wne -= w; 705 wch--; 706 storeline(i, w); 707 } 708 if (nel >= 0) { 709 nwd++; 710 return(0); /* line didn't fill up */ 711 } 712 #ifndef NROFF 713 xbits((tchar)HYPHEN, 1); 714 #endif 715 hys = width((tchar)HYPHEN); 716 m1: 717 if (!nhyp) { 718 if (!nwd) 719 goto m3; 720 if (wch == savwch) 721 goto m4; 722 } 723 if (*--linep != IMP) 724 goto m5; 725 if (!(--nhyp)) 726 if (!nwd) 727 goto m2; 728 if (nel < hys) { 729 nc--; 730 goto m1; 731 } 732 m2: 733 if ((i = cbits(*(linep - 1))) != '-' && i != EMDASH) { 734 *linep = (*(linep - 1) & SFMASK) | HYPHEN; 735 w = width(*linep); 736 nel -= w; 737 ne += w; 738 linep++; 739 } 740 m3: 741 nwd++; 742 m4: 743 wordp = wp; 744 return(1); /* line filled up */ 745 m5: 746 nc--; 747 w = width(*linep); 748 ne -= w; 749 nel += w; 750 wne += w; 751 wch++; 752 wp--; 753 goto m1; 754 } 755 756 757 int 758 horiz(i) 759 int i; 760 { 761 vflag = 0; 762 if (i) 763 pchar(makem(i)); 764 765 return (0); 766 } 767 768 769 int 770 setnel() 771 { 772 if (!nc) { 773 linep = line; 774 if (un1 >= 0) { 775 un = un1; 776 un1 = -1; 777 } 778 nel = ll - un; 779 ne = adsp = adrem = 0; 780 } 781 782 return (0); 783 } 784 785 int 786 getword(x) 787 int x; 788 { 789 int j, k; 790 tchar i, *wp; 791 int noword; 792 #ifdef EUC 793 #ifdef NROFF 794 wchar_t *wddelim; 795 char mbbuf3[MB_LEN_MAX + 1]; 796 char *mbbuf3p; 797 int wbf, n; 798 tchar m; 799 #endif /* NROFF */ 800 #endif /* EUC */ 801 802 noword = 0; 803 if (x) 804 if (pendw) { 805 *pendw = 0; 806 goto rtn; 807 } 808 if (wordp = pendw) 809 goto g1; 810 hyp = hyptr; 811 wordp = word; 812 over = wne = wch = 0; 813 hyoff = 0; 814 #ifdef EUC 815 #ifdef NROFF 816 mtbufp = mtbuf; 817 if (pendmb) { 818 while(*mtbufp) { 819 switch(*mtbufp & MBMASK) { 820 case LASTOFMB: 821 case BYTE_CHR: 822 storeword(*mtbufp++, -1); 823 break; 824 825 default: 826 storeword(*mtbufp++, 0); 827 } 828 } 829 mtbufp = mtbuf; 830 pendmb = 0; 831 goto g1; 832 } 833 #endif /* NROFF */ 834 #endif /* EUC */ 835 while (1) { /* picks up 1st char of word */ 836 j = cbits(i = GETCH()); 837 #ifdef EUC 838 #ifdef NROFF 839 if (multi_locale) 840 if (collectmb(i)) 841 continue; 842 #endif /* NROFF */ 843 #endif /* EUC */ 844 if (j == '\n') { 845 wne = wch = 0; 846 noword = 1; 847 goto rtn; 848 } 849 if (j == ohc) { 850 hyoff = 1; /* 1 => don't hyphenate */ 851 continue; 852 } 853 if (j == ' ') { 854 numtab[HP].val += sps; 855 widthp = sps; 856 storeword(i, sps); 857 continue; 858 } 859 break; 860 } 861 #ifdef EUC 862 #ifdef NROFF 863 if (!multi_locale) 864 goto a0; 865 if (wddlm && iswprint(wceoll) && iswprint(cwc) && 866 (!iswascii(wceoll) || !iswascii(cwc)) && 867 !iswspace(wceoll) && !iswspace(cwc)) { 868 wddelim = (*wddlm)(wceoll, cwc, 1); 869 wceoll = 0; 870 if (*wddelim != ' ') { 871 if (!*wddelim) { 872 storeword(((*wdbdg)(wceoll, cwc, 1) < 3) ? 873 ZWDELIM(1) : ZWDELIM(2), 0); 874 } else { 875 while (*wddelim) { 876 if ((n = wctomb(mbbuf3, *wddelim++)) 877 > 0) { 878 mbbuf3[n] = 0; 879 n--; 880 mbbuf3p = mbbuf3 + n; 881 while(n) { 882 m = *(mbbuf3p-- - n--) & 883 0xff | MIDDLEOFMB | 884 ZBIT; 885 storeword(m, 0); 886 } 887 m = *mbbuf3p & 0xff | LASTOFMB; 888 storeword(m, -1); 889 } else { 890 storeword(' ' | chbits, sps); 891 break; 892 } 893 } 894 } 895 spflg = 0; 896 goto g0; 897 } 898 } 899 a0: 900 #endif /* NROFF */ 901 #endif /* EUC */ 902 storeword(' ' | chbits, sps); 903 if (spflg) { 904 storeword(' ' | chbits, sps); 905 spflg = 0; 906 } 907 g0: 908 if (j == CONT) { 909 pendw = wordp; 910 nflush = 0; 911 flushi(); 912 return(1); 913 } 914 if (hyoff != 1) { 915 if (j == ohc) { 916 hyoff = 2; 917 *hyp++ = wordp; 918 if (hyp > (hyptr + NHYP - 1)) 919 hyp = hyptr + NHYP - 1; 920 goto g1; 921 } 922 if (j == '-' || j == EMDASH) 923 if (wordp > word + 1) { 924 hyoff = 2; 925 *hyp++ = wordp + 1; 926 if (hyp > (hyptr + NHYP - 1)) 927 hyp = hyptr + NHYP - 1; 928 } 929 } 930 j = width(i); 931 numtab[HP].val += j; 932 #ifndef EUC 933 storeword(i, j); 934 #else 935 #ifndef NROFF 936 storeword(i, j); 937 #else 938 if (multi_locale) { 939 mtbufp = mtbuf; 940 while(*mtbufp) { 941 switch(*mtbufp & MBMASK) { 942 case LASTOFMB: 943 case BYTE_CHR: 944 storeword(*mtbufp++, j); 945 break; 946 947 default: 948 storeword(*mtbufp++, 0); 949 } 950 } 951 mtbufp = mtbuf; 952 } else { 953 storeword(i, j); 954 } 955 #endif /* NROFF */ 956 #endif /* EUC */ 957 g1: 958 j = cbits(i = GETCH()); 959 #ifdef EUC 960 #ifdef NROFF 961 if (multi_locale) 962 if (collectmb(i)) 963 goto g1; 964 #endif /* NROFF */ 965 #endif /* EUC */ 966 if (j != ' ') { 967 static char *sentchar = ".?!:"; /* sentence terminators */ 968 if (j != '\n') 969 #ifdef EUC 970 #ifdef NROFF 971 if (!multi_locale) 972 #endif /* NROFF */ 973 #endif /* EUC */ 974 goto g0; 975 #ifdef EUC 976 #ifdef NROFF 977 else { 978 if (!wdbdg || (iswascii(cwc) && iswascii(owc))) 979 goto g0; 980 if ((wbf = (*wdbdg)(owc, cwc, 1)) < 5) { 981 pendmb++; 982 storeword((wbf < 3) ? ZWDELIM(1) : 983 ZWDELIM(2), 0); 984 *wordp = 0; 985 goto rtn; 986 } else goto g0; 987 } 988 #endif /* NROFF */ 989 #endif /* EUC */ 990 wp = wordp-1; /* handle extra space at end of sentence */ 991 while (wp >= word) { 992 j = cbits(*wp--); 993 if (j=='"' || j=='\'' || j==')' || j==']' || j=='*' || j==DAGGER) 994 continue; 995 for (k = 0; sentchar[k]; k++) 996 if (j == sentchar[k]) { 997 spflg++; 998 break; 999 } 1000 break; 1001 } 1002 } 1003 #ifdef EUC 1004 #ifdef NROFF 1005 wceoll = owc; 1006 #endif /* NROFF */ 1007 #endif /* EUC */ 1008 *wordp = 0; 1009 numtab[HP].val += sps; 1010 rtn: 1011 for (wp = word; *wp; wp++) { 1012 j = cbits(*wp); 1013 if (j == ' ') 1014 continue; 1015 if (!ischar(j) || (!isdigit(j) && j != '-')) 1016 break; 1017 } 1018 if (*wp == 0) /* all numbers, so don't hyphenate */ 1019 hyoff = 1; 1020 wdstart = 0; 1021 wordp = word; 1022 pendw = 0; 1023 *hyp++ = 0; 1024 setnel(); 1025 return(noword); 1026 } 1027 1028 1029 int 1030 storeword(c, w) 1031 tchar c; 1032 int w; 1033 { 1034 1035 if (wordp >= &word[WDSIZE - 3]) { 1036 if (!over) { 1037 flusho(); 1038 errprint(gettext("Word overflow.")); 1039 over++; 1040 c = LEFTHAND; 1041 w = -1; 1042 goto s1; 1043 } 1044 return (0); 1045 } 1046 s1: 1047 if (w == -1) 1048 w = width(c); 1049 widthp = w; 1050 wne += w; 1051 *wordp++ = c; 1052 wch++; 1053 1054 return (0); 1055 } 1056 1057 1058 #ifdef NROFF 1059 tchar gettch() 1060 { 1061 extern int c_isalnum; 1062 tchar i; 1063 int j; 1064 1065 i = getch(); 1066 j = cbits(i); 1067 if (ismot(i) || fbits(i) != ulfont) 1068 return(i); 1069 if (cu) { 1070 if (trtab[j] == ' ') { 1071 setcbits(i, '_'); 1072 setfbits(i, FT); /* default */ 1073 } 1074 return(i); 1075 } 1076 /* should test here for characters that ought to be underlined */ 1077 /* in the old nroff, that was the 200 bit on the width! */ 1078 /* for now, just do letters, digits and certain special chars */ 1079 if (j <= 127) { 1080 if (!isalnum(j)) 1081 setfbits(i, FT); 1082 } else { 1083 if (j < c_isalnum) 1084 setfbits(i, FT); 1085 } 1086 return(i); 1087 } 1088 1089 1090 #endif 1091 #ifdef EUC 1092 #ifdef NROFF 1093 int 1094 collectmb(i) 1095 tchar i; 1096 { 1097 int busy; 1098 1099 *mtbufp++ = i; 1100 *mbbuf2p++ = i & BYTEMASK; 1101 *mtbufp = *mbbuf2p = 0; 1102 if (ismot(i)) { 1103 mtbufp = mtbuf; 1104 mbbuf2p = mbbuf2; 1105 owc = 0; 1106 cwc = 0; 1107 return(busy = 0); 1108 } 1109 if ((i & MBMASK) == MIDDLEOFMB) { 1110 if (mtbufp <= (mtbuf + MB_CUR_MAX)) { 1111 busy = 1; 1112 } else { 1113 *(mtbufp - 1) &= ~MBMASK; 1114 goto gotmb; 1115 } 1116 } else { 1117 if ((i & MBMASK) == LASTOFMB) 1118 *(mtbufp - 1) &= ~MBMASK; 1119 gotmb: 1120 mtbufp = mtbuf; 1121 owc = cwc; 1122 if (mbtowc(&cwc, mbbuf2, MB_CUR_MAX) <= 0) { 1123 mtbufp = mtbuf; 1124 while (*mtbufp) { 1125 setcbits(*mtbufp, (*mtbufp & 0x1ff)); 1126 mtbufp++; 1127 } 1128 mtbufp = mtbuf; 1129 } 1130 mbbuf2p = mbbuf2; 1131 busy = 0; 1132 } 1133 return(busy); 1134 } 1135 1136 1137 #endif /* NROFF */ 1138 #endif /* EUC */ 1139