@@ -2,13 +2,26 @@ export executable "cat";
2
2
3
3
import "std.zig" ;
4
4
5
- pub fn main (args : [][]u8 ) error = > {
5
+ // Things to do to make this work:
6
+ // * isize instead of usize for things
7
+ // * var args printing
8
+ // * update std API
9
+ // * !void type
10
+ // * defer
11
+ // * !return
12
+ // * !! operator
13
+ // * make main return !void
14
+ // * how to reference error values (!void).Invalid ? !Invalid ?
15
+ // * ~ is bool not, not !
16
+ // * cast err type to string
17
+
18
+ pub fn main (args : [][]u8 ) ! void = > {
6
19
const exe = args [0 ];
7
20
var catted_anything = false ;
8
- for (arg in args [1... ]) {
21
+ for (arg , args [1... ]) {
9
22
if (arg == "-" ) {
10
23
catted_anything = true ;
11
- cat_stream (stdin ) !! ( err ) = > return err ;
24
+ ! return cat_stream (stdin );
12
25
} else if (arg [0 ] == '-' ) {
13
26
return usage (exe );
14
27
} else {
@@ -20,20 +33,20 @@ pub fn main(args: [][]u8) error => {
20
33
defer is .close ();
21
34
22
35
catted_anything = true ;
23
- cat_stream (is ) !! ( err ) = > return err ;
36
+ ! return cat_stream (is );
24
37
}
25
38
}
26
- if (! catted_anything ) {
27
- cat_stream (stdin ) !! ( err ) = > return err ;
39
+ if (~ catted_anything ) {
40
+ ! return cat_stream (stdin )
28
41
}
29
42
}
30
43
31
- fn usage (exe : []u8 ) error = > {
44
+ fn usage (exe : []u8 ) ! void = > {
32
45
stderr .print ("Usage: {} [FILE]...\n " , exe );
33
- return error . Invalid ;
46
+ return ! Invalid ;
34
47
}
35
48
36
- fn cat_stream (is : InputStream ) error = > {
49
+ fn cat_stream (is : InputStream ) ! void = > {
37
50
var buf : [1024 * 4 ]u8 ;
38
51
39
52
while (true ) {
0 commit comments