src/c2html.h

Wed, 10 Jul 2024 21:35:37 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 10 Jul 2024 21:35:37 +0200
changeset 75
c72b250866ab
parent 70
60cecca5e484
child 78
719e3c6d4c9b
permissions
-rw-r--r--

add basic support for line continuations in C highlighter

things that still do not work:
- user includes
- splitting keywords

fixes #392

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

mercurial