diff options
author | Aaron Seigo <aseigo@kde.org> | 2015-12-26 19:30:31 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2015-12-26 19:30:31 +0100 |
commit | 75a2fd102611a01dba3ab7b9a26a2e05908a3a4c (patch) | |
tree | 6217a82c771873bdbe757f0d2790c379667c5d8b /akonadish/main.cpp | |
parent | 50ac3277be22bb408e84baab5b60e0eb0c6db7f3 (diff) | |
download | sink-75a2fd102611a01dba3ab7b9a26a2e05908a3a4c.tar.gz sink-75a2fd102611a01dba3ab7b9a26a2e05908a3a4c.zip |
make it possible to write akonadish scripts..
help
Diffstat (limited to 'akonadish/main.cpp')
-rw-r--r-- | akonadish/main.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/akonadish/main.cpp b/akonadish/main.cpp index bd85fb4..6e7aa9e 100644 --- a/akonadish/main.cpp +++ b/akonadish/main.cpp | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include <QCoreApplication> | 22 | #include <QCoreApplication> |
23 | #include <QDebug> | 23 | #include <QDebug> |
24 | #include <QFile> | ||
24 | #include <QTextStream> | 25 | #include <QTextStream> |
25 | 26 | ||
26 | #include "syntaxtree.h" | 27 | #include "syntaxtree.h" |
@@ -42,6 +43,8 @@ int main(int argc, char *argv[]) | |||
42 | //TODO: make a json command parse cause that would be awesomesauce | 43 | //TODO: make a json command parse cause that would be awesomesauce |
43 | const bool startJsonListener = !startRepl && | 44 | const bool startJsonListener = !startRepl && |
44 | (argc == 2 && qstrcmp(argv[1], "-") == 0); | 45 | (argc == 2 && qstrcmp(argv[1], "-") == 0); |
46 | const bool fromScript = !startRepl && QFile::exists(argv[1]); | ||
47 | |||
45 | //qDebug() << "state at startup is" << interactive << startRepl << startJsonListener; | 48 | //qDebug() << "state at startup is" << interactive << startRepl << startJsonListener; |
46 | 49 | ||
47 | QCoreApplication app(argc, argv); | 50 | QCoreApplication app(argc, argv); |
@@ -62,6 +65,18 @@ int main(int argc, char *argv[]) | |||
62 | 65 | ||
63 | State::setHasEventLoop(true); | 66 | State::setHasEventLoop(true); |
64 | return app.exec(); | 67 | return app.exec(); |
68 | } else if (fromScript) { | ||
69 | QFile f(argv[1]); | ||
70 | if (!f.open(QIODevice::ReadOnly)) { | ||
71 | return 1; | ||
72 | } | ||
73 | |||
74 | QString line = f.readLine(); | ||
75 | while (!line.isEmpty()) { | ||
76 | SyntaxTree::self()->run(SyntaxTree::tokenize(line)); | ||
77 | line = f.readLine(); | ||
78 | } | ||
79 | exit(0); | ||
65 | } else if (!interactive) { | 80 | } else if (!interactive) { |
66 | QTextStream inputStream(stdin); | 81 | QTextStream inputStream(stdin); |
67 | while (true) { | 82 | while (true) { |