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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
32 * getword - extract one token from the string
33 * - token delimiter is white space if getall is FALSE
34 * - token delimiter is ':' or '\0' if getall is TRUE
37 getword(ptr
, size
, getall
)
38 register char *ptr
; /* pointer to the string to be scanned */
39 int *size
; /* *size = number of characters scanned */
40 int getall
; /* if TRUE, get all char until ':' or '\0' */
42 register char *optr
,c
;
44 static char word
[BUFSIZ
];
49 /* Skip all white spaces */
50 while (isspace(*ptr
)) {
56 /* Put all characters from here to next white space or ':' or '\0' */
57 /* into the word, up to the size of the word. */
58 for (optr
= word
,*optr
='\0';
59 *ptr
!= '\0' && *ptr
!= ':'; ptr
++,(*size
)++) {
65 /* If the character is quoted, analyze it. */
67 c
= quoted(ptr
,&qsize
);
72 /* If there is room, add this character to the word. */
73 if (optr
< &word
[BUFSIZ
] ) *optr
++ = c
;
76 /* skip trailing blanks if any*/
77 while (isspace(*ptr
)) {
82 /* Make sure the line is null terminated. */
87 /* "quoted" takes a quoted character, starting at the quote */
88 /* character, and returns a single character plus the size of */
89 /* the quote string. "quoted" recognizes the following as */
90 /* special, \n,\r,\v,\t,\b,\f as well as the \nnn notation. */
96 register char c
,*rptr
;
124 /* If this is a numeric string, take up to three characters of */
125 /* it as the value of the quoted character. */
126 if (*rptr
>= '0' && *rptr
<= '7') {
127 for (i
=0,c
=0; i
< 3;i
++) {
128 c
= c
*8 + (*rptr
- '0');
129 if (*++rptr
< '0' || *rptr
> '7') break;
133 /* If the character following the '\\' is a NULL, back up the */
134 /* ptr so that the NULL won't be missed. The sequence */
135 /* backslash null is essentually illegal. */
136 } else if (*rptr
== '\0') {
140 /* In all other cases the quoting does nothing. */
145 /* Compute the size of the quoted character. */
146 (*qsize
) = rptr
- ptr
;