diff options
Diffstat (limited to 'vendor/modernc.org/libc/printf.go')
-rw-r--r-- | vendor/modernc.org/libc/printf.go | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/vendor/modernc.org/libc/printf.go b/vendor/modernc.org/libc/printf.go index d6de15d5d..be9242a46 100644 --- a/vendor/modernc.org/libc/printf.go +++ b/vendor/modernc.org/libc/printf.go @@ -38,17 +38,17 @@ const ( // the output stream; and conversion specifications, each of which results in // fetching zero or more subsequent arguments. func printf(format, args uintptr) []byte { - format0 := format - args0 := args + // format0 := format + // args0 := args buf := bytes.NewBuffer(nil) for { switch c := *(*byte)(unsafe.Pointer(format)); c { case '%': format = printfConversion(buf, format, &args) case 0: - if dmesgs { - dmesg("%v: %q, %#x -> %q", origin(1), GoString(format0), args0, buf.Bytes()) - } + // if dmesgs { + // dmesg("%v: %q, %#x -> %q", origin(1), GoString(format0), args0, buf.Bytes()) + // } return buf.Bytes() default: format++ @@ -114,7 +114,7 @@ flags: break flags } } - format, width, hasWidth := parseFieldWidth(format) + format, width, hasWidth := parseFieldWidth(format, args) if hasWidth { spec += strconv.Itoa(width) } @@ -239,6 +239,38 @@ more: f := spec + "o" str = fmt.Sprintf(f, arg) + case 'b': + // Base 2. + format++ + var arg uint64 + if isWindows && mod == modL { + mod = modNone + } + switch mod { + case modNone: + arg = uint64(VaUint32(args)) + case modL, modLL, mod64: + arg = VaUint64(args) + case modH: + arg = uint64(uint16(VaInt32(args))) + case modHH: + arg = uint64(uint8(VaInt32(args))) + case mod32: + arg = uint64(VaInt32(args)) + default: + panic(todo("", mod)) + } + + if arg == 0 && hasPrecision && prec == 0 { + break + } + + if hasPrecision { + panic(todo("", prec)) + } + + f := spec + "b" + str = fmt.Sprintf(f, arg) case 'I': if !isWindows { panic(todo("%#U", c)) @@ -474,7 +506,7 @@ more: // nonexistent or small field width cause truncation of a field; if the result // of a conversion is wider than the field width, the field is expanded to // contain the conversion result. -func parseFieldWidth(format uintptr) (_ uintptr, n int, ok bool) { +func parseFieldWidth(format uintptr, args *uintptr) (_ uintptr, n int, ok bool) { first := true for { var digit int @@ -482,7 +514,13 @@ func parseFieldWidth(format uintptr) (_ uintptr, n int, ok bool) { case first && c == '0': return format, n, ok case first && c == '*': - panic(todo("")) + format++ + switch c := *(*byte)(unsafe.Pointer(format)); { + case c >= '0' && c <= '9': + panic(todo("")) + default: + return format, int(VaInt32(args)), true + } case c >= '0' && c <= '9': format++ ok = true |