Add a minimal --undefok to SkCommandLineFlags.

Similar in spirit to gflags' undefok, I'd like to be able to ignore
specific unknown flags.  This lets me run the same command line on, say,
a branch that's got a new flag and on a clean branch tracking
origin/master.  This is handy for performance comparison, etc.

It's not essential, and if you hate this I can find another way.

As an example, I want to compare the runtime of SKP recording with my new code.  I've added a flag --skr to bench_record to help this.  So I want to compare

origin/master: out/Release/bench_record
my patch:      out/Release/bench_record --skr

This lets me run both as out/Release/bench_record --undefok skr --skr, which is handy for scripts and things.

BUG=skia:
R=scroggo@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/209393015

git-svn-id: http://skia.googlecode.com/svn/trunk@13945 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/flags/SkCommandLineFlags.cpp b/tools/flags/SkCommandLineFlags.cpp
index 656a00a..9b31b65 100644
--- a/tools/flags/SkCommandLineFlags.cpp
+++ b/tools/flags/SkCommandLineFlags.cpp
@@ -8,6 +8,8 @@
 #include "SkCommandLineFlags.h"
 #include "SkTDArray.h"
 
+DEFINE_string(undefok, "", "Silently ignore unknown flags listed here instead of crashing.");
+
 bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName,
                                   SkCommandLineFlags::StringArray* pStrings,
                                   const char* defaultValue, const char* helpString) {
@@ -285,8 +287,14 @@
                 flag = flag->next();
             }
             if (!flagMatched) {
-                SkDebugf("Got unknown flag \"%s\". Exiting.\n", argv[i]);
-                exit(-1);
+                SkString stripped(argv[i]);
+                while (stripped.startsWith('-')) {
+                    stripped.remove(0, 1);
+                }
+                if (!FLAGS_undefok.contains(stripped.c_str())) {
+                    SkDebugf("Got unknown flag \"%s\". Exiting.\n", argv[i]);
+                    exit(-1);
+                }
             }
         }
     }