src/c2html.c

changeset 57
eba880c1705c
parent 55
bf54085ce341
child 60
9f25df78925e
equal deleted inserted replaced
56:81d99e9ceb20 57:eba880c1705c
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_copy(inputbuffer, content, rfnc, (write_func) ucx_buffer_write,
103 ibuf, ibuflen, (size_t)-1); 103 ibuf, ibuflen, (size_t)-1);
104 104
105 UcxList *lines = ucx_list_append(NULL, content->space); 105 size_t n = c2html_bformatn(content->space, content->size,
106 for (size_t i = 1 ; i < content->size ; i++) { 106 outputbuffer, wfnc, maxlen, hltr, showln);
107 if (content->space[i] == '\r') {
108 content->space[i] = '\n'; i++;
109 }
110 if (content->space[i] == '\n' && i+1 < content->size) {
111 ucx_list_append(lines, content->space+i+1);
112 }
113 }
114
115 size_t n = formatlines(hltr, lines, outputbuffer, wfnc, maxlen, showln);
116 107
117 ucx_buffer_free(content); 108 ucx_buffer_free(content);
118 return n; 109 return n;
119 } 110 }
120 111
123 c2html_highlighter_func hltr, int showln) { 114 c2html_highlighter_func hltr, int showln) {
124 return c2html_formatn(inputbuffer, rfnc, ibuf, ibuflen, 115 return c2html_formatn(inputbuffer, rfnc, ibuf, ibuflen,
125 outputbuffer, wfnc, (size_t)-1, hltr, showln); 116 outputbuffer, wfnc, (size_t)-1, hltr, showln);
126 } 117 }
127 118
128 size_t c2html_format_file(FILE* inputfile, char *ibuf, size_t ibuflen, 119 size_t c2html_fformat(FILE* inputfile, char *ibuf, size_t ibuflen,
129 void* outputbuffer, write_func wfnc, 120 void* outputbuffer, write_func wfnc,
130 c2html_highlighter_func hltr, int showln) { 121 c2html_highlighter_func hltr, int showln) {
131 return c2html_format(inputfile, (read_func) fread, ibuf, ibuflen, 122 return c2html_format(inputfile, (read_func) fread, ibuf, ibuflen,
132 outputbuffer, wfnc, hltr, showln); 123 outputbuffer, wfnc, hltr, showln);
133 } 124 }
134 125
135 void c2html_fformat_file(FILE *inputfile, char *ibuf, size_t ibuflen, 126 void c2html_fformatf(FILE *inputfile, char *ibuf, size_t ibuflen,
136 FILE* outputfile, c2html_highlighter_func hltr, int showln) { 127 FILE* outputfile, c2html_highlighter_func hltr, int showln) {
137 c2html_format(inputfile, (read_func) fread, ibuf, ibuflen, 128 c2html_format(inputfile, (read_func) fread, ibuf, ibuflen,
138 outputfile, (write_func) fwrite, hltr, showln); 129 outputfile, (write_func) fwrite, hltr, showln);
139 } 130 }
131
132 size_t c2html_bformatn(const char* inputbuffer, size_t inputbuflen,
133 void* outputbuffer, write_func wfnc,
134 size_t maxlen, c2html_highlighter_func hltr, int showln) {
135 UcxList *lines = ucx_list_append(NULL, (char*)inputbuffer);
136 for (size_t i = 1 ; i < inputbuflen ; i++) {
137 if (inputbuffer[i] == '\n' && i+1 < inputbuflen) {
138 ucx_list_append(lines, (char*)inputbuffer+i+1);
139 }
140 }
141
142 size_t n = formatlines(hltr, lines, outputbuffer, wfnc, maxlen, showln);
143
144 ucx_list_free(lines);
145 return n;
146 }
147
148 size_t c2html_bformat(const char* inputbuffer, size_t inputbuflen,
149 void* outputbuffer, write_func wfnc,
150 c2html_highlighter_func hltr, int showln) {
151 return c2html_bformatn(inputbuffer, inputbuflen, outputbuffer, wfnc,
152 (size_t)-1, hltr, showln);
153 }
154
155 void c2html_bformatf(const char* inputbuffer, size_t inputbuflen,
156 FILE* outputfile, c2html_highlighter_func hltr, int showln) {
157 c2html_bformatn(inputbuffer, inputbuflen, outputfile,
158 (write_func) fwrite, (size_t)-1, hltr, showln);
159 }

mercurial