summaryrefslogtreecommitdiffhomepage
path: root/coreutils
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-11-21 09:17:00 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-11-21 09:17:00 +0000
commit02d090d3d2623047009a17d47bf09df83285a75e (patch)
tree99e99178e2d54cafa3cd25e1b5cce143b20b267f /coreutils
parent2480e3a30a063fb400a0912ddf513dff03ebc641 (diff)
Use enums for selected functionality, Reduce the size by nearly 100 Bytes
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/wc.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/coreutils/wc.c b/coreutils/wc.c
index 695e7e7d4..03dd3c3af 100644
--- a/coreutils/wc.c
+++ b/coreutils/wc.c
@@ -27,26 +27,33 @@
#include "busybox.h"
static int total_lines, total_words, total_chars, max_length;
-static int print_lines, print_words, print_chars, print_length;
+//static int print_lines, print_words, print_chars, print_length;
+static char print_type = 0;
+enum print_e {
+ print_lines = 1,
+ print_words = 2,
+ print_chars = 4,
+ print_length = 8
+};
static void print_counts(int lines, int words, int chars, int length,
const char *name)
{
char const *space = "";
- if (print_lines) {
+ if (print_type & print_lines) {
printf("%7d", lines);
space = " ";
}
- if (print_words) {
+ if (print_type & print_words) {
printf("%s%7d", space, words);
space = " ";
}
- if (print_chars) {
+ if (print_type & print_chars) {
printf("%s%7d", space, chars);
space = " ";
}
- if (print_length)
+ if (print_type & print_length)
printf("%s%7d", space, length);
if (*name)
printf(" %s", name);
@@ -110,36 +117,37 @@ int wc_main(int argc, char **argv)
int opt, status = EXIT_SUCCESS;
total_lines = total_words = total_chars = max_length = 0;
- print_lines = print_words = print_chars = print_length = 0;
while ((opt = getopt(argc, argv, "clLw")) > 0) {
switch (opt) {
case 'c':
- print_chars = 1;
+ print_type |= print_chars;
break;
case 'l':
- print_lines = 1;
+ print_type |= print_lines;
break;
case 'L':
- print_length = 1;
+ print_type |= print_length;
break;
case 'w':
- print_words = 1;
+ print_type |= print_words;
break;
default:
show_usage();
}
}
- if (!print_lines && !print_words && !print_chars && !print_length)
- print_lines = print_words = print_chars = 1;
+ if (print_type == 0) {
+ print_type = print_lines | print_words | print_chars;
+ }
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
wc_file(stdin, "");
return EXIT_SUCCESS;
} else {
while (optind < argc) {
- if ((file = wfopen(argv[optind], "r")) != NULL)
+ file = wfopen(argv[optind], "r");
+ if (file != NULL)
wc_file(file, argv[optind]);
else
status = EXIT_FAILURE;