4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
50 #include <sys/types.h>
61 struct t t
; /* terminal characteristics */
67 char xchname
[4 * (NROFFCHARS
-_SPECCHAR_ST
)]; /* hy, em, etc. */
68 short xchtab
[NROFFCHARS
-_SPECCHAR_ST
]; /* indexes into chname[] */
70 char *chname
= xchname
;
71 short *chtab
= xchtab
;
78 int nfonts
= 4; /* R, I, B, S */
80 /* these characters are used as various signals or values
81 * in miscellaneous places.
82 * values are set in specnames in t10.c
109 extern char *skipstr(), *getstr(), *getint();
110 extern char *setbrk();
114 strcat(termtab
, devname
);
115 if ((fd
= open(termtab
, 0)) < 0) {
116 errprint(gettext("cannot open %s"), termtab
);
121 codestr
= setbrk((int) stbuf
.st_size
);
123 nread
= read(fd
, codestr
, (int) stbuf
.st_size
);
127 p
= skipstr(p
); /* skip over type, could check */
128 p
= skipstr(p
); p
= getint(p
, &t
.bset
);
129 p
= skipstr(p
); p
= getint(p
, &t
.breset
);
130 p
= skipstr(p
); p
= getint(p
, &t
.Hor
);
131 p
= skipstr(p
); p
= getint(p
, &t
.Vert
);
132 p
= skipstr(p
); p
= getint(p
, &t
.Newline
);
133 p
= skipstr(p
); p
= getint(p
, &t
.Char
);
134 p
= skipstr(p
); p
= getint(p
, &t
.Em
);
135 p
= skipstr(p
); p
= getint(p
, &t
.Halfline
);
136 p
= skipstr(p
); p
= getint(p
, &t
.Adj
);
137 p
= skipstr(p
); p
= getstr(p
, t
.twinit
= p
);
138 p
= skipstr(p
); p
= getstr(p
, t
.twrest
= p
);
139 p
= skipstr(p
); p
= getstr(p
, t
.twnl
= p
);
140 p
= skipstr(p
); p
= getstr(p
, t
.hlr
= p
);
141 p
= skipstr(p
); p
= getstr(p
, t
.hlf
= p
);
142 p
= skipstr(p
); p
= getstr(p
, t
.flr
= p
);
143 p
= skipstr(p
); p
= getstr(p
, t
.bdon
= p
);
144 p
= skipstr(p
); p
= getstr(p
, t
.bdoff
= p
);
145 p
= skipstr(p
); p
= getstr(p
, t
.iton
= p
);
146 p
= skipstr(p
); p
= getstr(p
, t
.itoff
= p
);
147 p
= skipstr(p
); p
= getstr(p
, t
.ploton
= p
);
148 p
= skipstr(p
); p
= getstr(p
, t
.plotoff
= p
);
149 p
= skipstr(p
); p
= getstr(p
, t
.up
= p
);
150 p
= skipstr(p
); p
= getstr(p
, t
.down
= p
);
151 p
= skipstr(p
); p
= getstr(p
, t
.right
= p
);
152 p
= skipstr(p
); p
= getstr(p
, t
.left
= p
);
155 if (strcmp(check
, "charset") != 0) {
156 errprint(gettext("device table apparently curdled"));
160 for (i
= 0; i
< _SPECCHAR_ST
; i
++)
161 t
.width
[i
] = 1; /* default widths */
164 /* this ought to be a pointer array and in place in codestr */
165 cp
= chname
+ 1; /* bug if starts at 0, in setch */
166 while (p
< codestr
+ nread
) {
167 while (*p
== ' ' || *p
== '\t' || *p
== '\n')
169 if (i
+ _SPECCHAR_ST
>= NROFFCHARS
) {
170 errprint(gettext("too many names in charset for %s"),
174 chtab
[i
] = cp
- chname
; /* index, not pointer */
175 *cp
++ = *p
++; /* 2-char names */
178 while (*p
== ' ' || *p
== '\t')
180 t
.width
[i
+_SPECCHAR_ST
] = *p
++ - '0';
181 while (*p
== ' ' || *p
== '\t')
184 p
= getstr(p
, p
); /* compress string */
193 for (i
= 0; i
< 16; i
++)
194 tabtab
[i
] = dtab
* (i
+ 1);
199 ll
= ll1
= lt
= lt1
= LL
;
200 smnt
= nfonts
= 5; /* R I B BI S */
201 specnames(); /* install names like "hyphen", etc. */
208 char *skipstr(s
) /* skip over leading space plus string */
211 while (*s
== ' ' || *s
== '\t' || *s
== '\n')
213 while (*s
!= ' ' && *s
!= '\t' && *s
!= '\n')
219 char *getstr(s
, t
) /* find next string in s, copy to t */
224 while (*s
== ' ' || *s
== '\t' || *s
== '\n')
231 if (quote
&& *s
== '"') {
235 if (!quote
&& (*s
== ' ' || *s
== '\t' || *s
== '\n'))
241 if (isdigit((unsigned char)s
[0]) &&
242 isdigit((unsigned char)s
[1]) &&
243 isdigit((unsigned char)s
[2])) {
244 *t
++ = (s
[0]-'0')<<6 | (s
[1]-'0')<<3 | s
[2]-'0';
246 } else if (isdigit((unsigned char)s
[0])) {
248 } else if (*s
== 'b') {
250 } else if (*s
== 'n') {
252 } else if (*s
== 'r') {
254 } else if (*s
== 't') {
266 char *getint(s
, pn
) /* find integer at s */
272 while (*s
== ' ' || *s
== '\t' || *s
== '\n')
274 base
= (*s
== '0') ? 8 : 10;
276 while (isdigit((unsigned char)*s
))
277 *pn
= base
* *pn
+ *s
++ - '0';
308 for (i
= 0; spnames
[i
].n
; i
++)
309 *spnames
[i
].n
= findch(spnames
[i
].v
);
311 c_isalnum
= NROFFCHARS
;
318 findch(s
) /* find char s in chname */
323 for (i
= 0; chtab
[i
] != 0; i
++)
324 if (strcmp(s
, &chname
[chtab
[i
]]) == 0)
325 return(i
+ _SPECCHAR_ST
);
335 if (t
.twrest
) /* has ptinit() been done yet? */
353 if (olinep
>= &oline
[LNSIZE
])
355 if (cbits(i
) != '\n')
358 lead
+= dip
->blss
+ lss
- t
.Newline
;
361 if (olinep
> oline
) {
396 static int oxfont
= FT
; /* start off in roman */
398 for (q
= oline
; q
< olinep
; q
++) {
410 if ((k
= cbits(i
)) <= 040) {
426 if (multi_locale
&& ((k
& MBMASK
) || (k
& CSMASK
))) {
428 while ((*q
& MBMASK1
) && (cnt
+ 1 < (int)MB_CUR_MAX
)) {
432 if ((cnt
&& !(*q
& CSMASK
)) || (*q
& MBMASK1
)) {
438 phyw
= w
= t
.Char
* csi_width
[cs(i
)];
442 phyw
= w
= t
.Char
* t
.width
[k
];
460 xfont
= (fbits(*q
) % NFONT
); /* for invalid code */
462 if (xfont
!= oxfont
) {
463 if (oxfont
== ulfont
|| oxfont
== BIFONT
)
467 if (xfont
== ulfont
|| xfont
== BIFONT
)
473 if ((xfont
== ulfont
|| xfont
== BIFONT
) && !(*t
.iton
& 0377)) {
474 for (j
= w
/ t
.Char
; j
> 0; j
--)
476 for (j
= w
/ t
.Char
; j
> 0; j
--)
479 if ((j
= bdtab
[xfont
]) && !(*t
.bdon
& 0377))
482 j
= 1; /* number of overstrikes for bold */
483 if (k
< 128) { /* ordinary ascii */
491 } else if (multi_locale
&& (k
& CSMASK
)) {
492 for (qq
= q
- cnt
; qq
<= q
;)
495 for (jj
= cnt
+ 1; jj
> 0; jj
--)
497 for (qq
= q
- cnt
; qq
<= q
;)
500 } else if (k
< 256) {
502 * Invalid character for C locale or
503 * non-printable 8-bit single byte
504 * character such as <no-break-sp>
514 } else if (k
>= nchtab
+ _SPECCHAR_ST
) {
515 oput(k
- nchtab
- _SPECCHAR_ST
);
518 codep
= t
.codetab
[k
-_SPECCHAR_ST
];
519 while (*codep
!= 0) {
524 if (*codep
== '%') /* escape */
527 if (*codep
== '\033')
529 else if (*codep
!= '\b')
530 for (j
= oj
; --j
> 0; ) {
539 for (j
= phyw
/ t
.Char
; j
> 0; j
--)
555 if ((*k
& 0377) == 0200)
558 if (*k
== '%') { /* quote char within plot mode */
560 } else if (*k
& 0200) {
572 if ((i
= *k
& 037) == 0) { /* 2nd 0200 turns it off */
606 /* if(!esct)i = t.flr; else i = "\0";*/
611 k
= lead
/ t
.Newline
;
612 lead
= lead
% t
.Newline
;
617 k
= lead
/ t
.Halfline
;
618 lead
= lead
% t
.Halfline
;
621 } else { /* no half-line forward, not at line begining */
622 k
= lead
/ t
.Newline
;
623 lead
= lead
% t
.Newline
;
639 while ((dt
= dtab
- (iesct
% dtab
)) <= esc
) {
652 if ((*t
.ploton
& 0377) && (esc
|| lead
)) {