2 * The authors of this software are Rob Pike and Ken Thompson.
3 * Copyright (c) 2002 by Lucent Technologies.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose without fee is hereby granted, provided that this entire notice
6 * is included in all copies of any software which is or includes a copy
7 * or modification of this software and in all copies of the supporting
8 * documentation for such software.
9 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
10 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
11 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
12 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
15 * dofmt -- format to a buffer
16 * the number of characters formatted is returned,
17 * or -1 if there was an error.
18 * if the buffer is ever filled, flush is called.
19 * it should reset the buffer and return whether formatting should continue.
21 #define uchar _fmtuchar
22 #define ushort _fmtushort
24 #define ulong _fmtulong
25 #define vlong _fmtvlong
26 #define uvlong _fmtuvlong
28 #define USED(x) if(x);else
30 typedef unsigned char uchar;
31 typedef unsigned short ushort;
32 typedef unsigned int uint;
33 typedef unsigned long ulong;
36 typedef unsigned long long uvlong;
37 typedef long long vlong;
40 #define nil 0 /* cannot be ((void*)0) because used for function pointers */
42 typedef int (*Fmts)(Fmt*);
44 typedef struct Quoteinfo Quoteinfo;
47 int quoted; /* if set, string must be quoted */
48 int nrunesin; /* number of input runes that can be accepted */
49 int nbytesin; /* number of input bytes that can be accepted */
50 int nrunesout; /* number of runes that will be generated */
51 int nbytesout; /* number of bytes that will be generated */
54 void *__fmtflush(Fmt*, void*, int);
55 void *__fmtdispatch(Fmt*, void*, int);
56 int __floatfmt(Fmt*, double);
57 int __fmtpad(Fmt*, int);
58 int __rfmtpad(Fmt*, int);
59 int __fmtFdFlush(Fmt*);
67 int __percentfmt(Fmt*);
71 int __fmtcpy(Fmt*, const void*, int, int);
72 int __fmtrcpy(Fmt*, const void*, int n);
75 double __fmtpow10(int);
78 void __fmtunlock(void);
80 #define FMTCHAR(f, t, s, c)\
82 if(t + 1 > (char*)s){\
83 t = __fmtflush(f, t, 1);\
92 #define FMTRCHAR(f, t, s, c)\
94 if(t + 1 > (Rune*)s){\
95 t = __fmtflush(f, t, sizeof(Rune));\
104 #define FMTRUNE(f, t, s, r)\
108 if(t + UTFmax > (char*)s && t + (_runelen = runelen(r)) > (char*)s){\
109 t = __fmtflush(f, t, _runelen);\
119 t += runetochar(t, &_rune);\