Sun, 11 Jun 2023 15:16:48 +0200
fix illegal memory access when input file does not end with line break
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2016 Mike Becker. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
30 #ifndef C2HTML_H
31 #define C2HTML_H
33 #include <stdio.h>
34 #include <cx/list.h>
35 #include "highlighter.h"
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
41 #define VERSION_MAJOR 3
42 #define VERSION_MINOR 0
43 #define VERSION_DEVELOP 0 /* set this to zero for release version */
45 /**
46 * Writes the formatted source data to the output buffer.
47 *
48 * @param inputtext the source file data as zero-terminated string
49 * @param outbuf the output buffer
50 * @param wfnc a write function for the output buffer
51 * @param hltr the highlighter function
52 * @param showln zero, if line numbers shall be omitted, nonzero otherwise
53 *
54 * @return total amount of bytes written to the output buffer
55 *
56 * @see c2html_plain_highlighter()
57 * @see c2html_c_highlighter()
58 * @see c2html_java_highlighter()
59 */
60 size_t c2html_textformat(char const* inputtext,
61 void* outbuf, cx_write_func wfnc,
62 c2html_highlighter_func hltr, int showln);
64 /**
65 * Writes the formatted source data to the output buffer.
66 *
67 * This function takes a list of \c char* that point to the beginning of each
68 * line. These pointers may point directly into the source text and the strings
69 * do not need to be zero-terminated, but the line-breaks must be included.
70 *
71 * @param lines a list of pointers to the beginning of each line
72 * @param outbuf the output buffer
73 * @param wfnc a write function for the output buffer
74 * @param hltr the highlighter function
75 * @param showln zero, if line numbers shall be omitted, nonzero otherwise
76 *
77 * @return total amount of bytes written to the output buffer
78 *
79 * @see c2html_plain_highlighter()
80 * @see c2html_c_highlighter()
81 * @see c2html_java_highlighter()
82 */
83 size_t c2html_format(CxList const* lines,
84 void* outbuf, cx_write_func wfnc,
85 c2html_highlighter_func hltr, int showln);
87 #ifdef __cplusplus
88 }
89 #endif
91 #endif /* C2HTML_H */