rsc | aa73861 | 2004-03-01 19:36:29 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * The authors of this software are Rob Pike and Ken Thompson. |
| 4 | * Copyright (c) 2002 by Lucent Technologies. |
| 5 | * Permission to use, copy, modify, and distribute this software for any |
| 6 | * purpose without fee is hereby granted, provided that this entire notice |
| 7 | * is included in all copies of any software which is or includes a copy |
| 8 | * or modification of this software and in all copies of the supporting |
| 9 | * documentation for such software. |
| 10 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED |
| 11 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY |
| 12 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY |
| 13 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. |
| 14 | */ |
| 15 | |
| 16 | #ifndef _FMTH_ |
| 17 | #define _FMTH_ 1 |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
| 22 | #include <stdarg.h> |
| 23 | |
| 24 | #ifndef _UTFH_ |
| 25 | #include <utf.h> |
| 26 | #endif |
| 27 | |
| 28 | typedef struct Fmt Fmt; |
| 29 | struct Fmt{ |
| 30 | unsigned char runes; /* output buffer is runes or chars? */ |
| 31 | void *start; /* of buffer */ |
| 32 | void *to; /* current place in the buffer */ |
| 33 | void *stop; /* end of the buffer; overwritten if flush fails */ |
| 34 | int (*flush)(Fmt *); /* called when to == stop */ |
| 35 | void *farg; /* to make flush a closure */ |
| 36 | int nfmt; /* num chars formatted so far */ |
| 37 | va_list args; /* args passed to dofmt */ |
| 38 | int r; /* % format Rune */ |
| 39 | int width; |
| 40 | int prec; |
| 41 | unsigned long flags; |
| 42 | }; |
| 43 | |
| 44 | enum{ |
| 45 | FmtWidth = 1, |
| 46 | FmtLeft = FmtWidth << 1, |
| 47 | FmtPrec = FmtLeft << 1, |
| 48 | FmtSharp = FmtPrec << 1, |
| 49 | FmtSpace = FmtSharp << 1, |
| 50 | FmtSign = FmtSpace << 1, |
| 51 | FmtZero = FmtSign << 1, |
| 52 | FmtUnsigned = FmtZero << 1, |
| 53 | FmtShort = FmtUnsigned << 1, |
| 54 | FmtLong = FmtShort << 1, |
| 55 | FmtVLong = FmtLong << 1, |
| 56 | FmtComma = FmtVLong << 1, |
| 57 | FmtByte = FmtComma << 1, |
| 58 | FmtLDouble = FmtByte << 1, |
| 59 | |
| 60 | FmtFlag = FmtLDouble << 1 |
| 61 | }; |
| 62 | |
| 63 | extern int print(char*, ...); |
| 64 | extern char* seprint(char*, char*, char*, ...); |
| 65 | extern char* vseprint(char*, char*, char*, va_list); |
| 66 | extern int snprint(char*, int, char*, ...); |
| 67 | extern int vsnprint(char*, int, char*, va_list); |
| 68 | extern char* smprint(char*, ...); |
| 69 | extern char* vsmprint(char*, va_list); |
| 70 | extern int sprint(char*, char*, ...); |
| 71 | extern int fprint(int, char*, ...); |
| 72 | extern int vfprint(int, char*, va_list); |
| 73 | |
| 74 | extern int runesprint(Rune*, char*, ...); |
| 75 | extern int runesnprint(Rune*, int, char*, ...); |
| 76 | extern int runevsnprint(Rune*, int, char*, va_list); |
| 77 | extern Rune* runeseprint(Rune*, Rune*, char*, ...); |
| 78 | extern Rune* runevseprint(Rune*, Rune*, char*, va_list); |
| 79 | extern Rune* runesmprint(char*, ...); |
| 80 | extern Rune* runevsmprint(char*, va_list); |
| 81 | |
| 82 | extern int fmtfdinit(Fmt*, int, char*, int); |
| 83 | extern int fmtfdflush(Fmt*); |
| 84 | extern int fmtstrinit(Fmt*); |
| 85 | extern char* fmtstrflush(Fmt*); |
| 86 | extern int runefmtstrinit(Fmt*); |
| 87 | |
| 88 | extern int quotestrfmt(Fmt *f); |
| 89 | extern void quotefmtinstall(void); |
| 90 | extern int (*fmtdoquote)(int); |
| 91 | |
| 92 | |
| 93 | extern int fmtinstall(int, int (*)(Fmt*)); |
| 94 | extern int dofmt(Fmt*, char*); |
| 95 | extern int fmtprint(Fmt*, char*, ...); |
| 96 | extern int fmtvprint(Fmt*, char*, va_list); |
| 97 | extern int fmtrune(Fmt*, int); |
| 98 | extern int fmtstrcpy(Fmt*, char*); |
| 99 | |
| 100 | extern double fmtstrtod(const char *, char **); |
| 101 | extern double fmtcharstod(int(*)(void*), void*); |
| 102 | |
| 103 | #ifdef __cplusplus |
| 104 | } |
| 105 | #endif |
| 106 | #endif |