fix utf8 IO_ERROR() compile problem

This commit is contained in:
Dick Hollenbeck 2010-12-27 23:37:23 -06:00
commit 02e1f83906
5 changed files with 48 additions and 44 deletions

View File

@ -30,6 +30,7 @@
#include <wx/string.h> #include <wx/string.h>
#include <string>
/** /**
* Struct IO_ERROR * Struct IO_ERROR
@ -41,18 +42,13 @@ struct IO_ERROR
{ {
wxString errorText; wxString errorText;
IO_ERROR( const wxChar* aMsg ) :
errorText( aMsg )
{
}
IO_ERROR( const wxString& aMsg ) : IO_ERROR( const wxString& aMsg ) :
errorText( aMsg ) errorText( aMsg )
{ {
} }
IO_ERROR( const char* aMsg ) : IO_ERROR( const std::string& aMsg ) :
errorText( wxConvertMB2WX( aMsg ) ) errorText( wxConvertMB2WX( aMsg.c_str() ) )
{ {
} }
}; };
@ -66,7 +62,7 @@ struct IO_ERROR
*/ */
struct PARSE_ERROR : public IO_ERROR struct PARSE_ERROR : public IO_ERROR
{ {
wxString source; ///< filename typically, unless from RAM wxString source; ///< filename typically, or other source
int lineNumber; int lineNumber;
int byteIndex; ///< char offset, starting from 1, into the problem line. int byteIndex; ///< char offset, starting from 1, into the problem line.

View File

@ -309,7 +309,7 @@ void DIR_LIB_SOURCE::readString( STRING* aResult, const STRING& aFileName ) thro
{ {
STRING msg = strerror( errno ); STRING msg = strerror( errno );
msg += "; cannot open(O_RDONLY) file " + aFileName; msg += "; cannot open(O_RDONLY) file " + aFileName;
throw( IO_ERROR( msg.c_str() ) ); throw( IO_ERROR( msg ) );
} }
struct stat fs; struct stat fs;
@ -321,7 +321,7 @@ void DIR_LIB_SOURCE::readString( STRING* aResult, const STRING& aFileName ) thro
{ {
STRING msg = aFileName; STRING msg = aFileName;
msg += " seems too big. ( > 1 mbyte )"; msg += " seems too big. ( > 1 mbyte )";
throw IO_ERROR( msg.c_str() ); throw IO_ERROR( msg );
} }
// reuse same readBuffer, which is not thread safe, but the API // reuse same readBuffer, which is not thread safe, but the API
@ -334,7 +334,7 @@ void DIR_LIB_SOURCE::readString( STRING* aResult, const STRING& aFileName ) thro
{ {
STRING msg = strerror( errno ); STRING msg = strerror( errno );
msg += "; cannot read file " + aFileName; msg += "; cannot read file " + aFileName;
throw( IO_ERROR( msg.c_str() ) ); throw( IO_ERROR( msg ) );
} }
// std::string chars are not guaranteed to be contiguous in // std::string chars are not guaranteed to be contiguous in
@ -447,7 +447,7 @@ void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const S
if( it == partnames.end() ) // part not found if( it == partnames.end() ) // part not found
{ {
partName += " not found."; partName += " not found.";
throw IO_ERROR( partName.c_str() ); throw IO_ERROR( partName );
} }
readString( aResult, makeFileName( partName ) ); readString( aResult, makeFileName( partName ) );
@ -466,7 +466,7 @@ void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const S
if( it == partnames.end() || it->compare( 0, search.size(), search ) != 0 ) if( it == partnames.end() || it->compare( 0, search.size(), search ) != 0 )
{ {
partName += " rev not found."; partName += " rev not found.";
throw IO_ERROR( partName.c_str() ); throw IO_ERROR( partName );
} }
readString( aResult, makeFileName( *it ) ); readString( aResult, makeFileName( *it ) );
@ -531,7 +531,7 @@ void DIR_LIB_SOURCE::cacheOneDir( const STRING& aCategory ) throw( IO_ERROR )
{ {
STRING msg = strerror( errno ); STRING msg = strerror( errno );
msg += "; scanning directory " + curDir; msg += "; scanning directory " + curDir;
throw( IO_ERROR( msg.c_str() ) ); throw( IO_ERROR( msg ) );
} }
struct stat fs; struct stat fs;
@ -557,7 +557,7 @@ void DIR_LIB_SOURCE::cacheOneDir( const STRING& aCategory ) throw( IO_ERROR )
{ {
STRING msg = partName; STRING msg = partName;
msg += " has already been encountered"; msg += " has already been encountered";
throw IO_ERROR( msg.c_str() ); throw IO_ERROR( msg );
} }
} }

