libt3highlight
 All Data Structures Functions Variables Typedefs Enumerator Groups Pages
highlight.h
1 /* Copyright (C) 2011-2012 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 #ifndef T3_HIGHLIGHT_H
15 #define T3_HIGHLIGHT_H
16 
17 #include <t3config/config.h>
18 #include <t3highlight/highlight_api.h>
19 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
41 #define T3_HIGHLIGHT_VERSION 0
42 
46 #define T3_ERR_INVALID_FORMAT (-96)
47 
48 #define T3_ERR_INVALID_REGEX (-95)
49 
50 #define T3_ERR_NO_SYNTAX (-94)
51 
52 #define T3_ERR_UNDEFINED_USE (-93)
53 
54 #define T3_ERR_INVALID_NAME (-92)
55 
56 #define T3_ERR_EMPTY_START_CYCLE (-91)
57 
58 #define T3_ERR_USE_CYCLE (-90)
59 
64 #define T3_HIGHLIGHT_UTF8 (1<<0)
65 
75 #define T3_HIGHLIGHT_UTF8_NOCHECK (1<<1)
76 
77 #define T3_HIGHLIGHT_USE_PATH (1<<2)
78 
79 #define T3_HIGHLIGHT_VERBOSE_ERROR (1<<3)
80 
86 typedef struct t3_highlight_t t3_highlight_t;
91 
95 typedef struct {
96  char *name;
97  char *lang_file;
99 
104 typedef struct {
105  int error;
107  char *file_name;
109  char *extra;
112 
119 T3_HIGHLIGHT_API t3_highlight_lang_t *t3_highlight_list(int flags, t3_highlight_error_t *error);
123 T3_HIGHLIGHT_API void t3_highlight_free_list(t3_highlight_lang_t *list);
124 
139 T3_HIGHLIGHT_API t3_highlight_t *t3_highlight_load(const char *name,
140  int (*map_style)(void *, const char *), void *map_style_data, int flags, t3_highlight_error_t *error);
154 T3_HIGHLIGHT_API t3_highlight_t *t3_highlight_load_by_filename(const char *name,
155  int (*map_style)(void *, const char *), void *map_style_data, int flags, t3_highlight_error_t *error);
167 T3_HIGHLIGHT_API t3_highlight_t *t3_highlight_load_by_langname(const char *name,
168  int (*map_style)(void *, const char *), void *map_style_data, int flags, t3_highlight_error_t *error);
181 T3_HIGHLIGHT_API t3_highlight_t *t3_highlight_load_by_detect(const char *line, size_t line_length, t3_bool first,
182  int (*map_style)(void *, const char *), void *map_style_data, int flags, t3_highlight_error_t *error);
183 
196 T3_HIGHLIGHT_API t3_highlight_t *t3_highlight_new(t3_config_t *syntax,
197  int (*map_style)(void *, const char *), void *map_style_data, int flags, t3_highlight_error_t *error);
198 
202 T3_HIGHLIGHT_API void t3_highlight_free(t3_highlight_t *highlight);
203 
205 T3_HIGHLIGHT_API const char *t3_highlight_get_langfile(const t3_highlight_t *highlight);
206 
245 T3_HIGHLIGHT_API t3_bool t3_highlight_match(t3_highlight_match_t *match, const char *str, size_t size);
246 
253 T3_HIGHLIGHT_API t3_highlight_match_t *t3_highlight_new_match(const t3_highlight_t *highlight);
257 T3_HIGHLIGHT_API void t3_highlight_free_match(t3_highlight_match_t *match);
266 T3_HIGHLIGHT_API void t3_highlight_reset(t3_highlight_match_t *match, int state);
270 T3_HIGHLIGHT_API size_t t3_highlight_get_start(t3_highlight_match_t *match);
272 T3_HIGHLIGHT_API size_t t3_highlight_get_match_start(t3_highlight_match_t *match);
274 T3_HIGHLIGHT_API size_t t3_highlight_get_end(t3_highlight_match_t *match);
276 T3_HIGHLIGHT_API int t3_highlight_get_begin_attr(t3_highlight_match_t *match);
278 T3_HIGHLIGHT_API int t3_highlight_get_match_attr(t3_highlight_match_t *match);
280 T3_HIGHLIGHT_API int t3_highlight_get_state(t3_highlight_match_t *match);
282 T3_HIGHLIGHT_API int t3_highlight_next_line(t3_highlight_match_t *match);
283 
288 T3_HIGHLIGHT_API const char *t3_highlight_strerror(int error);
289 
298 T3_HIGHLIGHT_API long t3_highlight_get_version(void);
299 
311 T3_HIGHLIGHT_API t3_bool t3_highlight_utf8check(const char *line, size_t size);
312 
328 T3_HIGHLIGHT_API char *t3_highlight_detect(const char *line, size_t line_length, t3_bool first,
329  int flags, t3_highlight_error_t *error);
330 
331 #ifdef __cplusplus
332 } /* extern "C" */
333 #endif
334 
335 #endif