unix/fiss

lib/libfmt/fmtdef.h in master
Repositories | Summary | Log | Files | LICENSE

fmtdef.h (4178B) download


  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
 11typedef int (*Fmts)(Fmt*);
 12
 13typedef struct Quoteinfo Quoteinfo;
 14struct 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 __ */
 23double __Inf(int sign);
 24double __NaN(void);
 25int    __badfmt(Fmt* f);
 26int    __charfmt(Fmt* f);
 27int    __countfmt(Fmt* f);
 28int    __efgfmt(Fmt* fmt);
 29int    __errfmt(Fmt* f);
 30int    __flagfmt(Fmt* f);
 31int    __fmtFdFlush(Fmt* f);
 32int    __fmtcpy(Fmt* f, const void* vm, int n, int sz);
 33void*  __fmtdispatch(Fmt* f, void* fmt, int isrunes);
 34void*  __fmtflush(Fmt* f, void* t, int len);
 35int    __fmtpad(Fmt* f, int n);
 36double __fmtpow10(int n);
 37int    __fmtrcpy(Fmt* f, const void* vm, int n);
 38void   __fmtlock(void);
 39void   __fmtunlock(void);
 40int    __ifmt(Fmt* f);
 41int    __isInf(double d, int sign);
 42int    __isNaN(double d);
 43int    __needsep(int*, char**);
 44int    __needsquotes(char* s, int* quotelenp);
 45int    __percentfmt(Fmt* f);
 46void   __quotesetup(char* s, Rune* r, int nin, int nout, Quoteinfo* q, int sharp, int runesout);
 47int    __quotestrfmt(int runesin, Fmt* f);
 48int    __rfmtpad(Fmt* f, int n);
 49int    __runefmt(Fmt* f);
 50int    __runeneedsquotes(Rune* r, int* quotelenp);
 51int    __runesfmt(Fmt* f);
 52int    __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