Csio.c 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdarg.h>
  4. #include "cstring.h"
  5. #include "markdown.h"
  6. #include "amalloc.h"
  7. /* putc() into a cstring
  8. */
  9. void
  10. Csputc(int c, Cstring *iot)
  11. {
  12. EXPAND(*iot) = c;
  13. }
  14. /* printf() into a cstring
  15. */
  16. int
  17. Csprintf(Cstring *iot, char *fmt, ...)
  18. {
  19. va_list ptr;
  20. int siz=100;
  21. do {
  22. RESERVE(*iot, siz);
  23. va_start(ptr, fmt);
  24. siz = vsnprintf(T(*iot)+S(*iot), ALLOCATED(*iot)-S(*iot), fmt, ptr);
  25. va_end(ptr);
  26. } while ( siz > (ALLOCATED(*iot)-S(*iot)) );
  27. S(*iot) += siz;
  28. return siz;
  29. }
  30. /* write() into a cstring
  31. */
  32. int
  33. Cswrite(Cstring *iot, char *bfr, int size)
  34. {
  35. RESERVE(*iot, size);
  36. memcpy(T(*iot)+S(*iot), bfr, size);
  37. S(*iot) += size;
  38. return size;
  39. }
  40. /* reparse() into a cstring
  41. */
  42. void
  43. Csreparse(Cstring *iot, char *buf, int size, mkd_flag_t* flags)
  44. {
  45. MMIOT f;
  46. ___mkd_initmmiot(&f, 0);
  47. ___mkd_reparse(buf, size, flags, &f, 0);
  48. ___mkd_emblock(&f);
  49. SUFFIX(*iot, T(f.out), S(f.out));
  50. ___mkd_freemmiot(&f, 0);
  51. }