Cleanup
This commit is contained in:
parent
588d7701f2
commit
7839208b62
@ -25,7 +25,7 @@ namespace cmd{
|
|||||||
static cmd::options cmd_options[] = {
|
static cmd::options cmd_options[] = {
|
||||||
{"--cumulative", 'c', "suppress normal output and sum all the lengths together", [](int, char**, int, cmd::flags& f)->int{f.cumulative = 1;return 0;}},
|
{"--cumulative", 'c', "suppress normal output and sum all the lengths together", [](int, char**, int, cmd::flags& f)->int{f.cumulative = 1;return 0;}},
|
||||||
{"--ignorenewline", 'n', "do not count newlines toward the character count", [](int, char**, int, cmd::flags& f)->int{f.ignorenl = 1;return 0;}},
|
{"--ignorenewline", 'n', "do not count newlines toward the character count", [](int, char**, int, cmd::flags& f)->int{f.ignorenl = 1;return 0;}},
|
||||||
{"--help", 'h', "print this help message and exit", [](int, char**, int, cmd::flags& f)->int{f.abort = 1;return 1;}}
|
{"--help", 'h', "print this help message and exit", [](int, char**, int, cmd::flags& f)->int{f.abort = 1;return 0;}}
|
||||||
};
|
};
|
||||||
|
|
||||||
//print usage message
|
//print usage message
|
||||||
@ -87,7 +87,7 @@ namespace cmd{
|
|||||||
if(argv[i][j] == cmd_options[k].sopt){
|
if(argv[i][j] == cmd_options[k].sopt){
|
||||||
found = true;
|
found = true;
|
||||||
return_val.retval = cmd_options[k].func(argc, argv, i, return_val);
|
return_val.retval = cmd_options[k].func(argc, argv, i, return_val);
|
||||||
if(return_val.retval)
|
if(return_val.abort)
|
||||||
return return_val;
|
return return_val;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -140,6 +140,15 @@ int do_stdin(bool ignore_newlines){
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int do_argument(const cmd::flags& flags, int i){
|
||||||
|
if(!strcmp(flags.args[i], "-")){
|
||||||
|
for(int len;(len = do_stdin(flags.ignorenl)) >= 0;){
|
||||||
|
return len
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return strlen(flags.args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
//Sum of all strlens
|
//Sum of all strlens
|
||||||
int do_cumulative(const cmd::flags& flags){
|
int do_cumulative(const cmd::flags& flags){
|
||||||
int total = 0;
|
int total = 0;
|
||||||
@ -150,13 +159,7 @@ int do_cumulative(const cmd::flags& flags){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for(size_t i = 0;i < flags.args.size();++i){
|
for(size_t i = 0;i < flags.args.size();++i){
|
||||||
if(!strcmp(flags.args[i], "-")){
|
total += do_argument(flags, i);
|
||||||
for(int len;(len = do_stdin(flags.ignorenl)) >= 0;){
|
|
||||||
total += len;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
total += strlen(flags.args[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
wprintf(L"%d\n", total);
|
wprintf(L"%d\n", total);
|
||||||
return 0;
|
return 0;
|
||||||
@ -170,13 +173,7 @@ int do_basic(const cmd::flags& flags){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for(size_t i = 0;i < flags.args.size();++i){
|
for(size_t i = 0;i < flags.args.size();++i){
|
||||||
if(!strcmp(flags.args[i], "-")){
|
wprintf(L"%d\n", do_argument(flags, i));
|
||||||
for(int len;(len = do_stdin(flags.ignorenl)) >= 0;){
|
|
||||||
wprintf(L"%d\n", len);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
wprintf(L"%d\n", strlen(flags.args[i]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user