xref: /titanic_50/usr/src/lib/libcurses/screen/print.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
43*7c478bd9Sstevel@tonic-gate #include <string.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
45*7c478bd9Sstevel@tonic-gate #include "curses_inc.h"
46*7c478bd9Sstevel@tonic-gate #include "print.h"
47*7c478bd9Sstevel@tonic-gate #include <signal.h>   /* use this file to determine if this is SVR4.0 system */
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #ifdef SIGSTOP	/* SVR4.0 and beyond */
50*7c478bd9Sstevel@tonic-gate #define	_ULIBTI	"/usr/share/lib/terminfo"
51*7c478bd9Sstevel@tonic-gate #else
52*7c478bd9Sstevel@tonic-gate #define	_ULIBTI	"/usr/lib/terminfo"
53*7c478bd9Sstevel@tonic-gate #endif
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate char *progname;
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate /* global variables */
58*7c478bd9Sstevel@tonic-gate static enum printtypes printing = pr_none;
59*7c478bd9Sstevel@tonic-gate static int onecolumn = 0;		/* print a single column */
60*7c478bd9Sstevel@tonic-gate static int width = 60;			/* width of multi-column printing */
61*7c478bd9Sstevel@tonic-gate static int restrictterm = 1;		/* restrict termcap names */
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate /* local variables */
64*7c478bd9Sstevel@tonic-gate static int printed = 0;
65*7c478bd9Sstevel@tonic-gate static size_t caplen = 0;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate void
68*7c478bd9Sstevel@tonic-gate pr_init(enum printtypes type)
69*7c478bd9Sstevel@tonic-gate {
70*7c478bd9Sstevel@tonic-gate 	printing = type;
71*7c478bd9Sstevel@tonic-gate }
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate void
74*7c478bd9Sstevel@tonic-gate pr_onecolumn(int onoff)
75*7c478bd9Sstevel@tonic-gate {
76*7c478bd9Sstevel@tonic-gate 	onecolumn = onoff;
77*7c478bd9Sstevel@tonic-gate }
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate void
80*7c478bd9Sstevel@tonic-gate pr_width(int nwidth)
81*7c478bd9Sstevel@tonic-gate {
82*7c478bd9Sstevel@tonic-gate 	if (nwidth > 0)
83*7c478bd9Sstevel@tonic-gate 		width = nwidth;
84*7c478bd9Sstevel@tonic-gate }
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate void
87*7c478bd9Sstevel@tonic-gate pr_caprestrict(int onoff)
88*7c478bd9Sstevel@tonic-gate {
89*7c478bd9Sstevel@tonic-gate 	restrictterm = onoff;
90*7c478bd9Sstevel@tonic-gate }
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate static char capbools[] =
93*7c478bd9Sstevel@tonic-gate 	"ambsbwdadbeoeshchshzinkmmimsncnsosptulxbxnxoxsxt";
94*7c478bd9Sstevel@tonic-gate static int ncapbools = sizeof (capbools) / sizeof (capbools[0]);
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate static char capnums[] =
97*7c478bd9Sstevel@tonic-gate 	"codBdCdFdNdTknlipbsgug";
98*7c478bd9Sstevel@tonic-gate static int ncapnums = sizeof (capnums) / sizeof (capnums[0]);
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate static char capstrs[] =
101*7c478bd9Sstevel@tonic-gate 	"ALDCDLDOICLERISFSRUPaealasbcbtcdcechclcmcsctcvdcdldmdsedeifshoi1i2i"
102*7c478bd9Sstevel@tonic-gate 	    "cifimipisk0k1k2k3k4k5k6k7k8k9kbkdkekhklkokrkskul0l1l2l3l4l5l6l7l"
103*7c478bd9Sstevel@tonic-gate 	    "8l9ndnlpcr1r2r3rcrfrpscsesosrsttetitsucueupusvbvevivs";
104*7c478bd9Sstevel@tonic-gate static int ncapstrs = sizeof (capstrs) / sizeof (capstrs[0]);
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate static int
107*7c478bd9Sstevel@tonic-gate findcapname(char *capname, char *caplist, int listsize)
108*7c478bd9Sstevel@tonic-gate {
109*7c478bd9Sstevel@tonic-gate 	int low = 0, mid, high = listsize - 2;
110*7c478bd9Sstevel@tonic-gate 	while (low <= high) {
111*7c478bd9Sstevel@tonic-gate 		mid = (low + high) / 4 * 2;
112*7c478bd9Sstevel@tonic-gate 		if (capname[0] == caplist[mid]) {
113*7c478bd9Sstevel@tonic-gate 			if (capname[1] == caplist[mid + 1])
114*7c478bd9Sstevel@tonic-gate 				return (1);
115*7c478bd9Sstevel@tonic-gate 			else if (capname[1] < caplist[mid + 1])
116*7c478bd9Sstevel@tonic-gate 				high = mid - 2;
117*7c478bd9Sstevel@tonic-gate 			else
118*7c478bd9Sstevel@tonic-gate 				low = mid + 2;
119*7c478bd9Sstevel@tonic-gate 		} else if (capname[0] < caplist[mid])
120*7c478bd9Sstevel@tonic-gate 			high = mid - 2;
121*7c478bd9Sstevel@tonic-gate 		else
122*7c478bd9Sstevel@tonic-gate 			low = mid + 2;
123*7c478bd9Sstevel@tonic-gate 	}
124*7c478bd9Sstevel@tonic-gate 	return (0);
125*7c478bd9Sstevel@tonic-gate /*
126*7c478bd9Sstevel@tonic-gate  *	for (; *caplist; caplist += 2)
127*7c478bd9Sstevel@tonic-gate  *		if (caplist[0] == capname[0] && caplist[1] == capname[1])
128*7c478bd9Sstevel@tonic-gate  *			return (1);
129*7c478bd9Sstevel@tonic-gate  *	return (0);
130*7c478bd9Sstevel@tonic-gate  */
131*7c478bd9Sstevel@tonic-gate }
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate /*
134*7c478bd9Sstevel@tonic-gate  *  Print out the first line of an entry.
135*7c478bd9Sstevel@tonic-gate  */
136*7c478bd9Sstevel@tonic-gate void
137*7c478bd9Sstevel@tonic-gate pr_heading(char *term, char *synonyms)
138*7c478bd9Sstevel@tonic-gate {
139*7c478bd9Sstevel@tonic-gate 	int	do_print = 0;	/* Can we print the path of the file ? */
140*7c478bd9Sstevel@tonic-gate 	char	buffer[512];	/* Holds search pathname */
141*7c478bd9Sstevel@tonic-gate 	FILE	*work_fp;	/* Used to try and open the files */
142*7c478bd9Sstevel@tonic-gate 	char	tail[4];	/* Used for terminfo pathname suffix */
143*7c478bd9Sstevel@tonic-gate 	char	*terminfo;	/* The value of $TERMINFO */
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	/*
147*7c478bd9Sstevel@tonic-gate 	 *	Try to obtain $TERMINFO
148*7c478bd9Sstevel@tonic-gate 	 */
149*7c478bd9Sstevel@tonic-gate 	terminfo = getenv("TERMINFO");
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 	if (term == (char *)0)
152*7c478bd9Sstevel@tonic-gate 		term = "";
153*7c478bd9Sstevel@tonic-gate 	/*
154*7c478bd9Sstevel@tonic-gate 	 *	Build the suffix for this device
155*7c478bd9Sstevel@tonic-gate 	 */
156*7c478bd9Sstevel@tonic-gate 	tail[0] = '/';
157*7c478bd9Sstevel@tonic-gate 	tail[1] = *term;
158*7c478bd9Sstevel@tonic-gate 	tail[2] = '/';
159*7c478bd9Sstevel@tonic-gate 	tail[3] = '\0';
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	/*
162*7c478bd9Sstevel@tonic-gate 	 *	If we have it - use it, otherwise use /usr/share/lib/terminfo
163*7c478bd9Sstevel@tonic-gate 	 *	as base directory
164*7c478bd9Sstevel@tonic-gate 	 */
165*7c478bd9Sstevel@tonic-gate 	if (terminfo != NULL)
166*7c478bd9Sstevel@tonic-gate 		(void) sprintf(buffer, "%s%s%s", terminfo, tail, term);
167*7c478bd9Sstevel@tonic-gate 	else
168*7c478bd9Sstevel@tonic-gate 		(void) sprintf(buffer, "%s%s%s", _ULIBTI, tail, term);
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 	/*
171*7c478bd9Sstevel@tonic-gate 	 *	Attempt to open the file.
172*7c478bd9Sstevel@tonic-gate 	 */
173*7c478bd9Sstevel@tonic-gate 	if ((work_fp = fopen(buffer, "r")) == NULL) {
174*7c478bd9Sstevel@tonic-gate 		/*
175*7c478bd9Sstevel@tonic-gate 		 * Open failed. If we were looking in /usr/share/lib/terminfo
176*7c478bd9Sstevel@tonic-gate 		 *	we are done, otherwise look there next.
177*7c478bd9Sstevel@tonic-gate 		 */
178*7c478bd9Sstevel@tonic-gate 		if (strncmp(buffer, _ULIBTI, strlen(_ULIBTI)) == 0) {
179*7c478bd9Sstevel@tonic-gate 				/*
180*7c478bd9Sstevel@tonic-gate 				 * We are done. Not in /usr/share/lib/terminfo,
181*7c478bd9Sstevel@tonic-gate 				 *	and $TERMINFO is not set.
182*7c478bd9Sstevel@tonic-gate 				 */
183*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "Error: Term \"%s\" not "
184*7c478bd9Sstevel@tonic-gate 				    "found in %s\n", term, _ULIBTI);
185*7c478bd9Sstevel@tonic-gate 		} else {
186*7c478bd9Sstevel@tonic-gate 			/*
187*7c478bd9Sstevel@tonic-gate 			 * Check /usr/share/lib/terminfo last. If this fails,
188*7c478bd9Sstevel@tonic-gate 			 * all hope is lost as we know it is not in $TERMINFO.
189*7c478bd9Sstevel@tonic-gate 			 */
190*7c478bd9Sstevel@tonic-gate 			(void) sprintf(buffer, "%s%s%s", _ULIBTI, tail, term);
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate 			if ((work_fp = fopen(buffer, "r")) == NULL) {
193*7c478bd9Sstevel@tonic-gate 				/*
194*7c478bd9Sstevel@tonic-gate 				 *	All hope is lost
195*7c478bd9Sstevel@tonic-gate 				 */
196*7c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "Error: Term \"%s\" not "
197*7c478bd9Sstevel@tonic-gate 				    "found in %s or %s\n", term, _ULIBTI,
198*7c478bd9Sstevel@tonic-gate 				    getenv("TERMINFO"));
199*7c478bd9Sstevel@tonic-gate 			} else do_print = 1;
200*7c478bd9Sstevel@tonic-gate 		}
201*7c478bd9Sstevel@tonic-gate 	} else do_print = 1;
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate 	/*
204*7c478bd9Sstevel@tonic-gate 	 *	If we found it - print the comment(after closing the file)
205*7c478bd9Sstevel@tonic-gate 	 */
206*7c478bd9Sstevel@tonic-gate 	if (do_print && *term) {
207*7c478bd9Sstevel@tonic-gate 		(void) fclose(work_fp);
208*7c478bd9Sstevel@tonic-gate 		(void) printf("#	Reconstructed via infocmp from file: "
209*7c478bd9Sstevel@tonic-gate 		    "%s\n", buffer);
210*7c478bd9Sstevel@tonic-gate 	}
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	switch ((int)printing) {
213*7c478bd9Sstevel@tonic-gate 		case (int)pr_terminfo:
214*7c478bd9Sstevel@tonic-gate 			(void) printf("%s,\n", synonyms);
215*7c478bd9Sstevel@tonic-gate 			break;
216*7c478bd9Sstevel@tonic-gate 		case (int)pr_cap:
217*7c478bd9Sstevel@tonic-gate 			(void) printf("%s:\\\n", synonyms);
218*7c478bd9Sstevel@tonic-gate 			caplen = strlen(synonyms) + 1;
219*7c478bd9Sstevel@tonic-gate 			break;
220*7c478bd9Sstevel@tonic-gate 		case (int)pr_longnames:
221*7c478bd9Sstevel@tonic-gate 			(void) printf("Terminal type %s\n", term);
222*7c478bd9Sstevel@tonic-gate 			(void) printf("  %s\n", synonyms);
223*7c478bd9Sstevel@tonic-gate 			break;
224*7c478bd9Sstevel@tonic-gate 	}
225*7c478bd9Sstevel@tonic-gate }
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate void
228*7c478bd9Sstevel@tonic-gate pr_bheading(void)
229*7c478bd9Sstevel@tonic-gate {
230*7c478bd9Sstevel@tonic-gate 	if (printing == pr_longnames)
231*7c478bd9Sstevel@tonic-gate 		(void) printf("flags\n");
232*7c478bd9Sstevel@tonic-gate 	printed = 0;
233*7c478bd9Sstevel@tonic-gate }
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate void
236*7c478bd9Sstevel@tonic-gate pr_boolean(char *infoname, char *capname, char *fullname, int value)
237*7c478bd9Sstevel@tonic-gate {
238*7c478bd9Sstevel@tonic-gate 	int	vlen;
239*7c478bd9Sstevel@tonic-gate 	size_t	nlen;
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate 	if (printing == pr_cap && restrictterm &&
242*7c478bd9Sstevel@tonic-gate 	    !findcapname(capname, capbools, ncapbools))
243*7c478bd9Sstevel@tonic-gate 		return;
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 	if (onecolumn) {
246*7c478bd9Sstevel@tonic-gate 		if (value < 0)
247*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
248*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
249*7c478bd9Sstevel@tonic-gate 					(void) printf("\t%s@,\n", infoname);
250*7c478bd9Sstevel@tonic-gate 					break;
251*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
252*7c478bd9Sstevel@tonic-gate 					(void) printf("\t:%s@:\\\n", capname);
253*7c478bd9Sstevel@tonic-gate 					caplen += 4 + strlen(capname);
254*7c478bd9Sstevel@tonic-gate 					break;
255*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
256*7c478bd9Sstevel@tonic-gate 					(void) printf("  %s@\n", fullname);
257*7c478bd9Sstevel@tonic-gate 			}
258*7c478bd9Sstevel@tonic-gate 		else
259*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
260*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
261*7c478bd9Sstevel@tonic-gate 					(void) printf("\t%s,\n", infoname);
262*7c478bd9Sstevel@tonic-gate 					break;
263*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
264*7c478bd9Sstevel@tonic-gate 					(void) printf("\t:%s:\\\n", capname);
265*7c478bd9Sstevel@tonic-gate 					caplen += 3 + strlen(capname);
266*7c478bd9Sstevel@tonic-gate 					break;
267*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
268*7c478bd9Sstevel@tonic-gate 					(void) printf("  %s\n", fullname);
269*7c478bd9Sstevel@tonic-gate 			}
270*7c478bd9Sstevel@tonic-gate 	} else {
271*7c478bd9Sstevel@tonic-gate 		switch ((int)printing) {
272*7c478bd9Sstevel@tonic-gate 			case (int)pr_terminfo:	nlen = strlen(infoname);
273*7c478bd9Sstevel@tonic-gate 						break;
274*7c478bd9Sstevel@tonic-gate 			case (int)pr_cap:	nlen = strlen(capname);
275*7c478bd9Sstevel@tonic-gate 						break;
276*7c478bd9Sstevel@tonic-gate 			case (int)pr_longnames:
277*7c478bd9Sstevel@tonic-gate 						nlen = strlen(fullname);
278*7c478bd9Sstevel@tonic-gate 						break;
279*7c478bd9Sstevel@tonic-gate 		}
280*7c478bd9Sstevel@tonic-gate 		vlen = (value < 0) ? 1 : 0;
281*7c478bd9Sstevel@tonic-gate 		if ((printed > 0) && (printed + nlen + vlen + 1 > width)) {
282*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
283*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
284*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
285*7c478bd9Sstevel@tonic-gate 						(void) printf("\n");
286*7c478bd9Sstevel@tonic-gate 						break;
287*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
288*7c478bd9Sstevel@tonic-gate 						(void) printf(":\\\n");
289*7c478bd9Sstevel@tonic-gate 						caplen += 1;
290*7c478bd9Sstevel@tonic-gate 			}
291*7c478bd9Sstevel@tonic-gate 			printed = 0;
292*7c478bd9Sstevel@tonic-gate 		}
293*7c478bd9Sstevel@tonic-gate 		if (printed == 0) {
294*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
295*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
296*7c478bd9Sstevel@tonic-gate 					(void) printf("\t");
297*7c478bd9Sstevel@tonic-gate 					printed = 8;
298*7c478bd9Sstevel@tonic-gate 					break;
299*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
300*7c478bd9Sstevel@tonic-gate 					(void) printf("\t:");
301*7c478bd9Sstevel@tonic-gate 					printed = 9;
302*7c478bd9Sstevel@tonic-gate 					caplen += 2;
303*7c478bd9Sstevel@tonic-gate 					break;
304*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
305*7c478bd9Sstevel@tonic-gate 					(void) printf("  ");
306*7c478bd9Sstevel@tonic-gate 					printed = 2;
307*7c478bd9Sstevel@tonic-gate 			}
308*7c478bd9Sstevel@tonic-gate 		} else {
309*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
310*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
311*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
312*7c478bd9Sstevel@tonic-gate 					(void) printf(" ");
313*7c478bd9Sstevel@tonic-gate 					break;
314*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
315*7c478bd9Sstevel@tonic-gate 					(void) printf(":");
316*7c478bd9Sstevel@tonic-gate 					caplen += 1;
317*7c478bd9Sstevel@tonic-gate 			}
318*7c478bd9Sstevel@tonic-gate 			printed++;
319*7c478bd9Sstevel@tonic-gate 		}
320*7c478bd9Sstevel@tonic-gate 		if (value < 0)
321*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
322*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
323*7c478bd9Sstevel@tonic-gate 					(void) printf("%s@,", infoname);
324*7c478bd9Sstevel@tonic-gate 					printed += nlen + 2;
325*7c478bd9Sstevel@tonic-gate 					break;
326*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
327*7c478bd9Sstevel@tonic-gate 					(void) printf("%s@", capname);
328*7c478bd9Sstevel@tonic-gate 					printed += nlen + 1;
329*7c478bd9Sstevel@tonic-gate 					caplen += nlen + 1;
330*7c478bd9Sstevel@tonic-gate 					break;
331*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
332*7c478bd9Sstevel@tonic-gate 					(void) printf("%s@,", fullname);
333*7c478bd9Sstevel@tonic-gate 					printed += nlen + 2;
334*7c478bd9Sstevel@tonic-gate 			}
335*7c478bd9Sstevel@tonic-gate 		else
336*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
337*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
338*7c478bd9Sstevel@tonic-gate 					(void) printf("%s,", infoname);
339*7c478bd9Sstevel@tonic-gate 					printed += nlen + 1;
340*7c478bd9Sstevel@tonic-gate 					break;
341*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
342*7c478bd9Sstevel@tonic-gate 					(void) printf("%s", capname);
343*7c478bd9Sstevel@tonic-gate 					printed += nlen;
344*7c478bd9Sstevel@tonic-gate 					caplen += nlen;
345*7c478bd9Sstevel@tonic-gate 					break;
346*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
347*7c478bd9Sstevel@tonic-gate 					(void) printf("%s,", fullname);
348*7c478bd9Sstevel@tonic-gate 					printed += nlen + 1;
349*7c478bd9Sstevel@tonic-gate 			}
350*7c478bd9Sstevel@tonic-gate 	}
351*7c478bd9Sstevel@tonic-gate }
352*7c478bd9Sstevel@tonic-gate 
353*7c478bd9Sstevel@tonic-gate void
354*7c478bd9Sstevel@tonic-gate pr_bfooting(void)
355*7c478bd9Sstevel@tonic-gate {
356*7c478bd9Sstevel@tonic-gate 	if (!onecolumn && (printed > 0))
357*7c478bd9Sstevel@tonic-gate 		switch ((int)printing) {
358*7c478bd9Sstevel@tonic-gate 			case (int)pr_terminfo:
359*7c478bd9Sstevel@tonic-gate 			case (int)pr_longnames:
360*7c478bd9Sstevel@tonic-gate 				(void) printf("\n");
361*7c478bd9Sstevel@tonic-gate 				break;
362*7c478bd9Sstevel@tonic-gate 			case (int)pr_cap:
363*7c478bd9Sstevel@tonic-gate 				(void) printf(":\\\n");
364*7c478bd9Sstevel@tonic-gate 			caplen += 1;
365*7c478bd9Sstevel@tonic-gate 	    }
366*7c478bd9Sstevel@tonic-gate }
367*7c478bd9Sstevel@tonic-gate 
368*7c478bd9Sstevel@tonic-gate void
369*7c478bd9Sstevel@tonic-gate pr_nheading(void)
370*7c478bd9Sstevel@tonic-gate {
371*7c478bd9Sstevel@tonic-gate 	if (printing == pr_longnames)
372*7c478bd9Sstevel@tonic-gate 		(void) printf("\nnumbers\n");
373*7c478bd9Sstevel@tonic-gate 	printed = 0;
374*7c478bd9Sstevel@tonic-gate }
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate /*
377*7c478bd9Sstevel@tonic-gate  *  Return the length of the number if it were printed out
378*7c478bd9Sstevel@tonic-gate  *  with %d. The number is guaranteed to be in the range
379*7c478bd9Sstevel@tonic-gate  *  0..maxshort.
380*7c478bd9Sstevel@tonic-gate  */
381*7c478bd9Sstevel@tonic-gate static int
382*7c478bd9Sstevel@tonic-gate digitlen(int value)
383*7c478bd9Sstevel@tonic-gate {
384*7c478bd9Sstevel@tonic-gate 	return (value >= 10000 ? 5 :
385*7c478bd9Sstevel@tonic-gate 	    value >=  1000 ? 4 :
386*7c478bd9Sstevel@tonic-gate 	    value >=   100 ? 3 :
387*7c478bd9Sstevel@tonic-gate 	    value >=    10 ? 2 :
388*7c478bd9Sstevel@tonic-gate 	    value >=	0 ? 1 : 0);
389*7c478bd9Sstevel@tonic-gate }
390*7c478bd9Sstevel@tonic-gate 
391*7c478bd9Sstevel@tonic-gate void
392*7c478bd9Sstevel@tonic-gate pr_number(char *infoname, char *capname, char *fullname, int value)
393*7c478bd9Sstevel@tonic-gate {
394*7c478bd9Sstevel@tonic-gate 	int	vlen;
395*7c478bd9Sstevel@tonic-gate 	size_t	nlen;
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate 	if (printing == pr_cap && restrictterm &&
398*7c478bd9Sstevel@tonic-gate 	    !findcapname(capname, capnums, ncapnums))
399*7c478bd9Sstevel@tonic-gate 		return;
400*7c478bd9Sstevel@tonic-gate 
401*7c478bd9Sstevel@tonic-gate 	if (onecolumn) {
402*7c478bd9Sstevel@tonic-gate 		if (value < 0)
403*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
404*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
405*7c478bd9Sstevel@tonic-gate 					(void) printf("\t%s@,\n", infoname);
406*7c478bd9Sstevel@tonic-gate 					break;
407*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
408*7c478bd9Sstevel@tonic-gate 					(void) printf("\t:%s@:\\\n", capname);
409*7c478bd9Sstevel@tonic-gate 					caplen += 4 + strlen(capname);
410*7c478bd9Sstevel@tonic-gate 					break;
411*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
412*7c478bd9Sstevel@tonic-gate 					(void) printf("  %s @\n", fullname);
413*7c478bd9Sstevel@tonic-gate 			}
414*7c478bd9Sstevel@tonic-gate 		else
415*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
416*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
417*7c478bd9Sstevel@tonic-gate 					(void) printf("\t%s#%d,\n", infoname,
418*7c478bd9Sstevel@tonic-gate 					    value);
419*7c478bd9Sstevel@tonic-gate 					break;
420*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
421*7c478bd9Sstevel@tonic-gate 					(void) printf("\t:%s#%d:\\\n",
422*7c478bd9Sstevel@tonic-gate 					    capname, value);
423*7c478bd9Sstevel@tonic-gate 					caplen += 4 + strlen(capname) +
424*7c478bd9Sstevel@tonic-gate 					    digitlen(value);
425*7c478bd9Sstevel@tonic-gate 					break;
426*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
427*7c478bd9Sstevel@tonic-gate 					(void) printf("  %s = %d\n", fullname,
428*7c478bd9Sstevel@tonic-gate 					    value);
429*7c478bd9Sstevel@tonic-gate 			}
430*7c478bd9Sstevel@tonic-gate 	} else {
431*7c478bd9Sstevel@tonic-gate 		switch ((int)printing) {
432*7c478bd9Sstevel@tonic-gate 			case (int)pr_terminfo:
433*7c478bd9Sstevel@tonic-gate 					nlen = strlen(infoname);
434*7c478bd9Sstevel@tonic-gate 					break;
435*7c478bd9Sstevel@tonic-gate 			case (int)pr_cap:
436*7c478bd9Sstevel@tonic-gate 					nlen = strlen(capname);
437*7c478bd9Sstevel@tonic-gate 					break;
438*7c478bd9Sstevel@tonic-gate 			case (int)pr_longnames:
439*7c478bd9Sstevel@tonic-gate 					nlen = strlen(fullname);
440*7c478bd9Sstevel@tonic-gate 					break;
441*7c478bd9Sstevel@tonic-gate 		}
442*7c478bd9Sstevel@tonic-gate 		vlen = digitlen(value);
443*7c478bd9Sstevel@tonic-gate 		if ((printed > 0) && (printed + nlen + vlen + 2 > width)) {
444*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
445*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
446*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
447*7c478bd9Sstevel@tonic-gate 					(void) printf("\n");
448*7c478bd9Sstevel@tonic-gate 					break;
449*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
450*7c478bd9Sstevel@tonic-gate 					(void) printf(":\\\n");
451*7c478bd9Sstevel@tonic-gate 					caplen += 1;
452*7c478bd9Sstevel@tonic-gate 			}
453*7c478bd9Sstevel@tonic-gate 			printed = 0;
454*7c478bd9Sstevel@tonic-gate 		}
455*7c478bd9Sstevel@tonic-gate 		if (printed == 0) {
456*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
457*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
458*7c478bd9Sstevel@tonic-gate 					(void) printf("\t");
459*7c478bd9Sstevel@tonic-gate 					printed = 8;
460*7c478bd9Sstevel@tonic-gate 					break;
461*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
462*7c478bd9Sstevel@tonic-gate 					(void) printf("\t:");
463*7c478bd9Sstevel@tonic-gate 					printed = 9;
464*7c478bd9Sstevel@tonic-gate 					caplen += 2;
465*7c478bd9Sstevel@tonic-gate 					break;
466*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
467*7c478bd9Sstevel@tonic-gate 					(void) printf("  ");
468*7c478bd9Sstevel@tonic-gate 					printed = 2;
469*7c478bd9Sstevel@tonic-gate 			}
470*7c478bd9Sstevel@tonic-gate 		} else {
471*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
472*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
473*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
474*7c478bd9Sstevel@tonic-gate 					(void) printf(" ");
475*7c478bd9Sstevel@tonic-gate 					break;
476*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
477*7c478bd9Sstevel@tonic-gate 					(void) printf(":");
478*7c478bd9Sstevel@tonic-gate 					caplen += 1;
479*7c478bd9Sstevel@tonic-gate 			}
480*7c478bd9Sstevel@tonic-gate 			printed++;
481*7c478bd9Sstevel@tonic-gate 		}
482*7c478bd9Sstevel@tonic-gate 		if (value < 0) {
483*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
484*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
485*7c478bd9Sstevel@tonic-gate 					(void) printf("%s@,", infoname);
486*7c478bd9Sstevel@tonic-gate 					printed += nlen + 2;
487*7c478bd9Sstevel@tonic-gate 					break;
488*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
489*7c478bd9Sstevel@tonic-gate 					(void) printf("%s@", capname);
490*7c478bd9Sstevel@tonic-gate 					printed += nlen + 1;
491*7c478bd9Sstevel@tonic-gate 					caplen += nlen + 1;
492*7c478bd9Sstevel@tonic-gate 					break;
493*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
494*7c478bd9Sstevel@tonic-gate 					(void) printf("%s@,", fullname);
495*7c478bd9Sstevel@tonic-gate 					printed += nlen + 2;
496*7c478bd9Sstevel@tonic-gate 			}
497*7c478bd9Sstevel@tonic-gate 		} else
498*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
499*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
500*7c478bd9Sstevel@tonic-gate 					(void) printf("%s#%d,", infoname,
501*7c478bd9Sstevel@tonic-gate 					    value);
502*7c478bd9Sstevel@tonic-gate 					printed += nlen + vlen + 2;
503*7c478bd9Sstevel@tonic-gate 					break;
504*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
505*7c478bd9Sstevel@tonic-gate 					(void) printf("%s#%d", capname, value);
506*7c478bd9Sstevel@tonic-gate 					printed += nlen + vlen + 1;
507*7c478bd9Sstevel@tonic-gate 					caplen += nlen + vlen + 1;
508*7c478bd9Sstevel@tonic-gate 					break;
509*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
510*7c478bd9Sstevel@tonic-gate 					(void) printf("%s = %d,", fullname,
511*7c478bd9Sstevel@tonic-gate 					    value);
512*7c478bd9Sstevel@tonic-gate 					printed += nlen + vlen + 4;
513*7c478bd9Sstevel@tonic-gate 			}
514*7c478bd9Sstevel@tonic-gate 	}
515*7c478bd9Sstevel@tonic-gate }
516*7c478bd9Sstevel@tonic-gate 
517*7c478bd9Sstevel@tonic-gate void
518*7c478bd9Sstevel@tonic-gate pr_nfooting(void)
519*7c478bd9Sstevel@tonic-gate {
520*7c478bd9Sstevel@tonic-gate 	if (!onecolumn && (printed > 0))
521*7c478bd9Sstevel@tonic-gate 		switch ((int)printing) {
522*7c478bd9Sstevel@tonic-gate 			case (int)pr_terminfo:
523*7c478bd9Sstevel@tonic-gate 			case (int)pr_longnames:
524*7c478bd9Sstevel@tonic-gate 				(void) printf("\n");
525*7c478bd9Sstevel@tonic-gate 				break;
526*7c478bd9Sstevel@tonic-gate 			case (int)pr_cap:
527*7c478bd9Sstevel@tonic-gate 				(void) printf(":\\\n");
528*7c478bd9Sstevel@tonic-gate 				caplen += 1;
529*7c478bd9Sstevel@tonic-gate 		}
530*7c478bd9Sstevel@tonic-gate }
531*7c478bd9Sstevel@tonic-gate 
532*7c478bd9Sstevel@tonic-gate void
533*7c478bd9Sstevel@tonic-gate pr_sheading(void)
534*7c478bd9Sstevel@tonic-gate {
535*7c478bd9Sstevel@tonic-gate 	if (printing == pr_longnames)
536*7c478bd9Sstevel@tonic-gate 		(void) printf("\nstrings\n");
537*7c478bd9Sstevel@tonic-gate 	printed = 0;
538*7c478bd9Sstevel@tonic-gate }
539*7c478bd9Sstevel@tonic-gate 
540*7c478bd9Sstevel@tonic-gate void
541*7c478bd9Sstevel@tonic-gate pr_string(char *infoname, char *capname, char *fullname, char *value)
542*7c478bd9Sstevel@tonic-gate {
543*7c478bd9Sstevel@tonic-gate 	char *evalue;
544*7c478bd9Sstevel@tonic-gate 	int badcapvalue;
545*7c478bd9Sstevel@tonic-gate 	size_t nlen, vlen;
546*7c478bd9Sstevel@tonic-gate 
547*7c478bd9Sstevel@tonic-gate 	if (printing == pr_cap) {
548*7c478bd9Sstevel@tonic-gate 		if (restrictterm && !findcapname(capname, capstrs, ncapstrs))
549*7c478bd9Sstevel@tonic-gate 			return;
550*7c478bd9Sstevel@tonic-gate 		if (value)
551*7c478bd9Sstevel@tonic-gate 			value = infotocap(value, &badcapvalue);
552*7c478bd9Sstevel@tonic-gate 	}
553*7c478bd9Sstevel@tonic-gate 
554*7c478bd9Sstevel@tonic-gate 	if (onecolumn) {
555*7c478bd9Sstevel@tonic-gate 		if (value == NULL)
556*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
557*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
558*7c478bd9Sstevel@tonic-gate 					(void) printf("\t%s@,\n", infoname);
559*7c478bd9Sstevel@tonic-gate 					break;
560*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
561*7c478bd9Sstevel@tonic-gate 					(void) printf("\t:%s@:\\\n", capname);
562*7c478bd9Sstevel@tonic-gate 					caplen += 4 + strlen(capname);
563*7c478bd9Sstevel@tonic-gate 					break;
564*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
565*7c478bd9Sstevel@tonic-gate 					(void) printf("  %s@\n", fullname);
566*7c478bd9Sstevel@tonic-gate 			}
567*7c478bd9Sstevel@tonic-gate 		else
568*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
569*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
570*7c478bd9Sstevel@tonic-gate 					(void) printf("\t%s=", infoname);
571*7c478bd9Sstevel@tonic-gate 					tpr(stdout, value);
572*7c478bd9Sstevel@tonic-gate 					(void) printf(",\n");
573*7c478bd9Sstevel@tonic-gate 					break;
574*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
575*7c478bd9Sstevel@tonic-gate 					(void) printf("\t:%s%s=",
576*7c478bd9Sstevel@tonic-gate 					    badcapvalue ? "." : "", capname);
577*7c478bd9Sstevel@tonic-gate 					caplen += 3 + strlen(capname) +
578*7c478bd9Sstevel@tonic-gate 					    (badcapvalue ? 1 : 0);
579*7c478bd9Sstevel@tonic-gate 					caplen += cpr(stdout, value);
580*7c478bd9Sstevel@tonic-gate 					(void) printf(":\\\n");
581*7c478bd9Sstevel@tonic-gate 					caplen += 1;
582*7c478bd9Sstevel@tonic-gate 					break;
583*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
584*7c478bd9Sstevel@tonic-gate 					(void) printf("  %s = '", fullname);
585*7c478bd9Sstevel@tonic-gate 					tpr(stdout, value);
586*7c478bd9Sstevel@tonic-gate 					(void) printf("'\n");
587*7c478bd9Sstevel@tonic-gate 			}
588*7c478bd9Sstevel@tonic-gate 	} else {
589*7c478bd9Sstevel@tonic-gate 		switch ((int)printing) {
590*7c478bd9Sstevel@tonic-gate 			case (int)pr_terminfo:
591*7c478bd9Sstevel@tonic-gate 				nlen = strlen(infoname);
592*7c478bd9Sstevel@tonic-gate 				break;
593*7c478bd9Sstevel@tonic-gate 			case (int)pr_cap:
594*7c478bd9Sstevel@tonic-gate 				nlen = strlen(capname);
595*7c478bd9Sstevel@tonic-gate 				if (badcapvalue)
596*7c478bd9Sstevel@tonic-gate 					nlen++;
597*7c478bd9Sstevel@tonic-gate 				break;
598*7c478bd9Sstevel@tonic-gate 			case (int)pr_longnames:
599*7c478bd9Sstevel@tonic-gate 				nlen = strlen(fullname);
600*7c478bd9Sstevel@tonic-gate 		}
601*7c478bd9Sstevel@tonic-gate 		if (value == NULL)
602*7c478bd9Sstevel@tonic-gate 			vlen = 1;
603*7c478bd9Sstevel@tonic-gate 		else
604*7c478bd9Sstevel@tonic-gate 			if (printing == pr_cap)
605*7c478bd9Sstevel@tonic-gate 				vlen = strlen(evalue = cexpand(value));
606*7c478bd9Sstevel@tonic-gate 			else
607*7c478bd9Sstevel@tonic-gate 				vlen = strlen(evalue = iexpand(value));
608*7c478bd9Sstevel@tonic-gate 		if ((printed > 0) && (printed + nlen + vlen + 1 > width)) {
609*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
610*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
611*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
612*7c478bd9Sstevel@tonic-gate 					(void) printf("\n");
613*7c478bd9Sstevel@tonic-gate 					break;
614*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
615*7c478bd9Sstevel@tonic-gate 					(void) printf(":\\\n");
616*7c478bd9Sstevel@tonic-gate 					caplen += 1;
617*7c478bd9Sstevel@tonic-gate 			}
618*7c478bd9Sstevel@tonic-gate 			printed = 0;
619*7c478bd9Sstevel@tonic-gate 		}
620*7c478bd9Sstevel@tonic-gate 		if (printed == 0) {
621*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
622*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
623*7c478bd9Sstevel@tonic-gate 					(void) printf("\t");
624*7c478bd9Sstevel@tonic-gate 					printed = 8;
625*7c478bd9Sstevel@tonic-gate 					break;
626*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
627*7c478bd9Sstevel@tonic-gate 					(void) printf("\t:");
628*7c478bd9Sstevel@tonic-gate 					printed = 9;
629*7c478bd9Sstevel@tonic-gate 					caplen += 2;
630*7c478bd9Sstevel@tonic-gate 					break;
631*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
632*7c478bd9Sstevel@tonic-gate 					(void) printf("  ");
633*7c478bd9Sstevel@tonic-gate 					printed = 2;
634*7c478bd9Sstevel@tonic-gate 			}
635*7c478bd9Sstevel@tonic-gate 		} else {
636*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
637*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
638*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
639*7c478bd9Sstevel@tonic-gate 					(void) printf(" ");
640*7c478bd9Sstevel@tonic-gate 					break;
641*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
642*7c478bd9Sstevel@tonic-gate 					(void) printf(":");
643*7c478bd9Sstevel@tonic-gate 					caplen += 1;
644*7c478bd9Sstevel@tonic-gate 			}
645*7c478bd9Sstevel@tonic-gate 			printed++;
646*7c478bd9Sstevel@tonic-gate 		}
647*7c478bd9Sstevel@tonic-gate 		if (value == NULL) {
648*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
649*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
650*7c478bd9Sstevel@tonic-gate 					(void) printf("%s@,", infoname);
651*7c478bd9Sstevel@tonic-gate 					printed += nlen + 2;
652*7c478bd9Sstevel@tonic-gate 					break;
653*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
654*7c478bd9Sstevel@tonic-gate 					(void) printf("%s@", capname);
655*7c478bd9Sstevel@tonic-gate 					printed += nlen + 1;
656*7c478bd9Sstevel@tonic-gate 					caplen += nlen + 1;
657*7c478bd9Sstevel@tonic-gate 					break;
658*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
659*7c478bd9Sstevel@tonic-gate 					(void) printf("%s@,", fullname);
660*7c478bd9Sstevel@tonic-gate 					printed += nlen + 2;
661*7c478bd9Sstevel@tonic-gate 			}
662*7c478bd9Sstevel@tonic-gate 		} else
663*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
664*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
665*7c478bd9Sstevel@tonic-gate 					(void) printf("%s=%s,", infoname,
666*7c478bd9Sstevel@tonic-gate 					    evalue);
667*7c478bd9Sstevel@tonic-gate 					printed += nlen + vlen + 2;
668*7c478bd9Sstevel@tonic-gate 					break;
669*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
670*7c478bd9Sstevel@tonic-gate 					if (badcapvalue) {
671*7c478bd9Sstevel@tonic-gate 						(void) printf(".");
672*7c478bd9Sstevel@tonic-gate 						caplen += 1;
673*7c478bd9Sstevel@tonic-gate 					}
674*7c478bd9Sstevel@tonic-gate 					(void) printf("%s=%s", capname,
675*7c478bd9Sstevel@tonic-gate 					    evalue);
676*7c478bd9Sstevel@tonic-gate 					printed += nlen + vlen + 1;
677*7c478bd9Sstevel@tonic-gate 					caplen += nlen + vlen + 1;
678*7c478bd9Sstevel@tonic-gate 					break;
679*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
680*7c478bd9Sstevel@tonic-gate 					(void) printf("%s = '%s',", fullname,
681*7c478bd9Sstevel@tonic-gate 					    evalue);
682*7c478bd9Sstevel@tonic-gate 					printed += nlen + vlen + 6;
683*7c478bd9Sstevel@tonic-gate 			}
684*7c478bd9Sstevel@tonic-gate 	}
685*7c478bd9Sstevel@tonic-gate }
686*7c478bd9Sstevel@tonic-gate 
687*7c478bd9Sstevel@tonic-gate void
688*7c478bd9Sstevel@tonic-gate pr_sfooting(void)
689*7c478bd9Sstevel@tonic-gate {
690*7c478bd9Sstevel@tonic-gate 	if (onecolumn) {
691*7c478bd9Sstevel@tonic-gate 		if (printing == pr_cap)
692*7c478bd9Sstevel@tonic-gate 			(void) printf("\n");
693*7c478bd9Sstevel@tonic-gate 	} else {
694*7c478bd9Sstevel@tonic-gate 		if (printed > 0)
695*7c478bd9Sstevel@tonic-gate 			switch ((int)printing) {
696*7c478bd9Sstevel@tonic-gate 				case (int)pr_terminfo:
697*7c478bd9Sstevel@tonic-gate 				case (int)pr_longnames:
698*7c478bd9Sstevel@tonic-gate 					(void) printf("\n");
699*7c478bd9Sstevel@tonic-gate 					break;
700*7c478bd9Sstevel@tonic-gate 				case (int)pr_cap:
701*7c478bd9Sstevel@tonic-gate 					(void) printf(":\n");
702*7c478bd9Sstevel@tonic-gate 					caplen += 1;
703*7c478bd9Sstevel@tonic-gate 			}
704*7c478bd9Sstevel@tonic-gate 	}
705*7c478bd9Sstevel@tonic-gate 	if (caplen >= 1024) {
706*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: WARNING: termcap entry is too "
707*7c478bd9Sstevel@tonic-gate 		    "long!\n", progname);
708*7c478bd9Sstevel@tonic-gate 	}
709*7c478bd9Sstevel@tonic-gate 
710*7c478bd9Sstevel@tonic-gate 	if (printing == pr_longnames)
711*7c478bd9Sstevel@tonic-gate 		(void) printf("end of strings\n");
712*7c478bd9Sstevel@tonic-gate }
713