forked from alkhizanah/nur
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.nur
More file actions
38 lines (30 loc) · 698 Bytes
/
Copy pathcat.nur
File metadata and controls
38 lines (30 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fs = import("fs")
io = import("io")
process = import("process")
duplicate_stdin = fn {
while (input = fs.read_line(io.stdin)) != null {
println(input)
}
}
concatenate_files = fn {
i = 0
while (i += 1) < len(process.argv) {
file_path = process.argv[i]
file = fs.open(file_path)
if file == null {
println(file_path + ": could not open file")
exit(1)
}
while (line = fs.read_line(file)) != null {
println(line)
}
fs.close(file)
}
}
if len(process.argv) < 2 {
duplicate_stdin()
} else if process.argv[1] == "-" {
duplicate_stdin()
} else {
concatenate_files()
}