From fd8a28b1ee22993bf70b0f451b46ab0a631b0c17 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 19 Apr 2017 22:20:17 +0200 Subject: Automatically process files passed as arguments --- source/app.d | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/source/app.d b/source/app.d index 4e7b546..dd7be6d 100644 --- a/source/app.d +++ b/source/app.d @@ -1,12 +1,23 @@ -import std.string : split; -import std.stdio : stdin, readln, writeln; +import std.string : split; +import std.range : dropOne; +import std.algorithm : map, each; +import std.stdio : stdin, File, lines; static import machine; -void main() { +void process(ref File file) { + foreach ( string line; lines(file) ) { + line.split.each!(machine.process); + } +} + +void main(string[] args) { + args + .dropOne + .map!(File) + .each!((File file) => file.process); + while ( !stdin.eof ) { - foreach ( token; stdin.readln.split ) { - machine.process(token); - } + stdin.readln.split.each!(machine.process); } } -- cgit v1.2.3