diff -r 820b22e13ff1 -r 39c28ec933dd bintools/rcomp/src/localise.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bintools/rcomp/src/localise.cpp Mon May 10 19:54:49 2010 +0100 @@ -0,0 +1,2053 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + + +#include "main.h" +#include "localise.h" + +#ifdef __VC32__ +#pragma warning( push, 1 ) // MS STL libraries do not compile cleanly, temporarily set warning level to 1 +#pragma warning( disable : 4710 ) // function not inlined. +#pragma warning( disable : 4530 ) // function not inlined. +#endif + +#include +#include +#include "ERRORHAN.H" +#include +#include + +#if defined(__MSVCDOTNET__) || defined(__TOOLS2__) +using std::ifstream; +using std::cerr; +using std::endl; +#endif //__MSVCDOTNET__ + + + +/****************************************************************************************** +** +** RlsItemRequirements +** +******************************************************************************************/ + +RlsItemRequirements::RlsItemRequirements(String aRlsName, int aRequirement) + :iRlsName(aRlsName), + iRequirement(aRequirement) + {} + +RlsItemRequirements::RlsItemRequirements(const RlsItemRequirements & aRlsItemRequirements) + :iRlsName(aRlsItemRequirements.iRlsName), + iRequirement(aRlsItemRequirements.iRequirement) + {} + +RlsItemRequirements::~RlsItemRequirements() + {} + +/****************************************************************************************** +** +** CommandRequirementsHolder +** +******************************************************************************************/ + +CommandRequirementsHolder::CommandRequirementsHolder(String aCommandName) + :iCommandName(aCommandName) + { + iRlsRequirements.clear(); + } + +CommandRequirementsHolder::CommandRequirementsHolder(const CommandRequirementsHolder & aCommandRequirmentsHolder) + :iCommandName(aCommandRequirmentsHolder.iCommandName) + { + for(unsigned int j = 0; j < aCommandRequirmentsHolder.iRlsRequirements.size() ; j++) + { + iRlsRequirements.push_back(aCommandRequirmentsHolder.iRlsRequirements[j]); + } + } + +CommandRequirementsHolder::~CommandRequirementsHolder() + {} + +/****************************************************************************************** +** +** TagParameterData +** +******************************************************************************************/ + +TagParameterData::TagParameterData(String aTagParameter) + :iTagParameter(aTagParameter) + {} + +TagParameterData::TagParameterData(const TagParameterData & aTagParameterData) + :iTagParameter(aTagParameterData.iTagParameter) + {} + +TagParameterData::~TagParameterData() + {} + +void TagParameterData::SetTagParameter(String aTagParameter) + { + iTagParameter = aTagParameter; + } + +String TagParameterData::GetTagParameter() + { + return iTagParameter; + } + +/****************************************************************************************** +** +** CommentRequirement +** +******************************************************************************************/ + +CommentRequirement::CommentRequirement(int aRequirementStatus, String aDefaultParameter) + :iRequirementStatus(aRequirementStatus), + iDefaultParameter(aDefaultParameter) + { + } + +CommentRequirement::CommentRequirement(const CommentRequirement & aCommentRequirement) + :iRequirementStatus(aCommentRequirement.iRequirementStatus), + iDefaultParameter(aCommentRequirement.iDefaultParameter) + { + } + +CommentRequirement::~CommentRequirement() + {} + +String CommentRequirement::GetDefault() + { + return iDefaultParameter; + } + +int CommentRequirement::GetRequirementStatus() + { + return iRequirementStatus; + } + +/****************************************************************************************** +** +** CommentRequirementPair +** +******************************************************************************************/ + +CommentRequirementPair::CommentRequirementPair(String aRlsItem, int aStatus, String aDefault) + :iRlsItem(aRlsItem), + iCommentRequirementData(aStatus, aDefault) + { + } + +CommentRequirementPair::CommentRequirementPair(const CommentRequirementPair & aCommentRequirementPair) + :iRlsItem(aCommentRequirementPair.iRlsItem), + iCommentRequirementData(aCommentRequirementPair.iCommentRequirementData) + {} + +CommentRequirementPair::~CommentRequirementPair() + {} + +int CommentRequirementPair::GetRequirementStatus() + { + return iCommentRequirementData.GetRequirementStatus(); + } + +String CommentRequirementPair::CheckIfOptionalAndHasDefault(String aRlsTypeName, String aCommandName) + { // returns a String containing a line which needs to be written out to the rpp file, or returns "" + String optionalLineToAdd = ""; + if(iRlsItem == aRlsTypeName) + { + int requirementStatus = iCommentRequirementData.GetRequirementStatus(); + if(requirementStatus == EOptionalWithDefault) + { + String defaultValue = iCommentRequirementData.GetDefault(); + if(defaultValue.Length()) // will only return true if a default exists + { + optionalLineToAdd = "@"; + optionalLineToAdd += aCommandName; + String tempString(" "); + optionalLineToAdd += tempString; + optionalLineToAdd += defaultValue; + tempString = "\n"; + optionalLineToAdd += tempString; + } + } + } + return optionalLineToAdd; + } + +String CommentRequirementPair::GetRlsItem() + { + return iRlsItem; + } + +void CommentRequirementPair::SetRlsItem(String aRlsItem) + { + iRlsItem = aRlsItem; + } + +/****************************************************************************************** +** +** CommentTag +** +******************************************************************************************/ + +CommentTag::CommentTag(String aTagType, bool aTagDeclared) + :iTagDeclared( aTagDeclared ), + iParameterType( aTagType ) + { + iPermissibleParameters.clear(); + iRequirements.clear(); + } + +CommentTag::CommentTag(const CommentTag & aCommentTag) + :iTagDeclared( aCommentTag.iTagDeclared ), + iParameterType( aCommentTag.iParameterType ) + { + unsigned int j; + for(j=0; j< aCommentTag.iPermissibleParameters.size(); j++) + { + iPermissibleParameters.push_back(aCommentTag.iPermissibleParameters[j]); + } + for(j=0; j< aCommentTag.iRequirements.size(); j++) + { + iRequirements.push_back(aCommentTag.iRequirements[j]); + } + } + +CommentTag::~CommentTag() + {} + +String CommentTag::CheckIfOptionalAndHasDefault(String aRlsTypeName, String aCommandName) + { + if(iTagDeclared) + { + for(unsigned int j=0; jRlsNameIndex.end(); + String rlsTypeName; + for (TNameIndex::iterator k = pG->RlsNameIndex.begin(); k != end; ++k) + { + int index = k->second; + int rlsLineNumber = pG->RlsValues[index].iLineNumber; + switch(pG->RlsValues[index].iType) + { + case(ERlsString): + case(ERlsStringChar): + rlsTypeName = iRlsTypes[0]; + break; + case(ERlsString8): + rlsTypeName = iRlsTypes[1]; + break; + case(ERlsByte): + case(ERlsByteChar): + rlsTypeName = iRlsTypes[2]; + break; + case(ERlsWord): + case(ERlsWordChar): + rlsTypeName = iRlsTypes[3]; + break; + case(ERlsLong): + case(ERlsLongChar): + rlsTypeName = iRlsTypes[4]; + break; + case(ERlsDouble): + rlsTypeName = iRlsTypes[5]; + break; + default: + rlsTypeName=""; + } + const String rlsFileName = *(pG->RlsValues[index].iFileName); + int commentOfInterest = FindIndex(rlsFileName, rlsLineNumber); + if(commentOfInterest == -1) // signifies there is no comment before rls declaration + { + Message * message = pG->Messages.GetEntry(LT_005); + if(message->GetActivated()) + { + pGL->AddWarningToStore(rlsFileName, rlsLineNumber, message->GetMessageOutput()); + } + } + else //know that there exists a tag directly before the rls item + { + CheckCommands(rlsTypeName, commentOfInterest); + } + } + } + +bool GlobalLocalisationData::LocalisationCommentsExist() + { + return (iCommentTagStore.size()) ? true : false; + } + +void GlobalLocalisationData::CheckCommands(String aRlsTypeName, int aCommentOfInterest) + { + std::vector commentsSeen; + unsigned int numberOfLines = iCommentTagStore[aCommentOfInterest].GetNumberOfLinesInComment(); + for(unsigned int j=0; jMessages.GetEntry(LT_006); + String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + } + else if(iCommentDefinitions[definitionNumber].TagDeclared() == false) // if tempCommandName not declared + { + Message * message = pG->Messages.GetEntry(LT_006); + String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + } + else + { + bool commentAlreadySeen=false; + unsigned int numberOfCommentsSeen = commentsSeen.size(); + for(unsigned int k=0; kMessages.GetEntry(LT_007); + String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + commentAlreadySeen = true; + } + } + if(commentAlreadySeen == false) + { + commentsSeen.push_back(commandName); // new tag so store it + if(iCommentDefinitions[definitionNumber].IsTagLegalForRlsType(aRlsTypeName) == false) + { + Message * message = pG->Messages.GetEntry(LT_008); + String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + } + else + { + String parameterType = iCommentDefinitions[definitionNumber].GetParameterType(); + int numberOfArgs = iCommentTagStore[aCommentOfInterest].GetNumberOfTokensInLine(j) - 1; + if(parameterType == "void") + { + if(numberOfArgs!=0) //void must have no arguments + { + Message * message = pG->Messages.GetEntry(LT_009); + String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + } + } + else if(parameterType == "single") + { + if(numberOfArgs!=1) //single must have one argument + { + Message * message = pG->Messages.GetEntry(LT_010); + String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + } + else + { + CheckParametersArePermitted(aCommentOfInterest, j, definitionNumber); + } + } + else if(parameterType == "multiple") + { + if(numberOfArgs<1) // multiple must have at least one argument + { + Message * message = pG->Messages.GetEntry(LT_011); + String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + } + else + { + CheckParametersArePermitted(aCommentOfInterest, j, definitionNumber); + } + } + else if(parameterType == "text") + { + if(numberOfArgs<1) // text must have somethign after it so numberOfArgs must be >= 1 + { + Message * message = pG->Messages.GetEntry(LT_012); + String fileName =iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(j); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + } + } + } + } + } + } + } + CheckWhetherAllCommentsPresent(aRlsTypeName, aCommentOfInterest, commentsSeen); + } + +void GlobalLocalisationData::CheckWhetherAllCommentsPresent(String aRlsTypeName, int aCommentOfInterest, std::vector aCommentsSeen) + { + for(unsigned int j=0; jMessages.GetEntry(LT_013); + String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetLastLineOfComment() + 1; + if(message->GetActivated()) + { + String comment = message->GetMessageOutput(); + comment += iCommentDefinitions[j].GetCommandName(); + pGL->AddWarningToStore(fileName, lineNumber, comment); + } + } + else if(requirementStatus == EOptionalWithDefault) // if optional check for default and add to file if default exists + { + String dataToAdd = iCommentDefinitions[j].CheckIfOptionalAndHasDefault(aRlsTypeName); + if(dataToAdd != "") + { + iCommentTagStore[aCommentOfInterest].AddOptionalData(dataToAdd); + } + } + } + } + } + +void GlobalLocalisationData::CheckParametersArePermitted(int aCommentOfInterest, int aLineInComment, int aDefinitionNumber) + { + unsigned int elementsInLine = iCommentTagStore[aCommentOfInterest].GetNumberOfTokensInLine(aLineInComment); + for(unsigned int j=1; j< elementsInLine;j++) + { // start iterating at 1 as 0th element is tag name + bool parameterPermitted = false; + unsigned int permissibleParameters = iCommentDefinitions[aDefinitionNumber].GetNumberOfPermissibleParameters(); + for(unsigned int k=0; kMessages.GetEntry(LT_014); + String fileName = iCommentTagStore[aCommentOfInterest].GetFileName(); + int lineNumber = iCommentTagStore[aCommentOfInterest].GetFirstLine(aLineInComment); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + } + } + +int GlobalLocalisationData::FindIndex(const String aFileName, int aLineNumber) + { + for(unsigned int j=0;j= 0) + AddCommentToStore(); + } + +void GlobalLocalisationData::StoreComment(String aString) + { + iTempCommentStore.AddElement(aString); + } + +void GlobalLocalisationData::Process(unsigned int aStoreIndex, unsigned int aCurrentIndex) + { + LocalisationLine tagCommandLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); + String firstWord = tagCommandLine.GetElement(0); + iCommentTagStore[aStoreIndex].SetAnalysed(aCurrentIndex, true); // will reset to false if turns out not to be a declaration + if(firstWord == "@declaretag") + ProcessDeclaration(aStoreIndex, aCurrentIndex); + else if(firstWord == "@tagvalue") + ProcessTagParameter(aStoreIndex, aCurrentIndex); + else if(firstWord == "@tagoptional") + { + ProcessOptional(aStoreIndex, aCurrentIndex); + } + else if(firstWord == "@tagrequired") + ProcessRequired(aStoreIndex, aCurrentIndex); + else if(firstWord[0]=='@') // must be a tag like 'localise' or 'description' + { + iCommentTagStore[aStoreIndex].SetAnalysed(aCurrentIndex, false); + } + else // first word on a line (not wrapping over from a previous line) does not start with an @ symbol, enit warning + { + Message * message = pG->Messages.GetEntry(LT_015); + String fileName = tagCommandLine.GetFileName(); + int lineNumber = tagCommandLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + } + } + +void GlobalLocalisationData::ProcessDeclaration(unsigned int aStoreIndex, unsigned int aCurrentIndex) + { + LocalisationLine tagDeclarationLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); + if(tagDeclarationLine.GetNumberOfTokens()!=3) // tag declaration lines must have three words in them + { + Message * message = pG->Messages.GetEntry(LT_016); + String fileName = tagDeclarationLine.GetFileName(); + int lineNumber = tagDeclarationLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + String tagType = tagDeclarationLine.GetElement(1); + bool acceptableParameter = false; // check that tagType is one of void, single, multiple or text + for(int i=0; i<4 && acceptableParameter == false; i++) + { + if(tagType == iTypes[i]) + { + acceptableParameter = true; + } + } + if(acceptableParameter == false) + { + Message * message = pG->Messages.GetEntry(LT_017); + String fileName = tagDeclarationLine.GetFileName(); + int lineNumber = tagDeclarationLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + if(tagDeclarationLine.GetElement(2).FindSubString("@")==0) + { + Message * message = pG->Messages.GetEntry(LT_018); + String fileName = tagDeclarationLine.GetFileName(); + int lineNumber = tagDeclarationLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + String tagName = tagDeclarationLine.GetElement(2); + CommentTagPair dataToAdd(tagName, tagType, true); + int entryNumber = GetTagDeclaredIndex(tagName); // check whether tag has already been declared + if(entryNumber == EStringNotFound) // if not then add to store + { + iCommentDefinitions.push_back( dataToAdd ); + } + else if(iCommentDefinitions[entryNumber].TagDeclared()) // emit warning if declared + { + Message * message = pG->Messages.GetEntry(LT_019); + String fileName = tagDeclarationLine.GetFileName(); + int lineNumber = tagDeclarationLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + } + else + iCommentDefinitions[entryNumber].SetTagDeclared(); // set tag as declared + } + +void GlobalLocalisationData::StoreTagParameter(String aCommandName, String aParameter) + { + int entryNumber = GetTagDeclaredIndex(aCommandName); + iCommentDefinitions[entryNumber].AddPermissibleParameter(aParameter); + } + +int GlobalLocalisationData::GetTagDeclaredIndex(String aCommandName) + { // return index number of tag in iCommentDefinitions store + for(unsigned int j = 0; j < iCommentDefinitions.size(); j++) + { + if(iCommentDefinitions[j].GetCommandName() == aCommandName) + { + return j; + } + } + return -1; + } + +void GlobalLocalisationData::ProcessTagParameter(unsigned int aStoreIndex, unsigned int aCurrentIndex) + { + LocalisationLine tagParameterLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); + if(tagParameterLine.GetNumberOfTokens()!=3) + { + Message * message = pG->Messages.GetEntry(LT_020); + String fileName = tagParameterLine.GetFileName(); + int lineNumber = tagParameterLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + String tagName = tagParameterLine.GetElement(1); + if(tagName.FindSubString("@") == 0) + { + Message * message = pG->Messages.GetEntry(LT_021); + String fileName = tagParameterLine.GetFileName(); + int lineNumber = tagParameterLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + int entryNumber = GetTagDeclaredIndex(tagName); + String parameter = tagParameterLine.GetElement(2); + 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 + { + CommentTagPair dataToAdd(tagName); + iCommentDefinitions.push_back(dataToAdd); + } + else + { + // check whether this parameter has alreasy been declared for this tag + bool alreadyDeclared = iCommentDefinitions[entryNumber].IsParameterAlreadyDeclared(parameter); + if(alreadyDeclared) + { + Message * message = pG->Messages.GetEntry(LT_022); + String fileName = tagParameterLine.GetFileName(); + int lineNumber = tagParameterLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + } + StoreTagParameter(tagName, parameter); // store the parameter if all conditions met + } + +void GlobalLocalisationData::ProcessRequired(unsigned int aStoreIndex, unsigned int aCurrentIndex) + { + LocalisationLine tagRequiredLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); + + // @tagrequired line must consist of three distinct tokens + + if(tagRequiredLine.GetNumberOfTokens()!=3) + { + Message * message = pG->Messages.GetEntry(LT_023); + String fileName = tagRequiredLine.GetFileName(); + int lineNumber = tagRequiredLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + + // get the tag name and check it doesn't start with an @ symbol + + String tagName = tagRequiredLine.GetElement(1); + if(tagName.FindSubString("@")==0) + { + Message * message = pG->Messages.GetEntry(LT_024); + String fileName = tagRequiredLine.GetFileName(); + int lineNumber = tagRequiredLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + + String rlsItem = tagRequiredLine.GetElement(2); + + //check that the rls type passed is one of the legally allowed values + + bool validRlsFlag = false; + for(int j=0; (j < ENumberOfRlsTypes) && (validRlsFlag == false); j++) + { + if(rlsItem == iRlsTypes[j]) + { + validRlsFlag = true; + } + } + if(validRlsFlag == false) + { + Message * message = pG->Messages.GetEntry(LT_036); + String fileName = tagRequiredLine.GetFileName(); + int lineNumber = tagRequiredLine.GetFirstLine(); + if(message->GetActivated()) + { + String comment = message->GetMessageOutput(); + comment += rlsItem; + pGL->AddWarningToStore(fileName, lineNumber, comment); + } + return; + } + + + // store the data + + int entryNumber = GetTagDeclaredIndex(tagName); + if(entryNumber == -1) + { + CommentTagPair dataToAdd(tagName); + iCommentDefinitions.push_back(dataToAdd); + } + else + { + int requirementStatus = iCommentDefinitions[entryNumber].GetRequirementStatus(rlsItem); + if(requirementStatus != EForbidden) + { + Message * message = pG->Messages.GetEntry(LT_025); + String fileName = tagRequiredLine.GetFileName(); + int lineNumber = tagRequiredLine.GetFirstLine(); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + } + StoreRlsItem(tagName, tagRequiredLine.GetElement(2), ERequired); + } + +void GlobalLocalisationData::StoreRlsItem(String aCommandName, String aRlsItem, int aRequired, String aDefault) + { + int entryNumber = GetTagDeclaredIndex(aCommandName); + iCommentDefinitions[entryNumber].AddRlsItem(aRlsItem,aRequired,aDefault); + } + +bool GlobalLocalisationData::IsAnRlsItem(String aString) const + { + //check whether aString is one of the legally allowed rls items + + for(int j=0; j < ENumberOfRlsTypes ; j++) + { + if(aString == iRlsTypes[j]) + { + return true; + } + } + return false; + } + +void GlobalLocalisationData::ProcessOptional(unsigned int aStoreIndex, unsigned int aCurrentIndex) + { + LocalisationLine tagOptionalLine(iCommentTagStore[aStoreIndex].GetLine(aCurrentIndex)); + int tagLineSize = tagOptionalLine.GetNumberOfTokens(); + + String fileName = tagOptionalLine.GetFileName(); + int lineNumber = tagOptionalLine.GetFirstLine(); + String comment; + + String commandName; + String defaultValue; + String rlsItem; + bool validOptionalDeclaration = false; // will be set to true if the line conforms to the accepted syntax + + unsigned int state = ELookingForCommand; + int firstOccurance; + String currentToken; + + for(int j=1; jMessages.GetEntry(LT_038); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else + { + commandName = currentToken; + state = ELookingForEqualSignOrRlsItem; + } + } + else if(firstOccurance == 0) // = sign is at the start + { + Message * message = pG->Messages.GetEntry(LT_039); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else if(currentToken.FindSubString("=",firstOccurance+1)!=EStringNotFound) // more than one = sign + { + Message * message = pG->Messages.GetEntry(LT_027); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else if((unsigned int)firstOccurance == currentToken.Length() - 1) // = sign at end + { + commandName = currentToken.ExtractSubString( 0, currentToken.Length()-2 ); + state = ELookingForDefault; + } + else // know that is of from = + { + commandName = currentToken.ExtractSubString( 0, firstOccurance - 1 ); + defaultValue = currentToken.ExtractSubString( firstOccurance + 1, currentToken.Length()-1 ); + if(IsAnRlsItem(commandName)) + { + Message * message = pG->Messages.GetEntry(LT_040); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else if(IsAnRlsItem(defaultValue)) + { + Message * message = pG->Messages.GetEntry(LT_041); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else // no problems so go and look next for an rls item + { + state = ELookingForRlsItem; + } + } + break; + case(ELookingForEqualSignOrRlsItem): + firstOccurance = currentToken.FindSubString("="); + if(firstOccurance == EStringNotFound) // element must be rls item or error + { + if(IsAnRlsItem(currentToken)) + { + rlsItem = currentToken; + state = EShouldBeFinished; + validOptionalDeclaration = true; + } + else // not an rls item + { + Message * message = pG->Messages.GetEntry(LT_035); + if(message->GetActivated()) + { + String comment = message->GetMessageOutput(); + comment += currentToken; + pGL->AddWarningToStore(fileName, lineNumber, comment); + } + return; + } + } + else if(currentToken.FindSubString("=",firstOccurance+1)!=EStringNotFound) // more than one = sign + { + Message * message = pG->Messages.GetEntry(LT_027); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else if(firstOccurance != 0) // = sign not at start + { + Message * message = pG->Messages.GetEntry(LT_042); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else if(currentToken.Length() == 1) // = sign by itself + { + state = ELookingForDefault; + } + else + { + defaultValue = currentToken.ExtractSubString( 1, currentToken.Length()-1 ); + if(IsAnRlsItem(defaultValue)) // if found rls item where default value should be + { + Message * message = pG->Messages.GetEntry(LT_041); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else + { + state = ELookingForRlsItem; + } + } + break; + case(ELookingForDefault): + firstOccurance = currentToken.FindSubString("="); + if(firstOccurance != EStringNotFound) // should not find any more equal signs on the line + { + Message * message = pG->Messages.GetEntry(LT_027); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else + { + defaultValue = currentToken; + if(IsAnRlsItem(defaultValue)) //check that default value is not an rls item + { + Message * message = pG->Messages.GetEntry(LT_041); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + else + { + state = ELookingForRlsItem; + } + } + break; + case(ELookingForRlsItem): + rlsItem = currentToken; + if(IsAnRlsItem(rlsItem) == false) + { + Message * message = pG->Messages.GetEntry(LT_035); + if(message->GetActivated()) + { + String comment = message->GetMessageOutput(); + comment += rlsItem; + pGL->AddWarningToStore(fileName, lineNumber, comment); + } + return; + } + else + { + state = EShouldBeFinished; + validOptionalDeclaration = true; + } + break; + case(EShouldBeFinished): + Message * message = pG->Messages.GetEntry(LT_043); + if(message->GetActivated()) + { + String comment = message->GetMessageOutput(); + comment += currentToken; + pGL->AddWarningToStore(fileName, lineNumber, comment); + } + return; + } + } + + if(validOptionalDeclaration == false) // end of line reached prematurely + { + Message * message = pG->Messages.GetEntry(LT_044); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + + + int entryNumber = GetTagDeclaredIndex(commandName); + if(entryNumber == -1) + { + CommentTagPair dataToAdd(commandName); + iCommentDefinitions.push_back(dataToAdd); + } + else + { + int requirementStatus = iCommentDefinitions[entryNumber].GetRequirementStatus(rlsItem); + if(requirementStatus != EForbidden) + { + Message * message = pG->Messages.GetEntry(LT_025); + if(message->GetActivated()) + { + pGL->AddWarningToStore(fileName, lineNumber, message->GetMessageOutput()); + } + return; + } + } + + if(defaultValue.Length()) + StoreRlsItem(commandName, rlsItem, EOptionalWithDefault, defaultValue); + else + StoreRlsItem(commandName, rlsItem, EOptional); + } + + +void GlobalLocalisationData::AddWarningToStore(const String aFileName, int aLineNumber, String aComment) + { + WarningToOutput warning(aFileName, aLineNumber, aComment); + iWarningStore.push_back(warning); + } + +void GlobalLocalisationData::PrintLocalisationWarnings() + { + std::vector warningStore; + unsigned int j; + unsigned int numberOfWarnings = iWarningStore.size(); + std::vector flags; + for(j=0 ; j=0) + { + flags[currentBestIndex]=0; + WarningToOutput warning(warningStore[currentBestIndex]); + iWarningStore.push_back(warning); + totalLeft--; + } + } + for(j=0; j< numberOfWarnings; j++) // outputs warning in alphabetical file order, by line number within a file + { + String fileName = iWarningStore[j].GetFileName(); + ErrorHandler::Register(& fileName, iWarningStore[j].GetLineNumber()); + ErrorHandler::OutputErrorLine(iWarningStore[j].GetComment()); + } + } + +void GlobalLocalisationData::OutputLocalisedFile(String SourceFileName) + { // reparse the source file and output a file with the optional tags with defaults added in + + char fileChar; + char * fileCharAsArray = new char[2]; + fileCharAsArray[0] = 'a'; + fileCharAsArray[1]='\0'; + const char * fileName = SourceFileName.GetAssertedNonEmptyBuffer(); + ifstream iFile(fileName); + +#ifdef __LINUX__ + char LocalisationOutputFileName[sizeof("/tmp/rcomp_temp_XXXXXX")]; + strcpy(LocalisationOutputFileName,"/tmp/rcomp_temp_XXXXXX"); + int fd = mkstemp(LocalisationOutputFileName); close(fd); +#endif +#ifdef WIN32 + char * LocalisationOutputFileName; + LocalisationOutputFileName = tmpnam(NULL); +#endif + + ofstream outputFile(LocalisationOutputFileName); + + String fileLine(""); + int fileLineLength = fileLine.Length(); + int previousState; + int state = EStartOfLine; + int currentFileLine = 1; + String currentFileName = SourceFileName; + int newLineNumber = -1; + String newFileName(""); + String newLineNumberAsString(""); + bool validLine = false; + while(iFile.get(fileChar)) // read file character by character looking for file declaration lines + { + fileCharAsArray[0]=fileChar; + if(state == EStartOfLine) // add character to store of this line + fileLine = fileCharAsArray; + else + fileLine += fileCharAsArray; + previousState = state; + switch(state) + { + case(EStartOfLine): + switch(fileChar) + { + case('#'): + state = EFindLineNo; + break; + case('\n'): + break; + default: + state = EGeneral; + } + break; + case(EGeneral): + switch(fileChar) + { + case('\n'): + state = EStartOfLine; + break; + } + break; + case(EFindLineNo): + switch(fileChar) + { + case('\n'): + state = EStartOfLine; + break; + case('0'): + case('1'): + case('2'): + case('3'): + case('4'): + case('5'): + case('6'): + case('7'): + case('8'): + case('9'): + state = EInLineNo; + break; + case(' '): + case('\t'): + break; + default: + state = EGeneral; + } + break; + case(EInLineNo): + switch(fileChar) + { + case('\n'): + state = EStartOfLine; + break; + case('0'): + case('1'): + case('2'): + case('3'): + case('4'): + case('5'): + case('6'): + case('7'): + case('8'): + case('9'): + break; + case(' '): + case('\t'): + state = EFindFileName; + break; + default: + state = EGeneral; + } + break; + case(EFindFileName): + switch(fileChar) + { + case('\n'): + state = EStartOfLine; + break; + case(' '): + case('\t'): + break; + case('\"'): + state = EInFileName; + break; + default: + state = EGeneral; + } + break; + case(EInFileName): + switch(fileChar) + { + case('\n'): + state = EStartOfLine; + break; + case(' '): + case('\t'): + state = EGeneral; + break; + case('\"'): + state = EFindDigit; + break; + } + break; + case(EFindDigit): + switch(fileChar) + { + case('\n'): + state = EStartOfLine; + break; + case(' '): + case('\t'): + break; + case('1'): + case('2'): + state = EAfterDigit; + break; + default: + state = EGeneral; + } + break; + case(EAfterDigit): + switch(fileChar) + { + case('\n'): + state = EStartOfLine; + break; + case(' '): + case('\t'): + break; + default: + state = EGeneral; + } + break; + } + int lineOfInterest; + switch(state) + { + case(EStartOfLine): + if(validLine) //validline will be true if this line is a file line declaration + { + currentFileName = newFileName; + currentFileLine = newLineNumber - 1; + } + validLine = false; + newFileName.Reset(); + newLineNumber = -1; + newLineNumberAsString.Reset(); + fileLineLength = fileLine.Length(); + lineOfInterest = NeedToAddDefaultData(currentFileName, currentFileLine); //checks if previous line was the end of a localisation tag and whether that tag has optional data to add + if(lineOfInterest > -1) // data to add + { + int end = fileLine.FindSubString("*/"); + String tempString; + if(end) + { + tempString = fileLine.ExtractSubString(0,end-1); + outputFile.write(tempString.GetBuffer(),tempString.Length()); + outputFile.write("\n",1); + } + unsigned int numberOfLinesToAdd = iCommentTagStore[lineOfInterest].GetNumberOfOptionalLinesToAdd(); + for(unsigned int j=0; jMessages.GetEntry(LT_037); + if(message->GetActivated()) + { + cerr << message->GetMessageOutput() << endl; + } + } + else + { + rename(LocalisationOutputFileName, fileName); + } + delete []fileCharAsArray; + } + + +#ifdef __VC32__ +#pragma warning( pop ) +#endif