static char *sccsid
= "@(#)glob.c 4.1 %G%";
char *globchars
= "`{[*?";
char *gpath
, *gpathp
, *lastgpathp
;
gpath
= agpath
; gpathp
= gpath
; *gpathp
= 0;
lastgpathp
= &gpath
[sizeof agpath
- 2];
ginit(agargv
); globcnt
= 0;
printf("glob entered: "); blkpr(v
); printf("\n");
noglob
= adrof("noglob") != 0;
nonomatch
= adrof("nonomatch") != 0;
globcnt
= noglob
| nonomatch
;
printf("glob done, globcnt=%d, gflag=%d: ", globcnt
, gflag
); blkpr(gargv
); printf("\n");
if (globcnt
== 0 && (gflag
&1)) {
blkfree(gargv
), gargv
= 0;
return (gargv
= copyblk(gargv
));
agargv
[0] = 0; gargv
= agargv
; sortbas
= agargv
; gargc
= 0;
printf("doing backp of %s\n", as
);
printf("backp done, acollect'ing\n");
for (i
= 0; i
< pargc
; i
++)
blkfree(pargv
), pargv
= 0;
printf("acollect done\n");
register int ogargc
= gargc
;
gpathp
= gpath
; *gpathp
= 0; globbed
= 0;
register char **p1
, **p2
, *c
;
char **Gvp
= &gargv
[gargc
];
if (strcmp(*p1
, *p2
) > 0)
c
= *p1
, *p1
= *p2
, *p2
= c
;
register char *sgpathp
, *oldcs
;
if (*cs
== '~' && gpathp
== gpath
) {
for (cs
++; letter(*cs
) || digit(*cs
) || *cs
== '-';)
if (!*cs
|| *cs
== '/') {
if (gpathp
!= gpath
+ 1) {
error("Unknown user: %s", gpath
+ 1);
strcpy(gpath
, gpath
+ 1);
strcpy(gpath
, value("home"));
while (!any(*cs
, globchars
)) {
else if (stat(gpath
, &stb
) >= 0) {
while (cs
> as
&& *cs
!= '/')
struct direct dirbuf
[BUFSIZ
/ sizeof (struct direct
)];
if (fstat(dirf
, &stb
) < 0)
while ((cnt
= read(dirf
, (char *) dirbuf
, sizeof dirbuf
)) >= sizeof dirbuf
[0]) {
register struct direct
*ep
= dirbuf
;
for (cnt
/= sizeof (struct direct
); cnt
> 0; cnt
--, ep
++) {
copdent(d_name
, ep
->d_name
);
if (match(d_name
, pattern
)) {
register char *to
, *from
;
register int cnt
= DIRSIZ
;
char restbuf
[BUFSIZ
+ 2];
register char *pe
, *pm
, *pl
;
char *lm
, savec
, *sgpathp
;
for (lm
= restbuf
; *p
!= '{'; *lm
++ = *p
++)
for (pe
= ++p
; *pe
; pe
++)
for (pe
++; *pe
&& *pe
!= ']'; pe
++)
for (pl
= pm
= p
; pm
<= pe
; pm
++)
switch (*pm
& (QUOTE
|TRIM
)) {
} else if (amatch(s
, restbuf
))
for (pm
++; *pm
&& *pm
!= ']'; pm
++)
if (*s
== '.' && *p
!= '.')
return (execbrc(p
- 1, s
- 1));
if (lc
<= scc
&& scc
<= *p
++)
if (stat(gpath
, &stb
) == 0 && isdir(stb
))
if (lc
<= scc
&& scc
<= *p
++)
gnleft
-= strlen(s1
) + strlen(s2
) + 1;
if (gnleft
<= 0 || ++gargc
>= GAVSIZ
)
error("Arguments too long");
gargv
[gargc
- 1] = strspl(s1
, s2
);
if (gpathp
>= lastgpathp
)
error("Pathname too long");
else if (eq(p
, "{") || eq(p
, "{}"))
gflag
|= c
== '{' ? 2 : 1;
bferr(cp ? "Ambiguous" : "No output");
xfree((char *)gargv
); gargv
= 0;
* Command substitute cp. If literal, then this is
* a substitution from a << redirection, and so we should
* not crunch blanks and tabs, separating words only at newlines.
char *apargv
[GAVSIZ
+ 2];
for (lp
= cp
; *lp
!= '`'; lp
++) {
printf("leaving dobackp\n");
return (pargv
= copyblk(pargv
));
for (rp
= lp
; *rp
&& *rp
!= '`'; rp
++)
printf("back from backeval\n");
int quoted
= (literal
|| (cp
[0] & QUOTE
)) ? QUOTE
: 0;
register int icnt
= 0, c
;
* We do the psave job to temporarily change the current job
* so that the following fork is considered a separate job.
* This is so that when backquotes are used in a
* builtin function that calls glob the "current job" is not corrupted.
* We only need one level of pushed jobs as long as we are sure to
* It would be nicer if we could integrate this redirection more
* with the routines in sh.sem.c by doing a fake execute on a builtin
* function that was piped out.
if (pfork(&faket
, -1) == 0) {
t
= syntax(paraml
.next
, ¶ml
, 0);
icnt
= read(pvec
[0], ip
, BUFSIZ
);
* Continue around the loop one
* more time, so that we can eat
* the last newline without terminating
if (!quoted
&& (c
== ' ' || c
== '\t'))
* Unless at end-of-file, we will form a new word
* here if there were characters in the word, or in
* any case when we take text literally. If
* we didn't make empty words here when literal was
* set then we would lose blank lines.
if (c
!= -1 && (cnt
|| literal
))
printf("done in backeval, pvec: %d %d\n", pvec
[0], pvec
[1]);
printf("also c = %c <%o>\n", c
, c
);
error("Too many words from ``");
pargv
[pargc
++] = savestr(pargs
);
printf("got word %s\n", pargv
[pargc
-1]);