diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-14 13:41:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-14 13:41:02 +0000 |
commit | 9d2b69a27306058af38a7e5c1b57dd419a57fd05 (patch) | |
tree | 0fbaa740a483519e42912ffb4fe74b36e4a6d90f | |
parent | ca32aea6a24d443434f1fa40b9091edc16ef03bf (diff) | |
download | ruby-9d2b69a27306058af38a7e5c1b57dd419a57fd05.tar.gz |
* dir.c (ruby_glob): glob function not using ruby exception system.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | dir.c | 87 | ||||
-rw-r--r-- | ruby.h | 7 | ||||
-rw-r--r-- | win32/win32.c | 6 |
4 files changed, 60 insertions, 44 deletions
@@ -1,3 +1,7 @@ +Wed Sep 14 22:40:26 2005 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * dir.c (ruby_glob): glob function not using ruby exception system. + Wed Sep 14 17:24:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp> * dir.c: changed `foo (*bar)_((boo))' to `foo (*bar)(boo)`. @@ -890,33 +890,38 @@ dir_s_rmdir(VALUE obj, VALUE dir) return INT2FIX(0); } +#define GLOB_VERBOSE (1 << (sizeof(int) * CHAR_BIT - 1)) +#define sys_warning(val) \ + ((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)(val), 0)) + /* System call with warning */ static int -do_stat(const char *path, struct stat *pst) +do_stat(const char *path, struct stat *pst, int flags) + { int ret = stat(path, pst); if (ret < 0 && errno != ENOENT) - rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)path, 0); + sys_warning(path); return ret; } static int -do_lstat(const char *path, struct stat *pst) +do_lstat(const char *path, struct stat *pst, int flags) { int ret = lstat(path, pst); if (ret < 0 && errno != ENOENT) - rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)path, 0); + sys_warning(path); return ret; } static DIR * -do_opendir(const char *path) +do_opendir(const char *path, int flags) { DIR *dirp = opendir(path); if (dirp == NULL && errno != ENOENT && errno != ENOTDIR) - rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)path, 0); + sys_warning(path); return dirp; } @@ -1118,19 +1123,7 @@ glob_func_caller(VALUE val) return Qnil; } -static int -glob_call_func(void (*func) (const char *, VALUE), const char *path, VALUE arg) -{ - int status; - struct glob_args args; - - args.func = func; - args.c = path; - args.v = arg; - - rb_protect(glob_func_caller, (VALUE)&args, &status); - return status; -} +#define glob_call_func(func, path, arg) (*func)(path, arg) static int glob_helper( @@ -1141,7 +1134,7 @@ glob_helper( struct glob_pattern **beg, struct glob_pattern **end, int flags, - void (*func) (const char *, VALUE), + int (*func)(const char *, VALUE), VALUE arg) { struct stat st; @@ -1176,7 +1169,7 @@ glob_helper( if (*path) { if (match_all && exist == UNKNOWN) { - if (do_lstat(path, &st) == 0) { + if (do_lstat(path, &st, flags) == 0) { exist = YES; isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO; } @@ -1186,7 +1179,7 @@ glob_helper( } } if (match_dir && isdir == UNKNOWN) { - if (do_stat(path, &st) == 0) { + if (do_stat(path, &st, flags) == 0) { exist = YES; isdir = S_ISDIR(st.st_mode) ? YES : NO; } @@ -1211,7 +1204,7 @@ glob_helper( if (magical || recursive) { struct dirent *dp; - DIR *dirp = do_opendir(*path ? path : "."); + DIR *dirp = do_opendir(*path ? path : ".", flags); if (dirp == NULL) return 0; for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { @@ -1221,7 +1214,7 @@ glob_helper( if (recursive && strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0 && fnmatch("*", dp->d_name, flags) == 0) { #ifndef _WIN32 - if (do_lstat(buf, &st) == 0) + if (do_lstat(buf, &st, flags) == 0) new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO; else new_isdir = NO; @@ -1293,7 +1286,7 @@ glob_helper( } static int -rb_glob2(const char *path, int flags, void (*func) (const char *, VALUE), VALUE arg) +ruby_glob0(const char *path, int flags, int (*func)(const char *, VALUE), VALUE arg) { struct glob_pattern *list; const char *root, *start; @@ -1301,10 +1294,6 @@ rb_glob2(const char *path, int flags, void (*func) (const char *, VALUE), VALUE int n; int status; - if (flags & FNM_CASEFOLD) { - rb_warn("Dir.glob() ignores File::FNM_CASEFOLD"); - } - start = root = path; #if defined DOSISH flags |= FNM_CASEFOLD; @@ -1328,28 +1317,42 @@ rb_glob2(const char *path, int flags, void (*func) (const char *, VALUE), VALUE return status; } -struct rb_glob_args { - void (*func)(const char*, VALUE); - VALUE arg; -}; +int +ruby_glob(const char *path, int flags, int (*func)(const char *, VALUE), VALUE arg) +{ + return ruby_glob0(path, flags & ~GLOB_VERBOSE, func, arg); +} -static void +static int rb_glob_caller(const char *path, VALUE a) { - struct rb_glob_args *args = (struct rb_glob_args *)a; - (*args->func)(path, args->arg); + int status; + struct glob_args *args = (struct glob_args *)a; + + args->c = path; + rb_protect(glob_func_caller, a, &status); + return status; } -void -rb_glob(const char *path, void (*func) (const char *, VALUE), VALUE arg) +static int +rb_glob2(const char *path, int flags, void (*func)(const char *, VALUE), VALUE arg) { - struct rb_glob_args args; - int status; + struct glob_args args; args.func = func; - args.arg = arg; - status = rb_glob2(path, 0, rb_glob_caller, (VALUE)&args); + args.v = arg; + if (flags & FNM_CASEFOLD) { + rb_warn("Dir.glob() ignores File::FNM_CASEFOLD"); + } + + return ruby_glob0(path, flags | GLOB_VERBOSE, rb_glob_caller, (VALUE)&args); +} + +void +rb_glob(const char *path, void (*func) (const char *, VALUE), VALUE arg) +{ + int status = rb_glob2(path, 0, func, arg); if (status) rb_jump_tag(status); } @@ -16,6 +16,9 @@ #if defined(__cplusplus) extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif #endif #include "config.h" @@ -490,6 +493,7 @@ struct RBignum { void rb_obj_infect(VALUE,VALUE); void rb_glob(const char*,void(*)(const char*,VALUE),VALUE); +int ruby_glob(const char*,int,int(*)(const char*,VALUE),VALUE); VALUE rb_define_class(const char*,VALUE); VALUE rb_define_module(const char*); @@ -735,6 +739,9 @@ void ruby_native_thread_kill(int); #endif #if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif } /* extern "C" { */ #endif diff --git a/win32/win32.c b/win32/win32.c index 53939d4ec9..e1468a1d8f 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1024,7 +1024,7 @@ typedef struct _NtCmdLineElement { #define NTMALLOC 0x2 // string in element was malloc'ed #define NTSTRING 0x4 // element contains a quoted string -static void +static int insert(const char *path, VALUE vinfo) { NtCmdLineElement *tmpcurr; @@ -1038,6 +1038,8 @@ insert(const char *path, VALUE vinfo) strcpy(tmpcurr->str, path); **tail = tmpcurr; *tail = &tmpcurr->next; + + return 0; } #ifdef HAVE_SYS_PARAM_H @@ -1062,7 +1064,7 @@ cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail) for (p = buf; *p; p = CharNext(p)) if (*p == '\\') *p = '/'; - rb_glob(buf, insert, (VALUE)&tail); + ruby_glob(buf, 0, insert, (VALUE)&tail); if (buf != buffer) free(buf); |