From ec380cc4ac09714c91a0b506563fac79c8b6b339 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sun, 10 Jan 2016 11:55:38 +0100 Subject: factor out the common multiline input routine --- akonadish/main.cpp | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'akonadish/main.cpp') 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 @@ * 3. called with commands: try to match to syntx */ +void processCommandStream(QTextStream &stream) +{ + QString line = stream.readLine(); + while (!line.isEmpty()) { + line = line.trimmed(); + + if (!line.isEmpty() && !line.startsWith('#')) { + SyntaxTree::self()->run(SyntaxTree::tokenize(line)); + } + + line = stream.readLine(); + } +} + int main(int argc, char *argv[]) { const bool interactive = isatty(fileno(stdin)); @@ -72,30 +86,11 @@ int main(int argc, char *argv[]) return 1; } - QString line = f.readLine(); - while (!line.isEmpty()) { - line = line.trimmed(); - - if (!line.isEmpty() && !line.startsWith('#')) { - SyntaxTree::self()->run(SyntaxTree::tokenize(line)); - } - - line = f.readLine(); - } - exit(0); + QTextStream inputStream(&f); + processCommandStream(inputStream); } else if (!interactive) { QTextStream inputStream(stdin); - - QString line = inputStream.readLine(); - while (!line.isEmpty()) { - line = line.trimmed(); - - if (!line.isEmpty() && !line.startsWith('#')) { - SyntaxTree::self()->run(SyntaxTree::tokenize(line)); - } - - line = inputStream.readLine(); - } + processCommandStream(inputStream); } else { QStringList commands = app.arguments(); commands.removeFirst(); -- cgit v1.2.3