fix for latest zig

This commit is contained in:
Luna 2020-01-14 22:31:20 -03:00
parent a10416e56f
commit 182d368363
10 changed files with 64 additions and 76 deletions

View file

@ -20,7 +20,7 @@ pub fn magicValid(magic: []const u8) !void {
}
if (!valid) {
std.debug.warn("\tINVALID HEADER: '{}'\n", magic);
std.debug.warn("\tINVALID HEADER: '{}'\n", .{magic});
return BMPValidError.InvalidMagic;
}
}

View file

@ -181,11 +181,10 @@ pub const Embed = struct {
if (read_bytes < 0) {
const st: i32 = c.sf_error(self.sndfile);
std.debug.warn(
"Failed to read {} ({})\n",
std.debug.warn("Failed to read {} ({})\n", .{
self.filepath,
c.sf_error_number(st),
);
});
return;
}

View file

@ -32,11 +32,10 @@ pub fn sopen(
const st: i32 = c.sf_error(file);
if (st != 0) {
std.debug.warn(
"Failed to open {} ({})\n",
std.debug.warn("Failed to open {} ({})\n", .{
path,
c.sf_error_number(st),
);
});
return ImageError.OpenFail;
}
@ -48,7 +47,7 @@ pub fn sopen(
const frames_on_end_by_end = c.sf_seek(file, frames_on_end, c.SEEK_SET);
std.testing.expectEqual(frames_on_end, frames_on_end_by_end);
std.debug.warn("frames on end: {}, frame on end (2): {}\n", frames_on_end, frames_on_end_by_end);
std.debug.warn("frames on end: {}, frame on end (2): {}\n", .{ frames_on_end, frames_on_end_by_end });
return file.?;
}
@ -57,7 +56,7 @@ pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void {
const count = c.sf_writef_float(file, buf, frames);
if (count != frames) {
std.debug.warn("Wanted to write {}, got {}\n", frames, count);
std.debug.warn("Wanted to write {}, got {}\n", .{ frames, count });
return ImageError.WriteFail;
}
}
@ -69,7 +68,7 @@ pub fn sseek(file: *c.SNDFILE, offset: usize) void {
std.testing.expectEqual(frames, frames_current);
if (frames != offset_i64) {
std.debug.warn("failed to seek to {} (seeked {} frames, offset_i64={})\n", offset, frames, offset_i64);
std.debug.warn("failed to seek to {} (seeked {} frames, offset_i64={})\n", .{ offset, frames, offset_i64 });
}
}
@ -180,11 +179,10 @@ pub const Image = struct {
var st: i32 = c.sf_close(self.sndfile);
if (st != 0) {
std.debug.warn(
"Failed to close {} ({})\n",
std.debug.warn("Failed to close {} ({})\n", .{
self.path,
c.sf_error_number(st),
);
});
}
}
@ -221,7 +219,7 @@ pub const Image = struct {
sseek(out_file, start);
while (i <= end) : (i += buf.len) {
std.debug.warn("\t\ti={}, buf.len={}, end={}\n", i, buf.len, end);
std.debug.warn("\t\ti={}, buf.len={}, end={}\n", .{ i, buf.len, end });
sseek(self.sndfile, i);
sseek(out_file, i);
@ -247,7 +245,7 @@ pub const Image = struct {
fn getSeekPos(self: *Image, position: plugins.Position) plugins.SeekPos {
const file_end = self.frames;
var seek_pos = position.seekPos(file_end);
std.debug.warn("\tstart {} end {}\n", seek_pos.start, seek_pos.end);
std.debug.warn("\tstart {} end {}\n", .{ seek_pos.start, seek_pos.end });
return seek_pos;
}
@ -260,12 +258,11 @@ pub const Image = struct {
self.curpath = path;
self.frames = @intCast(usize, in_fmt.frames);
std.debug.warn(
"\timage: reopened on '{}' (frames={}, fmt.frames={})\n",
std.debug.warn("\timage: reopened on '{}' (frames={}, fmt.frames={})\n", .{
self.curpath,
self.frames,
in_fmt.frames,
);
});
}
pub fn checkValid(self: *Image) !void {
@ -303,45 +300,42 @@ pub const Image = struct {
var ports = try lv2.setupPorts(&ctx);
if (ctx.n_audio_in > 2) {
std.debug.warn("plugin <{}> has more than two inputs.\n", plugin_uri);
std.debug.warn("plugin <{}> has more than two inputs.\n", .{plugin_uri});
return ImageError.InvalidPlugin;
}
if (ctx.n_audio_out > 2) {
std.debug.warn("plugin <{}> has more than two outputs.\n", plugin_uri);
std.debug.warn("plugin <{}> has more than two outputs.\n", .{plugin_uri});
return ImageError.InvalidPlugin;
}
// now, for each param for the plugin, we find its port, and set
// the value for the port there.
var it = params.iterator();
while (it.next()) |param| {
for (params.toSlice()) |param| {
var sym_cstr = try std.cstr.addNullByte(self.allocator, param.sym);
defer self.allocator.free(sym_cstr);
var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr);
const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse blk: {
std.debug.warn("assert fail: symbol {} not found on port\n", param.sym);
std.debug.warn("assert fail: symbol {} not found on port\n", .{param.sym});
return ImageError.InvalidSymbol;
};
c.lilv_node_free(sym);
var idx = c.lilv_port_get_index(ctx.plugin, port);
std.debug.warn(
"\tset sym={}, idx={} to val={}\n",
std.debug.warn("\tset sym={}, idx={} to val={}\n", .{
param.sym,
idx,
param.value,
);
});
(&ports[idx]).value = param.value;
}
// now we need to generate a temporary file and put the output of
// running the plugin on that file
var tmpnam = try temporaryName(self.allocator);
std.debug.warn("\trunning plugin from '{}' to '{}'\n", self.curpath, tmpnam);
std.debug.warn("\trunning plugin from '{}' to '{}'\n", .{ self.curpath, tmpnam });
var out_fmt = mkSfInfo();
var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt);
@ -374,7 +368,7 @@ pub const Image = struct {
sseek(self.sndfile, seek_pos.start);
var i: usize = seek_pos.start;
std.debug.warn("\tseek pos start: {} end: {}\n", seek_pos.start, seek_pos.end);
std.debug.warn("\tseek pos start: {} end: {}\n", .{ seek_pos.start, seek_pos.end });
var inbuf = rctx.buffers.in;
var outbuf = rctx.buffers.out;
@ -382,7 +376,7 @@ pub const Image = struct {
while (i <= seek_pos.end) : (i += 1) {
const read_bytes = c.sf_readf_float(self.sndfile, inbuf.ptr, 1);
if (read_bytes == 0) {
std.debug.warn("WARN! reached EOF at idx={}\n", i);
std.debug.warn("WARN! reached EOF at idx={}\n", .{i});
break;
}
@ -407,11 +401,11 @@ pub const Image = struct {
try self.checkValid();
var time_taken = timer.read();
std.debug.warn("\ttook {d:.2}ms running plugin\n", time_taken / std.time.millisecond);
std.debug.warn("\ttook {d:.2}ms running plugin\n", .{time_taken / std.time.millisecond});
}
pub fn saveTo(self: *Image, out_path: []const u8) !void {
std.debug.warn("\timg: copy from '{}' to '{}'\n", self.curpath, out_path);
std.debug.warn("\timg: copy from '{}' to '{}'\n", .{ self.curpath, out_path });
try std.fs.copyFile(self.curpath, out_path);
}
@ -440,7 +434,7 @@ pub const Image = struct {
// the code here is a copypaste of runPlugin() without the specific
// lilv things.
var tmpnam = try temporaryName(self.allocator);
std.debug.warn("\trunning CUSTOM plugin from '{}' to '{}'\n", self.curpath, tmpnam);
std.debug.warn("\trunning CUSTOM plugin from '{}' to '{}'\n", .{ self.curpath, tmpnam });
var out_fmt = mkSfInfo();
var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt);
@ -469,7 +463,7 @@ pub const Image = struct {
sseek(self.sndfile, seek_pos.start);
var i: usize = seek_pos.start;
std.debug.warn("\tseek pos start: {} end: {}\n", seek_pos.start, seek_pos.end);
std.debug.warn("\tseek pos start: {} end: {}\n", .{ seek_pos.start, seek_pos.end });
var inbuf = bufs.in;
var outbuf = bufs.out;
@ -477,7 +471,7 @@ pub const Image = struct {
while (i <= seek_pos.end) : (i += 1) {
const read_bytes = c.sf_readf_float(self.sndfile, bufs.in.ptr, 1);
if (read_bytes == 0) {
std.debug.warn("WARN! reached EOF at idx={}\n", i);
std.debug.warn("WARN! reached EOF at idx={}\n", .{i});
break;
}

View file

@ -41,14 +41,14 @@ pub const Command = struct {
cur_idx: usize = 0,
pub fn print(self: Command) void {
std.debug.warn("cmd:{}\n", self.command);
std.debug.warn("cmd:{}\n", .{self.command});
}
pub fn argAt(self: Command, idx: usize) ![]const u8 {
std.debug.warn("{} {}", idx, self.args.len);
std.debug.warn("{} {}", .{ idx, self.args.len });
if (idx > (self.args.len - 1)) {
std.debug.warn("Expected argument at index {}\n", idx);
std.debug.warn("Expected argument at index {}\n", .{idx});
return ParseError.ArgRequired;
}
@ -91,7 +91,7 @@ pub const Command = struct {
while (i < elements) : (i += 1) {
var value: f32 = self.floatArgAt(i) catch |err| blk: {
std.debug.warn("\tdoing default on arg {}\n", i);
std.debug.warn("\tdoing default on arg {}\n", .{i});
break :blk default;
};
@ -270,7 +270,7 @@ pub const Lang = struct {
fn expectAny(self: *Lang, count: usize, args: ArgList) !void {
if (args.len != count) {
self.doError("expected {} arguments, found {}", count, args.len);
self.doError("expected {} arguments, found {}", .{ count, args.len });
return error.ArgRequired;
}
}
@ -283,7 +283,7 @@ pub const Lang = struct {
var i: usize = 0;
if (args.len != count) {
self.doError("expected {} arguments, found {}", count, args.len);
self.doError("expected {} arguments, found {}", .{ count, args.len });
return error.ArgRequired;
}
@ -291,7 +291,7 @@ pub const Lang = struct {
var arg = args.at(i);
_ = std.fmt.parseFloat(f32, arg) catch |err| {
std.debug.warn("failed to parse f32: {}\n", err);
std.debug.warn("failed to parse f32: {}\n", .{err});
return error.FloatParseFail;
};
}
@ -318,14 +318,14 @@ pub const Lang = struct {
.Write => try self.expectFloat(3, cmd.args),
.Rotate => try self.expectAny(2, cmd.args),
.Embed => try self.expectAny(3, cmd.args),
else => std.debug.warn("WARN unchecked command {}\n", cmd.command),
else => std.debug.warn("WARN unchecked command {}\n", .{cmd.command}),
}
}
fn doError(self: *Lang, comptime fmt: []const u8, args: ...) void {
std.debug.warn("error at line {}: ", self.line);
fn doError(self: *Lang, comptime fmt: []const u8, args: var) void {
std.debug.warn("error at line {}: ", .{self.line});
std.debug.warn(fmt, args);
std.debug.warn("\n");
std.debug.warn("\n", .{});
self.has_error = true;
}
@ -347,7 +347,7 @@ pub const Lang = struct {
var cmd_opt = tok_it.next();
if (cmd_opt == null) {
self.doError("No command given");
self.doError("No command given", .{});
continue;
}
var command = cmd_opt.?;
@ -357,7 +357,7 @@ pub const Lang = struct {
if (ctype_opt) |ctype_val| {
ctype = ctype_val;
} else {
self.doError("Unknown command '{}' ({})", command, command.len);
self.doError("Unknown command '{}' ({})", .{ command, command.len });
continue;
}

View file

@ -116,7 +116,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port {
if (c.lilv_port_is_a(ctx.plugin, lport, lv2_InputPort)) {
port.is_input = true;
} else if (!c.lilv_port_is_a(ctx.plugin, lport, lv2_OutputPort) and !port.optional) {
std.debug.warn("Port {} is neither input or output\n", i);
std.debug.warn("Port {} is neither input or output\n", .{i});
return error.UnassignedIOPort;
}
@ -132,7 +132,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port {
ctx.n_audio_out += 1;
}
} else if (!port.optional) {
std.debug.warn("Port {} has unsupported type\n", i);
std.debug.warn("Port {} has unsupported type\n", .{i});
return error.UnsupportedPortType;
}
}

View file

@ -37,7 +37,7 @@ fn magickLoad(image: *Image) !MagickContext {
var curpath = try std.cstr.addNullByte(image.allocator, image.curpath);
defer image.allocator.free(curpath);
std.debug.warn("loading '{}'\n", curpath);
std.debug.warn("loading '{}'\n", .{curpath});
if (mc.MagickReadImage(mctx.wand, curpath.ptr) != 1)
return error.MagickReadFail;
@ -52,12 +52,12 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void {
var c_tmpnam = try std.cstr.addNullByte(allocator, tmpnam);
defer allocator.free(c_tmpnam);
std.debug.warn("\tmagick: saving to '{}'..", c_tmpnam);
std.debug.warn("\tmagick: saving to '{}'..", .{c_tmpnam});
if (mc.MagickWriteImage(wand, c_tmpnam.ptr) != 1)
return error.MagickWriteFail;
std.debug.warn("OK\n");
std.debug.warn("OK\n", .{});
try image.reopen(tmpnam);
}

View file

@ -51,8 +51,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
defer existing_cmds.deinit();
// copy the existing command list into the repl's command list
var it = existing_cmds.iterator();
while (it.next()) |existing_cmd| {
for (existing_cmds.toSlice()) |existing_cmd| {
try cmds.append(existing_cmd);
}
} else {
@ -110,7 +109,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
var rd_line = readline.readline("> ");
if (rd_line == null) {
std.debug.warn("leaving from eof\n");
std.debug.warn("leaving from eof\n", .{});
break;
}
readline.add_history(rd_line);
@ -138,14 +137,14 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
try printer.printList(cmds, stream);
continue;
} else if (std.mem.eql(u8, line, "quit") or std.mem.eql(u8, line, "q")) {
std.debug.warn("leaving\n");
std.debug.warn("leaving\n", .{});
break;
} else if (std.mem.startsWith(u8, line, "#")) {
continue;
}
var cmds_parsed = lang.parse(line) catch |err| {
std.debug.warn("repl: error while parsing: {}\n", err);
std.debug.warn("repl: error while parsing: {}\n", .{err});
continue;
};
current = cmds_parsed.at(0);

View file

@ -151,7 +151,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte
c.lilv_world_load_all(world);
var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse blk: {
std.debug.warn("Invalid plugin URI <{}>\n", plugin_uri);
std.debug.warn("Invalid plugin URI <{}>\n", .{plugin_uri});
return ImageError.InvalidPlugin;
};
defer c.lilv_node_free(uri);
@ -159,7 +159,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte
const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world);
var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse blk: {
std.debug.warn("Plugin <{}> not found\n", plugin_uri);
std.debug.warn("Plugin <{}> not found\n", .{plugin_uri});
return ImageError.UnknownPlugin;
};

View file

@ -29,10 +29,10 @@ pub fn printList(list: langs.CommandList, stream: var) !void {
.Rotate => "rotate",
};
try stream.print("{}", command);
try stream.print("{}", .{command});
for (cmd.args.toSlice()) |arg| {
try stream.print(" {}", arg);
try stream.print(" {}", .{arg});
}
try stream.write(";\n");

View file

@ -80,7 +80,7 @@ pub const Runner = struct {
fn loadCmd(self: *Runner, path_or_argidx: []const u8) !void {
var load_path = try self.resolveArgPath(path_or_argidx);
std.debug.warn("\tload path: {}\n", load_path);
std.debug.warn("\tload path: {}\n", .{load_path});
// we could use ImageMagick to convert from X to BMP
// but i can't find an easy way to do things in memory.
@ -90,7 +90,7 @@ pub const Runner = struct {
// krita/gimp and make it export a bmp and while in the program you can
// apply filters, etc.
if (!std.mem.endsWith(u8, load_path, ".bmp") and !std.mem.endsWith(u8, load_path, ".ppm")) {
std.debug.warn("Only BMP files are allowed to be loaded.\n");
std.debug.warn("Only BMP files are allowed to be loaded.\n", .{});
return RunError.NoBMP;
}
@ -104,7 +104,7 @@ pub const Runner = struct {
if (self.image) |image| {
return image;
} else {
std.debug.warn("image is required!\n");
std.debug.warn("image is required!\n", .{});
return RunError.ImageRequired;
}
}
@ -125,11 +125,9 @@ pub const Runner = struct {
// starts_with would be "x_g", we want to find all files in the directory
// that start with that name.
const starts_with = try std.fmt.allocPrint(
self.allocator,
"{}_g",
const starts_with = try std.fmt.allocPrint(self.allocator, "{}_g", .{
basename[0..period_idx],
);
});
defer self.allocator.free(starts_with);
var max: usize = 0;
@ -161,14 +159,12 @@ pub const Runner = struct {
}
}
const out_path = try std.fmt.allocPrint(
self.allocator,
"{}/{}{}{}",
const out_path = try std.fmt.allocPrint(self.allocator, "{}/{}{}{}", .{
dirname,
starts_with,
max + 1,
extension,
);
});
return out_path;
}
@ -190,7 +186,7 @@ pub const Runner = struct {
);
defer proc.deinit();
std.debug.warn("running '{} {}'\n", program, out_path);
std.debug.warn("running '{} {}'\n", .{ program, out_path });
_ = try proc.spawnAndWait();
}
@ -221,7 +217,7 @@ pub const Runner = struct {
defer params.deinit();
for (bands) |band_value, idx| {
var sym = try std.fmt.allocPrint(self.allocator, "band_{}", idx + 1);
var sym = try std.fmt.allocPrint(self.allocator, "band_{}", .{idx + 1});
try params.append(plugin.Param{
.sym = sym,
.value = band_value,
@ -482,7 +478,7 @@ pub const Runner = struct {
},
else => blk: {
std.debug.warn("Unsupported command: {}\n", cmd.command);
std.debug.warn("Unsupported command: {}\n", .{cmd.command});
break :blk RunError.UnknownCommand;
},
};