X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=cprogs%2Fsummer.c;h=762b5d68812ac0b5e20d86ce65745bb40b6a5e06;hp=66c790a0fe8e6c7810979835a5fd085a0c844bcb;hb=b075ddbfbdbf7d15d9f0c43d7316533cf9ed6229;hpb=506a099cb9d0200b394d19c17d6dc9a3478b9917 diff --git a/cprogs/summer.c b/cprogs/summer.c index 66c790a..762b5d6 100644 --- a/cprogs/summer.c +++ b/cprogs/summer.c @@ -47,7 +47,7 @@ #define CSUMXL 32 static int quiet=0, hidectime=0, hideatime=0, hidemtime=0; -static int hidedirsize=0, hidelinkmtime=0, onefilesystem=0; +static int hidedirsize=0, hidelinkmtime=0, hidextime=0, onefilesystem=0; static int filenamefieldsep=' '; static FILE *errfile; @@ -163,6 +163,28 @@ static void linktargpath(const char *linktarg) { fn_escaped(stdout, linktarg); } +static void pu10(void) { printf(" %10s", "?"); } + +#define PTIME(stab, memb) ((stab) ? ptime((stab), (stab)->memb) : pu10()) + +static void ptime(const struct stat *stab, unsigned long val) { + const char *instead; + + if (!hidextime) goto justprint; + else if (S_ISCHR(stab->st_mode)) instead= "char"; + else if (S_ISBLK(stab->st_mode)) instead= "block"; + else if (S_ISLNK(stab->st_mode)) instead= "link"; + else if (S_ISSOCK(stab->st_mode)) instead= "sock"; + else if (S_ISFIFO(stab->st_mode)) instead= "pipe"; + else { + justprint: + printf(" %10lu", val); + return; + } + + printf(" %10s",instead); +} + struct hardlink { dev_t dev; ino_t ino; @@ -170,8 +192,6 @@ struct hardlink { }; static void *hardlinks; -static void pu10(void) { printf(" %10s", "?"); } - static int hardlink_compar(const void *av, const void *bv) { const struct hardlink *a=av, *b=bv; if (a->ino != b->ino) return b->ino - a->ino; @@ -250,32 +270,18 @@ static void node(const char *path, unsigned nodeflags, dev_t fs) { printf(" %10s %4s %10s %10s", "?","?","?","?"); } - if (!hideatime) { - if (stab) - printf(" %10lu", - (unsigned long)stab->st_atime); - else - pu10(); - } + if (!hideatime) + PTIME(stab, st_atime); if (!hidemtime) { - if (stab) - if (S_ISLNK(stab->st_mode) && hidelinkmtime) - printf(" %10s","link"); - else - printf(" %10lu", - (unsigned long)stab->st_mtime); + if (stab && S_ISLNK(stab->st_mode) && hidelinkmtime) + printf(" %10s","link"); else - pu10(); + PTIME(stab, st_mtime); } - if (!hidectime) { - if (stab) - printf(" %10lu", - (unsigned long)stab->st_ctime); - else - pu10(); - } + if (!hidectime) + PTIME(stab, st_ctime); putchar(filenamefieldsep); fn_escaped(stdout, path); @@ -313,8 +319,7 @@ static int recurse_filter(const struct dirent *de) { return 1; } -static int recurse_compar(const void *av, const void *bv) { - const struct dirent *const *a=av, *const *b=bv; +static int recurse_compar(const struct dirent **a, const struct dirent **b) { return strcmp((*a)->d_name, (*b)->d_name); } @@ -401,6 +406,9 @@ int main(int argc, const char *const *argv) { case 'b': hidelinkmtime= 1; break; + case 'B': + hidextime= 1; + break; case 'x': onefilesystem= 1; break;