4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
39 #pragma ident "%Z%%M% %I% %E% SMI"
43 #include <sys/types.h>
44 #include "curses_inc.h"
46 #include <signal.h> /* use this file to determine if this is SVR4.0 system */
48 #ifdef SIGSTOP /* SVR4.0 and beyond */
49 #define _ULIBTI "/usr/share/lib/terminfo"
51 #define _ULIBTI "/usr/lib/terminfo"
56 /* global variables */
57 static enum printtypes printing
= pr_none
;
58 static int onecolumn
= 0; /* print a single column */
59 static int width
= 60; /* width of multi-column printing */
60 static int restrictterm
= 1; /* restrict termcap names */
63 static int printed
= 0;
64 static size_t caplen
= 0;
67 pr_init(enum printtypes type
)
73 pr_onecolumn(int onoff
)
86 pr_caprestrict(int onoff
)
91 static char capbools
[] =
92 "ambsbwdadbeoeshchshzinkmmimsncnsosptulxbxnxoxsxt";
93 static int ncapbools
= sizeof (capbools
) / sizeof (capbools
[0]);
95 static char capnums
[] =
96 "codBdCdFdNdTknlipbsgug";
97 static int ncapnums
= sizeof (capnums
) / sizeof (capnums
[0]);
99 static char capstrs
[] =
100 "ALDCDLDOICLERISFSRUPaealasbcbtcdcechclcmcsctcvdcdldmdsedeifshoi1i2i"
101 "cifimipisk0k1k2k3k4k5k6k7k8k9kbkdkekhklkokrkskul0l1l2l3l4l5l6l7l"
102 "8l9ndnlpcr1r2r3rcrfrpscsesosrsttetitsucueupusvbvevivs";
103 static int ncapstrs
= sizeof (capstrs
) / sizeof (capstrs
[0]);
106 findcapname(char *capname
, char *caplist
, int listsize
)
108 int low
= 0, mid
, high
= listsize
- 2;
109 while (low
<= high
) {
110 mid
= (low
+ high
) / 4 * 2;
111 if (capname
[0] == caplist
[mid
]) {
112 if (capname
[1] == caplist
[mid
+ 1])
114 else if (capname
[1] < caplist
[mid
+ 1])
118 } else if (capname
[0] < caplist
[mid
])
125 * for (; *caplist; caplist += 2)
126 * if (caplist[0] == capname[0] && caplist[1] == capname[1])
133 * Print out the first line of an entry.
136 pr_heading(char *term
, char *synonyms
)
138 int do_print
= 0; /* Can we print the path of the file ? */
139 char buffer
[512]; /* Holds search pathname */
140 FILE *work_fp
; /* Used to try and open the files */
141 char tail
[4]; /* Used for terminfo pathname suffix */
142 char *terminfo
; /* The value of $TERMINFO */
146 * Try to obtain $TERMINFO
148 terminfo
= getenv("TERMINFO");
150 if (term
== (char *)0)
153 * Build the suffix for this device
161 * If we have it - use it, otherwise use /usr/share/lib/terminfo
164 if (terminfo
!= NULL
)
165 (void) sprintf(buffer
, "%s%s%s", terminfo
, tail
, term
);
167 (void) sprintf(buffer
, "%s%s%s", _ULIBTI
, tail
, term
);
170 * Attempt to open the file.
172 if ((work_fp
= fopen(buffer
, "rF")) == NULL
) {
174 * Open failed. If we were looking in /usr/share/lib/terminfo
175 * we are done, otherwise look there next.
177 if (strncmp(buffer
, _ULIBTI
, strlen(_ULIBTI
)) == 0) {
179 * We are done. Not in /usr/share/lib/terminfo,
180 * and $TERMINFO is not set.
182 (void) fprintf(stderr
, "Error: Term \"%s\" not "
183 "found in %s\n", term
, _ULIBTI
);
186 * Check /usr/share/lib/terminfo last. If this fails,
187 * all hope is lost as we know it is not in $TERMINFO.
189 (void) sprintf(buffer
, "%s%s%s", _ULIBTI
, tail
, term
);
191 if ((work_fp
= fopen(buffer
, "rF")) == NULL
) {
195 (void) fprintf(stderr
, "Error: Term \"%s\" not "
196 "found in %s or %s\n", term
, _ULIBTI
,
203 * If we found it - print the comment(after closing the file)
205 if (do_print
&& *term
) {
206 (void) fclose(work_fp
);
207 (void) printf("# Reconstructed via infocmp from file: "
211 switch ((int)printing
) {
212 case (int)pr_terminfo
:
213 (void) printf("%s,\n", synonyms
);
216 (void) printf("%s:\\\n", synonyms
);
217 caplen
= strlen(synonyms
) + 1;
219 case (int)pr_longnames
:
220 (void) printf("Terminal type %s\n", term
);
221 (void) printf(" %s\n", synonyms
);
229 if (printing
== pr_longnames
)
230 (void) printf("flags\n");
235 pr_boolean(char *infoname
, char *capname
, char *fullname
, int value
)
240 if (printing
== pr_cap
&& restrictterm
&&
241 !findcapname(capname
, capbools
, ncapbools
))
246 switch ((int)printing
) {
247 case (int)pr_terminfo
:
248 (void) printf("\t%s@,\n", infoname
);
251 (void) printf("\t:%s@:\\\n", capname
);
252 caplen
+= 4 + strlen(capname
);
254 case (int)pr_longnames
:
255 (void) printf(" %s@\n", fullname
);
258 switch ((int)printing
) {
259 case (int)pr_terminfo
:
260 (void) printf("\t%s,\n", infoname
);
263 (void) printf("\t:%s:\\\n", capname
);
264 caplen
+= 3 + strlen(capname
);
266 case (int)pr_longnames
:
267 (void) printf(" %s\n", fullname
);
270 switch ((int)printing
) {
271 case (int)pr_terminfo
: nlen
= strlen(infoname
);
273 case (int)pr_cap
: nlen
= strlen(capname
);
275 case (int)pr_longnames
:
276 nlen
= strlen(fullname
);
279 vlen
= (value
< 0) ? 1 : 0;
280 if ((printed
> 0) && (printed
+ nlen
+ vlen
+ 1 > width
)) {
281 switch ((int)printing
) {
282 case (int)pr_terminfo
:
283 case (int)pr_longnames
:
287 (void) printf(":\\\n");
293 switch ((int)printing
) {
294 case (int)pr_terminfo
:
299 (void) printf("\t:");
303 case (int)pr_longnames
:
308 switch ((int)printing
) {
309 case (int)pr_terminfo
:
310 case (int)pr_longnames
:
320 switch ((int)printing
) {
321 case (int)pr_terminfo
:
322 (void) printf("%s@,", infoname
);
326 (void) printf("%s@", capname
);
330 case (int)pr_longnames
:
331 (void) printf("%s@,", fullname
);
335 switch ((int)printing
) {
336 case (int)pr_terminfo
:
337 (void) printf("%s,", infoname
);
341 (void) printf("%s", capname
);
345 case (int)pr_longnames
:
346 (void) printf("%s,", fullname
);
355 if (!onecolumn
&& (printed
> 0))
356 switch ((int)printing
) {
357 case (int)pr_terminfo
:
358 case (int)pr_longnames
:
362 (void) printf(":\\\n");
370 if (printing
== pr_longnames
)
371 (void) printf("\nnumbers\n");
376 * Return the length of the number if it were printed out
377 * with %d. The number is guaranteed to be in the range
383 return (value
>= 10000 ? 5 :
391 pr_number(char *infoname
, char *capname
, char *fullname
, int value
)
396 if (printing
== pr_cap
&& restrictterm
&&
397 !findcapname(capname
, capnums
, ncapnums
))
402 switch ((int)printing
) {
403 case (int)pr_terminfo
:
404 (void) printf("\t%s@,\n", infoname
);
407 (void) printf("\t:%s@:\\\n", capname
);
408 caplen
+= 4 + strlen(capname
);
410 case (int)pr_longnames
:
411 (void) printf(" %s @\n", fullname
);
414 switch ((int)printing
) {
415 case (int)pr_terminfo
:
416 (void) printf("\t%s#%d,\n", infoname
,
420 (void) printf("\t:%s#%d:\\\n",
422 caplen
+= 4 + strlen(capname
) +
425 case (int)pr_longnames
:
426 (void) printf(" %s = %d\n", fullname
,
430 switch ((int)printing
) {
431 case (int)pr_terminfo
:
432 nlen
= strlen(infoname
);
435 nlen
= strlen(capname
);
437 case (int)pr_longnames
:
438 nlen
= strlen(fullname
);
441 vlen
= digitlen(value
);
442 if ((printed
> 0) && (printed
+ nlen
+ vlen
+ 2 > width
)) {
443 switch ((int)printing
) {
444 case (int)pr_terminfo
:
445 case (int)pr_longnames
:
449 (void) printf(":\\\n");
455 switch ((int)printing
) {
456 case (int)pr_terminfo
:
461 (void) printf("\t:");
465 case (int)pr_longnames
:
470 switch ((int)printing
) {
471 case (int)pr_terminfo
:
472 case (int)pr_longnames
:
482 switch ((int)printing
) {
483 case (int)pr_terminfo
:
484 (void) printf("%s@,", infoname
);
488 (void) printf("%s@", capname
);
492 case (int)pr_longnames
:
493 (void) printf("%s@,", fullname
);
497 switch ((int)printing
) {
498 case (int)pr_terminfo
:
499 (void) printf("%s#%d,", infoname
,
501 printed
+= nlen
+ vlen
+ 2;
504 (void) printf("%s#%d", capname
, value
);
505 printed
+= nlen
+ vlen
+ 1;
506 caplen
+= nlen
+ vlen
+ 1;
508 case (int)pr_longnames
:
509 (void) printf("%s = %d,", fullname
,
511 printed
+= nlen
+ vlen
+ 4;
519 if (!onecolumn
&& (printed
> 0))
520 switch ((int)printing
) {
521 case (int)pr_terminfo
:
522 case (int)pr_longnames
:
526 (void) printf(":\\\n");
534 if (printing
== pr_longnames
)
535 (void) printf("\nstrings\n");
540 pr_string(char *infoname
, char *capname
, char *fullname
, char *value
)
546 if (printing
== pr_cap
) {
547 if (restrictterm
&& !findcapname(capname
, capstrs
, ncapstrs
))
550 value
= infotocap(value
, &badcapvalue
);
555 switch ((int)printing
) {
556 case (int)pr_terminfo
:
557 (void) printf("\t%s@,\n", infoname
);
560 (void) printf("\t:%s@:\\\n", capname
);
561 caplen
+= 4 + strlen(capname
);
563 case (int)pr_longnames
:
564 (void) printf(" %s@\n", fullname
);
567 switch ((int)printing
) {
568 case (int)pr_terminfo
:
569 (void) printf("\t%s=", infoname
);
571 (void) printf(",\n");
574 (void) printf("\t:%s%s=",
575 badcapvalue
? "." : "", capname
);
576 caplen
+= 3 + strlen(capname
) +
577 (badcapvalue
? 1 : 0);
578 caplen
+= cpr(stdout
, value
);
579 (void) printf(":\\\n");
582 case (int)pr_longnames
:
583 (void) printf(" %s = '", fullname
);
585 (void) printf("'\n");
588 switch ((int)printing
) {
589 case (int)pr_terminfo
:
590 nlen
= strlen(infoname
);
593 nlen
= strlen(capname
);
597 case (int)pr_longnames
:
598 nlen
= strlen(fullname
);
603 if (printing
== pr_cap
)
604 vlen
= strlen(evalue
= cexpand(value
));
606 vlen
= strlen(evalue
= iexpand(value
));
607 if ((printed
> 0) && (printed
+ nlen
+ vlen
+ 1 > width
)) {
608 switch ((int)printing
) {
609 case (int)pr_terminfo
:
610 case (int)pr_longnames
:
614 (void) printf(":\\\n");
620 switch ((int)printing
) {
621 case (int)pr_terminfo
:
626 (void) printf("\t:");
630 case (int)pr_longnames
:
635 switch ((int)printing
) {
636 case (int)pr_terminfo
:
637 case (int)pr_longnames
:
647 switch ((int)printing
) {
648 case (int)pr_terminfo
:
649 (void) printf("%s@,", infoname
);
653 (void) printf("%s@", capname
);
657 case (int)pr_longnames
:
658 (void) printf("%s@,", fullname
);
662 switch ((int)printing
) {
663 case (int)pr_terminfo
:
664 (void) printf("%s=%s,", infoname
,
666 printed
+= nlen
+ vlen
+ 2;
673 (void) printf("%s=%s", capname
,
675 printed
+= nlen
+ vlen
+ 1;
676 caplen
+= nlen
+ vlen
+ 1;
678 case (int)pr_longnames
:
679 (void) printf("%s = '%s',", fullname
,
681 printed
+= nlen
+ vlen
+ 6;
690 if (printing
== pr_cap
)
694 switch ((int)printing
) {
695 case (int)pr_terminfo
:
696 case (int)pr_longnames
:
700 (void) printf(":\n");
704 if (caplen
>= 1024) {
705 (void) fprintf(stderr
, "%s: WARNING: termcap entry is too "
706 "long!\n", progname
);
709 if (printing
== pr_longnames
)
710 (void) printf("end of strings\n");