1
0

fmt.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef _FMT_H_
  2. #define _FMT_H_ 1
  3. #pragma lib "/$M/lib/ape/libfmt.a"
  4. #pragma src "/sys/src/ape/lib/fmt"
  5. #if defined(__cplusplus)
  6. extern "C" {
  7. #endif
  8. /*
  9. * The authors of this software are Rob Pike and Ken Thompson.
  10. * Copyright (c) 2002 by Lucent Technologies.
  11. * Permission to use, copy, modify, and distribute this software for any
  12. * purpose without fee is hereby granted, provided that this entire notice
  13. * is included in all copies of any software which is or includes a copy
  14. * or modification of this software and in all copies of the supporting
  15. * documentation for such software.
  16. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
  17. * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
  18. * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
  19. * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  20. */
  21. #include <stdarg.h>
  22. #include <utf.h>
  23. typedef struct Fmt Fmt;
  24. struct 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. enum{
  39. FmtWidth = 1,
  40. FmtLeft = FmtWidth << 1,
  41. FmtPrec = FmtLeft << 1,
  42. FmtSharp = FmtPrec << 1,
  43. FmtSpace = FmtSharp << 1,
  44. FmtSign = FmtSpace << 1,
  45. FmtZero = FmtSign << 1,
  46. FmtUnsigned = FmtZero << 1,
  47. FmtShort = FmtUnsigned << 1,
  48. FmtLong = FmtShort << 1,
  49. FmtVLong = FmtLong << 1,
  50. FmtComma = FmtVLong << 1,
  51. FmtByte = FmtComma << 1,
  52. FmtLDouble = FmtByte << 1,
  53. FmtFlag = FmtLDouble << 1
  54. };
  55. extern int print(char*, ...);
  56. extern char* seprint(char*, char*, char*, ...);
  57. extern char* vseprint(char*, char*, char*, va_list);
  58. extern int snprint(char*, int, char*, ...);
  59. extern int vsnprint(char*, int, char*, va_list);
  60. extern char* smprint(char*, ...);
  61. extern char* vsmprint(char*, va_list);
  62. extern int sprint(char*, char*, ...);
  63. extern int fprint(int, char*, ...);
  64. extern int vfprint(int, char*, va_list);
  65. extern int runesprint(Rune*, char*, ...);
  66. extern int runesnprint(Rune*, int, char*, ...);
  67. extern int runevsnprint(Rune*, int, char*, va_list);
  68. extern Rune* runeseprint(Rune*, Rune*, char*, ...);
  69. extern Rune* runevseprint(Rune*, Rune*, char*, va_list);
  70. extern Rune* runesmprint(char*, ...);
  71. extern Rune* runevsmprint(char*, va_list);
  72. extern int fmtfdinit(Fmt*, int, char*, int);
  73. extern int fmtfdflush(Fmt*);
  74. extern int fmtstrinit(Fmt*);
  75. extern char* fmtstrflush(Fmt*);
  76. extern int runefmtstrinit(Fmt*);
  77. extern int quotestrfmt(Fmt *f);
  78. extern void quotefmtinstall(void);
  79. extern int (*fmtdoquote)(int);
  80. extern int fmtinstall(int, int (*)(Fmt*));
  81. extern int dofmt(Fmt*, char*);
  82. extern int fmtprint(Fmt*, char*, ...);
  83. extern int fmtvprint(Fmt*, char*, va_list);
  84. extern int fmtrune(Fmt*, int);
  85. extern int fmtstrcpy(Fmt*, char*);
  86. extern double fmtstrtod(const char *, char **);
  87. extern double fmtcharstod(int(*)(void*), void*);
  88. extern void werrstr(const char*, ...);
  89. #if defined(__cplusplus)
  90. }
  91. #endif
  92. #endif