View File

@ -33,7 +33,7 @@ using namespace SCH;
LIB_TABLE::LIB_TABLE( LIB_TABLE* aFallBackTable ) : LIB_TABLE::LIB_TABLE( LIB_TABLE* aFallBackTable ) :
fallBack( aFallBackTable ) fallBack( aFallBackTable )
{ {
/* not copying fall back, simply search it separately if "logicalName not found". /* not copying fall back, simply search aFallBackTable separately if "logicalName not found".
if( aFallBackTable ) if( aFallBackTable )
{ {
const ROWS& t = aFallBackTable->rows; const ROWS& t = aFallBackTable->rows;
@ -130,9 +130,9 @@ void LIB_TABLE::Parse( SCH_LIB_TABLE_LEXER* in ) throw( IO_ERROR )
// all logicalNames within this table fragment must be unique, so we do not // all logicalNames within this table fragment must be unique, so we do not
// replace. However a fallBack table can have a conflicting logicalName // replace. However a fallBack table can have a conflicting logicalName
// and ours will supercede that one since in findLib() we search this table // and ours will supercede that one since in FindLib() we search this table
// before any fall back. // before any fall back.
if( !InsertLib( row ) ) if( !InsertRow( row ) )
{ {
char buf[300]; char buf[300];
@ -163,30 +163,33 @@ void LIB_TABLE::ROW::Format( OUTPUTFORMATTER* out, int nestLevel ) const
} }
const LIB_TABLE::ROW* LIB_TABLE::FindLib( const STRING& aLogicalName ) const LIB_TABLE::ROW* LIB_TABLE::FindRow( const STRING& aLogicalName )
{ {
// this function must be *super* fast, so therefore should not instantiate // this function must be *super* fast, so therefore should not instantiate
// anything which would require using the heap. This function is the reason // anything which would require using the heap. This function is the reason
// ptr_map<> was used instead of ptr_set<>, which would have required // ptr_map<> was used instead of ptr_set<>, which would have required
// instantiating a ROW just to find a ROW. // instantiating a ROW just to find a ROW.
LIB_TABLE* cur = this;
ROWS_CITER it;
ROWS_CITER it = rows.find( aLogicalName ); do
if( it != rows.end() )
{ {
// reference: http://myitcorner.com/blog/?p=361 it = cur->rows.find( aLogicalName );
return (const LIB_TABLE::ROW*) it->second; // found
}
// not found, search fall back table if( it != cur->rows.end() )
if( fallBack ) {
return fallBack->FindLib( aLogicalName ); // reference: http://myitcorner.com/blog/?p=361
return (const LIB_TABLE::ROW*) it->second; // found
}
// not found, search fall back table(s), if any
} while( ( cur = cur->fallBack ) != 0 );
return 0; // not found return 0; // not found
} }
bool LIB_TABLE::InsertLib( auto_ptr<ROW>& aRow, bool doReplace ) bool LIB_TABLE::InsertRow( auto_ptr<ROW>& aRow, bool doReplace )
{ {
ROWS_ITER it = rows.find( aRow->logicalName ); ROWS_ITER it = rows.find( aRow->logicalName );
@ -209,9 +212,9 @@ bool LIB_TABLE::InsertLib( auto_ptr<ROW>& aRow, bool doReplace )
void LIB_TABLE::Test() void LIB_TABLE::Test()
{ {
// the null string is not really a legal DSN token since any double quotes // the null string is not really a legal DSN token since any duplicated
// are assumed to be a single quote. To pass an empty string, we pass " " // double quote ("") is assumed to be a single double quote (").
// to (options " ") // To pass an empty string, we can pass " " to (options " ")
SCH_LIB_TABLE_LEXER slr( SCH_LIB_TABLE_LEXER slr(
"(lib_table \n" "(lib_table \n"
" (lib (logical meparts) (type dir) (full_uri /tmp/eeschema-lib) (options \" \"))\n" " (lib (logical meparts) (type dir) (full_uri /tmp/eeschema-lib) (options \" \"))\n"
@ -249,12 +252,12 @@ void LIB_TABLE::Test()
printf( "%s", sf.GetString().c_str() ); printf( "%s", sf.GetString().c_str() );
printf( "\ntest a lookup of 'www':\n" ); printf( "\ntest a lookup of 'www':\n" );
sf.Clear(); const LIB_TABLE::ROW* www = FindRow( "www" );
const LIB_TABLE::ROW* www = FindLib( "www" );
if( www ) if( www )
{ {
// found, print it just to prove it. // found, print it just to prove it.
sf.Clear();
www->Format( &sf, 1 ); www->Format( &sf, 1 );
printf( "%s", sf.GetString().c_str() ); printf( "%s", sf.GetString().c_str() );
} }

View File

@ -273,7 +273,7 @@ public:
protected: // only a table editor can use these protected: // only a table editor can use these
/** /**
* Function InsertLib * Function InsertRow
* adds aRow if it does not already exist or if doReplace is true. If doReplace * adds aRow if it does not already exist or if doReplace is true. If doReplace
* is not true and the key for aRow already exists, the function fails and returns false. * is not true and the key for aRow already exists, the function fails and returns false.
* @param aRow is the new row to insert, or to forcibly add if doReplace is true. * @param aRow is the new row to insert, or to forcibly add if doReplace is true.
@ -281,13 +281,13 @@ protected: // only a table editor can use these
* if the key already exists. * if the key already exists.
* @return bool - true if the operation succeeded. * @return bool - true if the operation succeeded.
*/ */
bool InsertLib( std::auto_ptr<ROW>& aRow, bool doReplace = false ); bool InsertRow( std::auto_ptr<ROW>& aRow, bool doReplace = false );
/** /**
* Function FindLib * Function FindRow
* returns a ROW* if aLogicalName is found in this table or in fallBack. * returns a ROW* if aLogicalName is found in this table or in fallBack, else NULL.
*/ */
const ROW* FindLib( const STRING& aLogicalName ); const ROW* FindRow( const STRING& aLogicalName );
private: private:

View File

@ -9,14 +9,13 @@
set( CMAKE_SYSTEM_NAME Linux ) set( CMAKE_SYSTEM_NAME Linux )
# Specific to Dick's machine, again for testing only:
include_directories( /svn/wxWidgets/include )
#-----<configuration>----------------------------------------------- #-----<configuration>-----------------------------------------------
# configure only the lines within this <configure> block, typically # configure only the lines within this <configure> block, typically
# default is specific to Dick's machine, again for testing only:
set( WX_MINGW_BASE /opt/wx2.8-mingw )
# specify the cross compiler # specify the cross compiler
set( CMAKE_C_COMPILER i586-mingw32msvc-gcc ) set( CMAKE_C_COMPILER i586-mingw32msvc-gcc )
set( CMAKE_CXX_COMPILER i586-mingw32msvc-g++ ) set( CMAKE_CXX_COMPILER i586-mingw32msvc-g++ )
@ -24,6 +23,9 @@ set( CMAKE_CXX_COMPILER i586-mingw32msvc-g++ )
# where is the target environment # where is the target environment
set( CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc ) set( CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc )
include_directories( ${WX_MINGW_BASE}/include )
#-----</configuration>----------------------------------------------- #-----</configuration>-----------------------------------------------
@ -33,3 +35,6 @@ set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
# for libraries and headers in the target directories # for libraries and headers in the target directories
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
# try and pre-load this variable, or do it later in ccmake
set( wxWidgets_CONFIG_EXECUTABLE ${WX_MINGW_BASE}/bin/wx-config )