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