ref: 022ea933cb1ece0d00eeac4f01c8738fdd37ac91
parent: 5c11d9f0c97f8b466597c680e1178a61c676c489
author: Ori Bernstein <[email protected]>
date: Thu Jan 2 17:57:07 EST 2014
Parse resolv.conf in DNS implementation.
--- a/libstd/cmp.myr
+++ b/libstd/cmp.myr
@@ -26,14 +26,12 @@
const strcmp = {a, b
var l
var i
- var v
l = min(a.len, b.len)
for i = 0; i < l; i++
- v = a[i] - b[i]
- if v < 0
+ if a[i] < b[i]
-> `Before
- elif v > 0
+ elif a[i] > b[i]
-> `After
;;
;;
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -82,45 +82,6 @@
-> bfmtv(buf, fmt, vastart(&args))
}
-
-generic intfmt = {buf : byte[:], sval : @a::(tcnum,tctest,tcint), base, signed
- var isneg
- var val
- var b : char[32]
- var i
- var j
- var n
-
- n = 0
- i = 0
- if signed && sval < 0
- val = -sval castto(uint64)
- isneg = true
- else
- val = sval castto(uint64)
- val &= ((1 << 8*sizeof(@a)) - 1)
- isneg = false
- ;;
-
- if val == 0
- b[0] = '0'
- i++
- ;;
- while val != 0
- b[i] = digitchars[val % base]
- val /= base
- i++
- ;;
- n = 0
- if isneg
- n += encode(buf[n:], '-')
- ;;
- for j = i-1; j >= 0; j--
- n += encode(buf[n:], b[j])
- ;;
- -> n
-}
-
/* formats a string of text as specified by 'fmt' into 'buf',
using a valist for the arguments */
const bfmtv = {buf, fmt, ap
@@ -168,22 +129,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)
| _:
@@ -220,4 +181,41 @@
const digitchars = [
'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
]
+
+const intfmt = {buf, sval, base, signed
+ var isneg
+ var val
+ var b : char[32]
+ var i
+ var j
+ var n
+
+ n = 0
+ i = 0
+ if signed && sval < 0
+ val = -sval castto(uint64)
+ isneg = true
+ else
+ val = sval castto(uint64)
+ isneg = false
+ ;;
+
+ if val == 0
+ b[0] = '0'
+ i++
+ ;;
+ while val != 0
+ b[i] = digitchars[val % base]
+ val /= base
+ i++
+ ;;
+ n = 0
+ if isneg
+ n += encode(buf[n:], '-')
+ ;;
+ for j = i-1; j >= 0; j--
+ n += encode(buf[n:], b[j])
+ ;;
+ -> n
+}