Cleanup
This commit is contained in:
parent
588d7701f2
commit
7839208b62
@ -25,7 +25,7 @@ namespace cmd{
|
||||
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;}},
|
||||
{"--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
|
||||
@ -87,7 +87,7 @@ namespace cmd{
|
||||
if(argv[i][j] == cmd_options[k].sopt){
|
||||
found = true;
|
||||
return_val.retval = cmd_options[k].func(argc, argv, i, return_val);
|
||||
if(return_val.retval)
|
||||
if(return_val.abort)
|
||||
return return_val;
|
||||
break;
|
||||
}
|
||||
@ -140,6 +140,15 @@ int do_stdin(bool ignore_newlines){
|
||||
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
|
||||
int do_cumulative(const cmd::flags& flags){
|
||||
int total = 0;
|
||||
@ -150,13 +159,7 @@ int do_cumulative(const cmd::flags& flags){
|
||||
return 0;
|
||||
}
|
||||
for(size_t i = 0;i < flags.args.size();++i){
|
||||
if(!strcmp(flags.args[i], "-")){
|
||||
for(int len;(len = do_stdin(flags.ignorenl)) >= 0;){
|
||||
total += len;
|
||||
}
|
||||
}else{
|
||||
total += strlen(flags.args[i]);
|
||||
}
|
||||
total += do_argument(flags, i);
|
||||
}
|
||||
wprintf(L"%d\n", total);
|
||||
return 0;
|
||||
@ -170,13 +173,7 @@ int do_basic(const cmd::flags& flags){
|
||||
return 0;
|
||||
}
|
||||
for(size_t i = 0;i < flags.args.size();++i){
|
||||
if(!strcmp(flags.args[i], "-")){
|
||||
for(int len;(len = do_stdin(flags.ignorenl)) >= 0;){
|
||||
wprintf(L"%d\n", len);
|
||||
}
|
||||
}else{
|
||||
wprintf(L"%d\n", strlen(flags.args[i]));
|
||||
}
|
||||
wprintf(L"%d\n", do_argument(flags, i));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user