[#16211] pstore.rb and sync.rb — Kazuhiro NISHIYAMA <zn@...>

西山和広です。

19 messages 2002/03/04
[#16245] Re: pstore.rb and sync.rb — keiju@... (石塚圭樹) 2002/03/07

けいじゅ@日本ラショナルソフトウェアです.

[#16240] [Oni Guruma] look behind — nobu.nakada@...

なかだです。

14 messages 2002/03/07

[#16283] ライブラリ拡大計画 — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

124 messages 2002/03/08
[#16307] Re: ライブラリ拡大計画 — TAKAHASHI Masayoshi <maki@...> 2002/03/10

高橋征義です。

[#16317] Re: ライブラリ拡大計画 — matz@... (Yukihiro Matsumoto) 2002/03/11

まつもと ゆきひろです

[#16318] Re: ライブラリ拡大計画 — Tanaka Akira <akr@...17n.org> 2002/03/11

In article <1015827556.101112.6552.nullmailer@ev.netlab.jp>,

[#16320] Re: ライブラリ拡大計画 — matz@... (Yukihiro Matsumoto) 2002/03/11

まつもと ゆきひろです

[#16347] Re: ライブラリ拡大計画 — Minero Aoki <aamine@...> 2002/03/12

あおきです。

[#16308] Re: ライブラリ拡大計画 — WATANABE Hirofumi <eban@...> 2002/03/11

わたなべです。

[#16626] Re: ライブラリ拡大計画 — matz@... (Yukihiro Matsumoto) 2002/03/27

まつもと ゆきひろです

[#16628] Re: ライブラリ拡大計画 — Takaaki Tateishi <ttate@...> 2002/03/27

At Wed, 27 Mar 2002 18:56:03 +0900,

[#16629] Re: ライブラリ拡大計画 — matz@... (Yukihiro Matsumoto) 2002/03/27

まつもと ゆきひろです

[#16647] Re: ライブラリ拡大計画 — Takaaki Tateishi <ttate@...> 2002/03/28

At Thu, 28 Mar 2002 00:12:49 +0900,

[#16674] Re: ライブラリ拡大計画 — Takaaki Tateishi <ttate@...> 2002/03/29

At Thu, 28 Mar 2002 23:45:49 +0900,

[#16675] Re: ライブラリ拡大計画 — matz@... (Yukihiro Matsumoto) 2002/03/29

まつもと ゆきひろです

[#16680] Re: ライブラリ拡大計画 — nobu.nakada@... 2002/03/29

なかだです。

[#16681] Re: ライブラリ拡大計画 — matz@... (Yukihiro Matsumoto) 2002/03/29

まつもと ゆきひろです

[#16683] Re: ライブラリ拡大計画 — nobu.nakada@... 2002/03/29

なかだです。

[#16687] Re: ライブラリ拡大計画 — Takaaki Tateishi <ttate@...> 2002/03/30

At Fri, 29 Mar 2002 20:32:17 +0900,

[#16718] Re: ライブラリ拡大計画 — Takaaki Tateishi <ttate@...> 2002/04/02

At Sun, 31 Mar 2002 02:20:04 +0900,

[#16371] Re: ライブラリ拡大計画 — Takaaki Tateishi <ttate@...> 2002/03/13

At Fri, 8 Mar 2002 18:05:01 +0900,

[#16373] Re: ライブラリ拡大計画 — matz@... (Yukihiro Matsumoto) 2002/03/14

まつもと ゆきひろです

[#16397] Re: ライブラリ拡大計画 — nobu.nakada@... 2002/03/14

なかだです。

[#16404] Re: ライブラリ拡大計画 — Tanaka Akira <akr@...17n.org> 2002/03/14

In article <20020314133401.3918E10F3@sharui.nakada.kanuma.tochigi.jp>,

[#16406] Re: ライブラリ拡大計画 — nobu.nakada@... 2002/03/15

なかだです。

[#16290] IO#gets improvement — nobu.nakada@...

なかだです。

27 messages 2002/03/08
[#16291] Re: IO#gets improvement — Tanaka Akira <akr@...17n.org> 2002/03/08

In article <20020308131426.8C36123B9@sharui.nakada.kanuma.tochigi.jp>,

[#16294] Re: IO#gets improvement — nobu.nakada@... 2002/03/09

なかだです。

[#16549] Re: IO#gets improvement — nobu.nakada@... 2002/03/23

なかだです。

[#16486] mswin32 configuration — nobu.nakada@...

なかだです。

20 messages 2002/03/19
[#16488] Re: mswin32 configuration — "U.Nakamura" <usa@...> 2002/03/19

こんにちは、なかむら(う)です。

[#16489] Re: mswin32 configuration — nobu.nakada@... 2002/03/19

なかだです。

[#16490] Re: mswin32 configuration — "U.Nakamura" <usa@...> 2002/03/19

こんにちは、なかむら(う)です。

[#16545] BigFloat — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

51 messages 2002/03/23
[#16547] Re: BigFloat — "Akinori MUSHA" <knu@...> 2002/03/23

At Sat, 23 Mar 2002 22:55:45 +0900,

[#16548] Re: BigFloat — "Akinori MUSHA" <knu@...> 2002/03/23

At Sun, 24 Mar 2002 02:20:26 +0900,

[#16550] Re: BigFloat — Tanaka Akira <akr@...17n.org> 2002/03/23

In article <867ko3yyik.wl@archon.local.idaemons.org>,

[#16551] Re: BigFloat — "Akinori MUSHA" <knu@...> 2002/03/23

At Sun, 24 Mar 2002 04:21:59 +0900,

[#16552] Re: BigFloat — Tanaka Akira <akr@...17n.org> 2002/03/23

In article <864rj7yljs.wl@archon.local.idaemons.org>,

[#16553] Re: BigFloat — "Akinori MUSHA" <knu@...> 2002/03/23

At Sun, 24 Mar 2002 07:44:15 +0900,

[#16560] Re: BigFloat — Tanaka Akira <akr@...17n.org> 2002/03/24

In article <861yeazvtg.wl@archon.local.idaemons.org>,

[#16565] Re: BigFloat — "Akinori MUSHA" <knu@...> 2002/03/24

At Sun, 24 Mar 2002 15:41:18 +0900,

[#16575] Re: if Re: BigFloat — keiju@... (石塚圭樹) 2002/03/24

けいじゅ@日本ラショナルソフトウェアです.

[#16715] Re: if Re: BigFloat — keiju@... (石塚圭樹) 2002/04/02

けいじゅ@日本ラショナルソフトウェアです.

[#16725] Re: if Re: BigFloat — "Akinori MUSHA" <knu@...> 2002/04/02

At Tue, 2 Apr 2002 16:16:04 +0900,

[#16789] Re: if Re: BigFloat — "Shigeo Kobayashi" <shigeo@...> 2002/04/08

[#16805] Re: if Re: BigFloat — Shin-ichiro HARA <sinara@...> 2002/04/09

原です。

[#16811] Re: if Re: BigFloat — "Shigeo Kobayashi" <shigeo@...> 2002/04/09

[#16555] File.fnmatch (Re: [rubyist:1286] Re: ARGV の機能) — Koji Arai <JCA02266@...>

新井です。

11 messages 2002/03/24

[#16593] Oniguruma and multibyte character literal — TAKAHASHI Masayoshi <maki@...>

高橋征義です。

15 messages 2002/03/25
[#16594] Re: Oniguruma and multibyte character literal — matz@... (Yukihiro Matsumoto) 2002/03/25

まつもと ゆきひろです

[#16652] [OniGuruma] nested repeat operator — "K.Kosako" <kosako@...>

[ruby-talk:36959]で指摘された

31 messages 2002/03/29
[#16669] Re: [OniGuruma] nested repeat operator — Tanaka Akira <akr@...17n.org> 2002/03/29

In article <20020329022810.68F9E17@helium.ruby-lang.org>,

[#16676] Re: [OniGuruma] nested repeat operator — "K.Kosako" <kosako@...> 2002/03/29

Tanaka Akiraさんの<hvohemzoku6.fsf@coulee.a02.aist.go.jp>から

[ruby-dev:16288] Re: Dir::glob(pattern, flags = 0)

From: "Akinori MUSHA" <knu@...>
Date: 2002-03-08 10:19:16 UTC
List: ruby-dev #16288
At Fri, 8 Mar 2002 17:31:15 +0900,
matz wrote:
> 「Dir::[]の第2引数はあんまりよくないのでは」というのは、どう
> しますか? 個人的には複数パターンを受け付ける必要はないと思っ
> てはいますが、ここの引数はなるたけ対等であって欲しいのですが。

 現行の [] と glob が等価というのを踏襲しただけで、私としては
どちらでもいいと思っていました。

 確かに Dir["*", File::FNM_DOTMATCH] というのは気持ち悪いので、
Dir[] はフラグを受け付けないようにしたいと思います。

> で、Dir::globおよびその他の変更については反対しません。

 ありがとうございます。

-- 
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"Somewhere out of a memory.. of lighted streets on quiet nights.."

Index: dir.c
===================================================================
RCS file: /src/ruby/dir.c,v
retrieving revision 1.60
diff -u -u -r1.60 dir.c
--- dir.c	2002/02/18 09:52:45	1.60
+++ dir.c	2002/03/08 10:10:26
@@ -69,7 +69,7 @@
 
 #define FNM_NOESCAPE	0x01
 #define FNM_PATHNAME	0x02
-#define FNM_PERIOD	0x04
+#define FNM_DOTMATCH	0x04
 #define FNM_CASEFOLD	0x08
 
 #define FNM_NOMATCH	1
@@ -153,7 +153,7 @@
     const char *s = string;
     int escape = !(flags & FNM_NOESCAPE);
     int pathname = flags & FNM_PATHNAME;
-    int period = flags & FNM_PERIOD;
+    int period = !(flags & FNM_DOTMATCH);
     int nocase = flags & FNM_CASEFOLD;
 
     while (c = *pat++) {
@@ -188,7 +188,7 @@
 	    pat--;
 	    while (*s) {
 		if ((c == '[' || downcase(*s) == test) &&
-		    !fnmatch(pat, s, flags & ~FNM_PERIOD))
+		    !fnmatch(pat, s, flags | FNM_DOTMATCH))
 		    return 0;
 		else if (ISDIRSEP(*s))
 		    break;
@@ -793,13 +793,23 @@
     }
 }
 
+static void
+rb_glob2(path, flags, func, arg)
+    char *path;
+    int flags;
+    void (*func) _((const char*, VALUE));
+    VALUE arg;
+{
+    glob_helper(path, 0, flags, func, arg);
+}
+
 void
 rb_glob(path, func, arg)
     char *path;
     void (*func) _((const char*, VALUE));
     VALUE arg;
 {
-    glob_helper(path, 0, FNM_PERIOD, func, arg);
+    rb_glob2(path, 0, func, arg);
 }
 
 void
@@ -808,11 +818,9 @@
     void (*func) _((const char*, VALUE));
     VALUE arg;
 {
-    glob_helper(path, 0, FNM_PERIOD|FNM_CASEFOLD, func, arg);
+    rb_glob2(path, FNM_CASEFOLD, func, arg);
 }
 
-static void push_pattern _((const char *path, VALUE ary));
-
 static void
 push_pattern(path, ary)
     const char *path;
@@ -829,17 +837,19 @@
 }
 
 static void
-push_globs(ary, s)
+push_globs(ary, s, flags)
     VALUE ary;
     char *s;
+    int flags;
 {
-    rb_glob(s, push_pattern, ary);
+    rb_glob2(s, flags, push_pattern, ary);
 }
 
 static void
-push_braces(ary, s)
+push_braces(ary, s, flags)
     VALUE ary;
     char *s;
+    int flags;
 {
     char *buf;
     char *p, *t, *b;
@@ -878,31 +888,35 @@
 	    }
 	    memcpy(b, t, p-t);
 	    strcpy(b+(p-t), rbrace+1);
-	    push_braces(ary, buf);
+	    push_braces(ary, buf, flags);
 	}
 	free(buf);
     }
     else {
-	push_globs(ary, s);
+	push_globs(ary, s, flags);
     }
 }
 
 #define isdelim(c) ((c)=='\0')
 
 static VALUE
-dir_s_glob(dir, str)
-    VALUE dir, str;
+rb_push_glob(str, flags)
+    VALUE str;
+    int flags;
 {
     char *p, *pend;
     char *buf;
     char *t;
-    int nest;
-    VALUE ary = 0;
+    int nest, maxnest;
+    int noescape = flags & FNM_NOESCAPE;
+    VALUE ary;
 
-    SafeStringValue(str);
-    if (!rb_block_given_p()) {
+    if (rb_block_given_p())
+	ary = Qnil;
+    else
 	ary = rb_ary_new();
-    }
+
+    SafeStringValue(str);
     buf = xmalloc(RSTRING(str)->len + 1);
 
     p = RSTRING(str)->ptr;
@@ -913,28 +927,50 @@
 	nest = 0;
 	while (p < pend && isdelim(*p)) p++;
 	while (p < pend && !isdelim(*p)) {
-	    if (*p == '{') nest+=2;
-	    if (*p == '}') nest+=3;
-	    if (*p == '\\') {
+	    if (*p == '{') nest++, maxnest++;
+	    if (*p == '}') nest--;
+	    if (!noescape && *p == '\\') {
 		*t++ = *p++;
 		if (p == pend) break;
 	    }
 	    *t++ = *p++;
 	}
 	*t = '\0';
-	if (nest == 0) {
-	    push_globs(ary, buf);
+	if (maxnest == 0) {
+	    push_globs(ary, buf, flags);
 	}
-	else if (nest % 5 == 0) {
-	    push_braces(ary, buf);
+	else if (nest == 0) {
+	    push_braces(ary, buf, flags);
 	}
 	/* else unmatched braces */
     }
     free(buf);
-    if (ary) {
-	return ary;
-    }
-    return Qnil;
+
+    return ary;
+}
+
+static VALUE
+dir_s_aref(obj, str)
+    VALUE obj, str;
+{
+    return rb_push_glob(str, 0);
+}
+
+static VALUE
+dir_s_glob(argc, argv, obj)
+    int argc;
+    VALUE *argv;
+    VALUE obj;
+{
+    VALUE str, rflags;
+    int flags;
+
+    if (rb_scan_args(argc, argv, "11", &str, &rflags) == 2)
+	flags = NUM2INT(rflags);
+    else
+	flags = 0;
+
+    return rb_push_glob(str, flags);
 }
 
 static VALUE
@@ -1014,14 +1050,14 @@
     rb_define_singleton_method(rb_cDir,"delete", dir_s_rmdir, 1);
     rb_define_singleton_method(rb_cDir,"unlink", dir_s_rmdir, 1);
 
-    rb_define_singleton_method(rb_cDir,"glob", dir_s_glob, 1);
-    rb_define_singleton_method(rb_cDir,"[]", dir_s_glob, 1);
+    rb_define_singleton_method(rb_cDir,"glob", dir_s_glob, -1);
+    rb_define_singleton_method(rb_cDir,"[]", dir_s_aref, 1);
 
     rb_define_singleton_method(rb_cFile,"fnmatch", file_s_fnmatch, -1);
     rb_define_singleton_method(rb_cFile,"fnmatch?", file_s_fnmatch, -1);
 
     rb_file_const("FNM_NOESCAPE", INT2FIX(FNM_NOESCAPE));
     rb_file_const("FNM_PATHNAME", INT2FIX(FNM_PATHNAME));
-    rb_file_const("FNM_PERIOD", INT2FIX(FNM_PERIOD));
+    rb_file_const("FNM_DOTMATCH", INT2FIX(FNM_DOTMATCH));
     rb_file_const("FNM_CASEFOLD", INT2FIX(FNM_CASEFOLD));
 }

In This Thread

Prev Next