fmtdef.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * The authors of this software are Rob Pike and Ken Thompson.
  3. * Copyright (c) 2002 by Lucent Technologies.
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose without fee is hereby granted, provided that this entire notice
  6. * is included in all copies of any software which is or includes a copy
  7. * or modification of this software and in all copies of the supporting
  8. * documentation for such software.
  9. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
  10. * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
  11. * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
  12. * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  13. */
  14. /*
  15. * dofmt -- format to a buffer
  16. * the number of characters formatted is returned,
  17. * or -1 if there was an error.
  18. * if the buffer is ever filled, flush is called.
  19. * it should reset the buffer and return whether formatting should continue.
  20. */
  21. typedef int (*Fmts)(Fmt*);
  22. typedef struct Quoteinfo Quoteinfo;
  23. struct Quoteinfo
  24. {
  25. int quoted; /* if set, string must be quoted */
  26. int nrunesin; /* number of input runes that can be accepted */
  27. int nbytesin; /* number of input bytes that can be accepted */
  28. int nrunesout; /* number of runes that will be generated */
  29. int nbytesout; /* number of bytes that will be generated */
  30. };
  31. /* Edit .+1,/^$/ |cfn |grep -v static | grep __ */
  32. double __Inf(int sign);
  33. double __NaN(void);
  34. int __badfmt(Fmt *f);
  35. int __charfmt(Fmt *f);
  36. int __countfmt(Fmt *f);
  37. int __efgfmt(Fmt *fmt);
  38. int __errfmt(Fmt *f);
  39. int __flagfmt(Fmt *f);
  40. int __fmtFdFlush(Fmt *f);
  41. int __fmtcpy(Fmt *f, const void *vm, int n, int sz);
  42. void* __fmtdispatch(Fmt *f, void *fmt, int isrunes);
  43. void * __fmtflush(Fmt *f, void *t, int len);
  44. void __fmtlock(void);
  45. int __fmtpad(Fmt *f, int n);
  46. double __fmtpow10(int n);
  47. int __fmtrcpy(Fmt *f, const void *vm, int n);
  48. void __fmtunlock(void);
  49. int __ifmt(Fmt *f);
  50. int __isInf(double d, int sign);
  51. int __isNaN(double d);
  52. int __needsquotes(char *s, int *quotelenp);
  53. int __percentfmt(Fmt *f);
  54. void __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int runesout);
  55. int __quotestrfmt(int runesin, Fmt *f);
  56. int __rfmtpad(Fmt *f, int n);
  57. int __runefmt(Fmt *f);
  58. int __runeneedsquotes(Rune *r, int *quotelenp);
  59. int __runesfmt(Fmt *f);
  60. int __strfmt(Fmt *f);
  61. #define FMTCHAR(f, t, s, c)\
  62. do{\
  63. if(t + 1 > (char*)s){\
  64. t = __fmtflush(f, t, 1);\
  65. if(t != nil)\
  66. s = f->stop;\
  67. else\
  68. return -1;\
  69. }\
  70. *t++ = c;\
  71. }while(0)
  72. #define FMTRCHAR(f, t, s, c)\
  73. do{\
  74. if(t + 1 > (Rune*)s){\
  75. t = __fmtflush(f, t, sizeof(Rune));\
  76. if(t != nil)\
  77. s = f->stop;\
  78. else\
  79. return -1;\
  80. }\
  81. *t++ = c;\
  82. }while(0)
  83. #define FMTRUNE(f, t, s, r)\
  84. do{\
  85. Rune _rune;\
  86. int _runelen;\
  87. if(t + UTFmax > (char*)s && t + (_runelen = runelen(r)) > (char*)s){\
  88. t = __fmtflush(f, t, _runelen);\
  89. if(t != nil)\
  90. s = f->stop;\
  91. else\
  92. return -1;\
  93. }\
  94. if(r < Runeself)\
  95. *t++ = r;\
  96. else{\
  97. _rune = r;\
  98. t += runetochar(t, &_rune);\
  99. }\
  100. }while(0)
  101. #ifdef va_copy
  102. # define VA_COPY(a,b) va_copy(a,b)
  103. # define VA_END(a) va_end(a)
  104. #else
  105. # define VA_COPY(a,b) (a) = (b)
  106. # define VA_END(a)
  107. #endif
  108. #define PLAN9PORT