Wed, 31 Aug 2016 12:58:48 +0200
highlighter can now handle files which do not end with a blank line
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 | |
51
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
32 | HighlighterData* new_highlighter_data() { |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
33 | HighlighterData* hd = malloc(sizeof(HighlighterData)); |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
34 | if (hd == NULL) { |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
35 | return NULL; |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
36 | } else { |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
37 | hd->multiline_comment = 0; |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
38 | hd->primary_buffer = ucx_buffer_new(NULL, 256, UCX_BUFFER_AUTOEXTEND); |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
39 | hd->secondary_buffer = ucx_buffer_new(NULL, 32, UCX_BUFFER_AUTOEXTEND); |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
40 | return hd; |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
41 | } |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
42 | } |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
43 | |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
44 | void free_highlighter_data(HighlighterData *hd) { |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
45 | ucx_buffer_free(hd->primary_buffer); |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
46 | ucx_buffer_free(hd->secondary_buffer); |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
47 | free(hd); |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
48 | } |
f25ba6fd7a08
replaces stack buffers with UCX buffers
Mike Becker <universe@uap-core.de>
parents:
49
diff
changeset
|
49 | |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
50 | static void put_htmlescaped(UcxBuffer *dest, char c) { |
21 | 51 | 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
|
52 | ucx_buffer_puts(dest, ">"); |
21 | 53 | } 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
|
54 | 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
|
55 | } 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
|
56 | ucx_buffer_putc(dest, c); |
21 | 57 | } |
48
b2724c711203
highlighter now use the UcxBuffer API for writing to the destination buffer
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
58 | } |
21 | 59 | |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
60 | 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
|
61 | 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
|
62 | 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
|
63 | } |
21 | 64 | } |
65 | ||
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
66 | static int check_keyword(sstr_t word, const char** keywords) { |
21 | 67 | 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
|
68 | if (sstrcmp(word, sstr((char*)keywords[i])) == 0) { |
21 | 69 | return 1; |
70 | } | |
71 | } | |
72 | return 0; | |
73 | } | |
74 | ||
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
75 | 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
|
76 | 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
|
77 | 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
|
78 | && word.ptr[i] != '_') { |
21 | 79 | return 0; |
80 | } | |
81 | } | |
82 | return 1; | |
83 | } | |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
84 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
85 | /* Plaintext Highlighter */ |
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 | void plain_highlighter(char *src, UcxBuffer *dest, HighlighterData *hd) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
88 | while (*src && *src != '\n') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
89 | put_htmlescaped(dest, *src); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
90 | src++; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
91 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
92 | ucx_buffer_putc(dest, '\n'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
93 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
94 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
95 | /* C Highlighter */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
96 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
97 | static const char* ckeywords[] = { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
98 | "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
|
99 | "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
|
100 | "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
|
101 | "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
|
102 | "while", NULL |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
103 | }; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
104 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
105 | void c_highlighter(char *src, UcxBuffer *dest, HighlighterData *hd) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
106 | /* reset buffers without clearing them */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
107 | 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
|
108 | 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
|
109 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
110 | /* 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
|
111 | UcxBuffer *wbuf = hd->primary_buffer; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
112 | UcxBuffer *ifilebuf = hd->secondary_buffer; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
113 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
114 | /* local information */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
115 | 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
|
116 | 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
|
117 | char quote = '\0'; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
118 | int isescaping = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
119 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
120 | /* 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
|
121 | if (hd->multiline_comment) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
122 | iscomment = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
123 | 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
|
124 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
125 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
126 | char c; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
127 | do { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
128 | c = src[++sp]; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
129 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
130 | /* comments */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
131 | if (!isstring && c == '/') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
132 | 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
|
133 | iscomment = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
134 | hd->multiline_comment = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
135 | ucx_buffer_puts(dest, "/</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
136 | continue; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
137 | } 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
|
138 | iscomment = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
139 | 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
|
140 | 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
|
141 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
142 | } |
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 | if (iscomment) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
145 | if (c == '\n') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
146 | 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
|
147 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
148 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
149 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
150 | } else if (isinclude) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
151 | if (c == '<') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
152 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
153 | "<span class=\"c2html-stdinclude\"><"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
154 | } else if (c == '\"') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
155 | if (parseinclude) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
156 | ucx_buffer_puts(dest, "\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
157 | 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
|
158 | ucx_buffer_puts(dest, "\"</a>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
159 | parseinclude = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
160 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
161 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
162 | "<a class=\"c2html-userinclude\" href=\""); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
163 | ucx_buffer_putc(ifilebuf, '\"'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
164 | parseinclude = 1; |
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 | } else if (c == '>') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
167 | ucx_buffer_puts(dest, "></span>"); |
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 | if (parseinclude) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
170 | ucx_buffer_putc(ifilebuf, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
171 | } |
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 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
174 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
175 | /* strings */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
176 | if (!isescaping && (c == '\'' || c == '\"')) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
177 | if (isstring) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
178 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
179 | if (c == quote) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
180 | isstring = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
181 | ucx_buffer_puts(dest, "</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
182 | } else { |
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 | isstring = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
187 | quote = c; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
188 | 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
|
189 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
190 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
191 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
192 | if (isstring) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
193 | 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
|
194 | } 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
|
195 | /* 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
|
196 | 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
|
197 | } else { |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
198 | /* write buffered word, if any */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
199 | if (wbuf->size > 0) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
200 | 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
|
201 | int closespan = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
202 | sstr_t typesuffix = ST("_t"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
203 | if (check_keyword(word, ckeywords)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
204 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
205 | "<span class=\"c2html-keyword\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
206 | } else if (sstrsuffix(word, typesuffix)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
207 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
208 | "<span class=\"c2html-type\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
209 | } else if (word.ptr[0] == '#') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
210 | isinclude = !sstrcmp(word, S("#include")); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
211 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
212 | "<span class=\"c2html-directive\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
213 | } else if (check_capsonly(word)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
214 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
215 | "<span class=\"c2html-macroconst\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
216 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
217 | closespan = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
218 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
219 | put_htmlescapedstr(dest, word); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
220 | if (closespan) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
221 | ucx_buffer_puts(dest, "</span>"); |
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 | 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
|
225 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
226 | /* write current character */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
227 | put_htmlescaped(dest, c); |
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 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
231 | isescaping = !isescaping & (c == '\\'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
232 | } |
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
|
233 | } while (c && c != '\n'); |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
234 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
235 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
236 | /* Java Highlighter */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
237 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
238 | static const char* jkeywords[] = { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
239 | "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
|
240 | "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
|
241 | "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
|
242 | "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
|
243 | "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
|
244 | "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
|
245 | "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
|
246 | }; |
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 | void java_highlighter(char *src, UcxBuffer *dest, HighlighterData *hd) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
249 | /* reset buffers without clearing them */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
250 | 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
|
251 | 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
|
252 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
253 | /* 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
|
254 | UcxBuffer *wbuf = hd->primary_buffer; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
255 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
256 | /* local information */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
257 | 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
|
258 | 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
|
259 | char quote = '\0'; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
260 | int isescaping = 0; |
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 | if (hd->multiline_comment) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
263 | iscomment = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
264 | 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
|
265 | } |
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 | char c; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
268 | do { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
269 | c = src[++sp]; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
270 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
271 | /* comments */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
272 | if (!isstring && c == '/') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
273 | 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
|
274 | iscomment = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
275 | hd->multiline_comment = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
276 | ucx_buffer_puts(dest, "/</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
277 | continue; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
278 | } 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
|
279 | iscomment = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
280 | 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
|
281 | 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
|
282 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
283 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
284 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
285 | if (iscomment) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
286 | if (c == '\n') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
287 | 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
|
288 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
289 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
290 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
291 | } else if (isimport) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
292 | /* TODO: local imports */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
293 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
294 | /* strings */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
295 | if (!isescaping && (c == '\'' || c == '\"')) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
296 | if (isstring) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
297 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
298 | if (c == quote) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
299 | isstring = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
300 | ucx_buffer_puts(dest, "</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
301 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
302 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
303 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
304 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
305 | isstring = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
306 | quote = c; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
307 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
308 | "<span class=\"c2html-string\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
309 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
310 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
311 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
312 | if (isstring) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
313 | 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
|
314 | } 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
|
315 | /* 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
|
316 | 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
|
317 | } else { |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
318 | /* write buffered word, if any */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
319 | if (wbuf->size > 0) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
320 | 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
|
321 | int closespan = 1; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
322 | if (check_keyword(word, jkeywords)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
323 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
324 | "<span class=\"c2html-keyword\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
325 | } 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
|
326 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
327 | "<span class=\"c2html-type\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
328 | } else if (word.ptr[0] == '@') { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
329 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
330 | "<span class=\"c2html-directive\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
331 | } else if (check_capsonly(word)) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
332 | ucx_buffer_puts(dest, |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
333 | "<span class=\"c2html-macroconst\">"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
334 | } else { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
335 | closespan = 0; |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
336 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
337 | put_htmlescapedstr(dest, word); |
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 | if (closespan) { |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
340 | ucx_buffer_puts(dest, "</span>"); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
341 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
342 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
343 | 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
|
344 | |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
345 | /* write current character */ |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
346 | put_htmlescaped(dest, c); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
347 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
348 | } |
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 | isescaping = !isescaping & (c == '\\'); |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
351 | } |
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
|
352 | } while (c && c != '\n'); |
52
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
353 | } |
33ded421c512
merges all highlighter functions into one highlighter module
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
354 |