[#30920] [REQ] Regexp#match! — Minero Aoki <aamine@...>

あおきです。

19 messages 2001/08/16

[#30945] file exist check method? — "Inoue" <inoue@...>

井上です。

98 messages 2001/08/17
[#30947] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/17

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

[#30949] Re: file exist check method? — Koji Arai <JCA02266@...> 2001/08/17

新井です。

[#30950] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/17

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

[#30951] Re: file exist check method? — Koji Arai <JCA02266@...> 2001/08/17

新井です。

[#30953] Re: file exist check method? — nobu.nakada@... 2001/08/17

なかだです。

[#30954] Re: file exist check method? — Koji Arai <JCA02266@...> 2001/08/17

新井です。

[#30955] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/17

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

[#30956] Re: file exist check method? — Koji Arai <JCA02266@...> 2001/08/17

新井です。

[#30958] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/18

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

[#30962] Re: file exist check method? — Koji Arai <JCA02266@...> 2001/08/18

新井です。

[#30963] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/18

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

[#30965] Re: file exist check method? — Koji Arai <JCA02266@...> 2001/08/18

新井です。

[#30969] Re: file exist check method? — nobu.nakada@... 2001/08/18

なかだです。

[#30970] Re: file exist check method? — Koji Arai <JCA02266@...> 2001/08/18

新井です。

[#30981] Re: file exist check method? — Kazuhiro Yoshida <moriq.kazuhiro@...> 2001/08/18

もりきゅうです。長文ごめんなさい。

[#30983] Re: file exist check method? — IWATSUKI Hiroyuki <don@...> 2001/08/18

岩月と申します。そろそろ寝なくては。

[#30988] Re: file exist check method? — Kazuhiro Yoshida <moriq.kazuhiro@...> 2001/08/19

もりきゅうです。

[#30989] Re: file exist check method? — Kazuhiro Yoshida <moriq.kazuhiro@...> 2001/08/19

もりきゅうです。

[#30997] Re: file exist check method? — nobu.nakada@... 2001/08/19

なかだです。

[#31020] Re: file exist check method? — Kazuhiro Yoshida <moriq.kazuhiro@...> 2001/08/20

もりきゅうです。

[#31022] Re: file exist check method? — maili31s@... (SugHimsi == SUGIHARA Hiroshi) 2001/08/20

すぎむし。

[#31024] Re: file exist check method? — nobu.nakada@... 2001/08/20

なかだです。

[#31025] File#join — Kazuhiro Yoshida <moriq.kazuhiro@...> 2001/08/20

もりきゅうです。subject 変えました。

[#31029] Re: File#join — Kazuhiro NISHIYAMA <zn@...> 2001/08/21

In <200108201823.AA00825@yoshida.nifty.ne.jp>

[#31079] Re: File#join — "K.Umakoshi" <pegacorn@...> 2001/08/22

File#join とか File#split とか使った事ないんですが…

[#31062] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/21

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

[#31065] Re: file exist check method? — nobu.nakada@... 2001/08/22

なかだです。

[#31067] Re: file exist check method? — Kazuhiro Yoshida <moriq.kazuhiro@...> 2001/08/22

もりきゅうです。

[#31068] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/22

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

[#31073] Re: file exist check method? — nobu.nakada@... 2001/08/22

なかだです。

[#31082] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/22

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

[#31087] Re: file exist check method? — nobu.nakada@... 2001/08/23

なかだです。

[#31094] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/23

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

[#31096] Re: file exist check method? — "U.Nakamura" <usa@...> 2001/08/23

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

[#31005] インストールしました — 嶋崎 正貴 <hayashih@...>

嶋崎と申します

15 messages 2001/08/20

[#31144] create_process または Win での外部コマンド実行 — Take_tk <ggb03124@...>

Windows で外部コマンドを実行するにはどういう方法があるのでしょうか?。

33 messages 2001/08/29
[#31145] Re: create_process または Win での外部コマンド実行 — "U.Nakamura" <usa@...> 2001/08/29

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

[#31152] Re: create_process または Win での外部コマンド実行 — nobu.nakada@... 2001/08/29

なかだです。

[#31153] Re: create_process または Win での外部コマンド実行 — Take_tk <ggb03124@...> 2001/08/29

たけ(tk)です。

[ruby-list:31172] Re: file exist check method?

From: nobu.nakada@...
Date: 2001-08-30 14:01:18 UTC
List: ruby-list #31172
なかだです。

At Wed, 29 Aug 2001 22:19:04 +0900,
Kazuhiro Yoshida <moriq.kazuhiro@nifty.ne.jp> wrote:
> > # ところで、Downloadへのリンクが404なんですけど>もりきゅうさん
> ありゃ。置き直しました。ご指摘ありがとうございます。

 extract_file_drive()とかDOSish.joinなどが元のStringを変更して
しまうのはまずいのでは。あとWindows以外でも使えるようにとかなん
とか、もろもろ。

# ruby-devかruby-extに持ってたほうがいいかな。


diff -ru2p dosish-0.0.1/dosish.c dosish/dosish.c
--- dosish-0.0.1/dosish.c	Wed Aug 22 15:52:06 2001
+++ dosish/dosish.c	Thu Aug 30 12:55:55 2001
@@ -1,6 +1,9 @@
 /* for gcc */
+#if defined _WIN32 || defined __CYGWIN__
 #include <windows.h>
+#endif
 
 #include "ruby.h"
+#include "regex.h"
 
 /* Because ruby 1.6 doesn't have StringValuePtr macro, define here */
@@ -11,15 +14,23 @@
 VALUE rb_mDOSish;
 
-#if defined DOSISH
 #define isdirsep(x) ((x) == '/' || (x) == '\\')
-#else
-#define isdirsep(x) ((x) == '/')
+#ifndef CharNext		/* defined as CharNext[AW] on Windows. */
+# if defined(DJGPP)
+#   define CharNext(p) ((p) + mblen(p, MB_CUR_MAX))
+# else
+#   define CharNext(p) ((p) + mbclen(*p))
+# endif
 #endif
 
+static char *strrdirsep _((const char *path));
+static int extract_file_drive _((const char *d));
+static int extract_file_root _((const char *d));
+static void conv_separator _((char *p));
+
 static char *
 strrdirsep(path)
-    char *path;
+    const char *path;
 {
-    char *last = NULL;
+    const char *last = NULL;
     while (*path) {
 	if (isdirsep(*path)) {
@@ -30,35 +41,60 @@ strrdirsep(path)
 	}
     }
-    return last;
+    return (char *)last;
 }
 
-int
+static int
 extract_file_drive(d)
-    char *d;
+    const char *d;
 {
-    char *p;
+    const char *p;
     int len;
     
-    for (p = d; *p; p = CharNext(p)) if (*p == '\\') *p = '/';
-    len = strlen(d);
-    p = d + 1;
-    if (len >= 2 && d[1] == ':') {
+    if (d[0] && d[1] == ':') {
 	return 2;
-    } else if (len >= 2 && d[0] == '/' && d[1] == '/') {
+    }
+    else if (isdirsep(d[0]) && isdirsep(d[1])) {
 	int sepcnt = 0;
-	p = d + 2;
+	const char *last = p = d + 2;
 	while (*p) {
-	    if (*p == '/') {
+	    if (isdirsep(*p)) {
+		last = p++;
 		if (sepcnt++ == 1) break;
 	    }
-	    p++;
+	    else {
+		p = CharNext(p);
+	    }
 	}
-	if (*(p-1) == '/') p--;
+	if (p-1 == last) p = last;
 	return p - d;
-    } else {
+    }
+    else {
 	return 0;
     }
 }
 
+static int
+extract_file_root(d)
+    const char *d;
+{
+    int f = extract_file_drive(d);
+    if (isdirsep(d[f])) ++f;
+    return f;
+}
+
+static void
+conv_separator(p)
+    char *p;
+{
+    while (*p) {
+	if (*p == '\\') {
+	    *p++ = '/';
+	}
+	else {
+	    p = CharNext(p);
+	}
+    }
+}
+
 static VALUE
 rb_file_s_drivename(klass, fname)
@@ -68,48 +104,12 @@ rb_file_s_drivename(klass, fname)
     int f;
     VALUE drivename;
-    
+
     name = StringValuePtr(fname);
     f = extract_file_drive(name);
     drivename = rb_str_new(name, f);
-    
-    if (OBJ_TAINTED(fname)) OBJ_TAINT(drivename);
-    return drivename;
-}
+    conv_separator(RSTRING(drivename)->ptr);
 
-int
-extract_file_root(d)
-    char *d;
-{
-    char *p;
-    int len;
-    
-    for (p = d; *p; p = CharNext(p)) if (*p == '\\') *p = '/';
-    len = strlen(d);
-    if (len >= 2 && d[1] == ':') {
-	if (len >= 3 && d[2] == '/') {
-	    return 3;
-	} else {
-	    return 2;
-	}
-    } else if (len >= 2 && d[0] == '/' && d[1] == '/') {
-	int sepcnt = 0;
-	p = d + 2;
-	while (*p) {
-	    if (*p == '/') {
-		if (sepcnt++ == 1) {
-		    p++;
-		    break;
-		}
-	    }
-	    p++;
-	}
-	return p - d;
-    } else {
-	if (len >= 1 && d[0] == '/') {
-	    return 1;
-	} else {
-	    return 0;
-	}
-    }
+    OBJ_INFECT(drivename, fname);
+    return drivename;
 }
 
@@ -121,10 +121,11 @@ rb_file_s_rootdir(klass, fname)
     int f;
     VALUE rootdir;
-    
+
     name = StringValuePtr(fname);
     f = extract_file_root(name);
     rootdir = rb_str_new(name, f);
-    
-    if (OBJ_TAINTED(fname)) OBJ_TAINT(rootdir);
+    conv_separator(RSTRING(rootdir)->ptr);
+
+    OBJ_INFECT(rootdir, fname);
     return rootdir;
 }
@@ -135,18 +136,17 @@ rb_file_s_dirname(klass, fname)
 {
     char *name, *p;
-    int d, f;
+    int d;
     VALUE dirname;
 
     name = StringValuePtr(fname);
-    p = strrdirsep(name);
-    if (!p) {
-	return rb_str_new2(".");
-    }
-    if (p == name)
-	p++;
     d = extract_file_root(name);
-    f = p - name;
-    dirname = rb_str_new(name, f > d ? f : d);
-    if (OBJ_TAINTED(fname)) OBJ_TAINT(dirname);
+    p = strrdirsep(name + d);
+    if (p)
+	d = p - name;
+    else if (d == 0)
+	return rb_str_new2(".");
+    dirname = rb_str_new(name, d);
+    conv_separator(RSTRING(dirname)->ptr);
+    OBJ_INFECT(dirname, fname);
     return dirname;
 }
@@ -188,17 +188,18 @@ rb_file_s_basename(argc, argv)
     }
     name = StringValuePtr(fname);
+    d = extract_file_root(name);
+    name += d;
     p = strrdirsep(name);
     if (!p) {
-	if (NIL_P(fext) || !(f = rmext(name, ext)))
-	    return fname;
-	basename = rb_str_new(name, f);
+	if (NIL_P(fext) || !(f = rmext(name, ext))) {
+	    if (!d) return fname;
+	    basename = rb_str_new2(name);
+	}
+	else {
+	    basename = rb_str_new(name, f);
+	}
     }
     else {
 	p++;			/* skip last `/' */
-	d = extract_file_root(name);
-	if (d > p - name) {
-	    basename = rb_str_new(0, 0);
-	}
-	else
 	if (NIL_P(fext) || !(f = rmext(p, ext))) {
 	    basename = rb_str_new2(p);
@@ -225,5 +226,6 @@ rb_file_s_split(klass, path)
 #endif
 
-rb_str_uniqsep(str)
+static VALUE
+rb_str_uniqsep_bang(str)
     VALUE str;
 {
@@ -231,6 +233,4 @@ rb_str_uniqsep(str)
     int d;
     int slash;
-    VALUE ary, tmp;
-    char buf[MAXPATHLEN];
     char *p;
 
@@ -241,12 +241,11 @@ rb_str_uniqsep(str)
      *  gsub //+ to / except ^//
      */
+    rb_str_modify(str);
     len = RSTRING(str)->len;
     ptr = RSTRING(str)->ptr;
-    if (len > sizeof(buf))
-	rb_raise(rb_eArgError, "argument too long (size=%d)", len);
-    d = extract_file_root(ptr);
-    slash = (d > 0 && ptr[d-1] == '/');
-    memcpy(buf, ptr, d);
-    p = buf + d;
+    conv_separator(ptr);
+    d = extract_file_drive(ptr);
+    slash = 0;
+    p = ptr + d;
     for (i=d; i<len; i++) {
         if (slash)
@@ -260,6 +259,6 @@ rb_str_uniqsep(str)
 	*p++ = ptr[i];
     }
-    *p = '\0';
-    return rb_str_new2(buf);
+    rb_str_resize(str, p - ptr);
+    return str;
 }
 
@@ -281,5 +280,5 @@ rb_ary_strlist(ary)
 	  case T_ARRAY:
 	    tmp = rb_ary_strlist(tmp);
-	    ret = rb_ary_plus(ret, tmp);
+	    rb_ary_concat(ret, tmp);
 	    break;
 	  default:
@@ -301,14 +300,13 @@ rb_file_s_join(klass, args)
     VALUE ary, str;
 
-    ary = rb_ary_strlist(args);
+    ary = rb_funcall2(args, rb_intern("flatten"), 0, 0);
     for (i=0; i<RARRAY(ary)->len; i++) {
-	str = RARRAY(ary)->ptr[i];
+	RARRAY(ary)->ptr[i] = str = rb_str_dup(RARRAY(ary)->ptr[i]);
 	if (RSTRING(str)->len > 0) {
+	    conv_separator(RSTRING(str)->ptr);
 	    d = extract_file_root(RSTRING(str)->ptr);
 	    if (d == RSTRING(str)->len && RSTRING(str)->ptr[d-1] == '/') {
 		/* chop! */
-		rb_str_modify(str);
 		RSTRING(str)->len--;
-		RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
 	    }
 	}


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

In This Thread