新井です。

>>> From: Koji Arai <JCA02266 / nifty.ne.jp>
>>> Date: 18 Jun 2000 13:55:12 +0900
>>> Subject: [ruby-dev:10078] Re: File::Stat#inspect

> 新井です。

> > ううむ、なんだか情報が多いですねえ。元々多いんでしょうがない
> > と思うべきか、それとも...
> 
> では、こういうのはどうでしょう?

ちょっと訂正。


Sun Jun 18 15:59:57 2000 Koji Arai <JCA02266 / nifty.ne.jp> * file.c (rb_stat_inspect): added to give readable form which is like `ls' output. Index: configure.in =================================================================== RCS file: /home/cvs/ruby/configure.in,v retrieving revision 1.35 diff -u -p -u -r1.35 configure.in --- configure.in 2000/06/16 12:41:06 1.35 +++ configure.in 2000/06/18 15:59:54 @@ -194,6 +194,7 @@ AC_CHECK_LIB(dld, shl_load) # Dynamic li dnl Checks for header files. AC_HEADER_DIRENT +AC_HEADER_MAJOR AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\ Index: file.c =================================================================== RCS file: /home/cvs/ruby/file.c,v retrieving revision 1.29 diff -u -p -u -r1.29 file.c --- file.c 2000/06/12 07:48:19 1.29 +++ file.c 2000/06/18 15:59:57 @@ -69,7 +69,25 @@ char *strrchr _((const char*,const char) #ifdef __EMX__ #define lstat stat #endif - + +#ifdef MAJOR_IN_MKDEV +# include <sys/mkdev.h> +# define HAVE_MAJOR +#endif +#ifdef MAJOR_IN_SYSMACROS +# include <sys/sysmacros.h> +# define HAVE_MAJOR +#endif +#ifdef major +# define HAVE_MAJOR +#endif + +#ifndef HAVE_MAJOR +# define major(dev) (((dev) >> 8) & 0xff) +# define minor(dev) ((dev) & 0xff) +# define makedev(maj, min) (((maj) << 8) | (min)) +#endif + VALUE rb_cFile; VALUE rb_mFileTest; static VALUE rb_cStat; @@ -1933,6 +1951,47 @@ rb_stat_sticky(obj) return Qfalse; } +static VALUE +rb_stat_inspect(self) + VALUE self; +{ + VALUE str; + char tmp[256]; + + str = rb_str_new2("#<"); + rb_str_cat2(str, rb_class2name(CLASS_OF(self))); + + sprintf(tmp, " %06o", FIX2UINT(rb_stat_mode(self))); + rb_str_cat2(str, tmp); + + sprintf(tmp, " %3u", FIX2UINT(rb_stat_nlink(self))); + rb_str_cat2(str, tmp); + + sprintf(tmp, " %-8u", FIX2UINT(rb_stat_uid(self))); + rb_str_cat2(str, tmp); + + sprintf(tmp, " %-8u", FIX2UINT(rb_stat_gid(self))); + rb_str_cat2(str, tmp); + + if (rb_stat_b(self) || rb_stat_c(self)) { + unsigned int dev = FIX2UINT(rb_stat_rdev(self)); + sprintf(tmp, " %3u, %3u", major(dev), minor(dev)); + } + else { + sprintf(tmp, " %8lu", FIX2ULONG(rb_stat_size(self))); + } + + rb_str_cat2(str, tmp); + + rb_str_cat2(str, " "); + rb_str_append(str, rb_inspect(rb_stat_mtime(self))); + + rb_str_cat2(str, ">"); + OBJ_INFECT(str, self); + + return str; +} + static VALUE rb_mConst; void @@ -2241,4 +2300,6 @@ Init_File() rb_define_method(rb_cStat, "setuid?", rb_stat_suid, 0); rb_define_method(rb_cStat, "setgid?", rb_stat_sgid, 0); rb_define_method(rb_cStat, "sticky?", rb_stat_sticky, 0); + + rb_define_method(rb_cStat, "inspect", rb_stat_inspect, 0); } -- 新井康司 (Koji Arai)