Compare commits

..

2 commits

Author SHA1 Message Date
c78ca9dd5b refactor argument fetching for load cmd 2020-06-02 16:59:53 -03:00
dc98c7a22f use better seed 2020-06-02 16:59:36 -03:00
2 changed files with 15 additions and 13 deletions

View file

@ -79,7 +79,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
var nam = try allocator.alloc(u8, template.len);
std.mem.copy(u8, nam, template);
const seed = @bitCast(u64, std.time.timestamp());
const seed = @truncate(u64, @bitCast(u128, std.time.nanoTimestamp()));
var r = std.rand.DefaultPrng.init(seed);
var fill = nam[template_start.len..nam.len];

View file

@ -49,20 +49,22 @@ pub const Runner = struct {
// parse the index from 1 to end
var index = try std.fmt.parseInt(usize, load_path[1..], 10);
// don't care about the 'repl' being prepended when we're in repl
if (self.repl) index += 1;
// if it isn't in the repl, args look like this:
// 'scritcher ./script ./image'
// if it is, it looks like this
// 'scritcher repl ./script ./image'
var args_it = std.process.args();
_ = args_it.skip();
// ':0' should ALWAYS point to the image.
if (self.repl) index += 3 else index += 2;
var i: usize = 0;
while (i <= index) : (i += 1) {
_ = args_it.skip();
var args = try std.process.argsAlloc(self.allocator);
defer std.process.argsFree(self.allocator, args);
std.debug.warn("ARGS!! {} \n", .{args.len});
for (args) |arg, idx| {
std.debug.warn("arg{} = {}\n", .{ idx, arg });
}
const arg = try (args_it.next(self.allocator) orelse @panic("expected argument"));
return arg;
std.debug.warn("fetch arg idx={}, val={}\n", .{ index, args[index] });
return args[index];
} else {
return load_path;
}
@ -90,7 +92,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. Got path '{}'\n", .{load_path});
return RunError.NoBMP;
}