update to latest zig
This commit is contained in:
parent
667e6cbdac
commit
9937365433
10 changed files with 46 additions and 51 deletions
|
@ -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: '{s}'\n", .{magic});
|
||||
return BMPValidError.InvalidMagic;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ 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 {s} ({s})\n", .{
|
||||
self.filepath,
|
||||
c.sf_error_number(st),
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ 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 {s} ({s})\n", .{
|
||||
path,
|
||||
c.sf_error_number(st),
|
||||
});
|
||||
|
@ -181,7 +181,7 @@ pub const Image = struct {
|
|||
pub fn close(self: *Image) void {
|
||||
var st: i32 = c.sf_close(self.sndfile);
|
||||
if (st != 0) {
|
||||
std.debug.warn("Failed to close {} ({})\n", .{
|
||||
std.debug.warn("Failed to close {s} ({s})\n", .{
|
||||
self.path,
|
||||
c.sf_error_number(st),
|
||||
});
|
||||
|
@ -228,7 +228,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={d}, buf.len={d}, end={d}\n", .{ i, buf.len, end });
|
||||
sseek(self.sndfile, i);
|
||||
sseek(out_file, i);
|
||||
|
||||
|
@ -254,7 +254,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 {d} end {d}\n", .{ seek_pos.start, seek_pos.end });
|
||||
return seek_pos;
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,7 @@ 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 '{s}' (frames={d}, fmt.frames={d})\n", .{
|
||||
self.curpath,
|
||||
self.frames,
|
||||
in_fmt.frames,
|
||||
|
@ -310,12 +310,12 @@ pub const Image = struct {
|
|||
defer ctx.allocator.free(ports);
|
||||
|
||||
if (ctx.n_audio_in > 2) {
|
||||
std.debug.warn("plugin <{}> has more than two inputs.\n", .{plugin_uri});
|
||||
std.debug.warn("plugin <{s}> 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 <{s}> has more than two outputs.\n", .{plugin_uri});
|
||||
return ImageError.InvalidPlugin;
|
||||
}
|
||||
|
||||
|
@ -327,14 +327,14 @@ pub const Image = struct {
|
|||
|
||||
var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr);
|
||||
const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse {
|
||||
std.debug.warn("assert fail: symbol {} not found on port\n", .{param.sym});
|
||||
std.debug.warn("assert fail: symbol {s} 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={s}, idx={d} to val={}\n", .{
|
||||
param.sym,
|
||||
idx,
|
||||
param.value,
|
||||
|
@ -345,7 +345,7 @@ pub const Image = struct {
|
|||
// 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 '{s}' to '{s}'\n", .{ self.curpath, tmpnam });
|
||||
|
||||
var out_fmt = mkSfInfo();
|
||||
var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt);
|
||||
|
@ -378,7 +378,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: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end });
|
||||
|
||||
var inbuf = &rctx.buffers.in;
|
||||
var outbuf = &rctx.buffers.out;
|
||||
|
@ -389,7 +389,7 @@ pub const Image = struct {
|
|||
|
||||
const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1);
|
||||
if (read_bytes == 0) {
|
||||
std.debug.warn("WARN! reached EOF at idx={}\n", .{i});
|
||||
std.debug.warn("WARN! reached EOF at idx={d}\n", .{i});
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ pub const Image = struct {
|
|||
}
|
||||
|
||||
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 '{s}' to '{s}'\n", .{ self.curpath, out_path });
|
||||
try std.fs.copyFileAbsolute(self.curpath, out_path, .{});
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,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 '{s}' to '{s}'\n", .{ self.curpath, tmpnam });
|
||||
|
||||
var out_fmt = mkSfInfo();
|
||||
var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt);
|
||||
|
@ -477,7 +477,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: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end });
|
||||
|
||||
var inbuf = &bufs.in;
|
||||
var outbuf = &bufs.out;
|
||||
|
@ -485,7 +485,7 @@ pub const Image = struct {
|
|||
while (i <= seek_pos.end) : (i += 1) {
|
||||
const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1);
|
||||
if (read_bytes == 0) {
|
||||
std.debug.warn("WARN! reached EOF at idx={}\n", .{i});
|
||||
std.debug.warn("WARN! reached EOF at idx={d}\n", .{i});
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
10
src/lang.zig
10
src/lang.zig
|
@ -146,7 +146,7 @@ pub const Command = struct {
|
|||
}
|
||||
|
||||
pub fn print(base: *const @This()) void {
|
||||
std.debug.warn("tag: {}\n", .{base.tag});
|
||||
std.debug.warn("tag: {s}\n", .{base.tag});
|
||||
}
|
||||
|
||||
pub const Noop = struct {
|
||||
|
@ -549,7 +549,7 @@ pub const Lang = struct {
|
|||
inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| {
|
||||
const maybe_arg = tok_it.next();
|
||||
if (maybe_arg == null) {
|
||||
self.doError("Expected parameter for {}, got nothing", .{cmd_field.name});
|
||||
self.doError("Expected parameter for {s}, got nothing", .{cmd_field.name});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -580,7 +580,7 @@ pub const Lang = struct {
|
|||
else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."),
|
||||
};
|
||||
|
||||
std.debug.warn("parsing {}, arg of type {} => {}\n", .{
|
||||
std.debug.warn("parsing {s}, arg of type {s} => {any}\n", .{
|
||||
@typeName(command_struct),
|
||||
@typeName(@TypeOf(argument_value)),
|
||||
argument_value,
|
||||
|
@ -592,7 +592,7 @@ pub const Lang = struct {
|
|||
|
||||
cmd.base.tag = command_struct.base_tag;
|
||||
const command = cmd.base.cast(command_struct).?;
|
||||
std.debug.warn("cmd: {}\n", .{command});
|
||||
std.debug.warn("cmd: {s}\n", .{command});
|
||||
|
||||
try commands.append(&cmd.base);
|
||||
}
|
||||
|
@ -653,7 +653,7 @@ pub const Lang = struct {
|
|||
}
|
||||
|
||||
if (!found) {
|
||||
self.doError("Unknown command '{}' ({})", .{ command_string, command_string.len });
|
||||
self.doError("Unknown command '{s}' ({d} bytes)", .{ command_string, command_string.len });
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,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 {d} is neither input or output\n", .{i});
|
||||
return error.UnassignedIOPort;
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,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 {d} has unsupported type\n", .{i});
|
||||
return error.UnsupportedPortType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,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 '{s}'\n", .{curpath});
|
||||
|
||||
if (mc.MagickReadImage(mctx.wand, curpath.ptr) != 1)
|
||||
return error.MagickReadFail;
|
||||
|
@ -54,7 +54,7 @@ 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 '{s}'..", .{c_tmpnam});
|
||||
|
||||
if (mc.MagickWriteImage(wand, c_tmpnam.ptr) != 1)
|
||||
return error.MagickWriteFail;
|
||||
|
|
|
@ -38,7 +38,7 @@ fn copyCommandToHeap(allocator: *std.mem.Allocator, command: langs.Command, comp
|
|||
|
||||
pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void {
|
||||
var stdout_file = std.io.getStdOut();
|
||||
const stdout = &stdout_file.outStream();
|
||||
const stdout = &stdout_file.writer();
|
||||
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
|
||||
|
||||
var file_read_opt: ?std.fs.File = std.fs.cwd().openFile(scri_path, .{}) catch |err| blk: {
|
||||
|
@ -95,7 +95,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void {
|
|||
});
|
||||
defer file.close();
|
||||
|
||||
var out = file.outStream();
|
||||
var out = file.writer();
|
||||
var stream = &out;
|
||||
|
||||
// since we opened the file for writing, it becomes empty, so, to ensure
|
||||
|
|
|
@ -137,7 +137,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 {
|
||||
std.debug.warn("Invalid plugin URI <{}>\n", .{plugin_uri});
|
||||
std.debug.warn("Invalid plugin URI <{s}>\n", .{plugin_uri});
|
||||
return ImageError.InvalidPlugin;
|
||||
};
|
||||
defer c.lilv_node_free(uri);
|
||||
|
@ -145,7 +145,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 {
|
||||
std.debug.warn("Plugin <{}> not found\n", .{plugin_uri});
|
||||
std.debug.warn("Plugin <{s}> not found\n", .{plugin_uri});
|
||||
return ImageError.UnknownPlugin;
|
||||
};
|
||||
|
||||
|
|
|
@ -3,12 +3,14 @@ const langs = @import("lang.zig");
|
|||
|
||||
fn printCommandWithParams(stream: anytype, command: anytype) !void {
|
||||
const Parameters = @TypeOf(command.parameters);
|
||||
try stream.print(" {} {}", .{ command.split, command.index });
|
||||
try stream.print(" {d} {d}", .{ command.split, command.index });
|
||||
inline for (@typeInfo(Parameters).Struct.fields) |field| {
|
||||
if (field.field_type == f32 or field.field_type == f64) {
|
||||
try stream.print(" {}", .{@field(command.parameters, field.name)});
|
||||
} else if (field.field_type == usize or field.field_type == u64) {
|
||||
try stream.print(" {d}", .{@field(command.parameters, field.name)});
|
||||
} else {
|
||||
try stream.print(" {}", .{@field(command.parameters, field.name)});
|
||||
try stream.print(" {s}", .{@field(command.parameters, field.name)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +19,6 @@ fn printCommand(stream: anytype, cmd: *langs.Command, comptime tag: langs.Comman
|
|||
const CommandStruct = langs.Command.tagToType(tag);
|
||||
const casted = cmd.cast(CommandStruct).?;
|
||||
|
||||
// TODO move this to Tag method?
|
||||
const is_typed = switch (tag) {
|
||||
.noop, .load, .quicksave, .runqs, .rotate => false,
|
||||
else => true,
|
||||
};
|
||||
|
||||
const ctype = CommandStruct.command_type;
|
||||
switch (ctype) {
|
||||
.lv2_command => try printCommandWithParams(stream, casted),
|
||||
|
@ -33,21 +29,21 @@ fn printCommand(stream: anytype, cmd: *langs.Command, comptime tag: langs.Comman
|
|||
pub fn printList(list: langs.CommandList, stream: anytype) !void {
|
||||
for (list.list.items) |cmd| {
|
||||
const command = @tagName(cmd.tag);
|
||||
try stream.print("{}", .{command});
|
||||
try stream.print("{s}", .{command});
|
||||
|
||||
switch (cmd.tag) {
|
||||
.load => {
|
||||
const load = cmd.cast(langs.Command.Load).?;
|
||||
try stream.print(" {}", .{load.path});
|
||||
try stream.print(" {s}", .{load.path});
|
||||
},
|
||||
.runqs => {
|
||||
const runqs = cmd.cast(langs.Command.RunQS).?;
|
||||
try stream.print(" {}", .{runqs.program});
|
||||
try stream.print(" {s}", .{runqs.program});
|
||||
},
|
||||
.noop, .quicksave => {},
|
||||
.rotate => {
|
||||
const rotate = cmd.cast(langs.Command.Rotate).?;
|
||||
try stream.print(" {d} {}", .{ rotate.deg, rotate.bgfill });
|
||||
try stream.print(" {d} {s}", .{ rotate.deg, rotate.bgfill });
|
||||
},
|
||||
|
||||
.amp => try printCommand(stream, cmd, .amp),
|
||||
|
|
|
@ -67,11 +67,10 @@ pub const Runner = struct {
|
|||
// ':0' should ALWAYS point to the image.
|
||||
if (self.repl) index += 3 else index += 2;
|
||||
|
||||
std.debug.warn("ARGS!! {} \n", .{self.args.len});
|
||||
for (self.args) |arg, idx| {
|
||||
std.debug.warn("arg{} = {}\n", .{ idx, arg });
|
||||
std.debug.warn("arg{d} = {s}\n", .{ idx, arg });
|
||||
}
|
||||
std.debug.warn("fetch arg idx={}, val={}\n", .{ index, self.args[index] });
|
||||
std.debug.warn("fetch arg idx={d}, val={s}\n", .{ index, self.args[index] });
|
||||
return self.args[index];
|
||||
} else {
|
||||
return load_path;
|
||||
|
@ -91,7 +90,7 @@ pub const Runner = struct {
|
|||
|
||||
fn loadCmd(self: *Runner, path_or_argidx: []const u8) !void {
|
||||
const load_path = try self.resolveArgPath(path_or_argidx);
|
||||
std.debug.warn("\tload path: {}\n", .{load_path});
|
||||
std.debug.warn("\tload path: {s}\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.
|
||||
|
@ -101,7 +100,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. Got path '{}'\n", .{load_path});
|
||||
std.debug.warn("Only BMP files are allowed to be loaded. Got path '{s}'\n", .{load_path});
|
||||
return RunError.NoBMP;
|
||||
}
|
||||
|
||||
|
@ -138,7 +137,7 @@ 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, "{s}_g", .{
|
||||
basename[0..period_idx],
|
||||
});
|
||||
defer self.allocator.free(starts_with);
|
||||
|
@ -172,7 +171,7 @@ pub const Runner = struct {
|
|||
}
|
||||
}
|
||||
|
||||
const out_path = try std.fmt.allocPrint(self.allocator, "{}/{}{}{}", .{
|
||||
const out_path = try std.fmt.allocPrint(self.allocator, "{s}/{s}{d}{s}", .{
|
||||
dirname,
|
||||
starts_with,
|
||||
max + 1,
|
||||
|
@ -202,7 +201,7 @@ pub const Runner = struct {
|
|||
);
|
||||
defer proc.deinit();
|
||||
|
||||
std.debug.warn("running '{} {}'\n", .{ runqs.program, out_path });
|
||||
std.debug.warn("running '{s} {s}'\n", .{ runqs.program, out_path });
|
||||
_ = try proc.spawnAndWait();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue