summaryrefslogtreecommitdiffstats
path: root/akonadish/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'akonadish/main.cpp')
-rw-r--r--akonadish/main.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/akonadish/main.cpp b/akonadish/main.cpp
index bd85fb4..45bd5ea 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,7 +43,9 @@ 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);
45 //qDebug() << "state at startup is" << interactive << startRepl << startJsonListener; 46 const bool fromScript = !startRepl && QFile::exists(argv[1]);
47
48 //qDebug() << "state at startup is" << interactive << startRepl << startJsonListener << fromScript;
46 49
47 QCoreApplication app(argc, argv); 50 QCoreApplication app(argc, argv);
48 app.setApplicationName(argv[0]); 51 app.setApplicationName(argv[0]);
@@ -62,6 +65,22 @@ 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().trimmed();
75 while (!line.isEmpty()) {
76 if (line.isEmpty() || line.startsWith('#')) {
77 line = f.readLine().trimmed();
78 continue;
79 }
80 SyntaxTree::self()->run(SyntaxTree::tokenize(line));
81 line = f.readLine().trimmed();
82 }
83 exit(0);
65 } else if (!interactive) { 84 } else if (!interactive) {
66 QTextStream inputStream(stdin); 85 QTextStream inputStream(stdin);
67 while (true) { 86 while (true) {