Skip to content

Commit 92dccde

Browse files
committed
revise plan for cat example
1 parent ea21d2b commit 92dccde

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

example/cat/main.zig

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@ export executable "cat";
22

33
import "std.zig";
44

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 => {
619
const exe = args[0];
720
var catted_anything = false;
8-
for (arg in args[1...]) {
21+
for (arg, args[1...]) {
922
if (arg == "-") {
1023
catted_anything = true;
11-
cat_stream(stdin) !! (err) => return err;
24+
!return cat_stream(stdin);
1225
} else if (arg[0] == '-') {
1326
return usage(exe);
1427
} else {
@@ -20,20 +33,20 @@ pub fn main(args: [][]u8) error => {
2033
defer is.close();
2134

2235
catted_anything = true;
23-
cat_stream(is) !! (err) => return err;
36+
!return cat_stream(is);
2437
}
2538
}
26-
if (!catted_anything) {
27-
cat_stream(stdin) !! (err) => return err;
39+
if (~catted_anything) {
40+
!return cat_stream(stdin)
2841
}
2942
}
3043

31-
fn usage(exe: []u8) error => {
44+
fn usage(exe: []u8) !void => {
3245
stderr.print("Usage: {} [FILE]...\n", exe);
33-
return error.Invalid;
46+
return !Invalid;
3447
}
3548

36-
fn cat_stream(is: InputStream) error => {
49+
fn cat_stream(is: InputStream) !void => {
3750
var buf: [1024 * 4]u8;
3851

3952
while (true) {

0 commit comments

Comments
 (0)