// Copyright 2020 The Libc Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package libc // import "modernc.org/libc"import ()// The format string consists of a sequence of directives which describe how to// process the sequence of input characters. If processing of a directive// fails, no further input is read, and scanf() returns. A "failure" can// be either of the following: input failure, meaning that input characters// were unavailable, or matching failure, meaning that the input was// inappropriate.func ( *strings.Reader, , uintptr) ( int32) {var []byte//TODO-varbool:for { := *(*byte)(unsafe.Pointer()) = append(, ) //TODO-switch {case'%':varintvarbool , , = scanfConversion(, , &)if ! {break } += int32() = truecase0:breakcase' ', '\t', '\n', '\r', '\v', '\f': = skipWhiteSpace() = true :for { , := .ReadByte()if != nil {break }switch {case' ', '\t', '\n', '\r', '\v', '\f':// nopdefault: .UnreadByte()break } }default: , := .ReadByte()if != nil {break }if != { .UnreadByte()break } ++ = true } }if {return }return -1// stdio.EOF but not defined for windows}func ( *strings.Reader, uintptr, *uintptr) ( uintptr, int, bool) { ++ // '%'// Each conversion specification in format begins with either the character '%' // or the character sequence "%n$" (see below for the distinction) followed by: := 0 := -1:for {switch := *(*byte)(unsafe.Pointer()); {case'*':// An optional '*' assignment-suppression character: scanf() reads input as // directed by the conversion specification, but discards the input. No // corresponding pointer argument is re‐ quired, and this specification is not // included in the count of successful assignments returned by scanf(). ++panic(todo(""))case'\'':// For decimal conversions, an optional quote character ('). This specifies // that the input number may include thousands' separators as defined by the // LC_NUMERIC category of the current locale. (See setlocale(3).) The quote // character may precede or follow the '*' assignment-suppression character. ++panic(todo(""))case'0', '1', '2', '3', '4', '5', '6', '7', '8', '9':// An optional decimal integer which specifies the maximum field width. // Reading of characters stops either when this maximum is reached or when a // nonmatching character is found, whichever happens first. Most conversions // discard initial white space characters (the exceptions are noted below), and // these discarded characters don't count toward the maximum field width. // String input conversions store a terminating null byte ('\0') to mark the // end of the input; the maximum field width does not include this terminator. = 0 :for {varintswitch := *(*byte)(unsafe.Pointer()); {default:breakcase >= '0' && <= '9': ++ = int() - '0' } := = 10* + if < {panic(todo("")) } }case'h', 'j', 'l', 'L', 'q', 't', 'z': , = parseLengthModifier()default:break } }// A conversion specifier that specifies the type of input conversion to be // performed.switch := *(*byte)(unsafe.Pointer()); {case'%':// Matches a literal '%'. That is, %% in the format string matches a single // input '%' character. No conversion is done (but initial white space // characters are discarded), and assign‐ ment does not occur. ++panic(todo(""))case'd':// Matches an optionally signed decimal integer; the next pointer must be a // pointer to int. ++skipReaderWhiteSpace()var , uint64 := true := false :for ; != 0; -- { , := .ReadByte()if != nil {if {break }panic(todo("", )) }if {switch {case'-': = false = truecontinuecase'+': = falsecontinue } }switch {case >= '0' && <= '9': = uint64() - '0'default: .UnreadByte()break } = true := = *10 + if < {panic(todo("")) } }if ! {break } := VaUintptr() := int64()if { = - }switch {casemodNone: *(*int32)(unsafe.Pointer()) = int32()casemodH: *(*int16)(unsafe.Pointer()) = int16()casemodHH: *(*int8)(unsafe.Pointer()) = int8()casemodL: *(*long)(unsafe.Pointer()) = long()default:panic(todo("")) } = 1case'D':// Equivalent to ld; this exists only for backward compatibility. (Note: // thus only in libc4. In libc5 and glibc the %D is silently ignored, causing // old programs to fail mysteriously.) ++panic(todo(""))case'i':// Matches an optionally signed integer; the next pointer must be a pointer to // int. The integer is read in base 16 if it begins with 0x or 0X, in base 8 // if it begins with 0, and in base 10 otherwise. Only characters that // correspond to the base are used. ++panic(todo(""))case'o':// Matches an unsigned octal integer; the next pointer must be a pointer to // unsigned int. ++panic(todo(""))case'u':// Matches an unsigned decimal integer; the next pointer must be a pointer to // unsigned int. ++panic(todo(""))case'x', 'X':// Matches an unsigned hexadecimal integer; the next pointer must be a pointer // to unsigned int. ++skipReaderWhiteSpace()var , uint64 := truevar []byte :for ; != 0; -- { , := .ReadByte()if != nil {if {break }panic(todo("", )) }if {iflen() == 1 && [0] == '0' && ( == 'x' || == 'X') { = false = false = nilcontinue } = append(, ) }switch {case >= '0' && <= '9': = uint64() - '0'case >= 'a' && <= 'f': = uint64() - 'a' + 10case >= 'A' && <= 'F': = uint64() - 'A' + 10default: .UnreadByte()break } = true := = <<4 + if < {panic(todo("")) } }if ! {break } := VaUintptr()switch {casemodNone: *(*uint32)(unsafe.Pointer()) = uint32()casemodH: *(*uint16)(unsafe.Pointer()) = uint16()casemodHH: *(*byte)(unsafe.Pointer()) = byte()casemodL: *(*ulong)(unsafe.Pointer()) = ulong()default:panic(todo("")) } = 1case'f', 'e', 'g', 'E', 'a':// Matches an optionally signed floating-point number; the next pointer must be // a pointer to float. ++panic(todo(""))case's':// Matches a sequence of non-white-space characters; the next pointer must be // a pointer to the initial element of a character array that is long enough to // hold the input sequence and the terminating null byte ('\0'), which is added // automatically. The input string stops at white space or at the maximum // field width, whichever occurs first. ++panic(todo(""))case'c':// Matches a sequence of characters whose length is specified by the maximum // field width (default 1); the next pointer must be a pointer to char, and // there must be enough room for all the characters (no terminating null byte // is added). The usual skip of leading white space is suppressed. To skip // white space first, use an explicit space in the format. ++panic(todo(""))case'[':// Matches a nonempty sequence of characters from the specified set of // accepted characters; the next pointer must be a pointer to char, and there // must be enough room for all the char‐ acters in the string, plus a // terminating null byte. The usual skip of leading white space is suppressed. // The string is to be made up of characters in (or not in) a particular set; // the set is defined by the characters between the open bracket [ character // and a close bracket ] character. The set excludes those characters if the // first character after the open bracket is a circumflex (^). To include a // close bracket in the set, make it the first character after the open bracket // or the circumflex; any other position will end the set. The hyphen // character - is also special; when placed between two other characters, it // adds all intervening characters to the set. To include a hyphen, make it // the last character before the final close bracket. For instance, [^]0-9-] // means the set "everything except close bracket, zero through nine, and // hyphen". The string ends with the appearance of a character not in the // (or, with a circumflex, in) set or when the field width runs out. ++panic(todo(""))case'p':// Matches a pointer value (as printed by %p in printf(3); the next pointer // must be a pointer to a pointer to void. ++skipReaderWhiteSpace() , := .ReadByte()if != nil {panic(todo("")) }if != '0' { .UnreadByte()panic(todo("")) }if , = .ReadByte(); != nil {panic(todo("")) }if != 'x' && != 'X' { .UnreadByte()panic(todo("")) }var , uint64 :for ; != 0; -- { , := .ReadByte()if != nil {if {break }panic(todo("")) }switch {case >= '0' && <= '9': = uint64() - '0'case >= 'a' && <= 'f': = uint64() - 'a' + 10case >= 'A' && <= 'F': = uint64() - 'A' + 10default: .UnreadByte()break } = true := = <<4 + if < {panic(todo("")) } }if ! {break } := VaUintptr() *(*uintptr)(unsafe.Pointer()) = uintptr() = 1case'n':// Nothing is expected; instead, the number of characters consumed thus far // from the input is stored through the next pointer, which must be a pointer // to int. This is not a conversion and does not increase the count returned // by the function. The assignment can be suppressed with the * // assignment-suppression character, but the effect on the return value is // undefined. Therefore %*n conversions should not be used. ++panic(todo(""))default:panic(todo("%#U", )) }return , , }func ( *strings.Reader) error {for { , := .ReadByte()if != nil {return }switch {case' ', '\t', '\n', '\r', '\v', '\f':// okdefault: .UnreadByte()returnnil } }}func ( uintptr) uintptr {for {switch := *(*byte)(unsafe.Pointer()); {case' ', '\t', '\n', '\r', '\v', '\f': ++default:return } }}
The pages are generated with Goldsv0.3.6. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.