mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* dir.c: merge tuning from H.Yamamoto <ocean@m2.ccsnet.ne.jp>.
[ruby-dev:22486] * pack.c (pack_unpack): unpack requires big endian offet (OFF16B and OFF32B). The patch is from Minero Aoki in [ruby-dev:22489] * pack.c (OFF16B): add big-endian offset again. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7336cf5424
commit
caaac4db27
6 changed files with 90 additions and 29 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Mon Jan 5 18:58:47 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* dir.c: merge tuning from H.Yamamoto <ocean@m2.ccsnet.ne.jp>.
|
||||
[ruby-dev:22486]
|
||||
|
||||
* pack.c (pack_unpack): unpack requires big endian offet (OFF16B
|
||||
and OFF32B). The patch is from Minero Aoki in [ruby-dev:22489]
|
||||
|
||||
* pack.c (OFF16B): add big-endian offset again.
|
||||
|
||||
Mon Jan 5 03:00:53 2004 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* test/ruby/test_pack.rb: new test test_unpack_N.
|
||||
|
|
34
dir.c
34
dir.c
|
@ -235,7 +235,7 @@ fnmatch(pat, string, flags)
|
|||
INC_S();
|
||||
}
|
||||
return FNM_NOMATCH;
|
||||
|
||||
|
||||
case '[':
|
||||
if (!*s || ISDIRSEP(*s) || PERIOD_S())
|
||||
return FNM_NOMATCH;
|
||||
|
@ -1041,7 +1041,7 @@ glob_helper(path, sub, separator, flags, func, arg) /* if separator p[-1] is rem
|
|||
}
|
||||
|
||||
if (p[0] == '*' && p[1] == '*' && p[2] == '/') {
|
||||
char *t = p+3;
|
||||
char *t = p + 3;
|
||||
while (t[0] == '*' && t[1] == '*' && t[2] == '/') t += 3;
|
||||
memmove(p, t, strlen(t)+1); /* move '\0' too */
|
||||
magical = has_magic(p, &m, flags); /* next element */
|
||||
|
@ -1053,7 +1053,7 @@ glob_helper(path, sub, separator, flags, func, arg) /* if separator p[-1] is rem
|
|||
if (dirp == NULL) return 0;
|
||||
}
|
||||
else {
|
||||
char *t = separator ? p-1 : p;
|
||||
char *t = separator ? p - 1 : p;
|
||||
char c = *t;
|
||||
*t = '\0';
|
||||
dirp = do_opendir(path);
|
||||
|
@ -1065,23 +1065,29 @@ glob_helper(path, sub, separator, flags, func, arg) /* if separator p[-1] is rem
|
|||
const int n1 = p - path;
|
||||
const int n2 = n1 + NAMLEN(dp);
|
||||
const int ok = 0;
|
||||
const int no = 1;
|
||||
const int ln = 1;
|
||||
const int no = 2;
|
||||
int is_dir = -1; /* not checked yet */
|
||||
#ifdef _WIN32
|
||||
is_dir = dp->d_isdir ? (dp->d_isrep ? ln : ok) : no;
|
||||
#endif
|
||||
if (recursive && strcmp(".", dp->d_name) != 0 && strcmp("..", dp->d_name) != 0) {
|
||||
buf = ALLOC_N(char, n2+4+strlen(p)+1);
|
||||
memcpy(buf, path, n1);
|
||||
strcpy(buf+n1, dp->d_name);
|
||||
#ifndef _WIN32
|
||||
is_dir = no;
|
||||
if (do_lstat(buf, &st) == 0) {
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
strcpy(buf+n2, "/**/");
|
||||
strcpy(buf+n2+4, p);
|
||||
status = glob_helper(buf, buf+n2+1, 1, flags, func, arg);
|
||||
is_dir = ok;
|
||||
}
|
||||
else if (S_ISLNK(st.st_mode) && do_stat(buf, &st) == 0 && S_ISDIR(st.st_mode)) {
|
||||
is_dir = ok;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode))
|
||||
is_dir = ok;
|
||||
else if (S_ISLNK(st.st_mode) && do_stat(buf, &st) == 0 && S_ISDIR(st.st_mode))
|
||||
is_dir = ln;
|
||||
}
|
||||
#endif
|
||||
if (is_dir == ok) {
|
||||
strcpy(buf+n2, "/**/");
|
||||
strcpy(buf+n2+4, p);
|
||||
status = glob_helper(buf, buf+n2+1, 1, flags, func, arg);
|
||||
}
|
||||
free(buf);
|
||||
if (status) break;
|
||||
|
@ -1096,7 +1102,7 @@ glob_helper(path, sub, separator, flags, func, arg) /* if separator p[-1] is rem
|
|||
if (*m == '\0') {
|
||||
status = glob_call_func(func, buf, arg);
|
||||
}
|
||||
else if (m[1] == '\0' && is_dir == ok) { /* *m == '/' */
|
||||
else if (m[1] == '\0' && (is_dir == ok || is_dir == ln)) { /* *m == '/' */
|
||||
strcpy(buf+n2, "/");
|
||||
status = glob_call_func(func, buf, arg);
|
||||
}
|
||||
|
|
|
@ -964,7 +964,10 @@ balanced expression is found."
|
|||
;; get current method (or class/module)
|
||||
(if (re-search-backward
|
||||
(concat "^[ \t]*\\(def\\|class\\|module\\)[ \t]+"
|
||||
"\\(" ruby-symbol-re "+\\)")
|
||||
"\\("
|
||||
;; \\. for class method
|
||||
"\\(" ruby-symbol-re "\\|\\." "\\)"
|
||||
"+\\)")
|
||||
nil t)
|
||||
(progn
|
||||
(setq mlist (list (match-string 2)))
|
||||
|
|
14
pack.c
14
pack.c
|
@ -22,12 +22,14 @@
|
|||
#endif
|
||||
|
||||
#ifdef NATINT_PACK
|
||||
# define OFF16B(p) ((char*)(p) + (natint?0:(sizeof(short) - SIZE16)))
|
||||
# define OFF32B(p) ((char*)(p) + (natint?0:(sizeof(long) - SIZE32)))
|
||||
# define NATINT_I32(x) (natint?NUM2LONG(x):(NUM2I32(x)))
|
||||
# define NATINT_U32(x) (natint?NUM2ULONG(x):(NUM2U32(x)))
|
||||
# define NATINT_LEN(type,len) (natint?sizeof(type):(len))
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
# define OFF16(p) ((char*)(p) + (natint?0:(sizeof(short) - SIZE16)))
|
||||
# define OFF32(p) ((char*)(p) + (natint?0:(sizeof(long) - SIZE32)))
|
||||
# define OFF16(p) OFF16B(p)
|
||||
# define OFF32(p) OFF32B(p)
|
||||
# endif
|
||||
# define NATINT_HTOVS(x) (natint?htovs(x):htov16(x))
|
||||
# define NATINT_HTOVL(x) (natint?htovl(x):htov32(x))
|
||||
|
@ -47,6 +49,10 @@
|
|||
# define OFF16(p) (char*)(p)
|
||||
# define OFF32(p) (char*)(p)
|
||||
#endif
|
||||
#ifndef OFF16B
|
||||
# define OFF16B(p) (char*)(p)
|
||||
# define OFF32B(p) (char*)(p)
|
||||
#endif
|
||||
|
||||
#define define_swapx(x, xtype) \
|
||||
static xtype \
|
||||
|
@ -1648,7 +1654,7 @@ pack_unpack(str, fmt)
|
|||
PACK_LENGTH_ADJUST(unsigned short,2);
|
||||
while (len-- > 0) {
|
||||
unsigned short tmp = 0;
|
||||
memcpy(OFF16(&tmp), s, NATINT_LEN(unsigned short,2));
|
||||
memcpy(OFF16B(&tmp), s, NATINT_LEN(unsigned short,2));
|
||||
s += NATINT_LEN(unsigned short,2);
|
||||
rb_ary_push(ary, UINT2NUM(ntohs(tmp)));
|
||||
}
|
||||
|
@ -1659,7 +1665,7 @@ pack_unpack(str, fmt)
|
|||
PACK_LENGTH_ADJUST(unsigned long,4);
|
||||
while (len-- > 0) {
|
||||
unsigned long tmp = 0;
|
||||
memcpy(OFF32(&tmp), s, NATINT_LEN(unsigned long,4));
|
||||
memcpy(OFF32B(&tmp), s, NATINT_LEN(unsigned long,4));
|
||||
s += NATINT_LEN(unsigned long,4);
|
||||
rb_ary_push(ary, ULONG2NUM(ntohl(tmp)));
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ struct direct
|
|||
long d_namlen;
|
||||
ino_t d_ino;
|
||||
char d_name[256];
|
||||
char d_isdir; /* directory */
|
||||
char d_isrep; /* reparse point */
|
||||
char d_isdir;
|
||||
};
|
||||
typedef struct {
|
||||
|
@ -17,6 +19,8 @@ typedef struct {
|
|||
char *curr;
|
||||
long size;
|
||||
long nfiles;
|
||||
char *bits; /* used for d_isdir and d_isrep */
|
||||
long bitpos; /* used for d_isdir and d_isrep */
|
||||
struct direct dirstr;
|
||||
char *bits;
|
||||
long bitpos;
|
||||
|
|
|
@ -1323,6 +1323,9 @@ make_cmdvector(const char *cmd, char ***vec)
|
|||
// return the pointer to the current file name.
|
||||
//
|
||||
|
||||
#define GetBit(bits, i) ((bits)[(i) / 8] & (1 << (i) % 8))
|
||||
#define SetBit(bits, i) ((bits)[(i) / 8] |= (1 << (i) % 8))
|
||||
|
||||
DIR *
|
||||
rb_w32_opendir(const char *filename)
|
||||
{
|
||||
|
@ -1332,8 +1335,8 @@ rb_w32_opendir(const char *filename)
|
|||
char scannamespc[PATHLEN];
|
||||
char *scanname = scannamespc;
|
||||
struct stat sbuf;
|
||||
struct _finddata_t fd;
|
||||
long fh;
|
||||
WIN32_FIND_DATA fd;
|
||||
HANDLE fh;
|
||||
|
||||
//
|
||||
// check to see if we've got a directory
|
||||
|
@ -1371,8 +1374,8 @@ rb_w32_opendir(const char *filename)
|
|||
// do the FindFirstFile call
|
||||
//
|
||||
|
||||
fh = _findfirst(scanname, &fd);
|
||||
if (fh == -1) {
|
||||
fh = FindFirstFile(scanname, &fd);
|
||||
if (fh == INVALID_HANDLE_VALUE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1381,9 +1384,15 @@ rb_w32_opendir(const char *filename)
|
|||
// filenames that we find.
|
||||
//
|
||||
|
||||
idx = strlen(fd.name)+1;
|
||||
idx = strlen(fd.cFileName)+1;
|
||||
p->start = ALLOC_N(char, idx);
|
||||
strcpy(p->start, fd.name);
|
||||
strcpy(p->start, fd.cFileName);
|
||||
p->bits = ALLOC_N(char, 1);
|
||||
p->bits[0] = 0;
|
||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
SetBit(p->bits, 0);
|
||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
|
||||
SetBit(p->bits, 1);
|
||||
p->bits = ALLOC_N(char, 1);
|
||||
p->bits[0] = fd.attrib & _A_SUBDIR ? 1 : 0;
|
||||
p->nfiles++;
|
||||
|
@ -1394,8 +1403,8 @@ rb_w32_opendir(const char *filename)
|
|||
// the variable idx should point one past the null terminator
|
||||
// of the previous string found.
|
||||
//
|
||||
while (_findnext(fh, &fd) == 0) {
|
||||
len = strlen(fd.name);
|
||||
while (FindNextFile(fh, &fd)) {
|
||||
len = strlen(fd.cFileName);
|
||||
|
||||
//
|
||||
// bump the string table size by enough for the
|
||||
|
@ -1408,7 +1417,20 @@ rb_w32_opendir(const char *filename)
|
|||
if (p->start == NULL) {
|
||||
rb_fatal ("opendir: malloc failed!\n");
|
||||
}
|
||||
strcpy(&p->start[idx], fd.name);
|
||||
strcpy(&p->start[idx], fd.cFileName);
|
||||
|
||||
if (p->nfiles % 4 == 0) {
|
||||
Renew (p->bits, p->nfiles / 4 + 1, char);
|
||||
if (p->bits == NULL) {
|
||||
rb_fatal ("opendir: malloc failed!\n");
|
||||
}
|
||||
p->bits[p->nfiles / 4] = 0;
|
||||
}
|
||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
SetBit(p->bits, p->nfiles * 2);
|
||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
|
||||
SetBit(p->bits, p->nfiles * 2 + 1);
|
||||
|
||||
|
||||
if (p->nfiles % 8 == 0) {
|
||||
Renew (p->bits, p->nfiles / 8 + 1, char);
|
||||
|
@ -1424,7 +1446,7 @@ rb_w32_opendir(const char *filename)
|
|||
p->nfiles++;
|
||||
idx += len+1;
|
||||
}
|
||||
_findclose(fh);
|
||||
FindClose(fh);
|
||||
p->size = idx;
|
||||
p->curr = p->start;
|
||||
return p;
|
||||
|
@ -1463,6 +1485,14 @@ rb_w32_readdir(DIR *dirp)
|
|||
dirp->dirstr.d_isdir = dirp->bits[dirp->bitpos / 8] & (1 << dirp->bitpos % 8);
|
||||
dirp->bitpos++;
|
||||
|
||||
//
|
||||
// Attributes
|
||||
//
|
||||
dirp->dirstr.d_isdir = GetBit(dirp->bits, dirp->bitpos);
|
||||
dirp->bitpos++;
|
||||
dirp->dirstr.d_isrep = GetBit(dirp->bits, dirp->bitpos);
|
||||
dirp->bitpos++;
|
||||
|
||||
//
|
||||
// Now set up for the next call to readdir
|
||||
//
|
||||
|
@ -1507,6 +1537,7 @@ rb_w32_rewinddir(DIR *dirp)
|
|||
{
|
||||
dirp->curr = dirp->start;
|
||||
dirp->bitpos = 0;
|
||||
dirp->bitpos = 0;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -1516,6 +1547,7 @@ rb_w32_rewinddir(DIR *dirp)
|
|||
void
|
||||
rb_w32_closedir(DIR *dirp)
|
||||
{
|
||||
free(dirp->bits);
|
||||
free(dirp->start);
|
||||
free(dirp->bits);
|
||||
free(dirp);
|
||||
|
|
Loading…
Reference in a new issue