File src/escape.c changed (mode: 100644) (index 5d820c7b0..0d28a59cb) |
... |
... |
esc_highlight_pattern(const char line[], const regex_t *re) |
105 |
105 |
const size_t len = strlen(line); |
const size_t len = strlen(line); |
106 |
106 |
|
|
107 |
107 |
int *const offsets = malloc(sizeof(int)*(len + 1)); |
int *const offsets = malloc(sizeof(int)*(len + 1)); |
108 |
|
int noffsets = 0; |
|
109 |
108 |
|
|
110 |
109 |
char *const no_esc = malloc(len + 1); |
char *const no_esc = malloc(len + 1); |
111 |
110 |
char *no_esc_sym = no_esc; |
char *no_esc_sym = no_esc; |
|
111 |
|
int no_esc_sym_pos = 0; |
112 |
112 |
|
|
113 |
113 |
/* Fill no_esc and offsets. */ |
/* Fill no_esc and offsets. */ |
114 |
114 |
const char *src_sym = line; |
const char *src_sym = line; |
|
... |
... |
esc_highlight_pattern(const char line[], const regex_t *re) |
117 |
117 |
const size_t char_width_esc = get_char_width_esc(src_sym); |
const size_t char_width_esc = get_char_width_esc(src_sym); |
118 |
118 |
if(*src_sym != '\033') |
if(*src_sym != '\033') |
119 |
119 |
{ |
{ |
120 |
|
offsets[noffsets++] = src_sym - line; |
|
|
120 |
|
int i; |
|
121 |
|
const int offset = src_sym - line; |
|
122 |
|
/* Each offset value is filled over whole character width. */ |
|
123 |
|
for(i = 0; i < char_width_esc; i++) |
|
124 |
|
{ |
|
125 |
|
offsets[no_esc_sym_pos + i] = offset; |
|
126 |
|
} |
|
127 |
|
no_esc_sym_pos += char_width_esc; |
|
128 |
|
|
121 |
129 |
memcpy(no_esc_sym, src_sym, char_width_esc); |
memcpy(no_esc_sym, src_sym, char_width_esc); |
122 |
130 |
no_esc_sym += char_width_esc; |
no_esc_sym += char_width_esc; |
123 |
131 |
} |
} |
124 |
132 |
src_sym += char_width_esc; |
src_sym += char_width_esc; |
125 |
133 |
} |
} |
126 |
|
offsets[noffsets++] = src_sym - line; |
|
|
134 |
|
offsets[no_esc_sym_pos] = src_sym - line; |
127 |
135 |
*no_esc_sym = '\0'; |
*no_esc_sym = '\0'; |
|
136 |
|
assert(no_esc_sym_pos == no_esc_sym - no_esc); |
128 |
137 |
|
|
129 |
138 |
processed = add_pattern_highlights(line, len, no_esc, offsets, re); |
processed = add_pattern_highlights(line, len, no_esc, offsets, re); |
130 |
139 |
|
|
|
... |
... |
add_pattern_highlights(const char line[], size_t len, const char no_esc[], |
204 |
213 |
} |
} |
205 |
214 |
|
|
206 |
215 |
/* Corrects offset inside the line so that it points to the char after previous |
/* Corrects offset inside the line so that it points to the char after previous |
207 |
|
* character instead of the beginning of the current one.. */ |
|
|
216 |
|
* character instead of the beginning of the current one. */ |
208 |
217 |
static size_t |
static size_t |
209 |
218 |
correct_offset(const char line[], const int offsets[], size_t offset) |
correct_offset(const char line[], const int offsets[], size_t offset) |
210 |
219 |
{ |
{ |