xref: /minix3/minix/commands/cawf/pass3.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /*
2*433d6423SLionel Sambuc  *	pass3.c - cawf(1) pass 3 function
3*433d6423SLionel Sambuc  */
4*433d6423SLionel Sambuc 
5*433d6423SLionel Sambuc /*
6*433d6423SLionel Sambuc  *	Copyright (c) 1991 Purdue University Research Foundation,
7*433d6423SLionel Sambuc  *	West Lafayette, Indiana 47907.  All rights reserved.
8*433d6423SLionel Sambuc  *
9*433d6423SLionel Sambuc  *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
10*433d6423SLionel Sambuc  *	University Computing Center.  Not derived from licensed software;
11*433d6423SLionel Sambuc  *	derived from awf(1) by Henry Spencer of the University of Toronto.
12*433d6423SLionel Sambuc  *
13*433d6423SLionel Sambuc  *	Permission is granted to anyone to use this software for any
14*433d6423SLionel Sambuc  *	purpose on any computer system, and to alter it and redistribute
15*433d6423SLionel Sambuc  *	it freely, subject to the following restrictions:
16*433d6423SLionel Sambuc  *
17*433d6423SLionel Sambuc  *	1. The author is not responsible for any consequences of use of
18*433d6423SLionel Sambuc  *	   this software, even if they arise from flaws in it.
19*433d6423SLionel Sambuc  *
20*433d6423SLionel Sambuc  *	2. The origin of this software must not be misrepresented, either
21*433d6423SLionel Sambuc  *	   by explicit claim or by omission.  Credits must appear in the
22*433d6423SLionel Sambuc  *	   documentation.
23*433d6423SLionel Sambuc  *
24*433d6423SLionel Sambuc  *	3. Altered versions must be plainly marked as such, and must not
25*433d6423SLionel Sambuc  *	   be misrepresented as being the original software.  Credits must
26*433d6423SLionel Sambuc  *	   appear in the documentation.
27*433d6423SLionel Sambuc  *
28*433d6423SLionel Sambuc  *	4. This notice may not be removed or altered.
29*433d6423SLionel Sambuc  */
30*433d6423SLionel Sambuc 
31*433d6423SLionel Sambuc #include "cawf.h"
32*433d6423SLionel Sambuc 
33*433d6423SLionel Sambuc void
Pass3(len,word,sarg,narg)34*433d6423SLionel Sambuc Pass3(len, word, sarg, narg)
35*433d6423SLionel Sambuc 	int len;			/* length (negative is special) */
36*433d6423SLionel Sambuc 	unsigned char *word;		/* word */
37*433d6423SLionel Sambuc 	unsigned char *sarg;		/* string argument */
38*433d6423SLionel Sambuc 	int narg;			/* numeric argument */
39*433d6423SLionel Sambuc {
40*433d6423SLionel Sambuc 	int addto;			/* spaces to add to all words */
41*433d6423SLionel Sambuc 	int i, j, k;			/* temporary index */
42*433d6423SLionel Sambuc 	unsigned char msg[MAXLINE];	/* message buffer */
43*433d6423SLionel Sambuc 	int n;				/* temporary number */
44*433d6423SLionel Sambuc 	unsigned char *s1;		/* temporary string pointer */
45*433d6423SLionel Sambuc 	int sp = 0;			/* no-break spacing switch */
46*433d6423SLionel Sambuc 	int sp_Outll;			/* sp-saved Outll */
47*433d6423SLionel Sambuc 	char sp_Outln;			/* sp-saved Outln[0] */
48*433d6423SLionel Sambuc 	int sp_Outlx;			/* sp-saved Outlx */
49*433d6423SLionel Sambuc 	int sp_Padx;			/* sp-saved Padx */
50*433d6423SLionel Sambuc 	int sp_Tind;			/* sp-saved Tind */
51*433d6423SLionel Sambuc 	int wl;				/* real word length */
52*433d6423SLionel Sambuc 	int xsp;			/* extra spaces to add */
53*433d6423SLionel Sambuc 	int vsp;			/* vertical spacing status */
54*433d6423SLionel Sambuc 
55*433d6423SLionel Sambuc 	vsp = 0;
56*433d6423SLionel Sambuc 	if (word != NULL)
57*433d6423SLionel Sambuc 		wl = strlen((char *)word);
58*433d6423SLionel Sambuc     /*
59*433d6423SLionel Sambuc      * If not a special command, process a word.
60*433d6423SLionel Sambuc      */
61*433d6423SLionel Sambuc 	if (len >= 0 && Outll < 0) {
62*433d6423SLionel Sambuc 	/*
63*433d6423SLionel Sambuc 	 * Enter first word.
64*433d6423SLionel Sambuc 	 */
65*433d6423SLionel Sambuc 		(void) strcpy((char *)Outln, (char *)word);
66*433d6423SLionel Sambuc 		Outll = len;
67*433d6423SLionel Sambuc 		Outlx = wl;
68*433d6423SLionel Sambuc 		Padx = 0;
69*433d6423SLionel Sambuc 	} else if (len >= 0
70*433d6423SLionel Sambuc 	       && (Outll+Contlen+len+narg) <= (LL-Pgoff-Ind-Tind)) {
71*433d6423SLionel Sambuc 	/*
72*433d6423SLionel Sambuc 	 * The word fits, so enter it.
73*433d6423SLionel Sambuc 	 */
74*433d6423SLionel Sambuc 		if ((Contlen + len) > 0) {
75*433d6423SLionel Sambuc line_too_big:
76*433d6423SLionel Sambuc 			if ((Outlx + Contlen + wl) >= MAXOLL) {
77*433d6423SLionel Sambuc 				Error3(len, (char *)word, (char *)sarg, narg,
78*433d6423SLionel Sambuc 					"output line too big");
79*433d6423SLionel Sambuc 				return;
80*433d6423SLionel Sambuc 			} else {
81*433d6423SLionel Sambuc 				if (Contlen > 0 && Cont != NULL) {
82*433d6423SLionel Sambuc 					if (Contlen == 1 && *Cont == ' ') {
83*433d6423SLionel Sambuc 						Padchar[Padx++] = Outlx;
84*433d6423SLionel Sambuc 						Outln[Outlx++] = ' ';
85*433d6423SLionel Sambuc 					} else {
86*433d6423SLionel Sambuc 					    (void) strcpy((char *)&Outln[Outlx],
87*433d6423SLionel Sambuc 						(char *)Cont);
88*433d6423SLionel Sambuc 					    Outlx += Contlen;
89*433d6423SLionel Sambuc 					}
90*433d6423SLionel Sambuc 				}
91*433d6423SLionel Sambuc 				if (len > 0) {
92*433d6423SLionel Sambuc 					(void) strcpy((char *)&Outln[Outlx],
93*433d6423SLionel Sambuc 						(char *)word);
94*433d6423SLionel Sambuc 					Outlx += wl;
95*433d6423SLionel Sambuc 				}
96*433d6423SLionel Sambuc 			}
97*433d6423SLionel Sambuc 		}
98*433d6423SLionel Sambuc 		Outll += Contlen + len;
99*433d6423SLionel Sambuc 	} else if (len == NOBREAK || len == MESSAGE) {
100*433d6423SLionel Sambuc 		/*
101*433d6423SLionel Sambuc 		 * Do nothing (equivalent to break)
102*433d6423SLionel Sambuc 		 */
103*433d6423SLionel Sambuc 	} else if (len == DOBREAK && strcmp((char *)word, "need") == 0
104*433d6423SLionel Sambuc 	       &&  (Nxtln + narg) < (Pglen + 1 - Botmarg)) {
105*433d6423SLionel Sambuc 		/*
106*433d6423SLionel Sambuc 		 * Do nothing, because there is room on the page.
107*433d6423SLionel Sambuc 		 */
108*433d6423SLionel Sambuc 	} else if (len == DOBREAK && strcmp((char *)word, "toindent") == 0
109*433d6423SLionel Sambuc 	       &&  (Ind + Tind + Outll) < Ind) {
110*433d6423SLionel Sambuc 	/*
111*433d6423SLionel Sambuc 	 * Move to indent position with line - there is room.
112*433d6423SLionel Sambuc 	 */
113*433d6423SLionel Sambuc 		n = Ind - (Ind + Tind +Outll);
114*433d6423SLionel Sambuc 		Outll += n;
115*433d6423SLionel Sambuc 		if ((Outlx + n) >= MAXOLL)
116*433d6423SLionel Sambuc 			goto line_too_big;
117*433d6423SLionel Sambuc 		for (i = n; i; i--)
118*433d6423SLionel Sambuc 			Outln[Outlx++] = ' ';
119*433d6423SLionel Sambuc 		Padx = 0;
120*433d6423SLionel Sambuc 		Free(&Cont);
121*433d6423SLionel Sambuc 		Contlen = 0;
122*433d6423SLionel Sambuc 	} else if (Outll >= 0
123*433d6423SLionel Sambuc 	       || (len == DOBREAK && strcmp((char *)word, "need") == 0)) {
124*433d6423SLionel Sambuc 	/*
125*433d6423SLionel Sambuc 	 * A non-empty line or a "need" forces output.
126*433d6423SLionel Sambuc 	 */
127*433d6423SLionel Sambuc 		vsp = 0;
128*433d6423SLionel Sambuc 
129*433d6423SLionel Sambuc print_line:
130*433d6423SLionel Sambuc 		if (Nxtln == 1) {
131*433d6423SLionel Sambuc 	    /*
132*433d6423SLionel Sambuc 	     * We're at the top of the page, so issue the header.
133*433d6423SLionel Sambuc 	     */
134*433d6423SLionel Sambuc 			if (Thispg > 1)
135*433d6423SLionel Sambuc 				Charput((int)'\f');
136*433d6423SLionel Sambuc 			for (i = (Topmarg - 1)/2; i > 0; i--) {
137*433d6423SLionel Sambuc 				Charput((int)'\n');
138*433d6423SLionel Sambuc 				Nxtln++;
139*433d6423SLionel Sambuc 			}
140*433d6423SLionel Sambuc 		    /*
141*433d6423SLionel Sambuc 		     * Print the page header, as required.
142*433d6423SLionel Sambuc 		     */
143*433d6423SLionel Sambuc 			if (Fph || Thispg > 1) {
144*433d6423SLionel Sambuc 				i = LenprtHF(Hdc, Thispg, 0)
145*433d6423SLionel Sambuc 				  + LenprtHF(Hdl, Thispg, 0)
146*433d6423SLionel Sambuc 				  + LenprtHF(Hdr, Thispg, 0) + 2;
147*433d6423SLionel Sambuc 				j = (LL - i - Pgoff) / 2 + 1;
148*433d6423SLionel Sambuc 				n = LL - Pgoff - i - j + 2;
149*433d6423SLionel Sambuc 				for (k = 0; k < Pgoff; k++)
150*433d6423SLionel Sambuc 					Charput((int)' ');
151*433d6423SLionel Sambuc 				if (Hdl)
152*433d6423SLionel Sambuc 					LenprtHF(Hdl, Thispg, 1);
153*433d6423SLionel Sambuc 				while (j-- > 0)
154*433d6423SLionel Sambuc 					Charput((int)' ');
155*433d6423SLionel Sambuc 				if (Hdc)
156*433d6423SLionel Sambuc 					LenprtHF(Hdc, Thispg, 1);
157*433d6423SLionel Sambuc 				while (n-- > 0)
158*433d6423SLionel Sambuc 					Charput((int)' ');
159*433d6423SLionel Sambuc 				if (Hdr)
160*433d6423SLionel Sambuc 					LenprtHF(Hdr, Thispg, 1);
161*433d6423SLionel Sambuc 				Charput((int)'\n');
162*433d6423SLionel Sambuc 			} else
163*433d6423SLionel Sambuc 				Charput((int)'\n');
164*433d6423SLionel Sambuc 			Nxtln++;
165*433d6423SLionel Sambuc 			while(Nxtln <= Topmarg) {
166*433d6423SLionel Sambuc 				Charput((int)'\n');
167*433d6423SLionel Sambuc 				Nxtln++;
168*433d6423SLionel Sambuc 			}
169*433d6423SLionel Sambuc 		}
170*433d6423SLionel Sambuc 	    /*
171*433d6423SLionel Sambuc 	     *  Add a trailing hyphen, if mecessary.
172*433d6423SLionel Sambuc 	     */
173*433d6423SLionel Sambuc      		if (vsp == 0 && Eollen > 0 && Eol != NULL) {
174*433d6423SLionel Sambuc 			i = strlen((char *)Eol);
175*433d6423SLionel Sambuc 			if ((Outlx + i) >= MAXOLL)
176*433d6423SLionel Sambuc 				goto line_too_big;
177*433d6423SLionel Sambuc 			(void) strcpy((char *)&Outln[Outlx], (char *)Eol);
178*433d6423SLionel Sambuc 			Outlx += i;
179*433d6423SLionel Sambuc 			Outll += Eollen;
180*433d6423SLionel Sambuc 		}
181*433d6423SLionel Sambuc 	    /*
182*433d6423SLionel Sambuc 	     * Trim trailing spaces from the output line.
183*433d6423SLionel Sambuc 	     */
184*433d6423SLionel Sambuc      		while (Outlx > 0) {
185*433d6423SLionel Sambuc 			if (Outln[Outlx - 1] != ' ')
186*433d6423SLionel Sambuc 				break;
187*433d6423SLionel Sambuc 			if (Padx > 0 && (Outlx - 1) == Padchar[Padx - 1])
188*433d6423SLionel Sambuc 				Padx--;
189*433d6423SLionel Sambuc 			Outlx--;
190*433d6423SLionel Sambuc 			Outln[Outlx] = '\0';
191*433d6423SLionel Sambuc 			Outll--;
192*433d6423SLionel Sambuc 		}
193*433d6423SLionel Sambuc 		if (Outlx == 0)
194*433d6423SLionel Sambuc 			Charput((int)'\n');
195*433d6423SLionel Sambuc 		else if (len == DOBREAK && strcmp((char *)word, "center") == 0)
196*433d6423SLionel Sambuc 		    {
197*433d6423SLionel Sambuc 		    /*
198*433d6423SLionel Sambuc 		     * Center the output line.
199*433d6423SLionel Sambuc 		     */
200*433d6423SLionel Sambuc 			i = (LL - Pgoff - Outll) / 2;
201*433d6423SLionel Sambuc 			if (i < 0)
202*433d6423SLionel Sambuc 				i = 0;
203*433d6423SLionel Sambuc 			for (j = (Pgoff + Ind + Tind + i); j; j--)
204*433d6423SLionel Sambuc 				Charput((int)' ');
205*433d6423SLionel Sambuc 			Stringput(Outln);
206*433d6423SLionel Sambuc 			Charput((int)'\n');
207*433d6423SLionel Sambuc 		} else if (Adj == LEFTADJ
208*433d6423SLionel Sambuc 		       || (Adj == BOTHADJ && (len < 0 || Padx == 0))) {
209*433d6423SLionel Sambuc 		    /*
210*433d6423SLionel Sambuc 		     * No right margin adjustment - disabled, inappropriate
211*433d6423SLionel Sambuc 		     * (line ended by break) or impossible.
212*433d6423SLionel Sambuc 		     */
213*433d6423SLionel Sambuc 			for (i = 0; i < (Pgoff + Ind + Tind); i++)
214*433d6423SLionel Sambuc 				Charput((int)' ');
215*433d6423SLionel Sambuc 			Stringput(Outln);
216*433d6423SLionel Sambuc 			Charput((int)'\n');
217*433d6423SLionel Sambuc 		} else if (Adj == BOTHADJ) {
218*433d6423SLionel Sambuc 		    /*
219*433d6423SLionel Sambuc 		     * Adjust right margin.
220*433d6423SLionel Sambuc 		     */
221*433d6423SLionel Sambuc 			for (i = 0; i < (Pgoff + Ind + Tind); i++)
222*433d6423SLionel Sambuc 				Charput((int)' ');
223*433d6423SLionel Sambuc 			i = LL - (Pgoff + Ind + Tind);
224*433d6423SLionel Sambuc 			j = i - Outll;
225*433d6423SLionel Sambuc 			addto = Padx ? (j / Padx) : 0;
226*433d6423SLionel Sambuc 			xsp = j - (Padx * addto);
227*433d6423SLionel Sambuc 			for (i = 0, s1 = Outln; i < Padx; i++) {
228*433d6423SLionel Sambuc 				while (*s1 && (s1 - Outln) <= Padchar[i])
229*433d6423SLionel Sambuc 					Charput((int)*s1++);
230*433d6423SLionel Sambuc 				if (*s1 == '\0')
231*433d6423SLionel Sambuc 					break;
232*433d6423SLionel Sambuc 				j = addto;
233*433d6423SLionel Sambuc 				if (Padfrom == PADLEFT) {
234*433d6423SLionel Sambuc 					if (i < xsp)
235*433d6423SLionel Sambuc 						j++;
236*433d6423SLionel Sambuc 				} else if (i >= (Padx - xsp))
237*433d6423SLionel Sambuc 					j++;
238*433d6423SLionel Sambuc 				while (j-- > 0)
239*433d6423SLionel Sambuc 					Charput((int)' ');
240*433d6423SLionel Sambuc 			}
241*433d6423SLionel Sambuc 			while (*s1)
242*433d6423SLionel Sambuc 				Charput((int)*s1++);
243*433d6423SLionel Sambuc 			Charput((int)'\n');
244*433d6423SLionel Sambuc 			Padfrom = (Padfrom == PADLEFT) ? PADRIGHT : PADLEFT;
245*433d6423SLionel Sambuc 		}
246*433d6423SLionel Sambuc 	    /*
247*433d6423SLionel Sambuc 	     * End of line housekeeping
248*433d6423SLionel Sambuc 	     */
249*433d6423SLionel Sambuc 		Nxtln++;
250*433d6423SLionel Sambuc 		Outll = -1;
251*433d6423SLionel Sambuc 		Outlx = 0;
252*433d6423SLionel Sambuc 		Padx = 0;
253*433d6423SLionel Sambuc 		Tind = 0;
254*433d6423SLionel Sambuc 		Nospmode = 0;
255*433d6423SLionel Sambuc 		if (vsp == 0 && len == DOBREAK
256*433d6423SLionel Sambuc 		&&  strcmp((char *)word, "need") == 0) {
257*433d6423SLionel Sambuc 		    /*
258*433d6423SLionel Sambuc 		     * Break caused by "need" - satisfy it.
259*433d6423SLionel Sambuc 		     */
260*433d6423SLionel Sambuc 			while (Nxtln < (Pglen + 1 - Botmarg)) {
261*433d6423SLionel Sambuc 				Charput((int)'\n');
262*433d6423SLionel Sambuc 				Nxtln++;
263*433d6423SLionel Sambuc 			}
264*433d6423SLionel Sambuc 		}
265*433d6423SLionel Sambuc 		if (Nxtln >= (Pglen + 1 - Botmarg)) {
266*433d6423SLionel Sambuc 	    /*
267*433d6423SLionel Sambuc 	     * Footer required
268*433d6423SLionel Sambuc 	     */
269*433d6423SLionel Sambuc 			for (i = (Botmarg - 1)/2; i > 0; i--) {
270*433d6423SLionel Sambuc 				Charput((int)'\n');
271*433d6423SLionel Sambuc 				Nxtln++;
272*433d6423SLionel Sambuc 			}
273*433d6423SLionel Sambuc 			i = LenprtHF(Ftl, Thispg, 0) + LenprtHF(Ftc, Thispg, 0)
274*433d6423SLionel Sambuc 			  + LenprtHF(Ftr, Thispg, 0) + 2;
275*433d6423SLionel Sambuc 			j = (LL - i - Pgoff) / 2 + 1;
276*433d6423SLionel Sambuc 			n = LL - Pgoff - i - j + 2;
277*433d6423SLionel Sambuc 			for (k = 0; k < Pgoff; k++)
278*433d6423SLionel Sambuc 				Charput((int)' ');
279*433d6423SLionel Sambuc 			if (Ftl)
280*433d6423SLionel Sambuc 				LenprtHF(Ftl, Thispg, 1);
281*433d6423SLionel Sambuc 			while (j-- > 0)
282*433d6423SLionel Sambuc 				Charput((int)' ');
283*433d6423SLionel Sambuc 			if (Ftc)
284*433d6423SLionel Sambuc 				LenprtHF(Ftc, Thispg, 1);
285*433d6423SLionel Sambuc 			while (n-- > 0)
286*433d6423SLionel Sambuc 				Charput((int)' ');
287*433d6423SLionel Sambuc 			if (Ftr)
288*433d6423SLionel Sambuc 				LenprtHF(Ftr, Thispg, 1);
289*433d6423SLionel Sambuc 			Charput((int)'\n');
290*433d6423SLionel Sambuc 			Nxtln++;
291*433d6423SLionel Sambuc 		/*
292*433d6423SLionel Sambuc 		 * The last blank line on the page is suppressed to assist
293*433d6423SLionel Sambuc 		 * printers that can't look ahead to the following FF.
294*433d6423SLionel Sambuc 		 */
295*433d6423SLionel Sambuc 			while (Nxtln < Pglen) {
296*433d6423SLionel Sambuc 				Charput((int)'\n');
297*433d6423SLionel Sambuc 				Nxtln++;
298*433d6423SLionel Sambuc 			}
299*433d6423SLionel Sambuc 			Nxtln = 1;
300*433d6423SLionel Sambuc 			Thispg++;
301*433d6423SLionel Sambuc 			Nospmode = 1;
302*433d6423SLionel Sambuc 			Padfrom = PADRIGHT;
303*433d6423SLionel Sambuc 		}
304*433d6423SLionel Sambuc 	    /*
305*433d6423SLionel Sambuc 	     * Initiate any extra vertical spacing.
306*433d6423SLionel Sambuc 	     */
307*433d6423SLionel Sambuc 		if (++vsp < Vspace)
308*433d6423SLionel Sambuc 			goto print_line;
309*433d6423SLionel Sambuc 	    /*
310*433d6423SLionel Sambuc 	     * Save any input word that might have forced output.
311*433d6423SLionel Sambuc 	     */
312*433d6423SLionel Sambuc 		if (len >= 0) {
313*433d6423SLionel Sambuc 			(void) strcpy((char *)Outln, (char *)word);
314*433d6423SLionel Sambuc 			Outll = len;
315*433d6423SLionel Sambuc 			Outlx = wl;
316*433d6423SLionel Sambuc 			Padx = 0;
317*433d6423SLionel Sambuc 		}
318*433d6423SLionel Sambuc 	}
319*433d6423SLionel Sambuc     /*
320*433d6423SLionel Sambuc      * A break causes padding reversal.
321*433d6423SLionel Sambuc      */
322*433d6423SLionel Sambuc 	if (len == DOBREAK)
323*433d6423SLionel Sambuc 		Padfrom = PADRIGHT;
324*433d6423SLionel Sambuc 	if (len >= 0 || strcmp((char *)word, "nohyphen") == 0) {
325*433d6423SLionel Sambuc     /*
326*433d6423SLionel Sambuc      * Reset continuation and hyphenation.
327*433d6423SLionel Sambuc      */
328*433d6423SLionel Sambuc 		if (Contlen != 1 || Cont[0] != ' ') {
329*433d6423SLionel Sambuc 			Free(&Cont);
330*433d6423SLionel Sambuc 			Cont = Newstr((unsigned char *)" ");
331*433d6423SLionel Sambuc 			Contlen = 1;
332*433d6423SLionel Sambuc 		}
333*433d6423SLionel Sambuc 		if (Eollen > 0) {
334*433d6423SLionel Sambuc 			Free(&Eol);
335*433d6423SLionel Sambuc 			Eollen = 0;
336*433d6423SLionel Sambuc 		}
337*433d6423SLionel Sambuc 		return;
338*433d6423SLionel Sambuc 	}
339*433d6423SLionel Sambuc     /*
340*433d6423SLionel Sambuc      * Now post-process any special commands.
341*433d6423SLionel Sambuc      */
342*433d6423SLionel Sambuc 	if (len == MESSAGE) {
343*433d6423SLionel Sambuc 		Error3(len, (char *)word, (char *)sarg, narg, NULL);
344*433d6423SLionel Sambuc 		return;
345*433d6423SLionel Sambuc 	}
346*433d6423SLionel Sambuc 
347*433d6423SLionel Sambuc 	switch (*word) {
348*433d6423SLionel Sambuc 
349*433d6423SLionel Sambuc 	case 'b':				/* both */
350*433d6423SLionel Sambuc 	    /*
351*433d6423SLionel Sambuc 	     * Adjust on both margins.
352*433d6423SLionel Sambuc 	     */
353*433d6423SLionel Sambuc 		Adj = BOTHADJ;
354*433d6423SLionel Sambuc 		return;
355*433d6423SLionel Sambuc 
356*433d6423SLionel Sambuc 	case 'c':				/* center */
357*433d6423SLionel Sambuc 		return;
358*433d6423SLionel Sambuc 
359*433d6423SLionel Sambuc 	case 'e':				/* errsto */
360*433d6423SLionel Sambuc 	    /*
361*433d6423SLionel Sambuc 	     * "errsto" comes from awf.
362*433d6423SLionel Sambuc 	     */
363*433d6423SLionel Sambuc 		return;
364*433d6423SLionel Sambuc 
365*433d6423SLionel Sambuc 	case 'f':				/* flush and fph */
366*433d6423SLionel Sambuc 		if (word[1] == 'l')
367*433d6423SLionel Sambuc 			return;
368*433d6423SLionel Sambuc 		else if (word[1] == 'p') {
369*433d6423SLionel Sambuc 	    /*
370*433d6423SLionel Sambuc 	     * First page header status
371*433d6423SLionel Sambuc 	     */
372*433d6423SLionel Sambuc 			Fph = narg;
373*433d6423SLionel Sambuc 			return;
374*433d6423SLionel Sambuc 		}
375*433d6423SLionel Sambuc 		break;
376*433d6423SLionel Sambuc 
377*433d6423SLionel Sambuc 	case 'g':				/* gap */
378*433d6423SLionel Sambuc 	    /*
379*433d6423SLionel Sambuc 	     * Increase word gap.  (Space is not paddable.)
380*433d6423SLionel Sambuc 	     */
381*433d6423SLionel Sambuc 		if (Outll >= 0) {
382*433d6423SLionel Sambuc 			if ((Outlx + narg - 1) >= MAXOLL)
383*433d6423SLionel Sambuc 				goto line_too_big;
384*433d6423SLionel Sambuc 			for (i = 0; i < (narg - 1); i++) {
385*433d6423SLionel Sambuc 				Outln[Outlx++] = ' ';
386*433d6423SLionel Sambuc 				Outll++;
387*433d6423SLionel Sambuc 			}
388*433d6423SLionel Sambuc 		}
389*433d6423SLionel Sambuc 		return;
390*433d6423SLionel Sambuc 
391*433d6423SLionel Sambuc 	case 'h':				/* hyphen */
392*433d6423SLionel Sambuc 	    /*
393*433d6423SLionel Sambuc 	     * Set discretionary hyphen.
394*433d6423SLionel Sambuc 	     */
395*433d6423SLionel Sambuc 		Free(&Cont);
396*433d6423SLionel Sambuc 		Contlen = 0;
397*433d6423SLionel Sambuc 		Free(&Eol);
398*433d6423SLionel Sambuc 		Eol = (sarg != NULL) ? Newstr(sarg) : NULL;
399*433d6423SLionel Sambuc 		Eollen = narg;
400*433d6423SLionel Sambuc 		return;
401*433d6423SLionel Sambuc 
402*433d6423SLionel Sambuc 	case 'i':				/* indent */
403*433d6423SLionel Sambuc 	    /*
404*433d6423SLionel Sambuc 	     * Set indentation.
405*433d6423SLionel Sambuc 	     */
406*433d6423SLionel Sambuc 		Ind = narg;
407*433d6423SLionel Sambuc 		return;
408*433d6423SLionel Sambuc 
409*433d6423SLionel Sambuc 	case 'l':				/* left or linelen */
410*433d6423SLionel Sambuc 		if (word[1] == 'e') {
411*433d6423SLionel Sambuc 	    /*
412*433d6423SLionel Sambuc 	     * Adjust on left margin.
413*433d6423SLionel Sambuc 	     */
414*433d6423SLionel Sambuc 			Adj = LEFTADJ;
415*433d6423SLionel Sambuc 			return;
416*433d6423SLionel Sambuc 		} else if (word[1] == 'i') {
417*433d6423SLionel Sambuc 	    /*
418*433d6423SLionel Sambuc 	     * Set line length.
419*433d6423SLionel Sambuc 	     */
420*433d6423SLionel Sambuc 			LL = narg;
421*433d6423SLionel Sambuc 			return;
422*433d6423SLionel Sambuc 		}
423*433d6423SLionel Sambuc 		break;
424*433d6423SLionel Sambuc 
425*433d6423SLionel Sambuc 	case 'n':				/* need or nospace */
426*433d6423SLionel Sambuc 		if (word[1] == 'e')
427*433d6423SLionel Sambuc 			return;			/* need */
428*433d6423SLionel Sambuc 		else if (word[1] == 'o') {
429*433d6423SLionel Sambuc 	    /*
430*433d6423SLionel Sambuc 	     * Set no space mode.
431*433d6423SLionel Sambuc 	     */
432*433d6423SLionel Sambuc 			Nospmode = 1;
433*433d6423SLionel Sambuc 			return;
434*433d6423SLionel Sambuc 		}
435*433d6423SLionel Sambuc 		break;
436*433d6423SLionel Sambuc 
437*433d6423SLionel Sambuc 	case 'p':				/* pagelen or pageoffset */
438*433d6423SLionel Sambuc 		if (strncmp((char *)&word[1], "age", 3) != 0)
439*433d6423SLionel Sambuc 			break;
440*433d6423SLionel Sambuc 		if (word[4] == 'l') {
441*433d6423SLionel Sambuc 	    /*
442*433d6423SLionel Sambuc 	     * Set page length.
443*433d6423SLionel Sambuc 	     */
444*433d6423SLionel Sambuc 			Pglen = narg;
445*433d6423SLionel Sambuc 			return;
446*433d6423SLionel Sambuc 		} else if (word[4] == 'o') {
447*433d6423SLionel Sambuc 	    /*
448*433d6423SLionel Sambuc 	     * Set page offset.
449*433d6423SLionel Sambuc 	     */
450*433d6423SLionel Sambuc 			Pgoff = narg;
451*433d6423SLionel Sambuc 			return;
452*433d6423SLionel Sambuc 		}
453*433d6423SLionel Sambuc 		break;
454*433d6423SLionel Sambuc 
455*433d6423SLionel Sambuc 	case 's':				/* space */
456*433d6423SLionel Sambuc 		if (sp) {
457*433d6423SLionel Sambuc 
458*433d6423SLionel Sambuc 		/*
459*433d6423SLionel Sambuc 		 * Restore values after NOBREAK spacing ("^'sp").
460*433d6423SLionel Sambuc 		 */
461*433d6423SLionel Sambuc 			Outlx = sp_Outlx;
462*433d6423SLionel Sambuc 			Outln[0] = sp_Outln;
463*433d6423SLionel Sambuc 			Padx = sp_Padx;
464*433d6423SLionel Sambuc 			Outll = sp_Outll;
465*433d6423SLionel Sambuc 			Tind = sp_Tind;
466*433d6423SLionel Sambuc 			return;
467*433d6423SLionel Sambuc 		}
468*433d6423SLionel Sambuc 		if (Nospmode == 0) {
469*433d6423SLionel Sambuc 			if (len == NOBREAK) {
470*433d6423SLionel Sambuc 
471*433d6423SLionel Sambuc 			/*
472*433d6423SLionel Sambuc 			 * Set up for NOBREAK spacing.
473*433d6423SLionel Sambuc 			 */
474*433d6423SLionel Sambuc 				sp_Outlx = Outlx;
475*433d6423SLionel Sambuc 				sp_Outln = Outln[0];
476*433d6423SLionel Sambuc 				sp_Padx = Padx;
477*433d6423SLionel Sambuc 				sp_Outll = Outll;
478*433d6423SLionel Sambuc 				sp_Tind = Tind;
479*433d6423SLionel Sambuc 				vsp = Vspace + 1;
480*433d6423SLionel Sambuc 				sp = 1;
481*433d6423SLionel Sambuc 			}
482*433d6423SLionel Sambuc 		/*
483*433d6423SLionel Sambuc 		 * Generate a blank line.
484*433d6423SLionel Sambuc 		 */
485*433d6423SLionel Sambuc 			Outlx = 0;
486*433d6423SLionel Sambuc 			Outln[0] = '\0';
487*433d6423SLionel Sambuc 			Padx = 0;
488*433d6423SLionel Sambuc 			Outll = LL - 1;
489*433d6423SLionel Sambuc 			if (sp)
490*433d6423SLionel Sambuc 				goto print_line;
491*433d6423SLionel Sambuc 		}
492*433d6423SLionel Sambuc 		return;
493*433d6423SLionel Sambuc 
494*433d6423SLionel Sambuc 	case 't':				/* tabto, tempindent, or
495*433d6423SLionel Sambuc 						 * toindent */
496*433d6423SLionel Sambuc 		if (word[1] == 'a') {
497*433d6423SLionel Sambuc 	    /*
498*433d6423SLionel Sambuc 	     * Move to TAB stop.
499*433d6423SLionel Sambuc 	     */
500*433d6423SLionel Sambuc 			if (Outll < 0)
501*433d6423SLionel Sambuc 				Outll = 0;
502*433d6423SLionel Sambuc 			if ((n = narg - Outll) > 0) {
503*433d6423SLionel Sambuc 				if ((Outlx + n) >= MAXOLL)
504*433d6423SLionel Sambuc 					goto line_too_big;
505*433d6423SLionel Sambuc 				Outll += n;
506*433d6423SLionel Sambuc 				for (i = n; i > 0; i--)
507*433d6423SLionel Sambuc 					Outln[Outlx++] = ' ';
508*433d6423SLionel Sambuc 				Free(&Cont);
509*433d6423SLionel Sambuc 				Contlen = 0;
510*433d6423SLionel Sambuc 				Padx = 0;
511*433d6423SLionel Sambuc 			}
512*433d6423SLionel Sambuc 			return;
513*433d6423SLionel Sambuc 		} else if (word[1] == 'e') {
514*433d6423SLionel Sambuc 	    /*
515*433d6423SLionel Sambuc 	     * Set temporary indentation.
516*433d6423SLionel Sambuc 	     */
517*433d6423SLionel Sambuc 			if (*sarg == '\0' && narg >= 0)
518*433d6423SLionel Sambuc 				Tind = narg - Ind;
519*433d6423SLionel Sambuc 			else
520*433d6423SLionel Sambuc 				Tind = ((Ind + narg) >= 0) ? narg : -Ind;
521*433d6423SLionel Sambuc 			return;
522*433d6423SLionel Sambuc 		} else if (word[1] == 'o')
523*433d6423SLionel Sambuc 			return;				/* toindent */
524*433d6423SLionel Sambuc 		break;
525*433d6423SLionel Sambuc 
526*433d6423SLionel Sambuc 	case 'u':					/* userhyphen */
527*433d6423SLionel Sambuc 	    /*
528*433d6423SLionel Sambuc 	     * Set line length.
529*433d6423SLionel Sambuc 	     */
530*433d6423SLionel Sambuc 		Free(&Cont);
531*433d6423SLionel Sambuc 		Free(&Eol);
532*433d6423SLionel Sambuc 		Contlen = Eollen = narg;
533*433d6423SLionel Sambuc 		Cont = (sarg == NULL) ? NULL : Newstr(sarg);
534*433d6423SLionel Sambuc 		Eol = (sarg == NULL) ? NULL : Newstr(sarg);
535*433d6423SLionel Sambuc 		return;
536*433d6423SLionel Sambuc 
537*433d6423SLionel Sambuc 	case 'v':					/* vspace */
538*433d6423SLionel Sambuc 	    /*
539*433d6423SLionel Sambuc 	     * Set vertical spacing.
540*433d6423SLionel Sambuc 	     */
541*433d6423SLionel Sambuc 		Vspace = (narg == 0) ? 1 : narg;
542*433d6423SLionel Sambuc 		return;
543*433d6423SLionel Sambuc 
544*433d6423SLionel Sambuc 	case 'y':					/* yesspace */
545*433d6423SLionel Sambuc 	    /*
546*433d6423SLionel Sambuc 	     * Set space mode.
547*433d6423SLionel Sambuc 	     */
548*433d6423SLionel Sambuc 		Nospmode = 0;
549*433d6423SLionel Sambuc 		return;
550*433d6423SLionel Sambuc 	}				/* end of switch(*word) */
551*433d6423SLionel Sambuc     /*
552*433d6423SLionel Sambuc      * Locate header and footer defintions.
553*433d6423SLionel Sambuc      */
554*433d6423SLionel Sambuc 	if (regexec(Pat[14].pat, word)) {
555*433d6423SLionel Sambuc 		if (strcmp((char *)word, "LH") == 0) {
556*433d6423SLionel Sambuc 		    /*
557*433d6423SLionel Sambuc 		     * Left header
558*433d6423SLionel Sambuc 		     */
559*433d6423SLionel Sambuc 			Free(&Hdl);
560*433d6423SLionel Sambuc 			if (sarg != NULL)
561*433d6423SLionel Sambuc 				Hdl = Newstr(sarg);
562*433d6423SLionel Sambuc 			return;
563*433d6423SLionel Sambuc 		}
564*433d6423SLionel Sambuc 		if (strcmp((char *)word, "CH") == 0) {
565*433d6423SLionel Sambuc 		    /*
566*433d6423SLionel Sambuc 		     * Center header
567*433d6423SLionel Sambuc 		     */
568*433d6423SLionel Sambuc 			Free(&Hdc);
569*433d6423SLionel Sambuc 			if (sarg != NULL)
570*433d6423SLionel Sambuc 				Hdc = Newstr(sarg);
571*433d6423SLionel Sambuc 			return;
572*433d6423SLionel Sambuc 		}
573*433d6423SLionel Sambuc 		if (strcmp((char *)word, "RH") == 0) {
574*433d6423SLionel Sambuc 		    /*
575*433d6423SLionel Sambuc 		     * Right header
576*433d6423SLionel Sambuc 		     */
577*433d6423SLionel Sambuc 			Free(&Hdr);
578*433d6423SLionel Sambuc 			if (sarg != NULL)
579*433d6423SLionel Sambuc 				Hdr = Newstr(sarg);
580*433d6423SLionel Sambuc 			return;
581*433d6423SLionel Sambuc 		}
582*433d6423SLionel Sambuc 		if (strcmp((char *)word, "LF") == 0) {
583*433d6423SLionel Sambuc 		    /*
584*433d6423SLionel Sambuc 		     * Left footer
585*433d6423SLionel Sambuc 		     */
586*433d6423SLionel Sambuc 			Free(&Ftl);
587*433d6423SLionel Sambuc 			if (sarg != NULL)
588*433d6423SLionel Sambuc 				Ftl = Newstr(sarg);
589*433d6423SLionel Sambuc 			return;
590*433d6423SLionel Sambuc 		}
591*433d6423SLionel Sambuc 		if (strcmp((char *)word, "CF") == 0) {
592*433d6423SLionel Sambuc 		    /*
593*433d6423SLionel Sambuc 		     * Center footer
594*433d6423SLionel Sambuc 		     */
595*433d6423SLionel Sambuc 			Free(&Ftc);
596*433d6423SLionel Sambuc 			if (sarg != NULL)
597*433d6423SLionel Sambuc 				Ftc = Newstr(sarg);
598*433d6423SLionel Sambuc 			return;
599*433d6423SLionel Sambuc 		}
600*433d6423SLionel Sambuc 		if (strcmp((char *)word, "RF") == 0) {
601*433d6423SLionel Sambuc 		    /*
602*433d6423SLionel Sambuc 		     * Right footer
603*433d6423SLionel Sambuc 		     */
604*433d6423SLionel Sambuc 			Free(&Ftr);
605*433d6423SLionel Sambuc 			if (sarg != NULL)
606*433d6423SLionel Sambuc 				Ftr = Newstr(sarg);
607*433d6423SLionel Sambuc 			return;
608*433d6423SLionel Sambuc 		}
609*433d6423SLionel Sambuc 	}
610*433d6423SLionel Sambuc     /*
611*433d6423SLionel Sambuc      * Error on unknown arguments
612*433d6423SLionel Sambuc      */
613*433d6423SLionel Sambuc 	Error3(len, (char *)word, (char *)sarg, narg, "unknown request");
614*433d6423SLionel Sambuc }
615