mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* dir.c (glob_helper): get rid of using String. [ruby-dev:26180]
* dir.c (push_braces): should skip balanced braces. * eval.c (ruby_options), win32/win32.c (NtInitialize): move argument intialization back. [ruby-dev:26180] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2866bd642f
commit
a5f61654e9
4 changed files with 100 additions and 73 deletions
11
ChangeLog
11
ChangeLog
|
|
@ -1,6 +1,15 @@
|
||||||
|
Wed May 18 23:39:09 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* dir.c (glob_helper): get rid of using String. [ruby-dev:26180]
|
||||||
|
|
||||||
|
* dir.c (push_braces): should skip balanced braces.
|
||||||
|
|
||||||
|
* eval.c (ruby_options), win32/win32.c (NtInitialize): move argument
|
||||||
|
intialization back. [ruby-dev:26180]
|
||||||
|
|
||||||
Tue May 17 15:31:31 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
Tue May 17 15:31:31 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
||||||
|
|
||||||
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): should
|
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): should
|
||||||
break the loop if the socket reached to EOF. [ruby-talk:142285]
|
break the loop if the socket reached to EOF. [ruby-talk:142285]
|
||||||
|
|
||||||
Tue May 17 11:52:18 2005 NAKAMURA Usaku <usa@ruby-lang.org>
|
Tue May 17 11:52:18 2005 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
|
||||||
143
dir.c
143
dir.c
|
|
@ -877,8 +877,8 @@ remove_backslashes(p)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct glob_args {
|
struct glob_args {
|
||||||
void (*func) _((VALUE, VALUE));
|
void (*func) _((const char*, VALUE));
|
||||||
VALUE c;
|
const char *c;
|
||||||
VALUE v;
|
VALUE v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -889,18 +889,15 @@ glob_func_caller(val)
|
||||||
VALUE val;
|
VALUE val;
|
||||||
{
|
{
|
||||||
struct glob_args *args = (struct glob_args *)val;
|
struct glob_args *args = (struct glob_args *)val;
|
||||||
VALUE path = args->c;
|
|
||||||
|
|
||||||
OBJ_TAINT(path);
|
(*args->func)(args->c, args->v);
|
||||||
RSTRING(path)->len = strlen(RSTRING(path)->ptr);
|
|
||||||
(*args->func)(path, args->v);
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
glob_call_func(func, path, arg)
|
glob_call_func(func, path, arg)
|
||||||
void (*func) _((VALUE, VALUE));
|
void (*func) _((const char*, VALUE));
|
||||||
VALUE path;
|
const char *path;
|
||||||
VALUE arg;
|
VALUE arg;
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
@ -914,39 +911,53 @@ glob_call_func(func, path, arg)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int glob_helper(VALUE path, char *sub, int flags, void (*func)(VALUE,VALUE), VALUE arg);
|
static int glob_helper _((const char *path, const char *sub, int flags, void (*func)(const char *,VALUE), VALUE arg));
|
||||||
|
|
||||||
static int
|
static int
|
||||||
glob_helper(pv, sub, flags, func, arg)
|
glob_helper(path, sub, flags, func, arg)
|
||||||
VALUE pv;
|
const char *path;
|
||||||
char *sub;
|
const char *sub;
|
||||||
int flags;
|
int flags;
|
||||||
void (*func) _((VALUE, VALUE));
|
void (*func) _((const char *, VALUE));
|
||||||
VALUE arg;
|
VALUE arg;
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *p, *m, *path;
|
const char *p, *m;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
char *buf = 0;
|
||||||
|
char *newpath = 0;
|
||||||
|
|
||||||
StringValue(pv);
|
|
||||||
path = RSTRING(pv)->ptr;
|
|
||||||
p = sub ? sub : path;
|
p = sub ? sub : path;
|
||||||
if (!has_magic(p, 0, flags)) {
|
if (!has_magic(p, 0, flags)) {
|
||||||
|
if (
|
||||||
#if defined DOSISH
|
#if defined DOSISH
|
||||||
remove_backslashes(path);
|
TRUE
|
||||||
#else
|
#else
|
||||||
if (!(flags & FNM_NOESCAPE)) remove_backslashes(p);
|
!(flags & FNM_NOESCAPE)
|
||||||
#endif
|
#endif
|
||||||
|
)
|
||||||
|
{
|
||||||
|
newpath = strdup(path);
|
||||||
|
if (sub) {
|
||||||
|
p = newpath + (sub - path);
|
||||||
|
remove_backslashes(newpath + (sub - path));
|
||||||
|
sub = p;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
remove_backslashes(newpath);
|
||||||
|
p = path = newpath;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (lstat(path, &st) == 0) {
|
if (lstat(path, &st) == 0) {
|
||||||
status = glob_call_func(func, pv, arg);
|
status = glob_call_func(func, path, arg);
|
||||||
if (status) return status;
|
|
||||||
}
|
}
|
||||||
else if (errno != ENOENT) {
|
else if (errno != ENOENT) {
|
||||||
/* In case stat error is other than ENOENT and
|
/* In case stat error is other than ENOENT and
|
||||||
we may want to know what is wrong. */
|
we may want to know what is wrong. */
|
||||||
rb_sys_warning(path);
|
rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)path, 0);
|
||||||
}
|
}
|
||||||
return 0;
|
xfree(newpath);
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (p && !status) {
|
while (p && !status) {
|
||||||
|
|
@ -954,7 +965,6 @@ glob_helper(pv, sub, flags, func, arg)
|
||||||
m = strchr(p, '/');
|
m = strchr(p, '/');
|
||||||
if (has_magic(p, m, flags)) {
|
if (has_magic(p, m, flags)) {
|
||||||
char *dir, *base, *magic;
|
char *dir, *base, *magic;
|
||||||
VALUE buf;
|
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
int recursive = 0;
|
int recursive = 0;
|
||||||
|
|
@ -970,7 +980,8 @@ glob_helper(pv, sub, flags, func, arg)
|
||||||
|
|
||||||
magic = extract_elem(p);
|
magic = extract_elem(p);
|
||||||
if (stat(dir, &st) < 0) {
|
if (stat(dir, &st) < 0) {
|
||||||
if (errno != ENOENT) rb_sys_warning(dir);
|
if (errno != ENOENT)
|
||||||
|
rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)dir, 0);
|
||||||
free(base);
|
free(base);
|
||||||
free(magic);
|
free(magic);
|
||||||
break;
|
break;
|
||||||
|
|
@ -979,14 +990,14 @@ glob_helper(pv, sub, flags, func, arg)
|
||||||
if (m && strcmp(magic, "**") == 0) {
|
if (m && strcmp(magic, "**") == 0) {
|
||||||
int n = strlen(base);
|
int n = strlen(base);
|
||||||
recursive = 1;
|
recursive = 1;
|
||||||
buf = rb_str_new(0, n+strlen(m)+3);
|
REALLOC_N(buf, char, n+strlen(m)+3);
|
||||||
sprintf(RSTRING(buf)->ptr, "%s%s", base, *base ? m : m+1);
|
sprintf(buf, "%s%s", base, *base ? m : m+1);
|
||||||
status = glob_helper(buf, RSTRING(buf)->ptr+n, flags, func, arg);
|
status = glob_helper(buf, buf+n, flags, func, arg);
|
||||||
if (status) goto finalize;
|
if (status) goto finalize;
|
||||||
}
|
}
|
||||||
dirp = opendir(dir);
|
dirp = opendir(dir);
|
||||||
if (dirp == NULL) {
|
if (dirp == NULL) {
|
||||||
rb_sys_warning(dir);
|
rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)dir, 0);
|
||||||
free(base);
|
free(base);
|
||||||
free(magic);
|
free(magic);
|
||||||
break;
|
break;
|
||||||
|
|
@ -1010,14 +1021,15 @@ glob_helper(pv, sub, flags, func, arg)
|
||||||
continue;
|
continue;
|
||||||
if (fnmatch("*", dp->d_name, flags) != 0)
|
if (fnmatch("*", dp->d_name, flags) != 0)
|
||||||
continue;
|
continue;
|
||||||
buf = rb_str_new(0, strlen(base)+NAMLEN(dp)+strlen(m)+6);
|
REALLOC_N(buf, char, strlen(base)+NAMLEN(dp)+strlen(m)+6);
|
||||||
sprintf(RSTRING(buf)->ptr, "%s%s%s", base, (BASE) ? "/" : "", dp->d_name);
|
sprintf(buf, "%s%s%s", base, (BASE) ? "/" : "", dp->d_name);
|
||||||
if (lstat(RSTRING(buf)->ptr, &st) < 0) {
|
if (lstat(buf, &st) < 0) {
|
||||||
if (errno != ENOENT) rb_sys_warning(RSTRING(buf)->ptr);
|
if (errno != ENOENT)
|
||||||
|
rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)buf, 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
char *t = RSTRING(buf)->ptr+strlen(RSTRING(buf)->ptr);
|
char *t = buf+strlen(buf);
|
||||||
strcpy(t, "/**");
|
strcpy(t, "/**");
|
||||||
strcpy(t+3, m);
|
strcpy(t+3, m);
|
||||||
status = glob_helper(buf, t, flags, func, arg);
|
status = glob_helper(buf, t, flags, func, arg);
|
||||||
|
|
@ -1027,15 +1039,16 @@ glob_helper(pv, sub, flags, func, arg)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (fnmatch(magic, dp->d_name, flags) == 0) {
|
if (fnmatch(magic, dp->d_name, flags) == 0) {
|
||||||
buf = rb_str_new(0, strlen(base)+NAMLEN(dp)+2);
|
REALLOC_N(buf, char, strlen(base)+NAMLEN(dp)+2);
|
||||||
sprintf(RSTRING(buf)->ptr, "%s%s%s", base, (BASE) ? "/" : "", dp->d_name);
|
sprintf(buf, "%s%s%s", base, (BASE) ? "/" : "", dp->d_name);
|
||||||
if (!m) {
|
if (!m) {
|
||||||
status = glob_call_func(func, buf, arg);
|
status = glob_call_func(func, buf, arg);
|
||||||
if (status) break;
|
if (status) break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tmp = ALLOC(struct d_link);
|
tmp = ALLOC(struct d_link);
|
||||||
tmp->path = strdup(RSTRING(buf)->ptr);
|
tmp->path = buf;
|
||||||
|
buf = 0;
|
||||||
*tail = tmp;
|
*tail = tmp;
|
||||||
tail = &tmp->next;
|
tail = &tmp->next;
|
||||||
}
|
}
|
||||||
|
|
@ -1053,13 +1066,13 @@ glob_helper(pv, sub, flags, func, arg)
|
||||||
int len = strlen(link->path);
|
int len = strlen(link->path);
|
||||||
int mlen = strlen(m);
|
int mlen = strlen(m);
|
||||||
|
|
||||||
buf = rb_str_new(0, len+mlen+1);
|
REALLOC_N(buf, char, len+mlen+1);
|
||||||
sprintf(RSTRING(buf)->ptr, "%s%s", link->path, m);
|
sprintf(buf, "%s%s", link->path, m);
|
||||||
status = glob_helper(buf, RSTRING(buf)->ptr+len, flags, func, arg);
|
status = glob_helper(buf, buf+len, flags, func, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_sys_warning(link->path);
|
rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)link->path, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmp = link;
|
tmp = link;
|
||||||
|
|
@ -1072,14 +1085,16 @@ glob_helper(pv, sub, flags, func, arg)
|
||||||
}
|
}
|
||||||
p = m;
|
p = m;
|
||||||
}
|
}
|
||||||
|
xfree(buf);
|
||||||
|
xfree(newpath);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rb_glob2(path, flags, func, arg)
|
rb_glob2(path, flags, func, arg)
|
||||||
VALUE path;
|
const char *path;
|
||||||
int flags;
|
int flags;
|
||||||
void (*func) _((VALUE, VALUE));
|
void (*func) _((const char *, VALUE));
|
||||||
VALUE arg;
|
VALUE arg;
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
@ -1112,7 +1127,7 @@ rb_glob(path, func, arg)
|
||||||
|
|
||||||
args.func = func;
|
args.func = func;
|
||||||
args.arg = arg;
|
args.arg = arg;
|
||||||
status = rb_glob2(rb_str_new2(path), 0, rb_glob_caller, (VALUE)&args);
|
status = rb_glob2(path, 0, rb_glob_caller, (VALUE)&args);
|
||||||
|
|
||||||
if (status) rb_jump_tag(status);
|
if (status) rb_jump_tag(status);
|
||||||
}
|
}
|
||||||
|
|
@ -1128,23 +1143,23 @@ rb_globi(path, func, arg)
|
||||||
|
|
||||||
args.func = func;
|
args.func = func;
|
||||||
args.arg = arg;
|
args.arg = arg;
|
||||||
status = rb_glob2(rb_str_new2(path), FNM_CASEFOLD, rb_glob_caller, (VALUE)&args);
|
status = rb_glob2(path, FNM_CASEFOLD, rb_glob_caller, (VALUE)&args);
|
||||||
|
|
||||||
if (status) rb_jump_tag(status);
|
if (status) rb_jump_tag(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
push_pattern(path, ary)
|
push_pattern(path, ary)
|
||||||
VALUE path;
|
const char *path;
|
||||||
VALUE ary;
|
VALUE ary;
|
||||||
{
|
{
|
||||||
rb_ary_push(ary, path);
|
rb_ary_push(ary, rb_tainted_str_new2(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
push_globs(ary, s, flags)
|
push_globs(ary, s, flags)
|
||||||
VALUE ary;
|
VALUE ary;
|
||||||
VALUE s;
|
const char *s;
|
||||||
int flags;
|
int flags;
|
||||||
{
|
{
|
||||||
return rb_glob2(s, flags, push_pattern, ary);
|
return rb_glob2(s, flags, push_pattern, ary);
|
||||||
|
|
@ -1152,17 +1167,18 @@ push_globs(ary, s, flags)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
push_braces(ary, str, flags)
|
push_braces(ary, str, flags)
|
||||||
VALUE ary, str;
|
VALUE ary;
|
||||||
|
const char *str;
|
||||||
int flags;
|
int flags;
|
||||||
{
|
{
|
||||||
VALUE buf;
|
char *buf = 0;
|
||||||
char *b;
|
char *b;
|
||||||
const char *s, *p, *t;
|
const char *s, *p, *t;
|
||||||
const char *lbrace, *rbrace;
|
const char *lbrace, *rbrace;
|
||||||
int nest = 0;
|
int nest = 0;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
s = p = RSTRING(str)->ptr;
|
s = p = str;
|
||||||
lbrace = rbrace = 0;
|
lbrace = rbrace = 0;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (*p == '{') {
|
if (*p == '{') {
|
||||||
|
|
@ -1187,11 +1203,16 @@ push_braces(ary, str, flags)
|
||||||
t = p + 1;
|
t = p + 1;
|
||||||
for (p = t; *p!='}' && *p!=','; p++) {
|
for (p = t; *p!='}' && *p!=','; p++) {
|
||||||
/* skip inner braces */
|
/* skip inner braces */
|
||||||
if (*p == '{') while (*p!='}') p++;
|
if (*p == '{') {
|
||||||
|
nest = 1;
|
||||||
|
while (*++p != '}' || --nest) {
|
||||||
|
if (*p == '{') nest++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buf = rb_str_new(0, len+1);
|
REALLOC_N(buf, char, len+1);
|
||||||
memcpy(RSTRING(buf)->ptr, s, lbrace-s);
|
memcpy(buf, s, lbrace-s);
|
||||||
b = RSTRING(buf)->ptr + (lbrace-s);
|
b = buf + (lbrace-s);
|
||||||
memcpy(b, t, p-t);
|
memcpy(b, t, p-t);
|
||||||
strcpy(b+(p-t), rbrace+1);
|
strcpy(b+(p-t), rbrace+1);
|
||||||
status = push_braces(ary, buf, flags);
|
status = push_braces(ary, buf, flags);
|
||||||
|
|
@ -1201,6 +1222,7 @@ push_braces(ary, str, flags)
|
||||||
else {
|
else {
|
||||||
status = push_globs(ary, str, flags);
|
status = push_globs(ary, str, flags);
|
||||||
}
|
}
|
||||||
|
xfree(buf);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
@ -1212,9 +1234,7 @@ rb_push_glob(str, flags)
|
||||||
VALUE str;
|
VALUE str;
|
||||||
int flags;
|
int flags;
|
||||||
{
|
{
|
||||||
const char *p, *pend;
|
const char *p, *pend, *buf;
|
||||||
volatile VALUE buf;
|
|
||||||
char *t;
|
|
||||||
int nest, maxnest;
|
int nest, maxnest;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
int noescape = flags & FNM_NOESCAPE;
|
int noescape = flags & FNM_NOESCAPE;
|
||||||
|
|
@ -1226,20 +1246,17 @@ rb_push_glob(str, flags)
|
||||||
pend = p + RSTRING(str)->len;
|
pend = p + RSTRING(str)->len;
|
||||||
|
|
||||||
while (p < pend) {
|
while (p < pend) {
|
||||||
buf = rb_str_new(0, pend - p + 1);
|
|
||||||
t = RSTRING(buf)->ptr;
|
|
||||||
nest = maxnest = 0;
|
nest = maxnest = 0;
|
||||||
while (p < pend && isdelim(*p)) p++;
|
while (p < pend && isdelim(*p)) p++;
|
||||||
|
buf = p;
|
||||||
while (p < pend && !isdelim(*p)) {
|
while (p < pend && !isdelim(*p)) {
|
||||||
if (*p == '{') nest++, maxnest++;
|
if (*p == '{') nest++, maxnest++;
|
||||||
if (*p == '}') nest--;
|
if (*p == '}') nest--;
|
||||||
if (!noescape && *p == '\\') {
|
if (!noescape && *p == '\\') {
|
||||||
*t++ = *p++;
|
if (++p == pend) break;
|
||||||
if (p == pend) break;
|
|
||||||
}
|
}
|
||||||
*t++ = *p++;
|
p++;
|
||||||
}
|
}
|
||||||
*t = '\0';
|
|
||||||
if (maxnest == 0) {
|
if (maxnest == 0) {
|
||||||
status = push_globs(ary, buf, flags);
|
status = push_globs(ary, buf, flags);
|
||||||
if (status) break;
|
if (status) break;
|
||||||
|
|
|
||||||
9
eval.c
9
eval.c
|
|
@ -1394,10 +1394,6 @@ ruby_options(argc, argv)
|
||||||
{
|
{
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
argc = rb_w32_cmdvector(GetCommandLine(), &argv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Init_stack((void*)&state);
|
Init_stack((void*)&state);
|
||||||
PUSH_TAG(PROT_NONE);
|
PUSH_TAG(PROT_NONE);
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
if ((state = EXEC_TAG()) == 0) {
|
||||||
|
|
@ -1409,11 +1405,6 @@ ruby_options(argc, argv)
|
||||||
exit(error_handle(state));
|
exit(error_handle(state));
|
||||||
}
|
}
|
||||||
POP_TAG();
|
POP_TAG();
|
||||||
|
|
||||||
#ifdef _WIN32_WCE
|
|
||||||
// free commandline buffer
|
|
||||||
wce_FreeCommandLine();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_exec_end_proc _((void));
|
void rb_exec_end_proc _((void));
|
||||||
|
|
|
||||||
|
|
@ -365,6 +365,11 @@ NtInitialize(int *argc, char ***argv)
|
||||||
WORD version;
|
WORD version;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
//
|
||||||
|
// subvert cmd.exe's feeble attempt at command line parsing
|
||||||
|
//
|
||||||
|
*argc = rb_w32_cmdvector(GetCommandLine(), argv);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Now set up the correct time stuff
|
// Now set up the correct time stuff
|
||||||
//
|
//
|
||||||
|
|
@ -373,6 +378,11 @@ NtInitialize(int *argc, char ***argv)
|
||||||
|
|
||||||
// Initialize Winsock
|
// Initialize Winsock
|
||||||
StartSockets();
|
StartSockets();
|
||||||
|
|
||||||
|
#ifdef _WIN32_WCE
|
||||||
|
// free commandline buffer
|
||||||
|
wce_FreeCommandLine();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getlogin()
|
char *getlogin()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue