@@ -258,11 +258,10 @@ class AdbParser {
258258private:
259259 // METHODS
260260 string findFile (string fileName);
261- static bool is_relative (const string path);
262- static void includeFile (AdbParser *adbParser, string fileName,
263- int lineNumber = -1 );
264- static void startElement (void *adbParser, const XML_Char *name,
265- const XML_Char **atts);
261+ static void addIncludePaths (Adb *adbCtxt, string includePaths);
262+ static void includeFile (AdbParser *adbParser, string fileName, int lineNumber = -1 );
263+ static void startElement (void *adbParser, const XML_Char *name, const XML_Char **atts);
264+
266265 static void startNodesDefElement (const XML_Char **atts, AdbParser *adbParser);
267266 static void startEnumElement (const XML_Char **atts, AdbParser *adbParser, const int lineNumber);
268267 static void startConfigElement (const XML_Char **atts, AdbParser *adbParser, const int lineNumber);
@@ -271,9 +270,9 @@ class AdbParser {
271270 static void startInstOpAttrReplaceElement (const XML_Char **atts, AdbParser *adbParser, const int lineNumber);
272271 static void startNodeElement (const XML_Char **atts, AdbParser *adbParser, const int lineNumber);
273272 static void startFieldElement (const XML_Char **atts, AdbParser *adbParser, const int lineNumber);
273+
274274 static void endElement (void *adbParser, const XML_Char *name);
275- static void addReserved (vector<AdbField*> &reserveds, u_int32_t offset,
276- u_int32_t size);
275+ static void addReserved (vector<AdbField*> &reserveds, u_int32_t offset, u_int32_t size);
277276 static int attrCount (const XML_Char **atts);
278277 static string attrValue (const XML_Char **atts, const XML_Char *attrName);
279278 static string attrName (const XML_Char **atts, int i);
@@ -2058,16 +2057,6 @@ string AdbException::what_s() const {
20582057 return _msg;
20592058}
20602059
2061- /* *
2062- * Function: AdbParser::is_relative
2063- **/
2064- bool AdbParser::is_relative (const string path) {
2065- if (path[0 ] == ' /' ) {
2066- return false ;
2067- }
2068- return true ;
2069- }
2070-
20712060/* ************************** AdbParser Implementation ***************************/
20722061/* *
20732062 * Function: AdbParser::AdbParser
@@ -2081,8 +2070,28 @@ AdbParser::AdbParser(string fileName, Adb *adbCtxt, bool addReserved,
20812070 _currentConfig(0 ) {
20822071 _enforceExtraChecks = enforceExtraChecks;
20832072 if (includePath != " " ) {
2084- vector < string > paths;
2085- boost::algorithm::split (paths, includePath,
2073+ addIncludePaths (adbCtxt, includePath);
2074+ }
2075+ _xmlParser = XML_ParserCreate (0 );
2076+ XML_SetUserData (_xmlParser, this );
2077+ XML_SetElementHandler (_xmlParser, startElement, endElement);
2078+ if (adbCtxt->includePaths .size () == 0 ) {
2079+ // first add the opened project path
2080+ adbCtxt->includePaths .push_back (
2081+ _fileName.find (OS_PATH_SEP) == string::npos ? " ."
2082+ : _fileName.substr (0 , _fileName.rfind (OS_PATH_SEP)));
2083+ vector < string > path;
2084+ boost::algorithm::split (path, fileName,
2085+ boost::is_any_of (string (OS_PATH_SEP)));
2086+ IncludeFileInfo info = { fileName, " ROOT" , 0 };
2087+ _adbCtxt->includedFiles [path[path.size () - 1 ]] = info;
2088+ }
2089+ _instanceOps = false ;
2090+ }
2091+
2092+ void AdbParser::addIncludePaths (Adb *adbCtxt, string includePaths) {
2093+ vector < string > paths;
2094+ boost::algorithm::split (paths, includePaths,
20862095 boost::is_any_of (string (" ;" )));
20872096 adbCtxt->includePaths .insert (adbCtxt->includePaths .end (),
20882097 paths.begin (), paths.end ());
@@ -2094,29 +2103,13 @@ AdbParser::AdbParser(string fileName, Adb *adbCtxt, bool addReserved,
20942103
20952104 for (StringVector::iterator it = adbCtxt->includePaths .begin (); it
20962105 != adbCtxt->includePaths .end (); it++) {
2097- if (AdbParser::is_relative (*it)) {
2106+ if (projPath != " " && projPath != *it && boost::filesystem::path (*it). is_relative ( )) {
20982107 relatives.push_back (projPath + OS_PATH_SEP + *it);
20992108 }
21002109 }
21012110
21022111 adbCtxt->includePaths .insert (adbCtxt->includePaths .end (),
21032112 relatives.begin (), relatives.end ());
2104- }
2105- _xmlParser = XML_ParserCreate (0 );
2106- XML_SetUserData (_xmlParser, this );
2107- XML_SetElementHandler (_xmlParser, startElement, endElement);
2108- if (adbCtxt->includePaths .size () == 0 ) {
2109- // first add the opened project path
2110- adbCtxt->includePaths .push_back (
2111- _fileName.find (OS_PATH_SEP) == string::npos ? " ."
2112- : _fileName.substr (0 , _fileName.rfind (OS_PATH_SEP)));
2113- vector < string > path;
2114- boost::algorithm::split (path, fileName,
2115- boost::is_any_of (string (OS_PATH_SEP)));
2116- IncludeFileInfo info = { fileName, " ROOT" , 0 };
2117- _adbCtxt->includedFiles [path[path.size () - 1 ]] = info;
2118- }
2119- _instanceOps = false ;
21202113}
21212114
21222115/* *
@@ -2362,6 +2355,12 @@ string AdbParser::findFile(string fileName) {
23622355 if (f) {
23632356 fclose (f);
23642357 return filePath;
2358+ } else if (fileName.find (_adbCtxt->includePaths [i]) != string::npos) { // includePath is part of fileName
2359+ f = fopen (fileName.c_str (), " r" );
2360+ if (f) {
2361+ fclose (f);
2362+ return fileName;
2363+ }
23652364 }
23662365 }
23672366 return string ();
@@ -2462,7 +2461,7 @@ void AdbParser::includeFile(AdbParser *adbParser, string fileName,
24622461 string filePath;
24632462 FILE *probeFile = NULL ;
24642463
2465- if (!AdbParser::is_relative (fileName)) {
2464+ if (!boost::filesystem::path (fileName). is_relative ( )) {
24662465 probeFile = fopen (fileName.c_str (), " r" );
24672466 }
24682467
@@ -2478,7 +2477,7 @@ void AdbParser::includeFile(AdbParser *adbParser, string fileName,
24782477
24792478 // Update filename to be only base name with extension to prevent duplications
24802479 boost::filesystem::path boostPath (filePath);
2481- fileName = string ( boostPath.filename ().c_str () );
2480+ fileName = boostPath.filename ().string ( );
24822481
24832482 if (!adbParser->_adbCtxt ->includedFiles .count (fileName)) {
24842483 IncludeFileInfo info = { filePath, adbParser->_fileName , lineNumber };
@@ -2487,7 +2486,7 @@ void AdbParser::includeFile(AdbParser *adbParser, string fileName,
24872486 // parse the included file
24882487 AdbParser p (filePath, adbParser->_adbCtxt , adbParser->_addReserved ,
24892488 adbParser->_progressObj , adbParser->_strict ,
2490- adbParser-> _includePath , adbParser->_enforceExtraChecks );
2489+ " " , adbParser->_enforceExtraChecks );
24912490 if (!p.load ()) {
24922491 throw AdbException (p.getError ());
24932492 }
@@ -2506,6 +2505,7 @@ void AdbParser::includeAllFilesInDir(AdbParser *adbParser, string dirPath,
25062505 boost::filesystem::path fsPath (*pathIt);
25072506 if (boost::filesystem::exists (fsPath)
25082507 && boost::filesystem::is_directory (fsPath)) {
2508+ addIncludePaths (adbParser->_adbCtxt , *pathIt);
25092509 boost::filesystem::directory_iterator filesIter (fsPath), dirEnd;
25102510 for (; filesIter != dirEnd; ++filesIter) {
25112511 if (boost::filesystem::is_regular_file (filesIter->status ())
@@ -2679,7 +2679,7 @@ void AdbParser::startConfigElement(const XML_Char **atts, AdbParser *adbParser,
26792679 for (StringVector::iterator it =
26802680 adbParser->_adbCtxt ->includePaths .begin (); it
26812681 != adbParser->_adbCtxt ->includePaths .end (); it++) {
2682- if (AdbParser::is_relative (*it)) {
2682+ if (boost::filesystem::path (*it). is_relative ( )) {
26832683 relatives.push_back (projPath + OS_PATH_SEP + *it);
26842684 }
26852685 }
0 commit comments