8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / troff / n8.c
blobdf3bcc37a6c6999323ed9b87b40e786a3ccb718a
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 #include <ctype.h>
43 #include "tdef.h"
44 #include "ext.h"
45 #define HY_BIT 0200 /* stuff in here only works for ascii */
48 * troff8.c
50 * hyphenation
53 char hbuf[NHEX];
54 char *nexth = hbuf;
55 tchar *hyend;
56 #define THRESH 160 /*digram goodness threshold*/
57 int thresh = THRESH;
59 int
60 hyphen(wp)
61 tchar *wp;
63 int j;
64 tchar *i;
66 i = wp;
67 while (punct(cbits(*i++)))
69 if (!alph(cbits(*--i)))
70 return (0);
71 wdstart = i++;
72 while (alph(cbits(*i++)))
74 hyend = wdend = --i - 1;
75 while (punct(cbits(*i++)))
77 if (*--i)
78 return (0);
79 if ((wdend - wdstart - 4) < 0)
80 return (0);
81 hyp = hyptr;
82 *hyp = 0;
83 hyoff = 2;
84 if (!exword() && !suffix())
85 digram();
86 *hyp++ = 0;
87 if (*hyptr)
88 for (j = 1; j; ) {
89 j = 0;
90 for (hyp = hyptr + 1; *hyp != 0; hyp++) {
91 if (*(hyp - 1) > *hyp) {
92 j++;
93 i = *hyp;
94 *hyp = *(hyp - 1);
95 *(hyp - 1) = i;
100 return (0);
105 punct(i)
107 if (!i || alph(i))
108 return(0);
109 else
110 return(1);
115 alph(i)
117 if (i >= 'a' && i <= 'z' || i >= 'A' && i <= 'Z')
118 return(1);
119 else
120 return(0);
125 caseht()
127 thresh = THRESH;
128 if (skip())
129 return (0);
130 noscale++;
131 thresh = atoi();
132 noscale = 0;
134 return (0);
139 casehw()
141 int i, k;
142 char *j;
143 tchar t;
145 k = 0;
146 while (!skip()) {
147 if ((j = nexth) >= (hbuf + NHEX - 2))
148 goto full;
149 for (; ; ) {
150 if (ismot(t = getch()))
151 continue;
152 i = cbits(t);
153 if (i == ' ' || i == '\n') {
154 *j++ = 0;
155 nexth = j;
156 *j = 0;
157 if (i == ' ')
158 break;
159 else
160 return (0);
162 if (i == '-') {
163 k = HY_BIT;
164 continue;
166 *j++ = maplow(i) | k;
167 k = 0;
168 if (j >= (hbuf + NHEX - 2))
169 goto full;
172 return (0);
173 full:
174 errprint(gettext("exception word list full."));
175 *nexth = 0;
177 return (0);
182 exword()
184 tchar *w;
185 char *e;
186 char *save;
188 e = hbuf;
189 while (1) {
190 save = e;
191 if (*e == 0)
192 return(0);
193 w = wdstart;
194 while (*e && w <= hyend && (*e & 0177) == maplow(cbits(*w))) {
195 e++;
196 w++;
198 if (!*e) {
199 if (w-1 == hyend || (w == wdend && maplow(cbits(*w)) == 's')) {
200 w = wdstart;
201 for (e = save; *e; e++) {
202 if (*e & HY_BIT)
203 *hyp++ = w;
204 if (hyp > (hyptr + NHYP - 1))
205 hyp = hyptr + NHYP - 1;
206 w++;
208 return(1);
209 } else {
210 e++;
211 continue;
213 } else
214 while (*e++)
218 return (0);
223 suffix()
225 tchar *w;
226 char *s, *s0;
227 tchar i;
228 extern char *suftab[];
229 extern tchar *chkvow();
231 again:
232 if (!alph(cbits(i = cbits(*hyend))))
233 return(0);
234 if (i < 'a')
235 i -= 'A' - 'a';
236 if ((s0 = suftab[i-'a']) == 0)
237 return(0);
238 for (; ; ) {
239 if ((i = *s0 & 017) == 0)
240 return(0);
241 s = s0 + i - 1;
242 w = hyend - 1;
243 while (s > s0 && w >= wdstart && (*s & 0177) == maplow(cbits(*w))) {
244 s--;
245 w--;
247 if (s == s0)
248 break;
249 s0 += i;
251 s = s0 + i - 1;
252 w = hyend;
253 if (*s0 & HY_BIT)
254 goto mark;
255 while (s > s0) {
256 w--;
257 if (*s-- & HY_BIT) {
258 mark:
259 hyend = w - 1;
260 if (*s0 & 0100)
261 continue;
262 if (!chkvow(w))
263 return(0);
264 *hyp++ = w;
267 if (*s0 & 040)
268 return(0);
269 if (exword())
270 return(1);
271 goto again;
276 maplow(i)
277 int i;
279 if (ischar(i) && isupper(i))
280 i = tolower(i);
281 return(i);
286 vowel(i)
287 int i;
289 switch (maplow(i)) {
290 case 'a':
291 case 'e':
292 case 'i':
293 case 'o':
294 case 'u':
295 case 'y':
296 return(1);
297 default:
298 return(0);
303 tchar *chkvow(w)
304 tchar *w;
306 while (--w >= wdstart)
307 if (vowel(cbits(*w)))
308 return(w);
309 return(0);
314 digram()
316 tchar *w;
317 int val;
318 tchar * nhyend, *maxw;
319 int maxval;
320 extern char bxh[26][13], bxxh[26][13], xxh[26][13], xhx[26][13], hxx[26][13];
322 again:
323 if (!(w = chkvow(hyend + 1)))
324 return (0);
325 hyend = w;
326 if (!(w = chkvow(hyend)))
327 return (0);
328 nhyend = w;
329 maxval = 0;
330 w--;
331 while ((++w < hyend) && (w < (wdend - 1))) {
332 val = 1;
333 if (w == wdstart)
334 val *= dilook('a', cbits(*w), bxh);
335 else if (w == wdstart + 1)
336 val *= dilook(cbits(*(w-1)), cbits(*w), bxxh);
337 else
338 val *= dilook(cbits(*(w-1)), cbits(*w), xxh);
339 val *= dilook(cbits(*w), cbits(*(w+1)), xhx);
340 val *= dilook(cbits(*(w+1)), cbits(*(w+2)), hxx);
341 if (val > maxval) {
342 maxval = val;
343 maxw = w + 1;
346 hyend = nhyend;
347 if (maxval > thresh)
348 *hyp++ = maxw;
349 goto again;
354 dilook(a, b, t)
355 int a, b;
356 char t[26][13];
358 int i, j;
360 i = t[maplow(a)-'a'][(j = maplow(b)-'a')/2];
361 if (!(j & 01))
362 i >>= 4;
363 return(i & 017);