ref: 9b51700784b0b76155ad10591b9c224cf80cf3a6
dir: /util.myr/
use std pkg bld = const run : (cmd : byte[:][:], dir : byte[:] -> void) const swapsuffix : (f : byte[:], suff : byte[:], newsuff : byte[:] -> byte[:]) const strlistfree : (sl : byte[:][:] -> void) ;; const run = {cmd, dir var pid var status printcmd(cmd) pid = std.fork() if pid == -1 std.fatal(1, "could not fork command\n") elif pid == 0 if dir.len > 0 std.chdir(dir) ;; if std.execvp(cmd[0], cmd) < 0 std.fatal(1, "failed to exec %s\n", cmd[0]) ;; else std.waitpid(pid, &status, 0) ;; match std.waitstatus(status) | `std.Waitexit estatus: if estatus != 0 std.exit(estatus castto(int)) ;; | `std.Waitsig sig: std.fatal(1, "%s exited with signal %i\n", cmd[0], sig) ;; } const printcmd = {lst if lst.len > 0 std.put("\t") std.put("%s\t", lst[0]) for l in lst[1:] std.put("%s ", l) ;; ;; std.put("\n") } const swapsuffix = {f, suff, newsuff if std.hassuffix(f, suff) f = f[:f.len - suff.len] ;; -> std.fmt("%s%s", f, newsuff) } const strlistfree = {sl for s in sl std.slfree(s) ;; std.slfree(sl) }