shithub: mc

Download patch

ref: ce493274718acbe4ab1562f243cacfc9d00446a0
parent: 6a8370380656d6e0d6da26d5fcebcc41005b7af3
author: Ori Bernstein <[email protected]>
date: Thu Jan 2 18:24:58 EST 2014

Add ipv4 resolution.

--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -82,6 +82,9 @@
 	-> bfmtv(buf, fmt, vastart(&args))
 }
 
+const digitchars = [
+	'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
+]
 generic intfmt = {buf : byte[:], bits : @a::(tcint,tctest,tcnum), base, signed
 	var isneg
 	var val
@@ -167,22 +170,22 @@
 			/* format integers */
 			| 'b':
 				(b_val, ap) = vanext(ap)
-				n += intfmt(buf[n:], b_val, base, signed)
+				n += intfmt(buf[n:], b_val castto(int64), base, signed)
 			| 'w':
 				(w_val, ap) = vanext(ap)
-				n += intfmt(buf[n:], w_val, base, signed)
+				n += intfmt(buf[n:], w_val castto(int64), base, signed)
 			| 'i':
 				(i_val, ap) = vanext(ap)
-				n += intfmt(buf[n:], i_val, base, signed)
+				n += intfmt(buf[n:], i_val castto(int64), base, signed)
 			| 'l':
 				(l_val, ap) = vanext(ap)
-				n += intfmt(buf[n:], l_val, base, signed)
+				n += intfmt(buf[n:], l_val castto(int64), base, signed)
 			| 'z':
 				(z_val, ap) = vanext(ap)
-				n += intfmt(buf[n:], z_val, base, signed)
+				n += intfmt(buf[n:], z_val castto(int64), base, signed)
 			| 'p':
 				(p_val, ap) = vanext(ap)
-				n += intfmt(buf[n:], p_val castto(uint64), 16, false)
+				n += intfmt(buf[n:], p_val castto(int64), 16, false)
                         | 'c':    (c_val, ap) = vanext(ap)
                                 n += encode(buf[n:], c_val)
                         | _:
@@ -214,9 +217,3 @@
 	;;
 	-> strfmt(buf, s)
 }
-
-
-const digitchars = [
-'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
-]
-
--- a/libstd/resolve.myr
+++ b/libstd/resolve.myr
@@ -4,12 +4,13 @@
 use "endian.use"
 use "error.use"
 use "extremum.use"
+use "fmt.use"
 use "hashfuncs.use"
 use "htab.use"
 use "ipparse.use"
-use "fmt.use"
 use "option.use"
 use "slcp.use"
+use "sleq.use"
 use "slpush.use"
 use "slurp.use"
 use "strfind.use"
@@ -67,6 +68,7 @@
 	if !inited
 		hostmap = mkht(strhash, streq)
 		loadhosts()
+		loadresolv()
 		inited = true
 	;;
 	-> htget(hostmap, host)
@@ -85,13 +87,12 @@
 	for l in lines
 		/* trim comment */
 		match strfind(l, "#")
-		| `Some _idx:	l = l[:_idx]
+		| `Some idx:	l = l[:idx]
 		;;
 
 		match word(l)
 		| `Some (ip, rest):
 			match ipparse(ip)
-			| `None:
 			| `Some addr:
 				addhosts(addr, ip, rest)
 			;;
@@ -98,6 +99,7 @@
 		| `None:
 		;;
 	;;
+	slfree(lines)
 }
 
 const addhosts = {addr, as, str
@@ -128,13 +130,48 @@
 }
 
 const loadresolv = {
+	var h
+	var lines
+
+	match slurp(Resolvfile)
+	| `Success d:	h = d
+	| `Failure m:	->
+	;;
+
+	lines = strsplit(h, "\n")
+	for l in lines
+		match strfind(l, "#")
+		| `Some idx: l = l[:idx]
+		| `None:
+		;;
+
+		match word(l)
+		| `Some (cmd, rest):
+			if sleq(cmd, "nameserver")
+				addns(rest)
+			;;
+		;;
+	;;
+	slfree(lines)
 }
 
+const addns = {rest
+	match word(rest)
+	| `Some (name, _):
+		match ipparse(name)
+		| `Some addr: 
+			put("Adding nameserver %s\n", name)
+			nameservers = slpush(nameservers, addr)
+		| `None:
+		;;
+	;;
+}
+
 const word = {s
 	var c, len
 
 	len = 0
-	s = strstrip(s)
+	s = strfstrip(s)
 	for c = decode(s[len:]); c != Badchar && !isblank(c); c = decode(s[len:])
 		len += charlen(c)
 	;;
@@ -153,13 +190,24 @@
 	if !valid(host)
 		-> `Failure (`Badhost)
 	;;
-	if (nsrv = dnsconnect()) < 0
-		-> `Failure (`Badsrv)
+	for ns in nameservers
+		put("trying ns\n")
+		nsrv = dnsconnect(ns)
+		if nsrv >= 0
+			-> dnsquery(nsrv, host)
+		;;
 	;;
-	-> dnsquery(nsrv, host)
+	-> `Failure (`Badsrv)
 }
 
-const dnsconnect = {
+const dnsconnect = {ns
+	match ns
+	| `Ipv4 addr:	-> dnsconnectv4(ns)
+	| `Ipv6 addr:	die("don't support ipv6 yet\n")
+	;;
+}
+
+const dnsconnectv4 = {addr
 	var sa : sockaddr_in
 	var s
 	var status
@@ -451,5 +499,4 @@
 	;;
 
 	-> true
-
 }
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -975,7 +975,7 @@
         case Oucon:     inferucon(st, n, &n->expr.isconst);     break;
         case Ovar:
             s = getdcl(curstab(), args[0]);
-            if (s) {
+            if (s && !s->decl.ishidden) {
                 if (s->decl.isgeneric)
                     t = tyfreshen(st, s->decl.type);
                 else if (s->decl.isconst)