Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCommandLineFlags.h" | 8 #include "SkCommandLineFlags.h" |
| 9 #include "SkTDArray.h" | 9 #include "SkTDArray.h" |
| 10 | 10 |
| 11 DEFINE_string(undefok, "", "Silently ignore unknown flags listed here instead of crashing."); | |
|
scroggo
2014/03/25 20:09:06
Maybe specify that the use of this flag must follo
| |
| 12 | |
| 11 bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName, | 13 bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName, |
| 12 SkCommandLineFlags::StringArray* pStrings, | 14 SkCommandLineFlags::StringArray* pStrings, |
| 13 const char* defaultValue, const char* helpStri ng) { | 15 const char* defaultValue, const char* helpStri ng) { |
| 14 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_FlagType , helpString)); | 16 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_FlagType , helpString)); |
| 15 info->fDefaultString.set(defaultValue); | 17 info->fDefaultString.set(defaultValue); |
| 16 | 18 |
| 17 info->fStrings = pStrings; | 19 info->fStrings = pStrings; |
| 18 SetDefaultStrings(pStrings, defaultValue); | 20 SetDefaultStrings(pStrings, defaultValue); |
| 19 return true; | 21 return true; |
| 20 } | 22 } |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 flag->setDouble(atof(argv[i])); | 280 flag->setDouble(atof(argv[i])); |
| 279 break; | 281 break; |
| 280 default: | 282 default: |
| 281 SkDEBUGFAIL("Invalid flag type"); | 283 SkDEBUGFAIL("Invalid flag type"); |
| 282 } | 284 } |
| 283 break; | 285 break; |
| 284 } | 286 } |
| 285 flag = flag->next(); | 287 flag = flag->next(); |
| 286 } | 288 } |
| 287 if (!flagMatched) { | 289 if (!flagMatched) { |
| 288 SkDebugf("Got unknown flag \"%s\". Exiting.\n", argv[i]); | 290 SkString stripped(argv[i]); |
| 289 exit(-1); | 291 while (stripped.startsWith('-')) { |
| 292 stripped.remove(0, 1); | |
| 293 } | |
| 294 if (!FLAGS_undefok.contains(stripped.c_str())) { | |
| 295 SkDebugf("Got unknown flag \"%s\". Exiting.\n", argv[i]); | |
| 296 exit(-1); | |
| 297 } | |
| 290 } | 298 } |
| 291 } | 299 } |
| 292 } | 300 } |
| 293 // Since all of the flags have been set, release the memory used by each | 301 // Since all of the flags have been set, release the memory used by each |
| 294 // flag. FLAGS_x can still be used after this. | 302 // flag. FLAGS_x can still be used after this. |
| 295 SkFlagInfo* flag = gHead; | 303 SkFlagInfo* flag = gHead; |
| 296 gHead = NULL; | 304 gHead = NULL; |
| 297 while (flag != NULL) { | 305 while (flag != NULL) { |
| 298 SkFlagInfo* next = flag->next(); | 306 SkFlagInfo* next = flag->next(); |
| 299 SkDELETE(flag); | 307 SkDELETE(flag); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 } | 347 } |
| 340 | 348 |
| 341 } // namespace | 349 } // namespace |
| 342 | 350 |
| 343 bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const char* name) { | 351 bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const char* name) { |
| 344 return ShouldSkipImpl(strings, name); | 352 return ShouldSkipImpl(strings, name); |
| 345 } | 353 } |
| 346 bool SkCommandLineFlags::ShouldSkip(const StringArray& strings, const char* name ) { | 354 bool SkCommandLineFlags::ShouldSkip(const StringArray& strings, const char* name ) { |
| 347 return ShouldSkipImpl(strings, name); | 355 return ShouldSkipImpl(strings, name); |
| 348 } | 356 } |
| OLD | NEW |