Blob


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