shithub: mc

Download patch

ref: 288347d86a70e880a38627c6db5f66d6c7b690f3
parent: 4133ae84edc4becab38dee52de3f8e4b0d75ca45
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Sep 22 21:05:54 EDT 2014

Pull out functions into util.myr

    They're utility functions. hence util.myr

--- a/bldfile
+++ b/bldfile
@@ -1,2 +1,2 @@
 # comment
-bin mbld2 = main.myr build.myr parse.myr deps.myr config.myr opts.myr; # comment
+bin mbld2 = main.myr build.myr parse.myr deps.myr config.myr opts.myr util.myr; # comment
--- a/build.myr
+++ b/build.myr
@@ -4,6 +4,7 @@
 use "deps.use"
 use "opts.use"
 use "parse.use"
+use "util.use"
 
 pkg bld =
 	const build	: (p : parser# -> bool)
@@ -201,52 +202,3 @@
 	;;
 }
 
-const run = {cmd
-	var pid
-	var status
-
-	printcmd(cmd)
-	pid = std.fork()
-	if pid == -1
-		std.fatal(1, "could not fork command\n")
-	elif pid == 0
-		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)
-}
--- /dev/null
+++ b/util.myr
@@ -1,0 +1,58 @@
+use std
+
+pkg bld =
+	const run	: (cmd : byte[:][:] -> void)
+	const swapsuffix	: (f : byte[:], suff : byte[:], newsuff : byte[:] -> byte[:])
+	const strlistfree	: (sl : byte[:][:] -> void)
+;;
+
+
+const run = {cmd
+	var pid
+	var status
+
+	printcmd(cmd)
+	pid = std.fork()
+	if pid == -1
+		std.fatal(1, "could not fork command\n")
+	elif pid == 0
+		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)
+}