shithub: mc

Download patch

ref: de38fba80d0e8ee4b95c4e2ee8cd89d5b114a4ba
parent: c24fd19a65d43478eec1841c95c17b90a6a20eb4
author: Ori Bernstein <[email protected]>
date: Sat May 31 13:54:01 EDT 2014

Convert from 'error' to 'result'.

--- a/libstd/dial.myr
+++ b/libstd/dial.myr
@@ -1,7 +1,7 @@
 use "alloc.use"
 use "chartype.use"
 use "die.use"
-use "error.use"
+use "result.use"
 use "sys.use"
 use "sleq.use"
 use "option.use"
@@ -14,7 +14,7 @@
 use "utf.use"
 
 pkg std =
-	const dial	: (dialstr : byte[:] -> error(fd, byte[:]))
+	const dial	: (dialstr : byte[:] -> result(fd, byte[:]))
 ;;
 
 /*
@@ -38,17 +38,17 @@
 	(port, str) = nameseg(str)
 
 	if proto.len == 0
-		-> `Failure "missing proto"
+		-> `Fail "missing proto"
 	elif host.len == 0
-		-> `Failure "missing host"
+		-> `Fail "missing host"
 	elif port.len == 0
-		-> `Failure "missing port"
+		-> `Fail "missing port"
 	;;
 
 	if sleq(proto, "net")
-		-> `Failure "net wildcard proto not yet supported\n"
+		-> `Fail "net wildcard proto not yet supported\n"
 	elif sleq(proto, "unix")
-		-> `Failure "net unix proto not yet supported\n"
+		-> `Fail "net unix proto not yet supported\n"
 	elif sleq(proto, "tcp")
 		socktype = Sockstream
 	elif sleq(proto, "udp")
@@ -57,7 +57,7 @@
 
 	match parseport(port)
 	| `Some n:	portnum = n
-	| `None:	-> `Failure "bad port"
+	| `None:	-> `Fail "bad port"
 	;;
 
 	match getaddr(host)
@@ -66,12 +66,12 @@
 		sa.addr = bits
 		sa.port = hosttonet(portnum)
 	| `Ipv6 bits:
-		-> `Failure "ipv6 not yet supported"
+		-> `Fail "ipv6 not yet supported"
 	;;
 
 	sock = socket(sa.fam, socktype, 0)
 	if sock < 0
-		-> `Failure "failed to connect to socket"
+		-> `Fail "failed to connect to socket"
 	;;
 	var err
 	err = connect(sock, (&sa) castto(sockaddr#), sizeof(sockaddr_in))
@@ -78,10 +78,10 @@
 	if err < 0
 		put("Errno %i\n", -err)
 		close(sock)
-		-> `Failure "Failed to bind socket"
+		-> `Fail "Failed to bind socket"
 	;;
 
-	-> `Success sock
+	-> `Ok sock
 }
 
 const parseport = {port
@@ -109,10 +109,10 @@
 	| `Some a:	ip = a
 	| `None:
 		match resolve(addr)
-		| `Success hi:
+		| `Ok hi:
 			ip = hi[0].addr
 			slfree(hi)
-		| `Failure m:
+		| `Fail m:
 		;;
 	;;
 	-> ip
--- a/libstd/resolve.myr
+++ b/libstd/resolve.myr
@@ -2,7 +2,7 @@
 use "chartype.use"
 use "die.use"
 use "endian.use"
-use "error.use"
+use "result.use"
 use "extremum.use"
 use "fmt.use"
 use "hashfuncs.use"
@@ -61,9 +61,9 @@
 	*/
 	;;
 
-	const resolve	: (host : byte[:]	-> error(hostinfo[:], resolveerr))
-	const resolvemx	: (host : byte[:]	-> error(hostinfo[:], resolveerr))
-	const resolverec	: (host : byte[:], t : rectype	-> error(hostinfo[:], resolveerr))
+	const resolve	: (host : byte[:]	-> result(hostinfo[:], resolveerr))
+	const resolvemx	: (host : byte[:]	-> result(hostinfo[:], resolveerr))
+	const resolverec	: (host : byte[:], t : rectype	-> result(hostinfo[:], resolveerr))
 ;;
 
 const Hostfile = "/etc/hosts"
@@ -86,7 +86,7 @@
 const resolverec = {host, t
 	match hostfind(host)
 	| `Some hinf:
-		-> `Success slpush([][:], hinf)
+		-> `Ok slpush([][:], hinf)
 	| `None:
 		-> dnsresolve(host, DnsA)
 	;;
@@ -107,8 +107,8 @@
 	var lines
 
 	match slurp(Hostfile)
-	| `Success d:	h = d
-	| `Failure m:	->
+	| `Ok d:	h = d
+	| `Fail m:	->
 	;;
 
 	lines = strsplit(h, "\n")
@@ -162,8 +162,8 @@
 	var lines
 
 	match slurp(Resolvfile)
-	| `Success d:	h = d
-	| `Failure m:	->
+	| `Ok d:	h = d
+	| `Fail m:	->
 	;;
 
 	lines = strsplit(h, "\n")
@@ -214,7 +214,7 @@
 	var nsrv
 
 	if !valid(host)
-		-> `Failure (`Badhost)
+		-> `Fail (`Badhost)
 	;;
 	for ns in nameservers
 		nsrv = dnsconnect(ns)
@@ -222,7 +222,7 @@
 			-> dnsquery(nsrv, host, t)
 		;;
 	;;
-	-> `Failure (`Badsrv)
+	-> `Fail (`Badsrv)
 }
 
 const dnsconnect = {ns
@@ -311,7 +311,7 @@
 	/* parse header */
 	(v, off) = unpack16(pkt, off)	/* id */
 	if v != id
-		-> `Failure (`Badresp)
+		-> `Fail (`Badresp)
 	;;
 	(v, off) = unpack16(pkt, off)	/* flags */
 	(q, off) = unpack16(pkt, off)	/* qdcount */
@@ -338,7 +338,7 @@
 		hinf[i].addr = `Ipv4 [pkt[off], pkt[off+1], pkt[off+2], pkt[off+3]]
 		off += 4;
 	;;
-	-> `Success hinf
+	-> `Ok hinf
 }
 
 
--- a/libstd/slurp.myr
+++ b/libstd/slurp.myr
@@ -1,6 +1,6 @@
 use "alloc.use"
 use "die.use"
-use "error.use"
+use "result.use"
 use "extremum.use"
 use "fmt.use"
 use "sys.use"
@@ -7,7 +7,7 @@
 use "types.use"
 
 pkg std =
-	const slurp : (path : byte[:] -> error(byte[:], byte[:]))
+	const slurp : (path : byte[:] -> result(byte[:], byte[:]))
 ;;
 
 const Bufinc = 4096
@@ -20,7 +20,7 @@
 
 	fd = open(path, Ordonly, 0o777)
 	if fd < 0
-		-> `Failure "Could not open file"
+		-> `Fail "Could not open file"
 	;;
 
 	len = 0
@@ -34,5 +34,5 @@
 		buf = slgrow(buf, len + Bufinc)
 	;;
 :done
-	-> `Success buf[:len]
+	-> `Ok buf[:len]
 }