Commit 7c5e42b4 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

switch from STREAM_OUTPUTFORMATTER to FILE_OUTPUTFORMATTER mostly...

switch from STREAM_OUTPUTFORMATTER to FILE_OUTPUTFORMATTER mostly throughout,and minor richio factoring
parent 58ae2e19
Loading
Loading
Loading
Loading
+12 −12
Original line number Original line Diff line number Diff line
@@ -314,6 +314,11 @@ 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 );
@@ -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;
+10 −8
Original line number Original line Diff line number Diff line
@@ -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 )
        {
        {
+12 −12
Original line number Original line Diff line number Diff line
@@ -78,21 +78,21 @@ 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 = wxT( "Failed to create component library file " ) + aFileName;
            msg.Printf( _( "An error occurred attempting to save component library <%s>." ),
                        GetChars( aFileName ) );
            DisplayError( this, msg );
            DisplayError( this, msg );
            return false;
            return false;
        }
        }

    }
    STREAM_OUTPUTFORMATTER formatter( os );
    catch( ... /* IO_ERROR ioe */ )

    if( !libCache->Save( formatter ) )
    {
    {
        msg.Printf( _( "An error occurred attempting to save component \
        msg = wxT( "Failed to create component library file " ) + aFileName;
library <%s>." ), GetChars( aFileName ) );
        DisplayError( this, msg );
        DisplayError( this, msg );
        return false;
        return false;
    }
    }
+25 −25
Original line number Original line Diff line number Diff line
@@ -360,17 +360,9 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
        }
        }
    }
    }


    wxFFileOutputStream libStream( libFileName.GetFullPath(), wxT( "wt" ) );
    try

    if( !libStream.IsOk() )
    {
    {
        libFileName.MakeAbsolute();
        FILE_OUTPUTFORMATTER    libFormatter( libFileName.GetFullPath() );
        msg = wxT( "Failed to create component library file " ) + libFileName.GetFullPath();
        DisplayError( this, msg );
        return;
    }

    STREAM_OUTPUTFORMATTER libFormatter( libStream );


        if( !m_library->Save( libFormatter ) )
        if( !m_library->Save( libFormatter ) )
        {
        {
@@ -379,6 +371,14 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
            DisplayError( this, msg );
            DisplayError( this, msg );
            return;
            return;
        }
        }
    }
    catch( ... /* IO_ERROR ioe */ )
    {
        libFileName.MakeAbsolute();
        msg = wxT( "Failed to create component library file " ) + libFileName.GetFullPath();
        DisplayError( this, msg );
        return;
    }


    wxFileName docFileName = libFileName;
    wxFileName docFileName = libFileName;


@@ -399,18 +399,9 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
        }
        }
    }
    }


    wxFFileOutputStream docStream( docFileName.GetFullPath(), wxT( "wt" ) );
    try

    if( !docStream.IsOk() )
    {
    {
        docFileName.MakeAbsolute();
        FILE_OUTPUTFORMATTER    docFormatter( docFileName.GetFullPath() );
        msg = wxT( "Failed to create component document library file " ) +
              docFileName.GetFullPath();
        DisplayError( this, msg );
        return;
    }

    STREAM_OUTPUTFORMATTER docFormatter( docStream );


        if( !m_library->SaveDocs( docFormatter ) )
        if( !m_library->SaveDocs( docFormatter ) )
        {
        {
@@ -420,6 +411,15 @@ void LIB_EDIT_FRAME::SaveActiveLibrary( wxCommandEvent& event )
            DisplayError( this, msg );
            DisplayError( this, msg );
            return;
            return;
        }
        }
    }
    catch( ... /* IO_ERROR ioe */ )
    {
        docFileName.MakeAbsolute();
        msg = wxT( "Failed to create component document library file " ) +
              docFileName.GetFullPath();
        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 );
+9 −23
Original line number Original line Diff line number Diff line
@@ -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() )
    {
    L_error:
        wxString msg = _( "Failed to create file " ) + aOutFileName;
        DisplayError( NULL, msg );
    }
    else
    {
        XNODE*  xroot = makeGenericRoot();


    try
    try
    {
    {
            STREAM_OUTPUTFORMATTER  outputFormatter( os );
        FILE_OUTPUTFORMATTER    formatter( aOutFileName );
            xroot->Format( &outputFormatter, 0 );

        xroot->Format( &formatter, 0 );
    }
    }
    catch( IO_ERROR ioe )
    catch( IO_ERROR ioe )
    {
    {
            delete xroot;
        DisplayError( NULL, ioe.errorText );
            goto L_error;
        return false;
        }

        delete xroot;
        rc = true;
    }
    }


    return rc;
    return true;
}
}


bool NETLIST_EXPORT_TOOL::WriteGENERICNetList( const wxString& aOutFileName )
bool NETLIST_EXPORT_TOOL::WriteGENERICNetList( const wxString& aOutFileName )
Loading