| 54 written += wfnc("<div class=\"c2html-code\">\n", 1, 26, outbuf); |
54 written += wfnc("<div class=\"c2html-code\">\n", 1, 26, outbuf); |
| 55 |
55 |
| 56 /* process lines */ |
56 /* process lines */ |
| 57 int lineno = 0; |
57 int lineno = 0; |
| 58 c2html_highlighter_data hd = {0}; |
58 c2html_highlighter_data hd = {0}; |
| 59 cxBufferInit(&hd.primary_buffer, NULL, 256, NULL, CX_BUFFER_AUTO_EXTEND); |
59 cxBufferInit(&hd.primary_buffer, NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND); |
| 60 cxBufferInit(&hd.secondary_buffer, NULL, 32, NULL, CX_BUFFER_AUTO_EXTEND); |
60 cxBufferInit(&hd.secondary_buffer, NULL, NULL, 32, CX_BUFFER_AUTO_EXTEND); |
| 61 CxBuffer out_line; |
61 CxBuffer out_line; |
| 62 cxBufferInit(&out_line, NULL, 128, NULL, CX_BUFFER_AUTO_EXTEND); |
62 cxBufferInit(&out_line, NULL, NULL, 128, CX_BUFFER_AUTO_EXTEND); |
| 63 |
63 |
| 64 CxIterator in_lines = cxListIterator(lines); |
64 CxIterator in_lines = cxListIterator(lines); |
| 65 cx_foreach(char*, in_line, in_lines) { |
65 cx_foreach(char*, in_line, in_lines) { |
| 66 /* increase line number and clean line buffer */ |
66 /* increase line number and clean line buffer */ |
| 67 lineno++; |
67 lineno++; |
| 114 ) { |
114 ) { |
| 115 /* a rough estimate for the number of lines */ |
115 /* a rough estimate for the number of lines */ |
| 116 size_t est_cap = 16 + insize / 40; |
116 size_t est_cap = 16 + insize / 40; |
| 117 |
117 |
| 118 /* create the line pointer array */ |
118 /* create the line pointer array */ |
| 119 CxList *lines = cxArrayListCreateSimple(CX_STORE_POINTERS, est_cap); |
119 CxList *lines = cxArrayListCreate(NULL, CX_STORE_POINTERS, est_cap); |
| 120 cxListAdd(lines, inbuf); |
120 cxListAdd(lines, inbuf); |
| 121 for (size_t i = 0; i < insize; i++) { |
121 for (size_t i = 0; i < insize; i++) { |
| 122 if (inbuf[i] == '\n' && i + 1 < insize) { |
122 if (inbuf[i] == '\n' && i + 1 < insize) { |
| 123 cxListAdd(lines, inbuf + i + 1); |
123 cxListAdd(lines, inbuf + i + 1); |
| 124 } |
124 } |