fmt.h 3.7 KB

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