17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate * The Regents of the University of California
337c478bd9Sstevel@tonic-gate * All Rights Reserved
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate * contributors.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #include <ctype.h>
417c478bd9Sstevel@tonic-gate #include "tdef.h"
427c478bd9Sstevel@tonic-gate #include "ext.h"
437c478bd9Sstevel@tonic-gate #define HY_BIT 0200 /* stuff in here only works for ascii */
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate * troff8.c
477c478bd9Sstevel@tonic-gate *
487c478bd9Sstevel@tonic-gate * hyphenation
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate char hbuf[NHEX];
527c478bd9Sstevel@tonic-gate char *nexth = hbuf;
537c478bd9Sstevel@tonic-gate tchar *hyend;
547c478bd9Sstevel@tonic-gate #define THRESH 160 /*digram goodness threshold*/
557c478bd9Sstevel@tonic-gate int thresh = THRESH;
567c478bd9Sstevel@tonic-gate
57e5190c10Smuffin int
hyphen(wp)587c478bd9Sstevel@tonic-gate hyphen(wp)
597c478bd9Sstevel@tonic-gate tchar *wp;
607c478bd9Sstevel@tonic-gate {
61e5190c10Smuffin int j;
62e5190c10Smuffin tchar *i;
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate i = wp;
657c478bd9Sstevel@tonic-gate while (punct(cbits(*i++)))
667c478bd9Sstevel@tonic-gate ;
677c478bd9Sstevel@tonic-gate if (!alph(cbits(*--i)))
68e5190c10Smuffin return (0);
697c478bd9Sstevel@tonic-gate wdstart = i++;
707c478bd9Sstevel@tonic-gate while (alph(cbits(*i++)))
717c478bd9Sstevel@tonic-gate ;
727c478bd9Sstevel@tonic-gate hyend = wdend = --i - 1;
737c478bd9Sstevel@tonic-gate while (punct(cbits(*i++)))
747c478bd9Sstevel@tonic-gate ;
757c478bd9Sstevel@tonic-gate if (*--i)
76e5190c10Smuffin return (0);
777c478bd9Sstevel@tonic-gate if ((wdend - wdstart - 4) < 0)
78e5190c10Smuffin return (0);
797c478bd9Sstevel@tonic-gate hyp = hyptr;
807c478bd9Sstevel@tonic-gate *hyp = 0;
817c478bd9Sstevel@tonic-gate hyoff = 2;
827c478bd9Sstevel@tonic-gate if (!exword() && !suffix())
837c478bd9Sstevel@tonic-gate digram();
847c478bd9Sstevel@tonic-gate *hyp++ = 0;
857c478bd9Sstevel@tonic-gate if (*hyptr)
867c478bd9Sstevel@tonic-gate for (j = 1; j; ) {
877c478bd9Sstevel@tonic-gate j = 0;
887c478bd9Sstevel@tonic-gate for (hyp = hyptr + 1; *hyp != 0; hyp++) {
897c478bd9Sstevel@tonic-gate if (*(hyp - 1) > *hyp) {
907c478bd9Sstevel@tonic-gate j++;
917c478bd9Sstevel@tonic-gate i = *hyp;
927c478bd9Sstevel@tonic-gate *hyp = *(hyp - 1);
937c478bd9Sstevel@tonic-gate *(hyp - 1) = i;
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate }
97e5190c10Smuffin
98e5190c10Smuffin return (0);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate
102e5190c10Smuffin int
punct(int i)103*e0dcd577SToomas Soome punct(int i)
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate if (!i || alph(i))
1067c478bd9Sstevel@tonic-gate return(0);
1077c478bd9Sstevel@tonic-gate else
1087c478bd9Sstevel@tonic-gate return(1);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate
112e5190c10Smuffin int
alph(int i)113*e0dcd577SToomas Soome alph(int i)
1147c478bd9Sstevel@tonic-gate {
1157c478bd9Sstevel@tonic-gate if (i >= 'a' && i <= 'z' || i >= 'A' && i <= 'Z')
1167c478bd9Sstevel@tonic-gate return(1);
1177c478bd9Sstevel@tonic-gate else
1187c478bd9Sstevel@tonic-gate return(0);
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate
122e5190c10Smuffin int
caseht()1237c478bd9Sstevel@tonic-gate caseht()
1247c478bd9Sstevel@tonic-gate {
1257c478bd9Sstevel@tonic-gate thresh = THRESH;
1267c478bd9Sstevel@tonic-gate if (skip())
127e5190c10Smuffin return (0);
1287c478bd9Sstevel@tonic-gate noscale++;
1297c478bd9Sstevel@tonic-gate thresh = atoi();
1307c478bd9Sstevel@tonic-gate noscale = 0;
131e5190c10Smuffin
132e5190c10Smuffin return (0);
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate
136e5190c10Smuffin int
casehw()1377c478bd9Sstevel@tonic-gate casehw()
1387c478bd9Sstevel@tonic-gate {
139e5190c10Smuffin int i, k;
140e5190c10Smuffin char *j;
1417c478bd9Sstevel@tonic-gate tchar t;
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate k = 0;
1447c478bd9Sstevel@tonic-gate while (!skip()) {
1457c478bd9Sstevel@tonic-gate if ((j = nexth) >= (hbuf + NHEX - 2))
1467c478bd9Sstevel@tonic-gate goto full;
1477c478bd9Sstevel@tonic-gate for (; ; ) {
1487c478bd9Sstevel@tonic-gate if (ismot(t = getch()))
1497c478bd9Sstevel@tonic-gate continue;
1507c478bd9Sstevel@tonic-gate i = cbits(t);
1517c478bd9Sstevel@tonic-gate if (i == ' ' || i == '\n') {
1527c478bd9Sstevel@tonic-gate *j++ = 0;
1537c478bd9Sstevel@tonic-gate nexth = j;
1547c478bd9Sstevel@tonic-gate *j = 0;
1557c478bd9Sstevel@tonic-gate if (i == ' ')
1567c478bd9Sstevel@tonic-gate break;
1577c478bd9Sstevel@tonic-gate else
158e5190c10Smuffin return (0);
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate if (i == '-') {
1617c478bd9Sstevel@tonic-gate k = HY_BIT;
1627c478bd9Sstevel@tonic-gate continue;
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate *j++ = maplow(i) | k;
1657c478bd9Sstevel@tonic-gate k = 0;
1667c478bd9Sstevel@tonic-gate if (j >= (hbuf + NHEX - 2))
1677c478bd9Sstevel@tonic-gate goto full;
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate }
170e5190c10Smuffin return (0);
1717c478bd9Sstevel@tonic-gate full:
1727c478bd9Sstevel@tonic-gate errprint(gettext("exception word list full."));
1737c478bd9Sstevel@tonic-gate *nexth = 0;
174e5190c10Smuffin
175e5190c10Smuffin return (0);
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate
179e5190c10Smuffin int
exword()1807c478bd9Sstevel@tonic-gate exword()
1817c478bd9Sstevel@tonic-gate {
182e5190c10Smuffin tchar *w;
183e5190c10Smuffin char *e;
1847c478bd9Sstevel@tonic-gate char *save;
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate e = hbuf;
1877c478bd9Sstevel@tonic-gate while (1) {
1887c478bd9Sstevel@tonic-gate save = e;
1897c478bd9Sstevel@tonic-gate if (*e == 0)
1907c478bd9Sstevel@tonic-gate return(0);
1917c478bd9Sstevel@tonic-gate w = wdstart;
1927c478bd9Sstevel@tonic-gate while (*e && w <= hyend && (*e & 0177) == maplow(cbits(*w))) {
1937c478bd9Sstevel@tonic-gate e++;
1947c478bd9Sstevel@tonic-gate w++;
1957c478bd9Sstevel@tonic-gate };
1967c478bd9Sstevel@tonic-gate if (!*e) {
1977c478bd9Sstevel@tonic-gate if (w-1 == hyend || (w == wdend && maplow(cbits(*w)) == 's')) {
1987c478bd9Sstevel@tonic-gate w = wdstart;
1997c478bd9Sstevel@tonic-gate for (e = save; *e; e++) {
2007c478bd9Sstevel@tonic-gate if (*e & HY_BIT)
2017c478bd9Sstevel@tonic-gate *hyp++ = w;
2027c478bd9Sstevel@tonic-gate if (hyp > (hyptr + NHYP - 1))
2037c478bd9Sstevel@tonic-gate hyp = hyptr + NHYP - 1;
2047c478bd9Sstevel@tonic-gate w++;
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate return(1);
2077c478bd9Sstevel@tonic-gate } else {
2087c478bd9Sstevel@tonic-gate e++;
2097c478bd9Sstevel@tonic-gate continue;
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate } else
2127c478bd9Sstevel@tonic-gate while (*e++)
2137c478bd9Sstevel@tonic-gate ;
2147c478bd9Sstevel@tonic-gate }
215e5190c10Smuffin
216e5190c10Smuffin return (0);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate
220e5190c10Smuffin int
suffix()2217c478bd9Sstevel@tonic-gate suffix()
2227c478bd9Sstevel@tonic-gate {
223e5190c10Smuffin tchar *w;
224e5190c10Smuffin char *s, *s0;
2257c478bd9Sstevel@tonic-gate tchar i;
2267c478bd9Sstevel@tonic-gate extern char *suftab[];
2277c478bd9Sstevel@tonic-gate extern tchar *chkvow();
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate again:
2307c478bd9Sstevel@tonic-gate if (!alph(cbits(i = cbits(*hyend))))
2317c478bd9Sstevel@tonic-gate return(0);
2327c478bd9Sstevel@tonic-gate if (i < 'a')
2337c478bd9Sstevel@tonic-gate i -= 'A' - 'a';
2347c478bd9Sstevel@tonic-gate if ((s0 = suftab[i-'a']) == 0)
2357c478bd9Sstevel@tonic-gate return(0);
2367c478bd9Sstevel@tonic-gate for (; ; ) {
2377c478bd9Sstevel@tonic-gate if ((i = *s0 & 017) == 0)
2387c478bd9Sstevel@tonic-gate return(0);
2397c478bd9Sstevel@tonic-gate s = s0 + i - 1;
2407c478bd9Sstevel@tonic-gate w = hyend - 1;
2417c478bd9Sstevel@tonic-gate while (s > s0 && w >= wdstart && (*s & 0177) == maplow(cbits(*w))) {
2427c478bd9Sstevel@tonic-gate s--;
2437c478bd9Sstevel@tonic-gate w--;
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate if (s == s0)
2467c478bd9Sstevel@tonic-gate break;
2477c478bd9Sstevel@tonic-gate s0 += i;
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate s = s0 + i - 1;
2507c478bd9Sstevel@tonic-gate w = hyend;
2517c478bd9Sstevel@tonic-gate if (*s0 & HY_BIT)
2527c478bd9Sstevel@tonic-gate goto mark;
2537c478bd9Sstevel@tonic-gate while (s > s0) {
2547c478bd9Sstevel@tonic-gate w--;
2557c478bd9Sstevel@tonic-gate if (*s-- & HY_BIT) {
2567c478bd9Sstevel@tonic-gate mark:
2577c478bd9Sstevel@tonic-gate hyend = w - 1;
2587c478bd9Sstevel@tonic-gate if (*s0 & 0100)
2597c478bd9Sstevel@tonic-gate continue;
2607c478bd9Sstevel@tonic-gate if (!chkvow(w))
2617c478bd9Sstevel@tonic-gate return(0);
2627c478bd9Sstevel@tonic-gate *hyp++ = w;
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate if (*s0 & 040)
2667c478bd9Sstevel@tonic-gate return(0);
2677c478bd9Sstevel@tonic-gate if (exword())
2687c478bd9Sstevel@tonic-gate return(1);
2697c478bd9Sstevel@tonic-gate goto again;
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate
273e5190c10Smuffin int
maplow(i)2747c478bd9Sstevel@tonic-gate maplow(i)
275e5190c10Smuffin int i;
2767c478bd9Sstevel@tonic-gate {
2777c478bd9Sstevel@tonic-gate if (ischar(i) && isupper(i))
2787c478bd9Sstevel@tonic-gate i = tolower(i);
2797c478bd9Sstevel@tonic-gate return(i);
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate
283e5190c10Smuffin int
vowel(i)2847c478bd9Sstevel@tonic-gate vowel(i)
2857c478bd9Sstevel@tonic-gate int i;
2867c478bd9Sstevel@tonic-gate {
2877c478bd9Sstevel@tonic-gate switch (maplow(i)) {
2887c478bd9Sstevel@tonic-gate case 'a':
2897c478bd9Sstevel@tonic-gate case 'e':
2907c478bd9Sstevel@tonic-gate case 'i':
2917c478bd9Sstevel@tonic-gate case 'o':
2927c478bd9Sstevel@tonic-gate case 'u':
2937c478bd9Sstevel@tonic-gate case 'y':
2947c478bd9Sstevel@tonic-gate return(1);
2957c478bd9Sstevel@tonic-gate default:
2967c478bd9Sstevel@tonic-gate return(0);
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate
chkvow(w)3017c478bd9Sstevel@tonic-gate tchar *chkvow(w)
3027c478bd9Sstevel@tonic-gate tchar *w;
3037c478bd9Sstevel@tonic-gate {
3047c478bd9Sstevel@tonic-gate while (--w >= wdstart)
3057c478bd9Sstevel@tonic-gate if (vowel(cbits(*w)))
3067c478bd9Sstevel@tonic-gate return(w);
3077c478bd9Sstevel@tonic-gate return(0);
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate
311e5190c10Smuffin int
digram()3127c478bd9Sstevel@tonic-gate digram()
3137c478bd9Sstevel@tonic-gate {
314e5190c10Smuffin tchar *w;
315e5190c10Smuffin int val;
3167c478bd9Sstevel@tonic-gate tchar * nhyend, *maxw;
3177c478bd9Sstevel@tonic-gate int maxval;
3187c478bd9Sstevel@tonic-gate extern char bxh[26][13], bxxh[26][13], xxh[26][13], xhx[26][13], hxx[26][13];
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate again:
3217c478bd9Sstevel@tonic-gate if (!(w = chkvow(hyend + 1)))
322e5190c10Smuffin return (0);
3237c478bd9Sstevel@tonic-gate hyend = w;
3247c478bd9Sstevel@tonic-gate if (!(w = chkvow(hyend)))
325e5190c10Smuffin return (0);
3267c478bd9Sstevel@tonic-gate nhyend = w;
3277c478bd9Sstevel@tonic-gate maxval = 0;
3287c478bd9Sstevel@tonic-gate w--;
3297c478bd9Sstevel@tonic-gate while ((++w < hyend) && (w < (wdend - 1))) {
3307c478bd9Sstevel@tonic-gate val = 1;
3317c478bd9Sstevel@tonic-gate if (w == wdstart)
3327c478bd9Sstevel@tonic-gate val *= dilook('a', cbits(*w), bxh);
3337c478bd9Sstevel@tonic-gate else if (w == wdstart + 1)
3347c478bd9Sstevel@tonic-gate val *= dilook(cbits(*(w-1)), cbits(*w), bxxh);
3357c478bd9Sstevel@tonic-gate else
3367c478bd9Sstevel@tonic-gate val *= dilook(cbits(*(w-1)), cbits(*w), xxh);
3377c478bd9Sstevel@tonic-gate val *= dilook(cbits(*w), cbits(*(w+1)), xhx);
3387c478bd9Sstevel@tonic-gate val *= dilook(cbits(*(w+1)), cbits(*(w+2)), hxx);
3397c478bd9Sstevel@tonic-gate if (val > maxval) {
3407c478bd9Sstevel@tonic-gate maxval = val;
3417c478bd9Sstevel@tonic-gate maxw = w + 1;
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate }
3447c478bd9Sstevel@tonic-gate hyend = nhyend;
3457c478bd9Sstevel@tonic-gate if (maxval > thresh)
3467c478bd9Sstevel@tonic-gate *hyp++ = maxw;
3477c478bd9Sstevel@tonic-gate goto again;
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate
351e5190c10Smuffin int
dilook(a,b,t)3527c478bd9Sstevel@tonic-gate dilook(a, b, t)
3537c478bd9Sstevel@tonic-gate int a, b;
3547c478bd9Sstevel@tonic-gate char t[26][13];
3557c478bd9Sstevel@tonic-gate {
356e5190c10Smuffin int i, j;
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate i = t[maplow(a)-'a'][(j = maplow(b)-'a')/2];
3597c478bd9Sstevel@tonic-gate if (!(j & 01))
3607c478bd9Sstevel@tonic-gate i >>= 4;
3617c478bd9Sstevel@tonic-gate return(i & 017);
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate
365