src/c2html.c

changeset 57
eba880c1705c
parent 55
bf54085ce341
child 60
9f25df78925e
     1.1 --- a/src/c2html.c	Wed Aug 31 14:47:01 2016 +0200
     1.2 +++ b/src/c2html.c	Wed Aug 31 16:20:58 2016 +0200
     1.3 @@ -102,17 +102,8 @@
     1.4      ucx_stream_copy(inputbuffer, content, rfnc, (write_func) ucx_buffer_write,
     1.5              ibuf, ibuflen, (size_t)-1);
     1.6  
     1.7 -    UcxList *lines = ucx_list_append(NULL, content->space);
     1.8 -    for (size_t i = 1 ; i < content->size ; i++) {
     1.9 -        if (content->space[i] == '\r') {
    1.10 -            content->space[i] = '\n'; i++;
    1.11 -        }
    1.12 -        if (content->space[i] == '\n' && i+1 < content->size) {
    1.13 -            ucx_list_append(lines, content->space+i+1);
    1.14 -        }
    1.15 -    }
    1.16 -    
    1.17 -    size_t n = formatlines(hltr, lines, outputbuffer, wfnc, maxlen, showln);
    1.18 +    size_t n = c2html_bformatn(content->space, content->size,
    1.19 +            outputbuffer, wfnc, maxlen, hltr, showln);
    1.20      
    1.21      ucx_buffer_free(content);
    1.22      return n;
    1.23 @@ -125,15 +116,44 @@
    1.24              outputbuffer, wfnc, (size_t)-1, hltr, showln);
    1.25  }
    1.26  
    1.27 -size_t c2html_format_file(FILE* inputfile, char *ibuf, size_t ibuflen,
    1.28 +size_t c2html_fformat(FILE* inputfile, char *ibuf, size_t ibuflen,
    1.29          void* outputbuffer, write_func wfnc,
    1.30          c2html_highlighter_func hltr, int showln) {
    1.31      return c2html_format(inputfile, (read_func) fread, ibuf, ibuflen,
    1.32              outputbuffer, wfnc, hltr, showln);
    1.33  }
    1.34  
    1.35 -void c2html_fformat_file(FILE *inputfile, char *ibuf, size_t ibuflen,
    1.36 +void c2html_fformatf(FILE *inputfile, char *ibuf, size_t ibuflen,
    1.37          FILE* outputfile, c2html_highlighter_func hltr, int showln) {
    1.38      c2html_format(inputfile, (read_func) fread, ibuf, ibuflen,
    1.39              outputfile, (write_func) fwrite, hltr, showln);
    1.40  }
    1.41 +
    1.42 +size_t c2html_bformatn(const char* inputbuffer, size_t inputbuflen,
    1.43 +        void* outputbuffer, write_func wfnc,
    1.44 +        size_t maxlen, c2html_highlighter_func hltr, int showln) {
    1.45 +    UcxList *lines = ucx_list_append(NULL, (char*)inputbuffer);
    1.46 +    for (size_t i = 1 ; i < inputbuflen ; i++) {
    1.47 +        if (inputbuffer[i] == '\n' && i+1 < inputbuflen) {
    1.48 +            ucx_list_append(lines, (char*)inputbuffer+i+1);
    1.49 +        }
    1.50 +    }
    1.51 +    
    1.52 +    size_t n = formatlines(hltr, lines, outputbuffer, wfnc, maxlen, showln);
    1.53 +    
    1.54 +    ucx_list_free(lines);
    1.55 +    return n;
    1.56 +}
    1.57 +
    1.58 +size_t c2html_bformat(const char* inputbuffer, size_t inputbuflen,
    1.59 +        void* outputbuffer, write_func wfnc,
    1.60 +        c2html_highlighter_func hltr, int showln) {
    1.61 +    return c2html_bformatn(inputbuffer, inputbuflen, outputbuffer, wfnc,
    1.62 +            (size_t)-1, hltr, showln);
    1.63 +}
    1.64 +
    1.65 +void c2html_bformatf(const char* inputbuffer, size_t inputbuflen,
    1.66 +        FILE* outputfile, c2html_highlighter_func hltr, int showln) {
    1.67 +    c2html_bformatn(inputbuffer, inputbuflen, outputfile,
    1.68 +            (write_func) fwrite, (size_t)-1, hltr, showln);
    1.69 +}

mercurial