diff options
author | Nicholas <nbnoll@eml.cc> | 2021-11-11 08:10:09 -0800 |
---|---|---|
committer | Nicholas <nbnoll@eml.cc> | 2021-11-11 08:10:09 -0800 |
commit | 44b30ea0883af2827e618a45d472b47cf041a842 (patch) | |
tree | 1188e17590f8b8b664de4e880aa88433d325df76 /include | |
parent | b5de2d7bd1e08d27f7780434e601d6d3a0750583 (diff) |
feat: added libfmt
Diffstat (limited to 'include')
-rw-r--r-- | include/libfmt.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/include/libfmt.h b/include/libfmt.h new file mode 100644 index 0000000..17effc6 --- /dev/null +++ b/include/libfmt.h @@ -0,0 +1,62 @@ +#pragma once + +typedef struct fmt·State fmt·State; + +struct fmt·State +{ + struct{ + char *beg; + char *cur; + char *end; + } buffer; + int (*flush)(fmt·State *); + int n; + va_list args; + rune verb; + ulong flag; + int width; + int prec; +}; + +#define iota(x) (1 << (x)) +enum +{ + fmt·Width = iota(0), + fmt·Left = iota(1), + fmt·Prec = iota(2), + fmt·Sharp = iota(3), + fmt·Space = iota(4), + fmt·Sign = iota(5), + fmt·Apost = iota(6), + fmt·Zero = iota(7), + fmt·Unsigned = iota(8), + fmt·Short = iota(9), + fmt·Long = iota(10), + fmt·Vlong = iota(11), + fmt·Comma = iota(12), + fmt·Byte = iota(13), + fmt·Ldouble = iota(14), + fmt·Flag = iota(15), +}; +#undef iota + +/* normal printing interface */ +int fmt·print(char *fmt, ...); +int fmt·fprint(int fd, char *fmt, ...); + +int fmt·sprint(char *buf, char *fmt, ...); +int fmt·nsprint(int len, char *buf, char *fmt, ...); +int fmt·esprint(char *buf, char *end, char *fmt, ...); + +int fmt·vprint(char *fmt, va_list args); +int fmt·vfprint(int fd, char *fmt, va_list args); +int fmt·vwrite(char *buf, char *fmt, va_list args); +int fmt·vnwrite(int len, char *buf, char *fmt, va_list args); +int fmt·vewrite(char *buf, char *end, char *fmt, va_list args); + +/* low-level interface: custom printing verbs */ +int fmt·do(fmt·State *, char *fmt); +int fmt·put(fmt·State *, char *fmt, ...); +int fmt·vput(fmt·State *, char *fmt, va_list args); +int fmt·install(fmt·State *, int (*put)(fmt·State*)); +int fmt·flush(fmt·State *); |