summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-05-10 08:22:50 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-05-10 08:22:50 +0000
commit27e948fd458b06c3a018d46f04599a874f43fd92 (patch)
treee369ed2a78f4d5393074804b71f136c84e9dfca5 /dir.c
parent192463c7a5525008a7bf95065261877eff79cf74 (diff)
regexp,range,squeeze
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/dir.c b/dir.c
index c12fd542bc..3ddcc8fdf9 100644
--- a/dir.c
+++ b/dir.c
@@ -345,12 +345,6 @@ has_magic(s, send)
return Qfalse;
}
-struct glob1_arg {
- void (*func)();
- char *basename;
- VALUE arg;
-};
-
static char*
extract_path(p, pend)
char *p, *pend;
@@ -412,6 +406,11 @@ glob(path, func, arg)
DIR *dirp;
struct dirent *dp;
+ struct d_link {
+ char *path;
+ struct d_link *next;
+ } *tmp, *link = 0;
+
base = extract_path(path, p);
if (path == p) dir = ".";
else dir = base;
@@ -424,27 +423,39 @@ glob(path, func, arg)
magic = extract_elem(p);
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
if (fnmatch(magic, dp->d_name, FNM_PERIOD|FNM_PATHNAME) == 0) {
- char *fix = ALLOC_N(char, strlen(base)+strlen(dp->d_name)+2);
+ char *fix = ALLOC_N(char, strlen(base)+NAMLEN(dp)+2);
- sprintf(fix, "%s%s%s", base, (p==path)?"":"/", dp->d_name);
+ sprintf(fix, "%s%s%s", base, (*base)?"/":"", dp->d_name);
if (!m) {
(*func)(fix, arg);
free(fix);
continue;
}
- stat(fix, &st); /* should success */
- if (S_ISDIR(st.st_mode)) {
- char *t = ALLOC_N(char, strlen(fix)+strlen(m)+2);
- sprintf(t, "%s%s", fix, m);
- glob(t, func, arg);
- free(t);
- }
- free(fix);
+ tmp = ALLOC(struct d_link);
+ tmp->path = fix;
+ tmp->next = link;
+ link = tmp;
}
}
closedir(dirp);
free(base);
free(magic);
+ while (link) {
+ stat(link->path, &st); /* should success */
+ if (S_ISDIR(st.st_mode)) {
+ int len = strlen(link->path);
+ int mlen = strlen(m);
+ char *t = ALLOC_N(char, len+mlen+1);
+
+ sprintf(t, "%s%s", link->path, m);
+ glob(t, func, arg);
+ free(t);
+ }
+ tmp = link;
+ link = link->next;
+ free(tmp->path);
+ free(tmp);
+ }
}
p = m;
}