1 #ifndef _FMT_H_ 2 #define _FMT_H_ 1 3 /* 4 * The authors of this software are Rob Pike and Ken Thompson. 5 * Copyright (c) 2002 by Lucent Technologies. 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose without fee is hereby granted, provided that this entire notice 8 * is included in all copies of any software which is or includes a copy 9 * or modification of this software and in all copies of the supporting 10 * documentation for such software. 11 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 12 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 13 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 14 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 15 */ 16 17 #include <stdarg.h> 18 #include <utf.h> 19 20 typedef struct Fmt Fmt; 21 struct Fmt{ 22 unsigned char runes; /* output buffer is runes or chars? */ 23 void *start; /* of buffer */ 24 void *to; /* current place in the buffer */ 25 void *stop; /* end of the buffer; overwritten if flush fails */ 26 int (*flush)(Fmt *); /* called when to == stop */ 27 void *farg; /* to make flush a closure */ 28 int nfmt; /* num chars formatted so far */ 29 va_list args; /* args passed to dofmt */ 30 int r; /* % format Rune */ 31 int width; 32 int prec; 33 unsigned long flags; 34 }; 35 36 enum{ 37 FmtWidth = 1, 38 FmtLeft = FmtWidth << 1, 39 FmtPrec = FmtLeft << 1, 40 FmtSharp = FmtPrec << 1, 41 FmtSpace = FmtSharp << 1, 42 FmtSign = FmtSpace << 1, 43 FmtZero = FmtSign << 1, 44 FmtUnsigned = FmtZero << 1, 45 FmtShort = FmtUnsigned << 1, 46 FmtLong = FmtShort << 1, 47 FmtVLong = FmtLong << 1, 48 FmtComma = FmtVLong << 1, 49 FmtByte = FmtComma << 1, 50 FmtLDouble = FmtByte << 1, 51 52 FmtFlag = FmtLDouble << 1 53 }; 54 55 extern int (*fmtdoquote)(int); 56 57 #ifdef VARARGCK 58 # pragma varargck argpos fmtprint 2 59 # pragma varargck argpos fprint 2 60 # pragma varargck argpos print 1 61 # pragma varargck argpos runeseprint 3 62 # pragma varargck argpos runesmprint 1 63 # pragma varargck argpos runesnprint 3 64 # pragma varargck argpos runesprint 2 65 # pragma varargck argpos seprint 3 66 # pragma varargck argpos smprint 1 67 # pragma varargck argpos snprint 3 68 # pragma varargck argpos sprint 2 69 70 # pragma varargck type "lld" vlong 71 # pragma varargck type "llx" vlong 72 # pragma varargck type "lld" uvlong 73 # pragma varargck type "llx" uvlong 74 # pragma varargck type "ld" long 75 # pragma varargck type "lx" long 76 # pragma varargck type "lb" long 77 # pragma varargck type "ld" ulong 78 # pragma varargck type "lx" ulong 79 # pragma varargck type "lb" ulong 80 # pragma varargck type "d" int 81 # pragma varargck type "x" int 82 # pragma varargck type "c" int 83 # pragma varargck type "C" int 84 # pragma varargck type "b" int 85 # pragma varargck type "d" uint 86 # pragma varargck type "x" uint 87 # pragma varargck type "c" uint 88 # pragma varargck type "C" uint 89 # pragma varargck type "b" uint 90 # pragma varargck type "f" double 91 # pragma varargck type "e" double 92 # pragma varargck type "g" double 93 # pragma varargck type "s" char* 94 # pragma varargck type "q" char* 95 # pragma varargck type "S" Rune* 96 # pragma varargck type "Q" Rune* 97 # pragma varargck type "r" void 98 # pragma varargck type "%" void 99 # pragma varargck type "n" int* 100 # pragma varargck type "p" uintptr_t 101 # pragma varargck type "p" void* 102 # pragma varargck flag ',' 103 # pragma varargck flag 'h' 104 # pragma varargck type "<" void* 105 # pragma varargck type "[" void* 106 # pragma varargck type "H" void* 107 # pragma varargck type "lH" void* 108 #endif 109 110 /* Edit .+1,/^$/ | cfn $PLAN9/src/lib9/fmt/?*.c | grep -v static |grep -v __ */ 111 int dofmt(Fmt *f, const char *fmt); 112 int dorfmt(Fmt *f, const Rune *fmt); 113 double fmtcharstod(int(*f)(void*), void *vp); 114 int fmtfdflush(Fmt *f); 115 int fmtfdinit(Fmt *f, int fd, char *buf, int size); 116 int fmtinstall(int c, int (*f)(Fmt*)); 117 int fmtprint(Fmt *f, const char *fmt, ...); 118 int fmtrune(Fmt *f, int r); 119 int fmtrunestrcpy(Fmt *f, Rune *s); 120 int fmtstrcpy(Fmt *f, const char *s); 121 char* fmtstrflush(Fmt *f); 122 int fmtstrinit(Fmt *f); 123 double fmtstrtod(const char *as, char **aas); 124 int fmtvprint(Fmt *f, const char *fmt, va_list args); 125 int fprint(int fd, const char *fmt, ...); 126 int print(const char *fmt, ...); 127 void quotefmtinstall(void); 128 int quoterunestrfmt(Fmt *f); 129 int quotestrfmt(Fmt *f); 130 Rune* runefmtstrflush(Fmt *f); 131 int runefmtstrinit(Fmt *f); 132 Rune* runeseprint(Rune *buf, Rune *e, const char *fmt, ...); 133 Rune* runesmprint(const char *fmt, ...); 134 int runesnprint(Rune *buf, int len, const char *fmt, ...); 135 int runesprint(Rune *buf, const char *fmt, ...); 136 Rune* runevseprint(Rune *buf, Rune *e, const char *fmt, va_list args); 137 Rune* runevsmprint(const char *fmt, va_list args); 138 int runevsnprint(Rune *buf, int len, const char *fmt, va_list args); 139 char* seprint(char *buf, char *e, const char *fmt, ...); 140 char* smprint(const char *fmt, ...); 141 int snprint(char *buf, int len, const char *fmt, ...); 142 int sprint(char *buf, const char *fmt, ...); 143 int vfprint(int fd, const char *fmt, va_list args); 144 char* vseprint(char *buf, char *e, const char *fmt, va_list args); 145 char* vsmprint(const char *fmt, va_list args); 146 int vsnprint(char *buf, int len, const char *fmt, va_list args); 147 148 #endif 149