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 */
31 #pragma ident "%Z%%M% %I% %E% SMI"
41 * get next parameter from s
43 * whsp -> pointer to use to return leading whitespace
44 * prm -> pointer to use to return token
46 * s -> pointer to next character
54 char rightq
; /* the right quote character */
61 while ((width
= mbtowc(&ch
, s
, MB_CUR_MAX
)) &&
62 iswspace(ch
) || (ch
== '\n')) {
63 if (whsp
!= (char *) NULL
)
70 if ( whsp
!= (char *) NULL
)
73 while ((width
= mbtowc(&ch
, s
, MB_CUR_MAX
)) && ch
) {
74 if (iswspace(ch
) || ch
== '\n' || ch
== '\0') {
76 return(prm
== beginning
? NULL
: s
);
80 if ((prm
== beginning
+ 1) && (*beginning
== '2'))
82 if ((prm
== beginning
+ 1) && (*beginning
== '1'))
84 if (prm
== beginning
) {
85 width
= mbtowc(&ch
, s
+1, MB_CUR_MAX
);
86 if ((ch
== '>') || (ch
== '&'))
95 if ((prm
== beginning
+ 1) && (*beginning
== '0'))
97 if (prm
== beginning
) {
98 width
= mbtowc(&ch
, s
+1, MB_CUR_MAX
);
113 if (prm
== beginning
)
123 if (prm
== beginning
) {
124 rightq
= ( *s
== '(' ? ')' : *s
);
126 (void) strncpy(prm
, s
, c
-s
+1);
128 if ( *(s
=c
) == rightq
)
142 return(prm
== beginning
? NULL
: s
);
146 * bal - get balanced quoted string
150 * Note: *s is the left quote
152 * pointer to the end of the quoted string
154 * If the string is not balanced, it returns a pointer to the
166 char l
; /* left quote character */
168 for (l
= *s
++; *s
; s
+=width
) {
169 width
= mbtowc(&ch
, s
, MB_CUR_MAX
);
172 break; /* this is the balanced end */
181 * split - split the name into parts:
182 * arg - original string
183 * sys - leading system name
184 * fwd - intermediate destinations, if not NULL, otherwise
185 * only split into two parts.
186 * file - filename part
190 split(arg
, sys
, fwd
, file
)
191 char *arg
, *sys
, *fwd
, *file
;
193 wchar_t *cl
, *cr
, *n
;
195 wchar_t wcbuf
[MAXFULLNAME
];
196 wchar_t tmpbuf
[MAXFULLNAME
];
197 wchar_t myname
[MAXFULLNAME
];
199 *sys
= *file
= NULLCHAR
;
200 if ( fwd
!= (char *) NULL
)
203 /* uux can use parentheses for output file names */
204 /* we'll check here until we can move it to uux */
205 if (EQUALS(Progname
,"uux") && (*arg
== LQUOTE
)) {
207 c
= bal(arg
++, RQUOTE
);
208 (void) strncpy(file
, arg
, c
-arg
);
209 file
[c
-arg
] = NULLCHAR
;
214 mbstowcs(myname
, Myname
, MAXFULLNAME
);
215 mbstowcs(wcbuf
, arg
, MAXFULLNAME
);
216 for (n
=wcbuf
;; n
=cl
+1) {
217 cl
= wcschr(n
, (wchar_t)'!');
220 (void) wcstombs(file
, n
, MAXFULLNAME
);
225 if (cl
== n
) /* leading ! */
227 if (WEQUALSN(myname
, n
, cl
- n
) && myname
[cl
- n
] == NULLCHAR
)
230 (void) wcsncpy(tmpbuf
, n
, cl
-n
);
231 tmpbuf
[cl
-n
] = NULLCHAR
;
232 (void) wcstombs(sys
, tmpbuf
, MAXFULLNAME
);
234 if (fwd
!= (char *) NULL
) {
235 if (cl
!= (cr
= wcsrchr(n
, (wchar_t)'!'))) {
236 /* more than one ! */
237 wcsncpy(tmpbuf
, cl
+1, cr
-cl
-1);
238 tmpbuf
[cr
-cl
-1] = NULL
;
239 (void) wcstombs(fwd
, tmpbuf
, MAXFULLNAME
);
245 (void) wcstombs(file
, cr
+1, MAXFULLNAME
);