diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-04-24 03:53:12 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-04-24 03:53:12 +0000 |
commit | f06c4946368c3e60dda0f66e2729ae05d02621ca (patch) | |
tree | bc505213b55b91049c4224e8485fc52695bb62f4 /coreutils/stat.c | |
parent | 058e740d1e58604b37e2c94c505cd204eef32667 (diff) | |
download | busybox-w32-f06c4946368c3e60dda0f66e2729ae05d02621ca.tar.gz busybox-w32-f06c4946368c3e60dda0f66e2729ae05d02621ca.tar.bz2 busybox-w32-f06c4946368c3e60dda0f66e2729ae05d02621ca.zip |
rework options to get rid of extra variables
Diffstat (limited to 'coreutils/stat.c')
-rw-r--r-- | coreutils/stat.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/coreutils/stat.c b/coreutils/stat.c index e386d75a0..536873fdc 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
@@ -36,8 +36,9 @@ | |||
36 | #include "busybox.h" | 36 | #include "busybox.h" |
37 | 37 | ||
38 | /* vars to control behavior */ | 38 | /* vars to control behavior */ |
39 | static int follow_links = 0; | 39 | #define OPT_TERSE 2 |
40 | static int terse = 0; | 40 | #define OPT_DEREFERNCE 4 |
41 | static long flags; | ||
41 | 42 | ||
42 | static char const *file_type(struct stat const *st) | 43 | static char const *file_type(struct stat const *st) |
43 | { | 44 | { |
@@ -425,7 +426,7 @@ static int do_statfs(char const *filename, char const *format) | |||
425 | 426 | ||
426 | #ifdef CONFIG_FEATURE_STAT_FORMAT | 427 | #ifdef CONFIG_FEATURE_STAT_FORMAT |
427 | if (format == NULL) | 428 | if (format == NULL) |
428 | format = (terse | 429 | format = (flags & OPT_TERSE |
429 | ? "%n %i %l %t %s %S %b %f %a %c %d\n" | 430 | ? "%n %i %l %t %s %S %b %f %a %c %d\n" |
430 | : " File: \"%n\"\n" | 431 | : " File: \"%n\"\n" |
431 | " ID: %-8i Namelen: %-7l Type: %T\n" | 432 | " ID: %-8i Namelen: %-7l Type: %T\n" |
@@ -435,7 +436,7 @@ static int do_statfs(char const *filename, char const *format) | |||
435 | print_it(format, filename, print_statfs, &statfsbuf); | 436 | print_it(format, filename, print_statfs, &statfsbuf); |
436 | #else | 437 | #else |
437 | 438 | ||
438 | format = (terse | 439 | format = (flags & OPT_TERSE |
439 | ? "%s %Lx %lu " | 440 | ? "%s %Lx %lu " |
440 | : " File: \"%s\"\n" | 441 | : " File: \"%s\"\n" |
441 | " ID: %-8Lx Namelen: %-7lu "); | 442 | " ID: %-8Lx Namelen: %-7lu "); |
@@ -444,12 +445,12 @@ static int do_statfs(char const *filename, char const *format) | |||
444 | statfsbuf.f_fsid, | 445 | statfsbuf.f_fsid, |
445 | statfsbuf.f_namelen); | 446 | statfsbuf.f_namelen); |
446 | 447 | ||
447 | if (terse) | 448 | if (flags & OPT_TERSE) |
448 | printf("%lx ", (unsigned long int) (statfsbuf.f_type)); | 449 | printf("%lx ", (unsigned long int) (statfsbuf.f_type)); |
449 | else | 450 | else |
450 | printf("Type: %s\n", human_fstype(statfsbuf.f_type)); | 451 | printf("Type: %s\n", human_fstype(statfsbuf.f_type)); |
451 | 452 | ||
452 | format = (terse | 453 | format = (flags & OPT_TERSE |
453 | ? "%lu %lu %ld %ld %ld %ld %ld\n" | 454 | ? "%lu %lu %ld %ld %ld %ld %ld\n" |
454 | : "Block size: %-10lu Fundamental block size: %lu\n" | 455 | : "Block size: %-10lu Fundamental block size: %lu\n" |
455 | "Blocks: Total: %-10ld Free: %-10ld Available: %ld\n" | 456 | "Blocks: Total: %-10ld Free: %-10ld Available: %ld\n" |
@@ -472,14 +473,14 @@ static int do_stat(char const *filename, char const *format) | |||
472 | { | 473 | { |
473 | struct stat statbuf; | 474 | struct stat statbuf; |
474 | 475 | ||
475 | if ((follow_links ? stat : lstat) (filename, &statbuf) != 0) { | 476 | if ((flags & OPT_DEREFERNCE ? stat : lstat) (filename, &statbuf) != 0) { |
476 | bb_perror_msg("cannot stat '%s'", filename); | 477 | bb_perror_msg("cannot stat '%s'", filename); |
477 | return 0; | 478 | return 0; |
478 | } | 479 | } |
479 | 480 | ||
480 | #ifdef CONFIG_FEATURE_STAT_FORMAT | 481 | #ifdef CONFIG_FEATURE_STAT_FORMAT |
481 | if (format == NULL) { | 482 | if (format == NULL) { |
482 | if (terse) { | 483 | if (flags & OPT_TERSE) { |
483 | format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n"; | 484 | format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n"; |
484 | } else { | 485 | } else { |
485 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { | 486 | if (S_ISBLK(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { |
@@ -502,7 +503,7 @@ static int do_stat(char const *filename, char const *format) | |||
502 | } | 503 | } |
503 | print_it(format, filename, print_stat, &statbuf); | 504 | print_it(format, filename, print_stat, &statbuf); |
504 | #else | 505 | #else |
505 | if (terse) { | 506 | if (flags & OPT_TERSE) { |
506 | printf("%s %lu %lu %lx %lu %lu %lx %lu %lu %lx %lx %lu %lu %lu %lu\n", | 507 | printf("%s %lu %lu %lx %lu %lu %lx %lu %lu %lx %lx %lu %lu %lu %lu\n", |
507 | filename, | 508 | filename, |
508 | (uintmax_t) (statbuf.st_size), | 509 | (uintmax_t) (statbuf.st_size), |
@@ -574,10 +575,9 @@ int stat_main(int argc, char **argv) | |||
574 | int i; | 575 | int i; |
575 | char *format = NULL; | 576 | char *format = NULL; |
576 | int ok = 1; | 577 | int ok = 1; |
577 | long flags; | ||
578 | int (*statfunc)(char const *, char const *) = do_stat; | 578 | int (*statfunc)(char const *, char const *) = do_stat; |
579 | 579 | ||
580 | flags = bb_getopt_ulflags(argc, argv, "fLlt" | 580 | flags = bb_getopt_ulflags(argc, argv, "ftL" |
581 | #ifdef CONFIG_FEATURE_STAT_FORMAT | 581 | #ifdef CONFIG_FEATURE_STAT_FORMAT |
582 | "c:", &format | 582 | "c:", &format |
583 | #endif | 583 | #endif |
@@ -585,10 +585,6 @@ int stat_main(int argc, char **argv) | |||
585 | 585 | ||
586 | if (flags & 1) /* -f */ | 586 | if (flags & 1) /* -f */ |
587 | statfunc = do_statfs; | 587 | statfunc = do_statfs; |
588 | if (flags & 2 || flags & 4) /* -L, -l */ | ||
589 | follow_links = 1; | ||
590 | if (flags & 8) /* -t */ | ||
591 | terse = 1; | ||
592 | if (argc == optind) /* files */ | 588 | if (argc == optind) /* files */ |
593 | bb_show_usage(); | 589 | bb_show_usage(); |
594 | 590 | ||