@@ -446,23 +446,16 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
446446 location.fileIndex = fileIndex (cback ()->str ().substr (1U , cback ()->str ().size () - 2U ));
447447 location.line = 1U ;
448448 } else if (lastline == " # line %num%" ) {
449- const Location loc1 = location;
449+ loc. push ( location) ;
450450 location.line = std::atol (cback ()->str ().c_str ());
451- if (location.line < loc1.line )
452- location.line = loc1.line ;
453451 } else if (lastline == " # line %num% %str%" ) {
454- const Location loc1 = location;
452+ loc. push ( location) ;
455453 location.fileIndex = fileIndex (cback ()->str ().substr (1U , cback ()->str ().size () - 2U ));
456454 location.line = std::atol (cback ()->previous ->str ().c_str ());
457- if (loc1.fileIndex == location.fileIndex && location.line < loc1.line )
458- location.line = loc1.line ;
459455 } else if (lastline == " # %num% %str%" ) {
460- const Location loc1 = location;
461456 loc.push (location);
462457 location.fileIndex = fileIndex (cback ()->str ().substr (1U , cback ()->str ().size () - 2U ));
463458 location.line = std::atol (cback ()->previous ->str ().c_str ());
464- if (loc1.fileIndex == location.fileIndex && location.line < loc1.line )
465- location.line = loc1.line ;
466459 }
467460 // #endfile
468461 else if (lastline == " # endfile" && !loc.empty ()) {
@@ -555,8 +548,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
555548 else if (ch == ' \" ' || ch == ' \' ' ) {
556549 std::string prefix;
557550 if (cback () && cback ()->name && isStringLiteralPrefix (cback ()->str ()) &&
558- ((cback ()->location .col + cback ()->str ().size ()) == location.col ) &&
559- (cback ()->location .line == location.line )) {
551+ ((cback ()->location .col + cback ()->str ().size ()) == location.col )) {
560552 prefix = cback ()->str ();
561553 }
562554 // C++11 raw string literal
@@ -1124,9 +1116,9 @@ std::string simplecpp::TokenList::lastLine(int maxsize) const
11241116 if (tok->comment )
11251117 continue ;
11261118 if (!ret.empty ())
1127- ret. insert ( 0 , 1 , ' ' ) ;
1128- ret. insert ( 0 , tok->str ()[0 ] == ' \" ' ? std::string (" %str%" )
1129- : tok->number ? std::string (" %num%" ) : tok->str ());
1119+ ret = ' ' + ret ;
1120+ ret = ( tok->str ()[0 ] == ' \" ' ? std::string (" %str%" )
1121+ : tok->number ? std::string (" %num%" ) : tok->str ()) + ret ;
11301122 if (++count > maxsize)
11311123 return " " ;
11321124 }
@@ -2024,7 +2016,7 @@ static std::string realFilename(const std::string &f)
20242016 continue ;
20252017 }
20262018
2027- bool isDriveSpecification =
2019+ bool isDriveSpecification =
20282020 (pos == 2 && subpath.size () == 2 && std::isalpha (subpath[0 ]) && subpath[1 ] == ' :' );
20292021
20302022 // Append real filename (proper case)
@@ -2290,21 +2282,23 @@ static std::string _openHeader(std::ifstream &f, const std::string &path)
22902282#endif
22912283}
22922284
2293- static std::string openHeader (std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header)
2285+ static std::string openHeader (std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader )
22942286{
22952287 if (isAbsolutePath (header)) {
22962288 return _openHeader (f, header);
22972289 }
22982290
2299- if (sourcefile.find_first_of (" \\ /" ) != std::string::npos) {
2300- const std::string s = sourcefile.substr (0 , sourcefile.find_last_of (" \\ /" ) + 1U ) + header;
2301- const std::string simplePath = _openHeader (f, s);
2302- if (!simplePath.empty ())
2303- return simplePath;
2304- } else {
2305- const std::string simplePath = _openHeader (f, header);
2306- if (!simplePath.empty ())
2307- return simplePath;
2291+ if (!systemheader) {
2292+ if (sourcefile.find_first_of (" \\ /" ) != std::string::npos) {
2293+ const std::string s = sourcefile.substr (0 , sourcefile.find_last_of (" \\ /" ) + 1U ) + header;
2294+ std::string simplePath = _openHeader (f, s);
2295+ if (!simplePath.empty ())
2296+ return simplePath;
2297+ } else {
2298+ std::string simplePath = _openHeader (f, header);
2299+ if (!simplePath.empty ())
2300+ return simplePath;
2301+ }
23082302 }
23092303
23102304 for (std::list<std::string>::const_iterator it = dui.includePaths .begin (); it != dui.includePaths .end (); ++it) {
@@ -2413,7 +2407,7 @@ std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::To
24132407 continue ;
24142408
24152409 std::ifstream f;
2416- const std::string header2 = openHeader (f,dui,sourcefile,header);
2410+ const std::string header2 = openHeader (f,dui,sourcefile,header,systemheader );
24172411 if (!f.is_open ())
24182412 continue ;
24192413
@@ -2634,7 +2628,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
26342628 if (header2.empty ()) {
26352629 // try to load file..
26362630 std::ifstream f;
2637- header2 = openHeader (f, dui, rawtok->location .file (), header);
2631+ header2 = openHeader (f, dui, rawtok->location .file (), header, systemheader );
26382632 if (f.is_open ()) {
26392633 TokenList *tokens = new TokenList (f, files, header2, outputList);
26402634 filedata[header2] = tokens;
0 commit comments