Mon, 03 Oct 2022 12:14:53 +0200
update tests
21 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
35 | 4 | * Copyright 2016 Mike Becker. All rights reserved. |
21 | 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 | */ | |
29 | ||
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
30 | #include "highlighter.h" |
21 | 31 | |
55
bf54085ce341
adds appropriate public API
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
32 | #include <stdlib.h> |
bf54085ce341
adds appropriate public API
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
33 | #include <stdio.h> |
bf54085ce341
adds appropriate public API
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
34 | #include <string.h> |
bf54085ce341
adds appropriate public API
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
35 | #include <ctype.h> |
61
47a5fc33590a
ucx is now used as external library
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
36 | #include <ucx/string.h> |
47a5fc33590a
ucx is now used as external library
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
37 | #include <ucx/utils.h> |
51
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
38 | |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
39 | static void put_htmlescaped(UcxBuffer *dest, char c) { |
21 | 40 | if (c == '>') { |
48
b2724c711203
highlighter now use the UcxBuffer API for writing to the destination buffer
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
41 | ucx_buffer_puts(dest, ">"); |
21 | 42 | } else if (c == '<') { |
48
b2724c711203
highlighter now use the UcxBuffer API for writing to the destination buffer
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
43 | ucx_buffer_puts(dest, "<"); |
54
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
44 | } else if (c) { |
48
b2724c711203
highlighter now use the UcxBuffer API for writing to the destination buffer
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
45 | ucx_buffer_putc(dest, c); |
21 | 46 | } |
48
b2724c711203
highlighter now use the UcxBuffer API for writing to the destination buffer
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
47 | } |
21 | 48 | |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
49 | static void put_htmlescapedstr(UcxBuffer *dest, sstr_t s) { |
48
b2724c711203
highlighter now use the UcxBuffer API for writing to the destination buffer
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
50 | for (int i = 0 ; i < s.length ; i++) { |
b2724c711203
highlighter now use the UcxBuffer API for writing to the destination buffer
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
51 | put_htmlescaped(dest, s.ptr[i]); |
b2724c711203
highlighter now use the UcxBuffer API for writing to the destination buffer
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
52 | } |
21 | 53 | } |
54 | ||
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
55 | static int check_keyword(sstr_t word, const char** keywords) { |
21 | 56 | for (int i = 0 ; keywords[i] ; i++) { |
47
c39ecbbca7c0
words (token) are now stored as sstr_t
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
57 | if (sstrcmp(word, sstr((char*)keywords[i])) == 0) { |
21 | 58 | return 1; |
59 | } | |
60 | } | |
61 | return 0; | |
62 | } | |
63 | ||
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
64 | static int check_capsonly(sstr_t word) { |
47
c39ecbbca7c0
words (token) are now stored as sstr_t
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
65 | for (size_t i = 0 ; i < word.length ; i++) { |
c39ecbbca7c0
words (token) are now stored as sstr_t
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
66 | if (!isupper(word.ptr[i]) && !isdigit(word.ptr[i]) |
c39ecbbca7c0
words (token) are now stored as sstr_t
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
67 | && word.ptr[i] != '_') { |
21 | 68 | return 0; |
69 | } | |
70 | } | |
71 | return 1; | |
72 | } | |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
73 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
74 | /* Plaintext Highlighter */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
75 | |
57
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
76 | void c2html_plain_highlighter(char *src, UcxBuffer *dest, |
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
77 | c2html_highlighter_data *hd) { |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
78 | while (*src && *src != '\n') { |
57
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
79 | if (*src != '\r') { |
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
80 | put_htmlescaped(dest, *src); |
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
81 | } |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
82 | src++; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
83 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
84 | ucx_buffer_putc(dest, '\n'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
85 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
86 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
87 | /* C Highlighter */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
88 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
89 | static const char* ckeywords[] = { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
90 | "auto", "break", "case", "char", "const", "continue", "default", "do", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
91 | "double", "else", "enum", "extern", "float", "for", "goto", "if", "int", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
92 | "long", "register", "return", "short", "signed", "sizeof", "static", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
93 | "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
94 | "while", NULL |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
95 | }; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
96 | |
57
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
97 | void c2html_c_highlighter(char *src, UcxBuffer *dest, |
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
98 | c2html_highlighter_data *hd) { |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
99 | /* reset buffers without clearing them */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
100 | hd->primary_buffer->size = hd->primary_buffer->pos = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
101 | hd->secondary_buffer->size = hd->secondary_buffer->pos = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
102 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
103 | /* alias the buffers for better handling */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
104 | UcxBuffer *wbuf = hd->primary_buffer; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
105 | UcxBuffer *ifilebuf = hd->secondary_buffer; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
106 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
107 | /* local information */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
108 | size_t sp = (size_t)-1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
109 | int isstring = 0, iscomment = 0, isinclude = 0, parseinclude = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
110 | char quote = '\0'; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
111 | int isescaping = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
112 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
113 | /* continue a multi line comment highlighting */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
114 | if (hd->multiline_comment) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
115 | iscomment = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
116 | ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
117 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
118 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
119 | char c; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
120 | do { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
121 | c = src[++sp]; |
57
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
122 | if (c == '\r') continue; |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
123 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
124 | /* comments */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
125 | if (!isstring && c == '/') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
126 | if (hd->multiline_comment && sp > 0 && src[sp-1] == '*') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
127 | iscomment = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
128 | hd->multiline_comment = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
129 | ucx_buffer_puts(dest, "/</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
130 | continue; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
131 | } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
132 | iscomment = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
133 | hd->multiline_comment = (src[sp+1] == '*'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
134 | ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
135 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
136 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
137 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
138 | if (iscomment) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
139 | if (c == '\n') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
140 | ucx_buffer_puts(dest, "</span>\n"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
141 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
142 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
143 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
144 | } else if (isinclude) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
145 | if (c == '<') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
146 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
147 | "<span class=\"c2html-stdinclude\"><"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
148 | } else if (c == '\"') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
149 | if (parseinclude) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
150 | ucx_buffer_puts(dest, "\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
151 | ucx_buffer_write(ifilebuf->space, 1, ifilebuf->size, dest); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
152 | ucx_buffer_puts(dest, "\"</a>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
153 | parseinclude = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
154 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
155 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
156 | "<a class=\"c2html-userinclude\" href=\""); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
157 | ucx_buffer_putc(ifilebuf, '\"'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
158 | parseinclude = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
159 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
160 | } else if (c == '>') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
161 | ucx_buffer_puts(dest, "></span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
162 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
163 | if (parseinclude) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
164 | ucx_buffer_putc(ifilebuf, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
165 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
166 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
167 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
168 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
169 | /* strings */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
170 | if (!isescaping && (c == '\'' || c == '\"')) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
171 | if (isstring) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
172 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
173 | if (c == quote) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
174 | isstring = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
175 | ucx_buffer_puts(dest, "</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
176 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
177 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
178 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
179 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
180 | isstring = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
181 | quote = c; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
182 | ucx_buffer_puts(dest, "<span class=\"c2html-string\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
183 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
184 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
185 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
186 | if (isstring) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
187 | put_htmlescaped(dest, c); |
54
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
188 | } else if (isalnum(c) || c == '_' || c == '#') { |
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
189 | /* buffer the current word */ |
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
190 | ucx_buffer_putc(wbuf, c); |
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
191 | } else { |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
192 | /* write buffered word, if any */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
193 | if (wbuf->size > 0) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
194 | sstr_t word = sstrn(wbuf->space, wbuf->size); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
195 | int closespan = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
196 | sstr_t typesuffix = ST("_t"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
197 | if (check_keyword(word, ckeywords)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
198 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
199 | "<span class=\"c2html-keyword\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
200 | } else if (sstrsuffix(word, typesuffix)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
201 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
202 | "<span class=\"c2html-type\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
203 | } else if (word.ptr[0] == '#') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
204 | isinclude = !sstrcmp(word, S("#include")); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
205 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
206 | "<span class=\"c2html-directive\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
207 | } else if (check_capsonly(word)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
208 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
209 | "<span class=\"c2html-macroconst\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
210 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
211 | closespan = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
212 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
213 | put_htmlescapedstr(dest, word); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
214 | if (closespan) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
215 | ucx_buffer_puts(dest, "</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
216 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
217 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
218 | wbuf->pos = wbuf->size = 0; /* reset word buffer */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
219 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
220 | /* write current character */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
221 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
222 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
223 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
224 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
225 | isescaping = !isescaping & (c == '\\'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
226 | } |
54
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
227 | } while (c && c != '\n'); |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
228 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
229 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
230 | /* Java Highlighter */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
231 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
232 | static const char* jkeywords[] = { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
233 | "abstract", "continue", "for", "new", "switch", "assert", "default", "goto", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
234 | "package", "synchronized", "boolean", "do", "if", "private", "this", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
235 | "break", "double", "implements", "protected", "throw", "byte", "else", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
236 | "import", "public", "throws", "case", "enum", "instanceof", "return", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
237 | "transient", "catch", "extends", "int", "short", "try", "char", "final", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
238 | "interface", "static", "void", "class", "finally", "long", "strictfp", |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
239 | "volatile", "const", "float", "native", "super", "while", NULL |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
240 | }; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
241 | |
57
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
242 | void c2html_java_highlighter(char *src, UcxBuffer *dest, |
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
243 | c2html_highlighter_data *hd) { |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
244 | /* reset buffers without clearing them */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
245 | hd->primary_buffer->size = hd->primary_buffer->pos = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
246 | hd->secondary_buffer->size = hd->secondary_buffer->pos = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
247 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
248 | /* alias the buffers for better handling */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
249 | UcxBuffer *wbuf = hd->primary_buffer; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
250 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
251 | /* local information */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
252 | size_t sp = (size_t)-1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
253 | int isstring = 0, iscomment = 0, isimport = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
254 | char quote = '\0'; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
255 | int isescaping = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
256 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
257 | if (hd->multiline_comment) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
258 | iscomment = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
259 | ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
260 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
261 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
262 | char c; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
263 | do { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
264 | c = src[++sp]; |
57
eba880c1705c
improves API and adds functions for strings
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
265 | if (c == '\r') continue; |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
266 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
267 | /* comments */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
268 | if (!isstring && c == '/') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
269 | if (hd->multiline_comment && sp > 0 && src[sp-1] == '*') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
270 | iscomment = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
271 | hd->multiline_comment = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
272 | ucx_buffer_puts(dest, "/</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
273 | continue; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
274 | } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
275 | iscomment = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
276 | hd->multiline_comment = (src[sp+1] == '*'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
277 | ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
278 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
279 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
280 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
281 | if (iscomment) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
282 | if (c == '\n') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
283 | ucx_buffer_puts(dest, "</span>\n"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
284 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
285 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
286 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
287 | } else if (isimport) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
288 | /* TODO: local imports */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
289 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
290 | /* strings */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
291 | if (!isescaping && (c == '\'' || c == '\"')) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
292 | if (isstring) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
293 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
294 | if (c == quote) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
295 | isstring = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
296 | ucx_buffer_puts(dest, "</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
297 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
298 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
299 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
300 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
301 | isstring = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
302 | quote = c; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
303 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
304 | "<span class=\"c2html-string\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
305 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
306 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
307 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
308 | if (isstring) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
309 | put_htmlescaped(dest, c); |
54
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
310 | } else if (isalnum(c) || c == '_' || c == '@') { |
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
311 | /* buffer the current word */ |
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
312 | ucx_buffer_putc(wbuf, c); |
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
313 | } else { |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
314 | /* write buffered word, if any */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
315 | if (wbuf->size > 0) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
316 | sstr_t word = sstrn(wbuf->space, wbuf->size); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
317 | int closespan = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
318 | if (check_keyword(word, jkeywords)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
319 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
320 | "<span class=\"c2html-keyword\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
321 | } else if (isupper(word.ptr[0])) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
322 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
323 | "<span class=\"c2html-type\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
324 | } else if (word.ptr[0] == '@') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
325 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
326 | "<span class=\"c2html-directive\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
327 | } else if (check_capsonly(word)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
328 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
329 | "<span class=\"c2html-macroconst\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
330 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
331 | closespan = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
332 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
333 | put_htmlescapedstr(dest, word); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
334 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
335 | if (closespan) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
336 | ucx_buffer_puts(dest, "</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
337 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
338 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
339 | wbuf->pos = wbuf->size = 0; /* reset buffer */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
340 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
341 | /* write current character */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
342 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
343 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
344 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
345 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
346 | isescaping = !isescaping & (c == '\\'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
347 | } |
54
b3f24e23bc25
highlighter can now handle files which do not end with a blank line
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
348 | } while (c && c != '\n'); |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
349 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
350 |