Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: samples/pdfium_test.cc

Issue 477173003: Check if user provided more than one option for pdfium_test. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Tue 08/19/2014 14:38:22.91 Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits.h> 5 #include <limits.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 182 }
183 printf("Unsupported feature: %s.\n", feature.c_str()); 183 printf("Unsupported feature: %s.\n", feature.c_str());
184 } 184 }
185 185
186 bool ParseCommandLine(int argc, const char* argv[], OutputFormat* output_format, 186 bool ParseCommandLine(int argc, const char* argv[], OutputFormat* output_format,
187 std::list<const char*>* files) { 187 std::list<const char*>* files) {
188 *output_format = OUTPUT_NONE; 188 *output_format = OUTPUT_NONE;
189 files->clear(); 189 files->clear();
190 190
191 int cur_arg = 1; 191 int cur_arg = 1;
192 if (cur_arg < argc) { 192 for (; cur_arg < argc; ++cur_arg) {
193 if (strcmp(argv[cur_arg], "--ppm") == 0) 193 if (strcmp(argv[cur_arg], "--ppm") == 0)
194 *output_format = OUTPUT_PPM; 194 *output_format = OUTPUT_PPM;
195 #ifdef _WIN32 195 #ifdef _WIN32
196 if (strcmp(argv[cur_arg], "--emf") == 0) 196 else if (strcmp(argv[cur_arg], "--emf") == 0)
197 *output_format = OUTPUT_EMF; 197 *output_format = OUTPUT_EMF;
198 if (strcmp(argv[cur_arg], "--bmp") == 0) 198 else if (strcmp(argv[cur_arg], "--bmp") == 0)
199 *output_format = OUTPUT_BMP; 199 *output_format = OUTPUT_BMP;
200 #endif 200 #endif
201 if (*output_format != OUTPUT_NONE) 201 else
202 cur_arg++; 202 break;
203 } 203 }
204 204
205 if (cur_arg >= argc) 205 if (cur_arg > 2) // Multiple options.
206 return false;
207
208 if (cur_arg >= argc) // No input files.
206 return false; 209 return false;
207 210
208 for (int i = cur_arg; i < argc; i++) 211 for (int i = cur_arg; i < argc; i++)
209 files->push_back(argv[i]); 212 files->push_back(argv[i]);
210 213
211 return true; 214 return true;
212 } 215 }
213 216
214 class TestLoader { 217 class TestLoader {
215 public: 218 public:
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 const char* buffer = 321 const char* buffer =
319 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); 322 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap));
320 323
321 switch (format) { 324 switch (format) {
322 #ifdef _WIN32 325 #ifdef _WIN32
323 case OUTPUT_BMP: 326 case OUTPUT_BMP:
324 WriteBmp(name, i, buffer, stride, width, height); 327 WriteBmp(name, i, buffer, stride, width, height);
325 break; 328 break;
326 329
327 case OUTPUT_EMF: 330 case OUTPUT_EMF:
328 WriteEmf(page, name, i); 331 WriteEmf(page, name, i);
Bo Xu 2014/08/20 05:25:59 When do WriteEmf, bitmap is created but never used
329 break; 332 break;
330 #endif 333 #endif
331 case OUTPUT_PPM: 334 case OUTPUT_PPM:
332 WritePpm(name, i, buffer, stride, width, height); 335 WritePpm(name, i, buffer, stride, width, height);
333 break; 336 break;
334 default: 337 default:
335 break; 338 break;
336 } 339 }
337 340
338 FPDFBitmap_Destroy(bitmap); 341 FPDFBitmap_Destroy(bitmap);
(...skipping 10 matching lines...) Expand all
349 FPDFAvail_Destroy(pdf_avail); 352 FPDFAvail_Destroy(pdf_avail);
350 353
351 printf("Loaded, parsed and rendered %d pages.\n", page_count); 354 printf("Loaded, parsed and rendered %d pages.\n", page_count);
352 } 355 }
353 356
354 int main(int argc, const char* argv[]) { 357 int main(int argc, const char* argv[]) {
355 v8::V8::InitializeICU(); 358 v8::V8::InitializeICU();
356 OutputFormat format = OUTPUT_NONE; 359 OutputFormat format = OUTPUT_NONE;
357 std::list<const char*> files; 360 std::list<const char*> files;
358 if (!ParseCommandLine(argc, argv, &format, &files)) { 361 if (!ParseCommandLine(argc, argv, &format, &files)) {
359 printf("Usage: pdfium_test [OPTIONS] [FILE]\n"); 362 printf("Usage: pdfium_test [OPTION] [FILE]...\n");
360 printf("--ppm write page images <pdf-name>.<page-number>.ppm\n"); 363 printf("--ppm write page images <pdf-name>.<page-number>.ppm\n");
361 #ifdef _WIN32 364 #ifdef _WIN32
362 printf("--bmp write page images <pdf-name>.<page-number>.bmp\n"); 365 printf("--bmp write page images <pdf-name>.<page-number>.bmp\n");
363 printf("--emf write page meta files <pdf-name>.<page-number>.emf\n"); 366 printf("--emf write page meta files <pdf-name>.<page-number>.emf\n");
364 #endif 367 #endif
365 return 1; 368 return 1;
366 } 369 }
367 370
368 FPDF_InitLibrary(NULL); 371 FPDF_InitLibrary(NULL);
369 372
(...skipping 23 matching lines...) Expand all
393 } else { 396 } else {
394 RenderPdf(filename, pBuf, len, format); 397 RenderPdf(filename, pBuf, len, format);
395 } 398 }
396 free(pBuf); 399 free(pBuf);
397 } 400 }
398 401
399 FPDF_DestroyLibrary(); 402 FPDF_DestroyLibrary();
400 403
401 return 0; 404 return 0;
402 } 405 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698