fmtdef.h (4178B)
1 /* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ 2 3 /* 4 * dofmt -- format to a buffer 5 * the number of characters formatted is returned, 6 * or -1 if there was an error. 7 * if the buffer is ever filled, flush is called. 8 * it should reset the buffer and return whether formatting should continue. 9 */ 10 11 typedef int (*Fmts)(Fmt*); 12 13 typedef struct Quoteinfo Quoteinfo; 14 struct Quoteinfo { 15 int quoted; /* if set, string must be quoted */ 16 int nrunesin; /* number of input runes that can be accepted */ 17 int nbytesin; /* number of input bytes that can be accepted */ 18 int nrunesout; /* number of runes that will be generated */ 19 int nbytesout; /* number of bytes that will be generated */ 20 }; 21 22 /* Edit .+1,/^$/ |cfn |grep -v static | grep __ */ 23 double __Inf(int sign); 24 double __NaN(void); 25 int __badfmt(Fmt* f); 26 int __charfmt(Fmt* f); 27 int __countfmt(Fmt* f); 28 int __efgfmt(Fmt* fmt); 29 int __errfmt(Fmt* f); 30 int __flagfmt(Fmt* f); 31 int __fmtFdFlush(Fmt* f); 32 int __fmtcpy(Fmt* f, const void* vm, int n, int sz); 33 void* __fmtdispatch(Fmt* f, void* fmt, int isrunes); 34 void* __fmtflush(Fmt* f, void* t, int len); 35 int __fmtpad(Fmt* f, int n); 36 double __fmtpow10(int n); 37 int __fmtrcpy(Fmt* f, const void* vm, int n); 38 void __fmtlock(void); 39 void __fmtunlock(void); 40 int __ifmt(Fmt* f); 41 int __isInf(double d, int sign); 42 int __isNaN(double d); 43 int __needsep(int*, char**); 44 int __needsquotes(char* s, int* quotelenp); 45 int __percentfmt(Fmt* f); 46 void __quotesetup(char* s, Rune* r, int nin, int nout, Quoteinfo* q, int sharp, int runesout); 47 int __quotestrfmt(int runesin, Fmt* f); 48 int __rfmtpad(Fmt* f, int n); 49 int __runefmt(Fmt* f); 50 int __runeneedsquotes(Rune* r, int* quotelenp); 51 int __runesfmt(Fmt* f); 52 int __strfmt(Fmt* f); 53 54 #define FMTCHAR(f, t, s, c) \ 55 do { \ 56 if (t + 1 > (char*) s) { \ 57 t = (char*) __fmtflush(f, t, 1); \ 58 if (t != nil) \ 59 s = (char*) f->stop; \ 60 else \ 61 return -1; \ 62 } \ 63 *t++ = c; \ 64 } while (0) 65 66 #define FMTRCHAR(f, t, s, c) \ 67 do { \ 68 if (t + 1 > (Rune*) s) { \ 69 t = (Rune*) __fmtflush(f, t, sizeof(Rune)); \ 70 if (t != nil) \ 71 s = (Rune*) f->stop; \ 72 else \ 73 return -1; \ 74 } \ 75 *t++ = c; \ 76 } while (0) 77 78 #define FMTRUNE(f, t, s, r) \ 79 do { \ 80 Rune _rune; \ 81 int _runelen; \ 82 if (t + UTFmax > (char*) s && t + (_runelen = runelen(r)) > (char*) s) { \ 83 t = (char*) __fmtflush(f, t, _runelen); \ 84 if (t != nil) \ 85 s = (char*) f->stop; \ 86 else \ 87 return -1; \ 88 } \ 89 if (r < Runeself) \ 90 *t++ = r; \ 91 else { \ 92 _rune = r; \ 93 t += runetochar(t, &_rune); \ 94 } \ 95 } while (0) 96 97 #ifdef va_copy 98 # define VA_COPY(a, b) va_copy(a, b) 99 # define VA_END(a) va_end(a) 100 #else 101 # define VA_COPY(a, b) (a) = (b) 102 # define VA_END(a) 103 #endif