This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
/
h_msg.cpp
150 lines (142 loc) · 5.07 KB
/
h_msg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* h_msg.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#ifdef CONFIG_HILIT_MSG
#define hsMSG_Normal 0
#define hsMSG_Header 1
#define hsMSG_Quote 2
#define hsMSG_Tag 3
#define hsMSG_Control 4
int Hilit_MSG(EBuffer *BF, int /*LN*/, PCell B, int Pos, int Width, ELine* Line, hlState& State, hsState *StateMap, int *ECol) {
ChColor *Colors = BF->Mode->fColorize->Colors;
HILIT_VARS(Colors[CLR_Normal], Line);
int is_head = 0, is_quote = 0, is_space = 0, is_tag = 0, is_control = 0;
if (Line->Count > 0) {
if (State == hsMSG_Header) {
if (Line->Chars[0] == ' ' || Line->Chars[0] == '\t') is_head = 1;
else
State = hsMSG_Normal;
}
if (State == hsMSG_Normal) {
if (Line->Count >= 2 &&
Line->Chars[0] == '-' &&
Line->Chars[1] == '-' &&
(Line->Count == 2 || Line->Chars[2] == ' '))
is_tag = 1;
else if (Line->Count >= 2 &&
Line->Chars[0] == '.' &&
Line->Chars[1] == '.' &&
(Line->Count == 2 || Line->Chars[2] == ' '))
is_tag = 1;
else if (Line->Count >= 3 &&
Line->Chars[0] == '-' &&
Line->Chars[1] == '-' &&
Line->Chars[2] == '-' &&
(Line->Count == 3 || Line->Chars[3] == ' '))
is_tag = 1;
else if (Line->Count >= 3 &&
Line->Chars[0] == '.' &&
Line->Chars[1] == '.' &&
Line->Chars[2] == '.' &&
(Line->Count == 3 || Line->Chars[3] == ' '))
is_tag = 1;
else if (Line->Count > 10 && memcmp(Line->Chars, " * Origin:", 10) == 0)
is_control = 1;
else if (Line->Count > 0 && Line->Chars[0] == '\x01')
is_control = 1;
else for (i = 0; i < Line->Count; i++) {
if (i < 30 && Line->Chars[i] == ':' && i < Line->Count - 1 && Line->Chars[i+1] == ' ' && !is_space) { is_head = 1; break; }
else if (i < 5 && Line->Chars[i] == '>') { is_quote = 1; break; }
else if (Line->Chars[i] == '<' ||
(Line->Chars[i] == ' ' && i > 0) ||
Line->Chars[i] == '\t') break;
else if (Line->Chars[i] == ' ' || Line->Chars[i] == '\t')
is_space = 0;
}
}
}
if (is_head) {
State = hsMSG_Header;
Color = Colors[CLR_Header];
} else if (is_quote) {
State = hsMSG_Quote;
Color = Colors[CLR_Quotes];
} else if (is_tag) {
State = hsMSG_Tag;
Color = Colors[CLR_Tag];
} else if (is_control) {
State = hsMSG_Control;
Color = Colors[CLR_Control];
} else {
State = hsMSG_Normal;
Color = Colors[CLR_Normal];
}
ChColor DefColor = Color;
#ifdef CONFIG_WORD_HILIT
int j = 0;
if (BF->Mode->fColorize->Keywords.TotalCount > 0 ||
BF->WordCount > 0)
{ /* words have to be hilited, go slow */
for(i = 0; i < Line->Count;) {
IF_TAB() else {
if (isalpha(*p) || (*p == '_')) {
j = 0;
while (((i + j) < Line->Count) &&
(isalnum(Line->Chars[i+j]) ||
(Line->Chars[i + j] == '_'))
) j++;
if (BF->GetHilitWord(j, Line->Chars + i, Color, 1)) ;
else {
Color = DefColor;
}
if (StateMap)
memset(StateMap + i, State, j);
if (B)
MoveMem(B, C - Pos, Width, Line->Chars + i, Color, j);
i += j;
len -= j;
p += j;
C += j;
Color = DefColor;
continue;
}
ColorNext();
continue;
}
}
} else
#endif
if (ExpandTabs) { /* use slow mode */
for (i = 0; i < Line->Count;) {
IF_TAB() else {
ColorNext();
}
}
} else { /* fast mode */
if (Pos < Line->Count) {
if (Pos + Width < Line->Count) {
if (B)
MoveMem(B, 0, Width, Line->Chars + Pos, Color, Width);
if (StateMap)
memset(StateMap, State, Line->Count);
} else {
if (B)
MoveMem(B, 0, Width, Line->Chars + Pos, Color, Line->Count - Pos);
if (StateMap)
memset(StateMap, State, Line->Count);
}
}
C = Line->Count;
}
if (State != hsMSG_Header)
State = hsMSG_Normal;
*ECol = C;
return 0;
}
#endif