1
0

fmt.h 3.3 KB

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