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