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