GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixTex2Html/src/PGenericParser.cpp
Date: 2025-03-24 18:12:43
Exec Total Coverage
Lines: 459 513 89.5%
Branches: 644 884 72.9%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "data_all.h"
8 #include "pxml_utils.h"
9 #include "PConfigParser.h"
10 #include "PLatexObj/platexobj_text.h"
11
12 #include "PGenericParser.h"
13
14 ///Do a wget of a file
15 /** @param url : url to be used
16 * @return true on success, false otherwise
17 */
18 bool wgetFile(const PString& url){
19 PString command("wget \""+url+"\"");
20 return system(command.c_str()) != 0;
21 }
22
23 ///Get the sequence of the begining of an environement
24 /** @param envName : name of the environement
25 * @return corresponding sequence
26 */
27 2027748 PVecString getBeginSeqEnv(const PString & envName){
28 2027748 PVecString vecEndPatern;
29
2/2
✓ Branch 1 taken 2027748 times.
✓ Branch 4 taken 2027748 times.
2027748 vecEndPatern.push_back("\\begin");
30
2/2
✓ Branch 1 taken 2027748 times.
✓ Branch 4 taken 2027748 times.
2027748 vecEndPatern.push_back("{");
31
1/1
✓ Branch 1 taken 2027748 times.
2027748 vecEndPatern.push_back(envName);
32
2/2
✓ Branch 1 taken 2027748 times.
✓ Branch 4 taken 2027748 times.
2027748 vecEndPatern.push_back("}");
33 2027748 return vecEndPatern;
34 }
35
36 ///Get the sequence of the ending of an environement
37 /** @param envName : name of the environement
38 * @return corresponding sequence
39 */
40 651 PVecString getEndSeqEnv(const PString & envName){
41 651 PVecString vecEndPatern;
42
2/2
✓ Branch 1 taken 651 times.
✓ Branch 4 taken 651 times.
651 vecEndPatern.push_back("\\end");
43
2/2
✓ Branch 1 taken 651 times.
✓ Branch 4 taken 651 times.
651 vecEndPatern.push_back("{");
44
1/1
✓ Branch 1 taken 651 times.
651 vecEndPatern.push_back(envName);
45
2/2
✓ Branch 1 taken 651 times.
✓ Branch 4 taken 651 times.
651 vecEndPatern.push_back("}");
46 651 return vecEndPatern;
47 }
48
49 ///Default constructor of PGenericParser
50 /** @param installPrefix : installation prefix
51 */
52
10/10
✓ Branch 2 taken 1097 times.
✓ Branch 5 taken 1097 times.
✓ Branch 10 taken 1097 times.
✓ Branch 13 taken 1097 times.
✓ Branch 29 taken 1097 times.
✓ Branch 35 taken 1097 times.
✓ Branch 38 taken 1097 times.
✓ Branch 41 taken 1097 times.
✓ Branch 44 taken 1097 times.
✓ Branch 47 taken 1097 times.
1097 PGenericParser::PGenericParser(const PString & installPrefix){
53
1/1
✓ Branch 1 taken 1097 times.
1097 initialisationPGenericParser(installPrefix);
54 1097 }
55
56 ///Copy constructor of PGenericParser
57 /** @param other : class to copy
58 */
59
10/10
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 29 taken 3 times.
✓ Branch 35 taken 3 times.
✓ Branch 38 taken 3 times.
✓ Branch 41 taken 3 times.
✓ Branch 44 taken 3 times.
✓ Branch 47 taken 3 times.
3 PGenericParser::PGenericParser(const PGenericParser & other){
60
1/1
✓ Branch 1 taken 3 times.
3 copyPGenericParser(other);
61 3 }
62
63 ///Destructor of PGenericParser
64 2200 PGenericParser::~PGenericParser(){
65
66 }
67
68 ///Definition of equal operator of PGenericParser
69 /** @param other : class to copy
70 * @return copied class
71 */
72 PGenericParser & PGenericParser::operator = (const PGenericParser & other){
73 copyPGenericParser(other);
74 return *this;
75 }
76
77 ///Set if the PGenericParser is in debug mode
78 /** @param isDebugMode : true if the PGenericParser is in debug mode, false if not
79 */
80 130 void PGenericParser::setDebugMode(bool isDebugMode){
81 130 p_isDebugMode = isDebugMode;
82 130 }
83
84 ///Get the current source
85 /** @return current source
86 */
87 const PLatexObj & PGenericParser::getSource() const{
88 return p_currentSource;
89 }
90
91 ///Get the current source
92 /** @return current source
93 */
94 1097 PLatexObj & PGenericParser::getSource(){
95 1097 return p_currentSource;
96 }
97
98 ///Get the vector of include directories
99 /** @return vector of include directories
100 */
101 const PVecString & PGenericParser::getVecIncludeDir() const{
102 return p_vecIncludeDir;
103 }
104
105 ///Get the vector of include directories
106 /** @return vector of include directories
107 */
108 130 PVecString & PGenericParser::getVecIncludeDir(){
109 130 return p_vecIncludeDir;
110 }
111
112 ///Get the map of all bibliography entries
113 /** @return map of all bibliography entries
114 */
115 const PMapBiblioEntry & PGenericParser::getMapBiblioEntry() const{return p_mapBiblioEntry;}
116
117 ///Get the map of all bibliography entries
118 /** @return map of all bibliography entries
119 */
120 8 PMapBiblioEntry & PGenericParser::getMapBiblioEntry(){return p_mapBiblioEntry;}
121
122 ///Get the width of the book sidebar
123 /** @return width of the book sidebar
124 */
125 11 const PString & PGenericParser::getBookSideBarWidth() const{
126 11 return p_bookSideBarWidth;
127 }
128
129 ///Get the book gitlab url
130 /** @return width of the book sidebar
131 */
132 11 const PString & PGenericParser::getBookGitlabUrl() const{
133 11 return p_bookGitlabUrl;
134 }
135
136 ///Say if the book feedback if enable or not
137 /** @return true if the book feedback if enable, false if not
138 */
139 11 bool PGenericParser::getBookEnableFeedback() const{
140 11 return p_isEnableBookFeedback;
141 }
142
143 ///Get the book mail list
144 /** @return book mail list
145 */
146 11 const PString & PGenericParser::getBookMail() const{
147 11 return p_bookMail;
148 }
149
150 ///Get the book master project url
151 /** @return book master project url
152 */
153 11 const PString & PGenericParser::getBookMasterProjectUrl() const{
154 11 return p_bookMasterProjectUrl;
155 }
156
157 ///Get the book main page link
158 /** @return book main page link
159 */
160 11 const PLatexObj & PGenericParser::getBookMainPageLink() const{
161 11 return p_bookMainPageLink;
162 }
163
164 ///Save the css file
165 /** @return true on success, false otherwise
166 */
167 130 bool PGenericParser::saveCss(){
168 130 PVecString vecTheme;
169
2/2
✓ Branch 4 taken 520 times.
✓ Branch 5 taken 130 times.
650 for(std::map<PString, PString>::iterator itStyle(p_cssContent.begin()); itStyle != p_cssContent.end(); ++itStyle){
170
1/1
✓ Branch 2 taken 520 times.
520 vecTheme.push_back(itStyle->first);
171 }
172
173
2/2
✓ Branch 4 taken 520 times.
✓ Branch 5 taken 130 times.
650 for(std::map<PString, PString>::iterator itStyle(p_cssContent.begin()); itStyle != p_cssContent.end(); ++itStyle){
174
2/2
✓ Branch 2 taken 520 times.
✓ Branch 6 taken 520 times.
520 PString cssStyle(itStyle->second), cssThemeName(itStyle->first);
175
1/2
✓ Branch 1 taken 520 times.
✗ Branch 2 not taken.
520 if(p_vecExtraEnv.size() != 0lu){
176
2/2
✓ Branch 4 taken 6760 times.
✓ Branch 5 taken 520 times.
7280 for(PMapExtraEnv::iterator it(p_vecExtraEnv.begin()); it != p_vecExtraEnv.end(); ++it){
177
4/4
✓ Branch 2 taken 6760 times.
✓ Branch 5 taken 6760 times.
✓ Branch 8 taken 6760 times.
✓ Branch 11 taken 6760 times.
6760 cssStyle += "." + it->second.getName() + "Style{\n";
178
3/3
✓ Branch 2 taken 6760 times.
✓ Branch 5 taken 6760 times.
✓ Branch 8 taken 6760 times.
6760 cssStyle += select_css_theme(vecTheme, cssThemeName, it->second.getCss());
179
1/1
✓ Branch 1 taken 6760 times.
6760 cssStyle += "}\n\n";
180 }
181 }
182
1/2
✓ Branch 1 taken 520 times.
✗ Branch 2 not taken.
520 if(p_vecExtraFunction.size() != 0lu){
183
2/2
✓ Branch 4 taken 15600 times.
✓ Branch 5 taken 520 times.
16120 for(PMapExtraEnv::iterator it(p_vecExtraFunction.begin()); it != p_vecExtraFunction.end(); ++it){
184
4/4
✓ Branch 2 taken 15600 times.
✓ Branch 5 taken 15600 times.
✓ Branch 8 taken 15600 times.
✓ Branch 11 taken 15600 times.
15600 cssStyle += "." + it->second.getName() + "Style{\n";
185
3/3
✓ Branch 2 taken 15600 times.
✓ Branch 5 taken 15600 times.
✓ Branch 8 taken 15600 times.
15600 cssStyle += select_css_theme(vecTheme, cssThemeName, it->second.getCss());
186
1/1
✓ Branch 1 taken 15600 times.
15600 cssStyle += "}\n\n";
187 }
188 }
189
3/3
✓ Branch 1 taken 520 times.
✓ Branch 4 taken 520 times.
✓ Branch 7 taken 520 times.
1040 PPath fileName(cssThemeName + "_style.css");
190
2/3
✓ Branch 1 taken 520 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 520 times.
520 if(!fileName.saveFileContent(cssStyle)){
191 std::cerr << "PGenericParser::saveCss : can't save the file '"<<fileName<<"'" << std::endl;
192 return false;
193 }
194
3/6
✓ Branch 1 taken 520 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 520 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 520 times.
✗ Branch 8 not taken.
520 }
195 130 return true;
196 130 }
197
198 ///Copy function of PGenericParser
199 /** @param other : class to copy
200 */
201 6 void PGenericParser::copyPGenericParser(const PGenericParser & other){
202 6 p_isDebugMode = other.p_isDebugMode;
203
204 ///Vector of all the environements
205 6 p_vecEnv = other.p_vecEnv;
206 ///Vector of all the functions
207 6 p_vecFunc = other.p_vecFunc;
208
209 ///Vector of the include directories
210 6 p_vecIncludeDir = other.p_vecIncludeDir;
211
212 ///Vector of the name of the extra environement
213 6 p_vecNameExtraEnv = other.p_vecNameExtraEnv;
214 ///Vector of the name of the extra environement
215 6 p_vecNameFunctionExtraEnv = other.p_vecNameFunctionExtraEnv;
216 ///Vector of the name of the extra environement
217 6 p_vecNameMarkdownExtraEnv = other.p_vecNameMarkdownExtraEnv;
218 ///Vector of extra environements
219 6 p_vecExtraEnv = other.p_vecExtraEnv;
220
221 ///Vector of the name of the extra function
222 6 p_vecNameExtraFunction = other.p_vecNameExtraFunction;
223 ///Vector of extra function
224 6 p_vecExtraFunction = other.p_vecExtraFunction;
225
226 ///Vector of the name of the extra environement
227 6 p_vecNameExtraParser = other.p_vecNameExtraParser;
228 ///Vector of the function name of the extra environement
229 6 p_vecNameFunctionExtraParser = other.p_vecNameFunctionExtraParser;
230 ///Vector of the markdown name of the extra environement
231 6 p_vecNameMarkdownExtraParser = other.p_vecNameMarkdownExtraParser;
232 ///Vector of removed latex functions
233 6 p_vecRemoveLatexKeyword = other.p_vecRemoveLatexKeyword;
234 ///Vector of extra parser
235 6 p_vecExtraParser = other.p_vecExtraParser;
236
237 ///Css of all the configurations
238 6 p_cssContent = other.p_cssContent;
239 ///Map of all bibliography entries
240 6 p_mapBiblioEntry = other.p_mapBiblioEntry;
241 ///Map of copied files
242 6 p_mapCopiedFile = other.p_mapCopiedFile;
243
244 6 p_bookSideBarWidth = other.p_bookSideBarWidth;
245 6 p_bookMasterProjectUrl = other.p_bookMasterProjectUrl;
246 6 p_bookMainPageLink = other.p_bookMainPageLink;
247 6 p_bookMail = other.p_bookMail;
248 6 p_bookGitlabUrl = other.p_bookGitlabUrl;
249 6 p_isEnableBookFeedback = other.p_isEnableBookFeedback;
250 6 }
251
252 ///Clear a latex obj
253 /** @param[out] obj : PLatexObj to be cleared
254 */
255 9152 void PGenericParser::clearLatexObj(PLatexObj & obj){
256 9152 obj.getVecContent().clear();
257
1/1
✓ Branch 2 taken 9152 times.
9152 obj.setLabelName("");
258
1/1
✓ Branch 2 taken 9152 times.
9152 obj.setText("");
259
1/1
✓ Branch 2 taken 9152 times.
9152 obj.setName("");
260
1/1
✓ Branch 1 taken 9152 times.
9152 obj.setType(PLatexType::TEXT);
261 9152 }
262
263 ///Increment current char position
264 /** @param[out] textObj : obh to be used to store text
265 */
266 173575 void PGenericParser::incrementCurrentChar(PLatexObj & textObj){
267 //If nothing is known I need to save the current char in the MACRO TEXT
268 173575 char ch = p_parser->getCurrentCh();
269 173575 textObj.getText() += ch;
270 173575 p_parser->getNextChar();
271 173575 }
272
273 ///Play the text latex obj
274 /** @param[out] parent : parent PMacro
275 * @param[out] textObj : PLatexObj to deal with text
276 * @param isRemoveFirstLastSpace : true to remove first and last spaces (tabs and newline) before added the text object
277 * @return true if the textObj is added, false otherwise
278 */
279 10581 bool PGenericParser::playTextLatexObj(PLatexObj & parent, PLatexObj & textObj, bool isRemoveFirstLastSpace){
280
2/2
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 10479 times.
10581 if(isRemoveFirstLastSpace){
281
2/2
✓ Branch 3 taken 102 times.
✓ Branch 6 taken 102 times.
102 textObj.setText(textObj.getText().eraseFirstLastChar(" \t\n"));
282 }
283
2/2
✓ Branch 2 taken 6954 times.
✓ Branch 3 taken 3627 times.
10581 if(textObj.getText() != ""){
284 6954 parent.getVecContent().push_back(textObj);
285 6954 clearLatexObj(textObj);
286 6954 return true;
287 }
288 3627 return false;
289 }
290
291
292 ///Add latex obj in parent
293 /** @param[out] parent : parent PLatexObj
294 * @param obj : PLatexObj to be added into parent
295 */
296 6776 void PGenericParser::addLatexObj(PLatexObj & parent, const PLatexObj & obj){
297 6776 parent.getVecContent().push_back(obj);
298 6776 }
299
300 ///Execute the given latex command
301 /** @param inputStr : input latex string
302 * @return text string
303 */
304 377 PString PGenericParser::executeLatexCommand(const PString & inputStr){
305
2/2
✓ Branch 1 taken 377 times.
✓ Branch 4 taken 377 times.
377 PConfigParser parser;
306
3/3
✓ Branch 1 taken 377 times.
✓ Branch 4 taken 377 times.
✓ Branch 7 taken 377 times.
377 parser.setFileContent(inputStr + "\n");
307
1/1
✓ Branch 1 taken 377 times.
377 PString out("");
308
2/3
✓ Branch 1 taken 377 times.
✓ Branch 3 taken 377 times.
✗ Branch 4 not taken.
377 if(parser.fullParsing()){
309
2/2
✓ Branch 2 taken 377 times.
✓ Branch 5 taken 377 times.
377 out = platexobj_text(parser.getSource());
310 }else{
311 out = inputStr;
312 }
313 754 return out;
314 377 }
315
316 ///Get the string between the braces {...}
317 /** @param previousToken : previous token to be used
318 * @return string between {...}
319 */
320 5398 PString PGenericParser::getStringBetweenBraces(const PString & previousToken){
321
4/4
✓ Branch 1 taken 5398 times.
✓ Branch 4 taken 5398 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 5397 times.
5398 if(!isMatch("{")){
322
1/1
✓ Branch 1 taken 1 times.
1 errorAt();
323
7/7
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
1 std::cerr << "PGenericParser::getStringBetweenBraces : expect '{' after '"<<previousToken<<"' instead of '"<<p_parser->getNextChar()<<"'" << std::endl;
324
1/1
✓ Branch 1 taken 1 times.
1 stopParsing();
325
1/1
✓ Branch 1 taken 1 times.
1 return "";
326 }
327 // PString link(p_parser->getUntilKeyWithoutPatern("}"));
328
3/3
✓ Branch 1 taken 5397 times.
✓ Branch 4 taken 5397 times.
✓ Branch 7 taken 5397 times.
10794 PString link(p_parser->getUntilKeyWithoutPaternRecurse("}", "{"));
329
1/1
✓ Branch 1 taken 5397 times.
5397 return link;
330 5397 }
331
332 ///Get optional string between braces {...}
333 /** @return string between braces or empty string if there is no hook
334 */
335 63 PString PGenericParser::getOptionStringBetweenBraces(){
336
4/4
✓ Branch 1 taken 63 times.
✓ Branch 4 taken 63 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 62 times.
63 if(!isMatch("{")){ //No hook => empty string
337
1/1
✓ Branch 1 taken 1 times.
1 return "";
338 }
339
3/3
✓ Branch 1 taken 62 times.
✓ Branch 4 taken 62 times.
✓ Branch 7 taken 62 times.
124 PString link(p_parser->getUntilKeyWithoutPaternRecurse("}", "{"));
340
1/1
✓ Branch 1 taken 62 times.
62 return link;
341 62 }
342
343 ///Get optional string between hooks [...]
344 /** @return string between hooks or empty string if there is no hook
345 */
346 897 PString PGenericParser::getOptionStringBetweenHook(){
347
2/2
✓ Branch 1 taken 897 times.
✓ Branch 4 taken 897 times.
897 PARSER_SKIP_SPACE
348
1/1
✓ Branch 1 taken 897 times.
897 char ch = p_parser->getCurrentCh();
349
1/2
✓ Branch 0 taken 897 times.
✗ Branch 1 not taken.
897 if(ch != '['){ //No hook => empty string
350
1/1
✓ Branch 1 taken 897 times.
897 return "";
351 }
352 p_parser->getNextChar();
353 PString link(p_parser->getUntilKeyWithoutPatern("]"));
354 return link;
355 }
356
357 ///Parse all the functions which have mono parameter in braces {...}
358 /** @param[out] parent : parent PLatexObj
359 * @param[out] textObj : PLatexObj to deal with text
360 * @param functionName : name of the expected function
361 * @param type : type of the expected function
362 * @return true on success, false otherwise
363 */
364 696279 bool PGenericParser::parseMonoParam(PLatexObj & parent, PLatexObj & textObj, const PString & functionName, PLatexType::PLatexType type){
365
3/3
✓ Branch 1 taken 696279 times.
✓ Branch 3 taken 696126 times.
✓ Branch 4 taken 153 times.
696279 if(!p_parser->isMatch(functionName)){return false;}
366
1/1
✓ Branch 1 taken 153 times.
153 playTextLatexObj(parent, textObj);
367
1/1
✓ Branch 1 taken 153 times.
153 PLatexObj tmp;
368
1/1
✓ Branch 1 taken 153 times.
153 tmp.setType(type);
369
370
1/1
✓ Branch 1 taken 153 times.
153 PString textOption(getOptionStringBetweenHook());
371
1/1
✓ Branch 1 taken 153 times.
153 tmp.setText(textOption);
372
373
1/1
✓ Branch 1 taken 153 times.
153 PString title(getStringBetweenBraces(functionName));
374
1/1
✓ Branch 1 taken 153 times.
153 tmp.setName(title);
375
376
1/1
✓ Branch 1 taken 153 times.
153 addLatexObj(parent, tmp);
377 153 return true;
378 153 }
379
380 ///Parse the generic latex function which have to be used in the latex parser and the markdown parser too
381 /** @param[out] parent : parent PLatexObj
382 * @param[out] textObj : PLatexObj to deal with text
383 * @return true on success, false otherwise
384 */
385 175141 bool PGenericParser::parseGenericLatexObj(PLatexObj & parent, PLatexObj & textObj){
386
3/3
✓ Branch 2 taken 175141 times.
✓ Branch 5 taken 175118 times.
✓ Branch 6 taken 23 times.
175141 if(parseMonoParam(parent, textObj, "\\updateStyle", PLatexType::UPDATESTYLE)){}
387
3/3
✓ Branch 2 taken 175118 times.
✓ Branch 5 taken 175109 times.
✓ Branch 6 taken 9 times.
175118 else if(parseMonoParam(parent, textObj, "\\ref", PLatexType::REF)){}
388
3/3
✓ Branch 2 taken 175109 times.
✓ Branch 5 taken 175100 times.
✓ Branch 6 taken 9 times.
175109 else if(parseMonoParam(parent, textObj, "\\cite", PLatexType::CITATION)){}
389
2/2
✓ Branch 1 taken 175079 times.
✓ Branch 2 taken 21 times.
175100 else if(parseLabel(parent, textObj)){}
390
2/2
✓ Branch 1 taken 175072 times.
✓ Branch 2 taken 7 times.
175079 else if(parserGetEnv(parent, textObj)){}
391
2/2
✓ Branch 1 taken 174944 times.
✓ Branch 2 taken 128 times.
175072 else if(parseMainTitle(parent, textObj)){}
392
2/2
✓ Branch 1 taken 174868 times.
✓ Branch 2 taken 76 times.
174944 else if(parseMainSubTitle(parent, textObj)){}
393
2/2
✓ Branch 1 taken 174740 times.
✓ Branch 2 taken 128 times.
174868 else if(parseMainAuthor(parent, textObj)){}
394
1/2
✓ Branch 1 taken 174740 times.
✗ Branch 2 not taken.
174740 else if(parseMainDate(parent, textObj)){}
395
2/2
✓ Branch 1 taken 174731 times.
✓ Branch 2 taken 9 times.
174740 else if(parseBookSizeBarWidth(parent, textObj)){}
396
2/2
✓ Branch 1 taken 174722 times.
✓ Branch 2 taken 9 times.
174731 else if(parseBookGitlabUrl(parent, textObj)){}
397
2/2
✓ Branch 1 taken 174713 times.
✓ Branch 2 taken 9 times.
174722 else if(parseBookEnableFeedback(parent, textObj)){}
398
2/2
✓ Branch 1 taken 174704 times.
✓ Branch 2 taken 9 times.
174713 else if(parseBookMail(parent, textObj)){}
399
2/2
✓ Branch 1 taken 174695 times.
✓ Branch 2 taken 9 times.
174704 else if(parseBookMasterProject(parent, textObj)){}
400 174695 else{return false;}
401 446 return true;
402 }
403
404 ///Parse latex label
405 /** @param[out] parent : parent PLatexObj
406 * @param[out] textObj : PLatexObj to deal with text
407 * @return true on success, false otherwise
408 */
409 175100 bool PGenericParser::parseLabel(PLatexObj & parent, PLatexObj & textObj){
410
4/4
✓ Branch 1 taken 175100 times.
✓ Branch 4 taken 175100 times.
✓ Branch 7 taken 175079 times.
✓ Branch 8 taken 21 times.
175100 if(!p_parser->isMatchToken("\\label")){return false;}
411
1/1
✓ Branch 1 taken 21 times.
21 playTextLatexObj(parent, textObj);
412
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 PString link(getStringBetweenBraces("\\label"));
413
414
1/1
✓ Branch 1 taken 21 times.
21 PLatexObj* ptrLatex = getLastPLatexObj(parent);
415
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(ptrLatex != NULL){
416
1/1
✓ Branch 1 taken 21 times.
21 ptrLatex->setLabelName(link);
417 }
418 21 return true;
419 21 }
420
421 ///Parse a getenv function
422 /** @param[out] parent : parent PLatexObj
423 * @param[out] textObj : PLatexObj to deal with text
424 * @return true on success, false otherwise
425 */
426 175079 bool PGenericParser::parserGetEnv(PLatexObj & parent, PLatexObj & textObj){
427
4/4
✓ Branch 1 taken 175079 times.
✓ Branch 4 taken 175079 times.
✓ Branch 7 taken 175072 times.
✓ Branch 8 taken 7 times.
175079 if(!p_parser->isMatchToken("\\getenv")){return false;}
428
1/1
✓ Branch 1 taken 7 times.
7 playTextLatexObj(parent, textObj);
429
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 PString title(getStringBetweenBraces("\\getenv"));
430
1/1
✓ Branch 1 taken 7 times.
7 PLatexObj tmp;
431
1/1
✓ Branch 1 taken 7 times.
7 tmp.setType(PLatexType::GETENV);
432
1/1
✓ Branch 1 taken 7 times.
7 tmp.setName(title);
433
1/1
✓ Branch 1 taken 7 times.
7 addLatexObj(parent, tmp);
434
435 7 return true;
436 7 }
437
438 ///Parse the main title of the site
439 /** @param[out] parent : parent PLatexObj
440 * @param[out] textObj : PLatexObj to deal with text
441 * @return true on success, false otherwise
442 */
443 175072 bool PGenericParser::parseMainTitle(PLatexObj & parent, PLatexObj & textObj){
444
4/4
✓ Branch 1 taken 175072 times.
✓ Branch 4 taken 175072 times.
✓ Branch 7 taken 174944 times.
✓ Branch 8 taken 128 times.
175072 if(!p_parser->isMatchToken("\\title")){return false;}
445
1/1
✓ Branch 1 taken 128 times.
128 playTextLatexObj(parent, textObj);
446
2/2
✓ Branch 1 taken 128 times.
✓ Branch 4 taken 128 times.
128 PString title(getStringBetweenBraces("\\title"));
447
2/2
✓ Branch 1 taken 128 times.
✓ Branch 4 taken 128 times.
128 parent.setName(executeLatexCommand(title));
448 128 return true;
449 128 }
450
451 ///Parse the main title of the site
452 /** @param[out] parent : parent PLatexObj
453 * @param[out] textObj : PLatexObj to deal with text
454 * @return true on success, false otherwise
455 */
456 174944 bool PGenericParser::parseMainSubTitle(PLatexObj & parent, PLatexObj & textObj){
457
4/4
✓ Branch 1 taken 174944 times.
✓ Branch 4 taken 174944 times.
✓ Branch 7 taken 174868 times.
✓ Branch 8 taken 76 times.
174944 if(!p_parser->isMatchToken("\\subtitle")){return false;}
458
1/1
✓ Branch 1 taken 76 times.
76 playTextLatexObj(parent, textObj);
459
2/2
✓ Branch 1 taken 76 times.
✓ Branch 4 taken 76 times.
76 PString title(getStringBetweenBraces("\\subtitle"));
460
2/2
✓ Branch 1 taken 76 times.
✓ Branch 4 taken 76 times.
76 parent.setSubTitle(executeLatexCommand(title));
461 76 return true;
462 76 }
463
464 ///Parse the main author of the site
465 /** @param[out] parent : parent PLatexObj
466 * @param[out] textObj : PLatexObj to deal with text
467 * @return true on success, false otherwise
468 */
469 174868 bool PGenericParser::parseMainAuthor(PLatexObj & parent, PLatexObj & textObj){
470
4/4
✓ Branch 1 taken 174868 times.
✓ Branch 4 taken 174868 times.
✓ Branch 7 taken 174740 times.
✓ Branch 8 taken 128 times.
174868 if(!p_parser->isMatchToken("\\author")){return false;}
471
1/1
✓ Branch 1 taken 128 times.
128 playTextLatexObj(parent, textObj);
472
2/2
✓ Branch 1 taken 128 times.
✓ Branch 4 taken 128 times.
128 PString title(getStringBetweenBraces("\\author"));
473
2/2
✓ Branch 1 taken 128 times.
✓ Branch 4 taken 128 times.
128 parent.setAuthor(executeLatexCommand(title));
474 128 return true;
475 128 }
476
477 ///Parse the main date of the site
478 /** @param[out] parent : parent PLatexObj
479 * @param[out] textObj : PLatexObj to deal with text
480 * @return true on success, false otherwise
481 */
482 174740 bool PGenericParser::parseMainDate(PLatexObj & parent, PLatexObj & textObj){
483
3/4
✓ Branch 1 taken 174740 times.
✓ Branch 4 taken 174740 times.
✓ Branch 7 taken 174740 times.
✗ Branch 8 not taken.
174740 if(!p_parser->isMatchToken("\\date")){return false;}
484 playTextLatexObj(parent, textObj);
485 PString title(getStringBetweenBraces("\\date"));
486 parent.setDate(executeLatexCommand(title));
487 return true;
488 }
489
490 ///Parse the width of the book sidebar
491 /** @param[out] parent : parent PLatexObj
492 * @param[out] textObj : PLatexObj to deal with text
493 * @return true on success, false otherwise
494 */
495 174740 bool PGenericParser::parseBookSizeBarWidth(PLatexObj & parent, PLatexObj & textObj){
496
4/4
✓ Branch 1 taken 174740 times.
✓ Branch 4 taken 174740 times.
✓ Branch 7 taken 174731 times.
✓ Branch 8 taken 9 times.
174740 if(!p_parser->isMatchToken("\\bookSizebarWidth")){return false;}
497
1/1
✓ Branch 1 taken 9 times.
9 playTextLatexObj(parent, textObj);
498
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 PString title(getStringBetweenBraces("\\bookSizebarWidth"));
499
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 p_bookSideBarWidth = executeLatexCommand(title);
500 9 return true;
501 9 }
502
503 ///Parse the gitlab url in book mode
504 /** @param[out] parent : parent PLatexObj
505 * @param[out] textObj : PLatexObj to deal with text
506 * @return true on success, false otherwise
507 */
508 174731 bool PGenericParser::parseBookGitlabUrl(PLatexObj & parent, PLatexObj & textObj){
509
4/4
✓ Branch 1 taken 174731 times.
✓ Branch 4 taken 174731 times.
✓ Branch 7 taken 174722 times.
✓ Branch 8 taken 9 times.
174731 if(!p_parser->isMatchToken("\\bookGitlabUrl")){return false;}
510
1/1
✓ Branch 1 taken 9 times.
9 playTextLatexObj(parent, textObj);
511
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 PString title(getStringBetweenBraces("\\bookGitlabUrl"));
512
4/4
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
9 p_bookGitlabUrl = executeLatexCommand(title).eraseLastChar("/");
513 9 return true;
514 9 }
515
516 ///Parse the book enable feedback mode
517 /** @param[out] parent : parent PLatexObj
518 * @param[out] textObj : PLatexObj to deal with text
519 * @return true on success, false otherwise
520 */
521 174722 bool PGenericParser::parseBookEnableFeedback(PLatexObj & parent, PLatexObj & textObj){
522
4/4
✓ Branch 1 taken 174722 times.
✓ Branch 4 taken 174722 times.
✓ Branch 7 taken 174713 times.
✓ Branch 8 taken 9 times.
174722 if(!p_parser->isMatchToken("\\bookEnableFeedback")){return false;}
523
1/1
✓ Branch 1 taken 9 times.
9 playTextLatexObj(parent, textObj);
524
3/3
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
18 PString title(getStringBetweenBraces("\\bookEnableFeedback").toLower());
525
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 title = executeLatexCommand(title);
526
3/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
9 p_isEnableBookFeedback = (title == "true" || title == "yes" || title == "1");
527 9 return true;
528 9 }
529
530 ///Parse the mail in book mode
531 /** @param[out] parent : parent PLatexObj
532 * @param[out] textObj : PLatexObj to deal with text
533 * @return true on success, false otherwise
534 */
535 174713 bool PGenericParser::parseBookMail(PLatexObj & parent, PLatexObj & textObj){
536
4/4
✓ Branch 1 taken 174713 times.
✓ Branch 4 taken 174713 times.
✓ Branch 7 taken 174704 times.
✓ Branch 8 taken 9 times.
174713 if(!p_parser->isMatchToken("\\bookMail")){return false;}
537
1/1
✓ Branch 1 taken 9 times.
9 playTextLatexObj(parent, textObj);
538
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 PString title(getStringBetweenBraces("\\bookMail"));
539
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 p_bookMail = executeLatexCommand(title);
540 9 return true;
541 9 }
542
543 ///Parse the master project in book mode
544 /** @param[out] parent : parent PLatexObj
545 * @param[out] textObj : PLatexObj to deal with text
546 * @return true on success, false otherwise
547 */
548 174704 bool PGenericParser::parseBookMasterProject(PLatexObj & parent, PLatexObj & textObj){
549
4/4
✓ Branch 1 taken 174704 times.
✓ Branch 4 taken 174704 times.
✓ Branch 7 taken 174695 times.
✓ Branch 8 taken 9 times.
174704 if(!p_parser->isMatchToken("\\bookMasterProject")){return false;}
550
1/1
✓ Branch 1 taken 9 times.
9 playTextLatexObj(parent, textObj);
551
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 PString title(getStringBetweenBraces("\\bookMasterProject"));
552
4/4
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
9 p_bookMasterProjectUrl = executeLatexCommand(title).eraseLastChar("/");
553 9 return true;
554 9 }
555
556 ///Get a boolean from xml attribute
557 /** @param[out] isAllowComment : boolean to be set
558 * @param xml : main balise
559 * @param name : name of the attribute
560 */
561 28522 void setBoolFromAttr(bool & isAllowComment, const PXml & xml, const PString & name){
562
1/1
✓ Branch 1 taken 28522 times.
28522 PXmlAttr attr;
563
3/3
✓ Branch 1 taken 28522 times.
✓ Branch 3 taken 2194 times.
✓ Branch 4 taken 26328 times.
28522 if(pxml_getAttrIfExist(attr, xml, name)){
564
2/2
✓ Branch 1 taken 2194 times.
✓ Branch 4 taken 2194 times.
2194 PString value = attr.getValue().toLower();
565
3/6
✓ Branch 1 taken 2194 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2194 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2194 times.
2194 isAllowComment = value == "yes" || value == "1" || value == "y";
566 2194 }
567 28522 }
568
569 ///Load the extra environements with input file
570 /** @param inputFile : input directory
571 */
572 1227 void PGenericParser::loadDirExtraEnvironementFile(const PPath & inputFile){
573
1/1
✓ Branch 1 taken 1227 times.
1227 PXml root;
574
2/3
✓ Branch 1 taken 1227 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1227 times.
1227 if(!pxml_parserFile(root, inputFile)){
575 std::cerr << "PGenericParser::loadDirExtraEnvironementFile : can't read file '"<<inputFile<<"'" << std::endl;
576 return;
577 }
578
1/1
✓ Branch 1 taken 1227 times.
1227 PXml & childXml = root.getVecChild().front();
579
4/4
✓ Branch 1 taken 1227 times.
✓ Branch 4 taken 1227 times.
✓ Branch 7 taken 130 times.
✓ Branch 8 taken 1097 times.
1227 if(!pxml_getChildIfExist(childXml, root, "environement")){
580
4/4
✓ Branch 1 taken 130 times.
✓ Branch 4 taken 130 times.
✓ Branch 7 taken 130 times.
✓ Branch 10 taken 130 times.
130 std::cerr << "PGenericParser::loadDirExtraEnvironementFile : can't find <environement> </environement> balise in file '"<<inputFile<<"'" << std::endl;
581 130 return;
582 }
583 1097 PVecXml listEnv;
584
3/4
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
✓ Branch 7 taken 1097 times.
✗ Branch 8 not taken.
1097 if(pxml_getVecChildIfExist(listEnv, childXml, "env")){
585
2/2
✓ Branch 4 taken 14261 times.
✓ Branch 5 taken 1097 times.
15358 for(PVecXml::iterator it(listEnv.begin()); it != listEnv.end(); ++it){
586
1/1
✓ Branch 1 taken 14261 times.
14261 PXmlAttr attrName;
587
3/4
✓ Branch 1 taken 14261 times.
✓ Branch 5 taken 14261 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 14261 times.
14261 if(!pxml_getAttrIfExist(attrName, *it, "name")){continue;}
588
2/2
✓ Branch 1 taken 14261 times.
✓ Branch 4 taken 14261 times.
14261 PString name(attrName.getValue());
589
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14261 times.
14261 if(name == ""){
590 std::cerr << "PGenericParser::loadDirExtraEnvironementFile : expect name in balise" << std::endl;
591 continue;
592 }
593
1/1
✓ Branch 1 taken 14261 times.
14261 PString balise("div");
594
1/1
✓ Branch 1 taken 14261 times.
14261 PXmlAttr attr;
595
4/4
✓ Branch 1 taken 14261 times.
✓ Branch 5 taken 14261 times.
✓ Branch 8 taken 3291 times.
✓ Branch 9 taken 10970 times.
14261 if(pxml_getAttrIfExist(attr, *it, "balise")){
596
2/2
✓ Branch 1 taken 3291 times.
✓ Branch 4 taken 3291 times.
3291 balise = attr.getValue();
597 }
598 14261 bool isAllowComment(true), isAllowMath(true);
599
2/2
✓ Branch 1 taken 14261 times.
✓ Branch 5 taken 14261 times.
14261 setBoolFromAttr(isAllowComment, *it, "comment");
600
2/2
✓ Branch 1 taken 14261 times.
✓ Branch 5 taken 14261 times.
14261 setBoolFromAttr(isAllowMath, *it, "math");
601
602
1/1
✓ Branch 2 taken 14261 times.
14261 PString contentStr(pxml_getFullContent(*it));
603
604
1/1
✓ Branch 1 taken 14261 times.
14261 PEnvironement tmp;
605
1/1
✓ Branch 1 taken 14261 times.
14261 tmp.setName(name);
606
1/1
✓ Branch 1 taken 14261 times.
14261 tmp.setBalise(balise);
607
1/1
✓ Branch 1 taken 14261 times.
14261 tmp.setCss(contentStr);
608
1/1
✓ Branch 1 taken 14261 times.
14261 tmp.setIsAllowComment(isAllowComment);
609
1/1
✓ Branch 1 taken 14261 times.
14261 tmp.setIsAlloxMath(isAllowMath);
610
611
2/2
✓ Branch 1 taken 14261 times.
✓ Branch 4 taken 14261 times.
14261 p_vecExtraEnv[name] = tmp;
612
1/1
✓ Branch 1 taken 14261 times.
14261 p_vecNameExtraEnv.push_back(name);
613
3/3
✓ Branch 1 taken 14261 times.
✓ Branch 4 taken 14261 times.
✓ Branch 7 taken 14261 times.
14261 p_vecNameFunctionExtraEnv.push_back("\\" + name);
614
3/3
✓ Branch 1 taken 14261 times.
✓ Branch 4 taken 14261 times.
✓ Branch 7 taken 14261 times.
14261 p_vecNameMarkdownExtraEnv.push_back("```" + name);
615
2/4
✓ Branch 5 taken 14261 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 14261 times.
✗ Branch 9 not taken.
14261 }
616 }
617
2/2
✓ Branch 2 taken 1097 times.
✓ Branch 3 taken 130 times.
1227 }
618
619 ///Load the extra environements
620 /** @param inputDir : input directory
621 */
622 1097 void PGenericParser::loadDirExtraEnvironement(const PPath & inputDir){
623
1/1
✓ Branch 1 taken 1097 times.
1097 PListFile listInputFile = inputDir.getAllElementInDir();
624
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1097 times.
1097 if(listInputFile.size() == 0lu){
625 std::cerr << "PGenericParser::loadDirExtraEnvironement : can't read directory '"<<inputDir<<"'" << std::endl;
626 return;
627 }
628
2/2
✓ Branch 3 taken 1227 times.
✓ Branch 4 taken 1097 times.
2324 for(PListFile::iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
629
2/2
✓ Branch 2 taken 1227 times.
✓ Branch 5 taken 1227 times.
1227 loadDirExtraEnvironementFile(inputDir / (*it));
630 }
631
1/2
✓ Branch 1 taken 1097 times.
✗ Branch 2 not taken.
1097 }
632
633 ///Load the extra functions with input file
634 /** @param inputFile : input directory
635 */
636 1227 void PGenericParser::loadDirExtraFunctionFile(const PPath & inputFile){
637
1/1
✓ Branch 1 taken 1227 times.
1227 PXml root;
638
2/3
✓ Branch 1 taken 1227 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1227 times.
1227 if(!pxml_parserFile(root, inputFile)){
639 std::cerr << "PGenericParser::loadDirExtraFunctionFile : can't read file '"<<inputFile<<"'" << std::endl;
640 return;
641 }
642
1/1
✓ Branch 1 taken 1227 times.
1227 PXml & childXml = root.getVecChild().front();
643
4/4
✓ Branch 1 taken 1227 times.
✓ Branch 4 taken 1227 times.
✓ Branch 7 taken 130 times.
✓ Branch 8 taken 1097 times.
1227 if(!pxml_getChildIfExist(childXml, root, "function")){
644
4/4
✓ Branch 1 taken 130 times.
✓ Branch 4 taken 130 times.
✓ Branch 7 taken 130 times.
✓ Branch 10 taken 130 times.
130 std::cerr << "PGenericParser::loadDirExtraFunctionFile : can't find <function> </function> balise in file '"<<inputFile<<"'" << std::endl;
645 130 return;
646 }
647 1097 PVecXml listEnv;
648
3/4
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
✓ Branch 7 taken 1097 times.
✗ Branch 8 not taken.
1097 if(pxml_getVecChildIfExist(listEnv, childXml, "fct")){
649
2/2
✓ Branch 4 taken 32910 times.
✓ Branch 5 taken 1097 times.
34007 for(PVecXml::iterator it(listEnv.begin()); it != listEnv.end(); ++it){
650
1/1
✓ Branch 1 taken 32910 times.
32910 PXmlAttr attrName;
651
3/4
✓ Branch 1 taken 32910 times.
✓ Branch 5 taken 32910 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 32910 times.
32910 if(!pxml_getAttrIfExist(attrName, *it, "name")){continue;}
652
2/2
✓ Branch 1 taken 32910 times.
✓ Branch 4 taken 32910 times.
32910 PString name(attrName.getValue());
653
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32910 times.
32910 if(name == ""){
654 std::cerr << "PGenericParser::loadDirExtraFunctionFile : expect name in balise" << std::endl;
655 continue;
656 }
657
1/1
✓ Branch 1 taken 32910 times.
32910 PString balise("span");
658
1/1
✓ Branch 1 taken 32910 times.
32910 PXmlAttr attr;
659
4/4
✓ Branch 1 taken 32910 times.
✓ Branch 5 taken 32910 times.
✓ Branch 8 taken 1097 times.
✓ Branch 9 taken 31813 times.
32910 if(pxml_getAttrIfExist(attr, *it, "balise")){
660
2/2
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
1097 balise = attr.getValue();
661 }
662
1/1
✓ Branch 2 taken 32910 times.
32910 PString contentStr(pxml_getFullContent(*it));
663
1/1
✓ Branch 1 taken 32910 times.
32910 PEnvironement tmp;
664
1/1
✓ Branch 1 taken 32910 times.
32910 tmp.setName(name);
665
1/1
✓ Branch 1 taken 32910 times.
32910 tmp.setBalise(balise);
666
1/1
✓ Branch 1 taken 32910 times.
32910 tmp.setCss(contentStr);
667
668
2/2
✓ Branch 1 taken 32910 times.
✓ Branch 4 taken 32910 times.
32910 p_vecExtraFunction[name] = tmp;
669
3/3
✓ Branch 1 taken 32910 times.
✓ Branch 4 taken 32910 times.
✓ Branch 7 taken 32910 times.
32910 p_vecNameExtraFunction.push_back("\\" + name);
670
2/4
✓ Branch 5 taken 32910 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 32910 times.
✗ Branch 9 not taken.
32910 }
671 }
672
2/2
✓ Branch 2 taken 1097 times.
✓ Branch 3 taken 130 times.
1227 }
673
674 ///Load the extra functions
675 /** @param inputDir : input directory
676 */
677 1097 void PGenericParser::loadDirExtraFunction(const PPath & inputDir){
678
1/1
✓ Branch 1 taken 1097 times.
1097 PListFile listInputFile = inputDir.getAllElementInDir();
679
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1097 times.
1097 if(listInputFile.size() == 0lu){
680 std::cerr << "PGenericParser::loadDirExtraFunction : can't read directory '"<<inputDir<<"'" << std::endl;
681 return;
682 }
683
2/2
✓ Branch 3 taken 1227 times.
✓ Branch 4 taken 1097 times.
2324 for(PListFile::iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
684
2/2
✓ Branch 2 taken 1227 times.
✓ Branch 5 taken 1227 times.
1227 loadDirExtraFunctionFile(inputDir / (*it));
685 }
686
1/2
✓ Branch 1 taken 1097 times.
✗ Branch 2 not taken.
1097 }
687
688 ///Load the extra environements with input file
689 /** @param inputFile : input directory
690 */
691 28652 void PGenericParser::loadDirExtraParserFile(const PPath & inputFile){
692
1/1
✓ Branch 1 taken 28652 times.
28652 PXml root;
693
2/3
✓ Branch 1 taken 28652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28652 times.
28652 if(!pxml_parserFile(root, inputFile)){
694 std::cerr << "PGenericParser::loadDirExtraParserFile : can't read file '"<<inputFile<<"'" << std::endl;
695 return;
696 }
697
1/1
✓ Branch 1 taken 28652 times.
28652 PXml & childXml = root.getVecChild().front();
698
4/4
✓ Branch 1 taken 28652 times.
✓ Branch 4 taken 28652 times.
✓ Branch 7 taken 130 times.
✓ Branch 8 taken 28522 times.
28652 if(!pxml_getChildIfExist(childXml, root, "highlighting")){
699
4/4
✓ Branch 1 taken 130 times.
✓ Branch 4 taken 130 times.
✓ Branch 7 taken 130 times.
✓ Branch 10 taken 130 times.
130 std::cerr << "PGenericParser::loadDirExtraParserFile : can't find <highlighting> </highlighting> balise in file '"<<inputFile<<"'" << std::endl;
700 130 return;
701 }
702
3/3
✓ Branch 1 taken 28522 times.
✓ Branch 4 taken 28522 times.
✓ Branch 7 taken 28522 times.
28522 PString environementName(inputFile.getFileName().eraseExtension());
703
1/1
✓ Branch 1 taken 28522 times.
28522 p_vecNameExtraParser.push_back(environementName);
704
3/3
✓ Branch 1 taken 28522 times.
✓ Branch 4 taken 28522 times.
✓ Branch 7 taken 28522 times.
28522 p_vecNameFunctionExtraParser.push_back("\\" + environementName);
705
3/3
✓ Branch 1 taken 28522 times.
✓ Branch 4 taken 28522 times.
✓ Branch 7 taken 28522 times.
28522 p_vecNameMarkdownExtraParser.push_back("```" + environementName);
706
707
1/1
✓ Branch 1 taken 28522 times.
28522 PParserEnv parserEnv;
708
1/1
✓ Branch 1 taken 28522 times.
28522 parserEnv.setName(environementName);
709
710
1/1
✓ Branch 1 taken 28522 times.
28522 PXml matchPlainText;
711
3/4
✓ Branch 1 taken 28522 times.
✓ Branch 4 taken 28522 times.
✓ Branch 7 taken 28522 times.
✗ Branch 8 not taken.
28522 if(pxml_getChildIfExist(matchPlainText, childXml, "plainText")){
712
3/3
✓ Branch 1 taken 28522 times.
✓ Branch 4 taken 28522 times.
✓ Branch 7 taken 28522 times.
28522 parserEnv.setPlainText(convertBackSlahedStr(pxml_getFullContent(matchPlainText)));
713 }
714 28522 PVecXml listEnv;
715
3/4
✓ Branch 1 taken 28522 times.
✓ Branch 4 taken 28522 times.
✓ Branch 7 taken 28522 times.
✗ Branch 8 not taken.
28522 if(pxml_getVecChildIfExist(listEnv, childXml, "context")){
716
2/2
✓ Branch 4 taken 317033 times.
✓ Branch 5 taken 28522 times.
345555 for(PVecXml::iterator itBalise(listEnv.begin()); itBalise != listEnv.end(); ++itBalise){
717
1/1
✓ Branch 1 taken 317033 times.
317033 PXmlAttr attrClass;
718
3/4
✓ Branch 1 taken 317033 times.
✓ Branch 5 taken 317033 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 317033 times.
317033 if(!pxml_getAttrIfExist(attrClass, *itBalise, "class")){continue;}
719
2/2
✓ Branch 1 taken 317033 times.
✓ Branch 4 taken 317033 times.
317033 PString nameClass(attrClass.getValue());
720
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 317033 times.
317033 if(nameClass == ""){
721 std::cerr << "PGenericParser::loadDirExtraEnvironementFile : expect 'class' in balise" << std::endl;
722 continue;
723 }
724
1/1
✓ Branch 1 taken 317033 times.
317033 PContext tmp;
725
1/1
✓ Branch 1 taken 317033 times.
317033 tmp.setName(nameClass);
726
727
1/1
✓ Branch 1 taken 317033 times.
317033 PXml matchBegin;
728
4/4
✓ Branch 1 taken 317033 times.
✓ Branch 5 taken 317033 times.
✓ Branch 8 taken 144804 times.
✓ Branch 9 taken 172229 times.
317033 if(pxml_getChildIfExist(matchBegin, *itBalise, "begin")){
729
3/3
✓ Branch 1 taken 144804 times.
✓ Branch 4 taken 144804 times.
✓ Branch 7 taken 144804 times.
144804 tmp.setBegin(convertBackSlahedStr(pxml_getFullContent(matchBegin)));
730 }
731
1/1
✓ Branch 1 taken 317033 times.
317033 PXml matchEnd;
732
4/4
✓ Branch 1 taken 317033 times.
✓ Branch 5 taken 317033 times.
✓ Branch 8 taken 144804 times.
✓ Branch 9 taken 172229 times.
317033 if(pxml_getChildIfExist(matchEnd, *itBalise, "end")){
733
3/3
✓ Branch 1 taken 144804 times.
✓ Branch 4 taken 144804 times.
✓ Branch 7 taken 144804 times.
144804 tmp.setEnd(convertBackSlahedStr(pxml_getFullContent(matchEnd)));
734 }
735
1/1
✓ Branch 1 taken 317033 times.
317033 PXml matchNotBeforeBegin;
736
4/4
✓ Branch 1 taken 317033 times.
✓ Branch 5 taken 317033 times.
✓ Branch 8 taken 1097 times.
✓ Branch 9 taken 315936 times.
317033 if(pxml_getChildIfExist(matchNotBeforeBegin, *itBalise, "notBeforeBegin")){
737
3/3
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
✓ Branch 7 taken 1097 times.
1097 tmp.setNotBeforeBegin(convertBackSlahedStr(pxml_getFullContent(matchNotBeforeBegin)));
738 }
739
1/1
✓ Branch 1 taken 317033 times.
317033 PXml matchNotAfterBegin;
740
3/4
✓ Branch 1 taken 317033 times.
✓ Branch 5 taken 317033 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 317033 times.
317033 if(pxml_getChildIfExist(matchNotAfterBegin, *itBalise, "notAfterBegin")){
741 tmp.setNotAfterBegin(convertBackSlahedStr(pxml_getFullContent(matchNotAfterBegin)));
742 }
743
1/1
✓ Branch 1 taken 317033 times.
317033 PXml matchNotBeforEnd;
744
4/4
✓ Branch 1 taken 317033 times.
✓ Branch 5 taken 317033 times.
✓ Branch 8 taken 17552 times.
✓ Branch 9 taken 299481 times.
317033 if(pxml_getChildIfExist(matchNotBeforEnd, *itBalise, "notBeforeEnd")){
745
3/3
✓ Branch 1 taken 17552 times.
✓ Branch 4 taken 17552 times.
✓ Branch 7 taken 17552 times.
17552 tmp.setNotBeforeEnd(convertBackSlahedStr(pxml_getFullContent(matchNotBeforEnd)));
746 }
747 317033 PVecXml listKw;
748
4/4
✓ Branch 1 taken 317033 times.
✓ Branch 5 taken 317033 times.
✓ Branch 8 taken 118476 times.
✓ Branch 9 taken 198557 times.
317033 if(pxml_getVecChildIfExist(listKw, *itBalise, "keyword")){
749
2/2
✓ Branch 3 taken 1892325 times.
✓ Branch 4 taken 118476 times.
2010801 for(PVecXml::iterator it(listKw.begin()); it != listKw.end(); ++it){
750
4/4
✓ Branch 1 taken 1892325 times.
✓ Branch 5 taken 1892325 times.
✓ Branch 8 taken 1892325 times.
✓ Branch 11 taken 1892325 times.
1892325 tmp.getVecKeyword().push_back(convertBackSlahedStr(pxml_getFullContent(*it)));
751 }
752 }
753
754
1/1
✓ Branch 1 taken 317033 times.
317033 PXml matchSequence;
755
4/4
✓ Branch 1 taken 317033 times.
✓ Branch 5 taken 317033 times.
✓ Branch 8 taken 53753 times.
✓ Branch 9 taken 263280 times.
317033 if(pxml_getChildIfExist(matchSequence, *itBalise, "sequence")){
756
1/1
✓ Branch 1 taken 53753 times.
53753 PParseSeq seq;
757
2/3
✓ Branch 1 taken 53753 times.
✓ Branch 3 taken 53753 times.
✗ Branch 4 not taken.
53753 if(loadParserSeq(seq, matchSequence)){
758
1/1
✓ Branch 1 taken 53753 times.
53753 tmp.setSeq(seq);
759 }else{
760 std::cerr << "PGenericParser::loadDirExtraParserFile : can't initialise sequence with balise in file '"<<inputFile<<"'" << std::endl;
761 }
762 53753 }
763
2/2
✓ Branch 1 taken 317033 times.
✓ Branch 4 taken 317033 times.
317033 parserEnv.getVecContext().push_back(tmp);
764
2/4
✓ Branch 9 taken 317033 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 317033 times.
✗ Branch 13 not taken.
317033 }
765
2/2
✓ Branch 1 taken 28522 times.
✓ Branch 4 taken 28522 times.
28522 p_vecExtraParser.getVecEnv().push_back(parserEnv);
766 }
767
2/2
✓ Branch 5 taken 28522 times.
✓ Branch 6 taken 130 times.
28652 }
768
769 ///Load the extra parsers
770 /** @param inputDir : input directory
771 */
772 1097 void PGenericParser::loadDirExtraParser(const PPath & inputDir){
773
1/1
✓ Branch 1 taken 1097 times.
1097 PListFile listInputFile = inputDir.getAllElementInDir();
774
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1097 times.
1097 if(listInputFile.size() == 0lu){
775 std::cerr << "PGenericParser::loadDirExtraParser : can't read directory '"<<inputDir<<"'" << std::endl;
776 return;
777 }
778
2/2
✓ Branch 3 taken 28652 times.
✓ Branch 4 taken 1097 times.
29749 for(PListFile::iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
779
2/2
✓ Branch 2 taken 28652 times.
✓ Branch 5 taken 28652 times.
28652 loadDirExtraParserFile(inputDir / (*it));
780 }
781
1/2
✓ Branch 1 taken 1097 times.
✗ Branch 2 not taken.
1097 }
782
783 ///Load the css
784 /** @param inputDir : input directory
785 */
786 1097 void PGenericParser::loadCss(const PPath & inputDir){
787
1/1
✓ Branch 1 taken 1097 times.
1097 PListFile listInputFile = inputDir.getAllElementInDir();
788
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1097 times.
1097 if(listInputFile.size() == 0lu){
789 std::cerr << "PGenericParser::loadCss : can't read directory '"<<inputDir<<"'" << std::endl;
790 return;
791 }
792
2/2
✓ Branch 4 taken 3421 times.
✓ Branch 5 taken 1097 times.
4518 for(PListFile::iterator it(listInputFile.begin()); it != listInputFile.end(); ++it){
793
3/3
✓ Branch 2 taken 3421 times.
✓ Branch 5 taken 3421 times.
✓ Branch 8 taken 3421 times.
3421 PString styleName(it->getFileName().eraseExtension());
794
1/1
✓ Branch 2 taken 3421 times.
3421 PPath tmpFile(inputDir / (*it));
795
3/3
✓ Branch 1 taken 3421 times.
✓ Branch 4 taken 3421 times.
✓ Branch 7 taken 3421 times.
3421 p_cssContent[styleName] = tmpFile.loadFileContent();
796 3421 }
797
1/2
✓ Branch 1 taken 1097 times.
✗ Branch 2 not taken.
1097 }
798
799 ///Load the map of copied files
800 1097 void PGenericParser::loadMapFile(){
801
1/1
✓ Branch 1 taken 1097 times.
1097 PString fileName(COPIED_RECOVER_FILE);
802
3/3
✓ Branch 1 taken 1097 times.
✓ Branch 3 taken 403 times.
✓ Branch 4 taken 694 times.
1097 if(!data_load(fileName, p_mapCopiedFile)){return;}
803
2/2
✓ Branch 1 taken 694 times.
✓ Branch 2 taken 403 times.
1097 }
804
805 ///Save the map of copied files
806 1095 void PGenericParser::saveMapFile(){
807
1/1
✓ Branch 1 taken 1095 times.
1095 PString fileName(COPIED_RECOVER_FILE);
808
3/3
✓ Branch 1 taken 1095 times.
✓ Branch 3 taken 339 times.
✓ Branch 4 taken 756 times.
1095 if(!data_save(fileName, p_mapCopiedFile)){return;}
809
2/2
✓ Branch 1 taken 756 times.
✓ Branch 2 taken 339 times.
1095 }
810
811 ///Get the absolute path of a file
812 /** @param fileName : file to be used
813 * @return corresponding absolute file name
814 */
815 418 PPath PGenericParser::getAbsoluteFileName(const PPath & fileName){
816
1/1
✓ Branch 1 taken 418 times.
418 PPath fileToBeCopied(fileName);
817
3/3
✓ Branch 1 taken 418 times.
✓ Branch 3 taken 209 times.
✓ Branch 4 taken 209 times.
418 if(!fileToBeCopied.isFileExist()){ //If the fileName does not exists, it is relative to the current parsed file
818
4/4
✓ Branch 1 taken 209 times.
✓ Branch 4 taken 209 times.
✓ Branch 7 taken 209 times.
✓ Branch 10 taken 209 times.
209 fileToBeCopied = p_parser->getFileName().getParentDirectory() / fileName;
819
3/3
✓ Branch 1 taken 209 times.
✓ Branch 3 taken 141 times.
✓ Branch 4 taken 68 times.
209 if(!fileToBeCopied.isFileExist()){ //Il the fileName still does not exists, we have to complain
820
6/6
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✓ Branch 7 taken 141 times.
✓ Branch 10 taken 141 times.
✓ Branch 13 taken 141 times.
✓ Branch 16 taken 141 times.
141 std::cerr << "PGenericParser::getAbsoluteFileName : file '"<<fileName<<"' does not exists, even relative to the current parsed file that gives '"<<fileToBeCopied<<"'" << std::endl;
821
2/2
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
141 return PPath("");
822 }
823 }
824
1/1
✓ Branch 1 taken 277 times.
277 return fileToBeCopied;
825 418 }
826
827 ///Copy a file
828 /** @param outputDir : output directory where to put the input file
829 * @param fileName ; name of the file to be copied
830 * @return the name of the copied file, empty string on fail
831 */
832 412 PPath PGenericParser::copyFile(const PPath & outputDir, const PPath & fileName){
833
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 412 times.
412 if(fileName == ""){
834 std::cerr << "PGenericParser::copyFile : fileName is empty" << std::endl;
835 return PPath("");
836 }
837
1/1
✓ Branch 1 taken 412 times.
412 PPath fileToBeCopied(getAbsoluteFileName(fileName));
838
2/2
✓ Branch 1 taken 141 times.
✓ Branch 2 taken 271 times.
412 if(fileToBeCopied == ""){ //If the fileName does not exists, it is relative to the current parsed file
839
6/6
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✓ Branch 7 taken 141 times.
✓ Branch 10 taken 141 times.
✓ Branch 13 taken 141 times.
✓ Branch 16 taken 141 times.
141 std::cerr << "PGenericParser::copyFile : file '"<<fileName<<"' does not exists, even relative to the current parsed file that gives '"<<fileToBeCopied<<"'" << std::endl;
840
2/2
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
141 return PPath("");
841 }
842
843
2/2
✓ Branch 1 taken 271 times.
✓ Branch 4 taken 271 times.
271 PString baseFileName(fileToBeCopied.getFileName());
844
4/4
✓ Branch 1 taken 271 times.
✓ Branch 4 taken 271 times.
✓ Branch 7 taken 271 times.
✓ Branch 10 taken 271 times.
542 PString linkDir(fileName.getParentDirectory().replace("../", ""));
845
10/10
✓ Branch 1 taken 271 times.
✓ Branch 4 taken 271 times.
✓ Branch 7 taken 271 times.
✓ Branch 10 taken 271 times.
✓ Branch 13 taken 271 times.
✓ Branch 16 taken 271 times.
✓ Branch 19 taken 271 times.
✓ Branch 22 taken 271 times.
✓ Branch 25 taken 271 times.
✓ Branch 28 taken 271 times.
542 PPath buildFileName(outputDir + PPath("/") + linkDir + PPath("/") + baseFileName);
846
847 //Do we know the input file (did we already copy it)
848
1/1
✓ Branch 1 taken 271 times.
271 PMapFile::iterator it(p_mapCopiedFile.find(fileName));
849
2/2
✓ Branch 2 taken 133 times.
✓ Branch 3 taken 138 times.
271 if(it != p_mapCopiedFile.end()){
850 //Let's check if the copied file still exists
851
2/3
✓ Branch 1 taken 133 times.
✓ Branch 3 taken 133 times.
✗ Branch 4 not taken.
133 if(buildFileName.isFileExist()){
852 //Ok, now let's get it's last modification time to be sure
853
1/1
✓ Branch 1 taken 133 times.
133 time_t currentModifTime = fileToBeCopied.getFileModificationTime();
854 //Now let's check if it is the same one
855
3/6
✓ Branch 1 taken 133 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 133 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 133 times.
✗ Branch 6 not taken.
133 if(currentModifTime == it->second && currentModifTime > 0){ //negative value is an error
856 //Ok, no need to copy, we already did it and the file if up to date
857
5/5
✓ Branch 1 taken 133 times.
✓ Branch 4 taken 133 times.
✓ Branch 7 taken 133 times.
✓ Branch 10 taken 133 times.
✓ Branch 13 taken 133 times.
133 std::cout << "PGenericParser::copyFile : no need to copy file '"<<fileName<<"' already updated at time " << currentModifTime << std::endl;
858
1/1
✓ Branch 1 taken 133 times.
133 return buildFileName;
859 }
860 }
861 }
862
863
2/3
✓ Branch 1 taken 138 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
138 if(linkDir != ""){ //If there is other directories
864 if(!PPath(outputDir + "/" + linkDir).createDirectory()){
865 std::cerr << "PGenericParser::copyFile : cannot create directory '"<<(outputDir + "/" + linkDir)<<"'" << std::endl;
866 return PPath("");
867 }
868 }else{
869
2/3
✓ Branch 1 taken 138 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
138 if(!outputDir.createDirectory()){
870 std::cerr << "PGenericParser::copyFile : cannot create directory '"<<outputDir<<"'" << std::endl;
871 return PPath("");
872 }
873 }
874
875 //Set the modification time
876
1/1
✓ Branch 1 taken 138 times.
138 time_t lastModifTime = fileToBeCopied.getFileModificationTime();
877
878
4/4
✓ Branch 1 taken 138 times.
✓ Branch 4 taken 138 times.
✓ Branch 7 taken 138 times.
✓ Branch 10 taken 138 times.
276 PString command("cp "+fileToBeCopied+" " + buildFileName);
879
2/3
✓ Branch 2 taken 138 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 138 times.
138 if(system(command.c_str()) != 0){
880 errorAt();
881 std::cerr << "PGenericParser::copyFile : can't copy file '"<<fileToBeCopied<<"' into '"<<buildFileName<<"' directory" << std::endl;
882 stopParsing();
883 return PPath("");
884 }
885 // std::cout << "PGenericParser::copyFile : copy file '"<<fileToBeCopied<<"' at time " << lastModifTime << std::endl;
886
1/1
✓ Branch 1 taken 138 times.
138 p_mapCopiedFile[fileToBeCopied] = lastModifTime;
887
1/1
✓ Branch 1 taken 138 times.
138 return buildFileName;
888 412 }
889
890 ///Initialisation function of the class PGenericParser
891 /** @param baseInstallPrefix : installation prefix
892 */
893 1097 void PGenericParser::initialisationPGenericParser(const PString & baseInstallPrefix){
894 1097 p_isDebugMode = false;
895
1/1
✓ Branch 1 taken 1097 times.
1097 p_currentText.setType(PLatexType::TEXT);
896
1/1
✓ Branch 1 taken 1097 times.
1097 p_currentSource.setType(PLatexType::FILE);
897
898
1/1
✓ Branch 1 taken 1097 times.
1097 PString installPrefix(CMAKE_INSTALL_PREFIX);
899
3/3
✓ Branch 1 taken 1097 times.
✓ Branch 3 taken 130 times.
✓ Branch 4 taken 967 times.
1097 if(baseInstallPrefix != ""){
900
1/1
✓ Branch 1 taken 130 times.
130 installPrefix = baseInstallPrefix;
901 }
902
903
3/3
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
✓ Branch 7 taken 1097 times.
2194 PPath dirExtraEnv(installPrefix+"/share/PhoenixTex2Html/ENVIRONEMENT");
904
1/1
✓ Branch 1 taken 1097 times.
1097 loadDirExtraEnvironement(dirExtraEnv);
905
906
3/3
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
✓ Branch 7 taken 1097 times.
2194 PPath dirExtraFunction(installPrefix+"/share/PhoenixTex2Html/FUNCTION");
907
1/1
✓ Branch 1 taken 1097 times.
1097 loadDirExtraFunction(dirExtraFunction);
908
909
3/3
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
✓ Branch 7 taken 1097 times.
2194 PPath dirExtraParser(installPrefix+"/share/PhoenixTex2Html/PARSER");
910
1/1
✓ Branch 1 taken 1097 times.
1097 loadDirExtraParser(dirExtraParser);
911
912
3/3
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
✓ Branch 7 taken 1097 times.
2194 PPath dirCss(installPrefix+"/share/PhoenixTex2Html/STYLE");
913
1/1
✓ Branch 1 taken 1097 times.
1097 loadCss(dirCss);
914
915
2/2
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
1097 p_vecRemoveLatexKeyword.push_back("\\toprule");
916
2/2
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
1097 p_vecRemoveLatexKeyword.push_back("\\midrule");
917
2/2
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
1097 p_vecRemoveLatexKeyword.push_back("\\bottomrule");
918
2/2
✓ Branch 1 taken 1097 times.
✓ Branch 4 taken 1097 times.
1097 p_vecRemoveLatexKeyword.push_back("\\hline");
919
1/1
✓ Branch 1 taken 1097 times.
1097 loadMapFile();
920
921
1/1
✓ Branch 1 taken 1097 times.
1097 p_bookSideBarWidth = "300px";
922 1097 p_isEnableBookFeedback = false;
923
924
1/1
✓ Branch 1 taken 1097 times.
1097 p_bookMainPageLink.setType(PLatexType::NONE); //None by default, type will be updated on update
925 1097 }
926
927
928
929
930
931