fix utf8 IO_ERROR() compile problem

This commit is contained in:
Dick Hollenbeck 2010-12-27 23:35:57 -06:00
parent a7c11a0b11
commit 53249cda85
5 changed files with 48 additions and 44 deletions

View File

@ -30,6 +30,7 @@
#include <wx/string.h>
#include <string>
/**
* Struct IO_ERROR
@ -41,18 +42,13 @@ struct IO_ERROR
{
wxString errorText;
IO_ERROR( const wxChar* aMsg ) :
errorText( aMsg )
{
}
IO_ERROR( const wxString& aMsg ) :
errorText( aMsg )
{
}
IO_ERROR( const char* aMsg ) :
errorText( wxConvertMB2WX( aMsg ) )
IO_ERROR( const std::string& aMsg ) :
errorText( wxConvertMB2WX( aMsg.c_str() ) )
{
}
};
@ -66,7 +62,7 @@ struct 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 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 );
msg += "; cannot open(O_RDONLY) file " + aFileName;
throw( IO_ERROR( msg.c_str() ) );
throw( IO_ERROR( msg ) );
}
struct stat fs;
@ -321,7 +321,7 @@ void DIR_LIB_SOURCE::readString( STRING* aResult, const STRING& aFileName ) thro
{
STRING msg = aFileName;
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
@ -334,7 +334,7 @@ void DIR_LIB_SOURCE::readString( STRING* aResult, const STRING& aFileName ) thro
{
STRING msg = strerror( errno );
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
@ -447,7 +447,7 @@ void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const S
if( it == partnames.end() ) // part not found
{
partName += " not found.";
throw IO_ERROR( partName.c_str() );
throw IO_ERROR( 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 )
{
partName += " rev not found.";
throw IO_ERROR( partName.c_str() );
throw IO_ERROR( partName );
}
readString( aResult, makeFileName( *it ) );
@ -531,7 +531,7 @@ void DIR_LIB_SOURCE::cacheOneDir( const STRING& aCategory ) throw( IO_ERROR )
{
STRING msg = strerror( errno );
msg += "; scanning directory " + curDir;
throw( IO_ERROR( msg.c_str() ) );
throw( IO_ERROR( msg ) );
}
struct stat fs;
@ -557,7 +557,7 @@ void DIR_LIB_SOURCE::cacheOneDir( const STRING& aCategory ) throw( IO_ERROR )
{
STRING msg = partName;
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 ) :
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 )
{
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
// 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.
if( !InsertLib( row ) )
if( !InsertRow( row ) )
{
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
// anything which would require using the heap. This function is the reason
// ptr_map<> was used instead of ptr_set<>, which would have required
// instantiating a ROW just to find a ROW.
LIB_TABLE* cur = this;
ROWS_CITER it;
ROWS_CITER it = rows.find( aLogicalName );
if( it != rows.end() )
do
{
// reference: http://myitcorner.com/blog/?p=361
return (const LIB_TABLE::ROW*) it->second; // found
}
it = cur->rows.find( aLogicalName );
// not found, search fall back table
if( fallBack )
return fallBack->FindLib( aLogicalName );
if( it != cur->rows.end() )
{
// 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
}
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 );
@ -209,9 +212,9 @@ bool LIB_TABLE::InsertLib( auto_ptr<ROW>& aRow, bool doReplace )
void LIB_TABLE::Test()
{
// the null string is not really a legal DSN token since any double quotes
// are assumed to be a single quote. To pass an empty string, we pass " "
// to (options " ")
// the null string is not really a legal DSN token since any duplicated
// double quote ("") is assumed to be a single double quote (").
// To pass an empty string, we can pass " " to (options " ")
SCH_LIB_TABLE_LEXER slr(
"(lib_table \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( "\ntest a lookup of 'www':\n" );
sf.Clear();
const LIB_TABLE::ROW* www = FindLib( "www" );
const LIB_TABLE::ROW* www = FindRow( "www" );
if( www )
{
// found, print it just to prove it.
sf.Clear();
www->Format( &sf, 1 );
printf( "%s", sf.GetString().c_str() );
}

View File

@ -273,7 +273,7 @@ public:
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
* 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.
@ -281,13 +281,13 @@ protected: // only a table editor can use these
* if the key already exists.
* @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
* returns a ROW* if aLogicalName is found in this table or in fallBack.
* Function FindRow
* 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:

View File

@ -9,14 +9,13 @@
set( CMAKE_SYSTEM_NAME Linux )
# Specific to Dick's machine, again for testing only:
include_directories( /svn/wxWidgets/include )
#-----<configuration>-----------------------------------------------
# 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
set( CMAKE_C_COMPILER i586-mingw32msvc-gcc )
set( CMAKE_CXX_COMPILER i586-mingw32msvc-g++ )
@ -24,6 +23,9 @@ set( CMAKE_CXX_COMPILER i586-mingw32msvc-g++ )
# where is the target environment
set( CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc )
include_directories( ${WX_MINGW_BASE}/include )
#-----</configuration>-----------------------------------------------
@ -33,3 +35,6 @@ set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
# for libraries and headers in the target directories
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY 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 )