github.com/tcnksm/go@v0.0.0-20141208075154-439b32936367/src/lib9/fmt/fmtdef.h (about) 1 /* 2 * The authors of this software are Rob Pike and Ken Thompson. 3 * 4 * Copyright (c) 2002-2006 by Lucent Technologies. 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose without fee is hereby granted, provided that this entire notice 8 * is included in all copies of any software which is or includes a copy 9 * or modification of this software and in all copies of the supporting 10 * documentation for such software. 11 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 12 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 13 * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 14 * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 15 */ 16 17 /* 18 * dofmt -- format to a buffer 19 * the number of characters formatted is returned, 20 * or -1 if there was an error. 21 * if the buffer is ever filled, flush is called. 22 * it should reset the buffer and return whether formatting should continue. 23 */ 24 25 typedef int (*Fmts)(Fmt*); 26 27 typedef struct Quoteinfo Quoteinfo; 28 struct Quoteinfo 29 { 30 int quoted; /* if set, string must be quoted */ 31 int nrunesin; /* number of input runes that can be accepted */ 32 int nbytesin; /* number of input bytes that can be accepted */ 33 int nrunesout; /* number of runes that will be generated */ 34 int nbytesout; /* number of bytes that will be generated */ 35 }; 36 37 /* Edit .+1,/^$/ |cfn |grep -v static | grep __ */ 38 double __Inf(int sign); 39 double __NaN(void); 40 int __badfmt(Fmt *f); 41 int __charfmt(Fmt *f); 42 int __countfmt(Fmt *f); 43 int __efgfmt(Fmt *fmt); 44 int __errfmt(Fmt *f); 45 int __flagfmt(Fmt *f); 46 int __fmtFdFlush(Fmt *f); 47 int __fmtcpy(Fmt *f, const void *vm, int n, int sz); 48 void* __fmtdispatch(Fmt *f, void *fmt, int isrunes); 49 void * __fmtflush(Fmt *f, void *t, int len); 50 void __fmtlock(void); 51 int __fmtpad(Fmt *f, int n); 52 double __fmtpow10(int n); 53 int __fmtrcpy(Fmt *f, const void *vm, int n); 54 void __fmtunlock(void); 55 int __ifmt(Fmt *f); 56 int __isInf(double d, int sign); 57 int __isNaN(double d); 58 int __needsep(int*, char**); 59 int __needsquotes(char *s, int *quotelenp); 60 int __percentfmt(Fmt *f); 61 void __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int runesout); 62 int __quotestrfmt(int runesin, Fmt *f); 63 int __rfmtpad(Fmt *f, int n); 64 int __runefmt(Fmt *f); 65 int __runeneedsquotes(Rune *r, int *quotelenp); 66 int __runesfmt(Fmt *f); 67 int __strfmt(Fmt *f); 68 69 #define FMTCHAR(f, t, s, c)\ 70 do{\ 71 if(t + 1 > (char*)s){\ 72 t = (char*)__fmtflush(f, t, 1);\ 73 if(t != nil)\ 74 s = (char*)f->stop;\ 75 else\ 76 return -1;\ 77 }\ 78 *t++ = (char)c;\ 79 }while(0) 80 81 #define FMTRCHAR(f, t, s, c)\ 82 do{\ 83 if(t + 1 > (Rune*)s){\ 84 t = (Rune*)__fmtflush(f, t, sizeof(Rune));\ 85 if(t != nil)\ 86 s = (Rune*)f->stop;\ 87 else\ 88 return -1;\ 89 }\ 90 *t++ = (Rune)c;\ 91 }while(0) 92 93 #define FMTRUNE(f, t, s, r)\ 94 do{\ 95 Rune _rune;\ 96 int _runelen;\ 97 if(t + UTFmax > (char*)s && t + (_runelen = runelen(r)) > (char*)s){\ 98 t = (char*)__fmtflush(f, t, _runelen);\ 99 if(t != nil)\ 100 s = (char*)f->stop;\ 101 else\ 102 return -1;\ 103 }\ 104 if(r < Runeself)\ 105 *t++ = (char)r;\ 106 else{\ 107 _rune = r;\ 108 t += runetochar(t, &_rune);\ 109 }\ 110 }while(0) 111 112 #ifdef va_copy 113 # define VA_COPY(a,b) va_copy(a,b) 114 # define VA_END(a) va_end(a) 115 #else 116 # define VA_COPY(a,b) (a) = (b) 117 # define VA_END(a) 118 #endif 119