[#22503] can't require — IWATSUKI Hiroyuki <don@...>

岩月と申します。

94 messages 2004/01/06
[#22504] Re: can't require — nobu.nakada@... 2004/01/06

なかだです。

[#22505] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/06

まつもと ゆきひろです

[#22506] Re: can't require — IWATSUKI Hiroyuki <don@...> 2004/01/06

岩月と申します。

[#22509] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/07

山本です。

[#22513] Re: can't require — IWATSUKI Hiroyuki <don@...> 2004/01/07

岩月と申します。

[#22514] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22522] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/07

山本です。

[#22524] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22526] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/07

山本です。

[#22534] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22535] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/07

まつもと ゆきひろです

[#22536] Re: can't require — Tanaka Akira <akr@...17n.org> 2004/01/07

In article <1073474004.933446.5475.nullmailer@picachu.netlab.jp>,

[#22540] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22541] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/07

山本です。なかださんのコードで気になった点が3つあります。

[#22546] Re: can't require — nobu.nakada@... 2004/01/07

なかだです。

[#22549] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/08

山本です。

[#22550] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/08

山本です。

[#22551] Re: can't require — nobu.nakada@... 2004/01/08

なかだです。

[#22571] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/11

山本です。

[#22667] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/22

山本です。

[#22668] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/22

まつもと ゆきひろです

[#22669] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/22

山本です。

[#22676] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/24

山本です。

[#22677] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/25

まつもと ゆきひろです

[#22678] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/25

山本です。

[#22679] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/25

山本です。

[#22680] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/25

まつもと ゆきひろです

[#22682] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/25

山本です。

[#22683] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/25

まつもと ゆきひろです

[#22686] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/26

山本です。

[#22687] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/26

山本です。

[#22697] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/27

山本です。

[#22700] Re: can't require — nobu.nakada@... 2004/01/27

なかだです。

[#22712] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/27

山本です。WinCVS + byacc + sed をインストールして、ビルドできるようになりました。

[#22714] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/27

山本です。

[#22716] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/27

山本です。

[#22725] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22729] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/28

まつもと ゆきひろです

[#22734] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22736] Re: can't require — matz@... (Yukihiro Matsumoto) 2004/01/28

まつもと ゆきひろです

[#22738] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22739] Re: can't require — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22740] Dir.glob (Re: Re: can't require) — nobu.nakada@... 2004/01/28

なかだです。

[#22741] Re: Dir.glob (Re: Re: can't require) — matz@... (Yukihiro Matsumoto) 2004/01/28

まつもと ゆきひろです

[#22744] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22746] Re: Dir.glob (Re: Re: can't require) — nobu.nakada@... 2004/01/28

なかだです。

[#22747] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22748] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/28

山本です。

[#22750] Re: Dir.glob (Re: Re: can't require) — matz@... (Yukihiro Matsumoto) 2004/01/28

まつもと ゆきひろです

[#22761] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/29

山本です。

[#22764] Re: Dir.glob (Re: Re: can't require) — nobu.nakada@... 2004/01/29

なかだです。

[#22766] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/29

山本です。

[#22770] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/29

山本です。

[#22772] Re: Dir.glob (Re: Re: can't require) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/01/29

山本です。

[#22774] Re: Dir.glob (Re: Re: can't require) — matz@... (Yukihiro Matsumoto) 2004/01/29

まつもと ゆきひろです

[#22688] output directory for extensions — nobu.nakada@...

なかだです。

14 messages 2004/01/26

[#22691] 次期リリースでの新規添付ライブラリ — "Kawaji, Shinya" <kawaji@...>

かわじ、です

18 messages 2004/01/26
[#22693] Re: 次期リリースでの新規添付ライブラリ — matz@... (Yukihiro Matsumoto) 2004/01/26

まつもと ゆきひろです

[#22694] Re: 次期リリースでの新規添付ライブラリ — matz@... (Yukihiro Matsumoto) 2004/01/26

まつもと ゆきひろです

[#22763] $: trick in test/* — "NAKAMURA, Hiroshi" <nakahiro@...>

なひです。

21 messages 2004/01/29

[ruby-dev:22546] Re: can't require

From: nobu.nakada@...
Date: 2004-01-07 15:13:43 UTC
List: ruby-dev #22546
なかだです。

At Wed, 7 Jan 2004 21:57:13 +0900,
H.Yamamoto wrote:
> 山本です。なかださんのコードで気になった点が3つあります。
> (_WIN32のコードだとコンパイルで無限ループしたので、_WIN32の部分は削除してコンパイルしました。)

_WIN32と非_WIN32で相似にしたつもりなのですが、「コンパイルで無
限ループ」というのはどういう意味でしょうか。

> // 1
> E:\ruby-dev\ruby-1.8.1>miniruby -Ks -e "puts Dir.glob('s:/script/**/*/*/')"
> s:/script/sample/aya/cscript/
> s:/script/sample/aya/error/
> s:/script/sample/aya/vs Perl/
> s:/script/sample/aya/
> s:/script/sample/tcp/
> s:/script/test/class/
> s:/script/test/file/
> s:/script/project/java/
> s:/script/project/wwwc/
> s:/script/project/bcb/
> 
> は、上からマッチしません。これは意図された動作でしょうか?

直しました。

> // 2
> 
> ALLOC_BUF()ですが、malloc と free は狭いスコープで完結していたほうが保守しやすいと思います。
> (途中で return や break が入ることを考えると、特に)
> 速度が大きく違うならと思って計測しましたが、速度に違いはありませんでした。

差は出ませんでしたか。じゃやめましょう。

> // 3
> 
> status = glob_helper が非0を返す場合に中断していないようです。
> こっちが正しい動作なのかもしれませんが・・・

見落としてました。


Index: dir.c
===================================================================
RCS file: /cvs/ruby/src/ruby/dir.c,v
retrieving revision 1.95
diff -u -2 -p -r1.95 dir.c
--- dir.c	7 Jan 2004 13:28:15 -0000	1.95
+++ dir.c	7 Jan 2004 14:53:47 -0000
@@ -72,4 +72,5 @@ char *strchr _((char*,char));
 #define FNM_DOTMATCH	0x04
 #define FNM_CASEFOLD	0x08
+#define GLOB_POSTORDER	0x0100
 
 #define FNM_NOMATCH	1
@@ -1002,4 +1003,5 @@ glob_helper(path, sub, separator, flags,
     int recursive = 0;
     int magical = 1;
+    int n1, mlen;
 
     struct d_link {
@@ -1050,4 +1052,12 @@ glob_helper(path, sub, separator, flags,
     }
 
+    n1 = p - path;
+
+    mlen = strlen(m);
+    if (!magical && !(flags & GLOB_POSTORDER)) {
+	status = glob_helper(path, p, separator, flags, func, arg);
+	if (status) return status;
+    }
+
     if (path == p) {
 	dirp = do_opendir(".");
@@ -1064,27 +1074,23 @@ glob_helper(path, sub, separator, flags,
 
     for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
-	const int n1 = p - path;
 	const int n2 = n1 + NAMLEN(dp);
-	const int ok = 0;
-	const int ln = 1;
-	const int no = 2;
-	int is_dir = -1; /* not checked yet */
-#ifdef _WIN32
-	is_dir = dp->d_isdir ? (dp->d_isrep ? ln : ok) : no;
-#endif
+	enum {unknown = -1, dir, symlnk, nodir} dirtype = unknown;
+
 	if (recursive && strcmp(".", dp->d_name) != 0 && strcmp("..", dp->d_name) != 0) {
+	    dirtype = nodir;
 	    buf = ALLOC_N(char, n2+4+strlen(p)+1);
 	    memcpy(buf, path, n1);
 	    strcpy(buf+n1, dp->d_name);
 #ifndef _WIN32
-	    is_dir = no;
 	    if (do_lstat(buf, &st) == 0) {
 		if (S_ISDIR(st.st_mode))
-		    is_dir = ok;
+		    dirtype = dir;
 		else if (S_ISLNK(st.st_mode) && do_stat(buf, &st) == 0 && S_ISDIR(st.st_mode))
-		    is_dir = ln;
+		    dirtype = symlnk;
 	    }
+#else
+	    if (dp->d_isdir) dirtype = (dp->d_isrep ? symlnk : dir);
 #endif
-	    if (is_dir == ok) {
+	    if (dirtype == dir && (flags & GLOB_POSTORDER)) {
 		strcpy(buf+n2, "/**/");
 		strcpy(buf+n2+4, p);
@@ -1092,19 +1098,26 @@ glob_helper(path, sub, separator, flags,
 	    }
 	    free(buf);
-	    if (status) break;
 	}
-	if (is_dir == no && *m == '/') {
+	if (dirtype == nodir && *m == '/') {
 	    continue;
 	}
 	if (magical && do_fnmatch(p, m, dp->d_name, flags) == 0) {
-	    buf = ALLOC_N(char, n2+1+1);
-	    memcpy(buf, path, n1);
-	    strcpy(buf+n1, dp->d_name);
-	    if (*m == '\0') {
+	    if (mlen == 0 || mlen == 1 && (dirtype == dir || dirtype == symlnk)) {
+		buf = ALLOC_N(char, n2+mlen+1);
+		memcpy(buf, path, n1);
+		strcpy(buf+n1, dp->d_name);
+		strcpy(buf+n2, m);
 		status = glob_call_func(func, buf, arg);
+		free(buf);
+		if (status) break;
 	    }
-	    else if (m[1] == '\0' && (is_dir == ok || is_dir == ln)) { /* *m == '/' */
-		strcpy(buf+n2, "/");
-		status = glob_call_func(func, buf, arg);
+	    else if (!(flags & GLOB_POSTORDER)) {
+		buf = ALLOC_N(char, n2+mlen+1);
+		memcpy(buf, path, n1);
+		strcpy(buf+n1, dp->d_name);
+		strcpy(buf+n2, m);
+		status = glob_helper(buf, buf+n2+1, 1, flags, func, arg);
+		free(buf);
+		if (status) break;
 	    }
 	    else {
@@ -1115,4 +1128,12 @@ glob_helper(path, sub, separator, flags,
 		tail = &tmp->next;
 	    }
+	}
+	if (dirtype == dir && !(flags & GLOB_POSTORDER)) {
+	    buf = ALLOC_N(char, n2+4+strlen(p)+1);
+	    memcpy(buf, path, n1);
+	    strcpy(buf+n1, dp->d_name);
+	    strcpy(buf+n2, "/**/");
+	    strcpy(buf+n2+4, p);
+	    status = glob_helper(buf, buf+n2+1, 1, flags, func, arg);
 	    free(buf);
 	    if (status) break;
@@ -1124,7 +1145,6 @@ glob_helper(path, sub, separator, flags,
     while (link) {
 	if (status == 0) {
-	    const int n1 = p - path;
 	    const int n2 = n1 + strlen(link->name);
-	    buf = ALLOC_N(char, n2+strlen(m)+1);
+	    buf = ALLOC_N(char, n2+mlen+1);
 	    memcpy(buf, path, n1);
 	    strcpy(buf+n1, link->name);
@@ -1139,5 +1159,5 @@ glob_helper(path, sub, separator, flags,
     }
 
-    if (!magical) {
+    if (!status && !magical && (flags & GLOB_POSTORDER)) {
 	status = glob_helper(path, p, separator, flags, func, arg);
     }
@@ -1531,3 +1551,5 @@ Init_Dir()
     rb_file_const("FNM_DOTMATCH", INT2FIX(FNM_DOTMATCH));
     rb_file_const("FNM_CASEFOLD", INT2FIX(FNM_CASEFOLD));
+
+    rb_define_const(rb_cDir, "GLOB_POSTORDER", INT2FIX(GLOB_POSTORDER));
 }


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread