sped up strip_comments, and added File::SaveFromString() in the process of hunting down a recursive c include.

svn path=/trunk/; revision=6731
This commit is contained in:
Royce Mitchell III 2003-11-20 18:27:33 +00:00
parent 8a095f86fc
commit ef60bea82e
4 changed files with 22 additions and 5 deletions

View file

@ -118,3 +118,12 @@ void File::close()
s.resize ( len );
return true;
}
/*static*/ bool File::SaveFromString ( const char* filename, const std::string& s, bool binary )
{
File out ( filename, binary ? "wb" : "w" );
if ( !out.isopened() )
return false;
out.write ( s.c_str(), s.size() );
return true;
}

View file

@ -99,6 +99,7 @@ public:
}
static bool LoadIntoString ( std::string& s, const char* filename );
static bool SaveFromString ( const char* filename, const std::string& s, bool binary );
private:
File(const File&) {}

View file

@ -58,6 +58,7 @@ const char* libc_includes[] =
{
"basestd.h",
"except.h",
"float.h",
"limits.h",
"stdarg.h",
"stddef.h",
@ -87,6 +88,8 @@ BOOL FileEnumProc ( PWIN32_FIND_DATA pwfd, const char* filename, long lParam )
void main()
{
//import_file ( "coff.h" );
File f ( "input.lst", "r" );
if ( !f.isopened() )
{
@ -133,7 +136,7 @@ bool import_file ( const char* filename )
/*{
string no_comments ( filename );
no_comments += ".nocom.txt";
File::SaveFromString ( s, no_comments );
File::SaveFromString ( no_comments.c_str(), s, false );
}*/
Header* h = new Header ( filename );

View file

@ -23,10 +23,14 @@ void strip_comments ( std::string& s, bool strip_lf )
else if ( src[0] == '/' && src[1] == '*' )
{
src += 2;
while ( *src && ( src[0] != '*' || src[1] != '/' ) )
src++;
if ( *src )
src += 2;
char* newsrc = strstr ( src, "*/" );
if ( !newsrc )
break;
src = newsrc;
//while ( *src && ( src[0] != '*' || src[1] != '/' ) )
// src++;
if ( *src ) src++;
if ( *src ) src++;
}
else if ( src[0] == '\r' && strip_lf )
src++;