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"
56 * misc processing requests
71 switch (i
= cbits(getch())) {
72 case 'r': /*right adj, left ragged*/
75 case 'l': /*left adj, right ragged*/
76 admod
= ad
= 0; /*same as casena*/
78 case 'c': /*centered adj*/
92 admod
= (i
- '0') / 2;
154 if (skip() || ismot(i
= getch()) || cbits(i
) == ' ' || cbits(i
) == '\n') {
158 return(i
& BYTEMASK
);
272 i
= max(hnumb(&in
), 0);
293 i
= max(hnumb(&ll
), INCH
/ 10);
310 i
= max(hnumb(<
), 0);
325 i
= max(hnumb(&in
), 0);
343 i
= max(inumb(&ls
), 1);
360 i
= max(hnumb(&po
), 0);
377 if ((i
= vnumb(&pl
)) == 0)
378 pl
= 11 * INCH
; /*11in*/
381 if (numtab
[NL
].val
> pl
)
400 if ((k
= findn(i
)) != NTRAP
) {
404 for (k
= 0; k
< NTRAP
; k
++)
409 errprint(gettext("cannot plant trap."));
429 for (k
= 0; k
< NTRAP
; k
++)
450 for (k
= 0; k
< NTRAP
; k
++)
451 if ((nlist
[k
] == i
) && (mlist
[k
] != 0))
464 i
= max(inumb(&numtab
[PN
].val
), 0);
485 if ((i
= inumb(&numtab
[PN
].val
)) < 0)
509 errprint(gettext("User Abort"));
510 for (i
= 0; i
< NTM
- 2; )
511 if ((tmbuf
[i
++] = getch()) == '\n')
516 if (ab
) /* truncate output */
517 obufp
= obuf
; /* should be a function in n2.c */
519 fdprintf(stderr
, "%s", tmbuf
);
534 if (dip
->nls
|| trap
)
576 if ((a
< 0) || (a
>= *p
))
615 nxev
= evlist
[--evi
];
624 if ((nxev
>= NEV
) || (nxev
< 0) || (evi
>= EVLSZ
)) {
626 errprint(gettext("cannot do ev."));
639 extern tchar corebuf
[];
640 *(struct env
*)&corebuf
[ev
* sizeof(env
)/sizeof(tchar
)] = env
;
641 env
= *(struct env
*)&corebuf
[nxev
* sizeof(env
)/sizeof(tchar
)];
644 lseek(ibf
, ev
* (long)sizeof(env
), 0);
645 write(ibf
, (char *) & env
, sizeof(env
));
646 lseek(ibf
, nxev
* (long)sizeof(env
), 0);
647 read(ibf
, (char *) & env
, sizeof(env
));
671 errprint(gettext("if-else overflow."));
697 if ((cbits(i
= getch())) == '!') {
712 if (!(numtab
[PN
].val
& 01))
716 if (numtab
[PN
].val
& 01)
740 while ((cbits(i
= getch())) == ' ')
742 if (cbits(i
) == LEFT
)
774 case '{': i
= LEFT
; break;
775 case '}': i
= RIGHT
; break;
776 case '\n': i
= 'x'; break;
780 if (i
== LEFT
) eatblk(1);
781 } while ((!inblk
&& (i
!= '\n')) || (inblk
&& (i
!= RIGHT
)));
796 int savapts
, savapts1
, savfont
, savfont1
, savpts
, savpts1
;
810 while ((j
= cbits(i
= getch()))!=delim
&& j
!='\n' && sp
<&string
[1280-1])
812 if (sp
>= string
+ 1280) {
813 errprint(gettext("too-long string compare."));
830 while ((j
= cbits(i
= getch())) != delim
&& j
!= '\n') {
865 fdprintf(stderr
, "\007"); /*bell*/
868 fdprintf(stderr
, "%s:", nextf
);
870 fdprintf(stderr
, "\007"); /*bell*/
876 pushi(NBLIST
*BLK
, PAIR('r','d'));
893 if (read(0, &onechar
, 1) == 1) {
912 if ((n
= mbtowc(&twc
, mbbuf1
, MB_CUR_MAX
)) <= 0) {
913 if (mbbuf1p
>= mbbuf1
+ MB_CUR_MAX
) {
914 i
&= ~(MBMASK
| CSMASK
);
929 if ((col_index
= wcwidth(twc
)) < 0)
932 setcsbits(i
, col_index
);
954 eschar
= chget('\\');
974 tabtab
[0] = nonumb
= 0;
975 for (i
= 0; ((i
< (NTAB
- 1)) && !nonumb
); i
++) {
978 tabtab
[i
] = max(hnumb(&tabtab
[max(i
-1,0)]), 0) & TABMASK
;
987 default: /*includes L*/
1004 i
= vnumb((int *)0);
1007 if (i
> (j
= findt1())) {
1027 while ((i
= cbits(k
=getch())) != '\n') {
1030 if (ismot(k
= getch()))
1032 if ((j
= cbits(k
)) == '\n')
1061 if (ul
&& (i
== 0)) {
1084 if (skip() || !(i
= getrq()) || i
== 'S' || (j
= findft(i
)) == -1)
1085 ulfont
= ULFONT
; /*default underline position*/
1107 if (!nonumb
&& (itmac
= getrq()))
1128 i
= max(hnumb((int *)0), 0);
1149 if ((i
= getrq()) == 0)
1151 numtab
[findr(i
)].val
= j
;
1163 if ((i
= vnumb((int *)0)) < 0)
1179 if (sv
<= findt1()) {
1201 i
= inumb(&numtab
[LN
].val
);
1203 numtab
[LN
].val
= max(i
, 0);
1237 nn
= max(atoi(), 1);
1256 * The following routines are concerned with setting terminal options.
1257 * The manner of doing this differs between research/Berkeley systems
1258 * and UNIX System V systems (i.e. DOCUMENTER'S WORKBENCH)
1259 * The distinction is controlled by the #define'd variable USG,
1260 * which must be set by System V users.
1266 #define ECHO_USG (ECHO | ECHOE | ECHOK | ECHONL)
1270 struct sgttyb ttys
[2];
1273 int ttysave
[2] = {-1, -1};
1276 save_tty() /*save any tty settings that may be changed*/
1280 if (ioctl(0, TCGETA
, &ttys
) >= 0)
1281 ttysave
[0] = ttys
.c_lflag
;
1283 if (gtty(0, &ttys
[0]) >= 0)
1284 ttysave
[0] = ttys
[0].sg_flags
;
1285 if (gtty(1, &ttys
[1]) >= 0)
1286 ttysave
[1] = ttys
[1].sg_flags
;
1294 restore_tty() /*restore tty settings from beginning*/
1297 if (ttysave
[0] != -1) {
1299 ttys
.c_lflag
= ttysave
[0];
1300 ioctl(0, TCSETAW
, &ttys
);
1302 ttys
[0].sg_flags
= ttysave
[0];
1305 if (ttysave
[1] != -1) {
1306 ttys
[1].sg_flags
= ttysave
[1];
1316 set_tty() /*this replaces the use of bset and breset*/
1319 #ifndef USG /*for research/BSD only, reset CRMOD*/
1320 if (ttysave
[1] == -1)
1322 if (ttysave
[1] != -1) {
1323 ttys
[1].sg_flags
&= ~CRMOD
;
1333 echo_off() /*turn off ECHO for .rd in "-q" mode*/
1335 if (ttysave
[0] == -1)
1339 ttys
.c_lflag
&= ~ECHO_USG
;
1340 ioctl(0, TCSETAW
, &ttys
);
1342 ttys
[0].sg_flags
&= ~ECHO
;
1352 echo_on() /*restore ECHO after .rd in "-q" mode*/
1354 if (ttysave
[0] == -1)
1358 ttys
.c_lflag
|= ECHO_USG
;
1359 ioctl(0, TCSETAW
, &ttys
);
1361 ttys
[0].sg_flags
|= ECHO
;