Add glob and some finer tuning of documentation

This commit is contained in:
Justine Tunney 2020-06-21 00:10:11 -07:00
parent 799e24a87b
commit d51409ccd9
77 changed files with 1321 additions and 736 deletions

View file

@ -170,138 +170,138 @@ kErrnoNames:
/ @assume linker invoked as LC_ALL=C ld ...
/ @see libc/sysv/systemfive.S
/ @see libc/sysv/consts/syscon.h
yoink E2BIG
yoink EACCES
yoink EADDRINUSE
yoink EADDRNOTAVAIL
yoink EADV
yoink EAFNOSUPPORT
yoink EAGAIN
yoink EALREADY
yoink EBADE
yoink EBADF
yoink EBADFD
yoink EBADMSG
yoink EBADR
yoink EBADRQC
yoink EBADSLT
yoink EBFONT
yoink EBUSY
yoink ECANCELED
yoink ECHILD
yoink ECHRNG
yoink ECOMM
yoink ECONNABORTED
yoink ECONNREFUSED
yoink ECONNRESET
yoink EDEADLK
yoink EDESTADDRREQ
yoink EDOM
yoink EDOTDOT
yoink EDQUOT
yoink EEXIST
yoink EFAULT
yoink EFBIG
yoink EHOSTDOWN
yoink EHOSTUNREACH
yoink EHWPOISON
yoink EIDRM
yoink EILSEQ
yoink EINPROGRESS
yoink EINTR
yoink EINVAL
yoink EIO
yoink EISCONN
yoink EISDIR
yoink EISNAM
yoink EKEYEXPIRED
yoink EKEYREJECTED
yoink EKEYREVOKED
yoink EL2HLT
yoink EL2NSYNC
yoink EL3HLT
yoink EL3RST
yoink ELIBACC
yoink ELIBBAD
yoink ELIBEXEC
yoink ELIBMAX
yoink ELIBSCN
yoink ELNRNG
yoink ELOOP
yoink EMEDIUMTYPE
yoink EMFILE
yoink EMLINK
yoink EMSGSIZE
yoink EMULTIHOP
yoink ENAMETOOLONG
yoink ENAVAIL
yoink ENETDOWN
yoink ENETRESET
yoink ENETUNREACH
yoink ENFILE
yoink ENOANO
yoink ENOBUFS
yoink ENOCSI
yoink ENODATA
yoink ENODEV
yoink ENOENT
yoink ENOEXEC
yoink ENOKEY
yoink ENOLCK
yoink ENOLINK
yoink ENOMEDIUM
yoink ENOMEM
yoink ENOMSG
yoink ENONET
yoink ENOPKG
yoink ENOPROTOOPT
yoink ENOSPC
yoink ENOSR
yoink ENOSTR
yoink ENOSYS
yoink ENOTBLK
yoink ENOTCONN
yoink ENOTDIR
yoink ENOTEMPTY
yoink ENOTNAM
yoink ENOTRECOVERABLE
yoink ENOTSOCK
yoink ENOTSUP
yoink ENOTTY
yoink ENOTUNIQ
yoink ENXIO
yoink EOPNOTSUPP
yoink EOVERFLOW
yoink EOWNERDEAD
yoink EPERM
yoink EPFNOSUPPORT
yoink EPIPE
yoink EPROTO
yoink EPROTONOSUPPORT
yoink EPROTOTYPE
yoink ERANGE
yoink EREMCHG
yoink EREMOTE
yoink EREMOTEIO
yoink ERESTART
yoink ERFKILL
yoink EROFS
yoink ESHUTDOWN
yoink ESOCKTNOSUPPORT
yoink ESPIPE
yoink ESRCH
yoink ESRMNT
yoink ESTALE
yoink ESTRPIPE
yoink ETIME
yoink ETIMEDOUT
yoink ETOOMANYREFS
yoink ETXTBSY
yoink EUCLEAN
yoink EUNATCH
yoink EUSERS
yoink EXDEV
yoink EXFULL
.yoink E2BIG
.yoink EACCES
.yoink EADDRINUSE
.yoink EADDRNOTAVAIL
.yoink EADV
.yoink EAFNOSUPPORT
.yoink EAGAIN
.yoink EALREADY
.yoink EBADE
.yoink EBADF
.yoink EBADFD
.yoink EBADMSG
.yoink EBADR
.yoink EBADRQC
.yoink EBADSLT
.yoink EBFONT
.yoink EBUSY
.yoink ECANCELED
.yoink ECHILD
.yoink ECHRNG
.yoink ECOMM
.yoink ECONNABORTED
.yoink ECONNREFUSED
.yoink ECONNRESET
.yoink EDEADLK
.yoink EDESTADDRREQ
.yoink EDOM
.yoink EDOTDOT
.yoink EDQUOT
.yoink EEXIST
.yoink EFAULT
.yoink EFBIG
.yoink EHOSTDOWN
.yoink EHOSTUNREACH
.yoink EHWPOISON
.yoink EIDRM
.yoink EILSEQ
.yoink EINPROGRESS
.yoink EINTR
.yoink EINVAL
.yoink EIO
.yoink EISCONN
.yoink EISDIR
.yoink EISNAM
.yoink EKEYEXPIRED
.yoink EKEYREJECTED
.yoink EKEYREVOKED
.yoink EL2HLT
.yoink EL2NSYNC
.yoink EL3HLT
.yoink EL3RST
.yoink ELIBACC
.yoink ELIBBAD
.yoink ELIBEXEC
.yoink ELIBMAX
.yoink ELIBSCN
.yoink ELNRNG
.yoink ELOOP
.yoink EMEDIUMTYPE
.yoink EMFILE
.yoink EMLINK
.yoink EMSGSIZE
.yoink EMULTIHOP
.yoink ENAMETOOLONG
.yoink ENAVAIL
.yoink ENETDOWN
.yoink ENETRESET
.yoink ENETUNREACH
.yoink ENFILE
.yoink ENOANO
.yoink ENOBUFS
.yoink ENOCSI
.yoink ENODATA
.yoink ENODEV
.yoink ENOENT
.yoink ENOEXEC
.yoink ENOKEY
.yoink ENOLCK
.yoink ENOLINK
.yoink ENOMEDIUM
.yoink ENOMEM
.yoink ENOMSG
.yoink ENONET
.yoink ENOPKG
.yoink ENOPROTOOPT
.yoink ENOSPC
.yoink ENOSR
.yoink ENOSTR
.yoink ENOSYS
.yoink ENOTBLK
.yoink ENOTCONN
.yoink ENOTDIR
.yoink ENOTEMPTY
.yoink ENOTNAM
.yoink ENOTRECOVERABLE
.yoink ENOTSOCK
.yoink ENOTSUP
.yoink ENOTTY
.yoink ENOTUNIQ
.yoink ENXIO
.yoink EOPNOTSUPP
.yoink EOVERFLOW
.yoink EOWNERDEAD
.yoink EPERM
.yoink EPFNOSUPPORT
.yoink EPIPE
.yoink EPROTO
.yoink EPROTONOSUPPORT
.yoink EPROTOTYPE
.yoink ERANGE
.yoink EREMCHG
.yoink EREMOTE
.yoink EREMOTEIO
.yoink ERESTART
.yoink ERFKILL
.yoink EROFS
.yoink ESHUTDOWN
.yoink ESOCKTNOSUPPORT
.yoink ESPIPE
.yoink ESRCH
.yoink ESRMNT
.yoink ESTALE
.yoink ESTRPIPE
.yoink ETIME
.yoink ETIMEDOUT
.yoink ETOOMANYREFS
.yoink ETXTBSY
.yoink EUCLEAN
.yoink EUNATCH
.yoink EUSERS
.yoink EXDEV
.yoink EXFULL
.type kErrnoStart,@object
.type kErrnoEnd,@object

