OSDN Git Service

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