various small cleanups

This commit is contained in:
Andrew Kelley 2016-01-23 03:06:29 -07:00
parent 706f72f1b4
commit 37aae53009
3 changed files with 17 additions and 15 deletions

View File

@ -9,7 +9,7 @@ endif
syn keyword zigStorage const var extern volatile export pub noalias
syn keyword zigStructure struct enum
syn keyword zigStatement goto break return continue asm
syn keyword zigStatement goto break return continue asm defer
syn keyword zigConditional if else switch
syn keyword zigRepeat while for

View File

@ -7,11 +7,10 @@ import "std.zig";
// * update std API
// * defer
// * %return
// * %% operator
// * %% binary operator
// * %% prefix operator
// * cast err type to string
pub %.Invalid;
pub fn main(args: [][]u8) %void => {
const exe = args[0];
var catted_anything = false;
@ -24,7 +23,7 @@ pub fn main(args: [][]u8) %void => {
} else {
var is: InputStream;
is.open(arg, OpenReadOnly) %% (err) => {
stderr.print("Unable to open file: {}", ([]u8])(err));
%%stderr.print("Unable to open file: {}", ([]u8])(err));
return err;
}
defer is.close();
@ -39,7 +38,7 @@ pub fn main(args: [][]u8) %void => {
}
fn usage(exe: []u8) %void => {
stderr.print("Usage: {} [FILE]...\n", exe);
%%stderr.print("Usage: {} [FILE]...\n", exe);
return %.Invalid;
}
@ -47,16 +46,18 @@ fn cat_stream(is: InputStream) %void => {
var buf: [1024 * 4]u8;
while (true) {
const bytes_read = is.read(buf);
if (bytes_read < 0) {
stderr.print("Unable to read from stream: {}", ([]u8)(is.err));
return is.err;
const bytes_read = is.read(buf) %% (err) => {
%%stderr.print("Unable to read from stream: {}", ([]u8)(err));
return err;
}
const bytes_written = stdout.write(buf[0...bytes_read]);
if (bytes_written < bytes_read) {
stderr.print("Unable to write to stdout: {}", ([]u8)(stdout.err));
return stdout.err;
if (bytes_read == 0) {
break;
}
stdout.write(buf[0...bytes_read]) %% (err) => {
%%stderr.print("Unable to write to stdout: {}", ([]u8)(err));
return err;
}
}
}

View File

@ -23,6 +23,7 @@ pub var stderr = OutStream {
.index = 0,
.buffered = false,
};
*/
pub %.Unexpected;
pub %.DiskQuota;
@ -32,7 +33,7 @@ pub %.Io;
pub %.NoSpaceLeft;
pub %.BadPerm;
pub %.PipeFail;
*/
pub %.Invalid;
const buffer_size = 4 * 1024;
const max_u64_base10_digits = 20;