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]
24 * Copyright 2000 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
41 static int readb(struct fileblk
*, int, int);
43 /* ======== character handling for command lines ======== */
48 unsigned int c
, d
, cc
;
49 struct argnod
*arg
= (struct argnod
*)locstak();
50 unsigned char *argp
= arg
->argval
;
51 unsigned char *oldargp
;
60 while (c
= nextwc(), space(c
)) /* skipc() */
65 while ((c
= readwc()) != NL
&& c
!= EOF
);
70 break; /* out of comment - white space loop */
80 while ((c
= readwc()) && c
!= LITERAL
){
82 * quote each character within
89 /* Pick up rest of multibyte character */
95 *argp
++ = (unsigned char)c
;
98 if (argp
== oldargp
) { /* null argument - '' */
100 * Word will be represented by quoted null
101 * in macro.c if necessary
126 if ((cc
= readwc()) == 0) {
148 if ((c
= nextwc()) == 0) {
160 if (c
== 0 || c
== d
)
165 * don't interpret quoted
169 if ((cc
= readwc()) == 0) {
185 } while ((c
= nextwc(), !eofmeta(c
)));
186 argp
= endstak(argp
);
187 if (!letter(arg
->argval
[0]))
191 if (arg
->argval
[1] == 0 &&
192 (d
= arg
->argval
[0], digit(d
)) &&
193 (c
== '>' || c
== '<'))
197 }else{ /* check for reserved words */
198 if (reserv
== FALSE
||
199 (wdval
= syslook(arg
->argval
,
200 reserved
, no_reserved
)) == 0) {
203 /* set arg for reserved words too */
206 }else if (dipchar(c
)){
207 if ((d
= nextwc()) == c
)
212 if ((d
= nextwc()) == '-')
226 if ((wdval
= c
) == EOF
)
228 if (iopend
&& eolchar(c
))
230 struct ionod
*tmp_iopend
;
240 unsigned int skipwc()
244 while (c
= nextwc(), space(c
))
249 unsigned int nextwc()
254 if ((d
= readwc()) == ESCAPE
) {
255 if ((c
= readwc()) == NL
) {
264 unsigned char *readw(d
)
267 static unsigned char c
[MULTI_BYTE_MAX
+ 1];
276 length
= wctomb((char *)c
, d
);
278 c
[0] = (unsigned char)d
;
291 int mbmax
= MB_CUR_MAX
;
295 c
= peekn
& 0x7fffffff;
300 c
= peekc
& 0x7fffffff;
307 if (f
->fend
> f
->fnxt
) {
309 * something in buffer
315 goto retry
; /* = c = readc(); */
316 if (estabf(*f
->feval
++))
320 if (flags
& readpr
&& standin
->fstak
== 0)
327 if (isascii(c
= (unsigned char)*f
->fnxt
)) {
330 if (flags
& readpr
&& standin
->fstak
== 0)
337 for (i
= 1; i
<= mbmax
; i
++) {
339 if ((rest
= f
->fend
- f
->fnxt
) < i
) {
341 * not enough bytes available
342 * f->fsiz could be BUFFERSIZE or 1
343 * since mbmax is enough smaller than BUFFERSIZE,
344 * this loop won't overrun the f->fbuf buffer.
347 (f
->fsiz
== 1) ? 1 : (f
->fsiz
- rest
),
352 mlen
= mbtowc(&c
, (char *)f
->fnxt
, i
);
359 * enough bytes available but cannot be converted to
362 c
= (unsigned char)*f
->fnxt
;
368 if (flags
& readpr
&& standin
->fstak
== 0)
375 if (f
->feof
|| f
->fdes
< 0){
381 if (readb(f
, f
->fsiz
, 0) <= 0){
382 if (f
->fdes
!= input
|| !isatty(input
)) {
394 readb(struct fileblk
*f
, int toread
, int rest
)
401 * copies the remaining 'rest' bytes from f->fnxt
404 (void) memcpy(f
->fbuf
, f
->fnxt
, rest
);
406 f
->fend
= f
->fnxt
+ rest
;
409 if (f
->fbuf
[rest
- 1] == '\n') {
411 * if '\n' found, it should be
412 * a bondary of multibyte char.
420 if (trapnote
& SIGSET
) {
423 } else if ((trapnote
& TRAPSET
) && (rwait
> 0)) {
428 } while ((len
= read(f
->fdes
, f
->fbuf
+ rest
, toread
)) < 0 && trapnote
);
430 * if child sets O_NDELAY or O_NONBLOCK on stdin
431 * and exited then turn the modes off and retry
434 if (((flags
& intflg
) ||
435 ((flags
& oneflg
) == 0 && isatty(input
) &&
436 (flags
& stdflg
))) &&
437 ((fflags
= fcntl(f
->fdes
, F_GETFL
, 0)) & O_NDELAY
)) {
439 fcntl(f
->fdes
, F_SETFL
, fflags
);
442 } else if (len
< 0) {
443 if (errno
== EAGAIN
) {
444 fflags
= fcntl(f
->fdes
, F_GETFL
, 0);
445 fflags
&= ~O_NONBLOCK
;
446 fcntl(f
->fdes
, F_SETFL
, fflags
);
452 f
->fend
= f
->fnxt
+ (len
+ rest
);
454 f
->endoff
= len
+ rest
;