mirror of https://git.qorg11.net/k9core.git
somebody pls fix flags and stdin
This commit is contained in:
parent
3a44055d37
commit
dcf829ab3e
53
src/wc.c
53
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue