diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-11-25 09:03:08 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-11-25 09:03:08 +0000 |
commit | ebab487fcd7633038b9272ddbe31c268cda15723 (patch) | |
tree | e7880ae217a2a58dbe35bcf0f94744bc03805e08 /dir.c | |
parent | 8e48dc16e97a783a69f0972b4882ad2faae561ea (diff) |
19991125
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -557,9 +557,10 @@ glob(path, func, arg) if (*p == '/') p++; m = strchr(p, '/'); if (has_magic(p, m)) { - char *dir, *base, *magic; + char *dir, *base, *magic, *buf; DIR *dirp; struct dirent *dp; + int recursive = 0; struct d_link { char *path; @@ -570,24 +571,39 @@ glob(path, func, arg) if (path == p) dir = "."; else dir = base; + magic = extract_elem(p); + if (strcmp(magic, "**") == 0) { + recursive = 1; + buf = ALLOC_N(char, strlen(base)+strlen(m)+3); + sprintf(buf, "%s%s%s", base, (*base)?"":".", m); + glob(buf, func, arg); + free(buf); + } dirp = opendir(dir); if (dirp == NULL) { free(base); break; } - magic = extract_elem(p); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { + if (recursive) { + if (strcmp(".", dp->d_name) == 0 || strcmp("..", dp->d_name) == 0) + continue; + buf = ALLOC_N(char, strlen(base)+NAMLEN(dp)+strlen(m)+6); + sprintf(buf, "%s%s%s/**%s", base, (*base)?"/":"", dp->d_name, m); + glob(buf, func, arg); + free(buf); + continue; + } if (fnmatch(magic, dp->d_name, FNM_PERIOD|FNM_PATHNAME) == 0) { - char *fix = ALLOC_N(char, strlen(base)+NAMLEN(dp)+2); - - sprintf(fix, "%s%s%s", base, (*base)?"/":"", dp->d_name); + buf = ALLOC_N(char, strlen(base)+NAMLEN(dp)+2); + sprintf(buf, "%s%s%s", base, (*base)?"/":"", dp->d_name); if (!m) { - (*func)(fix, arg); - free(fix); + (*func)(buf, arg); + free(buf); continue; } tmp = ALLOC(struct d_link); - tmp->path = fix; + tmp->path = buf; tmp->next = link; link = tmp; } |