blob: 2280f25250b7adfdfadf7aa0b1ad329ee6bc69d2 [file] [log] [blame]
Rob Pike69b74c32008-06-12 13:26:16 -07001#ifndef _FMT_H_
2#define _FMT_H_ 1
3#if defined(__cplusplus)
Russ Cox04a77ac2009-08-31 16:38:50 -07004extern "C" {
Rob Pike69b74c32008-06-12 13:26:16 -07005#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 */
19
20#include <stdarg.h>
21#include <utf.h>
22
23typedef struct Fmt Fmt;
24struct 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 */
Russ Cox04a77ac2009-08-31 16:38:50 -070033 Rune r; /* % format Rune */
Rob Pike69b74c32008-06-12 13:26:16 -070034 int width;
35 int prec;
36 unsigned long flags;
37 char *decimal; /* decimal point; cannot be "" */
38
39 /* For %'d */
40 char *thousands; /* separator for thousands */
Russ Cox04a77ac2009-08-31 16:38:50 -070041
42 /*
Rob Pike69b74c32008-06-12 13:26:16 -070043 * Each char is an integer indicating #digits before next separator. Values:
44 * \xFF: no more grouping (or \x7F; defined to be CHAR_MAX in POSIX)
45 * \x00: repeat previous indefinitely
46 * \x**: count that many
47 */
48 char *grouping; /* descriptor of separator placement */
49};
50
51enum{
52 FmtWidth = 1,
53 FmtLeft = FmtWidth << 1,
54 FmtPrec = FmtLeft << 1,
55 FmtSharp = FmtPrec << 1,
56 FmtSpace = FmtSharp << 1,
57 FmtSign = FmtSpace << 1,
58 FmtApost = FmtSign << 1,
59 FmtZero = FmtApost << 1,
60 FmtUnsigned = FmtZero << 1,
61 FmtShort = FmtUnsigned << 1,
62 FmtLong = FmtShort << 1,
63 FmtVLong = FmtLong << 1,
64 FmtComma = FmtVLong << 1,
65 FmtByte = FmtComma << 1,
66 FmtLDouble = FmtByte << 1,
67
68 FmtFlag = FmtLDouble << 1
69};
70
71extern int (*fmtdoquote)(int);
72
73/* Edit .+1,/^$/ | cfn $PLAN9/src/lib9/fmt/?*.c | grep -v static |grep -v __ */
74int dofmt(Fmt *f, char *fmt);
75int dorfmt(Fmt *f, const Rune *fmt);
76double fmtcharstod(int(*f)(void*), void *vp);
77int fmtfdflush(Fmt *f);
78int fmtfdinit(Fmt *f, int fd, char *buf, int size);
79int fmtinstall(int c, int (*f)(Fmt*));
80int fmtnullinit(Fmt*);
81void fmtlocaleinit(Fmt*, char*, char*, char*);
82int fmtprint(Fmt *f, char *fmt, ...);
83int fmtrune(Fmt *f, int r);
84int fmtrunestrcpy(Fmt *f, Rune *s);
85int fmtstrcpy(Fmt *f, char *s);
86char* fmtstrflush(Fmt *f);
87int fmtstrinit(Fmt *f);
88double fmtstrtod(const char *as, char **aas);
89int fmtvprint(Fmt *f, char *fmt, va_list args);
90int fprint(int fd, char *fmt, ...);
91int print(char *fmt, ...);
92void quotefmtinstall(void);
93int quoterunestrfmt(Fmt *f);
94int quotestrfmt(Fmt *f);
95Rune* runefmtstrflush(Fmt *f);
96int runefmtstrinit(Fmt *f);
97Rune* runeseprint(Rune *buf, Rune *e, char *fmt, ...);
98Rune* runesmprint(char *fmt, ...);
99int runesnprint(Rune *buf, int len, char *fmt, ...);
100int runesprint(Rune *buf, char *fmt, ...);
101Rune* runevseprint(Rune *buf, Rune *e, char *fmt, va_list args);
102Rune* runevsmprint(char *fmt, va_list args);
103int runevsnprint(Rune *buf, int len, char *fmt, va_list args);
104char* seprint(char *buf, char *e, char *fmt, ...);
105char* smprint(char *fmt, ...);
106int snprint(char *buf, int len, char *fmt, ...);
107int sprint(char *buf, char *fmt, ...);
108int vfprint(int fd, char *fmt, va_list args);
109char* vseprint(char *buf, char *e, char *fmt, va_list args);
110char* vsmprint(char *fmt, va_list args);
111int vsnprint(char *buf, int len, char *fmt, va_list args);
112
113#if defined(__cplusplus)
114}
115#endif
116#endif