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