diff -r 81d99e9ceb20 -r eba880c1705c src/c2html.c --- a/src/c2html.c Wed Aug 31 14:47:01 2016 +0200 +++ b/src/c2html.c Wed Aug 31 16:20:58 2016 +0200 @@ -102,17 +102,8 @@ ucx_stream_copy(inputbuffer, content, rfnc, (write_func) ucx_buffer_write, ibuf, ibuflen, (size_t)-1); - UcxList *lines = ucx_list_append(NULL, content->space); - for (size_t i = 1 ; i < content->size ; i++) { - if (content->space[i] == '\r') { - content->space[i] = '\n'; i++; - } - if (content->space[i] == '\n' && i+1 < content->size) { - ucx_list_append(lines, content->space+i+1); - } - } - - size_t n = formatlines(hltr, lines, outputbuffer, wfnc, maxlen, showln); + size_t n = c2html_bformatn(content->space, content->size, + outputbuffer, wfnc, maxlen, hltr, showln); ucx_buffer_free(content); return n; @@ -125,15 +116,44 @@ outputbuffer, wfnc, (size_t)-1, hltr, showln); } -size_t c2html_format_file(FILE* inputfile, char *ibuf, size_t ibuflen, +size_t c2html_fformat(FILE* inputfile, char *ibuf, size_t ibuflen, void* outputbuffer, write_func wfnc, c2html_highlighter_func hltr, int showln) { return c2html_format(inputfile, (read_func) fread, ibuf, ibuflen, outputbuffer, wfnc, hltr, showln); } -void c2html_fformat_file(FILE *inputfile, char *ibuf, size_t ibuflen, +void c2html_fformatf(FILE *inputfile, char *ibuf, size_t ibuflen, FILE* outputfile, c2html_highlighter_func hltr, int showln) { c2html_format(inputfile, (read_func) fread, ibuf, ibuflen, outputfile, (write_func) fwrite, hltr, showln); } + +size_t c2html_bformatn(const char* inputbuffer, size_t inputbuflen, + void* outputbuffer, write_func wfnc, + size_t maxlen, c2html_highlighter_func hltr, int showln) { + UcxList *lines = ucx_list_append(NULL, (char*)inputbuffer); + for (size_t i = 1 ; i < inputbuflen ; i++) { + if (inputbuffer[i] == '\n' && i+1 < inputbuflen) { + ucx_list_append(lines, (char*)inputbuffer+i+1); + } + } + + size_t n = formatlines(hltr, lines, outputbuffer, wfnc, maxlen, showln); + + ucx_list_free(lines); + return n; +} + +size_t c2html_bformat(const char* inputbuffer, size_t inputbuflen, + void* outputbuffer, write_func wfnc, + c2html_highlighter_func hltr, int showln) { + return c2html_bformatn(inputbuffer, inputbuflen, outputbuffer, wfnc, + (size_t)-1, hltr, showln); +} + +void c2html_bformatf(const char* inputbuffer, size_t inputbuflen, + FILE* outputfile, c2html_highlighter_func hltr, int showln) { + c2html_bformatn(inputbuffer, inputbuflen, outputfile, + (write_func) fwrite, (size_t)-1, hltr, showln); +}