1
// Scintilla source code edit control
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.
7
// Copyright 2003 by Marius Gheorghe <mgheorghe@cabletest.com>
8
// The License.txt file describes the conditions under which this software may be distributed.
22
#include "Scintilla.h"
26
using namespace Scintilla;
29
static int GetLotLineState(std::string &line) {
31
// Most of the time the first non-blank character in line determines that line's type
32
// Now finds the first non-blank character
33
unsigned i; // Declares counter here to make it persistent after the for loop
34
for (i = 0; i < line.length(); ++i) {
35
if (!isspace(line[i]))
39
// Checks if it was a blank line
40
if (i == line.length())
41
return SCE_LOT_DEFAULT;
44
case '*': // Fail measurement
49
return SCE_LOT_HEADER;
51
case ':': // Set test limits
54
case '-': // Section break
57
default: // Any other line
58
// Checks for message at the end of lot file
59
if (line.find("PASSED") != std::string::npos) {
62
else if (line.find("FAILED") != std::string::npos) {
65
else if (line.find("ABORTED") != std::string::npos) {
69
return i ? SCE_LOT_PASS : SCE_LOT_DEFAULT;
74
return SCE_LOT_DEFAULT;
78
static void ColourizeLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
79
styler.StartAt(startPos);
80
styler.StartSegment(startPos);
81
bool atLineStart = true;// Arms the 'at line start' flag
82
char chNext = styler.SafeGetCharAt(startPos);
84
line.reserve(256); // Lot lines are less than 256 chars long most of the time. This should avoid reallocations
86
// Styles LOT document
87
unsigned int i; // Declared here because it's used after the for loop
88
for (i = startPos; i < startPos + length; ++i) {
90
chNext = styler.SafeGetCharAt(i + 1);
94
// LOT files are only used on the Win32 platform, thus EOL == CR+LF
95
// Searches for the end of line
96
if (ch == '\r' && chNext == '\n') {
97
line += chNext; // Gets the '\n'
98
++i; // Advances past the '\n'
99
chNext = styler.SafeGetCharAt(i + 1); // Gets character of next line
100
styler.ColourTo(i, GetLotLineState(line));
102
atLineStart = true; // Arms flag for next line
106
// Last line may not have a line ending
108
styler.ColourTo(i - 1, GetLotLineState(line));
112
// Folds an MPT LOT file: the blocks that can be folded are:
113
// sections (headed by a set line)
114
// passes (contiguous pass results within a section)
115
// fails (contiguous fail results within a section)
116
static void FoldLotDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
117
bool foldCompact = styler.GetPropertyInt("fold.compact", 0) != 0;
118
unsigned int endPos = startPos + length;
119
int visibleChars = 0;
120
int lineCurrent = styler.GetLine(startPos);
122
char chNext = styler.SafeGetCharAt(startPos);
123
int style = SCE_LOT_DEFAULT;
124
int styleNext = styler.StyleAt(startPos);
125
int lev = SC_FOLDLEVELBASE;
127
// Gets style of previous line if not at the beginning of the document
129
style = styler.StyleAt(startPos - 2);
131
for (unsigned int i = startPos; i < endPos; i++) {
133
chNext = styler.SafeGetCharAt(i + 1);
135
if (ch == '\r' && chNext == '\n') {
137
// Should really get the state of the previous line from the styler
138
int stylePrev = style;
140
styleNext = styler.StyleAt(i + 2);
145
lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
150
if (stylePrev != SCE_LOT_FAIL)
151
lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
153
lev = SC_FOLDLEVELBASE + 1;
155
lev = SC_FOLDLEVELBASE;
159
if (lineCurrent == 0 || stylePrev == SCE_LOT_FAIL)
160
lev = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG;
162
lev = SC_FOLDLEVELBASE + 1;
164
if (visibleChars == 0 && foldCompact)
165
lev |= SC_FOLDLEVELWHITEFLAG;
169
if (lev != styler.LevelAt(lineCurrent))
170
styler.SetLevel(lineCurrent, lev);
176
if (!isspacechar(ch))
180
int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
181
styler.SetLevel(lineCurrent, lev | flagsNext);
184
static const char * const emptyWordListDesc[] = {
188
LexerModule lmLot(SCLEX_LOT, ColourizeLotDoc, "lot", FoldLotDoc, emptyWordListDesc);