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 1995 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 */
30 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/types.h>
44 * globals (file name generation)
46 * "*" in params matches r.e ".*"
47 * "?" in params matches r.e. "."
48 * "[...]" in params matches character class
49 * "[...a-z...]" in params matches a through z.
52 static void addg(unsigned char *, unsigned char *, unsigned char *,
54 void makearg(struct argnod
*);
57 expand(unsigned char *as
, int rcnt
)
62 unsigned char *rescan
= 0;
63 unsigned char *slashsav
= 0;
64 unsigned char *s
, *cs
;
65 unsigned char *s2
= 0;
66 struct argnod
*schain
= gchain
;
71 if (trapnote
& SIGSET
)
75 * check for meta chars
84 if ((len
= mbtowc(&wc
, (char *)cs
, MB_LEN_MAX
)) <= 0) {
86 wc
= (unsigned char)*cs
;
129 s
= (unsigned char *)nullstr
;
131 } else if (*--cs
== '/') {
134 s
= (unsigned char *)"/";
137 * push trimmed copy of directory prefix
148 if ((dirf
= opendir(*s
? (char *)s
: (char *)".")) != 0)
151 /* Let s point to original string because it will be trimmed later */
156 slashsav
= cs
++; /* remember where first slash in as is */
158 /* check for rescan */
164 do /* find next / in as */
173 while ((e
= readdir(dirf
)) && (trapnote
& SIGSET
) == 0) {
174 if (e
->d_name
[0] == '.' && *cs
!= '.')
177 if (gmatch(e
->d_name
, cs
)) {
178 addg(s
, (unsigned char *)e
->d_name
, rescan
,
183 (void) closedir(dirf
);
186 struct argnod
*rchain
;
193 count
+= expand(rchain
->argval
,
195 rchain
= rchain
->argnxt
;
208 addg(unsigned char *as1
, unsigned char *as2
, unsigned char *as3
,
211 unsigned char *s1
, *s2
;
216 s2
= locstak() + BYTESPERWORD
;
225 * Restore first slash before the first metacharacter
234 /* add matched entries, plus extra \\ to escape \\'s */
237 if ((len
= mbtowc(&wc
, (char *)s1
, MB_LEN_MAX
)) <= 0) {
239 wc
= (unsigned char)*s1
;
257 if ((s2
+ len
) >= brkend
)
272 while (*s2
++ = *++s1
);
274 makearg((struct argnod
*)endstak(s2
));
278 makearg(struct argnod
*args
)
280 args
->argnxt
= gchain
;