Landin library reference discuss source

compiler/tests/fixtures/runtime/library-system-arguments/main.ldn

1--  Print the arguments the program was given, one to a line after its
2--  index, then look for a settings file.  When it cannot be opened the
3--  program says why, in the library's words and by the system's own error
4--  number, and goes on with its defaults.
5import core/failure
6import core/io
7import core/text
8import hosted/system
9
10public main: () -> (code: i32) =
11    host := system.new()
12    mut storage: [256]u8 = zeroed
13    mut out := io.buffered_over(host, io.out(host), storage)
14    defer io.flush(out) else none
15    code = 1
16    count: usize = io.argument_count(host)
17    io.format(out, "{} arguments\n", [any(addr count)]) else none
18    for index in 0..<count do
19        argument := io.argument_at(host, index) else (problem)
20            return
21        end
22        io.format(out, "{}: {}\n", [any(addr index), any(addr argument)])
23            else none
24    end for
25    path: []u8 = "settings.conf"
26    file := io.open_read(host, text.host_over(path)) else (problem)
27        reason: []u8 = failure.words(problem)
28        number: i32 = system.last_errno(host)
29        io.format(out, "{}: {} (errno {}), so the defaults apply\n",
30                  [any(addr path), any(addr reason), any(addr number)])
31            else none
32        code = 0
33        return
34    end
35    io.close(host, file) else none
36    io.format(out, "{}: opened\n", [any(addr path)]) else none
37    code = 0
38end main