bring back the c2html_bformat() function default tip

Sat, 15 Feb 2025 23:26:08 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 15 Feb 2025 23:26:08 +0100
changeset 88
15fe9c1d7f1a
parent 87
a53fa82bbdcf

bring back the c2html_bformat() function

fixes #592

src/c2html.c file | annotate | diff | comparison | revisions
src/c2html.h file | annotate | diff | comparison | revisions
--- a/src/c2html.c	Sat Feb 15 23:21:29 2025 +0100
+++ b/src/c2html.c	Sat Feb 15 23:26:08 2025 +0100
@@ -99,16 +99,28 @@
         c2html_highlighter_func highlighter,
         int showln
 ) {
+    size_t insize = strlen(inputbuffer);
+    return c2html_bformat(inputbuffer, insize,
+        outbuf, wfnc, highlighter, showln);
+}
+
+size_t c2html_bformat(
+        char const *inbuf,
+        size_t insize,
+        void *outbuf,
+        cx_write_func wfnc,
+        c2html_highlighter_func highlighter,
+        int showln
+) {
     /* a rough estimate for the number of lines */
-    size_t inputbuflen = strlen(inputbuffer);
-    size_t est_cap = 16 + inputbuflen / 40;
+    size_t est_cap = 16 + insize / 40;
 
     /* create the line pointer array */
     CxList *lines = cxArrayListCreateSimple(CX_STORE_POINTERS, est_cap);
-    cxListAdd(lines, inputbuffer);
-    for (size_t i = 0; i < inputbuflen; i++) {
-        if (inputbuffer[i] == '\n' && i + 1 < inputbuflen) {
-            cxListAdd(lines, inputbuffer + i + 1);
+    cxListAdd(lines, inbuf);
+    for (size_t i = 0; i < insize; i++) {
+        if (inbuf[i] == '\n' && i + 1 < insize) {
+            cxListAdd(lines, inbuf + i + 1);
         }
     }
 
--- a/src/c2html.h	Sat Feb 15 23:21:29 2025 +0100
+++ b/src/c2html.h	Sat Feb 15 23:26:08 2025 +0100
@@ -64,6 +64,26 @@
 /**
  * Writes the formatted source data to the output buffer.
  *
+ * @param inbuf the input buffer
+ * @param insize the size of the input buffer
+ * @param outbuf the output buffer
+ * @param wfnc a write function for the output buffer
+ * @param hltr the highlighter function
+ * @param showln zero, if line numbers shall be omitted, nonzero otherwise
+ *
+ * @return total amount of bytes written to the output buffer
+ *
+ * @see c2html_plain_highlighter()
+ * @see c2html_c_highlighter()
+ * @see c2html_java_highlighter()
+ */
+size_t c2html_bformat(char const* inbuf, size_t insize,
+                      void* outbuf, cx_write_func wfnc,
+                      c2html_highlighter_func hltr, int showln);
+
+/**
+ * Writes the formatted source data to the output buffer.
+ *
  * This function takes a list of \c char* that point to the beginning of each
  * line. These pointers may point directly into the source text and the strings
  * do not need to be zero-terminated, but the line-breaks must be included.

mercurial