src/c2html.c

changeset 88
15fe9c1d7f1a
parent 86
c41ab60fd27a
equal deleted inserted replaced
87:a53fa82bbdcf 88:15fe9c1d7f1a
97 void *outbuf, 97 void *outbuf,
98 cx_write_func wfnc, 98 cx_write_func wfnc,
99 c2html_highlighter_func highlighter, 99 c2html_highlighter_func highlighter,
100 int showln 100 int showln
101 ) { 101 ) {
102 size_t insize = strlen(inputbuffer);
103 return c2html_bformat(inputbuffer, insize,
104 outbuf, wfnc, highlighter, showln);
105 }
106
107 size_t c2html_bformat(
108 char const *inbuf,
109 size_t insize,
110 void *outbuf,
111 cx_write_func wfnc,
112 c2html_highlighter_func highlighter,
113 int showln
114 ) {
102 /* a rough estimate for the number of lines */ 115 /* a rough estimate for the number of lines */
103 size_t inputbuflen = strlen(inputbuffer); 116 size_t est_cap = 16 + insize / 40;
104 size_t est_cap = 16 + inputbuflen / 40;
105 117
106 /* create the line pointer array */ 118 /* create the line pointer array */
107 CxList *lines = cxArrayListCreateSimple(CX_STORE_POINTERS, est_cap); 119 CxList *lines = cxArrayListCreateSimple(CX_STORE_POINTERS, est_cap);
108 cxListAdd(lines, inputbuffer); 120 cxListAdd(lines, inbuf);
109 for (size_t i = 0; i < inputbuflen; i++) { 121 for (size_t i = 0; i < insize; i++) {
110 if (inputbuffer[i] == '\n' && i + 1 < inputbuflen) { 122 if (inbuf[i] == '\n' && i + 1 < insize) {
111 cxListAdd(lines, inputbuffer + i + 1); 123 cxListAdd(lines, inbuf + i + 1);
112 } 124 }
113 } 125 }
114 126
115 /* invoke the other function */ 127 /* invoke the other function */
116 size_t n = c2html_format(lines, outbuf, wfnc, highlighter, showln); 128 size_t n = c2html_format(lines, outbuf, wfnc, highlighter, showln);

mercurial