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 2005 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 */
40 * get next parameter from s
42 * whsp -> pointer to use to return leading whitespace
43 * prm -> pointer to use to return token
45 * s -> pointer to next character
53 char rightq
; /* the right quote character */
60 while ((width
= mbtowc(&ch
, s
, MB_CUR_MAX
)) &&
61 iswspace(ch
) || (ch
== '\n')) {
62 if (whsp
!= (char *) NULL
)
69 if ( whsp
!= (char *) NULL
)
72 while ((width
= mbtowc(&ch
, s
, MB_CUR_MAX
)) && ch
) {
73 if (iswspace(ch
) || ch
== '\n' || ch
== '\0') {
75 return(prm
== beginning
? NULL
: s
);
79 if ((prm
== beginning
+ 1) && (*beginning
== '2'))
81 if ((prm
== beginning
+ 1) && (*beginning
== '1'))
83 if (prm
== beginning
) {
84 width
= mbtowc(&ch
, s
+1, MB_CUR_MAX
);
85 if ((ch
== '>') || (ch
== '&'))
94 if ((prm
== beginning
+ 1) && (*beginning
== '0'))
96 if (prm
== beginning
) {
97 width
= mbtowc(&ch
, s
+1, MB_CUR_MAX
);
112 if (prm
== beginning
)
122 if (prm
== beginning
) {
123 rightq
= ( *s
== '(' ? ')' : *s
);
125 (void) strncpy(prm
, s
, c
-s
+1);
127 if ( *(s
=c
) == rightq
)
141 return(prm
== beginning
? NULL
: s
);
145 * bal - get balanced quoted string
149 * Note: *s is the left quote
151 * pointer to the end of the quoted string
153 * If the string is not balanced, it returns a pointer to the
165 char l
; /* left quote character */
167 for (l
= *s
++; *s
; s
+=width
) {
168 width
= mbtowc(&ch
, s
, MB_CUR_MAX
);
171 break; /* this is the balanced end */
180 * split - split the name into parts:
181 * arg - original string
182 * sys - leading system name
183 * fwd - intermediate destinations, if not NULL, otherwise
184 * only split into two parts.
185 * file - filename part
189 split(arg
, sys
, fwd
, file
)
190 char *arg
, *sys
, *fwd
, *file
;
192 wchar_t *cl
, *cr
, *n
;
194 wchar_t wcbuf
[MAXFULLNAME
];
195 wchar_t tmpbuf
[MAXFULLNAME
];
196 wchar_t myname
[MAXFULLNAME
];
198 *sys
= *file
= NULLCHAR
;
199 if ( fwd
!= (char *) NULL
)
202 /* uux can use parentheses for output file names */
203 /* we'll check here until we can move it to uux */
204 if (EQUALS(Progname
,"uux") && (*arg
== LQUOTE
)) {
206 c
= bal(arg
++, RQUOTE
);
207 (void) strncpy(file
, arg
, c
-arg
);
208 file
[c
-arg
] = NULLCHAR
;
213 mbstowcs(myname
, Myname
, MAXFULLNAME
);
214 mbstowcs(wcbuf
, arg
, MAXFULLNAME
);
215 for (n
=wcbuf
;; n
=cl
+1) {
216 cl
= wcschr(n
, (wchar_t)'!');
219 (void) wcstombs(file
, n
, MAXFULLNAME
);
224 if (cl
== n
) /* leading ! */
226 if (WEQUALSN(myname
, n
, cl
- n
) && myname
[cl
- n
] == NULLCHAR
)
229 (void) wcsncpy(tmpbuf
, n
, cl
-n
);
230 tmpbuf
[cl
-n
] = NULLCHAR
;
231 (void) wcstombs(sys
, tmpbuf
, MAXFULLNAME
);
233 if (fwd
!= (char *) NULL
) {
234 if (cl
!= (cr
= wcsrchr(n
, (wchar_t)'!'))) {
235 /* more than one ! */
236 wcsncpy(tmpbuf
, cl
+1, cr
-cl
-1);
237 tmpbuf
[cr
-cl
-1] = NULLCHAR
;
238 (void) wcstombs(fwd
, tmpbuf
, MAXFULLNAME
);
244 (void) wcstombs(file
, cr
+1, MAXFULLNAME
);