aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-19 22:20:17 +0200
committerAdrian Kummerlaender2017-04-19 22:20:17 +0200
commitfd8a28b1ee22993bf70b0f451b46ab0a631b0c17 (patch)
tree25bbd58fbd24a4fa436f64bf5701fff61ac7693e
parentfa1bdcab3f371f1ec79621fbd890f3ddd8b5019c (diff)
downloadslang-fd8a28b1ee22993bf70b0f451b46ab0a631b0c17.tar
slang-fd8a28b1ee22993bf70b0f451b46ab0a631b0c17.tar.gz
slang-fd8a28b1ee22993bf70b0f451b46ab0a631b0c17.tar.bz2
slang-fd8a28b1ee22993bf70b0f451b46ab0a631b0c17.tar.lz
slang-fd8a28b1ee22993bf70b0f451b46ab0a631b0c17.tar.xz
slang-fd8a28b1ee22993bf70b0f451b46ab0a631b0c17.tar.zst
slang-fd8a28b1ee22993bf70b0f451b46ab0a631b0c17.zip
Automatically process files passed as arguments
-rw-r--r--source/app.d23
1 files 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);
}
}