]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexMPT.cxx
Updated Watcom/OS2 makefiles.
[wxWidgets.git] / contrib / src / stc / scintilla / src / LexMPT.cxx
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
23 static int GetLotLineState(SString &line) {
24 if (line.length()) {
25 // Most of the time the first non-blank character in line determines that line's type
26 // Now finds the first non-blank character
27 unsigned i; // Declares counter here to make it persistent after the for loop
28 for (i = 0; i < line.length(); ++i) {
29 if (!isspace(line[i]))
30 break;
31 }
32
33 // Checks if it was a blank line
34 if (i == line.length())
35 return SCE_LOT_DEFAULT;
36
37 switch (line[i]) {
38 case '*': // Fail measurement
39 return SCE_LOT_FAIL;
40
41 case '+': // Header
42 case '|': // Header
43 return SCE_LOT_HEADER;
44
45 case ':': // Set test limits
46 return SCE_LOT_SET;
47
48 case '-': // Section break
49 return SCE_LOT_BREAK;
50
51 default: // Any other line
52 // Checks for message at the end of lot file
53 if (line.contains("PASSED")) {
54 return SCE_LOT_PASS;
55 }
56 else if (line.contains("FAILED")) {
57 return SCE_LOT_FAIL;
58 }
59 else if (line.contains("ABORTED")) {
60 return SCE_LOT_ABORT;
61 }
62 else {
63 return i ? SCE_LOT_PASS : SCE_LOT_DEFAULT;
64 }
65 }
66 }
67 else {
68 return SCE_LOT_DEFAULT;
69 }
70 }
71
72 static void ColourizeLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
73 styler.StartAt(startPos);
74 styler.StartSegment(startPos);
75 bool atLineStart = true;// Arms the 'at line start' flag
76 char chNext = styler.SafeGetCharAt(startPos);
77 SString line("");
78 line.setsizegrowth(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations
79
80 // Styles LOT document
81 unsigned int i; // Declared here because it's used after the for loop
82 for (i = startPos; i < startPos + length; ++i) {
83 char ch = chNext;
84 chNext = styler.SafeGetCharAt(i + 1);
85 line += ch;
86 atLineStart = false;
87
88 // LOT files are only used on the Win32 platform, thus EOL == CR+LF
89 // Searches for the end of line
90 if (ch == '\r' && chNext == '\n') {
91 line += chNext; // Gets the '\n'
92 ++i; // Advances past the '\n'
93 chNext = styler.SafeGetCharAt(i + 1); // Gets character of next line
94 styler.ColourTo(i, GetLotLineState(line));
95 line = "";
96 atLineStart = true; // Arms flag for next line
97 }
98 }
99
100 // Last line may not have a line ending
101 if (!atLineStart) {
102 styler.ColourTo(i - 1, GetLotLineState(line));
103 }
104 }
105
106 // Folds an MPT LOT file: the blocks that can be folded are:
107 // sections (headed by a set line)
108 // passes (contiguous pass results within a section)
109 // fails (contiguous fail results within a section)
110 static void FoldLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
111 bool foldCompact = styler.GetPropertyInt("fold.compact", 0) != 0;
112 unsigned int endPos = startPos + length;
113 int visibleChars = 0;
114 int lineCurrent = styler.GetLine(startPos);
115
116 char chNext = styler.SafeGetCharAt(startPos);
117 int style = SCE_LOT_DEFAULT;
118 int styleNext = styler.StyleAt(startPos);
119 int lev = SC_FOLDLEVELBASE;
120
121 // Gets style of previous line if not at the beginning of the document
122 if (startPos > 1)
123 style = styler.StyleAt(startPos - 2);
124
125 for (unsigned int i = startPos; i < endPos; i++) {
126 char ch = chNext;
127 chNext = styler.SafeGetCharAt(i + 1);
128
129 if (ch == '\r' && chNext == '\n') {
130 // TO DO:
131 // Should really get the state of the previous line from the styler
132 int stylePrev = style;
133 style = styleNext;
134 styleNext = styler.StyleAt(i + 2);
135
136 switch (style) {
137 /*
138 case SCE_LOT_SET:
139 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
140 break;
141 */
142 case SCE_LOT_FAIL:
143 /*
144 if (stylePrev != SCE_LOT_FAIL)
145 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
146 else
147 lev = SC_FOLDLEVELBASE + 1;
148 */
149 lev = SC_FOLDLEVELBASE;
150 break;
151
152 default:
153 if (lineCurrent == 0 || stylePrev == SCE_LOT_FAIL)
154 lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
155 else
156 lev = SC_FOLDLEVELBASE + 1;
157
158 if (visibleChars == 0 && foldCompact)
159 lev |= SC_FOLDLEVELWHITEFLAG;
160 break;
161 }
162
163 if (lev != styler.LevelAt(lineCurrent))
164 styler.SetLevel(lineCurrent, lev);
165
166 lineCurrent++;
167 visibleChars = 0;
168 }
169
170 if (!isspacechar(ch))
171 visibleChars++;
172 }
173
174 int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
175 styler.SetLevel(lineCurrent, lev | flagsNext);
176 }
177
178 static const char * const emptyWordListDesc[] = {
179 0
180 };
181
182 LexerModule lmLot(SCLEX_LOT, ColourizeLotDoc, "lot", FoldLotDoc, emptyWordListDesc);