Blob


1 #ifndef _FMT_H_
2 #define _FMT_H_ 1
3 #if defined(__cplusplus)
4 extern "C" {
5 #endif
7 /*
8 * The authors of this software are Rob Pike and Ken Thompson.
9 * Copyright (c) 2002 by Lucent Technologies.
10 * Permission to use, copy, modify, and distribute this software for any
11 * purpose without fee is hereby granted, provided that this entire notice
12 * is included in all copies of any software which is or includes a copy
13 * or modification of this software and in all copies of the supporting
14 * documentation for such software.
15 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
16 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
17 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
18 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
19 */
21 #include <stdarg.h>
22 #include <utf.h>
24 typedef struct Fmt Fmt;
25 struct Fmt{
26 unsigned char runes; /* output buffer is runes or chars? */
27 void *start; /* of buffer */
28 void *to; /* current place in the buffer */
29 void *stop; /* end of the buffer; overwritten if flush fails */
30 int (*flush)(Fmt *); /* called when to == stop */
31 void *farg; /* to make flush a closure */
32 int nfmt; /* num chars formatted so far */
33 va_list args; /* args passed to dofmt */
34 int r; /* % format Rune */
35 int width;
36 int prec;
37 unsigned long flags;
38 };
40 enum{
41 FmtWidth = 1,
42 FmtLeft = FmtWidth << 1,
43 FmtPrec = FmtLeft << 1,
44 FmtSharp = FmtPrec << 1,
45 FmtSpace = FmtSharp << 1,
46 FmtSign = FmtSpace << 1,
47 FmtZero = FmtSign << 1,
48 FmtUnsigned = FmtZero << 1,
49 FmtShort = FmtUnsigned << 1,
50 FmtLong = FmtShort << 1,
51 FmtVLong = FmtLong << 1,
52 FmtComma = FmtVLong << 1,
53 FmtByte = FmtComma << 1,
54 FmtLDouble = FmtByte << 1,
56 FmtFlag = FmtLDouble << 1
57 };
59 extern int print(char*, ...);
60 extern char* seprint(char*, char*, char*, ...);
61 extern char* vseprint(char*, char*, char*, va_list);
62 extern int snprint(char*, int, char*, ...);
63 extern int vsnprint(char*, int, char*, va_list);
64 extern char* smprint(char*, ...);
65 extern char* vsmprint(char*, va_list);
66 extern int sprint(char*, char*, ...);
67 extern int fprint(int, char*, ...);
68 extern int vfprint(int, char*, va_list);
70 extern int runesprint(Rune*, char*, ...);
71 extern int runesnprint(Rune*, int, char*, ...);
72 extern int runevsnprint(Rune*, int, char*, va_list);
73 extern Rune* runeseprint(Rune*, Rune*, char*, ...);
74 extern Rune* runevseprint(Rune*, Rune*, char*, va_list);
75 extern Rune* runesmprint(char*, ...);
76 extern Rune* runevsmprint(char*, va_list);
78 extern int fmtfdinit(Fmt*, int, char*, int);
79 extern int fmtfdflush(Fmt*);
80 extern int fmtstrinit(Fmt*);
81 extern char* fmtstrflush(Fmt*);
82 extern int runefmtstrinit(Fmt*);
83 extern Rune* runefmtstrflush(Fmt*);
85 extern int quotestrfmt(Fmt *f);
86 extern void quotefmtinstall(void);
87 extern int (*fmtdoquote)(int);
90 extern int fmtinstall(int, int (*)(Fmt*));
91 extern int dofmt(Fmt*, char*);
92 extern int fmtprint(Fmt*, char*, ...);
93 extern int fmtvprint(Fmt*, char*, va_list);
94 extern int fmtrune(Fmt*, int);
95 extern int fmtstrcpy(Fmt*, char*);
97 extern double fmtstrtod(const char *, char **);
98 extern double fmtcharstod(int(*)(void*), void*);
100 #if defined(__cplusplus)
102 #endif
103 #endif