From 8f2c3dc95a6a42ea52d923457a688a6db1c4aace Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 20 Aug 2014 10:32:36 -0700 Subject: Check if user provided more than one option for pdfium_test. R=bo_xu@foxitsoftware.com Review URL: https://codereview.chromium.org/477173003 --- samples/pdfium_test.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index e92d7a1250..72c8c5dcd1 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -189,20 +189,23 @@ bool ParseCommandLine(int argc, const char* argv[], OutputFormat* output_format, files->clear(); int cur_arg = 1; - if (cur_arg < argc) { + for (; cur_arg < argc; ++cur_arg) { if (strcmp(argv[cur_arg], "--ppm") == 0) *output_format = OUTPUT_PPM; #ifdef _WIN32 - if (strcmp(argv[cur_arg], "--emf") == 0) + else if (strcmp(argv[cur_arg], "--emf") == 0) *output_format = OUTPUT_EMF; - if (strcmp(argv[cur_arg], "--bmp") == 0) + else if (strcmp(argv[cur_arg], "--bmp") == 0) *output_format = OUTPUT_BMP; #endif - if (*output_format != OUTPUT_NONE) - cur_arg++; + else + break; } - if (cur_arg >= argc) + if (cur_arg > 2) // Multiple options. + return false; + + if (cur_arg >= argc) // No input files. return false; for (int i = cur_arg; i < argc; i++) @@ -356,7 +359,7 @@ int main(int argc, const char* argv[]) { OutputFormat format = OUTPUT_NONE; std::list files; if (!ParseCommandLine(argc, argv, &format, &files)) { - printf("Usage: pdfium_test [OPTIONS] [FILE]\n"); + printf("Usage: pdfium_test [OPTION] [FILE]...\n"); printf("--ppm write page images ..ppm\n"); #ifdef _WIN32 printf("--bmp write page images ..bmp\n"); -- cgit v1.2.3