mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
ca32aea6a2
commit
9d2b69a273
4 changed files with 61 additions and 45 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>
|
Wed Sep 14 17:24:22 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||||
|
|
||||||
* dir.c: changed `foo (*bar)_((boo))' to `foo (*bar)(boo)`.
|
* dir.c: changed `foo (*bar)_((boo))' to `foo (*bar)(boo)`.
|
||||||
|
|
89
dir.c
89
dir.c
|
@ -890,33 +890,38 @@ dir_s_rmdir(VALUE obj, VALUE dir)
|
||||||
return INT2FIX(0);
|
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 */
|
/* System call with warning */
|
||||||
static int
|
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);
|
int ret = stat(path, pst);
|
||||||
if (ret < 0 && errno != ENOENT)
|
if (ret < 0 && errno != ENOENT)
|
||||||
rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)path, 0);
|
sys_warning(path);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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);
|
int ret = lstat(path, pst);
|
||||||
if (ret < 0 && errno != ENOENT)
|
if (ret < 0 && errno != ENOENT)
|
||||||
rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)path, 0);
|
sys_warning(path);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DIR *
|
static DIR *
|
||||||
do_opendir(const char *path)
|
do_opendir(const char *path, int flags)
|
||||||
{
|
{
|
||||||
DIR *dirp = opendir(path);
|
DIR *dirp = opendir(path);
|
||||||
if (dirp == NULL && errno != ENOENT && errno != ENOTDIR)
|
if (dirp == NULL && errno != ENOENT && errno != ENOTDIR)
|
||||||
rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)path, 0);
|
sys_warning(path);
|
||||||
|
|
||||||
return dirp;
|
return dirp;
|
||||||
}
|
}
|
||||||
|
@ -1118,19 +1123,7 @@ glob_func_caller(VALUE val)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
#define glob_call_func(func, path, arg) (*func)(path, arg)
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
glob_helper(
|
glob_helper(
|
||||||
|
@ -1141,7 +1134,7 @@ glob_helper(
|
||||||
struct glob_pattern **beg,
|
struct glob_pattern **beg,
|
||||||
struct glob_pattern **end,
|
struct glob_pattern **end,
|
||||||
int flags,
|
int flags,
|
||||||
void (*func) (const char *, VALUE),
|
int (*func)(const char *, VALUE),
|
||||||
VALUE arg)
|
VALUE arg)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -1176,7 +1169,7 @@ glob_helper(
|
||||||
|
|
||||||
if (*path) {
|
if (*path) {
|
||||||
if (match_all && exist == UNKNOWN) {
|
if (match_all && exist == UNKNOWN) {
|
||||||
if (do_lstat(path, &st) == 0) {
|
if (do_lstat(path, &st, flags) == 0) {
|
||||||
exist = YES;
|
exist = YES;
|
||||||
isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;
|
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 (match_dir && isdir == UNKNOWN) {
|
||||||
if (do_stat(path, &st) == 0) {
|
if (do_stat(path, &st, flags) == 0) {
|
||||||
exist = YES;
|
exist = YES;
|
||||||
isdir = S_ISDIR(st.st_mode) ? YES : NO;
|
isdir = S_ISDIR(st.st_mode) ? YES : NO;
|
||||||
}
|
}
|
||||||
|
@ -1211,7 +1204,7 @@ glob_helper(
|
||||||
|
|
||||||
if (magical || recursive) {
|
if (magical || recursive) {
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
DIR *dirp = do_opendir(*path ? path : ".");
|
DIR *dirp = do_opendir(*path ? path : ".", flags);
|
||||||
if (dirp == NULL) return 0;
|
if (dirp == NULL) return 0;
|
||||||
|
|
||||||
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
|
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
|
if (recursive && strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0
|
||||||
&& fnmatch("*", dp->d_name, flags) == 0) {
|
&& fnmatch("*", dp->d_name, flags) == 0) {
|
||||||
#ifndef _WIN32
|
#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;
|
new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;
|
||||||
else
|
else
|
||||||
new_isdir = NO;
|
new_isdir = NO;
|
||||||
|
@ -1293,7 +1286,7 @@ glob_helper(
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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;
|
struct glob_pattern *list;
|
||||||
const char *root, *start;
|
const char *root, *start;
|
||||||
|
@ -1301,10 +1294,6 @@ rb_glob2(const char *path, int flags, void (*func) (const char *, VALUE), VALUE
|
||||||
int n;
|
int n;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (flags & FNM_CASEFOLD) {
|
|
||||||
rb_warn("Dir.glob() ignores File::FNM_CASEFOLD");
|
|
||||||
}
|
|
||||||
|
|
||||||
start = root = path;
|
start = root = path;
|
||||||
#if defined DOSISH
|
#if defined DOSISH
|
||||||
flags |= FNM_CASEFOLD;
|
flags |= FNM_CASEFOLD;
|
||||||
|
@ -1328,28 +1317,42 @@ rb_glob2(const char *path, int flags, void (*func) (const char *, VALUE), VALUE
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct rb_glob_args {
|
int
|
||||||
void (*func)(const char*, VALUE);
|
ruby_glob(const char *path, int flags, int (*func)(const char *, VALUE), VALUE arg)
|
||||||
VALUE arg;
|
{
|
||||||
};
|
return ruby_glob0(path, flags & ~GLOB_VERBOSE, func, arg);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
rb_glob_caller(const char *path, VALUE a)
|
rb_glob_caller(const char *path, VALUE a)
|
||||||
{
|
{
|
||||||
struct rb_glob_args *args = (struct rb_glob_args *)a;
|
int status;
|
||||||
(*args->func)(path, args->arg);
|
struct glob_args *args = (struct glob_args *)a;
|
||||||
|
|
||||||
|
args->c = path;
|
||||||
|
rb_protect(glob_func_caller, a, &status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
rb_glob2(const char *path, int flags, void (*func)(const char *, VALUE), VALUE arg)
|
||||||
|
{
|
||||||
|
struct glob_args args;
|
||||||
|
|
||||||
|
args.func = func;
|
||||||
|
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
|
void
|
||||||
rb_glob(const char *path, void (*func) (const char *, VALUE), VALUE arg)
|
rb_glob(const char *path, void (*func) (const char *, VALUE), VALUE arg)
|
||||||
{
|
{
|
||||||
struct rb_glob_args args;
|
int status = rb_glob2(path, 0, func, arg);
|
||||||
int status;
|
|
||||||
|
|
||||||
args.func = func;
|
|
||||||
args.arg = arg;
|
|
||||||
status = rb_glob2(path, 0, rb_glob_caller, (VALUE)&args);
|
|
||||||
|
|
||||||
if (status) rb_jump_tag(status);
|
if (status) rb_jump_tag(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
ruby.h
7
ruby.h
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#if 0
|
||||||
|
} /* satisfy cc-mode */
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -490,6 +493,7 @@ struct RBignum {
|
||||||
void rb_obj_infect(VALUE,VALUE);
|
void rb_obj_infect(VALUE,VALUE);
|
||||||
|
|
||||||
void rb_glob(const char*,void(*)(const char*,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_class(const char*,VALUE);
|
||||||
VALUE rb_define_module(const char*);
|
VALUE rb_define_module(const char*);
|
||||||
|
@ -735,6 +739,9 @@ void ruby_native_thread_kill(int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
#if 0
|
||||||
|
{ /* satisfy cc-mode */
|
||||||
|
#endif
|
||||||
} /* extern "C" { */
|
} /* extern "C" { */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1024,7 +1024,7 @@ typedef struct _NtCmdLineElement {
|
||||||
#define NTMALLOC 0x2 // string in element was malloc'ed
|
#define NTMALLOC 0x2 // string in element was malloc'ed
|
||||||
#define NTSTRING 0x4 // element contains a quoted string
|
#define NTSTRING 0x4 // element contains a quoted string
|
||||||
|
|
||||||
static void
|
static int
|
||||||
insert(const char *path, VALUE vinfo)
|
insert(const char *path, VALUE vinfo)
|
||||||
{
|
{
|
||||||
NtCmdLineElement *tmpcurr;
|
NtCmdLineElement *tmpcurr;
|
||||||
|
@ -1038,6 +1038,8 @@ insert(const char *path, VALUE vinfo)
|
||||||
strcpy(tmpcurr->str, path);
|
strcpy(tmpcurr->str, path);
|
||||||
**tail = tmpcurr;
|
**tail = tmpcurr;
|
||||||
*tail = &tmpcurr->next;
|
*tail = &tmpcurr->next;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SYS_PARAM_H
|
#ifdef HAVE_SYS_PARAM_H
|
||||||
|
@ -1062,7 +1064,7 @@ cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail)
|
||||||
for (p = buf; *p; p = CharNext(p))
|
for (p = buf; *p; p = CharNext(p))
|
||||||
if (*p == '\\')
|
if (*p == '\\')
|
||||||
*p = '/';
|
*p = '/';
|
||||||
rb_glob(buf, insert, (VALUE)&tail);
|
ruby_glob(buf, 0, insert, (VALUE)&tail);
|
||||||
if (buf != buffer)
|
if (buf != buffer)
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue