From 0b76820079b17c6e3879a1979687258039bb159f Mon Sep 17 00:00:00 2001 From: fredrik Date: Mon, 5 Jun 2006 02:51:57 +0000 Subject: [PATCH] Allow printing of total size. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@643 959494ce-11ee-0310-bf91-de5d638817bd --- bkselect.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/bkselect.c b/bkselect.c index 6227a5b..7912898 100644 --- a/bkselect.c +++ b/bkselect.c @@ -8,6 +8,10 @@ #include #include +int printsize = 0; +int printnames = 1; +long long tsize = 0; + int bkselect(char *path, int s) { DIR *d; @@ -66,8 +70,9 @@ int bkselect(char *path, int s) if(bkselect(pb, s)) r = 1; } else if(S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode)) { - if(s) + if(s && printnames) printf("%s\n", pb); + tsize += sb.st_size; } } @@ -75,18 +80,39 @@ int bkselect(char *path, int s) return(r); } +void usage(void) +{ + fprintf(stderr, "usage: bkselect [-hsq] path...\n"); +} + int main(int argc, char **argv) { - int i, r; + int c, i, r; - if(argc < 1) { - fprintf(stderr, "usage: bkselect path...\n"); + while((c = getopt(argc, argv, "hsq")) >= 0) { + switch(c) { + case 's': + printsize = 1; + break; + case 'q': + printnames = 0; + break; + case 'h': + default: + usage(); + exit((c == 'h')?0:1); + } + } + if(argc - optind < 1) { + usage(); exit(1); } r = 0; - for(i = 1; i < argc; i++) { + for(i = optind; i < argc; i++) { if(bkselect(argv[i], 0)) r = 1; } + if(printsize) + printf("%lli\n", tsize); return(r); } -- 2.11.0