k9core

Unnamed repository
Log | Files | Refs | LICENSE

commit dcf829ab3eeebd17f06ad5c4aea43de3b18fbdf4
parent 3a44055d3752abfc094ba3fd099feac95b2bd98a
Author: qorg11 <qorg@vxempire.xyz>
Date:   Thu, 30 Jul 2020 13:59:34 +0200

somebody pls fix flags and stdin

Diffstat:
Msrc/wc.c | 53++++++++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 25 deletions(-)

diff --git a/src/wc.c b/src/wc.c @@ -45,41 +45,44 @@ main(int argc, char *argv[]) { int c; int show_lines, show_words, show_bytes; - show_lines = show_words = show_bytes = 0; + struct wc_values data; /* Process arguments */ while((c = getopt(argc,argv,"lwc")) > 0) { switch(c) - { - case 'l': - show_lines = 1; - break; - case 'w': - show_words = 1; - break; - case 'c': - show_bytes = 1; - break; - default: - show_lines = show_words = show_bytes = 1; - } + { + case 'l': + show_lines = 1; + break; + case 'w': + show_words = 1; + break; + case 'c': + show_bytes = 1; + break; + } } for(int i = optind; i<argc;i++) { if(argc > 1) - { - data = wc(fopen(argv[i],"r")); - if(show_lines) - printf("%i ",data.lines); - if(show_words) - printf("%i ",data.words); - if(show_bytes) - printf("%i",data.words); - } - + { + if(argc > i) + data = wc(fopen(argv[i],"r")); + else + data = wc(stdin); + /* printf("%i %i %i\n",show_lines, show_bytes, + show_words); */ + if(show_lines) + printf("%i ",data.lines); + if(show_words) + printf("%i ",data.words); + if(show_bytes) + printf("%i",data.bytes); + } + printf("\n"); } - printf("\n"); + return 0; }