Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

stat module fixes



-----BEGIN PGP SIGNED MESSAGE-----

This patch fixes a few small problems with Peter's stat module.

1. zll should display the mtime instead of atime.

2. To be more like ls -l, zll should use %e instead of %d to format the
   day of the month in times.

3. I added the module to mods.conf and Modules/Makefile.in.

4. Added some (unsigned long) casts for portability.

5. String form of the mode should default to ?--------- instead of
   ----------; as originally written it isn't possible to distinguish
   between a regular file and an unknown file type.

6. S_ISCHR() was being tested twice.

7. Elements st_{a,m,c}tim in struct stat were being used; these appear to
   be struct timeval.  I haven't seen any system that has these members,
   so I changed it to use the more conventional st_{a,m,c}time, which
   are time_t.  If the systems that have st_{a,m,c}tim don't also support
   st_{a,m,c}time, it'll have to be autoconfed.

 -zefram

 *** Functions/zll	1997/03/17 00:48:01	1.1
 --- Functions/zll	1997/03/17 01:30:18
 ***************
 *** 14,27 ****
   
   for f in $*
   do
 !     stat -sL -A stat -F "%b %d %H:%M" - $f || continue
   
       nlink=$stat[4] 
       uid=$stat[5] 
       gid=$stat[6] 
       size=$stat[8] 
   
 !     print -n -- "$stat[3] $nlink $uid $gid $size $stat[9] $f"
       [[ -n $stat[14] ]] && print -n " -> $stat[14]"
       print
   done
 --- 14,27 ----
   
   for f in $*
   do
 !     stat -sL -A stat -F "%b %e %H:%M" - $f || continue
   
       nlink=$stat[4] 
       uid=$stat[5] 
       gid=$stat[6] 
       size=$stat[8] 
   
 !     print -n -- "$stat[3] $nlink $uid $gid $size $stat[10] $f"
       [[ -n $stat[14] ]] && print -n " -> $stat[14]"
       print
   done
 *** Src/mods.conf	1997/01/29 03:25:19	1.8
 --- Src/mods.conf	1997/03/17 01:08:12
 ***************
 *** 21,26 ****
 --- 21,28 ----
   
   example:	Modules/example.o
   files:		Modules/files.o
 + clone:		Modules/clone.o
 + stat:		Modules/stat.o
   
   comp1:		Zle/comp1.o
   compctl:	Zle/compctl.o
 *** Src/Modules/Makefile.in	1997/01/29 03:25:40	1.17
 --- Src/Modules/Makefile.in	1997/03/17 01:06:01
 ***************
 *** 103,116 ****
   ../signames.h ../system.h ../zsh.h ../ztype.h ../../config.h
   
   # generated prototypes
 ! PROTO = example.pro files.pro clone.pro
   
   # target modules
 ! MODULES = example.so files.so clone.so
   
   # object files
 ! OBJS = example.o files.o clone.o
 ! DOBJS = example..o files..o clone..o
   
   ALLOBJS = $(OBJS) $(DOBJS)
   
 --- 103,116 ----
   ../signames.h ../system.h ../zsh.h ../ztype.h ../../config.h
   
   # generated prototypes
 ! PROTO = example.pro files.pro clone.pro stat.pro
   
   # target modules
 ! MODULES = example.so files.so clone.so stat.so
   
   # object files
 ! OBJS = example.o files.o clone.o stat.o
 ! DOBJS = example..o files..o clone..o stat..o
   
   ALLOBJS = $(OBJS) $(DOBJS)
   
 ***************
 *** 134,139 ****
 --- 134,140 ----
   example.so: example..o
   files.so: files..o
   clone.so: clone..o
 + stat.so: stat..o
   
   # ========== DEPENDENCIES FOR INSTALLING ==========
   
 *** Src/Modules/stat.c	1997/03/17 00:48:03	1.1
 --- Src/Modules/stat.c	1997/03/17 01:14:09
 ***************
 *** 48,60 ****
   statmodeprint(mode_t mode, char *outbuf, int flags)
   {
       if (flags & STF_RAW) {
 ! 	sprintf(outbuf, "%lu", mode);
   	if (flags & STF_STRING)
   	    strcat(outbuf, " (");
       }
       if (flags & STF_STRING) {
   	int ioff, itest;
 ! 	char pm[11] = "----------";
   
   #ifdef S_ISBLK
   	if (S_ISBLK(mode))
 --- 48,60 ----
   statmodeprint(mode_t mode, char *outbuf, int flags)
   {
       if (flags & STF_RAW) {
 ! 	sprintf(outbuf, "%lu", (unsigned long)mode);
   	if (flags & STF_STRING)
   	    strcat(outbuf, " (");
       }
       if (flags & STF_STRING) {
   	int ioff, itest;
 ! 	char pm[11] = "?---------";
   
   #ifdef S_ISBLK
   	if (S_ISBLK(mode))
 ***************
 *** 64,72 ****
   	if (S_ISCHR(mode))
   	    *pm = 'c';
   #endif
 ! #ifdef S_ISCHR
 ! 	if (S_ISCHR(mode))
 ! 	    *pm = 'c';
   #endif
   #ifdef S_ISDIR
   	if (S_ISDIR(mode))
 --- 64,72 ----
   	if (S_ISCHR(mode))
   	    *pm = 'c';
   #endif
 ! #ifdef S_ISREG
 ! 	if (S_ISREG(mode))
 ! 	    *pm = '-';
   #endif
   #ifdef S_ISDIR
   	if (S_ISDIR(mode))
 ***************
 *** 117,123 ****
   statuidprint(uid_t uid, char *outbuf, int flags)
   {
       if (flags & STF_RAW) {
 ! 	sprintf(outbuf, "%lu", uid);
   	if (flags & STF_STRING)
   	    strcat(outbuf, " (");
       }
 --- 117,123 ----
   statuidprint(uid_t uid, char *outbuf, int flags)
   {
       if (flags & STF_RAW) {
 ! 	sprintf(outbuf, "%lu", (unsigned long)uid);
   	if (flags & STF_STRING)
   	    strcat(outbuf, " (");
       }
 ***************
 *** 136,142 ****
   statgidprint(gid_t gid, char *outbuf, int flags)
   {
       if (flags & STF_RAW) {
 ! 	sprintf(outbuf, "%lu", gid);
   	if (flags & STF_STRING)
   	    strcat(outbuf, " (");
       }
 --- 136,142 ----
   statgidprint(gid_t gid, char *outbuf, int flags)
   {
       if (flags & STF_RAW) {
 ! 	sprintf(outbuf, "%lu", (unsigned long)gid);
   	if (flags & STF_STRING)
   	    strcat(outbuf, " (");
       }
 ***************
 *** 156,162 ****
   stattimeprint(time_t tim, char *outbuf, int flags)
   {
       if (flags & STF_RAW) {
 ! 	sprintf(outbuf, "%ld", tim);
   	if (flags & STF_STRING)
   	    strcat(outbuf, " (");
       }
 --- 156,162 ----
   stattimeprint(time_t tim, char *outbuf, int flags)
   {
       if (flags & STF_RAW) {
 ! 	sprintf(outbuf, "%ld", (unsigned long)tim);
   	if (flags & STF_STRING)
   	    strcat(outbuf, " (");
       }
 ***************
 *** 242,256 ****
   	break;
   
       case ST_ATIM:
 ! 	stattimeprint(sbuf->st_atim.tv_sec, optr, flags);
   	break;
   
       case ST_MTIM:
 ! 	stattimeprint(sbuf->st_mtim.tv_sec, optr, flags);
   	break;
   
       case ST_CTIM:
 ! 	stattimeprint(sbuf->st_ctim.tv_sec, optr, flags);
   	break;
   
       case ST_BLKSIZE:
 --- 242,256 ----
   	break;
   
       case ST_ATIM:
 ! 	stattimeprint(sbuf->st_atime, optr, flags);
   	break;
   
       case ST_MTIM:
 ! 	stattimeprint(sbuf->st_mtime, optr, flags);
   	break;
   
       case ST_CTIM:
 ! 	stattimeprint(sbuf->st_ctime, optr, flags);
   	break;
   
       case ST_BLKSIZE:

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: ascii

iQCVAwUBMyyhX3D/+HJTpU/hAQFyhgQAm+k/4loiuHvI2m2KUFDE6SvZmgvA87fh
vFezcthbtk0IEBd3neFE0GFonLkh4hdgHyrV0iLFmSPcStQobgf9+HEa2jEqLLrw
cjHFWMsEQOTsLJc+qVFxH9aaC3F4lL6hbYFSoZ/d1dvMb3XJ6BkhBCfftSSfOK7H
Xn8N0A5Iqw4=
=x9N1
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author