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