xref: /minix3/minix/commands/cawf/output.c (revision d9494baa34075b158415cc42d68bd0927d8124c1)
1433d6423SLionel Sambuc /*
2433d6423SLionel Sambuc  *	output-c - output support functions for cawf(1)
3433d6423SLionel Sambuc  */
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc /*
6433d6423SLionel Sambuc  *	Copyright (c) 1991 Purdue University Research Foundation,
7433d6423SLionel Sambuc  *	West Lafayette, Indiana 47907.  All rights reserved.
8433d6423SLionel Sambuc  *
9433d6423SLionel Sambuc  *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
10433d6423SLionel Sambuc  *	University Computing Center.  Not derived from licensed software;
11433d6423SLionel Sambuc  *	derived from awf(1) by Henry Spencer of the University of Toronto.
12433d6423SLionel Sambuc  *
13433d6423SLionel Sambuc  *	Permission is granted to anyone to use this software for any
14433d6423SLionel Sambuc  *	purpose on any computer system, and to alter it and redistribute
15433d6423SLionel Sambuc  *	it freely, subject to the following restrictions:
16433d6423SLionel Sambuc  *
17433d6423SLionel Sambuc  *	1. The author is not responsible for any consequences of use of
18433d6423SLionel Sambuc  *	   this software, even if they arise from flaws in it.
19433d6423SLionel Sambuc  *
20433d6423SLionel Sambuc  *	2. The origin of this software must not be misrepresented, either
21433d6423SLionel Sambuc  *	   by explicit claim or by omission.  Credits must appear in the
22433d6423SLionel Sambuc  *	   documentation.
23433d6423SLionel Sambuc  *
24433d6423SLionel Sambuc  *	3. Altered versions must be plainly marked as such, and must not
25433d6423SLionel Sambuc  *	   be misrepresented as being the original software.  Credits must
26433d6423SLionel Sambuc  *	   appear in the documentation.
27433d6423SLionel Sambuc  *
28433d6423SLionel Sambuc  *	4. This notice may not be removed or altered.
29433d6423SLionel Sambuc  */
30433d6423SLionel Sambuc 
31433d6423SLionel Sambuc #include "cawf.h"
32433d6423SLionel Sambuc 
33433d6423SLionel Sambuc 
34433d6423SLionel Sambuc /*
35433d6423SLionel Sambuc  * LenprtHF(s, p, t) - get length of print header or footer with page number
36433d6423SLionel Sambuc  *		       interpolation
37433d6423SLionel Sambuc  */
38433d6423SLionel Sambuc 
LenprtHF(unsigned char * s,int p,int t)39*d9494baaSJacob Adams int LenprtHF(unsigned char *s, int p, int t) {
40*d9494baaSJacob Adams /* header/footer string s
41*d9494baaSJacob Adams  * page number p
42*d9494baaSJacob Adams  * type t: 0 = get interpolated length
43*d9494baaSJacob Adams  *	 1 = print
44*d9494baaSJacob Adams  */
45433d6423SLionel Sambuc 	unsigned char buf[10];		/* buffer for page number */
46433d6423SLionel Sambuc 	int len;			/* line length */
47433d6423SLionel Sambuc 	unsigned char *s1;		/* temporary string pointer */
48433d6423SLionel Sambuc 
49433d6423SLionel Sambuc 	if (s == NULL)
50433d6423SLionel Sambuc 		return(0);
51433d6423SLionel Sambuc 	for (len = 0; *s && *s != '%'; s++) {
52433d6423SLionel Sambuc 		len++;
53433d6423SLionel Sambuc 		if (t)
54433d6423SLionel Sambuc 			Charput((int)*s);
55433d6423SLionel Sambuc 	}
56433d6423SLionel Sambuc 	if (*s) {
57433d6423SLionel Sambuc 		(void) sprintf((char *)buf, "%d", p);
58433d6423SLionel Sambuc 		for (s1 = buf; *s1; s1++) {
59433d6423SLionel Sambuc 			len++;
60433d6423SLionel Sambuc 			if (t)
61433d6423SLionel Sambuc 				Charput((int)*s1);
62433d6423SLionel Sambuc 		}
63433d6423SLionel Sambuc 		for (s++; *s; s++) {
64433d6423SLionel Sambuc 			len++;
65433d6423SLionel Sambuc 			if (t)
66433d6423SLionel Sambuc 				Charput((int)*s);
67433d6423SLionel Sambuc 		}
68433d6423SLionel Sambuc 	}
69433d6423SLionel Sambuc 	return(len);
70433d6423SLionel Sambuc }
71433d6423SLionel Sambuc 
72433d6423SLionel Sambuc 
73433d6423SLionel Sambuc /*
74433d6423SLionel Sambuc  * Charput(s) - put a character to output, subject to diversion
75433d6423SLionel Sambuc  */
76433d6423SLionel Sambuc 
Charput(int c)77*d9494baaSJacob Adams void Charput(int c) {
78*d9494baaSJacob Adams /* character to put c */
79433d6423SLionel Sambuc 	if (Divert == 0)
80433d6423SLionel Sambuc 		putchar((unsigned char)c);
81433d6423SLionel Sambuc }
82433d6423SLionel Sambuc 
83433d6423SLionel Sambuc 
84433d6423SLionel Sambuc /*
85433d6423SLionel Sambuc  * Stringput(s) - put a string to output, subject to diversion
86433d6423SLionel Sambuc  */
87433d6423SLionel Sambuc 
Stringput(unsigned char * s)88*d9494baaSJacob Adams void Stringput(unsigned char *s) {
89*d9494baaSJacob Adams /* string to put s */
90433d6423SLionel Sambuc 	if (Divert == 0)
91433d6423SLionel Sambuc 		fputs((char *)s, stdout);
92433d6423SLionel Sambuc }
93