port main() code path to latest zig

This commit is contained in:
Luna 2022-04-28 00:08:52 -03:00
parent 1987c4d497
commit 2796b654e5
3 changed files with 9 additions and 9 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
zig-cache/
zig-out/
*.mp3
*.wav
build_runner.zig

View file

@ -161,7 +161,7 @@ pub const Image = struct {
var in_fmt = mkSfInfo();
// clone sndfile
var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt);
std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames));
std.debug.assert(self.frames == @intCast(usize, in_fmt.frames));
var image = try self.allocator.create(Image);

View file

@ -41,7 +41,7 @@ fn copyCommandToHeap(allocator: std.mem.Allocator, command: langs.Command, compt
pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void {
var stdout_file = std.io.getStdOut();
const stdout = &stdout_file.writer();
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
const scri_path = (args_it.next() orelse @panic("expected scri path"));
errdefer allocator.free(scri_path);
defer allocator.free(scri_path);
@ -246,8 +246,7 @@ fn doRun(allocator: std.mem.Allocator, args_it: anytype) !void {
var runner = runners.Runner.init(allocator, false);
defer runner.deinit();
const scri_path = try (args_it.next(allocator) orelse @panic("run: expected scri path"));
defer allocator.free(scri_path);
const scri_path = (args_it.next() orelse @panic("run: expected scri path"));
var file = try std.fs.cwd().openFile(scri_path, .{});
defer file.close();
@ -270,18 +269,18 @@ pub fn main() !void {
defer {
_ = allocator_instance.deinit();
}
const allocator = &allocator_instance.allocator;
const allocator = allocator_instance.allocator();
var args_it = std.process.args();
var args_it = try std.process.argsWithAllocator(allocator);
defer args_it.deinit();
_ = args_it.skip();
const cli_command_opt = args_it.next(allocator);
const cli_command_opt = args_it.next();
if (cli_command_opt == null) {
return doHelp();
}
const cli_command = try cli_command_opt.?;
defer allocator.free(cli_command);
const cli_command = cli_command_opt.?;
if (std.mem.eql(u8, cli_command, "help")) {
return doHelp();