File indexing completed on 2024-04-28 11:21:06

0001 #include <stdio.h>
0002 #include <string.h>
0003 #include <stdarg.h>
0004 #include "cstring.h"
0005 #include "markdown.h"
0006 #include "amalloc.h"
0007 
0008 
0009 /* putc() into a cstring
0010  */
0011 void
0012 Csputc(int c, Cstring *iot)
0013 {
0014     EXPAND(*iot) = c;
0015 }
0016 
0017 
0018 /* printf() into a cstring
0019  */
0020 int
0021 Csprintf(Cstring *iot, char *fmt, ...)
0022 {
0023     va_list ptr;
0024     int siz=100;
0025 
0026     do {
0027     RESERVE(*iot, siz);
0028     va_start(ptr, fmt);
0029     siz = vsnprintf(T(*iot)+S(*iot), ALLOCATED(*iot)-S(*iot), fmt, ptr);
0030     va_end(ptr);
0031     } while ( siz > (ALLOCATED(*iot)-S(*iot)) );
0032 
0033     S(*iot) += siz;
0034     return siz;
0035 }
0036 
0037 
0038 /* write() into a cstring
0039  */
0040 int
0041 Cswrite(Cstring *iot, char *bfr, int size)
0042 {
0043     RESERVE(*iot, size);
0044     memcpy(T(*iot)+S(*iot), bfr, size);
0045     S(*iot) += size;
0046     return size;
0047 }
0048 
0049 
0050 /* reparse() into a cstring
0051  */
0052 void
0053 Csreparse(Cstring *iot, char *buf, int size, mkd_flag_t flags)
0054 {
0055     MMIOT f;
0056     ___mkd_initmmiot(&f, 0);
0057     ___mkd_reparse(buf, size, flags, &f, 0);
0058     ___mkd_emblock(&f);
0059     SUFFIX(*iot, T(f.out), S(f.out));
0060     ___mkd_freemmiot(&f, 0);
0061 }