diff options
-rw-r--r-- | akonadish/main.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/akonadish/main.cpp b/akonadish/main.cpp index ba8be96..139b28f 100644 --- a/akonadish/main.cpp +++ b/akonadish/main.cpp | |||
@@ -36,6 +36,20 @@ | |||
36 | * 3. called with commands: try to match to syntx | 36 | * 3. called with commands: try to match to syntx |
37 | */ | 37 | */ |
38 | 38 | ||
39 | int enterRepl() | ||
40 | { | ||
41 | Repl *repl = new Repl; | ||
42 | QObject::connect(repl, &QStateMachine::finished, | ||
43 | repl, &QObject::deleteLater); | ||
44 | QObject::connect(repl, &QStateMachine::finished, | ||
45 | QCoreApplication::instance(), &QCoreApplication::quit); | ||
46 | |||
47 | State::setHasEventLoop(true); | ||
48 | int rv = QCoreApplication::instance()->exec(); | ||
49 | State::setHasEventLoop(false); | ||
50 | return rv; | ||
51 | } | ||
52 | |||
39 | void processCommandStream(QTextStream &stream) | 53 | void processCommandStream(QTextStream &stream) |
40 | { | 54 | { |
41 | QString line = stream.readLine(); | 55 | QString line = stream.readLine(); |
@@ -55,31 +69,15 @@ int main(int argc, char *argv[]) | |||
55 | const bool interactive = isatty(fileno(stdin)); | 69 | const bool interactive = isatty(fileno(stdin)); |
56 | const bool startRepl = (argc == 1) && interactive; | 70 | const bool startRepl = (argc == 1) && interactive; |
57 | //TODO: make a json command parse cause that would be awesomesauce | 71 | //TODO: make a json command parse cause that would be awesomesauce |
58 | const bool startJsonListener = !startRepl && | ||
59 | (argc == 2 && qstrcmp(argv[1], "-") == 0); | ||
60 | const bool fromScript = !startRepl && QFile::exists(argv[1]); | 72 | const bool fromScript = !startRepl && QFile::exists(argv[1]); |
61 | 73 | ||
62 | //qDebug() << "state at startup is" << interactive << startRepl << startJsonListener << fromScript; | 74 | //qDebug() << "state at startup is" << interactive << startRepl << fromScript; |
63 | 75 | ||
64 | QCoreApplication app(argc, argv); | 76 | QCoreApplication app(argc, argv); |
65 | app.setApplicationName(fromScript ? "interactive-app-shell" : argv[0]); | 77 | app.setApplicationName(fromScript ? "interactive-app-shell" : argv[0]); |
66 | //app.setApplicationName(argv[0]); | ||
67 | |||
68 | if (startRepl || startJsonListener) { | ||
69 | if (startRepl) { | ||
70 | Repl *repl = new Repl; | ||
71 | QObject::connect(repl, &QStateMachine::finished, | ||
72 | repl, &QObject::deleteLater); | ||
73 | QObject::connect(repl, &QStateMachine::finished, | ||
74 | &app, &QCoreApplication::quit); | ||
75 | } | ||
76 | |||
77 | if (startJsonListener) { | ||
78 | // JsonListener listener(syntax); | ||
79 | } | ||
80 | 78 | ||
81 | State::setHasEventLoop(true); | 79 | if (startRepl) { |
82 | return app.exec(); | 80 | return enterRepl(); |
83 | } else if (fromScript) { | 81 | } else if (fromScript) { |
84 | QFile f(argv[1]); | 82 | QFile f(argv[1]); |
85 | if (!f.open(QIODevice::ReadOnly)) { | 83 | if (!f.open(QIODevice::ReadOnly)) { |