libt3highlight
/home/gertjan/projects/tilde/highlight/src/internal.h
00001 /* Copyright (C) 2011-2012 G.P. Halkes
00002    This program is free software: you can redistribute it and/or modify
00003    it under the terms of the GNU General Public License version 3, as
00004    published by the Free Software Foundation.
00005 
00006    This program is distributed in the hope that it will be useful,
00007    but WITHOUT ANY WARRANTY; without even the implied warranty of
00008    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00009    GNU General Public License for more details.
00010 
00011    You should have received a copy of the GNU General Public License
00012    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00013 */
00014 #ifndef INTERNAL_H
00015 #define INTERNAL_H
00016 
00017 #include <pcre.h>
00018 #include "highlight_api.h"
00019 #include "vector.h"
00020 
00021 #define NO_CHANGE (-1)
00022 /* EXIT_STATE is equal to exit = 1. For higher values of the exit attribute,
00023    subtract from EXIT_STATE. I.e. -3 equals exit = 2, -4 equals exit = 3, etc. */
00024 #define EXIT_STATE (-2)
00025 
00026 typedef struct {
00027         pcre *regex;
00028         pcre_extra *extra;
00029 } full_pcre_t;
00030 
00031 typedef struct {
00032         char *end_pattern;
00033         int state;
00034 } on_entry_info_t;
00035 
00036 typedef struct {
00037         char *name;
00038         char *pattern;
00039         on_entry_info_t *on_entry;
00040         int on_entry_cnt;
00041 } dynamic_highlight_t;
00042 
00043 typedef struct {
00044         full_pcre_t regex;
00045         dynamic_highlight_t *dynamic; /* Only set for start patterns. */
00046         int next_state, /* Values: NO_CHANGE, EXIT_STATE or smaller,  or a value >= 0. */
00047                 attribute_idx;
00048 } highlight_t;
00049 
00050 typedef struct {
00051         VECTOR(highlight_t, highlights);
00052         int attribute_idx;
00053 } state_t;
00054 
00055 typedef struct {
00056         full_pcre_t regex;
00057         char *extracted;
00058         int extracted_length;
00059 } dynamic_state_t;
00060 
00061 typedef struct {
00062         int parent;
00063         int highlight;
00064         dynamic_state_t *dynamic;
00065 } state_mapping_t;
00066 
00067 struct t3_highlight_t {
00068         VECTOR(state_t, states);
00069         char *lang_file;
00070         int flags;
00071 };
00072 
00073 #define RETURN_ERROR_FULL(_error, _line_number, _file_name, _extra, _flags) do { \
00074         if (error != NULL) { \
00075                 error->error = (_error); \
00076                 if (_flags & T3_HIGHLIGHT_VERBOSE_ERROR) { \
00077                         error->line_number = _line_number; \
00078                         error->file_name = _file_name; \
00079                         error->extra = _extra; \
00080                 } \
00081         } \
00082         goto return_error; \
00083 } while (0)
00084 #define RETURN_ERROR(_error, _flags) RETURN_ERROR_FULL(_error, 0, NULL, NULL, _flags)
00085 
00086 
00087 T3_HIGHLIGHT_LOCAL char *_t3_highlight_strdup(const char *str);
00088 #endif
 All Data Structures Variables