From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17131 invoked from network); 7 Apr 2000 16:26:47 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 7 Apr 2000 16:26:47 -0000 Received: (qmail 2340 invoked by alias); 7 Apr 2000 16:26:33 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10584 Received: (qmail 2327 invoked from network); 7 Apr 2000 16:26:33 -0000 Date: Fri, 07 Apr 2000 17:26:05 +0100 From: Peter Stephenson Subject: Show file modes in octal To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Message-id: <0FSN0077NMZH7B@la-la.cambridgesiliconradio.com> Content-transfer-encoding: 7BIT 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 Cambridge Silicon Radio, Unit 300, Science Park, Milton Road, Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070