27 * |
27 * |
28 */ |
28 */ |
29 |
29 |
30 #include "c2html.h" |
30 #include "c2html.h" |
31 |
31 |
32 #include "ucx/list.h" |
32 #include <ucx/list.h> |
33 #include "ucx/utils.h" |
33 #include <ucx/utils.h> |
34 |
34 |
35 #define try_write(wfnc, str, n, buf, written, maxlen) \ |
35 #define try_write(wfnc, str, n, buf, written, maxlen) \ |
36 { \ |
36 { \ |
37 size_t m = maxlen-written; \ |
37 size_t m = maxlen-written; \ |
38 written += wfnc(str, 1, n > m ? m : n, buf); \ |
38 written += wfnc(str, 1, n > m ? m : n, buf); \ |
97 size_t c2html_formatn(void* inputbuffer, read_func rfnc, |
97 size_t c2html_formatn(void* inputbuffer, read_func rfnc, |
98 char* ibuf, size_t ibuflen, void* outputbuffer, write_func wfnc, |
98 char* ibuf, size_t ibuflen, void* outputbuffer, write_func wfnc, |
99 size_t maxlen, c2html_highlighter_func hltr, int showln) { |
99 size_t maxlen, c2html_highlighter_func hltr, int showln) { |
100 |
100 |
101 UcxBuffer *content = ucx_buffer_new(NULL, ibuflen*2, UCX_BUFFER_AUTOEXTEND); |
101 UcxBuffer *content = ucx_buffer_new(NULL, ibuflen*2, UCX_BUFFER_AUTOEXTEND); |
102 ucx_stream_copy(inputbuffer, content, rfnc, (write_func) ucx_buffer_write, |
102 ucx_stream_bcopy(inputbuffer, content, rfnc, (write_func) ucx_buffer_write, |
103 ibuf, ibuflen, (size_t)-1); |
103 ibuf, ibuflen); |
104 |
104 |
105 size_t n = c2html_bformatn(content->space, content->size, |
105 size_t n = c2html_bformatn(content->space, content->size, |
106 outputbuffer, wfnc, maxlen, hltr, showln); |
106 outputbuffer, wfnc, maxlen, hltr, showln); |
107 |
107 |
108 ucx_buffer_free(content); |
108 ucx_buffer_free(content); |