]>
Commit | Line | Data |
---|---|---|
8e54aaed RD |
1 | // Scintilla source code edit control |
2 | /** @file LexMPT.cxx | |
3 | ** Lexer for MPT specific files. Based on LexOthers.cxx | |
4 | ** LOT = the text log file created by the MPT application while running a test program | |
5 | ** Other MPT specific files to be added later. | |
6 | **/ | |
7 | // Copyright 2003 by Marius Gheorghe <mgheorghe@cabletest.com> | |
8 | // The License.txt file describes the conditions under which this software may be distributed. | |
9 | ||
10 | #include <string.h> | |
11 | #include <stdio.h> | |
12 | #include <ctype.h> | |
13 | #include <stdlib.h> | |
14 | #include "Platform.h" | |
15 | ||
16 | #include "PropSet.h" | |
17 | #include "Accessor.h" | |
18 | #include "KeyWords.h" | |
19 | #include "Scintilla.h" | |
20 | #include "SciLexer.h" | |
21 | #include "SString.h" | |
22 | ||
7e0c58e9 RD |
23 | #ifdef SCI_NAMESPACE |
24 | using namespace Scintilla; | |
25 | #endif | |
26 | ||
8e54aaed RD |
27 | static int GetLotLineState(SString &line) { |
28 | if (line.length()) { | |
29 | // Most of the time the first non-blank character in line determines that line's type | |
30 | // Now finds the first non-blank character | |
31 | unsigned i; // Declares counter here to make it persistent after the for loop | |
32 | for (i = 0; i < line.length(); ++i) { | |
33 | if (!isspace(line[i])) | |
34 | break; | |
35 | } | |
36 | ||
37 | // Checks if it was a blank line | |
38 | if (i == line.length()) | |
39 | return SCE_LOT_DEFAULT; | |
40 | ||
41 | switch (line[i]) { | |
42 | case '*': // Fail measurement | |
43 | return SCE_LOT_FAIL; | |
44 | ||
45 | case '+': // Header | |
46 | case '|': // Header | |
47 | return SCE_LOT_HEADER; | |
48 | ||
49 | case ':': // Set test limits | |
50 | return SCE_LOT_SET; | |
51 | ||
52 | case '-': // Section break | |
53 | return SCE_LOT_BREAK; | |
54 | ||
55 | default: // Any other line | |
56 | // Checks for message at the end of lot file | |
57 | if (line.contains("PASSED")) { | |
58 | return SCE_LOT_PASS; | |
59 | } | |
60 | else if (line.contains("FAILED")) { | |
61 | return SCE_LOT_FAIL; | |
62 | } | |
63 | else if (line.contains("ABORTED")) { | |
64 | return SCE_LOT_ABORT; | |
65 | } | |
66 | else { | |
67 | return i ? SCE_LOT_PASS : SCE_LOT_DEFAULT; | |
68 | } | |
69 | } | |
70 | } | |
71 | else { | |
72 | return SCE_LOT_DEFAULT; | |
73 | } | |
74 | } | |
75 | ||
76 | static void ColourizeLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) { | |
77 | styler.StartAt(startPos); | |
78 | styler.StartSegment(startPos); | |
79 | bool atLineStart = true;// Arms the 'at line start' flag | |
80 | char chNext = styler.SafeGetCharAt(startPos); | |
81 | SString line(""); | |
82 | line.setsizegrowth(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations | |
83 | ||
84 | // Styles LOT document | |
85 | unsigned int i; // Declared here because it's used after the for loop | |
86 | for (i = startPos; i < startPos + length; ++i) { | |
87 | char ch = chNext; | |
88 | chNext = styler.SafeGetCharAt(i + 1); | |
89 | line += ch; | |
90 | atLineStart = false; | |
91 | ||
92 | // LOT files are only used on the Win32 platform, thus EOL == CR+LF | |
93 | // Searches for the end of line | |
94 | if (ch == '\r' && chNext == '\n') { | |
95 | line += chNext; // Gets the '\n' | |
96 | ++i; // Advances past the '\n' | |
97 | chNext = styler.SafeGetCharAt(i + 1); // Gets character of next line | |
98 | styler.ColourTo(i, GetLotLineState(line)); | |
99 | line = ""; | |
100 | atLineStart = true; // Arms flag for next line | |
101 | } | |
102 | } | |
103 | ||
104 | // Last line may not have a line ending | |
105 | if (!atLineStart) { | |
106 | styler.ColourTo(i - 1, GetLotLineState(line)); | |
107 | } | |
108 | } | |
109 | ||
110 | // Folds an MPT LOT file: the blocks that can be folded are: | |
111 | // sections (headed by a set line) | |
112 | // passes (contiguous pass results within a section) | |
113 | // fails (contiguous fail results within a section) | |
114 | static void FoldLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) { | |
115 | bool foldCompact = styler.GetPropertyInt("fold.compact", 0) != 0; | |
116 | unsigned int endPos = startPos + length; | |
117 | int visibleChars = 0; | |
118 | int lineCurrent = styler.GetLine(startPos); | |
119 | ||
120 | char chNext = styler.SafeGetCharAt(startPos); | |
121 | int style = SCE_LOT_DEFAULT; | |
122 | int styleNext = styler.StyleAt(startPos); | |
123 | int lev = SC_FOLDLEVELBASE; | |
124 | ||
125 | // Gets style of previous line if not at the beginning of the document | |
126 | if (startPos > 1) | |
127 | style = styler.StyleAt(startPos - 2); | |
128 | ||
129 | for (unsigned int i = startPos; i < endPos; i++) { | |
130 | char ch = chNext; | |
131 | chNext = styler.SafeGetCharAt(i + 1); | |
132 | ||
133 | if (ch == '\r' && chNext == '\n') { | |
134 | // TO DO: | |
135 | // Should really get the state of the previous line from the styler | |
136 | int stylePrev = style; | |
137 | style = styleNext; | |
138 | styleNext = styler.StyleAt(i + 2); | |
139 | ||
140 | switch (style) { | |
141 | /* | |
142 | case SCE_LOT_SET: | |
143 | lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG; | |
144 | break; | |
145 | */ | |
146 | case SCE_LOT_FAIL: | |
147 | /* | |
148 | if (stylePrev != SCE_LOT_FAIL) | |
149 | lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG; | |
150 | else | |
151 | lev = SC_FOLDLEVELBASE + 1; | |
152 | */ | |
153 | lev = SC_FOLDLEVELBASE; | |
154 | break; | |
155 | ||
156 | default: | |
157 | if (lineCurrent == 0 || stylePrev == SCE_LOT_FAIL) | |
158 | lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG; | |
159 | else | |
160 | lev = SC_FOLDLEVELBASE + 1; | |
161 | ||
162 | if (visibleChars == 0 && foldCompact) | |
163 | lev |= SC_FOLDLEVELWHITEFLAG; | |
164 | break; | |
165 | } | |
166 | ||
167 | if (lev != styler.LevelAt(lineCurrent)) | |
168 | styler.SetLevel(lineCurrent, lev); | |
169 | ||
170 | lineCurrent++; | |
171 | visibleChars = 0; | |
172 | } | |
173 | ||
174 | if (!isspacechar(ch)) | |
175 | visibleChars++; | |
176 | } | |
177 | ||
178 | int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; | |
179 | styler.SetLevel(lineCurrent, lev | flagsNext); | |
180 | } | |
181 | ||
182 | static const char * const emptyWordListDesc[] = { | |
183 | 0 | |
184 | }; | |
185 | ||
186 | LexerModule lmLot(SCLEX_LOT, ColourizeLotDoc, "lot", FoldLotDoc, emptyWordListDesc); |