[#30827] 正規表現まわりの parse — sheepman <sheepman@...>
こんにちは。
[#30850] ruby-mode.el の改善案 — sheepman <sheepman@...>
こんにちは。
[#30852] Ruby/Tk on Windows — hidaka@... (HIDAKA Takahiro)
ひだかです。
[#30855] オブジェクトをソースへ — Daisuke Aoki <dai@...>
青木@横浜です。
[#30872] ext/curses — Takaaki Tateishi <ttate@...>
立石です.
[#30885] SAGE — "Shin'ya Adzumi" <adzumi@...>
あづみです。
[#30897] ActiveScriptRuby + showModalDialog — keiichi matsunaga <ma2@...>
松永です。
[#30920] [REQ] Regexp#match! — Minero Aoki <aamine@...>
あおきです。
At Thu, 16 Aug 2001 11:24:45 +0900,
[#30945] file exist check method? — "Inoue" <inoue@...>
井上です。
こんにちは、なかむら(う)です。
新井です。
こんにちは、なかむら(う)です。
新井です。
なかだです。
新井です。
こんにちは、なかむら(う)です。
新井です。
こんにちは、なかむら(う)です。
新井です。
こんにちは、なかむら(う)です。
新井です。
なかだです。
新井です。
こんにちは、なかむら(う)です。
新井です。
もりきゅうです。長文ごめんなさい。
岩月と申します。そろそろ寝なくては。
もりきゅうです。
もりきゅうです。
なかだです。
もりきゅうです。
すぎむし。
なかだです。
もりきゅうです。subject 変えました。
In <200108201823.AA00825@yoshida.nifty.ne.jp>
File#join とか File#split とか使った事ないんですが…
なかだです。
From: nobu.nakada@nifty.ne.jp
In <20010823.222131.74756515.pegacorn@jcom.home.ne.jp>
こんにちは、なかむら(う)です。
なかだです。
もりきゅうです。
こんにちは、なかむら(う)です。
なかだです。
こんにちは、なかむら(う)です。
なかだです。
こんにちは、なかむら(う)です。
こんにちは、なかむら(う)です。
なかだです。
こんにちは、なかむら(う)です。
なかだです。
こんにちは、なかむら(う)です。
なかだです。
[#30961] popen() で Insecure PATH — 堀川 久 <vzw00011@...>
こんにちは。
まつもと ゆきひろです
こんにちは。
In <3b7e90ac.6968%vzw00011@nifty.ne.jp>
[#30987] [REQ] String#slice(re, n) — Minero Aoki <aamine@...>
あおきです。
[#31002] ruby のインストール — Andre Ribeiro Hanai <andre@...>
始めまして葉内です。
[#31005] インストールしました — 嶋崎 正貴 <hayashih@...>
嶋崎と申します
From: 嶋崎 正貴 <hayashih@interbroad.or.jp>
[#31035] 安全な文字列の評価方法 — 斉藤和樹 <QZS01353@...>
こんにちは。斉藤です。
[#31060] WIN32OLE の質問 : 環境変数の設定はどうやる? — Hirofumi Tamori <tamori@...>
[#31066] [Q] string underline in emacs — "K.Kosako" <kosako@...>
emacs 20.7.2でruby-mode.elを使用しています。
[#31069] ruby と mysql の使える webhosting — Ryuichiro Hara <ruby@...>
FAQかもしれないのですが...
[#31071] ruby on sun — Koichi Takehara <Koichi.Takehara@...>
ルビー初心者の竹原です。
[#31128] Ruby.exe で実行中は編集禁止? — Take_tk <ggb03124@...>
Ruby.exe(ruby 1.6.4 (2001-06-04) [i586-mswin32])で一日中回しているスク
[#31144] create_process または Win での外部コマンド実行 — Take_tk <ggb03124@...>
Windows で外部コマンドを実行するにはどういう方法があるのでしょうか?。
こんにちは、なかむら(う)です。
なかだです。
たけ(tk)です。
なかだです。
たけ(tk)です。
なかだです。
In message <200108291540.f7TFecg03766@sharui.nakada.kanuma.tochigi.jp>
[ruby-list:31172] Re: file exist check method?
なかだです。
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はできる。
中田 伸悦