|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "main.h" |
|
22 #include "localise.h" |
|
23 |
|
24 #ifdef __VC32__ |
|
25 #pragma warning( push, 1 ) // MS STL libraries do not compile cleanly, temporarily set warning level to 1 |
|
26 #pragma warning( disable : 4710 ) // function not inlined. |
|
27 #pragma warning( disable : 4530 ) // function not inlined. |
|
28 #endif |
|
29 |
|
30 #include <cstdio> |
|
31 #include <iostream> |
|
32 #include "ERRORHAN.H" |
|
33 #include <cstring> |
|
34 #include <cstdlib> |
|
35 |
|
36 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
37 using std::ifstream; |
|
38 using std::cerr; |
|
39 using std::endl; |
|
40 #endif //__MSVCDOTNET__ |
|
41 |
|
42 |
|
43 |
|
44 /****************************************************************************************** |
|
45 ** |
|
46 ** RlsItemRequirements |
|
47 ** |
|
48 ******************************************************************************************/ |
|
49 |
|
50 RlsItemRequirements::RlsItemRequirements(String aRlsName, int aRequirement) |
|
51 :iRlsName(aRlsName), |
|
52 iRequirement(aRequirement) |
|
53 {} |
|
54 |
|
55 RlsItemRequirements::RlsItemRequirements(const RlsItemRequirements & aRlsItemRequirements) |
|
56 :iRlsName(aRlsItemRequirements.iRlsName), |
|
57 iRequirement(aRlsItemRequirements.iRequirement) |
|
58 {} |
|
59 |
|
60 RlsItemRequirements::~RlsItemRequirements() |
|
61 {} |
|
62 |
|
63 /****************************************************************************************** |
|
64 ** |
|
65 ** CommandRequirementsHolder |
|
66 ** |
|
67 ******************************************************************************************/ |
|
68 |
|
69 CommandRequirementsHolder::CommandRequirementsHolder(String aCommandName) |
|
70 :iCommandName(aCommandName) |
|
71 { |
|
72 iRlsRequirements.clear(); |
|
73 } |
|
74 |
|
75 CommandRequirementsHolder::CommandRequirementsHolder(const CommandRequirementsHolder & aCommandRequirmentsHolder) |
|
76 :iCommandName(aCommandRequirmentsHolder.iCommandName) |
|
77 { |
|
78 for(unsigned int j = 0; j < aCommandRequirmentsHolder.iRlsRequirements.size() ; j++) |
|
79 { |
|
80 iRlsRequirements.push_back(aCommandRequirmentsHolder.iRlsRequirements[j]); |
|
81 } |
|
82 } |
|
83 |
|
84 CommandRequirementsHolder::~CommandRequirementsHolder() |
|
85 {} |
|
86 |
|
87 /****************************************************************************************** |
|
88 ** |
|
89 ** TagParameterData |
|
90 ** |
|
91 ******************************************************************************************/ |
|
92 |
|
93 TagParameterData::TagParameterData(String aTagParameter) |
|
94 :iTagParameter(aTagParameter) |
|
95 {} |
|
96 |
|
97 TagParameterData::TagParameterData(const TagParameterData & aTagParameterData) |
|
98 :iTagParameter(aTagParameterData.iTagParameter) |
|
99 {} |
|
100 |
|
101 TagParameterData::~TagParameterData() |
|
102 {} |
|
103 |
|
104 void TagParameterData::SetTagParameter(String aTagParameter) |
|
105 { |
|
106 iTagParameter = aTagParameter; |
|
107 } |
|
108 |
|
109 String TagParameterData::GetTagParameter() |
|
110 { |
|
111 return iTagParameter; |
|
112 } |
|
113 |
|
114 /****************************************************************************************** |
|
115 ** |
|
116 ** CommentRequirement |
|
117 ** |
|
118 ******************************************************************************************/ |
|
119 |
|
120 CommentRequirement::CommentRequirement(int aRequirementStatus, String aDefaultParameter) |
|
121 :iRequirementStatus(aRequirementStatus), |
|
122 iDefaultParameter(aDefaultParameter) |
|
123 { |
|
124 } |
|
125 |
|
126 CommentRequirement::CommentRequirement(const CommentRequirement & aCommentRequirement) |
|
127 :iRequirementStatus(aCommentRequirement.iRequirementStatus), |
|
128 iDefaultParameter(aCommentRequirement.iDefaultParameter) |
|
129 { |
|
130 } |
|
131 |
|
132 CommentRequirement::~CommentRequirement() |
|
133 {} |
|
134 |
|
135 String CommentRequirement::GetDefault() |
|
136 { |
|
137 return iDefaultParameter; |
|
138 } |
|
139 |
|
140 int CommentRequirement::GetRequirementStatus() |
|
141 { |
|
142 return iRequirementStatus; |
|
143 } |
|
144 |
|
145 /****************************************************************************************** |
|
146 ** |
|
147 ** CommentRequirementPair |
|
148 ** |
|
149 ******************************************************************************************/ |
|
150 |
|
151 CommentRequirementPair::CommentRequirementPair(String aRlsItem, int aStatus, String aDefault) |
|
152 :iRlsItem(aRlsItem), |
|
153 iCommentRequirementData(aStatus, aDefault) |
|
154 { |
|
155 } |
|
156 |
|
157 CommentRequirementPair::CommentRequirementPair(const CommentRequirementPair & aCommentRequirementPair) |
|
158 :iRlsItem(aCommentRequirementPair.iRlsItem), |
|
159 iCommentRequirementData(aCommentRequirementPair.iCommentRequirementData) |
|
160 {} |
|
161 |
|
162 CommentRequirementPair::~CommentRequirementPair() |
|
163 {} |
|
164 |
|
165 int CommentRequirementPair::GetRequirementStatus() |
|
166 { |
|
167 return iCommentRequirementData.GetRequirementStatus(); |
|
168 } |
|
169 |
|
170 String CommentRequirementPair::CheckIfOptionalAndHasDefault(String aRlsTypeName, String aCommandName) |
|
171 { // returns a String containing a line which needs to be written out to the rpp file, or returns "" |
|
172 String optionalLineToAdd = ""; |
|
173 if(iRlsItem == aRlsTypeName) |
|
174 { |
|
175 int requirementStatus = iCommentRequirementData.GetRequirementStatus(); |
|
176 if(requirementStatus == EOptionalWithDefault) |
|
177 { |
|
178 String defaultValue = iCommentRequirementData.GetDefault(); |
|
179 if(defaultValue.Length()) // will only return true if a default exists |
|
180 { |
|
181 optionalLineToAdd = "@"; |
|
182 optionalLineToAdd += aCommandName; |
|
183 String tempString(" "); |
|
184 optionalLineToAdd += tempString; |
|
185 optionalLineToAdd += defaultValue; |
|
186 tempString = "\n"; |
|
187 optionalLineToAdd += tempString; |
|
188 } |
|
189 } |
|
190 } |
|
191 return optionalLineToAdd; |
|
192 } |
|
193 |
|
194 String CommentRequirementPair::GetRlsItem() |
|
195 { |
|
196 return iRlsItem; |
|
197 } |
|
198 |
|
199 void CommentRequirementPair::SetRlsItem(String aRlsItem) |
|
200 { |
|
201 iRlsItem = aRlsItem; |
|
202 } |
|
203 |
|
204 /****************************************************************************************** |
|
205 ** |
|
206 ** CommentTag |
|
207 ** |
|
208 ******************************************************************************************/ |
|
209 |
|
210 CommentTag::CommentTag(String aTagType, bool aTagDeclared) |
|
211 :iTagDeclared( aTagDeclared ), |
|
212 iParameterType( aTagType ) |
|
213 { |
|
214 iPermissibleParameters.clear(); |
|
215 iRequirements.clear(); |
|
216 } |
|
217 |
|
218 CommentTag::CommentTag(const CommentTag & aCommentTag) |
|
219 :iTagDeclared( aCommentTag.iTagDeclared ), |
|
220 iParameterType( aCommentTag.iParameterType ) |
|
221 { |
|
222 unsigned int j; |
|
223 for(j=0; j< aCommentTag.iPermissibleParameters.size(); j++) |
|
224 { |
|
225 iPermissibleParameters.push_back(aCommentTag.iPermissibleParameters[j]); |
|
226 } |
|
227 for(j=0; j< aCommentTag.iRequirements.size(); j++) |
|
228 { |
|
229 iRequirements.push_back(aCommentTag.iRequirements[j]); |
|
230 } |
|
231 } |
|
232 |
|
233 CommentTag::~CommentTag() |
|
234 {} |
|
235 |
|
236 String CommentTag::CheckIfOptionalAndHasDefault(String aRlsTypeName, String aCommandName) |
|
237 { |
|
238 if(iTagDeclared) |
|
239 { |
|
240 for(unsigned int j=0; j<iRequirements.size(); j++) |
|
241 { |
|
242 String defaultParameter = iRequirements[j].CheckIfOptionalAndHasDefault(aRlsTypeName, aCommandName); |
|
243 if(defaultParameter.Length()) |
|
244 return defaultParameter; // returns default parameter if it exists |
|
245 } |
|
246 } |
|
247 return ""; // returns "" if no default parameter exists |
|
248 } |
|
249 |
|
250 int CommentTag::GetRequirementStatus(String aRlsItem) |
|
251 { |
|
252 for(unsigned int j=0; j<iRequirements.size(); j++) |
|
253 { |
|
254 if(iRequirements[j].GetRlsItem() == aRlsItem) |
|
255 { |
|
256 int requirementStatus = iRequirements[j].GetRequirementStatus(); |
|
257 return requirementStatus; |
|
258 } |
|
259 } |
|
260 return EForbidden; |
|
261 } |
|
262 |
|
263 bool CommentTag::IsTagLegalForRlsType(String aRlsTypeName) |
|
264 { |
|
265 for(unsigned int j=0; j<iRequirements.size(); j++) |
|
266 { |
|
267 if(iRequirements[j].GetRlsItem() == aRlsTypeName) |
|
268 { |
|
269 return iRequirements[j].GetRequirementStatus() != EForbidden ? true : false; |
|
270 } |
|
271 } |
|
272 return false; |
|
273 } |
|
274 |
|
275 bool CommentTag::IsParameterAlreadyDeclared(String aTagParameter) |
|
276 { |
|
277 for(int j=0; j<GetNumberOfPermissibleParameters(); j++) |
|
278 { |
|
279 if(iPermissibleParameters[j].GetTagParameter() == aTagParameter) |
|
280 { |
|
281 return true; // returns true if the given parameter is already declared |
|
282 } |
|
283 } |
|
284 return false; |
|
285 } |
|
286 |
|
287 String CommentTag::GetPermissibleParameter(int aIndex) // returns pointer to aIndex-th parameter |
|
288 { |
|
289 return iPermissibleParameters[aIndex].GetTagParameter(); |
|
290 } |
|
291 |
|
292 int CommentTag::GetNumberOfPermissibleParameters() |
|
293 { |
|
294 return iPermissibleParameters.size(); |
|
295 } |
|
296 |
|
297 bool CommentTag::IsTagDeclared() |
|
298 { |
|
299 return iTagDeclared; |
|
300 } |
|
301 |
|
302 void CommentTag::SetDeclared() |
|
303 { |
|
304 iTagDeclared = true; |
|
305 } |
|
306 |
|
307 |
|
308 void CommentTag::SetParameterType(String aParameterType) |
|
309 { |
|
310 iParameterType = aParameterType; |
|
311 } |
|
312 |
|
313 String CommentTag::GetParameterType() |
|
314 { |
|
315 return iParameterType; |
|
316 } |
|
317 |
|
318 void CommentTag::AddTagParameterData(String aTagParameterData) |
|
319 { |
|
320 TagParameterData dataToAdd( aTagParameterData ); |
|
321 iPermissibleParameters.push_back( dataToAdd ); |
|
322 } |
|
323 |
|
324 void CommentTag::AddRequirements(String aRlsItem, int aRequired, String aDefault) |
|
325 { |
|
326 CommentRequirementPair commentRequirementPair( aRlsItem, aRequired, aDefault ); |
|
327 iRequirements.push_back( commentRequirementPair ); |
|
328 } |
|
329 |
|
330 /****************************************************************************************** |
|
331 ** |
|
332 ** CommentTag |
|
333 ** |
|
334 ******************************************************************************************/ |
|
335 |
|
336 CommentTagPair::CommentTagPair(String aCommandName, String aParameterType, bool aTagDeclared) |
|
337 :iCommandName(aCommandName), |
|
338 iTagVariables(aParameterType, aTagDeclared) |
|
339 {} |
|
340 |
|
341 CommentTagPair::CommentTagPair(const CommentTagPair & aCommentTagPair) |
|
342 :iCommandName(aCommentTagPair.iCommandName), |
|
343 iTagVariables(aCommentTagPair.iTagVariables) |
|
344 {} |
|
345 |
|
346 CommentTagPair::~CommentTagPair() |
|
347 {} |
|
348 |
|
349 String CommentTagPair::CheckIfOptionalAndHasDefault(String aRlsTypeName) |
|
350 { |
|
351 return iTagVariables.CheckIfOptionalAndHasDefault(aRlsTypeName, iCommandName); |
|
352 } |
|
353 |
|
354 int CommentTagPair::GetRequirementStatus(String aRlsItem) |
|
355 { |
|
356 return iTagVariables.GetRequirementStatus( aRlsItem ); |
|
357 } |
|
358 |
|
359 bool CommentTagPair::IsTagLegalForRlsType(String aRlsTypeName) |
|
360 { |
|
361 return iTagVariables.IsTagLegalForRlsType(aRlsTypeName); |
|
362 } |
|
363 |
|
364 bool CommentTagPair::IsParameterAlreadyDeclared(String aTagParameter) |
|
365 { |
|
366 return iTagVariables.IsParameterAlreadyDeclared(aTagParameter); |
|
367 } |
|
368 |
|
369 String CommentTagPair::GetPermissibleParameter(int aIndex) |
|
370 { |
|
371 return iTagVariables.GetPermissibleParameter(aIndex); |
|
372 } |
|
373 |
|
374 int CommentTagPair::GetNumberOfPermissibleParameters() |
|
375 { |
|
376 return iTagVariables.GetNumberOfPermissibleParameters(); |
|
377 } |
|
378 |
|
379 void CommentTagPair::SetCommandName(String aCommandName) |
|
380 { |
|
381 iCommandName = aCommandName; |
|
382 } |
|
383 |
|
384 String CommentTagPair::GetCommandName() |
|
385 { |
|
386 return iCommandName; |
|
387 } |
|
388 |
|
389 void CommentTagPair::SetTagDeclared() |
|
390 { |
|
391 iTagVariables.SetDeclared(); |
|
392 } |
|
393 |
|
394 bool CommentTagPair::TagDeclared() |
|
395 { |
|
396 return iTagVariables.IsTagDeclared(); |
|
397 } |
|
398 |
|
399 String CommentTagPair::GetParameterType() |
|
400 { |
|
401 return iTagVariables.GetParameterType(); |
|
402 } |
|
403 |
|
404 void CommentTagPair::AddPermissibleParameter(String aPermissibleParameter) |
|
405 { |
|
406 iTagVariables.AddTagParameterData( aPermissibleParameter ); |
|
407 } |
|
408 |
|
409 void CommentTagPair::AddRlsItem(String aRlsItem, int aRequired, String aDefault) |
|
410 { |
|
411 iTagVariables.AddRequirements(aRlsItem, aRequired, aDefault); |
|
412 } |
|
413 |
|
414 /****************************************************************************************** |
|
415 ** |
|
416 ** LocalisationLine |
|
417 ** |
|
418 ******************************************************************************************/ |
|
419 |
|
420 LocalisationLine::LocalisationLine(String aFileName, int aFirstLine) |
|
421 :iAnalysed(false), |
|
422 iFirstLine(aFirstLine), |
|
423 iLastLine(aFirstLine), |
|
424 iFileName(aFileName) |
|
425 { |
|
426 iData.clear(); |
|
427 } |
|
428 |
|
429 LocalisationLine::LocalisationLine(const LocalisationLine & aLocalisationLine) |
|
430 :iAnalysed(aLocalisationLine.iAnalysed), |
|
431 iFirstLine(aLocalisationLine.iFirstLine), |
|
432 iLastLine(aLocalisationLine.iLastLine), |
|
433 iFileName(aLocalisationLine.iFileName) |
|
434 { |
|
435 for(unsigned int j=0; j<aLocalisationLine.iData.size(); j++) |
|
436 { |
|
437 iData.push_back(aLocalisationLine.iData[j]); |
|
438 } |
|
439 } |
|
440 |
|
441 LocalisationLine::~LocalisationLine() |
|
442 {} |
|
443 |
|
444 void LocalisationLine::Reset(String aFileName, int aFirstLine) |
|
445 { |
|
446 iFirstLine = aFirstLine; |
|
447 iLastLine = aFirstLine; |
|
448 iFileName = aFileName; |
|
449 iAnalysed = false; |
|
450 iData.clear(); |
|
451 } |
|
452 |
|
453 String LocalisationLine::GetFileName() |
|
454 { |
|
455 return iFileName; |
|
456 } |
|
457 |
|
458 int LocalisationLine::GetFirstLine() |
|
459 { |
|
460 return iFirstLine; |
|
461 } |
|
462 |
|
463 int LocalisationLine::GetLastLine() |
|
464 { |
|
465 return iLastLine; |
|
466 } |
|
467 |
|
468 void LocalisationLine::SetFirstLine(int aFirstLine) |
|
469 { |
|
470 iFirstLine = aFirstLine; |
|
471 } |
|
472 |
|
473 void LocalisationLine::SetFileName(String aFileName) |
|
474 { |
|
475 iFileName = aFileName; |
|
476 } |
|
477 |
|
478 unsigned int LocalisationLine::GetNumberOfTokens() |
|
479 { |
|
480 return iData.size(); |
|
481 } |
|
482 |
|
483 String LocalisationLine::GetElement(unsigned int aIndex) |
|
484 { |
|
485 return iData[aIndex]; |
|
486 } |
|
487 |
|
488 void LocalisationLine::AddElement(String aElement) |
|
489 { |
|
490 iData.push_back(aElement); |
|
491 } |
|
492 |
|
493 void LocalisationLine::SetLastLine(int aLastLine) |
|
494 { |
|
495 iLastLine = aLastLine; |
|
496 } |
|
497 |
|
498 void LocalisationLine::SetAnalysed(bool aParity) |
|
499 { |
|
500 iAnalysed = aParity; |
|
501 } |
|
502 |
|
503 void LocalisationLine::Empty() |
|
504 { |
|
505 iData.clear(); |
|
506 } |
|
507 |
|
508 bool LocalisationLine::IsLineAnalysed() |
|
509 { |
|
510 return iAnalysed; |
|
511 } |
|
512 |
|
513 /****************************************************************************************** |
|
514 ** |
|
515 ** LocalisationComment |
|
516 ** |
|
517 ******************************************************************************************/ |
|
518 |
|
519 |
|
520 LocalisationComment::LocalisationComment(LocalisationLine & aComment) |
|
521 :iOriginalData(aComment) |
|
522 { |
|
523 iData.clear(); |
|
524 iOptionalLinesToAdd.clear(); |
|
525 } |
|
526 |
|
527 LocalisationComment::~LocalisationComment() |
|
528 { |
|
529 } |
|
530 |
|
531 String LocalisationComment::GetFileName() |
|
532 { |
|
533 return iOriginalData.GetFileName(); |
|
534 } |
|
535 |
|
536 int LocalisationComment::GetFirstLineOfComment() |
|
537 { |
|
538 return iOriginalData.GetFirstLine(); |
|
539 } |
|
540 |
|
541 int LocalisationComment::GetLastLineOfComment() |
|
542 { |
|
543 return iOriginalData.GetLastLine(); |
|
544 } |
|
545 |
|
546 int LocalisationComment::GetNumberOfOptionalLinesToAdd() |
|
547 { |
|
548 return iOptionalLinesToAdd.size(); |
|
549 } |
|
550 |
|
551 unsigned int LocalisationComment::GetNumberOfTokensInComment() |
|
552 { |
|
553 return iOriginalData.GetNumberOfTokens(); |
|
554 } |
|
555 |
|
556 String LocalisationComment::GetOriginalElement(unsigned int aIndex) |
|
557 { |
|
558 return iOriginalData.GetElement(aIndex); |
|
559 } |
|
560 |
|
561 void LocalisationComment::AddDataLine(LocalisationLine aDataLine) |
|
562 { |
|
563 iData.push_back( aDataLine ); |
|
564 } |
|
565 |
|
566 unsigned int LocalisationComment::GetNumberOfTokensInLine(unsigned int aIndex) |
|
567 { |
|
568 return iData[aIndex].GetNumberOfTokens(); |
|
569 } |
|
570 |
|
571 LocalisationLine LocalisationComment::GetLine(unsigned int aIndex) |
|
572 { |
|
573 return iData[aIndex]; |
|
574 } |
|
575 |
|
576 void LocalisationComment::SetAnalysed(unsigned int aIndex, bool aParity) |
|
577 { |
|
578 iData[aIndex].SetAnalysed(aParity); |
|
579 } |
|
580 |
|
581 void LocalisationComment::SetLastLine(int aLineNumber) |
|
582 { |
|
583 iOriginalData.SetLastLine(aLineNumber); |
|
584 } |
|
585 |
|
586 bool LocalisationComment::IsLineAnalysed(unsigned int aIndex) |
|
587 { |
|
588 return iData[aIndex].IsLineAnalysed(); |
|
589 } |
|
590 |
|
591 void LocalisationComment::SetWholeTagAnalysed(bool aParity) |
|
592 { |
|
593 iOriginalData.SetAnalysed(aParity); |
|
594 } |
|
595 |
|
596 String LocalisationComment::GetElementFromLine(unsigned int aLine, unsigned int aElement) |
|
597 { |
|
598 return iData[aLine].GetElement(aElement); |
|
599 } |
|
600 |
|
601 int LocalisationComment::GetFirstLine(unsigned int aIndex) |
|
602 { |
|
603 return iData[aIndex].GetFirstLine(); |
|
604 } |
|
605 |
|
606 void LocalisationComment::AddOptionalData(String aOptionalData) |
|
607 { |
|
608 iOptionalLinesToAdd.push_back(aOptionalData); |
|
609 } |
|
610 |
|
611 String LocalisationComment::GetOptionalLineToAdd(unsigned int aLine) |
|
612 { |
|
613 return iOptionalLinesToAdd[aLine]; |
|
614 } |
|
615 |
|
616 unsigned int LocalisationComment::GetNumberOfLinesInComment() |
|
617 { |
|
618 return iData.size(); |
|
619 } |
|
620 |
|
621 /****************************************************************************************** |
|
622 ** |
|
623 ** WarningToOutput |
|
624 ** |
|
625 ******************************************************************************************/ |
|
626 |
|
627 WarningToOutput::WarningToOutput(const String aFileName, int aLineNumber, String aComment) |
|
628 :iFileName(aFileName), |
|
629 iLineNumber(aLineNumber), |
|
630 iComment(aComment) |
|
631 {} |
|
632 |
|
633 WarningToOutput::WarningToOutput(const WarningToOutput & aWarningToOutput) |
|
634 :iFileName(aWarningToOutput.iFileName), |
|
635 iLineNumber(aWarningToOutput.iLineNumber), |
|
636 iComment(aWarningToOutput.iComment) |
|
637 {} |
|
638 |
|
639 WarningToOutput::~WarningToOutput() |
|
640 {} |
|
641 |
|
642 const String WarningToOutput::GetFileName() |
|
643 { |
|
644 return iFileName; |
|
645 } |
|
646 |
|
647 int WarningToOutput::GetLineNumber() |
|
648 { |
|
649 return iLineNumber; |
|
650 } |
|
651 |
|
652 String WarningToOutput::GetComment() |
|
653 { |
|
654 return iComment; |
|
655 } |
|
656 |
|
657 WarningToOutput& WarningToOutput::operator=(const WarningToOutput& aWarningToOutput) |
|
658 { |
|
659 if(&aWarningToOutput==this) |
|
660 return *this; |
|
661 iFileName = aWarningToOutput.iFileName; |
|
662 iLineNumber = aWarningToOutput.iLineNumber; |
|
663 iComment = aWarningToOutput.iComment; |
|
664 return *this; |
|
665 } |
|
666 |
|
667 /****************************************************************************************** |
|
668 ** |
|
669 ** GlobalLocalisationData |
|
670 ** |
|
671 ******************************************************************************************/ |
|
672 |
|
673 GlobalLocalisationData::GlobalLocalisationData() |
|
674 :iCommentStarted(true) |
|
675 { |
|
676 iTypes[0] = "single"; |
|
677 iTypes[1] = "multiple"; |
|
678 iTypes[2] = "void"; |
|
679 iTypes[3] = "text"; |
|
680 iRlsTypes[0] = "rls_string"; |
|
681 iRlsTypes[1] = "rls_string8"; |
|
682 iRlsTypes[2] = "rls_byte"; |
|
683 iRlsTypes[3] = "rls_word"; |
|
684 iRlsTypes[4] = "rls_long"; |
|
685 iRlsTypes[5] = "rls_double"; |
|
686 iRlsTypes[6] = "RESOURCE"; |
|
687 iCommentTagStore.clear(); |
|
688 iCommentDefinitions.clear(); |
|
689 iWarningStore.clear(); |
|
690 } |
|
691 |
|
692 GlobalLocalisationData::~GlobalLocalisationData() |
|
693 { |
|
694 } |
|
695 |
|
696 int GlobalLocalisationData::NeedToAddDefaultData(String aFileName, int aFileLine) |
|
697 { |
|
698 for(unsigned int j=0; j<iCommentTagStore.size(); j++) |
|
699 { |
|
700 String fileName = iCommentTagStore[j].GetFileName(); |
|
701 if(fileName == aFileName) |
|
702 { |
|
703 int lastLine = iCommentTagStore[j].GetLastLineOfComment(); |
|
704 if(lastLine == aFileLine) |
|
705 { |
|
706 if(iCommentTagStore[j].GetNumberOfOptionalLinesToAdd()) |
|
707 return j; // returns the index of the localisation comment which needs default data adding |
|
708 else |
|
709 return -1; // if default data doesn't need adding for this rls item then returns -1 |
|
710 } |
|
711 } |
|
712 } |
|
713 return -1; |
|
714 } |
|
715 |
|
716 void GlobalLocalisationData::AddCommentToStore() |
|
717 { |
|
718 LocalisationComment aLocalisationComment( iTempCommentStore ); |
|
719 iCommentTagStore.push_back(aLocalisationComment); |
|
720 } |
|
721 |
|
722 void GlobalLocalisationData::SetStart(String aFileName, int aLineNumber) |
|
723 { |
|
724 if(iCommentStarted == false) //means that any time other than first time, contents will be added to Store |
|
725 { |
|
726 AddCommentToStore(); |
|
727 iTempCommentStore.Reset(aFileName, aLineNumber); // empties the temporary comment store |
|
728 } |
|
729 else |
|
730 { |
|
731 iTempCommentStore.SetFirstLine( aLineNumber ); |
|
732 iTempCommentStore.SetFileName( aFileName ); |
|
733 } |
|
734 iCommentStarted = false; |
|
735 } |
|
736 |
|
737 void GlobalLocalisationData::AnalyseLocalisationData() |
|
738 { |
|
739 for(unsigned int i = 0; i < iCommentTagStore.size(); i++) |
|
740 { |
|
741 ParseCommentTags(i); |
|
742 } |
|
743 CheckIfCommentTagsFullyAnalysed(); |
|
744 CheckRlsEntries(); |
|
745 } |
|
746 |
|
747 void GlobalLocalisationData::ParseCommentTags(unsigned int i) |
|
748 { |
|
749 LocalisationLine tagCommandLine; |
|
750 int newLinesSeen = 0; |
|
751 int currentIndex; |
|
752 int state = EStartOfComment; |
|
753 tagCommandLine.SetFileName(iCommentTagStore[i].GetFileName()); |
|
754 int startLineNumber = iCommentTagStore[i].GetFirstLineOfComment(); |
|
755 |
|
756 // parse all the comment tags to find definitions and values |
|
757 unsigned int originalNumberOfTokensInComment = iCommentTagStore[i].GetNumberOfTokensInComment(); |
|
758 for(unsigned int j = 0; j < originalNumberOfTokensInComment; j++) |
|
759 { |
|
760 bool wordIsNewLine = iCommentTagStore[i].GetOriginalElement(j) == "\n" ? true : false; |
|
761 |
|
762 switch(state) |
|
763 { |
|
764 case(EStartOfComment): |
|
765 switch(wordIsNewLine) |
|
766 { |
|
767 case(true): |
|
768 state = ENewLineAtStart; |
|
769 newLinesSeen++; |
|
770 break; |
|
771 default: |
|
772 state = EAfterFirstWordOfTag; |
|
773 tagCommandLine.SetFirstLine(startLineNumber + newLinesSeen); |
|
774 tagCommandLine.SetLastLine(tagCommandLine.GetFirstLine()); |
|
775 tagCommandLine.AddElement(iCommentTagStore[i].GetOriginalElement(j)); |
|
776 } |
|
777 break; |
|
778 case(EAfterFirstWordOfTag): |
|
779 switch(wordIsNewLine) |
|
780 { |
|
781 case(true): |
|
782 state = ENewLineInTag; |
|
783 newLinesSeen++; |
|
784 break; |
|
785 default: |
|
786 state = EInTag; |
|
787 tagCommandLine.AddElement( iCommentTagStore[i].GetOriginalElement(j) ); |
|
788 } |
|
789 break; |
|
790 case(ENewLineAtStart): |
|
791 switch(wordIsNewLine) |
|
792 { |
|
793 case(true): |
|
794 newLinesSeen++; |
|
795 break; |
|
796 default: |
|
797 state = EAfterFirstWordOfTag; |
|
798 tagCommandLine.SetFirstLine(startLineNumber + newLinesSeen); |
|
799 tagCommandLine.SetLastLine( tagCommandLine.GetFirstLine() ); |
|
800 tagCommandLine.AddElement( iCommentTagStore[i].GetOriginalElement(j) ); |
|
801 } |
|
802 break; |
|
803 case(EInTag): |
|
804 switch(wordIsNewLine) |
|
805 { |
|
806 case(true): |
|
807 state = ENewLineInTag; |
|
808 newLinesSeen++; |
|
809 break; |
|
810 default: |
|
811 state = EInTag; |
|
812 tagCommandLine.AddElement( iCommentTagStore[i].GetOriginalElement(j) ); |
|
813 } |
|
814 break; |
|
815 case(ENewLineInTag): |
|
816 { |
|
817 if(wordIsNewLine) |
|
818 { |
|
819 newLinesSeen++; |
|
820 } |
|
821 else if( iCommentTagStore[i].GetOriginalElement(j).FindSubString("@")==0) |
|
822 { |
|
823 iCommentTagStore[i].AddDataLine( tagCommandLine ); |
|
824 currentIndex = iCommentTagStore[i].GetNumberOfLinesInComment()-1; |
|
825 Process(i, currentIndex); |
|
826 tagCommandLine.Empty(); |
|
827 tagCommandLine.AddElement(iCommentTagStore[i].GetOriginalElement(j)); |
|
828 tagCommandLine.SetFirstLine( startLineNumber + newLinesSeen ); |
|
829 tagCommandLine.SetLastLine( tagCommandLine.GetFirstLine() ); |
|
830 state = EAfterFirstWordOfTag; |
|
831 } |
|
832 else |
|
833 { |
|
834 state = EInTag; |
|
835 tagCommandLine.AddElement(iCommentTagStore[i].GetOriginalElement(j)); |
|
836 tagCommandLine.SetLastLine( startLineNumber + newLinesSeen ); |
|
837 } |
|
838 } |
|
839 } |
|
840 } |
|
841 |
|
842 if( tagCommandLine.GetNumberOfTokens() ) |
|
843 { |
|
844 iCommentTagStore[i].AddDataLine( tagCommandLine ); |
|
845 currentIndex = iCommentTagStore[i].GetNumberOfLinesInComment()-1; |
|
846 Process( i, currentIndex ); // process the current tag and parameters |
|
847 } |
|
848 iCommentTagStore[i].SetLastLine( startLineNumber + newLinesSeen ); |
|
849 } |
|
850 |
|
851 |
|
852 void GlobalLocalisationData::CheckIfCommentTagsFullyAnalysed() |
|
853 { |
|
854 for(unsigned int i = 0; i < iCommentTagStore.size(); i++) //for each of the original comments sets whether or not all parts analysed |
|
855 { |
|
856 bool allAnalysed = true; //set to true then see if any are not analysed in which case will set to false |
|
857 unsigned int numberOfLinesInComment = iCommentTagStore[i].GetNumberOfLinesInComment(); |
|
858 for(unsigned int j=0;j < numberOfLinesInComment && allAnalysed; j++) |
|
859 { |
|
860 if(iCommentTagStore[i].IsLineAnalysed(j) == false) |
|
861 allAnalysed = false; |
|
862 } |
|
863 if(allAnalysed) |
|
864 { |
|
865 iCommentTagStore[i].SetWholeTagAnalysed( true ); |
|
866 } |
|
867 } |
|
868 } |
|
869 |
|
870 void GlobalLocalisationData::CheckRlsEntries() |
|
871 { |
|
872 // check each rls item to see if there is a localisation comment before it |
|
873 |
|
874 TNameIndex::iterator end = pG->RlsNameIndex.end(); |
|
875 String rlsTypeName; |
|
876 for (TNameIndex::iterator k = pG->RlsNameIndex.begin(); k != end; ++k) |
|
877 { |
|
878 int index = k->second; |
|
879 int rlsLineNumber = pG->RlsValues[index].iLineNumber; |
|
880 switch(pG->RlsValues[index].iType) |
|
881 { |
|
882 case(ERlsString): |
|
883 case(ERlsStringChar): |
|
884 rlsTypeName = iRlsTypes[0]; |
|
885 break; |
|
886 case(ERlsString8): |
|
887 rlsTypeName = iRlsTypes[1]; |
|
888 break; |
|
889 case(ERlsByte): |
|
890 case(ERlsByteChar): |
|
891 rlsTypeName = iRlsTypes[2]; |
|
892 break; |
|
893 case(ERlsWord): |
|
894 case(ERlsWordChar): |
|
895 rlsTypeName = iRlsTypes[3]; |
|
896 break; |
|
897 case(ERlsLong): |
|
898 case(ERlsLongChar): |
|
899 rlsTypeName = iRlsTypes[4]; |
|
900 break; |
|
901 case(ERlsDouble): |
|
902 rlsTypeName = iRlsTypes[5]; |
|
903 break; |
|
904 default: |
|
905 rlsTypeName=""; |
|
906 } |
|
907 const String rlsFileName = *(pG->RlsValues[index].iFileName); |
|
908 int commentOfInterest = FindIndex(rlsFileName, rlsLineNumber); |
|
909 if(commentOfInterest == -1) // signifies there is no comment before rls declaration |
|
910 { |
|
911 Message * message = pG->Messages.GetEntry(LT_005); |
|
912 if(message->GetActivated()) |
|
913 { |
|
914 pGL->AddWarningToStore(rlsFileName, rlsLineNumber, message->GetMessageOutput()); |
|
915 } |
|
916 } |
|
917 else //know that there exists a tag directly before the rls item |
|
918 { |
|
919 CheckCommands(rlsTypeName, commentOfInterest); |
|
920 } |
|
921 } |
|
922 } |
|
923 |
|
924 bool GlobalLocalisationData::LocalisationCommentsExist() |
|
925 { |
|
926 return (iCommentTagStore.size()) ? true : false; |
|
927 } |
|
928 |
|
929 void GlobalLocalisationData::CheckCommands(String aRlsTypeName, int aCommentOfInterest) |
|
930 { |
|
931 std::vector<String> commentsSeen; |
|
932 unsigned int numberOfLines = iCommentTagStore[aCommentOfInterest].GetNumberOfLinesInComment(); |
|
933 for(unsigned int j=0; j<numberOfLines; j++) // for each command in the particular comment |
|
934 { |
|
935 if(iCommentTagStore[aCommentOfInterest].IsLineAnalysed(j) == false) |
|
936 { |
|
937 iCommentTagStore[aCommentOfInterest].SetAnalysed( j, true ); |
|
938 String commandName = iCommentTagStore[aCommentOfInterest].GetElementFromLine( j, 0 ); //gets tag value |
|
939 int length = commandName.Length(); |
|
940 String tempCommandName = commandName.ExtractSubString(1, length-1); //strips off @ symbol |
|
941 |
|
942 int definitionNumber = iCommentDefinitions.size(); |
|
943 for(int k=0; k<definitionNumber; k++) // finds tempCommandName in iCommentDefinitions |
|
944 if(iCommentDefinitions[k].GetCommandName() == tempCommandName) |
|
945 definitionNumber = k; |
|
946 |
|
947 if(definitionNumber == (int)iCommentDefinitions.size()) // if tempCommandName not found |
|
948 { |
|
949 Message * message = pG->Messages.GetEntry(LT_006); |
|
950 String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
951 int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); |
|
952 if(message->GetActivated()) |
|
953 { |
|
954 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
955 } |
|
956 } |
|
957 else if(iCommentDefinitions[definitionNumber].TagDeclared() == false) // if tempCommandName not declared |
|
958 { |
|
959 Message * message = pG->Messages.GetEntry(LT_006); |
|
960 String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
961 int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); |
|
962 if(message->GetActivated()) |
|
963 { |
|
964 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
965 } |
|
966 } |
|
967 else |
|
968 { |
|
969 bool commentAlreadySeen=false; |
|
970 unsigned int numberOfCommentsSeen = commentsSeen.size(); |
|
971 for(unsigned int k=0; k<numberOfCommentsSeen && commentAlreadySeen == false ;k++) |
|
972 { // checks in the commentsSeen vector for whether or not the tag has already been used |
|
973 if(commandName==commentsSeen[k]) |
|
974 { |
|
975 Message * message = pG->Messages.GetEntry(LT_007); |
|
976 String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
977 int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); |
|
978 if(message->GetActivated()) |
|
979 { |
|
980 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
981 } |
|
982 commentAlreadySeen = true; |
|
983 } |
|
984 } |
|
985 if(commentAlreadySeen == false) |
|
986 { |
|
987 commentsSeen.push_back(commandName); // new tag so store it |
|
988 if(iCommentDefinitions[definitionNumber].IsTagLegalForRlsType(aRlsTypeName) == false) |
|
989 { |
|
990 Message * message = pG->Messages.GetEntry(LT_008); |
|
991 String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
992 int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); |
|
993 if(message->GetActivated()) |
|
994 { |
|
995 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
996 } |
|
997 } |
|
998 else |
|
999 { |
|
1000 String parameterType = iCommentDefinitions[definitionNumber].GetParameterType(); |
|
1001 int numberOfArgs = iCommentTagStore[aCommentOfInterest].GetNumberOfTokensInLine(j) - 1; |
|
1002 if(parameterType == "void") |
|
1003 { |
|
1004 if(numberOfArgs!=0) //void must have no arguments |
|
1005 { |
|
1006 Message * message = pG->Messages.GetEntry(LT_009); |
|
1007 String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
1008 int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); |
|
1009 if(message->GetActivated()) |
|
1010 { |
|
1011 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1012 } |
|
1013 } |
|
1014 } |
|
1015 else if(parameterType == "single") |
|
1016 { |
|
1017 if(numberOfArgs!=1) //single must have one argument |
|
1018 { |
|
1019 Message * message = pG->Messages.GetEntry(LT_010); |
|
1020 String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
1021 int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); |
|
1022 if(message->GetActivated()) |
|
1023 { |
|
1024 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1025 } |
|
1026 } |
|
1027 else |
|
1028 { |
|
1029 CheckParametersArePermitted(aCommentOfInterest, j, definitionNumber); |
|
1030 } |
|
1031 } |
|
1032 else if(parameterType == "multiple") |
|
1033 { |
|
1034 if(numberOfArgs<1) // multiple must have at least one argument |
|
1035 { |
|
1036 Message * message = pG->Messages.GetEntry(LT_011); |
|
1037 String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
1038 int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); |
|
1039 if(message->GetActivated()) |
|
1040 { |
|
1041 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1042 } |
|
1043 } |
|
1044 else |
|
1045 { |
|
1046 CheckParametersArePermitted(aCommentOfInterest, j, definitionNumber); |
|
1047 } |
|
1048 } |
|
1049 else if(parameterType == "text") |
|
1050 { |
|
1051 if(numberOfArgs<1) // text must have somethign after it so numberOfArgs must be >= 1 |
|
1052 { |
|
1053 Message * message = pG->Messages.GetEntry(LT_012); |
|
1054 String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
1055 int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); |
|
1056 if(message->GetActivated()) |
|
1057 { |
|
1058 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1059 } |
|
1060 } |
|
1061 } |
|
1062 } |
|
1063 } |
|
1064 } |
|
1065 } |
|
1066 } |
|
1067 CheckWhetherAllCommentsPresent(aRlsTypeName, aCommentOfInterest, commentsSeen); |
|
1068 } |
|
1069 |
|
1070 void GlobalLocalisationData::CheckWhetherAllCommentsPresent(String aRlsTypeName, int aCommentOfInterest, std::vector<String> aCommentsSeen) |
|
1071 { |
|
1072 for(unsigned int j=0; j<iCommentDefinitions.size(); j++) |
|
1073 { |
|
1074 bool commentAlreadyUsed = false; |
|
1075 for(unsigned int k=0; k<aCommentsSeen.size() && commentAlreadyUsed == false;k++) |
|
1076 { |
|
1077 String storedCommandName = iCommentDefinitions[j].GetCommandName(); |
|
1078 String extractedCommandName = aCommentsSeen[k].ExtractSubString(1,aCommentsSeen[k].Length()-1); |
|
1079 if(storedCommandName == extractedCommandName) |
|
1080 { |
|
1081 //this command already used in the comment tag |
|
1082 commentAlreadyUsed = true; |
|
1083 } |
|
1084 } |
|
1085 if(commentAlreadyUsed == false) // if tag wasn't present in the localisation comment |
|
1086 { |
|
1087 int requirementStatus = iCommentDefinitions[j].GetRequirementStatus(aRlsTypeName); |
|
1088 if(iCommentDefinitions[j].GetRequirementStatus(aRlsTypeName) == ERequired) // if required emit warning |
|
1089 { |
|
1090 Message * message = pG->Messages.GetEntry(LT_013); |
|
1091 String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
1092 int lineNumber = iCommentTagStore[aCommentOfInterest].GetLastLineOfComment() + 1; |
|
1093 if(message->GetActivated()) |
|
1094 { |
|
1095 String comment = message->GetMessageOutput(); |
|
1096 comment += iCommentDefinitions[j].GetCommandName(); |
|
1097 pGL->AddWarningToStore(fileName, lineNumber, comment); |
|
1098 } |
|
1099 } |
|
1100 else if(requirementStatus == EOptionalWithDefault) // if optional check for default and add to file if default exists |
|
1101 { |
|
1102 String dataToAdd = iCommentDefinitions[j].CheckIfOptionalAndHasDefault(aRlsTypeName); |
|
1103 if(dataToAdd != "") |
|
1104 { |
|
1105 iCommentTagStore[aCommentOfInterest].AddOptionalData(dataToAdd); |
|
1106 } |
|
1107 } |
|
1108 } |
|
1109 } |
|
1110 } |
|
1111 |
|
1112 void GlobalLocalisationData::CheckParametersArePermitted(int aCommentOfInterest, int aLineInComment, int aDefinitionNumber) |
|
1113 { |
|
1114 unsigned int elementsInLine = iCommentTagStore[aCommentOfInterest].GetNumberOfTokensInLine(aLineInComment); |
|
1115 for(unsigned int j=1; j< elementsInLine;j++) |
|
1116 { // start iterating at 1 as 0th element is tag name |
|
1117 bool parameterPermitted = false; |
|
1118 unsigned int permissibleParameters = iCommentDefinitions[aDefinitionNumber].GetNumberOfPermissibleParameters(); |
|
1119 for(unsigned int k=0; k<permissibleParameters && parameterPermitted==false;k++) |
|
1120 { |
|
1121 if(iCommentTagStore[aCommentOfInterest].GetElementFromLine(aLineInComment,j)== iCommentDefinitions[aDefinitionNumber].GetPermissibleParameter(k)) |
|
1122 { |
|
1123 parameterPermitted = true; |
|
1124 } |
|
1125 } |
|
1126 if(parameterPermitted == false) |
|
1127 { |
|
1128 Message * message = pG->Messages.GetEntry(LT_014); |
|
1129 String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); |
|
1130 int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(aLineInComment); |
|
1131 if(message->GetActivated()) |
|
1132 { |
|
1133 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1134 } |
|
1135 return; |
|
1136 } |
|
1137 } |
|
1138 } |
|
1139 |
|
1140 int GlobalLocalisationData::FindIndex(const String aFileName, int aLineNumber) |
|
1141 { |
|
1142 for(unsigned int j=0;j<iCommentTagStore.size(); j++) |
|
1143 { |
|
1144 if(iCommentTagStore[j].GetFileName() == aFileName) |
|
1145 { |
|
1146 if(iCommentTagStore[j].GetLastLineOfComment() == aLineNumber - 1) |
|
1147 { |
|
1148 return j; |
|
1149 } |
|
1150 } |
|
1151 } |
|
1152 return -1; //signifies that there is no localisation comment preceding this rls line |
|
1153 } |
|
1154 |
|
1155 |
|
1156 bool GlobalLocalisationData::CheckFirstIsCommand(LocalisationLine aCommandLine) |
|
1157 { |
|
1158 return aCommandLine.GetElement(0).FindSubString("@") == 0 ? true : false; |
|
1159 } |
|
1160 |
|
1161 void GlobalLocalisationData::StoreFinalComment() |
|
1162 { |
|
1163 if(iTempCommentStore.GetFirstLine() >= 0) |
|
1164 AddCommentToStore(); |
|
1165 } |
|
1166 |
|
1167 void GlobalLocalisationData::StoreComment(String aString) |
|
1168 { |
|
1169 iTempCommentStore.AddElement(aString); |
|
1170 } |
|
1171 |
|
1172 void GlobalLocalisationData::Process(unsigned int aStoreIndex, unsigned int aCurrentIndex) |
|
1173 { |
|
1174 LocalisationLine tagCommandLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); |
|
1175 String firstWord = tagCommandLine.GetElement(0); |
|
1176 iCommentTagStore[aStoreIndex].SetAnalysed(aCurrentIndex, true); // will reset to false if turns out not to be a declaration |
|
1177 if(firstWord == "@declaretag") |
|
1178 ProcessDeclaration(aStoreIndex, aCurrentIndex); |
|
1179 else if(firstWord == "@tagvalue") |
|
1180 ProcessTagParameter(aStoreIndex, aCurrentIndex); |
|
1181 else if(firstWord == "@tagoptional") |
|
1182 { |
|
1183 ProcessOptional(aStoreIndex, aCurrentIndex); |
|
1184 } |
|
1185 else if(firstWord == "@tagrequired") |
|
1186 ProcessRequired(aStoreIndex, aCurrentIndex); |
|
1187 else if(firstWord[0]=='@') // must be a tag like 'localise' or 'description' |
|
1188 { |
|
1189 iCommentTagStore[aStoreIndex].SetAnalysed(aCurrentIndex, false); |
|
1190 } |
|
1191 else // first word on a line (not wrapping over from a previous line) does not start with an @ symbol, enit warning |
|
1192 { |
|
1193 Message * message = pG->Messages.GetEntry(LT_015); |
|
1194 String fileName = tagCommandLine.GetFileName(); |
|
1195 int lineNumber = tagCommandLine.GetFirstLine(); |
|
1196 if(message->GetActivated()) |
|
1197 { |
|
1198 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1199 } |
|
1200 } |
|
1201 } |
|
1202 |
|
1203 void GlobalLocalisationData::ProcessDeclaration(unsigned int aStoreIndex, unsigned int aCurrentIndex) |
|
1204 { |
|
1205 LocalisationLine tagDeclarationLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); |
|
1206 if(tagDeclarationLine.GetNumberOfTokens()!=3) // tag declaration lines must have three words in them |
|
1207 { |
|
1208 Message * message = pG->Messages.GetEntry(LT_016); |
|
1209 String fileName = tagDeclarationLine.GetFileName(); |
|
1210 int lineNumber = tagDeclarationLine.GetFirstLine(); |
|
1211 if(message->GetActivated()) |
|
1212 { |
|
1213 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1214 } |
|
1215 return; |
|
1216 } |
|
1217 String tagType = tagDeclarationLine.GetElement(1); |
|
1218 bool acceptableParameter = false; // check that tagType is one of void, single, multiple or text |
|
1219 for(int i=0; i<4 && acceptableParameter == false; i++) |
|
1220 { |
|
1221 if(tagType == iTypes[i]) |
|
1222 { |
|
1223 acceptableParameter = true; |
|
1224 } |
|
1225 } |
|
1226 if(acceptableParameter == false) |
|
1227 { |
|
1228 Message * message = pG->Messages.GetEntry(LT_017); |
|
1229 String fileName = tagDeclarationLine.GetFileName(); |
|
1230 int lineNumber = tagDeclarationLine.GetFirstLine(); |
|
1231 if(message->GetActivated()) |
|
1232 { |
|
1233 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1234 } |
|
1235 return; |
|
1236 } |
|
1237 if(tagDeclarationLine.GetElement(2).FindSubString("@")==0) |
|
1238 { |
|
1239 Message * message = pG->Messages.GetEntry(LT_018); |
|
1240 String fileName = tagDeclarationLine.GetFileName(); |
|
1241 int lineNumber = tagDeclarationLine.GetFirstLine(); |
|
1242 if(message->GetActivated()) |
|
1243 { |
|
1244 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1245 } |
|
1246 return; |
|
1247 } |
|
1248 String tagName = tagDeclarationLine.GetElement(2); |
|
1249 CommentTagPair dataToAdd(tagName, tagType, true); |
|
1250 int entryNumber = GetTagDeclaredIndex(tagName); // check whether tag has already been declared |
|
1251 if(entryNumber == EStringNotFound) // if not then add to store |
|
1252 { |
|
1253 iCommentDefinitions.push_back( dataToAdd ); |
|
1254 } |
|
1255 else if(iCommentDefinitions[entryNumber].TagDeclared()) // emit warning if declared |
|
1256 { |
|
1257 Message * message = pG->Messages.GetEntry(LT_019); |
|
1258 String fileName = tagDeclarationLine.GetFileName(); |
|
1259 int lineNumber = tagDeclarationLine.GetFirstLine(); |
|
1260 if(message->GetActivated()) |
|
1261 { |
|
1262 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1263 } |
|
1264 } |
|
1265 else |
|
1266 iCommentDefinitions[entryNumber].SetTagDeclared(); // set tag as declared |
|
1267 } |
|
1268 |
|
1269 void GlobalLocalisationData::StoreTagParameter(String aCommandName, String aParameter) |
|
1270 { |
|
1271 int entryNumber = GetTagDeclaredIndex(aCommandName); |
|
1272 iCommentDefinitions[entryNumber].AddPermissibleParameter(aParameter); |
|
1273 } |
|
1274 |
|
1275 int GlobalLocalisationData::GetTagDeclaredIndex(String aCommandName) |
|
1276 { // return index number of tag in iCommentDefinitions store |
|
1277 for(unsigned int j = 0; j < iCommentDefinitions.size(); j++) |
|
1278 { |
|
1279 if(iCommentDefinitions[j].GetCommandName() == aCommandName) |
|
1280 { |
|
1281 return j; |
|
1282 } |
|
1283 } |
|
1284 return -1; |
|
1285 } |
|
1286 |
|
1287 void GlobalLocalisationData::ProcessTagParameter(unsigned int aStoreIndex, unsigned int aCurrentIndex) |
|
1288 { |
|
1289 LocalisationLine tagParameterLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); |
|
1290 if(tagParameterLine.GetNumberOfTokens()!=3) |
|
1291 { |
|
1292 Message * message = pG->Messages.GetEntry(LT_020); |
|
1293 String fileName = tagParameterLine.GetFileName(); |
|
1294 int lineNumber = tagParameterLine.GetFirstLine(); |
|
1295 if(message->GetActivated()) |
|
1296 { |
|
1297 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1298 } |
|
1299 return; |
|
1300 } |
|
1301 String tagName = tagParameterLine.GetElement(1); |
|
1302 if(tagName.FindSubString("@") == 0) |
|
1303 { |
|
1304 Message * message = pG->Messages.GetEntry(LT_021); |
|
1305 String fileName = tagParameterLine.GetFileName(); |
|
1306 int lineNumber = tagParameterLine.GetFirstLine(); |
|
1307 if(message->GetActivated()) |
|
1308 { |
|
1309 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1310 } |
|
1311 return; |
|
1312 } |
|
1313 int entryNumber = GetTagDeclaredIndex(tagName); |
|
1314 String parameter = tagParameterLine.GetElement(2); |
|
1315 if(entryNumber == -1) // if tag not declared then add to store, doesn't set tag as declared though as haven't seen a @declaretag line for this tag |
|
1316 { |
|
1317 CommentTagPair dataToAdd(tagName); |
|
1318 iCommentDefinitions.push_back(dataToAdd); |
|
1319 } |
|
1320 else |
|
1321 { |
|
1322 // check whether this parameter has alreasy been declared for this tag |
|
1323 bool alreadyDeclared = iCommentDefinitions[entryNumber].IsParameterAlreadyDeclared(parameter); |
|
1324 if(alreadyDeclared) |
|
1325 { |
|
1326 Message * message = pG->Messages.GetEntry(LT_022); |
|
1327 String fileName = tagParameterLine.GetFileName(); |
|
1328 int lineNumber = tagParameterLine.GetFirstLine(); |
|
1329 if(message->GetActivated()) |
|
1330 { |
|
1331 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1332 } |
|
1333 return; |
|
1334 } |
|
1335 } |
|
1336 StoreTagParameter(tagName, parameter); // store the parameter if all conditions met |
|
1337 } |
|
1338 |
|
1339 void GlobalLocalisationData::ProcessRequired(unsigned int aStoreIndex, unsigned int aCurrentIndex) |
|
1340 { |
|
1341 LocalisationLine tagRequiredLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); |
|
1342 |
|
1343 // @tagrequired line must consist of three distinct tokens |
|
1344 |
|
1345 if(tagRequiredLine.GetNumberOfTokens()!=3) |
|
1346 { |
|
1347 Message * message = pG->Messages.GetEntry(LT_023); |
|
1348 String fileName = tagRequiredLine.GetFileName(); |
|
1349 int lineNumber = tagRequiredLine.GetFirstLine(); |
|
1350 if(message->GetActivated()) |
|
1351 { |
|
1352 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1353 } |
|
1354 return; |
|
1355 } |
|
1356 |
|
1357 // get the tag name and check it doesn't start with an @ symbol |
|
1358 |
|
1359 String tagName = tagRequiredLine.GetElement(1); |
|
1360 if(tagName.FindSubString("@")==0) |
|
1361 { |
|
1362 Message * message = pG->Messages.GetEntry(LT_024); |
|
1363 String fileName = tagRequiredLine.GetFileName(); |
|
1364 int lineNumber = tagRequiredLine.GetFirstLine(); |
|
1365 if(message->GetActivated()) |
|
1366 { |
|
1367 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1368 } |
|
1369 return; |
|
1370 } |
|
1371 |
|
1372 String rlsItem = tagRequiredLine.GetElement(2); |
|
1373 |
|
1374 //check that the rls type passed is one of the legally allowed values |
|
1375 |
|
1376 bool validRlsFlag = false; |
|
1377 for(int j=0; (j < ENumberOfRlsTypes) && (validRlsFlag == false); j++) |
|
1378 { |
|
1379 if(rlsItem == iRlsTypes[j]) |
|
1380 { |
|
1381 validRlsFlag = true; |
|
1382 } |
|
1383 } |
|
1384 if(validRlsFlag == false) |
|
1385 { |
|
1386 Message * message = pG->Messages.GetEntry(LT_036); |
|
1387 String fileName = tagRequiredLine.GetFileName(); |
|
1388 int lineNumber = tagRequiredLine.GetFirstLine(); |
|
1389 if(message->GetActivated()) |
|
1390 { |
|
1391 String comment = message->GetMessageOutput(); |
|
1392 comment += rlsItem; |
|
1393 pGL->AddWarningToStore(fileName, lineNumber, comment); |
|
1394 } |
|
1395 return; |
|
1396 } |
|
1397 |
|
1398 |
|
1399 // store the data |
|
1400 |
|
1401 int entryNumber = GetTagDeclaredIndex(tagName); |
|
1402 if(entryNumber == -1) |
|
1403 { |
|
1404 CommentTagPair dataToAdd(tagName); |
|
1405 iCommentDefinitions.push_back(dataToAdd); |
|
1406 } |
|
1407 else |
|
1408 { |
|
1409 int requirementStatus = iCommentDefinitions[entryNumber].GetRequirementStatus(rlsItem); |
|
1410 if(requirementStatus != EForbidden) |
|
1411 { |
|
1412 Message * message = pG->Messages.GetEntry(LT_025); |
|
1413 String fileName = tagRequiredLine.GetFileName(); |
|
1414 int lineNumber = tagRequiredLine.GetFirstLine(); |
|
1415 if(message->GetActivated()) |
|
1416 { |
|
1417 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1418 } |
|
1419 return; |
|
1420 } |
|
1421 } |
|
1422 StoreRlsItem(tagName, tagRequiredLine.GetElement(2), ERequired); |
|
1423 } |
|
1424 |
|
1425 void GlobalLocalisationData::StoreRlsItem(String aCommandName, String aRlsItem, int aRequired, String aDefault) |
|
1426 { |
|
1427 int entryNumber = GetTagDeclaredIndex(aCommandName); |
|
1428 iCommentDefinitions[entryNumber].AddRlsItem(aRlsItem,aRequired,aDefault); |
|
1429 } |
|
1430 |
|
1431 bool GlobalLocalisationData::IsAnRlsItem(String aString) const |
|
1432 { |
|
1433 //check whether aString is one of the legally allowed rls items |
|
1434 |
|
1435 for(int j=0; j < ENumberOfRlsTypes ; j++) |
|
1436 { |
|
1437 if(aString == iRlsTypes[j]) |
|
1438 { |
|
1439 return true; |
|
1440 } |
|
1441 } |
|
1442 return false; |
|
1443 } |
|
1444 |
|
1445 void GlobalLocalisationData::ProcessOptional(unsigned int aStoreIndex, unsigned int aCurrentIndex) |
|
1446 { |
|
1447 LocalisationLine tagOptionalLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); |
|
1448 int tagLineSize = tagOptionalLine.GetNumberOfTokens(); |
|
1449 |
|
1450 String fileName = tagOptionalLine.GetFileName(); |
|
1451 int lineNumber = tagOptionalLine.GetFirstLine(); |
|
1452 String comment; |
|
1453 |
|
1454 String commandName; |
|
1455 String defaultValue; |
|
1456 String rlsItem; |
|
1457 bool validOptionalDeclaration = false; // will be set to true if the line conforms to the accepted syntax |
|
1458 |
|
1459 unsigned int state = ELookingForCommand; |
|
1460 int firstOccurance; |
|
1461 String currentToken; |
|
1462 |
|
1463 for(int j=1; j<tagLineSize; j++) // start at 1 as 0th element is @tagoptional |
|
1464 { |
|
1465 currentToken = tagOptionalLine.GetElement(j); |
|
1466 switch(state) |
|
1467 { |
|
1468 case(ELookingForCommand): |
|
1469 firstOccurance = currentToken.FindSubString("="); |
|
1470 if(firstOccurance == EStringNotFound) |
|
1471 { |
|
1472 if(IsAnRlsItem(currentToken)) |
|
1473 { |
|
1474 Message * message = pG->Messages.GetEntry(LT_038); |
|
1475 if(message->GetActivated()) |
|
1476 { |
|
1477 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1478 } |
|
1479 return; |
|
1480 } |
|
1481 else |
|
1482 { |
|
1483 commandName = currentToken; |
|
1484 state = ELookingForEqualSignOrRlsItem; |
|
1485 } |
|
1486 } |
|
1487 else if(firstOccurance == 0) // = sign is at the start |
|
1488 { |
|
1489 Message * message = pG->Messages.GetEntry(LT_039); |
|
1490 if(message->GetActivated()) |
|
1491 { |
|
1492 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1493 } |
|
1494 return; |
|
1495 } |
|
1496 else if(currentToken.FindSubString("=",firstOccurance+1)!=EStringNotFound) // more than one = sign |
|
1497 { |
|
1498 Message * message = pG->Messages.GetEntry(LT_027); |
|
1499 if(message->GetActivated()) |
|
1500 { |
|
1501 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1502 } |
|
1503 return; |
|
1504 } |
|
1505 else if((unsigned int)firstOccurance == currentToken.Length() - 1) // = sign at end |
|
1506 { |
|
1507 commandName = currentToken.ExtractSubString( 0, currentToken.Length()-2 ); |
|
1508 state = ELookingForDefault; |
|
1509 } |
|
1510 else // know that is of from <string1>=<string2> |
|
1511 { |
|
1512 commandName = currentToken.ExtractSubString( 0, firstOccurance - 1 ); |
|
1513 defaultValue = currentToken.ExtractSubString( firstOccurance + 1, currentToken.Length()-1 ); |
|
1514 if(IsAnRlsItem(commandName)) |
|
1515 { |
|
1516 Message * message = pG->Messages.GetEntry(LT_040); |
|
1517 if(message->GetActivated()) |
|
1518 { |
|
1519 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1520 } |
|
1521 return; |
|
1522 } |
|
1523 else if(IsAnRlsItem(defaultValue)) |
|
1524 { |
|
1525 Message * message = pG->Messages.GetEntry(LT_041); |
|
1526 if(message->GetActivated()) |
|
1527 { |
|
1528 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1529 } |
|
1530 return; |
|
1531 } |
|
1532 else // no problems so go and look next for an rls item |
|
1533 { |
|
1534 state = ELookingForRlsItem; |
|
1535 } |
|
1536 } |
|
1537 break; |
|
1538 case(ELookingForEqualSignOrRlsItem): |
|
1539 firstOccurance = currentToken.FindSubString("="); |
|
1540 if(firstOccurance == EStringNotFound) // element must be rls item or error |
|
1541 { |
|
1542 if(IsAnRlsItem(currentToken)) |
|
1543 { |
|
1544 rlsItem = currentToken; |
|
1545 state = EShouldBeFinished; |
|
1546 validOptionalDeclaration = true; |
|
1547 } |
|
1548 else // not an rls item |
|
1549 { |
|
1550 Message * message = pG->Messages.GetEntry(LT_035); |
|
1551 if(message->GetActivated()) |
|
1552 { |
|
1553 String comment = message->GetMessageOutput(); |
|
1554 comment += currentToken; |
|
1555 pGL->AddWarningToStore(fileName, lineNumber, comment); |
|
1556 } |
|
1557 return; |
|
1558 } |
|
1559 } |
|
1560 else if(currentToken.FindSubString("=",firstOccurance+1)!=EStringNotFound) // more than one = sign |
|
1561 { |
|
1562 Message * message = pG->Messages.GetEntry(LT_027); |
|
1563 if(message->GetActivated()) |
|
1564 { |
|
1565 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1566 } |
|
1567 return; |
|
1568 } |
|
1569 else if(firstOccurance != 0) // = sign not at start |
|
1570 { |
|
1571 Message * message = pG->Messages.GetEntry(LT_042); |
|
1572 if(message->GetActivated()) |
|
1573 { |
|
1574 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1575 } |
|
1576 return; |
|
1577 } |
|
1578 else if(currentToken.Length() == 1) // = sign by itself |
|
1579 { |
|
1580 state = ELookingForDefault; |
|
1581 } |
|
1582 else |
|
1583 { |
|
1584 defaultValue = currentToken.ExtractSubString( 1, currentToken.Length()-1 ); |
|
1585 if(IsAnRlsItem(defaultValue)) // if found rls item where default value should be |
|
1586 { |
|
1587 Message * message = pG->Messages.GetEntry(LT_041); |
|
1588 if(message->GetActivated()) |
|
1589 { |
|
1590 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1591 } |
|
1592 return; |
|
1593 } |
|
1594 else |
|
1595 { |
|
1596 state = ELookingForRlsItem; |
|
1597 } |
|
1598 } |
|
1599 break; |
|
1600 case(ELookingForDefault): |
|
1601 firstOccurance = currentToken.FindSubString("="); |
|
1602 if(firstOccurance != EStringNotFound) // should not find any more equal signs on the line |
|
1603 { |
|
1604 Message * message = pG->Messages.GetEntry(LT_027); |
|
1605 if(message->GetActivated()) |
|
1606 { |
|
1607 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1608 } |
|
1609 return; |
|
1610 } |
|
1611 else |
|
1612 { |
|
1613 defaultValue = currentToken; |
|
1614 if(IsAnRlsItem(defaultValue)) //check that default value is not an rls item |
|
1615 { |
|
1616 Message * message = pG->Messages.GetEntry(LT_041); |
|
1617 if(message->GetActivated()) |
|
1618 { |
|
1619 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1620 } |
|
1621 return; |
|
1622 } |
|
1623 else |
|
1624 { |
|
1625 state = ELookingForRlsItem; |
|
1626 } |
|
1627 } |
|
1628 break; |
|
1629 case(ELookingForRlsItem): |
|
1630 rlsItem = currentToken; |
|
1631 if(IsAnRlsItem(rlsItem) == false) |
|
1632 { |
|
1633 Message * message = pG->Messages.GetEntry(LT_035); |
|
1634 if(message->GetActivated()) |
|
1635 { |
|
1636 String comment = message->GetMessageOutput(); |
|
1637 comment += rlsItem; |
|
1638 pGL->AddWarningToStore(fileName, lineNumber, comment); |
|
1639 } |
|
1640 return; |
|
1641 } |
|
1642 else |
|
1643 { |
|
1644 state = EShouldBeFinished; |
|
1645 validOptionalDeclaration = true; |
|
1646 } |
|
1647 break; |
|
1648 case(EShouldBeFinished): |
|
1649 Message * message = pG->Messages.GetEntry(LT_043); |
|
1650 if(message->GetActivated()) |
|
1651 { |
|
1652 String comment = message->GetMessageOutput(); |
|
1653 comment += currentToken; |
|
1654 pGL->AddWarningToStore(fileName, lineNumber, comment); |
|
1655 } |
|
1656 return; |
|
1657 } |
|
1658 } |
|
1659 |
|
1660 if(validOptionalDeclaration == false) // end of line reached prematurely |
|
1661 { |
|
1662 Message * message = pG->Messages.GetEntry(LT_044); |
|
1663 if(message->GetActivated()) |
|
1664 { |
|
1665 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1666 } |
|
1667 return; |
|
1668 } |
|
1669 |
|
1670 |
|
1671 int entryNumber = GetTagDeclaredIndex(commandName); |
|
1672 if(entryNumber == -1) |
|
1673 { |
|
1674 CommentTagPair dataToAdd(commandName); |
|
1675 iCommentDefinitions.push_back(dataToAdd); |
|
1676 } |
|
1677 else |
|
1678 { |
|
1679 int requirementStatus = iCommentDefinitions[entryNumber].GetRequirementStatus(rlsItem); |
|
1680 if(requirementStatus != EForbidden) |
|
1681 { |
|
1682 Message * message = pG->Messages.GetEntry(LT_025); |
|
1683 if(message->GetActivated()) |
|
1684 { |
|
1685 pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); |
|
1686 } |
|
1687 return; |
|
1688 } |
|
1689 } |
|
1690 |
|
1691 if(defaultValue.Length()) |
|
1692 StoreRlsItem(commandName, rlsItem, EOptionalWithDefault, defaultValue); |
|
1693 else |
|
1694 StoreRlsItem(commandName, rlsItem, EOptional); |
|
1695 } |
|
1696 |
|
1697 |
|
1698 void GlobalLocalisationData::AddWarningToStore(const String aFileName, int aLineNumber, String aComment) |
|
1699 { |
|
1700 WarningToOutput warning(aFileName, aLineNumber, aComment); |
|
1701 iWarningStore.push_back(warning); |
|
1702 } |
|
1703 |
|
1704 void GlobalLocalisationData::PrintLocalisationWarnings() |
|
1705 { |
|
1706 std::vector<WarningToOutput> warningStore; |
|
1707 unsigned int j; |
|
1708 unsigned int numberOfWarnings = iWarningStore.size(); |
|
1709 std::vector<int> flags; |
|
1710 for(j=0 ; j<numberOfWarnings; j++) |
|
1711 { |
|
1712 warningStore.push_back(iWarningStore[j]); |
|
1713 flags.push_back(1); |
|
1714 } |
|
1715 |
|
1716 iWarningStore.clear(); |
|
1717 StringLess stringCompare; |
|
1718 int currentBestIndex; |
|
1719 int totalLeft = numberOfWarnings; |
|
1720 while(totalLeft) // loop orders stored warnings alphabetically by file name and then by line number |
|
1721 { |
|
1722 String fileName; |
|
1723 int lineNumber = -1; |
|
1724 String comment; |
|
1725 String currentBestFileName; |
|
1726 int currentBestLineNumber = -1; |
|
1727 String currentBestComment; |
|
1728 bool beforeFirst = true; |
|
1729 for(j=0,totalLeft=0,currentBestIndex=-1; j< numberOfWarnings; j++) |
|
1730 { |
|
1731 if(flags[j]) |
|
1732 { |
|
1733 if(beforeFirst) |
|
1734 { |
|
1735 currentBestFileName = warningStore[j].GetFileName(); |
|
1736 currentBestLineNumber = warningStore[j].GetLineNumber(); |
|
1737 currentBestComment = warningStore[j].GetComment(); |
|
1738 currentBestIndex = j; |
|
1739 beforeFirst = false; |
|
1740 } |
|
1741 else |
|
1742 { |
|
1743 fileName = warningStore[j].GetFileName(); |
|
1744 lineNumber = warningStore[j].GetLineNumber(); |
|
1745 comment = warningStore[j].GetComment(); |
|
1746 if(!stringCompare(fileName, currentBestFileName) && !stringCompare(currentBestFileName, fileName)) |
|
1747 { |
|
1748 if(lineNumber < currentBestLineNumber) |
|
1749 { |
|
1750 currentBestLineNumber = lineNumber; |
|
1751 currentBestComment = comment; |
|
1752 currentBestIndex = j; |
|
1753 } |
|
1754 } |
|
1755 else if(stringCompare(fileName, currentBestFileName)) |
|
1756 { |
|
1757 currentBestFileName = fileName; |
|
1758 currentBestLineNumber = lineNumber; |
|
1759 currentBestComment = comment; |
|
1760 currentBestIndex = j; |
|
1761 } |
|
1762 } |
|
1763 totalLeft++; |
|
1764 } |
|
1765 } |
|
1766 if(currentBestIndex>=0) |
|
1767 { |
|
1768 flags[currentBestIndex]=0; |
|
1769 WarningToOutput warning(warningStore[currentBestIndex]); |
|
1770 iWarningStore.push_back(warning); |
|
1771 totalLeft--; |
|
1772 } |
|
1773 } |
|
1774 for(j=0; j< numberOfWarnings; j++) // outputs warning in alphabetical file order, by line number within a file |
|
1775 { |
|
1776 String fileName = iWarningStore[j].GetFileName(); |
|
1777 ErrorHandler::Register(& fileName, iWarningStore[j].GetLineNumber()); |
|
1778 ErrorHandler::OutputErrorLine(iWarningStore[j].GetComment()); |
|
1779 } |
|
1780 } |
|
1781 |
|
1782 void GlobalLocalisationData::OutputLocalisedFile(String SourceFileName) |
|
1783 { // reparse the source file and output a file with the optional tags with defaults added in |
|
1784 |
|
1785 char fileChar; |
|
1786 char * fileCharAsArray = new char[2]; |
|
1787 fileCharAsArray[0] = 'a'; |
|
1788 fileCharAsArray[1]='\0'; |
|
1789 const char * fileName = SourceFileName.GetAssertedNonEmptyBuffer(); |
|
1790 ifstream iFile(fileName); |
|
1791 |
|
1792 #ifdef __LINUX__ |
|
1793 char LocalisationOutputFileName[sizeof("/tmp/rcomp_temp_XXXXXX")]; |
|
1794 strcpy(LocalisationOutputFileName,"/tmp/rcomp_temp_XXXXXX"); |
|
1795 int fd = mkstemp(LocalisationOutputFileName); close(fd); |
|
1796 #endif |
|
1797 #ifdef WIN32 |
|
1798 char * LocalisationOutputFileName; |
|
1799 LocalisationOutputFileName = tmpnam(NULL); |
|
1800 #endif |
|
1801 |
|
1802 ofstream outputFile(LocalisationOutputFileName); |
|
1803 |
|
1804 String fileLine(""); |
|
1805 int fileLineLength = fileLine.Length(); |
|
1806 int previousState; |
|
1807 int state = EStartOfLine; |
|
1808 int currentFileLine = 1; |
|
1809 String currentFileName = SourceFileName; |
|
1810 int newLineNumber = -1; |
|
1811 String newFileName(""); |
|
1812 String newLineNumberAsString(""); |
|
1813 bool validLine = false; |
|
1814 while(iFile.get(fileChar)) // read file character by character looking for file declaration lines |
|
1815 { |
|
1816 fileCharAsArray[0]=fileChar; |
|
1817 if(state == EStartOfLine) // add character to store of this line |
|
1818 fileLine = fileCharAsArray; |
|
1819 else |
|
1820 fileLine += fileCharAsArray; |
|
1821 previousState = state; |
|
1822 switch(state) |
|
1823 { |
|
1824 case(EStartOfLine): |
|
1825 switch(fileChar) |
|
1826 { |
|
1827 case('#'): |
|
1828 state = EFindLineNo; |
|
1829 break; |
|
1830 case('\n'): |
|
1831 break; |
|
1832 default: |
|
1833 state = EGeneral; |
|
1834 } |
|
1835 break; |
|
1836 case(EGeneral): |
|
1837 switch(fileChar) |
|
1838 { |
|
1839 case('\n'): |
|
1840 state = EStartOfLine; |
|
1841 break; |
|
1842 } |
|
1843 break; |
|
1844 case(EFindLineNo): |
|
1845 switch(fileChar) |
|
1846 { |
|
1847 case('\n'): |
|
1848 state = EStartOfLine; |
|
1849 break; |
|
1850 case('0'): |
|
1851 case('1'): |
|
1852 case('2'): |
|
1853 case('3'): |
|
1854 case('4'): |
|
1855 case('5'): |
|
1856 case('6'): |
|
1857 case('7'): |
|
1858 case('8'): |
|
1859 case('9'): |
|
1860 state = EInLineNo; |
|
1861 break; |
|
1862 case(' '): |
|
1863 case('\t'): |
|
1864 break; |
|
1865 default: |
|
1866 state = EGeneral; |
|
1867 } |
|
1868 break; |
|
1869 case(EInLineNo): |
|
1870 switch(fileChar) |
|
1871 { |
|
1872 case('\n'): |
|
1873 state = EStartOfLine; |
|
1874 break; |
|
1875 case('0'): |
|
1876 case('1'): |
|
1877 case('2'): |
|
1878 case('3'): |
|
1879 case('4'): |
|
1880 case('5'): |
|
1881 case('6'): |
|
1882 case('7'): |
|
1883 case('8'): |
|
1884 case('9'): |
|
1885 break; |
|
1886 case(' '): |
|
1887 case('\t'): |
|
1888 state = EFindFileName; |
|
1889 break; |
|
1890 default: |
|
1891 state = EGeneral; |
|
1892 } |
|
1893 break; |
|
1894 case(EFindFileName): |
|
1895 switch(fileChar) |
|
1896 { |
|
1897 case('\n'): |
|
1898 state = EStartOfLine; |
|
1899 break; |
|
1900 case(' '): |
|
1901 case('\t'): |
|
1902 break; |
|
1903 case('\"'): |
|
1904 state = EInFileName; |
|
1905 break; |
|
1906 default: |
|
1907 state = EGeneral; |
|
1908 } |
|
1909 break; |
|
1910 case(EInFileName): |
|
1911 switch(fileChar) |
|
1912 { |
|
1913 case('\n'): |
|
1914 state = EStartOfLine; |
|
1915 break; |
|
1916 case(' '): |
|
1917 case('\t'): |
|
1918 state = EGeneral; |
|
1919 break; |
|
1920 case('\"'): |
|
1921 state = EFindDigit; |
|
1922 break; |
|
1923 } |
|
1924 break; |
|
1925 case(EFindDigit): |
|
1926 switch(fileChar) |
|
1927 { |
|
1928 case('\n'): |
|
1929 state = EStartOfLine; |
|
1930 break; |
|
1931 case(' '): |
|
1932 case('\t'): |
|
1933 break; |
|
1934 case('1'): |
|
1935 case('2'): |
|
1936 state = EAfterDigit; |
|
1937 break; |
|
1938 default: |
|
1939 state = EGeneral; |
|
1940 } |
|
1941 break; |
|
1942 case(EAfterDigit): |
|
1943 switch(fileChar) |
|
1944 { |
|
1945 case('\n'): |
|
1946 state = EStartOfLine; |
|
1947 break; |
|
1948 case(' '): |
|
1949 case('\t'): |
|
1950 break; |
|
1951 default: |
|
1952 state = EGeneral; |
|
1953 } |
|
1954 break; |
|
1955 } |
|
1956 int lineOfInterest; |
|
1957 switch(state) |
|
1958 { |
|
1959 case(EStartOfLine): |
|
1960 if(validLine) //validline will be true if this line is a file line declaration |
|
1961 { |
|
1962 currentFileName = newFileName; |
|
1963 currentFileLine = newLineNumber - 1; |
|
1964 } |
|
1965 validLine = false; |
|
1966 newFileName.Reset(); |
|
1967 newLineNumber = -1; |
|
1968 newLineNumberAsString.Reset(); |
|
1969 fileLineLength = fileLine.Length(); |
|
1970 lineOfInterest = NeedToAddDefaultData(currentFileName, currentFileLine); //checks if previous line was the end of a localisation tag and whether that tag has optional data to add |
|
1971 if(lineOfInterest > -1) // data to add |
|
1972 { |
|
1973 int end = fileLine.FindSubString("*/"); |
|
1974 String tempString; |
|
1975 if(end) |
|
1976 { |
|
1977 tempString = fileLine.ExtractSubString(0,end-1); |
|
1978 outputFile.write(tempString.GetBuffer(),tempString.Length()); |
|
1979 outputFile.write("\n",1); |
|
1980 } |
|
1981 unsigned int numberOfLinesToAdd = iCommentTagStore[lineOfInterest].GetNumberOfOptionalLinesToAdd(); |
|
1982 for(unsigned int j=0; j<numberOfLinesToAdd; j++) |
|
1983 { |
|
1984 tempString = iCommentTagStore[lineOfInterest].GetOptionalLineToAdd(j); |
|
1985 const char * pTempString = tempString.GetBuffer(); |
|
1986 outputFile.write(pTempString,tempString.Length()-1); |
|
1987 outputFile.write("\n",1); |
|
1988 } |
|
1989 tempString = fileLine.ExtractSubString(end, fileLine.Length()-1); |
|
1990 outputFile.write(tempString.GetBuffer(),tempString.Length()); |
|
1991 } |
|
1992 else |
|
1993 outputFile.write(fileLine.GetBuffer(), fileLineLength); |
|
1994 fileLine.Reset(); |
|
1995 currentFileLine++; |
|
1996 break; |
|
1997 case(EGeneral): |
|
1998 if(previousState!=EGeneral) |
|
1999 { |
|
2000 newLineNumber = -1; |
|
2001 newLineNumberAsString.Reset(); |
|
2002 newFileName.Reset(); |
|
2003 validLine = false; |
|
2004 } |
|
2005 break; |
|
2006 case(EInLineNo): |
|
2007 if(newLineNumberAsString.Length()) |
|
2008 newLineNumberAsString+= fileCharAsArray; |
|
2009 else |
|
2010 newLineNumberAsString = fileCharAsArray; |
|
2011 break; |
|
2012 case(EFindFileName): |
|
2013 if(previousState == EInLineNo) |
|
2014 { |
|
2015 newLineNumber = newLineNumberAsString.Atoi(); |
|
2016 } |
|
2017 break; |
|
2018 case(EInFileName): |
|
2019 if(previousState == EInFileName) |
|
2020 { |
|
2021 if(newFileName.Length()) |
|
2022 newFileName += fileCharAsArray; |
|
2023 else |
|
2024 newFileName = fileCharAsArray; |
|
2025 } |
|
2026 break; |
|
2027 case(EFindDigit): |
|
2028 if(previousState == EInFileName) |
|
2029 validLine = true; |
|
2030 break; |
|
2031 } |
|
2032 } |
|
2033 iFile.close(); |
|
2034 outputFile.close(); |
|
2035 if(remove(fileName) != 0) |
|
2036 { |
|
2037 Message * message = pG->Messages.GetEntry(LT_037); |
|
2038 if(message->GetActivated()) |
|
2039 { |
|
2040 cerr << message->GetMessageOutput() << endl; |
|
2041 } |
|
2042 } |
|
2043 else |
|
2044 { |
|
2045 rename(LocalisationOutputFileName, fileName); |
|
2046 } |
|
2047 delete []fileCharAsArray; |
|
2048 } |
|
2049 |
|
2050 |
|
2051 #ifdef __VC32__ |
|
2052 #pragma warning( pop ) |
|
2053 #endif |