zsh-workers
 help / color / mirror / code / Atom feed
* Show file modes in octal
@ 2000-04-07 16:26 Peter Stephenson
  2000-04-07 17:55 ` Zefram
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2000-04-07 16:26 UTC (permalink / raw)
  To: Zsh hackers list

The stat module shows file modes in decimal, which is logical if it is
printing raw numbers, but not very readable.  This allows the option -o to
show a raw mode in octal.  It doesn't affect the format of an ls-like
mode.

By the way, what's going on here?

% cd Src/Modules
% MODULE_PATH=.
% zmodload
zsh/complete
zsh/compctl
zsh/zutil
zsh/main
zsh/zle
zsh/parameter
% zmodload stat
zsh: failed to load module: zsh/stat

I didn't ask it to, and the stat module in the current directory is the
real one.  How is it finding the alias?

This will be committed later on.

Index: Doc/Zsh/mod_stat.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_stat.yo,v
retrieving revision 1.1.1.8
diff -u -u -r1.1.1.8 mod_stat.yo
--- Doc/Zsh/mod_stat.yo	1999/12/20 11:24:39	1.1.1.8
+++ Doc/Zsh/mod_stat.yo	2000/04/07 16:19:56
@@ -7,7 +7,7 @@
 findex(stat)
 cindex(files, listing)
 cindex(files, examining)
-item(tt(stat) [ tt(-gnNlLtTrs) ] [ tt(-f) var(fd) ] \
+item(tt(stat) [ tt(-gnNolLtTrs) ] [ tt(-f) var(fd) ] \
     [ tt(-H) var(hash) ] [ tt(-A) var(array) ] \
     [ tt(-F) var(fmt) ] [ tt(PLUS())var(element) ] [ var(file) ... ])(
 The command acts as a front end to the tt(stat) system call (see
@@ -128,6 +128,13 @@
 )
 item(tt(-N))(
 Never show the names of files.
+)
+item(tt(-o))(
+If a raw file mode is printed, show it in octal, which is more useful for
+human consumption than the default of decimal.  A leading zero will be
+printed in this case.  Note that this does not affect whether a raw or
+formatted file mode is shown, which is controlled by the tt(-r) and tt(-s)
+options, nor whether a mode is shown at all.
 )
 item(tt(-r))(
 Print raw data (the default format) alongside string
Index: Src/Modules/stat.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/stat.c,v
retrieving revision 1.1.1.13
diff -u -u -r1.1.1.13 stat.c
--- Src/Modules/stat.c	2000/03/14 11:17:59	1.1.1.13
+++ Src/Modules/stat.c	2000/04/07 16:19:56
@@ -35,7 +35,7 @@
 		   ST_BLKSIZE, ST_BLOCKS, ST_READLINK, ST_COUNT };
 enum statflags { STF_NAME = 1,  STF_FILE = 2, STF_STRING = 4, STF_RAW = 8,
 		     STF_PICK = 16, STF_ARRAY = 32, STF_GMT = 64,
-		     STF_HASH = 128 };
+		     STF_HASH = 128, STF_OCTAL = 256 };
 static char *statelts[] = { "device", "inode", "mode", "nlink",
 				"uid", "gid", "rdev", "size", "atime",
 				"mtime", "ctime", "blksize", "blocks",
@@ -47,7 +47,8 @@
 statmodeprint(mode_t mode, char *outbuf, int flags)
 {
     if (flags & STF_RAW) {
-	sprintf(outbuf, "%lu", (unsigned long)mode);
+	sprintf(outbuf, (flags & STF_OCTAL) ? "0%lo" : "%lu",
+		(unsigned long)mode);
 	if (flags & STF_STRING)
 	    strcat(outbuf, " (");
     }
@@ -359,7 +360,7 @@
 	    flags |= STF_PICK;
 	} else {
 	    for (; *arg; arg++) {
-		if (strchr("glLnNrstT", *arg))
+		if (strchr("glLnNorstT", *arg))
 		    ops[STOUC(*arg)] = 1;
 		else if (*arg == 'A') {
 		    if (arg[1]) {
@@ -472,6 +473,8 @@
 	flags |= STF_RAW;
     if (ops['n'])
 	flags |= STF_FILE;
+    if (ops['o'])
+	flags |= STF_OCTAL;
     if (ops['t'])
 	flags |= STF_NAME;
 

-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Show file modes in octal
  2000-04-07 16:26 Show file modes in octal Peter Stephenson
@ 2000-04-07 17:55 ` Zefram
  2000-04-07 20:05   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Zefram @ 2000-04-07 17:55 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

Peter Stephenson wrote:
>% zmodload stat
>zsh: failed to load module: zsh/stat
>
>I didn't ask it to, and the stat module in the current directory is the
>real one.  How is it finding the alias?

The alias is implemented as a dependency.  Dependencies are still handled
statically; I've been considering ways to keep dependency information
in the module file, but not actually tried anything out yet.

Yes, it's confusing.

-zefram


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Show file modes in octal
  2000-04-07 17:55 ` Zefram
@ 2000-04-07 20:05   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2000-04-07 20:05 UTC (permalink / raw)
  To: Zsh hackers list

Zefram wrote:
> Peter Stephenson wrote:
> >% zmodload stat
> >zsh: failed to load module: zsh/stat
> >
> >I didn't ask it to, and the stat module in the current directory is the
> >real one.  How is it finding the alias?
> 
> The alias is implemented as a dependency.  Dependencies are still handled
> statically; I've been considering ways to keep dependency information
> in the module file, but not actually tried anything out yet.
> 
> Yes, it's confusing.

Hmph.  I still prefer my original suggestion: make aliases an internal
matter under zmodload control.  That way the user has full control, can see
straight away what's aliased to what, can change it, isn't forced to load
files by a bolshie computer, can add aliases for compatibility purposes
unforeseen by the developers/installer, and doesn't have 100k of no-op
lying on the disk.

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@CambridgeSiliconRadio.com
Web: http://www.pwstephenson.fsnet.co.uk


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-04-07 20:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-07 16:26 Show file modes in octal Peter Stephenson
2000-04-07 17:55 ` Zefram
2000-04-07 20:05   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).