10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*1914Scasper * Common Development and Distribution License (the "License").
6*1914Scasper * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*1914Scasper * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate * The Regents of the University of California
320Sstevel@tonic-gate * All Rights Reserved
330Sstevel@tonic-gate *
340Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate * contributors.
370Sstevel@tonic-gate */
380Sstevel@tonic-gate
390Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
400Sstevel@tonic-gate
410Sstevel@tonic-gate #include <stdlib.h>
420Sstevel@tonic-gate #include <string.h>
430Sstevel@tonic-gate #include <sys/types.h>
440Sstevel@tonic-gate #include "curses_inc.h"
450Sstevel@tonic-gate #include "print.h"
460Sstevel@tonic-gate #include <signal.h> /* use this file to determine if this is SVR4.0 system */
470Sstevel@tonic-gate
480Sstevel@tonic-gate #ifdef SIGSTOP /* SVR4.0 and beyond */
490Sstevel@tonic-gate #define _ULIBTI "/usr/share/lib/terminfo"
500Sstevel@tonic-gate #else
510Sstevel@tonic-gate #define _ULIBTI "/usr/lib/terminfo"
520Sstevel@tonic-gate #endif
530Sstevel@tonic-gate
540Sstevel@tonic-gate char *progname;
550Sstevel@tonic-gate
560Sstevel@tonic-gate /* global variables */
570Sstevel@tonic-gate static enum printtypes printing = pr_none;
580Sstevel@tonic-gate static int onecolumn = 0; /* print a single column */
590Sstevel@tonic-gate static int width = 60; /* width of multi-column printing */
600Sstevel@tonic-gate static int restrictterm = 1; /* restrict termcap names */
610Sstevel@tonic-gate
620Sstevel@tonic-gate /* local variables */
630Sstevel@tonic-gate static int printed = 0;
640Sstevel@tonic-gate static size_t caplen = 0;
650Sstevel@tonic-gate
660Sstevel@tonic-gate void
pr_init(enum printtypes type)670Sstevel@tonic-gate pr_init(enum printtypes type)
680Sstevel@tonic-gate {
690Sstevel@tonic-gate printing = type;
700Sstevel@tonic-gate }
710Sstevel@tonic-gate
720Sstevel@tonic-gate void
pr_onecolumn(int onoff)730Sstevel@tonic-gate pr_onecolumn(int onoff)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate onecolumn = onoff;
760Sstevel@tonic-gate }
770Sstevel@tonic-gate
780Sstevel@tonic-gate void
pr_width(int nwidth)790Sstevel@tonic-gate pr_width(int nwidth)
800Sstevel@tonic-gate {
810Sstevel@tonic-gate if (nwidth > 0)
820Sstevel@tonic-gate width = nwidth;
830Sstevel@tonic-gate }
840Sstevel@tonic-gate
850Sstevel@tonic-gate void
pr_caprestrict(int onoff)860Sstevel@tonic-gate pr_caprestrict(int onoff)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate restrictterm = onoff;
890Sstevel@tonic-gate }
900Sstevel@tonic-gate
910Sstevel@tonic-gate static char capbools[] =
920Sstevel@tonic-gate "ambsbwdadbeoeshchshzinkmmimsncnsosptulxbxnxoxsxt";
930Sstevel@tonic-gate static int ncapbools = sizeof (capbools) / sizeof (capbools[0]);
940Sstevel@tonic-gate
950Sstevel@tonic-gate static char capnums[] =
960Sstevel@tonic-gate "codBdCdFdNdTknlipbsgug";
970Sstevel@tonic-gate static int ncapnums = sizeof (capnums) / sizeof (capnums[0]);
980Sstevel@tonic-gate
990Sstevel@tonic-gate static char capstrs[] =
1000Sstevel@tonic-gate "ALDCDLDOICLERISFSRUPaealasbcbtcdcechclcmcsctcvdcdldmdsedeifshoi1i2i"
1010Sstevel@tonic-gate "cifimipisk0k1k2k3k4k5k6k7k8k9kbkdkekhklkokrkskul0l1l2l3l4l5l6l7l"
1020Sstevel@tonic-gate "8l9ndnlpcr1r2r3rcrfrpscsesosrsttetitsucueupusvbvevivs";
1030Sstevel@tonic-gate static int ncapstrs = sizeof (capstrs) / sizeof (capstrs[0]);
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate static int
findcapname(char * capname,char * caplist,int listsize)1060Sstevel@tonic-gate findcapname(char *capname, char *caplist, int listsize)
1070Sstevel@tonic-gate {
1080Sstevel@tonic-gate int low = 0, mid, high = listsize - 2;
1090Sstevel@tonic-gate while (low <= high) {
1100Sstevel@tonic-gate mid = (low + high) / 4 * 2;
1110Sstevel@tonic-gate if (capname[0] == caplist[mid]) {
1120Sstevel@tonic-gate if (capname[1] == caplist[mid + 1])
1130Sstevel@tonic-gate return (1);
1140Sstevel@tonic-gate else if (capname[1] < caplist[mid + 1])
1150Sstevel@tonic-gate high = mid - 2;
1160Sstevel@tonic-gate else
1170Sstevel@tonic-gate low = mid + 2;
1180Sstevel@tonic-gate } else if (capname[0] < caplist[mid])
1190Sstevel@tonic-gate high = mid - 2;
1200Sstevel@tonic-gate else
1210Sstevel@tonic-gate low = mid + 2;
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate return (0);
1240Sstevel@tonic-gate /*
1250Sstevel@tonic-gate * for (; *caplist; caplist += 2)
1260Sstevel@tonic-gate * if (caplist[0] == capname[0] && caplist[1] == capname[1])
1270Sstevel@tonic-gate * return (1);
1280Sstevel@tonic-gate * return (0);
1290Sstevel@tonic-gate */
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate /*
1330Sstevel@tonic-gate * Print out the first line of an entry.
1340Sstevel@tonic-gate */
1350Sstevel@tonic-gate void
pr_heading(char * term,char * synonyms)1360Sstevel@tonic-gate pr_heading(char *term, char *synonyms)
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate int do_print = 0; /* Can we print the path of the file ? */
1390Sstevel@tonic-gate char buffer[512]; /* Holds search pathname */
1400Sstevel@tonic-gate FILE *work_fp; /* Used to try and open the files */
1410Sstevel@tonic-gate char tail[4]; /* Used for terminfo pathname suffix */
1420Sstevel@tonic-gate char *terminfo; /* The value of $TERMINFO */
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate /*
1460Sstevel@tonic-gate * Try to obtain $TERMINFO
1470Sstevel@tonic-gate */
1480Sstevel@tonic-gate terminfo = getenv("TERMINFO");
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate if (term == (char *)0)
1510Sstevel@tonic-gate term = "";
1520Sstevel@tonic-gate /*
1530Sstevel@tonic-gate * Build the suffix for this device
1540Sstevel@tonic-gate */
1550Sstevel@tonic-gate tail[0] = '/';
1560Sstevel@tonic-gate tail[1] = *term;
1570Sstevel@tonic-gate tail[2] = '/';
1580Sstevel@tonic-gate tail[3] = '\0';
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate /*
1610Sstevel@tonic-gate * If we have it - use it, otherwise use /usr/share/lib/terminfo
1620Sstevel@tonic-gate * as base directory
1630Sstevel@tonic-gate */
1640Sstevel@tonic-gate if (terminfo != NULL)
1650Sstevel@tonic-gate (void) sprintf(buffer, "%s%s%s", terminfo, tail, term);
1660Sstevel@tonic-gate else
1670Sstevel@tonic-gate (void) sprintf(buffer, "%s%s%s", _ULIBTI, tail, term);
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate /*
1700Sstevel@tonic-gate * Attempt to open the file.
1710Sstevel@tonic-gate */
172*1914Scasper if ((work_fp = fopen(buffer, "rF")) == NULL) {
1730Sstevel@tonic-gate /*
1740Sstevel@tonic-gate * Open failed. If we were looking in /usr/share/lib/terminfo
1750Sstevel@tonic-gate * we are done, otherwise look there next.
1760Sstevel@tonic-gate */
1770Sstevel@tonic-gate if (strncmp(buffer, _ULIBTI, strlen(_ULIBTI)) == 0) {
1780Sstevel@tonic-gate /*
1790Sstevel@tonic-gate * We are done. Not in /usr/share/lib/terminfo,
1800Sstevel@tonic-gate * and $TERMINFO is not set.
1810Sstevel@tonic-gate */
1820Sstevel@tonic-gate (void) fprintf(stderr, "Error: Term \"%s\" not "
1830Sstevel@tonic-gate "found in %s\n", term, _ULIBTI);
1840Sstevel@tonic-gate } else {
1850Sstevel@tonic-gate /*
1860Sstevel@tonic-gate * Check /usr/share/lib/terminfo last. If this fails,
1870Sstevel@tonic-gate * all hope is lost as we know it is not in $TERMINFO.
1880Sstevel@tonic-gate */
1890Sstevel@tonic-gate (void) sprintf(buffer, "%s%s%s", _ULIBTI, tail, term);
1900Sstevel@tonic-gate
191*1914Scasper if ((work_fp = fopen(buffer, "rF")) == NULL) {
1920Sstevel@tonic-gate /*
1930Sstevel@tonic-gate * All hope is lost
1940Sstevel@tonic-gate */
1950Sstevel@tonic-gate (void) fprintf(stderr, "Error: Term \"%s\" not "
1960Sstevel@tonic-gate "found in %s or %s\n", term, _ULIBTI,
1970Sstevel@tonic-gate getenv("TERMINFO"));
1980Sstevel@tonic-gate } else do_print = 1;
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate } else do_print = 1;
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate /*
2030Sstevel@tonic-gate * If we found it - print the comment(after closing the file)
2040Sstevel@tonic-gate */
2050Sstevel@tonic-gate if (do_print && *term) {
2060Sstevel@tonic-gate (void) fclose(work_fp);
2070Sstevel@tonic-gate (void) printf("# Reconstructed via infocmp from file: "
2080Sstevel@tonic-gate "%s\n", buffer);
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate switch ((int)printing) {
2120Sstevel@tonic-gate case (int)pr_terminfo:
2130Sstevel@tonic-gate (void) printf("%s,\n", synonyms);
2140Sstevel@tonic-gate break;
2150Sstevel@tonic-gate case (int)pr_cap:
2160Sstevel@tonic-gate (void) printf("%s:\\\n", synonyms);
2170Sstevel@tonic-gate caplen = strlen(synonyms) + 1;
2180Sstevel@tonic-gate break;
2190Sstevel@tonic-gate case (int)pr_longnames:
2200Sstevel@tonic-gate (void) printf("Terminal type %s\n", term);
2210Sstevel@tonic-gate (void) printf(" %s\n", synonyms);
2220Sstevel@tonic-gate break;
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate void
pr_bheading(void)2270Sstevel@tonic-gate pr_bheading(void)
2280Sstevel@tonic-gate {
2290Sstevel@tonic-gate if (printing == pr_longnames)
2300Sstevel@tonic-gate (void) printf("flags\n");
2310Sstevel@tonic-gate printed = 0;
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate void
pr_boolean(char * infoname,char * capname,char * fullname,int value)2350Sstevel@tonic-gate pr_boolean(char *infoname, char *capname, char *fullname, int value)
2360Sstevel@tonic-gate {
2370Sstevel@tonic-gate int vlen;
2380Sstevel@tonic-gate size_t nlen;
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate if (printing == pr_cap && restrictterm &&
2410Sstevel@tonic-gate !findcapname(capname, capbools, ncapbools))
2420Sstevel@tonic-gate return;
2430Sstevel@tonic-gate
2440Sstevel@tonic-gate if (onecolumn) {
2450Sstevel@tonic-gate if (value < 0)
2460Sstevel@tonic-gate switch ((int)printing) {
2470Sstevel@tonic-gate case (int)pr_terminfo:
2480Sstevel@tonic-gate (void) printf("\t%s@,\n", infoname);
2490Sstevel@tonic-gate break;
2500Sstevel@tonic-gate case (int)pr_cap:
2510Sstevel@tonic-gate (void) printf("\t:%s@:\\\n", capname);
2520Sstevel@tonic-gate caplen += 4 + strlen(capname);
2530Sstevel@tonic-gate break;
2540Sstevel@tonic-gate case (int)pr_longnames:
2550Sstevel@tonic-gate (void) printf(" %s@\n", fullname);
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate else
2580Sstevel@tonic-gate switch ((int)printing) {
2590Sstevel@tonic-gate case (int)pr_terminfo:
2600Sstevel@tonic-gate (void) printf("\t%s,\n", infoname);
2610Sstevel@tonic-gate break;
2620Sstevel@tonic-gate case (int)pr_cap:
2630Sstevel@tonic-gate (void) printf("\t:%s:\\\n", capname);
2640Sstevel@tonic-gate caplen += 3 + strlen(capname);
2650Sstevel@tonic-gate break;
2660Sstevel@tonic-gate case (int)pr_longnames:
2670Sstevel@tonic-gate (void) printf(" %s\n", fullname);
2680Sstevel@tonic-gate }
2690Sstevel@tonic-gate } else {
2700Sstevel@tonic-gate switch ((int)printing) {
2710Sstevel@tonic-gate case (int)pr_terminfo: nlen = strlen(infoname);
2720Sstevel@tonic-gate break;
2730Sstevel@tonic-gate case (int)pr_cap: nlen = strlen(capname);
2740Sstevel@tonic-gate break;
2750Sstevel@tonic-gate case (int)pr_longnames:
2760Sstevel@tonic-gate nlen = strlen(fullname);
2770Sstevel@tonic-gate break;
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate vlen = (value < 0) ? 1 : 0;
2800Sstevel@tonic-gate if ((printed > 0) && (printed + nlen + vlen + 1 > width)) {
2810Sstevel@tonic-gate switch ((int)printing) {
2820Sstevel@tonic-gate case (int)pr_terminfo:
2830Sstevel@tonic-gate case (int)pr_longnames:
2840Sstevel@tonic-gate (void) printf("\n");
2850Sstevel@tonic-gate break;
2860Sstevel@tonic-gate case (int)pr_cap:
2870Sstevel@tonic-gate (void) printf(":\\\n");
2880Sstevel@tonic-gate caplen += 1;
2890Sstevel@tonic-gate }
2900Sstevel@tonic-gate printed = 0;
2910Sstevel@tonic-gate }
2920Sstevel@tonic-gate if (printed == 0) {
2930Sstevel@tonic-gate switch ((int)printing) {
2940Sstevel@tonic-gate case (int)pr_terminfo:
2950Sstevel@tonic-gate (void) printf("\t");
2960Sstevel@tonic-gate printed = 8;
2970Sstevel@tonic-gate break;
2980Sstevel@tonic-gate case (int)pr_cap:
2990Sstevel@tonic-gate (void) printf("\t:");
3000Sstevel@tonic-gate printed = 9;
3010Sstevel@tonic-gate caplen += 2;
3020Sstevel@tonic-gate break;
3030Sstevel@tonic-gate case (int)pr_longnames:
3040Sstevel@tonic-gate (void) printf(" ");
3050Sstevel@tonic-gate printed = 2;
3060Sstevel@tonic-gate }
3070Sstevel@tonic-gate } else {
3080Sstevel@tonic-gate switch ((int)printing) {
3090Sstevel@tonic-gate case (int)pr_terminfo:
3100Sstevel@tonic-gate case (int)pr_longnames:
3110Sstevel@tonic-gate (void) printf(" ");
3120Sstevel@tonic-gate break;
3130Sstevel@tonic-gate case (int)pr_cap:
3140Sstevel@tonic-gate (void) printf(":");
3150Sstevel@tonic-gate caplen += 1;
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate printed++;
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate if (value < 0)
3200Sstevel@tonic-gate switch ((int)printing) {
3210Sstevel@tonic-gate case (int)pr_terminfo:
3220Sstevel@tonic-gate (void) printf("%s@,", infoname);
3230Sstevel@tonic-gate printed += nlen + 2;
3240Sstevel@tonic-gate break;
3250Sstevel@tonic-gate case (int)pr_cap:
3260Sstevel@tonic-gate (void) printf("%s@", capname);
3270Sstevel@tonic-gate printed += nlen + 1;
3280Sstevel@tonic-gate caplen += nlen + 1;
3290Sstevel@tonic-gate break;
3300Sstevel@tonic-gate case (int)pr_longnames:
3310Sstevel@tonic-gate (void) printf("%s@,", fullname);
3320Sstevel@tonic-gate printed += nlen + 2;
3330Sstevel@tonic-gate }
3340Sstevel@tonic-gate else
3350Sstevel@tonic-gate switch ((int)printing) {
3360Sstevel@tonic-gate case (int)pr_terminfo:
3370Sstevel@tonic-gate (void) printf("%s,", infoname);
3380Sstevel@tonic-gate printed += nlen + 1;
3390Sstevel@tonic-gate break;
3400Sstevel@tonic-gate case (int)pr_cap:
3410Sstevel@tonic-gate (void) printf("%s", capname);
3420Sstevel@tonic-gate printed += nlen;
3430Sstevel@tonic-gate caplen += nlen;
3440Sstevel@tonic-gate break;
3450Sstevel@tonic-gate case (int)pr_longnames:
3460Sstevel@tonic-gate (void) printf("%s,", fullname);
3470Sstevel@tonic-gate printed += nlen + 1;
3480Sstevel@tonic-gate }
3490Sstevel@tonic-gate }
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate void
pr_bfooting(void)3530Sstevel@tonic-gate pr_bfooting(void)
3540Sstevel@tonic-gate {
3550Sstevel@tonic-gate if (!onecolumn && (printed > 0))
3560Sstevel@tonic-gate switch ((int)printing) {
3570Sstevel@tonic-gate case (int)pr_terminfo:
3580Sstevel@tonic-gate case (int)pr_longnames:
3590Sstevel@tonic-gate (void) printf("\n");
3600Sstevel@tonic-gate break;
3610Sstevel@tonic-gate case (int)pr_cap:
3620Sstevel@tonic-gate (void) printf(":\\\n");
3630Sstevel@tonic-gate caplen += 1;
3640Sstevel@tonic-gate }
3650Sstevel@tonic-gate }
3660Sstevel@tonic-gate
3670Sstevel@tonic-gate void
pr_nheading(void)3680Sstevel@tonic-gate pr_nheading(void)
3690Sstevel@tonic-gate {
3700Sstevel@tonic-gate if (printing == pr_longnames)
3710Sstevel@tonic-gate (void) printf("\nnumbers\n");
3720Sstevel@tonic-gate printed = 0;
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate /*
3760Sstevel@tonic-gate * Return the length of the number if it were printed out
3770Sstevel@tonic-gate * with %d. The number is guaranteed to be in the range
3780Sstevel@tonic-gate * 0..maxshort.
3790Sstevel@tonic-gate */
3800Sstevel@tonic-gate static int
digitlen(int value)3810Sstevel@tonic-gate digitlen(int value)
3820Sstevel@tonic-gate {
3830Sstevel@tonic-gate return (value >= 10000 ? 5 :
3840Sstevel@tonic-gate value >= 1000 ? 4 :
3850Sstevel@tonic-gate value >= 100 ? 3 :
3860Sstevel@tonic-gate value >= 10 ? 2 :
3870Sstevel@tonic-gate value >= 0 ? 1 : 0);
3880Sstevel@tonic-gate }
3890Sstevel@tonic-gate
3900Sstevel@tonic-gate void
pr_number(char * infoname,char * capname,char * fullname,int value)3910Sstevel@tonic-gate pr_number(char *infoname, char *capname, char *fullname, int value)
3920Sstevel@tonic-gate {
3930Sstevel@tonic-gate int vlen;
3940Sstevel@tonic-gate size_t nlen;
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate if (printing == pr_cap && restrictterm &&
3970Sstevel@tonic-gate !findcapname(capname, capnums, ncapnums))
3980Sstevel@tonic-gate return;
3990Sstevel@tonic-gate
4000Sstevel@tonic-gate if (onecolumn) {
4010Sstevel@tonic-gate if (value < 0)
4020Sstevel@tonic-gate switch ((int)printing) {
4030Sstevel@tonic-gate case (int)pr_terminfo:
4040Sstevel@tonic-gate (void) printf("\t%s@,\n", infoname);
4050Sstevel@tonic-gate break;
4060Sstevel@tonic-gate case (int)pr_cap:
4070Sstevel@tonic-gate (void) printf("\t:%s@:\\\n", capname);
4080Sstevel@tonic-gate caplen += 4 + strlen(capname);
4090Sstevel@tonic-gate break;
4100Sstevel@tonic-gate case (int)pr_longnames:
4110Sstevel@tonic-gate (void) printf(" %s @\n", fullname);
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate else
4140Sstevel@tonic-gate switch ((int)printing) {
4150Sstevel@tonic-gate case (int)pr_terminfo:
4160Sstevel@tonic-gate (void) printf("\t%s#%d,\n", infoname,
4170Sstevel@tonic-gate value);
4180Sstevel@tonic-gate break;
4190Sstevel@tonic-gate case (int)pr_cap:
4200Sstevel@tonic-gate (void) printf("\t:%s#%d:\\\n",
4210Sstevel@tonic-gate capname, value);
4220Sstevel@tonic-gate caplen += 4 + strlen(capname) +
4230Sstevel@tonic-gate digitlen(value);
4240Sstevel@tonic-gate break;
4250Sstevel@tonic-gate case (int)pr_longnames:
4260Sstevel@tonic-gate (void) printf(" %s = %d\n", fullname,
4270Sstevel@tonic-gate value);
4280Sstevel@tonic-gate }
4290Sstevel@tonic-gate } else {
4300Sstevel@tonic-gate switch ((int)printing) {
4310Sstevel@tonic-gate case (int)pr_terminfo:
4320Sstevel@tonic-gate nlen = strlen(infoname);
4330Sstevel@tonic-gate break;
4340Sstevel@tonic-gate case (int)pr_cap:
4350Sstevel@tonic-gate nlen = strlen(capname);
4360Sstevel@tonic-gate break;
4370Sstevel@tonic-gate case (int)pr_longnames:
4380Sstevel@tonic-gate nlen = strlen(fullname);
4390Sstevel@tonic-gate break;
4400Sstevel@tonic-gate }
4410Sstevel@tonic-gate vlen = digitlen(value);
4420Sstevel@tonic-gate if ((printed > 0) && (printed + nlen + vlen + 2 > width)) {
4430Sstevel@tonic-gate switch ((int)printing) {
4440Sstevel@tonic-gate case (int)pr_terminfo:
4450Sstevel@tonic-gate case (int)pr_longnames:
4460Sstevel@tonic-gate (void) printf("\n");
4470Sstevel@tonic-gate break;
4480Sstevel@tonic-gate case (int)pr_cap:
4490Sstevel@tonic-gate (void) printf(":\\\n");
4500Sstevel@tonic-gate caplen += 1;
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate printed = 0;
4530Sstevel@tonic-gate }
4540Sstevel@tonic-gate if (printed == 0) {
4550Sstevel@tonic-gate switch ((int)printing) {
4560Sstevel@tonic-gate case (int)pr_terminfo:
4570Sstevel@tonic-gate (void) printf("\t");
4580Sstevel@tonic-gate printed = 8;
4590Sstevel@tonic-gate break;
4600Sstevel@tonic-gate case (int)pr_cap:
4610Sstevel@tonic-gate (void) printf("\t:");
4620Sstevel@tonic-gate printed = 9;
4630Sstevel@tonic-gate caplen += 2;
4640Sstevel@tonic-gate break;
4650Sstevel@tonic-gate case (int)pr_longnames:
4660Sstevel@tonic-gate (void) printf(" ");
4670Sstevel@tonic-gate printed = 2;
4680Sstevel@tonic-gate }
4690Sstevel@tonic-gate } else {
4700Sstevel@tonic-gate switch ((int)printing) {
4710Sstevel@tonic-gate case (int)pr_terminfo:
4720Sstevel@tonic-gate case (int)pr_longnames:
4730Sstevel@tonic-gate (void) printf(" ");
4740Sstevel@tonic-gate break;
4750Sstevel@tonic-gate case (int)pr_cap:
4760Sstevel@tonic-gate (void) printf(":");
4770Sstevel@tonic-gate caplen += 1;
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate printed++;
4800Sstevel@tonic-gate }
4810Sstevel@tonic-gate if (value < 0) {
4820Sstevel@tonic-gate switch ((int)printing) {
4830Sstevel@tonic-gate case (int)pr_terminfo:
4840Sstevel@tonic-gate (void) printf("%s@,", infoname);
4850Sstevel@tonic-gate printed += nlen + 2;
4860Sstevel@tonic-gate break;
4870Sstevel@tonic-gate case (int)pr_cap:
4880Sstevel@tonic-gate (void) printf("%s@", capname);
4890Sstevel@tonic-gate printed += nlen + 1;
4900Sstevel@tonic-gate caplen += nlen + 1;
4910Sstevel@tonic-gate break;
4920Sstevel@tonic-gate case (int)pr_longnames:
4930Sstevel@tonic-gate (void) printf("%s@,", fullname);
4940Sstevel@tonic-gate printed += nlen + 2;
4950Sstevel@tonic-gate }
4960Sstevel@tonic-gate } else
4970Sstevel@tonic-gate switch ((int)printing) {
4980Sstevel@tonic-gate case (int)pr_terminfo:
4990Sstevel@tonic-gate (void) printf("%s#%d,", infoname,
5000Sstevel@tonic-gate value);
5010Sstevel@tonic-gate printed += nlen + vlen + 2;
5020Sstevel@tonic-gate break;
5030Sstevel@tonic-gate case (int)pr_cap:
5040Sstevel@tonic-gate (void) printf("%s#%d", capname, value);
5050Sstevel@tonic-gate printed += nlen + vlen + 1;
5060Sstevel@tonic-gate caplen += nlen + vlen + 1;
5070Sstevel@tonic-gate break;
5080Sstevel@tonic-gate case (int)pr_longnames:
5090Sstevel@tonic-gate (void) printf("%s = %d,", fullname,
5100Sstevel@tonic-gate value);
5110Sstevel@tonic-gate printed += nlen + vlen + 4;
5120Sstevel@tonic-gate }
5130Sstevel@tonic-gate }
5140Sstevel@tonic-gate }
5150Sstevel@tonic-gate
5160Sstevel@tonic-gate void
pr_nfooting(void)5170Sstevel@tonic-gate pr_nfooting(void)
5180Sstevel@tonic-gate {
5190Sstevel@tonic-gate if (!onecolumn && (printed > 0))
5200Sstevel@tonic-gate switch ((int)printing) {
5210Sstevel@tonic-gate case (int)pr_terminfo:
5220Sstevel@tonic-gate case (int)pr_longnames:
5230Sstevel@tonic-gate (void) printf("\n");
5240Sstevel@tonic-gate break;
5250Sstevel@tonic-gate case (int)pr_cap:
5260Sstevel@tonic-gate (void) printf(":\\\n");
5270Sstevel@tonic-gate caplen += 1;
5280Sstevel@tonic-gate }
5290Sstevel@tonic-gate }
5300Sstevel@tonic-gate
5310Sstevel@tonic-gate void
pr_sheading(void)5320Sstevel@tonic-gate pr_sheading(void)
5330Sstevel@tonic-gate {
5340Sstevel@tonic-gate if (printing == pr_longnames)
5350Sstevel@tonic-gate (void) printf("\nstrings\n");
5360Sstevel@tonic-gate printed = 0;
5370Sstevel@tonic-gate }
5380Sstevel@tonic-gate
5390Sstevel@tonic-gate void
pr_string(char * infoname,char * capname,char * fullname,char * value)5400Sstevel@tonic-gate pr_string(char *infoname, char *capname, char *fullname, char *value)
5410Sstevel@tonic-gate {
5420Sstevel@tonic-gate char *evalue;
5430Sstevel@tonic-gate int badcapvalue;
5440Sstevel@tonic-gate size_t nlen, vlen;
5450Sstevel@tonic-gate
5460Sstevel@tonic-gate if (printing == pr_cap) {
5470Sstevel@tonic-gate if (restrictterm && !findcapname(capname, capstrs, ncapstrs))
5480Sstevel@tonic-gate return;
5490Sstevel@tonic-gate if (value)
5500Sstevel@tonic-gate value = infotocap(value, &badcapvalue);
5510Sstevel@tonic-gate }
5520Sstevel@tonic-gate
5530Sstevel@tonic-gate if (onecolumn) {
5540Sstevel@tonic-gate if (value == NULL)
5550Sstevel@tonic-gate switch ((int)printing) {
5560Sstevel@tonic-gate case (int)pr_terminfo:
5570Sstevel@tonic-gate (void) printf("\t%s@,\n", infoname);
5580Sstevel@tonic-gate break;
5590Sstevel@tonic-gate case (int)pr_cap:
5600Sstevel@tonic-gate (void) printf("\t:%s@:\\\n", capname);
5610Sstevel@tonic-gate caplen += 4 + strlen(capname);
5620Sstevel@tonic-gate break;
5630Sstevel@tonic-gate case (int)pr_longnames:
5640Sstevel@tonic-gate (void) printf(" %s@\n", fullname);
5650Sstevel@tonic-gate }
5660Sstevel@tonic-gate else
5670Sstevel@tonic-gate switch ((int)printing) {
5680Sstevel@tonic-gate case (int)pr_terminfo:
5690Sstevel@tonic-gate (void) printf("\t%s=", infoname);
5700Sstevel@tonic-gate tpr(stdout, value);
5710Sstevel@tonic-gate (void) printf(",\n");
5720Sstevel@tonic-gate break;
5730Sstevel@tonic-gate case (int)pr_cap:
5740Sstevel@tonic-gate (void) printf("\t:%s%s=",
5750Sstevel@tonic-gate badcapvalue ? "." : "", capname);
5760Sstevel@tonic-gate caplen += 3 + strlen(capname) +
5770Sstevel@tonic-gate (badcapvalue ? 1 : 0);
5780Sstevel@tonic-gate caplen += cpr(stdout, value);
5790Sstevel@tonic-gate (void) printf(":\\\n");
5800Sstevel@tonic-gate caplen += 1;
5810Sstevel@tonic-gate break;
5820Sstevel@tonic-gate case (int)pr_longnames:
5830Sstevel@tonic-gate (void) printf(" %s = '", fullname);
5840Sstevel@tonic-gate tpr(stdout, value);
5850Sstevel@tonic-gate (void) printf("'\n");
5860Sstevel@tonic-gate }
5870Sstevel@tonic-gate } else {
5880Sstevel@tonic-gate switch ((int)printing) {
5890Sstevel@tonic-gate case (int)pr_terminfo:
5900Sstevel@tonic-gate nlen = strlen(infoname);
5910Sstevel@tonic-gate break;
5920Sstevel@tonic-gate case (int)pr_cap:
5930Sstevel@tonic-gate nlen = strlen(capname);
5940Sstevel@tonic-gate if (badcapvalue)
5950Sstevel@tonic-gate nlen++;
5960Sstevel@tonic-gate break;
5970Sstevel@tonic-gate case (int)pr_longnames:
5980Sstevel@tonic-gate nlen = strlen(fullname);
5990Sstevel@tonic-gate }
6000Sstevel@tonic-gate if (value == NULL)
6010Sstevel@tonic-gate vlen = 1;
6020Sstevel@tonic-gate else
6030Sstevel@tonic-gate if (printing == pr_cap)
6040Sstevel@tonic-gate vlen = strlen(evalue = cexpand(value));
6050Sstevel@tonic-gate else
6060Sstevel@tonic-gate vlen = strlen(evalue = iexpand(value));
6070Sstevel@tonic-gate if ((printed > 0) && (printed + nlen + vlen + 1 > width)) {
6080Sstevel@tonic-gate switch ((int)printing) {
6090Sstevel@tonic-gate case (int)pr_terminfo:
6100Sstevel@tonic-gate case (int)pr_longnames:
6110Sstevel@tonic-gate (void) printf("\n");
6120Sstevel@tonic-gate break;
6130Sstevel@tonic-gate case (int)pr_cap:
6140Sstevel@tonic-gate (void) printf(":\\\n");
6150Sstevel@tonic-gate caplen += 1;
6160Sstevel@tonic-gate }
6170Sstevel@tonic-gate printed = 0;
6180Sstevel@tonic-gate }
6190Sstevel@tonic-gate if (printed == 0) {
6200Sstevel@tonic-gate switch ((int)printing) {
6210Sstevel@tonic-gate case (int)pr_terminfo:
6220Sstevel@tonic-gate (void) printf("\t");
6230Sstevel@tonic-gate printed = 8;
6240Sstevel@tonic-gate break;
6250Sstevel@tonic-gate case (int)pr_cap:
6260Sstevel@tonic-gate (void) printf("\t:");
6270Sstevel@tonic-gate printed = 9;
6280Sstevel@tonic-gate caplen += 2;
6290Sstevel@tonic-gate break;
6300Sstevel@tonic-gate case (int)pr_longnames:
6310Sstevel@tonic-gate (void) printf(" ");
6320Sstevel@tonic-gate printed = 2;
6330Sstevel@tonic-gate }
6340Sstevel@tonic-gate } else {
6350Sstevel@tonic-gate switch ((int)printing) {
6360Sstevel@tonic-gate case (int)pr_terminfo:
6370Sstevel@tonic-gate case (int)pr_longnames:
6380Sstevel@tonic-gate (void) printf(" ");
6390Sstevel@tonic-gate break;
6400Sstevel@tonic-gate case (int)pr_cap:
6410Sstevel@tonic-gate (void) printf(":");
6420Sstevel@tonic-gate caplen += 1;
6430Sstevel@tonic-gate }
6440Sstevel@tonic-gate printed++;
6450Sstevel@tonic-gate }
6460Sstevel@tonic-gate if (value == NULL) {
6470Sstevel@tonic-gate switch ((int)printing) {
6480Sstevel@tonic-gate case (int)pr_terminfo:
6490Sstevel@tonic-gate (void) printf("%s@,", infoname);
6500Sstevel@tonic-gate printed += nlen + 2;
6510Sstevel@tonic-gate break;
6520Sstevel@tonic-gate case (int)pr_cap:
6530Sstevel@tonic-gate (void) printf("%s@", capname);
6540Sstevel@tonic-gate printed += nlen + 1;
6550Sstevel@tonic-gate caplen += nlen + 1;
6560Sstevel@tonic-gate break;
6570Sstevel@tonic-gate case (int)pr_longnames:
6580Sstevel@tonic-gate (void) printf("%s@,", fullname);
6590Sstevel@tonic-gate printed += nlen + 2;
6600Sstevel@tonic-gate }
6610Sstevel@tonic-gate } else
6620Sstevel@tonic-gate switch ((int)printing) {
6630Sstevel@tonic-gate case (int)pr_terminfo:
6640Sstevel@tonic-gate (void) printf("%s=%s,", infoname,
6650Sstevel@tonic-gate evalue);
6660Sstevel@tonic-gate printed += nlen + vlen + 2;
6670Sstevel@tonic-gate break;
6680Sstevel@tonic-gate case (int)pr_cap:
6690Sstevel@tonic-gate if (badcapvalue) {
6700Sstevel@tonic-gate (void) printf(".");
6710Sstevel@tonic-gate caplen += 1;
6720Sstevel@tonic-gate }
6730Sstevel@tonic-gate (void) printf("%s=%s", capname,
6740Sstevel@tonic-gate evalue);
6750Sstevel@tonic-gate printed += nlen + vlen + 1;
6760Sstevel@tonic-gate caplen += nlen + vlen + 1;
6770Sstevel@tonic-gate break;
6780Sstevel@tonic-gate case (int)pr_longnames:
6790Sstevel@tonic-gate (void) printf("%s = '%s',", fullname,
6800Sstevel@tonic-gate evalue);
6810Sstevel@tonic-gate printed += nlen + vlen + 6;
6820Sstevel@tonic-gate }
6830Sstevel@tonic-gate }
6840Sstevel@tonic-gate }
6850Sstevel@tonic-gate
6860Sstevel@tonic-gate void
pr_sfooting(void)6870Sstevel@tonic-gate pr_sfooting(void)
6880Sstevel@tonic-gate {
6890Sstevel@tonic-gate if (onecolumn) {
6900Sstevel@tonic-gate if (printing == pr_cap)
6910Sstevel@tonic-gate (void) printf("\n");
6920Sstevel@tonic-gate } else {
6930Sstevel@tonic-gate if (printed > 0)
6940Sstevel@tonic-gate switch ((int)printing) {
6950Sstevel@tonic-gate case (int)pr_terminfo:
6960Sstevel@tonic-gate case (int)pr_longnames:
6970Sstevel@tonic-gate (void) printf("\n");
6980Sstevel@tonic-gate break;
6990Sstevel@tonic-gate case (int)pr_cap:
7000Sstevel@tonic-gate (void) printf(":\n");
7010Sstevel@tonic-gate caplen += 1;
7020Sstevel@tonic-gate }
7030Sstevel@tonic-gate }
7040Sstevel@tonic-gate if (caplen >= 1024) {
7050Sstevel@tonic-gate (void) fprintf(stderr, "%s: WARNING: termcap entry is too "
7060Sstevel@tonic-gate "long!\n", progname);
7070Sstevel@tonic-gate }
7080Sstevel@tonic-gate
7090Sstevel@tonic-gate if (printing == pr_longnames)
7100Sstevel@tonic-gate (void) printf("end of strings\n");
7110Sstevel@tonic-gate }
712