[#12387] reducing logical operation — "Nobuyoshi.Nakada" <nobu.nakada@...>

なかだです。

17 messages 2001/03/07
[#12388] Re: reducing logical operation — EGUCHI Osamu <eguchi@...> 2001/03/07

えぐち@エスアンドイー です。

[#12389] Re: reducing logical operation — nobu.nakada@... 2001/03/07

なかだです。

[#12391] Re: reducing logical operation — EGUCHI Osamu <eguchi@...> 2001/03/07

えぐち@エスアンドイー です。

[#12404] fork in threads — keiju@... (Keiju ISHITSUKA)

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

14 messages 2001/03/09

[#12405] at_exit — keiju@... (Keiju ISHITSUKA)

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

15 messages 2001/03/09
[#12409] Re: at_exit — matz@... (Yukihiro Matsumoto) 2001/03/10

まつもと ゆきひろです

[#12411] Re: at_exit — keiju@... (石塚圭樹) 2001/03/10

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

[#12425] bignum % の結果が負数になることがある — Hisayasu Nakao <h-nakao@...>

最近、ruby-1.6.2を使い出したばかりの中尾です。

39 messages 2001/03/12
[#12427] Re: bignum % の結果が負数になることがある — WATANABE Hirofumi <eban@...> 2001/03/12

わたなべです。

[#12463] Re: bignum % の結果が負数になることがある — Takahiro Kambe <taca@...> 2001/03/13

In message <4518-Mon12Mar2001145434+0900-eban@os.rim.or.jp>

[#12464] Re: bignum % の結果が負数になることがある — matz@... (Yukihiro Matsumoto) 2001/03/13

まつもと ゆきひろです

[#12466] Re: bignum % の結果が負数になることがある — Takahiro Kambe <taca@...> 2001/03/13

In message <984469222.234203.1007.nullmailer@ev.netlab.zetabits.com>

[#12475] Re: bignum % の結果が負数になることがある — matz@... (Yukihiro Matsumoto) 2001/03/14

まつもと ゆきひろです

[#12476] Re: bignum % の結果が負数になることがある — Takahiro Kambe <taca@...> 2001/03/14

In message <984550885.417146.3670.nullmailer@ev.netlab.zetabits.com>

[#12480] Re: bignum % の結果が負数になることがある — matz@... (Yukihiro Matsumoto) 2001/03/14

まつもと ゆきひろです

[#12481] Re: bignum % の結果が負数になることがある — Takahiro Kambe <taca@...> 2001/03/14

In message <984553493.009507.3747.nullmailer@ev.netlab.zetabits.com>

[#12488] Re: bignum % の結果が負数になることがある — matz@... (Yukihiro Matsumoto) 2001/03/14

まつもと ゆきひろです

[#12493] Re: bignum % の結果が負数になることがある — Takahiro Kambe <taca@...> 2001/03/14

In message <984579430.080967.5569.nullmailer@ev.netlab.zetabits.com>

[#12578] require 'win32api' — Kazuhiro NISHIYAMA <zn@...>

require 'win32api'のエラーメッセージがわかりにくいと

21 messages 2001/03/20
[#12579] Re: require 'win32api' — nobu.nakada@... 2001/03/20

なかだです。

[#12598] Re: require 'win32api' — nobu.nakada@... 2001/03/21

なかだです。

[#12582] finalizer problem — keiju@... (Keiju ISHITSUKA)

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

20 messages 2001/03/20
[#12583] Re: finalizer problem — matz@... (Yukihiro Matsumoto) 2001/03/20

まつもと ゆきひろです

[#12585] Re: finalizer problem — keiju@... (石塚圭樹) 2001/03/20

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

[#12591] Re: finalizer problem — matz@... (Yukihiro Matsumoto) 2001/03/20

まつもと ゆきひろです

[#12619] Re: finalizer problem — keiju@... (石塚圭樹) 2001/03/22

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

[#12605] extern inline (ruby.h) ruby-1.6.3 — WATANABE Tetsuya <tetsu@...>

渡辺哲也です。

17 messages 2001/03/22
[#12606] Re: extern inline (ruby.h) ruby-1.6.3 — matz@... (Yukihiro Matsumoto) 2001/03/22

まつもと ゆきひろです

[#12607] Re: extern inline (ruby.h) ruby-1.6.3 — WATANABE Tetsuya <tetsu@...> 2001/03/22

渡辺哲也です。

[#12608] Re: extern inline (ruby.h) ruby-1.6.3 — matz@... (Yukihiro Matsumoto) 2001/03/22

まつもと ゆきひろです

[#12674] Was: [rubyist:0454] Re: to_str — Kenichi Komiya <kom@...1.accsnet.ne.jp>

21 messages 2001/03/25
[#12675] Re: Was: [rubyist:0454] Re: to_str — matz@... (Yukihiro Matsumoto) 2001/03/26

まつもと ゆきひろです

[#12678] Re: Was: [rubyist:0454] Re: to_str — Kenichi Komiya <kom@...1.accsnet.ne.jp> 2001/03/26

[#12681] Re: Was: [rubyist:0454] Re: to_str — matz@... (Yukihiro Matsumoto) 2001/03/26

まつもと ゆきひろです

[#12687] Re: Was: [rubyist:0454] Re: to_str — Kenichi Komiya <kom@...1.accsnet.ne.jp> 2001/03/27

[#12688] Re: Was: [rubyist:0454] Re: to_str — matz@... (Yukihiro Matsumoto) 2001/03/28

まつもと ゆきひろです

[#12710] Re: Was: [rubyist:0454] Re: to_str — Kenichi Komiya <kom@...1.accsnet.ne.jp> 2001/03/31

[ruby-dev:12369] File::fnmatch? (was: Re: Dir::fnmatch?)

From: "Akinori MUSHA" <knu@...>
Date: 2001-03-05 17:22:03 UTC
List: ruby-dev #12369
At Tue, 6 Mar 2001 01:01:01 +0900,
matz wrote:
> | [ruby-dev:12229] の、 Dir::fnmatch? の追加には特に問題や反対
> |意見は出ませんでしたが、入れてしまってよいでしょうか?
> 
> 実は、Fileクラスに入るべきでは、という印象を持ってます。
> fnmatchって、たぶんfile name matchだし。

 なるほど。確かに、 basename や dirname も File に入っている
ことだし、File クラスが適当かもしれませんね。そうすると、添付の
パッチのように fnmatch() 絡みはまるごと file.c に移動した方が
よさそうです。

 また、 File クラスという分類を活かし、 File::namematch? でも
いけるようにしてみました。この方が意味明瞭ですね。


 これでどうでしょうか。

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

"We're only at home when we're on the run, on the wing, on the fly"

Index: dir.c
===================================================================
RCS file: /mirror/ruby/src/ruby/dir.c,v
retrieving revision 1.33
diff -u -r1.33 dir.c
--- dir.c	2001/02/28 06:30:03	1.33
+++ dir.c	2001/03/05 16:59:55
@@ -65,165 +65,6 @@
 #define lstat rb_sys_stat
 #endif
 
-#define FNM_NOESCAPE	0x01
-#define FNM_PATHNAME	0x02
-#define FNM_PERIOD	0x04
-#define FNM_NOCASE	0x08
-
-#define FNM_NOMATCH	1
-#define FNM_ERROR	2
-
-#define downcase(c) (nocase && ISUPPER(c) ? tolower(c) : (c))
-
-#if defined DOSISH
-#define isdirsep(c) ((c) == '/' || (c) == '\\')
-static char *
-find_dirsep(s)
-    char *s;
-{
-    while (*s) {
-	if (isdirsep(*s))
-	    return s;
-	s++;
-    }
-    return 0;
-}
-#else
-#define isdirsep(c) ((c) == '/')
-#define find_dirsep(s) strchr(s, '/')
-#endif
-
-static char *
-range(pat, test, flags)
-    char *pat;
-    char test;
-    int flags;
-{
-    int not, ok = 0;
-    int nocase = flags & FNM_NOCASE;
-    int escape = !(flags & FNM_NOESCAPE);
-
-    not = *pat == '!' || *pat == '^';
-    if (not)
-	pat++;
-
-    test = downcase(test);
-
-    while (*pat) {
-	int cstart, cend;
-	cstart = cend = *pat++;
-	if (cstart == ']')
-	    return ok == not ? 0 : pat;
-        else if (escape && cstart == '\\')
-	    cstart = cend = *pat++;
-	if (*pat == '-' && pat[1] != ']') {
-	    if (escape && pat[1] == '\\')
-		pat++;
-	    cend = pat[1];
-	    if (!cend)
-		return 0;
-	    pat += 2;
-	}
-	if (downcase(cstart) <= test && test <= downcase(cend))
-	    ok = 1;
-    }
-    return 0;
-}
-
-#define PERIOD(s) (period && *(s) == '.' && \
-		  ((s) == string || pathname && isdirsep(*(s))))
-static int
-fnmatch(pat, string, flags)
-    char *pat;
-    char *string;
-    int flags;
-{
-    int c;
-    int test;
-    char *s = string;
-    int escape = !(flags & FNM_NOESCAPE);
-    int pathname = flags & FNM_PATHNAME;
-    int period = flags & FNM_PERIOD;
-    int nocase = flags & FNM_NOCASE;
-
-    while (c = *pat++) {
-	switch (c) {
-	case '?':
-	    if (!*s || pathname && isdirsep(*s) || PERIOD(s))
-		return FNM_NOMATCH;
-	    s++;
-	    break;
-	case '*':
-	    while ((c = *pat++) == '*')
-		;
-
-	    if (PERIOD(s))
-		return FNM_NOMATCH;
-
-	    if (!c) {
-		if (pathname && find_dirsep(s))
-		    return FNM_NOMATCH;
-		else
-		    return 0;
-	    }
-	    else if (pathname && isdirsep(c)) {
-		s = find_dirsep(s);
-		if (s)
-		    break;
-		return FNM_NOMATCH;
-	    }
-
-	    test = escape && c == '\\' ? *pat : c;
-	    test = downcase(test);
-	    pat--;
-	    while (*s) {
-		if ((c == '[' || downcase(*s) == test) &&
-		    !fnmatch(pat, s, flags & ~FNM_PERIOD))
-		    return 0;
-		else if (pathname && isdirsep(*s))
-		    break;
-		s++;
-	    }
-	    return FNM_NOMATCH;
-      
-	case '[':
-	    if (!*s || pathname && isdirsep(*s) || PERIOD(s))
-		return FNM_NOMATCH;
-	    pat = range(pat, *s, flags);
-	    if (!pat)
-		return FNM_NOMATCH;
-	    s++;
-	    break;
-
-	case '\\':
-	    if (escape
-#if defined DOSISH
-		&& *pat && strchr("*?[\\", *pat)
-#endif
-		) {
-		c = *pat;
-		if (!c)
-		    c = '\\';
-		else
-		    pat++;
-	    }
-	    /* FALLTHROUGH */
-
-	default:
-#if defined DOSISH
-	    if (pathname && isdirsep(c) && isdirsep(*s))
-		;
-	    else
-#endif
-	    if(downcase(c) != downcase(*s))
-		return FNM_NOMATCH;
-	    s++;
-	    break;
-	}
-    }
-    return !*s ? 0 : FNM_NOMATCH;
-}
-
 VALUE rb_cDir;
 
 static void
@@ -666,7 +507,7 @@
 		    free(buf);
 		    continue;
 		}
-		if (fnmatch(magic, dp->d_name, flag) == 0) {
+		if (rb_fnmatch(magic, dp->d_name, flag) == 0) {
 		    buf = ALLOC_N(char, strlen(base)+NAMLEN(dp)+2);
 		    sprintf(buf, "%s%s%s", base, (BASE)?"/":"", dp->d_name);
 		    if (!m) {
Index: file.c
===================================================================
RCS file: /mirror/ruby/src/ruby/file.c,v
retrieving revision 1.48
diff -u -r1.48 file.c
--- file.c	2001/02/24 17:51:02	1.48
+++ file.c	2001/03/05 17:10:53
@@ -70,6 +70,63 @@
 #define lstat rb_sys_stat
 #endif
  
+#define downcase(c) (nocase && ISUPPER(c) ? tolower(c) : (c))
+
+#if defined DOSISH
+#define isdirsep(c) ((c) == '/' || (c) == '\\')
+static char *
+find_dirsep(s)
+    char *s;
+{
+    while (*s) {
+	if (isdirsep(*s))
+	    return s;
+	s++;
+    }
+    return 0;
+}
+#else
+#define isdirsep(c) ((c) == '/')
+#define find_dirsep(s) strchr(s, '/')
+#endif
+
+static char *
+range(pat, test, flags)
+    char *pat;
+    char test;
+    int flags;
+{
+    int not, ok = 0;
+    int nocase = flags & FNM_NOCASE;
+    int escape = !(flags & FNM_NOESCAPE);
+
+    not = *pat == '!' || *pat == '^';
+    if (not)
+	pat++;
+
+    test = downcase(test);
+
+    while (*pat) {
+	int cstart, cend;
+	cstart = cend = *pat++;
+	if (cstart == ']')
+	    return ok == not ? 0 : pat;
+        else if (escape && cstart == '\\')
+	    cstart = cend = *pat++;
+	if (*pat == '-' && pat[1] != ']') {
+	    if (escape && pat[1] == '\\')
+		pat++;
+	    cend = pat[1];
+	    if (!cend)
+		return 0;
+	    pat += 2;
+	}
+	if (downcase(cstart) <= test && test <= downcase(cend))
+	    ok = 1;
+    }
+    return 0;
+}
+
 VALUE rb_cFile;
 VALUE rb_mFileTest;
 static VALUE rb_cStat;
@@ -1493,6 +1550,123 @@
     return dirname;
 }
 
+#define PERIOD(s) (period && *(s) == '.' && \
+		  ((s) == string || pathname && isdirsep(*(s))))
+int
+rb_fnmatch(pat, string, flags)
+    char *pat;
+    char *string;
+    int flags;
+{
+    int c;
+    int test;
+    char *s = string;
+    int escape = !(flags & FNM_NOESCAPE);
+    int pathname = flags & FNM_PATHNAME;
+    int period = flags & FNM_PERIOD;
+    int nocase = flags & FNM_NOCASE;
+
+    while (c = *pat++) {
+	switch (c) {
+	case '?':
+	    if (!*s || pathname && isdirsep(*s) || PERIOD(s))
+		return FNM_NOMATCH;
+	    s++;
+	    break;
+	case '*':
+	    while ((c = *pat++) == '*')
+		;
+
+	    if (PERIOD(s))
+		return FNM_NOMATCH;
+
+	    if (!c) {
+		if (pathname && find_dirsep(s))
+		    return FNM_NOMATCH;
+		else
+		    return 0;
+	    }
+	    else if (pathname && isdirsep(c)) {
+		s = find_dirsep(s);
+		if (s)
+		    break;
+		return FNM_NOMATCH;
+	    }
+
+	    test = escape && c == '\\' ? *pat : c;
+	    test = downcase(test);
+	    pat--;
+	    while (*s) {
+		if ((c == '[' || downcase(*s) == test) &&
+		    !rb_fnmatch(pat, s, flags & ~FNM_PERIOD))
+		    return 0;
+		else if (pathname && isdirsep(*s))
+		    break;
+		s++;
+	    }
+	    return FNM_NOMATCH;
+      
+	case '[':
+	    if (!*s || pathname && isdirsep(*s) || PERIOD(s))
+		return FNM_NOMATCH;
+	    pat = range(pat, *s, flags);
+	    if (!pat)
+		return FNM_NOMATCH;
+	    s++;
+	    break;
+
+	case '\\':
+	    if (escape
+#if defined DOSISH
+		&& *pat && strchr("*?[\\", *pat)
+#endif
+		) {
+		c = *pat;
+		if (!c)
+		    c = '\\';
+		else
+		    pat++;
+	    }
+	    /* FALLTHROUGH */
+
+	default:
+#if defined DOSISH
+	    if (pathname && isdirsep(c) && isdirsep(*s))
+		;
+	    else
+#endif
+	    if(downcase(c) != downcase(*s))
+		return FNM_NOMATCH;
+	    s++;
+	    break;
+	}
+    }
+    return !*s ? 0 : FNM_NOMATCH;
+}
+
+static VALUE
+rb_file_s_fnmatch(argc, argv, obj)
+    int argc;
+    VALUE *argv;
+    VALUE obj;
+{
+    VALUE pattern, string;
+    VALUE flags;
+    int f;
+
+    if (rb_scan_args(argc, argv, "21", &pattern, &string, &flags) == 3) {
+	f = NUM2INT(flags);
+    }
+    else {
+	f = 0;
+    }
+
+    if (rb_fnmatch(RSTRING(pattern)->ptr, RSTRING(string)->ptr, f) == 0)
+	return Qtrue;
+
+    return Qfalse;
+}
+
 static VALUE
 rb_file_s_split(obj, path)
     VALUE obj, path;
@@ -2309,6 +2483,8 @@
     rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1);
     rb_define_singleton_method(rb_cFile, "basename", rb_file_s_basename, -1);
     rb_define_singleton_method(rb_cFile, "dirname", rb_file_s_dirname, 1);
+    rb_define_singleton_method(rb_cFile, "fnmatch?", rb_file_s_fnmatch, -1);
+    rb_define_singleton_method(rb_cFile, "namematch?", rb_file_s_fnmatch, -1);
 
     separator = rb_str_new2("/");
     rb_define_const(rb_cFile, "Separator", separator);
@@ -2338,6 +2514,10 @@
 
     rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
     rb_include_module(rb_cFile, rb_mFConst);
+    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_NOCASE", INT2FIX(FNM_NOCASE));
     rb_file_const("LOCK_SH", INT2FIX(LOCK_SH));
     rb_file_const("LOCK_EX", INT2FIX(LOCK_EX));
     rb_file_const("LOCK_UN", INT2FIX(LOCK_UN));
Index: intern.h
===================================================================
RCS file: /mirror/ruby/src/ruby/intern.h,v
retrieving revision 1.41
diff -u -r1.41 intern.h
--- intern.h	2001/02/16 07:53:19	1.41
+++ intern.h	2001/03/05 16:57:08
@@ -173,8 +173,16 @@
 VALUE rb_thread_local_aset _((VALUE, ID, VALUE));
 void rb_thread_atfork _((void));
 /* file.c */
+#define FNM_NOESCAPE	0x01
+#define FNM_PATHNAME	0x02
+#define FNM_PERIOD	0x04
+#define FNM_NOCASE	0x08
+
+#define FNM_NOMATCH	1
+#define FNM_ERROR	2
 int eaccess _((const char*, int));
 VALUE rb_file_s_expand_path _((int, VALUE *));
+int rb_fnmatch _((char *, char *, int));
 void rb_file_const _((const char*, VALUE));
 char *rb_find_file _((char*));
 /* gc.c */

In This Thread