From: arton Date: 2001-03-20T14:33:38+09:00 Subject: [ruby-list:28868] Re: patch glob for MSWin32 ruby-1.6.3 artonです。 On Tue, 20 Mar 2001 13:08:18 +0900 nobu.nakada@nifty.ne.jp wrote: > #if defined DOSISH > ! if (len > 2) { > ! if (pend[-2] != ':' && isdirsep(pend[-1])) --len; あんまり有効じゃないような。というのは、has_magic()で、'\'のチェックをし て食っちゃうからですが、 Dir['.\*.c'] -> has_magic() で食われるので、*が消える Dir[".\\*.c"] ->同じ Dir['.\\*.c']  ->has_magic()には耐えるが、パス名としては無効 #has_magic()に、エスケープ文字としての'\'が渡る可能性があるかどうか(文 字列としては展開済みのはずなので、このチェックを削除しても問題ないとは思 うけど、断言できない)、追いきれないのでいじれません。 dir.cの、'/'を生で書いているところを全部、潰したけど上述の理由で、\をセ パレータに使うとだめ。 UNCは\\で書いていいものなのか。現時点では p Dir['//host/dir/*.c'] のパターンはダメです。 *** dir.c.org Tue Mar 20 09:46:53 2001 --- dir.c Tue Mar 20 13:59:13 2001 *************** extract_path(p, pend) *** 533,550 **** int len; len = pend - p; - alloc = ALLOC_N(char, len+1); - memcpy(alloc, p, len); - if (len > 1 && pend[-1] == '/' #if defined DOSISH ! && len > 2 && pend[-2] != ':' ! #endif ! ) { ! alloc[len-1] = 0; ! } ! else { ! alloc[len] = 0; } return alloc; } --- 533,549 ---- int len; len = pend - p; #if defined DOSISH ! if (len > 2) { ! if (pend[-2] != ':' && isdirsep(pend[-1])) --len; } + else + #endif + if (len > 1 && isdirsep(pend[-1])) --len; + + alloc = ALLOC_N(char, len+1); + memcpy(alloc, p, len); + alloc[len] = 0; return alloc; } *************** extract_elem(path) *** 555,561 **** { char *pend; ! pend = strchr(path, '/'); if (!pend) pend = path + strlen(path); return extract_path(path, pend); --- 554,560 ---- { char *pend; ! pend = find_dirsep(path); if (!pend) pend = path + strlen(path); return extract_path(path, pend); *************** rb_glob_helper(path, flag, func, arg) *** 584,591 **** p = path; while (p) { ! if (*p == '/') p++; ! m = strchr(p, '/'); if (has_magic(p, m)) { char *dir, *base, *magic, *buf; DIR *dirp; --- 583,590 ---- p = path; while (p) { ! if (isdirsep(*p)) p++; ! m = find_dirsep(p); if (has_magic(p, m)) { char *dir, *base, *magic, *buf; DIR *dirp; -- arton