Add a dry run option for wesmage.

When timing an algorithm the writing of the png can take a
non-significant portion of the time.
This commit is contained in:
Mark de Wever 2012-03-17 07:56:58 +00:00
parent 1b3b6a33c7
commit 58ae900485
2 changed files with 13 additions and 2 deletions

View file

@ -108,6 +108,7 @@ print_help(const int exit_status)
"The FILE is the name of the input file to be converted.\n"
"OPTIONS:\n"
"-o, --output FILE The name of the output file to be written.\n"
"-n, --dry-run No output is written.\n"
"-f, --filter FILTER Filters to be applied to the image. See FILTERS.\n"
"-h, --help Show this help and terminate the programme.\n"
"\n"
@ -147,6 +148,7 @@ toptions::parse(int argc, char* argv[])
toptions& result = singleton(false);
bool help = false;
bool dry_run = false;
/* argv[0] is the name of the programme, not a command-line argument. */
for(int i = 1; i < argc; ++i) {
@ -154,6 +156,8 @@ toptions::parse(int argc, char* argv[])
if(option == "-h" || option == "--help") {
help = true;
} else if(option == "-n" || option == "--dry-run") {
dry_run = true;
} else if(option == "-o" || option == "--output") {
++i;
VALIDATE_NOT_PAST_END;
@ -182,12 +186,17 @@ toptions::parse(int argc, char* argv[])
print_help(EXIT_SUCCESS);
}
if(dry_run && !result.output_filename.empty()) {
std::cerr << "Error: Dry run with an output file is not allowed.\n";
print_help(EXIT_FAILURE);
}
if(result.input_filename.empty()) {
std::cerr << "Error: Input filename omitted.\n";
print_help(EXIT_FAILURE);
}
if(result.output_filename.empty()) {
if(result.output_filename.empty() && !dry_run) {
std::cerr << "Error: Output filename omitted.\n";
print_help(EXIT_FAILURE);
}

View file

@ -49,7 +49,9 @@ main(int argc, char* argv[])
filter_apply(surf, filter);
}
save_image(surf, options.output_filename);
if(!options.output_filename.empty()) {
save_image(surf, options.output_filename);
}
} catch(const texit& exit) {
return exit.status;