switch from STREAM_OUTPUTFORMATTER to FILE_OUTPUTFORMATTER mostly throughout,and minor richio factoring
This commit is contained in:
parent
58ae2e1920
commit
7c5e42b4d0
|
@ -289,12 +289,12 @@ const char* OUTPUTFORMATTER::GetQuoteChar( const char* wrapee, const char* quote
|
||||||
if( *wrapee == '#' )
|
if( *wrapee == '#' )
|
||||||
return quote_char;
|
return quote_char;
|
||||||
|
|
||||||
if( strlen(wrapee)==0 )
|
if( strlen( wrapee ) == 0 )
|
||||||
return quote_char;
|
return quote_char;
|
||||||
|
|
||||||
bool isFirst = true;
|
bool isFirst = true;
|
||||||
|
|
||||||
for( ; *wrapee; ++wrapee, isFirst=false )
|
for( ; *wrapee; ++wrapee, isFirst = false )
|
||||||
{
|
{
|
||||||
static const char quoteThese[] = "\t ()"
|
static const char quoteThese[] = "\t ()"
|
||||||
"%" // per Alfons of freerouting.net, he does not like this unquoted as of 1-Feb-2008
|
"%" // per Alfons of freerouting.net, he does not like this unquoted as of 1-Feb-2008
|
||||||
|
@ -314,12 +314,17 @@ const char* OUTPUTFORMATTER::GetQuoteChar( const char* wrapee, const char* quote
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* OUTPUTFORMATTER::GetQuoteChar( const char* wrapee )
|
||||||
|
{
|
||||||
|
return GetQuoteChar( wrapee, quoteChar );
|
||||||
|
}
|
||||||
|
|
||||||
int OUTPUTFORMATTER::vprint( const char* fmt, va_list ap ) throw( IO_ERROR )
|
int OUTPUTFORMATTER::vprint( const char* fmt, va_list ap ) throw( IO_ERROR )
|
||||||
{
|
{
|
||||||
int ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap );
|
int ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap );
|
||||||
if( ret >= (int) buffer.size() )
|
if( ret >= (int) buffer.size() )
|
||||||
{
|
{
|
||||||
buffer.resize( ret+2000 );
|
buffer.resize( ret + 2000 );
|
||||||
ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap );
|
ret = vsnprintf( &buffer[0], buffer.size(), fmt, ap );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +427,7 @@ std::string OUTPUTFORMATTER::Quotes( const std::string& aWrapee ) throw( IO_ERRO
|
||||||
|
|
||||||
std::string OUTPUTFORMATTER::Quotew( const wxString& aWrapee ) throw( IO_ERROR )
|
std::string OUTPUTFORMATTER::Quotew( const wxString& aWrapee ) throw( IO_ERROR )
|
||||||
{
|
{
|
||||||
// s-expressions atoms are always encoded as UTF-8.
|
// wxStrings are always encoded as UTF-8 as we convert to a byte sequence.
|
||||||
// The non-virutal function calls the virtual workhorse function, and if
|
// The non-virutal function calls the virtual workhorse function, and if
|
||||||
// a different quoting or escaping strategy is desired from the standard,
|
// a different quoting or escaping strategy is desired from the standard,
|
||||||
// a derived class can overload Quotes() above, but
|
// a derived class can overload Quotes() above, but
|
||||||
|
@ -455,8 +460,9 @@ void STRING_FORMATTER::StripUseless()
|
||||||
|
|
||||||
//-----<FILE_OUTPUTFORMATTER>----------------------------------------
|
//-----<FILE_OUTPUTFORMATTER>----------------------------------------
|
||||||
|
|
||||||
FILE_OUTPUTFORMATTER::FILE_OUTPUTFORMATTER( const wxString& aFileName, const wxChar* aMode )
|
FILE_OUTPUTFORMATTER::FILE_OUTPUTFORMATTER( const wxString& aFileName,
|
||||||
throw( IO_ERROR ) :
|
const wxChar* aMode, char aQuoteChar ) throw( IO_ERROR ) :
|
||||||
|
OUTPUTFORMATTER( OUTPUTFMTBUFZ, aQuoteChar ),
|
||||||
m_filename( aFileName )
|
m_filename( aFileName )
|
||||||
{
|
{
|
||||||
m_fp = wxFopen( aFileName, aMode );
|
m_fp = wxFopen( aFileName, aMode );
|
||||||
|
@ -492,12 +498,6 @@ void FILE_OUTPUTFORMATTER::write( const char* aOutBuf, int aCount ) throw( IO_ER
|
||||||
|
|
||||||
//-----<STREAM_OUTPUTFORMATTER>--------------------------------------
|
//-----<STREAM_OUTPUTFORMATTER>--------------------------------------
|
||||||
|
|
||||||
const char* STREAM_OUTPUTFORMATTER::GetQuoteChar( const char* wrapee )
|
|
||||||
{
|
|
||||||
return OUTPUTFORMATTER::GetQuoteChar( wrapee, quoteChar );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void STREAM_OUTPUTFORMATTER::write( const char* aOutBuf, int aCount ) throw( IO_ERROR )
|
void STREAM_OUTPUTFORMATTER::write( const char* aOutBuf, int aCount ) throw( IO_ERROR )
|
||||||
{
|
{
|
||||||
int lastWrite;
|
int lastWrite;
|
||||||
|
|
|
@ -124,9 +124,15 @@ void LIB_EDIT_FRAME::OnExportPart( wxCommandEvent& event )
|
||||||
|
|
||||||
SaveOnePartInMemory();
|
SaveOnePartInMemory();
|
||||||
|
|
||||||
wxFFileOutputStream os( fn.GetFullPath(), wxT( "wt" ) );
|
bool result = false;
|
||||||
|
|
||||||
if( !os.IsOk() )
|
try
|
||||||
|
{
|
||||||
|
FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
|
||||||
|
|
||||||
|
result = m_library->Save( formatter );
|
||||||
|
}
|
||||||
|
catch( ... /* IO_ERROR ioe */ )
|
||||||
{
|
{
|
||||||
fn.MakeAbsolute();
|
fn.MakeAbsolute();
|
||||||
msg = wxT( "Failed to create component library file " ) + fn.GetFullPath();
|
msg = wxT( "Failed to create component library file " ) + fn.GetFullPath();
|
||||||
|
@ -134,17 +140,13 @@ void LIB_EDIT_FRAME::OnExportPart( wxCommandEvent& event )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
STREAM_OUTPUTFORMATTER formatter( os );
|
if( result )
|
||||||
|
|
||||||
bool success = m_library->Save( formatter );
|
|
||||||
|
|
||||||
if( success )
|
|
||||||
m_lastLibExportPath = fn.GetPath();
|
m_lastLibExportPath = fn.GetPath();
|
||||||
|
|
||||||
delete m_library;
|
delete m_library;
|
||||||
m_library = CurLibTmp;
|
m_library = CurLibTmp;
|
||||||
|
|
||||||
if( success )
|
if( result )
|
||||||
{
|
{
|
||||||
if( createLib )
|
if( createLib )
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,24 +78,24 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileOutputStream os( aFileName, wxT( "wt" ) );
|
try
|
||||||
|
{
|
||||||
|
FILE_OUTPUTFORMATTER formatter( aFileName );
|
||||||
|
|
||||||
if( !os.IsOk() )
|
if( !libCache->Save( formatter ) )
|
||||||
|
{
|
||||||
|
msg.Printf( _( "An error occurred attempting to save component library <%s>." ),
|
||||||
|
GetChars( aFileName ) );
|
||||||
|
DisplayError( this, msg );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( ... /* IO_ERROR ioe */ )
|
||||||
{
|
{
|
||||||
msg = wxT( "Failed to create component library file " ) + aFileName;
|
msg = wxT( "Failed to create component library file " ) + aFileName;
|
||||||
DisplayError( this, msg );
|
DisplayError( this, msg );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
STREAM_OUTPUTFORMATTER formatter( os );
|
|
||||||
|
|
||||||
if( !libCache->Save( formatter ) )
|
|
||||||
{
|
|
||||||
msg.Printf( _( "An error occurred attempting to save component \
|
|
||||||
library <%s>." ), GetChars( aFileName ) );
|
|
||||||
DisplayError( this, msg );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -360,9 +360,19 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileOutputStream libStream( libFileName.GetFullPath(), wxT( "wt" ) );
|
try
|
||||||
|
{
|
||||||
|
FILE_OUTPUTFORMATTER libFormatter( libFileName.GetFullPath() );
|
||||||
|
|
||||||
if( !libStream.IsOk() )
|
if( !m_library->Save( libFormatter ) )
|
||||||
|
{
|
||||||
|
msg = _( "Error occurred while saving library file \"" ) + fn.GetFullPath() + _( "\"." );
|
||||||
|
AppendMsgPanel( _( "*** ERROR: ***" ), msg, RED );
|
||||||
|
DisplayError( this, msg );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( ... /* IO_ERROR ioe */ )
|
||||||
{
|
{
|
||||||
libFileName.MakeAbsolute();
|
libFileName.MakeAbsolute();
|
||||||
msg = wxT( "Failed to create component library file " ) + libFileName.GetFullPath();
|
msg = wxT( "Failed to create component library file " ) + libFileName.GetFullPath();
|
||||||
|
@ -370,16 +380,6 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
STREAM_OUTPUTFORMATTER libFormatter( libStream );
|
|
||||||
|
|
||||||
if( !m_library->Save( libFormatter ) )
|
|
||||||
{
|
|
||||||
msg = _( "Error occurred while saving library file \"" ) + fn.GetFullPath() + _( "\"." );
|
|
||||||
AppendMsgPanel( _( "*** ERROR: ***" ), msg, RED );
|
|
||||||
DisplayError( this, msg );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFileName docFileName = libFileName;
|
wxFileName docFileName = libFileName;
|
||||||
|
|
||||||
docFileName.SetExt( DOC_EXT );
|
docFileName.SetExt( DOC_EXT );
|
||||||
|
@ -399,9 +399,20 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFFileOutputStream docStream( docFileName.GetFullPath(), wxT( "wt" ) );
|
try
|
||||||
|
{
|
||||||
|
FILE_OUTPUTFORMATTER docFormatter( docFileName.GetFullPath() );
|
||||||
|
|
||||||
if( !docStream.IsOk() )
|
if( !m_library->SaveDocs( docFormatter ) )
|
||||||
|
{
|
||||||
|
msg = _( "Error occurred while saving library document file \"" ) +
|
||||||
|
docFileName.GetFullPath() + _( "\"." );
|
||||||
|
AppendMsgPanel( _( "*** ERROR: ***" ), msg, RED );
|
||||||
|
DisplayError( this, msg );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( ... /* IO_ERROR ioe */ )
|
||||||
{
|
{
|
||||||
docFileName.MakeAbsolute();
|
docFileName.MakeAbsolute();
|
||||||
msg = wxT( "Failed to create component document library file " ) +
|
msg = wxT( "Failed to create component document library file " ) +
|
||||||
|
@ -410,17 +421,6 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
STREAM_OUTPUTFORMATTER docFormatter( docStream );
|
|
||||||
|
|
||||||
if( !m_library->SaveDocs( docFormatter ) )
|
|
||||||
{
|
|
||||||
msg = _( "Error occurred while saving library document file \"" ) +
|
|
||||||
docFileName.GetFullPath() + _( "\"." );
|
|
||||||
AppendMsgPanel( _( "*** ERROR: ***" ), msg, RED );
|
|
||||||
DisplayError( this, msg );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = _( "Library file \"" ) + fn.GetFullName() + wxT( "\" Ok" );
|
msg = _( "Library file \"" ) + fn.GetFullName() + wxT( "\" Ok" );
|
||||||
fn.SetExt( DOC_EXT );
|
fn.SetExt( DOC_EXT );
|
||||||
wxString msg1 = _( "Document file \"" ) + fn.GetFullPath() + wxT( "\" Ok" );
|
wxString msg1 = _( "Document file \"" ) + fn.GetFullPath() + wxT( "\" Ok" );
|
||||||
|
|
|
@ -1063,35 +1063,21 @@ bool NETLIST_EXPORT_TOOL::WriteKiCadNetList( const wxString& aOutFileName )
|
||||||
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
||||||
g_NetObjectslist[ii]->m_Flag = 0;
|
g_NetObjectslist[ii]->m_Flag = 0;
|
||||||
|
|
||||||
bool rc = false;
|
std::auto_ptr<XNODE> xroot( makeGenericRoot() );
|
||||||
wxFFileOutputStream os( aOutFileName, wxT( "wt" ) );
|
|
||||||
|
|
||||||
if( !os.IsOk() )
|
try
|
||||||
{
|
{
|
||||||
L_error:
|
FILE_OUTPUTFORMATTER formatter( aOutFileName );
|
||||||
wxString msg = _( "Failed to create file " ) + aOutFileName;
|
|
||||||
DisplayError( NULL, msg );
|
xroot->Format( &formatter, 0 );
|
||||||
}
|
}
|
||||||
else
|
catch( IO_ERROR ioe )
|
||||||
{
|
{
|
||||||
XNODE* xroot = makeGenericRoot();
|
DisplayError( NULL, ioe.errorText );
|
||||||
|
return false;
|
||||||
try
|
|
||||||
{
|
|
||||||
STREAM_OUTPUTFORMATTER outputFormatter( os );
|
|
||||||
xroot->Format( &outputFormatter, 0 );
|
|
||||||
}
|
|
||||||
catch( IO_ERROR ioe )
|
|
||||||
{
|
|
||||||
delete xroot;
|
|
||||||
goto L_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete xroot;
|
|
||||||
rc = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NETLIST_EXPORT_TOOL::WriteGENERICNetList( const wxString& aOutFileName )
|
bool NETLIST_EXPORT_TOOL::WriteGENERICNetList( const wxString& aOutFileName )
|
||||||
|
|
|
@ -155,20 +155,9 @@ void LIB_EDIT_FRAME::SaveOneSymbol()
|
||||||
|
|
||||||
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
||||||
|
|
||||||
wxFile file( fn.GetFullPath(), wxFile::write );
|
|
||||||
|
|
||||||
if( !file.IsOpened() )
|
|
||||||
{
|
|
||||||
msg.Printf( _( "Unable to create file <%s>" ), GetChars( fn.GetFullPath() ) );
|
|
||||||
DisplayError( this, msg );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.Printf( _( "Saving symbol in [%s]" ), GetChars( fn.GetPath() ) );
|
msg.Printf( _( "Saving symbol in [%s]" ), GetChars( fn.GetPath() ) );
|
||||||
SetStatusText( msg );
|
SetStatusText( msg );
|
||||||
|
|
||||||
wxFileOutputStream os( file );
|
|
||||||
STREAM_OUTPUTFORMATTER formatter( os );
|
|
||||||
wxString line;
|
wxString line;
|
||||||
|
|
||||||
/* File header */
|
/* File header */
|
||||||
|
@ -201,36 +190,46 @@ void LIB_EDIT_FRAME::SaveOneSymbol()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
formatter.Print( 0, "%s", TO_UTF8( line ) );
|
FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
|
||||||
m_component->GetReferenceField().Save( formatter );
|
|
||||||
m_component->GetValueField().Save( formatter );
|
|
||||||
formatter.Print( 0, "DRAW\n" );
|
|
||||||
|
|
||||||
LIB_ITEMS& drawList = m_component->GetDrawItemList();
|
try
|
||||||
|
|
||||||
BOOST_FOREACH( LIB_ITEM& item, drawList )
|
|
||||||
{
|
{
|
||||||
if( item.Type() == LIB_FIELD_T )
|
formatter.Print( 0, "%s", TO_UTF8( line ) );
|
||||||
continue;
|
m_component->GetReferenceField().Save( formatter );
|
||||||
|
m_component->GetValueField().Save( formatter );
|
||||||
|
formatter.Print( 0, "DRAW\n" );
|
||||||
|
|
||||||
/* Don't save unused parts or alternate body styles. */
|
LIB_ITEMS& drawList = m_component->GetDrawItemList();
|
||||||
if( m_unit && item.GetUnit() && ( item.GetUnit() != m_unit ) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( m_convert && item.GetConvert() && ( item.GetConvert() != m_convert ) )
|
BOOST_FOREACH( LIB_ITEM& item, drawList )
|
||||||
continue;
|
{
|
||||||
|
if( item.Type() == LIB_FIELD_T )
|
||||||
|
continue;
|
||||||
|
|
||||||
item.Save( formatter );
|
/* Don't save unused parts or alternate body styles. */
|
||||||
|
if( m_unit && item.GetUnit() && ( item.GetUnit() != m_unit ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( m_convert && item.GetConvert() && ( item.GetConvert() != m_convert ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
item.Save( formatter );
|
||||||
|
}
|
||||||
|
|
||||||
|
formatter.Print( 0, "ENDDRAW\n" );
|
||||||
|
formatter.Print( 0, "ENDDEF\n" );
|
||||||
|
}
|
||||||
|
catch( IO_ERROR ioe )
|
||||||
|
{
|
||||||
|
msg.Printf( _( "An error occurred attempting to save symbol file <%s>" ),
|
||||||
|
GetChars( fn.GetFullPath() ) );
|
||||||
|
DisplayError( this, msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
formatter.Print( 0, "ENDDRAW\n" );
|
|
||||||
formatter.Print( 0, "ENDDEF\n" );
|
|
||||||
}
|
}
|
||||||
catch( IO_ERROR ioe )
|
catch( IO_ERROR ioe )
|
||||||
{
|
{
|
||||||
msg.Printf( _( "An error occurred attempting to save symbol file <%s>" ),
|
DisplayError( this, ioe.errorText );
|
||||||
GetChars( fn.GetFullPath() ) );
|
return;
|
||||||
DisplayError( this, msg );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -406,9 +406,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define OUTPUTFMTBUFZ 500 ///< default buffer size for any OUTPUT_FORMATTER
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OUTPUTFORMATTER
|
* Class OUTPUTFORMATTER
|
||||||
* is an important interface (abstract) class used to output UTF8 text in
|
* is an important interface (abstract class) used to output 8 bit text in
|
||||||
* a convenient way. The primary interface is "printf() - like" but
|
* a convenient way. The primary interface is "printf() - like" but
|
||||||
* with support for indentation control. The destination of the 8 bit
|
* with support for indentation control. The destination of the 8 bit
|
||||||
* wide text is up to the implementer.
|
* wide text is up to the implementer.
|
||||||
|
@ -424,16 +426,19 @@ public:
|
||||||
*/
|
*/
|
||||||
class OUTPUTFORMATTER
|
class OUTPUTFORMATTER
|
||||||
{
|
{
|
||||||
std::vector<char> buffer;
|
std::vector<char> buffer;
|
||||||
|
char quoteChar[2];
|
||||||
|
|
||||||
int sprint( const char* fmt, ... ) throw( IO_ERROR );
|
int sprint( const char* fmt, ... ) throw( IO_ERROR );
|
||||||
int vprint( const char* fmt, va_list ap ) throw( IO_ERROR );
|
int vprint( const char* fmt, va_list ap ) throw( IO_ERROR );
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
OUTPUTFORMATTER( int aReserve = 300 ) :
|
OUTPUTFORMATTER( int aReserve = OUTPUTFMTBUFZ, char aQuoteChar = '"' ) :
|
||||||
buffer( aReserve, '\0' )
|
buffer( aReserve, '\0' )
|
||||||
{
|
{
|
||||||
|
quoteChar[0] = aQuoteChar;
|
||||||
|
quoteChar[1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~OUTPUTFORMATTER() {}
|
virtual ~OUTPUTFORMATTER() {}
|
||||||
|
@ -507,10 +512,7 @@ public:
|
||||||
* @return const char* - the quote_char as a single character string, or ""
|
* @return const char* - the quote_char as a single character string, or ""
|
||||||
* if the wrapee does not need to be wrapped.
|
* if the wrapee does not need to be wrapped.
|
||||||
*/
|
*/
|
||||||
virtual const char* GetQuoteChar( const char* wrapee )
|
virtual const char* GetQuoteChar( const char* wrapee );
|
||||||
{
|
|
||||||
return GetQuoteChar( wrapee, "\"" );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function Quotes
|
* Function Quotes
|
||||||
|
@ -550,8 +552,8 @@ public:
|
||||||
* Constructor STRING_FORMATTER
|
* Constructor STRING_FORMATTER
|
||||||
* reserves space in the buffer
|
* reserves space in the buffer
|
||||||
*/
|
*/
|
||||||
STRING_FORMATTER( int aReserve = 300 ) :
|
STRING_FORMATTER( int aReserve = OUTPUTFMTBUFZ, char aQuoteChar = '"' ) :
|
||||||
OUTPUTFORMATTER( aReserve )
|
OUTPUTFORMATTER( aReserve, aQuoteChar )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,8 +577,8 @@ public:
|
||||||
return mystring;
|
return mystring;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----<OUTPUTFORMATTER>------------------------------------------------
|
|
||||||
protected:
|
protected:
|
||||||
|
//-----<OUTPUTFORMATTER>------------------------------------------------
|
||||||
void write( const char* aOutBuf, int aCount ) throw( IO_ERROR );
|
void write( const char* aOutBuf, int aCount ) throw( IO_ERROR );
|
||||||
//-----</OUTPUTFORMATTER>-----------------------------------------------
|
//-----</OUTPUTFORMATTER>-----------------------------------------------
|
||||||
};
|
};
|
||||||
|
@ -589,9 +591,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
class FILE_OUTPUTFORMATTER : public OUTPUTFORMATTER
|
class FILE_OUTPUTFORMATTER : public OUTPUTFORMATTER
|
||||||
{
|
{
|
||||||
FILE* m_fp; ///< takes ownership
|
|
||||||
wxString m_filename;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -599,9 +598,14 @@ public:
|
||||||
* @param aFileName is the full filename to open and save to as a text file.
|
* @param aFileName is the full filename to open and save to as a text file.
|
||||||
* @param aMode is what you would pass to wxFopen()'s mode, defaults to wxT( "wt" )
|
* @param aMode is what you would pass to wxFopen()'s mode, defaults to wxT( "wt" )
|
||||||
* for text files that are to be created here and now.
|
* for text files that are to be created here and now.
|
||||||
|
* @param qQuoteChar is a C string holding a single char used for quoting
|
||||||
|
problematic strings (with whitespace or special characters in them).
|
||||||
* @throw IO_ERROR if the file cannot be opened.
|
* @throw IO_ERROR if the file cannot be opened.
|
||||||
*/
|
*/
|
||||||
FILE_OUTPUTFORMATTER( const wxString& aFileName, const wxChar* aMode = wxT( "wt" ) ) throw( IO_ERROR );
|
FILE_OUTPUTFORMATTER( const wxString& aFileName,
|
||||||
|
const wxChar* aMode = wxT( "wt" ),
|
||||||
|
char aQuoteChar = '"' )
|
||||||
|
throw( IO_ERROR );
|
||||||
|
|
||||||
~FILE_OUTPUTFORMATTER();
|
~FILE_OUTPUTFORMATTER();
|
||||||
|
|
||||||
|
@ -609,6 +613,9 @@ protected:
|
||||||
//-----<OUTPUTFORMATTER>------------------------------------------------
|
//-----<OUTPUTFORMATTER>------------------------------------------------
|
||||||
void write( const char* aOutBuf, int aCount ) throw( IO_ERROR );
|
void write( const char* aOutBuf, int aCount ) throw( IO_ERROR );
|
||||||
//-----</OUTPUTFORMATTER>-----------------------------------------------
|
//-----</OUTPUTFORMATTER>-----------------------------------------------
|
||||||
|
|
||||||
|
FILE* m_fp; ///< takes ownership
|
||||||
|
wxString m_filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -620,7 +627,6 @@ protected:
|
||||||
class STREAM_OUTPUTFORMATTER : public OUTPUTFORMATTER
|
class STREAM_OUTPUTFORMATTER : public OUTPUTFORMATTER
|
||||||
{
|
{
|
||||||
wxOutputStream& os;
|
wxOutputStream& os;
|
||||||
char quoteChar[2];
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -629,16 +635,13 @@ public:
|
||||||
* to a file, socket, or zip file.
|
* to a file, socket, or zip file.
|
||||||
*/
|
*/
|
||||||
STREAM_OUTPUTFORMATTER( wxOutputStream& aStream, char aQuoteChar = '"' ) :
|
STREAM_OUTPUTFORMATTER( wxOutputStream& aStream, char aQuoteChar = '"' ) :
|
||||||
|
OUTPUTFORMATTER( OUTPUTFMTBUFZ, aQuoteChar ),
|
||||||
os( aStream )
|
os( aStream )
|
||||||
{
|
{
|
||||||
quoteChar[0] = aQuoteChar;
|
|
||||||
quoteChar[1] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----<OUTPUTFORMATTER>------------------------------------------------
|
|
||||||
const char* GetQuoteChar( const char* wrapee );
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
//-----<OUTPUTFORMATTER>------------------------------------------------
|
||||||
void write( const char* aOutBuf, int aCount ) throw( IO_ERROR );
|
void write( const char* aOutBuf, int aCount ) throw( IO_ERROR );
|
||||||
//-----</OUTPUTFORMATTER>-----------------------------------------------
|
//-----</OUTPUTFORMATTER>-----------------------------------------------
|
||||||
};
|
};
|
||||||
|
|
|
@ -84,32 +84,27 @@ bool PCB_CALCULATOR_FRAME::ReadDataFile()
|
||||||
|
|
||||||
bool PCB_CALCULATOR_FRAME::WriteDataFile()
|
bool PCB_CALCULATOR_FRAME::WriteDataFile()
|
||||||
{
|
{
|
||||||
wxFFileOutputStream os( GetDataFilename(), wxT( "wt" ) );
|
|
||||||
if( !os.IsOk() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Switch the locale to standard C (needed to read/write floating point numbers
|
// Switch the locale to standard C (needed to read/write floating point numbers
|
||||||
LOCALE_IO toggle;
|
LOCALE_IO toggle;
|
||||||
|
|
||||||
PCB_CALCULATOR_DATAFILE * datafile = new PCB_CALCULATOR_DATAFILE( &m_RegulatorList );
|
std::auto_ptr<PCB_CALCULATOR_DATAFILE> datafile( new PCB_CALCULATOR_DATAFILE( &m_RegulatorList ) );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int nestlevel;
|
FILE_OUTPUTFORMATTER formatter( GetDataFilename() );
|
||||||
STREAM_OUTPUTFORMATTER outputFormatter( os );
|
|
||||||
nestlevel = datafile->WriteHeader( &outputFormatter );
|
int nestlevel = datafile->WriteHeader( &formatter );
|
||||||
datafile->Format( &outputFormatter, nestlevel );
|
|
||||||
|
datafile->Format( &formatter, nestlevel );
|
||||||
|
|
||||||
while( nestlevel-- )
|
while( nestlevel-- )
|
||||||
outputFormatter.Print( nestlevel, ")\n" );
|
formatter.Print( nestlevel, ")\n" );
|
||||||
}
|
}
|
||||||
catch( IO_ERROR ioe )
|
catch( IO_ERROR ioe )
|
||||||
{
|
{
|
||||||
delete datafile;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete datafile;
|
|
||||||
|
|
||||||
m_RegulatorListChanged = false;
|
m_RegulatorListChanged = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3437,19 +3437,12 @@ void SPECCTRA_DB::ExportPCB( wxString filename, bool aNameChange ) throw( IO_ERR
|
||||||
{
|
{
|
||||||
if( pcb )
|
if( pcb )
|
||||||
{
|
{
|
||||||
wxFFileOutputStream os( filename, wxT( "wt" ) );
|
FILE_OUTPUTFORMATTER formatter( filename, wxT( "wt" ), quote_char[0] );
|
||||||
|
|
||||||
if( !os.IsOk() )
|
|
||||||
{
|
|
||||||
ThrowIOError( _("Unable to open file \"%s\""), GetChars(filename) );
|
|
||||||
}
|
|
||||||
|
|
||||||
STREAM_OUTPUTFORMATTER outputFormatter( os, quote_char[0] );
|
|
||||||
|
|
||||||
if( aNameChange )
|
if( aNameChange )
|
||||||
pcb->pcbname = TO_UTF8(filename);
|
pcb->pcbname = TO_UTF8( filename );
|
||||||
|
|
||||||
pcb->Format( &outputFormatter, 0 );
|
pcb->Format( &formatter, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3458,16 +3451,9 @@ void SPECCTRA_DB::ExportSESSION( wxString filename )
|
||||||
{
|
{
|
||||||
if( session )
|
if( session )
|
||||||
{
|
{
|
||||||
wxFFileOutputStream os( filename, wxT( "wt" ) );
|
FILE_OUTPUTFORMATTER formatter( filename, wxT( "wt" ), quote_char[0] );
|
||||||
|
|
||||||
if( !os.IsOk() )
|
session->Format( &formatter, 0 );
|
||||||
{
|
|
||||||
ThrowIOError( _("Unable to open file \"%s\""), GetChars(filename) );
|
|
||||||
}
|
|
||||||
|
|
||||||
STREAM_OUTPUTFORMATTER outputFormatter( os, quote_char[0] );
|
|
||||||
|
|
||||||
session->Format( &outputFormatter, 0 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue