|
1 | 1 | import (
|
2 |
| - "std.um" |
| 2 | + "std.um" |
3 | 3 | )
|
4 | 4 |
|
5 | 5 | fn peekstr(f: std.File, next: int): str {
|
6 |
| - tr := "" |
7 |
| - var c: char |
8 |
| - for i:=0; i < next; i++ { |
9 |
| - fscanf(f, "%c", &c) |
10 |
| - tr += str(c) |
11 |
| - } |
12 |
| - |
13 |
| - return tr |
| 6 | + tr := "" |
| 7 | + var c: char |
| 8 | + for i:=0; i < next; i++ { |
| 9 | + fscanf(f, "%c", &c) |
| 10 | + tr += str(c) |
| 11 | + } |
| 12 | + |
| 13 | + return tr |
14 | 14 | }
|
15 | 15 |
|
16 | 16 | fn peekn(f: std.File, next: int): int {
|
17 |
| - tr := 0 |
18 |
| - var c: char |
19 |
| - for i:=0; i < next; i++ { |
20 |
| - fscanf(f, "%c", &c) |
21 |
| - ic := int(c) |
22 |
| - if ic < 0 { ic += 256 } |
23 |
| - tr += ic << (8 * (next - i - 1)) |
24 |
| - } |
25 |
| - |
26 |
| - return tr |
| 17 | + tr := 0 |
| 18 | + var c: char |
| 19 | + for i:=0; i < next; i++ { |
| 20 | + fscanf(f, "%c", &c) |
| 21 | + ic := int(c) |
| 22 | + if ic < 0 { ic += 256 } |
| 23 | + tr += ic << (8 * (next - i - 1)) |
| 24 | + } |
| 25 | + |
| 26 | + return tr |
27 | 27 | }
|
28 | 28 |
|
29 | 29 | fn loadFF*(path: str): ([]uint32, int, int, int) {
|
30 |
| - f, err := std.fopen(path, "r") |
| 30 | + f, err := std.fopen(path, "r") |
31 | 31 | std.exitif(err)
|
32 |
| - if f == null { return []uint32{}, -1, -1, 1 } |
33 |
| - var w, h: int |
34 |
| - var tr: []uint32 |
35 |
| - |
36 |
| - if val := peekstr(f, 8); val != "farbfeld" { return []uint32{}, -1, -1, 2 } |
37 |
| - w = peekn(f, 4) |
38 |
| - h = peekn(f, 4) |
39 |
| - tr = make([]uint32, w * h) |
40 |
| - var c: char |
41 |
| - for j:=0; j < w * h; j++ { |
42 |
| - for h:=0; h < 4; h++ { |
43 |
| - fscanf(f, "%c", &c) |
44 |
| - fscanf(f, "%c", &c) |
45 |
| - ic := int(c) |
46 |
| - if ic < 0 { ic += 256 } |
47 |
| - tr[j] += ic << (8 * (3 - h)) |
48 |
| - } |
49 |
| - } |
50 |
| - |
51 |
| - std.fclose(f) |
52 |
| - return tr, w, h, 0 |
| 32 | + if f == null { return []uint32{}, -1, -1, 1 } |
| 33 | + var w, h: int |
| 34 | + var tr: []uint32 |
| 35 | + |
| 36 | + if val := peekstr(f, 8); val != "farbfeld" { return []uint32{}, -1, -1, 2 } |
| 37 | + w = peekn(f, 4) |
| 38 | + h = peekn(f, 4) |
| 39 | + tr = make([]uint32, w * h) |
| 40 | + var c: char |
| 41 | + for j:=0; j < w * h; j++ { |
| 42 | + for h:=0; h < 4; h++ { |
| 43 | + fscanf(f, "%c", &c) |
| 44 | + fscanf(f, "%c", &c) |
| 45 | + ic := int(c) |
| 46 | + if ic < 0 { ic += 256 } |
| 47 | + tr[j] += ic << (8 * (3 - h)) |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + std.fclose(f) |
| 52 | + return tr, w, h, 0 |
53 | 53 | }
|
54 | 54 |
|
55 | 55 | fn readall(f: std.File): str {
|
56 |
| - const blockSize = 16 |
57 |
| - res := "" |
| 56 | + const blockSize = 16 |
| 57 | + res := "" |
58 | 58 |
|
59 |
| - for ok := true; ok { |
60 |
| - var buff: [blockSize + 1]char |
61 |
| - ok = std.fread(f, ^[blockSize]char(&buff)).item1.code == 0 |
62 |
| - res += str([]char(buff)) |
63 |
| - } |
| 59 | + for ok := true; ok { |
| 60 | + var buff: [blockSize + 1]char |
| 61 | + ok = std.fread(f, ^[blockSize]char(&buff)).item1.code == 0 |
| 62 | + res += str([]char(buff)) |
| 63 | + } |
64 | 64 |
|
65 |
| - return res |
| 65 | + return res |
66 | 66 | }
|
67 | 67 |
|
68 | 68 | fn chcnt(chars: str, c: str): bool {
|
@@ -105,15 +105,15 @@ fn main() {
|
105 | 105 | // embeds contents of a file as a string. TODO just as bytes
|
106 | 106 | if mode == "em" {
|
107 | 107 | printf("const char *%s[] = {\n", std.argv(2))
|
108 |
| - |
| 108 | + |
109 | 109 | for i:=3; i < std.argc(); i++ {
|
110 | 110 | f, err := std.fopen(std.argv(i), "r")
|
111 | 111 | std.exitif(err)
|
112 | 112 | data := readall(f)
|
113 | 113 | printf("%s\n", strtoc(data)+",")
|
114 | 114 | std.fclose(f)
|
115 | 115 | }
|
116 |
| - |
| 116 | + |
117 | 117 | printf("};\n")
|
118 | 118 | // creates a string array with args as values
|
119 | 119 | } else if mode == "argarr" {
|
|
0 commit comments