1607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
2607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com/*
3607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com * Copyright 2012 Google Inc.
4607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com *
5607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com * Use of this source code is governed by a BSD-style license that can be
6607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com * found in the LICENSE file.
7607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com */
8607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
9607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com#include "SkDebuggerGUI.h"
10607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com#include <QApplication>
11607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
12ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.comstatic void usage(const char * argv0) {
13ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    SkDebugf("%s <input> \n", argv0);
14ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    SkDebugf("    [--help|-h]: show this help message\n");
15ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    SkDebugf("\n\n");
16ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    SkDebugf("     input:     Either a directory or a single .skp file.\n");
17ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com}
18ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
19607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.comint main(int argc, char *argv[]) {
20607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    QApplication a(argc, argv);
21ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
22ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    QStringList argList = a.arguments();
23ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
24ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    if (argList.count() <= 0) {
25ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com        return -1;  // should at least have command name
26ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    }
27ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
28ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    SkString input;
29ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
30ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    QStringList::const_iterator iter = argList.begin();
31ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
32e219baf74742ee5cda3c99fabe6acaa8f878fe00robertphillips@google.com    SkString commandName(iter->toAscii().data());
33ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    ++iter; // skip the command name
34ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
35ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    for ( ; iter != argList.end(); ++iter) {
36ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com        if (0 == iter->compare("--help") || 0 == iter->compare("-h")) {
37ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com            usage(commandName.c_str());
38ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com            return -1;
39ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com        } else if (input.isEmpty()) {
40e219baf74742ee5cda3c99fabe6acaa8f878fe00robertphillips@google.com            input = SkString(iter->toAscii().data());
41ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com        } else {
42ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com            usage(commandName.c_str());
43ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com            return -1;
44ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com        }
45ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    }
46ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
47607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    SkDebuggerGUI w;
48ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
49ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    if (!input.isEmpty()) {
50ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com        if (SkStrEndsWith(input.c_str(), ".skp")) {
51ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com            w.openFile(input.c_str());
52ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com        } else {
53ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com            w.setupDirectoryWidget(input.c_str());
54ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com        }
55ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com    }
56ff6e6bade36c34a4c4fce4c14b480b9d2435bcd5robertphillips@google.com
57607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    w.show();
58607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    return a.exec();
59607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com}
60