View file

@ -37,6 +37,12 @@
static const int kPow10[] = {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000};
/**
* Formats floating point number.
*
* @see xdtoa() for higher precision at the cost of bloat
* @see palandprintf() which is intended caller
*/
int ftoa(int out(int, void *), void *arg, long double value, unsigned long prec,
unsigned long width, unsigned long flags) {
long whole, frac;

View file

@ -56,7 +56,52 @@ static unsigned ppatoi(const char **str) {
/**
* Implements {,v}{,s{,n},{,{,x}as},f,d}printf state machine.
* @see libc/stdio/printf.c for documentation
*
* Type Specifiers
*
* - `%s` char * (thompson-pike unicode)
* - `%ls` wchar_t * (32-bit unicode thompson-pike unicode)
* - `%hs` char16_t * (16-bit unicode thompson-pike unicode)
* - `%b` int (radix 2 binary)
* - `%o` int (radix 8 octal)
* - `%d` int (radix 10 decimal)
* - `%x` int (radix 16 hexadecimal)
* - `%X` int (radix 16 hexadecimal uppercase)
* - `%u` unsigned
* - `%f` double
* - `%Lf` long double
* - `%p` pointer (48-bit hexadecimal)
*
* Length Modifiers
*
* - `%hhd` char (8-bit)
* - `%hd` short (16-bit)
* - `%ld` long (64-bit)
* - `%lu` unsigned long (64-bit)
* - `%lx` unsigned long (64-bit hexadecimal)
* - `%jd` intmax_t (128-bit)
*
* Width Modifiers
*
* - `%08d` fixed columns w/ zero leftpadding
* - `%8d` fixed columns w/ space leftpadding
* - `%*s` variable column string (thompson-pike)
* - `%.*s` variable column data (ignore nul terminator)
*
* Formatting Modifiers
*
* - `%,d` thousands separators
* - `%'s` escaped c string literal
* - `%'c` escaped c character literal
* - `%`s` escaped double quoted c string literal
* - `%`c` escaped double quoted c character literal
* - `%+d` plus leftpad if positive (aligns w/ negatives)
* - `% d` space leftpad if positive (aligns w/ negatives)
* - `%#s` datum (radix 256 null-terminated ibm cp437)
* - `%#x` int (radix 16 hexadecimal w/ 0x prefix if not zero)
*
* @note implementation detail of printf(), snprintf(), etc.
* @see printf() for wordier documentation
*/
hidden int palandprintf(void *fn, void *arg, const char *format, va_list va) {
int (*out)(int, void *);

View file

@ -50,8 +50,18 @@
#endif
#if defined(__GNUC__) && __GNUC__ < 6
/*
* Compilers don't understand the features we've added to the format
* string DSL, such as c string escaping, therefore we can't use it.
* Ideally compilers should grant us more flexibility to define DSLs
*
* The recommended approach to turning this back on is `CFLAGS=-std=c11`
* which puts the compiler in __STRICT_ANSI__ mode, which Cosmopolitan
* respects by disabling all the esoteric tuning in headers like this.
*/
#pragma GCC diagnostic ignored "-Wformat-security"
#endif /* __GNUC__ + 0 < 6 */
#else
#define PFLINK(FMT) FMT
#define SFLINK(FMT) FMT

View file

@ -25,7 +25,7 @@
* @return number of bytes written, excluding the NUL terminator; or,
* if the output buffer wasn't passed, or was too short, then the
* number of characters that *would* have been written is returned
* @see libc/fmt/fmt.h for documentation
* @see palandprintf() and printf() for detailed documentation
*/
int(snprintf)(char* buf, size_t count, const char* fmt, ...) {
int rc;

View file

@ -20,6 +20,12 @@
#include "libc/fmt/fmt.h"
#include "libc/limits.h"
/**
* Formats string to buffer that's hopefully large enough.
*
* @see palandprintf() and printf() for detailed documentation
* @see snprintf() for same w/ buf size param
*/
int(sprintf)(char *buf, const char *fmt, ...) {
int rc;
va_list va;

View file

@ -74,6 +74,8 @@ forceinline int emitquote(int out(int, void *), void *arg, unsigned flags,
* This function is used by palandprintf() to implement the %s and %c
* directives. The content outputted to the array is always UTF-8, but
* the input may be UTF-16 or UTF-32.
*
* @see palandprintf()
*/
int stoa(int out(int, void *), void *arg, void *data, unsigned long flags,
unsigned long precision, unsigned long width, unsigned char signbit,

View file

@ -34,6 +34,9 @@
* 8-bit through 128-bit integers (with validation), floating point
* numbers, etc. It can also be used to convert UTF-8 to UTF-16/32.
*
* - `%d` parses integer
* - `%ms` parses string allocating buffer assigning pointer
*
* @param callback supplies UTF-8 characters using -1 sentinel
* @param fmt is a computer program embedded inside a c string, written
* in a domain-specific programming language that, by design, lacks

View file

@ -40,7 +40,7 @@ static int vsnprintfputchar(unsigned char c, struct SprintfStr *str) {
}
/**
* Formats string to buffer.
* Formats string to buffer w/ preexisting vararg state.
*
* @param buf stores output and a NUL-terminator is always written,
* provided buf!=NULL && size!=0
@ -50,7 +50,7 @@ static int vsnprintfputchar(unsigned char c, struct SprintfStr *str) {
* number of characters that *would* have been written is returned
* @throw EOVERFLOW when a formatted field exceeds its limit, which can
* be checked by setting errno to 0 before calling
* @see libc/fmt/fmt.h for further documentation
* @see palandprintf() and printf() for detailed documentation
*/
int(vsnprintf)(char *buf, size_t size, const char *fmt, va_list va) {
struct SprintfStr str = {buf, 0, size};

View file

@ -20,6 +20,12 @@
#include "libc/fmt/fmt.h"
#include "libc/limits.h"
/**
* Formats string to buffer hopefully large enough w/ vararg state.
*
* @see palandprintf() and printf() for detailed documentation
* @see vsnprintf() for modern alternative w/ buf size param
*/
int(vsprintf)(char *buf, const char *fmt, va_list va) {
return (vsnprintf)(buf, INT_MAX, fmt, va);
}

View file

@ -21,7 +21,7 @@
#include "libc/fmt/vsscanf.h"
/**
* String decoder.
* Decodes string.
*
* @see libc/fmt/vcscanf.h (for docs and implementation)
* @note to offer the best performance, we assume small codebases