Text::Markdown::Discount
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1008 B

  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, int flags)
  44. {
  45. MMIOT f;
  46. ___mkd_initmmiot(&f, 0);
  47. ___mkd_reparse(buf, size, 0, &f, 0);
  48. ___mkd_emblock(&f);
  49. SUFFIX(*iot, T(f.out), S(f.out));
  50. ___mkd_freemmiot(&f, 0);
  51. }