Blame


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