예제 #1
0
int Compiler::compile()
{
    int retval( EXIT_SUCCESS );
    std::auto_ptr< Document > doc( new Document( *this, loc ) );
    doc->setOutputType( outType );
    doc->parse( lexer.get() );
    doc->build();
    std::FILE* out( std::fopen( outFileName.c_str() , "wb" ) );
    if( !out )
        throw FatalIOError( ERR_OPEN, L"for inf or hlp output" );
    try {
        doc->write( out );
    }
    catch( FatalError& e ) {
        retval = EXIT_FAILURE;
        printError( e.code );
    }
    catch( FatalIOError& e ) {
        retval = EXIT_FAILURE;
        printError( e.code, e.fname );
    }
    std::fclose( out );
    if( xref ) {
        //TODO: convert to ostream when streams and strings mature
        std::string fname( outFileName );
        fname.erase( fname.rfind( '.' ) );
        fname += ".log";
        out = std::fopen( fname.c_str(), "w" );
        if( !out )
            throw FatalIOError( ERR_OPEN, L"for log output" );
        try {
            std::fprintf( out, "Summary for %s\n\n", outFileName.c_str() );
            doc->summary( out );
        }
        catch( FatalError& e ) {
            retval = EXIT_FAILURE;
            printError( e.code );
        }
        catch( FatalIOError& e ) {
            retval = EXIT_FAILURE;
            printError( e.code, e.fname );
        }
        std::fclose( out );
    }
    return retval;
}
예제 #2
0
STD1::uint32_t Document::writeBitmaps( std::FILE* out )
{
    STD1::uint32_t offset( 0 );
    if( !bitmapNames.empty() ) {
        offset = std::ftell( out );
        std::FILE* tmp( std::fopen( tmpName.c_str(), "rb" ) );
        if( !tmp )
            throw FatalIOError( ERR_OPEN, L"(temporary file for bitmaps)" );
        std::fseek( tmp, 0L, SEEK_END );
        STD1::uint32_t length( std::ftell( tmp ) );
        std::fseek( tmp, 0L, SEEK_SET );
        std::vector< STD1::uint8_t > buffer( BUFSIZ );
        //copy the temporary file into this one
        try {
            while( length > BUFSIZ ) {
                if( std::fread( &buffer[0], sizeof( STD1::uint8_t ), BUFSIZ, tmp ) != BUFSIZ )
                    throw FatalIOError( ERR_READ, L"(temporary file for bitmaps)" );
                if( std::fwrite( &buffer[0], sizeof( STD1::uint8_t ), BUFSIZ, out ) != BUFSIZ )
                    throw FatalError( ERR_WRITE );
                length -= BUFSIZ;
            }
            if( length ) {
                if( std::fread( &buffer[0], sizeof( STD1::uint8_t ), length, tmp ) != length )
                    throw FatalIOError( ERR_READ, L"(temporary file for bitmaps)" );
                if( std::fwrite( &buffer[0], sizeof( STD1::uint8_t ), length, out ) != length )
                    throw FatalError( ERR_WRITE );
            }
        }
        catch( FatalError& e ) {
            std::fclose( tmp );
            std::remove( tmpName.c_str() );
            throw e;
        }
        catch( FatalIOError& e ) {
            std::fclose( tmp );
            std::remove( tmpName.c_str() );
            throw e;
        }
        std::fclose( tmp );
        std::remove( tmpName.c_str() );
    }
    return offset;
}
예제 #3
0
Foam::Istream& Foam::regIOobject::readStream()
{
    if (IFstream::debug)
    {
        Info<< "regIOobject::readStream() : "
            << "reading object " << name()
            << " from file " << objectPath()
            << endl;
    }

    if (readOpt() == NO_READ)
    {
        FatalErrorIn("regIOobject::readStream()")
            << "NO_READ specified for read-constructor of object " << name()
            << " of class " << headerClassName()
            << abort(FatalError);
    }

    // Construct object stream and read header if not already constructed
    if (!isPtr_)
    {
        if (!(isPtr_ = objectStream()))
        {
            FatalIOError
            (
                "regIOobject::readStream()",
                __FILE__,
                __LINE__,
                objectPath(),
                0
            )   << "cannot open file"
                << exit(FatalIOError);
        }
        else if (!readHeader(*isPtr_))
        {
            FatalIOErrorIn("regIOobject::readStream()", *isPtr_)
                << "problem while reading header for object " << name()
                << exit(FatalIOError);
        }
    }

    if (!lastModified_)
    {
        lastModified_ = lastModified(filePath());
    }

    return *isPtr_;
}
예제 #4
0
void Foam::IOerror::SafeFatalIOError
(
    const char* functionName,
    const char* sourceFileName,
    const int sourceFileLineNumber,
    const IOstream& ioStream,
    const string& msg
)
{
    if (JobInfo::constructed)
    {
        FatalIOError
        (
            functionName,
            sourceFileName,
            sourceFileLineNumber,
            ioStream
        )   << msg << Foam::exit(FatalIOError);
    }
    else
    {
        std::cerr
            << std::endl
            << "--> FOAM FATAL IO ERROR:" << std::endl
            << msg
            << std::endl
            << "file: " << ioStream.name()
            << " at line " << ioStream.lineNumber() << '.'
            << std::endl << std::endl
            << "    From function " << functionName
            << std::endl
            << "    in file " << sourceFileName
            << " at line " << sourceFileLineNumber << '.'
            << std::endl;
        ::exit(1);
    }
}
예제 #5
0
void Document::makeBitmaps()
{
    if( !bitmapNames.empty() ) {
        //could use tmpfile...
        tmpName = Environment.value( "TMP" );
        tmpName += std::tmpnam( NULL );
        std::FILE* tmp( std::fopen( tmpName.c_str(), "wb" ) );
        if( !tmp )
            throw FatalIOError( ERR_OPEN, L"(temporary file for bitmaps)" );
        //get IPFCARTWORK from env
        std::string env( Environment.value( "IPFCARTWORK" ) );
        std::vector< std::string > paths;
        std::string cwd;    //empty string for current directory
        paths.push_back( cwd );
#ifdef __UNIX__
        std::string separators( ":;" );
        char slash( '/' );
#else
        std::string separators( ";" );
        char slash( '\\' );
#endif
        std::string::size_type idx1( 0 );
        std::string::size_type idx2( env.find_first_of( separators, idx1 ) );
        paths.push_back( env.substr( idx1, idx2 - idx1 ) );
        while( idx2 != std::string::npos ) {
            idx1 = idx2 + 1;
            idx2 = env.find_first_of( separators, idx1 );
            paths.push_back( env.substr( idx1, idx2 - idx1 ) );
        }
        try {
            for( BitmapNameIter itr = bitmapNames.begin(); itr != bitmapNames.end(); ++itr ) {
                std::string fname;
                wtombstring( itr->first, fname );
                for( size_t count = 0; count < paths.size(); ++count ) {
                    std::string fullname( paths[ count ] );
                    if( !fullname.empty() )
                        fullname += slash;
                    fullname += fname;
#ifndef __UNIX__
                    if( fullname.size() > PATH_MAX ) {
                        throw FatalError( ERR_PATH_MAX );
                    }
#endif
                    try {
#ifdef CHECKCOMP
                        std::printf( "Processing bitmap %s\n", fullname.c_str() );
#endif
                        Bitmap bm( fullname );
                        itr->second = bm.write( tmp );
                        break;
                    }
                    catch( FatalError& e ) {
                        if( count == paths.size() - 1 )
                            throw FatalIOError( e.code, itr->first );
                    }
                    catch( Class1Error& e ) {
                        printError( e.code, itr->first );
                    }
                }
            }
        }
        catch( FatalError& e ) {
            std::fclose( tmp );
            std::remove( tmpName.c_str() );
            throw e;
        }
        catch( FatalIOError& e ) {
            std::fclose( tmp );
            std::remove( tmpName.c_str() );
            throw e;
        }
        std::fclose( tmp );
    }
}