Parse SampleApp command line for a test name. If an argument is passed to
SampleApp on the command line, interpret it as a test name.  If it's a valid
test, open that test at startup.

Review URL:  http://codereview.appspot.com/4661054/



git-svn-id: http://skia.googlecode.com/svn/trunk@1742 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index d561c85..a5987f2 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -347,7 +347,7 @@
     return gCT[ct];
 }
 
-SampleWindow::SampleWindow(void* hwnd) : INHERITED(hwnd) {
+SampleWindow::SampleWindow(void* hwnd, int argc, char** argv) : INHERITED(hwnd) {
 #ifdef  PIPE_FILE
     //Clear existing file or create file if it doesn't exist
     FILE* f = fopen(FILE_PATH, "wb");
@@ -404,6 +404,19 @@
         }
     }
     fCurrIndex = 0;
+    if (argc > 1) {
+        int i, count = fSamples.count();
+        for (i = 0; i < count; i++) {
+            SkString title = getSampleTitle(i);
+            if (title.equals(argv[1])) {
+                fCurrIndex = i;
+                break;
+            }
+        }
+        if (i == count) {
+            fprintf(stderr, "Unknown sample \"%s\"\n", argv[1]);
+        }
+    }
     this->loadView(fSamples[fCurrIndex]());
 
     // If another constructor set our dimensions, ensure that our
@@ -1673,9 +1686,9 @@
     }
 }
 
-SkOSWindow* create_sk_window(void* hwnd) {
+SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
 //    test();
-    return new SampleWindow(hwnd);
+    return new SampleWindow(hwnd, argc, argv);
 }
 
 void get_preferred_size(int* x, int* y, int* width, int* height) {