summaryrefslogtreecommitdiffstats
path: root/akonadish/main.cpp
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2016-01-10 11:55:38 +0100
committerAaron Seigo <aseigo@kde.org>2016-01-10 11:55:38 +0100
commitec380cc4ac09714c91a0b506563fac79c8b6b339 (patch)
treebf794868c6ea1d6d2932383122203cebc61cc2c4 /akonadish/main.cpp
parentf17cd15e3dda370d67ef40fae10f1cf01195f55e (diff)
downloadsink-ec380cc4ac09714c91a0b506563fac79c8b6b339.tar.gz
sink-ec380cc4ac09714c91a0b506563fac79c8b6b339.zip
factor out the common multiline input routine
Diffstat (limited to 'akonadish/main.cpp')
-rw-r--r--akonadish/main.cpp39
1 files changed, 17 insertions, 22 deletions
diff --git a/akonadish/main.cpp b/akonadish/main.cpp
index f3cbcac..ba8be96 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
39void processCommandStream(QTextStream &stream)
40{
41 QString line = stream.readLine();
42 while (!line.isEmpty()) {
43 line = line.trimmed();
44
45 if (!line.isEmpty() && !line.startsWith('#')) {
46 SyntaxTree::self()->run(SyntaxTree::tokenize(line));
47 }
48
49 line = stream.readLine();
50 }
51}
52
39int main(int argc, char *argv[]) 53int main(int argc, char *argv[])
40{ 54{
41 const bool interactive = isatty(fileno(stdin)); 55 const bool interactive = isatty(fileno(stdin));
@@ -72,30 +86,11 @@ int main(int argc, char *argv[])
72 return 1; 86 return 1;
73 } 87 }
74 88
75 QString line = f.readLine(); 89 QTextStream inputStream(&f);
76 while (!line.isEmpty()) { 90 processCommandStream(inputStream);
77 line = line.trimmed();
78
79 if (!line.isEmpty() && !line.startsWith('#')) {
80 SyntaxTree::self()->run(SyntaxTree::tokenize(line));
81 }
82
83 line = f.readLine();
84 }
85 exit(0);
86 } else if (!interactive) { 91 } else if (!interactive) {
87 QTextStream inputStream(stdin); 92 QTextStream inputStream(stdin);
88 93 processCommandStream(inputStream);
89 QString line = inputStream.readLine();
90 while (!line.isEmpty()) {
91 line = line.trimmed();
92
93 if (!line.isEmpty() && !line.startsWith('#')) {
94 SyntaxTree::self()->run(SyntaxTree::tokenize(line));
95 }
96
97 line = inputStream.readLine();
98 }
99 } else { 94 } else {
100 QStringList commands = app.arguments(); 95 QStringList commands = app.arguments();
101 commands.removeFirst(); 96 commands.removeFirst();