blob: 1744ddc061ff1b1d0b3a5101136a28cdb622f55b [file] [log] [blame]
rscf7012582003-11-25 01:40:27 +00001#ifndef _FMT_H_
2#define _FMT_H_ 1
3#if defined(__cplusplus)
4extern "C" {
5#endif
rscb2cfc4e2003-09-30 17:47:41 +00006/*
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
rscb2cfc4e2003-09-30 17:47:41 +000020#include <stdarg.h>
rscb2cfc4e2003-09-30 17:47:41 +000021#include <utf.h>
rscb2cfc4e2003-09-30 17:47:41 +000022
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 */
33 int r; /* % format Rune */
34 int width;
35 int prec;
36 unsigned long flags;
37};
38
39enum{
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,
54
55 FmtFlag = FmtLDouble << 1
56};
57
rscb2cfc4e2003-09-30 17:47:41 +000058extern int (*fmtdoquote)(int);
59
rsc8bbb2f62004-12-25 22:00:00 +000060/* Edit .+1,/^$/ | cfn $PLAN9/src/lib9/fmt/?*.c | grep -v static |grep -v __ */
61int dofmt(Fmt *f, char *fmt);
62int dorfmt(Fmt *f, const Rune *fmt);
63double fmtcharstod(int(*f)(void*), void *vp);
64int fmtfdflush(Fmt *f);
65int fmtfdinit(Fmt *f, int fd, char *buf, int size);
66int fmtinstall(int c, int (*f)(Fmt*));
67int fmtprint(Fmt *f, char *fmt, ...);
68int fmtrune(Fmt *f, int r);
69int fmtrunestrcpy(Fmt *f, Rune *s);
70int fmtstrcpy(Fmt *f, char *s);
71char* fmtstrflush(Fmt *f);
72int fmtstrinit(Fmt *f);
73double fmtstrtod(const char *as, char **aas);
74int fmtvprint(Fmt *f, char *fmt, va_list args);
75int fprint(int fd, char *fmt, ...);
76int print(char *fmt, ...);
77void quotefmtinstall(void);
78int quoterunestrfmt(Fmt *f);
79int quotestrfmt(Fmt *f);
80Rune* runefmtstrflush(Fmt *f);
81int runefmtstrinit(Fmt *f);
82Rune* runeseprint(Rune *buf, Rune *e, char *fmt, ...);
83Rune* runesmprint(char *fmt, ...);
84int runesnprint(Rune *buf, int len, char *fmt, ...);
85int runesprint(Rune *buf, char *fmt, ...);
86Rune* runevseprint(Rune *buf, Rune *e, char *fmt, va_list args);
87Rune* runevsmprint(char *fmt, va_list args);
88int runevsnprint(Rune *buf, int len, char *fmt, va_list args);
89char* seprint(char *buf, char *e, char *fmt, ...);
90char* smprint(char *fmt, ...);
91int snprint(char *buf, int len, char *fmt, ...);
92int sprint(char *buf, char *fmt, ...);
93int vfprint(int fd, char *fmt, va_list args);
94char* vseprint(char *buf, char *e, char *fmt, va_list args);
95char* vsmprint(char *fmt, va_list args);
96int vsnprint(char *buf, int len, char *fmt, va_list args);
rscb2cfc4e2003-09-30 17:47:41 +000097
rscf7012582003-11-25 01:40:27 +000098#if defined(__cplusplus)
99}
100#endif
rscb2cfc4e2003-09-30 17:47:41 +0000101#endif