Ejemplo n.º 1
0
void splitAttribute( const std::wstring& text, std::wstring& key, std::wstring& value)
{
    std::wstring::size_type index( text.find( '=', 0 ) );
    key = text.substr( 0, index );
    value = text.substr( index + 1 );
    killQuotes( value );
}
Ejemplo n.º 2
0
/*****************************************************************************
* First character of command id should be second char of line
* Lexer returns a full line of data, needs to be parsed if .ce
* In version 1.0, valid commands are:
* .* (comment) followed by text to '\n'
* .br (new line), nothing else allowed on line
* .im (include file) 'filename'
* .nameit (define text macro) symbol=[a-zA-Z0-9]+ (10 max) text='text string'
*     text may contain entity references, nameit references and tags
* .ce (center) no tags, but text and both entity types
* Version 2.0 only supports .*, .br, .im
*/
Lexer::Token Document::processCommand( Lexer* lexer, Tag* parent )
{
    if( lexer->cmdId() == Lexer::COMMENT )
        ;//do nothing
    else if( lexer->cmdId() == Lexer::BREAK )
        parent->appendChild( new BrCmd( this, parent, dataName(), dataLine(), dataCol() ) );
    else if( lexer->cmdId() == Lexer::CENTER ) {
        CeCmd* cecmd( new CeCmd( this, parent, dataName(), dataLine(), dataCol() ) );
        parent->appendChild( cecmd );
        return cecmd->parse( lexer );
    }
    else if( lexer->cmdId() == Lexer::IMBED ) {
        std::string env( Environment.value( "IPFCIMBED" ) );
        std::vector< std::wstring > paths;
        std::wstring 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 ) );
        std::wstring fbuffer;
        mbtowstring( env.substr( idx1, idx2 - idx1 ), fbuffer );
        paths.push_back( fbuffer );
        while( idx2 != std::string::npos ) {
            idx1 = idx2 + 1;
            idx2 = env.find_first_of( separators, idx1 );
            fbuffer.clear();
            mbtowstring( env.substr( idx1, idx2 - idx1 ), fbuffer );
            paths.push_back( fbuffer );
        }
        for( size_t count = 0; count < paths.size(); ++count ) {
            std::wstring* fname( new std::wstring( paths[ count ] ) );
            if( !fname->empty() )
                *fname += slash;
            *fname += lexer->text();
#ifndef __UNIX__
            if( fname->size() > PATH_MAX ) {
                throw FatalError( ERR_PATH_MAX );
            }
#endif
            try {
                IpfFile* ipff( new IpfFile( fname ) );
                fname = addFileName( fname );
                pushInput( ipff );
                break;
            }
            catch( FatalError& e ) {
                delete fname;
                if( count == paths.size() - 1 )
                    throw e;
            }
            catch( FatalIOError& e ) {
                delete fname;
                if( count == paths.size() - 1 )
                    throw e;
            }
        }
    }
    else if( lexer->cmdId() == Lexer::NAMEIT ) {
        std::wstring::size_type idx1( lexer->text().find( L"symbol=" ) );
        std::wstring::size_type idx2( lexer->text().find( L' ', idx1 ) );
        std::wstring sym( lexer->text().substr( idx1 + 7, idx2 - idx1 - 7 ) );
        killQuotes( sym );
        sym.insert( sym.begin(), L'&' );
        sym += L'.';
        std::wstring::size_type idx3( lexer->text().find( L"text=" ) );
        //check for single quotes
        std::wstring::size_type idx4( lexer->text()[ idx3 + 5 ] == L'\'' ? \
            lexer->text().find( L'\'', idx3  + 6 ) : \
            lexer->text().find( L' ', idx3 + 5 ) );
        std::wstring txt( lexer->text().substr( idx3 + 5, idx4 - idx3 - 5 ) );
        killQuotes( txt );
        if( !nls->isEntity( sym ) && nameIts.find( sym ) == nameIts.end() ) //add it to the list
            nameIts.insert( std::map< std::wstring, std::wstring >::value_type( sym, txt ) );
        else
            printError( ERR3_DUPSYMBOL );
    }
    else
        printError( ERR1_CMDNOTDEF );
    return getNextToken();
}
Ejemplo n.º 3
0
void Nls::readNLS( std::FILE *nls )
{
    wchar_t  buffer[ 256 ];
    wchar_t* value;
    bool     doGrammer( false );
    while( std::fgetws( buffer, sizeof( buffer ) / sizeof( wchar_t ), nls )) {
        size_t len( std::wcslen( buffer ) );
        killEOL( buffer + len - 1 );
        if( len == 1 )
            continue;               //skip blank lines
        if( buffer[0] == L'#' )
            continue;               //skip comments
        if( ( value = std::wcschr( buffer, L'=' ) ) != 0 ) {
            *value = '\0';
            ++value;
        }
        else
            value = buffer;
        if( doGrammer ) {
            if( std::wcscmp( buffer, L"Words" ) == 0 ) {
                processGrammer( value );
            }
            else if ( std::wcscmp( buffer, L"RemoveNL" ) == 0 ) {
                //FIXME: exclude these values from s/dbcs table?
            }
        }
        else if( std::wcscmp( buffer, L"Country" ) == 0 ) {
            country.country = static_cast< STD1::uint16_t >( std::wcstoul( value, 0, 10 ) );
        }
        else if( std::wcscmp( buffer, L"CodePage" ) == 0 ) {
            country.codePage = static_cast< STD1::uint16_t >( std::wcstoul( value, 0, 10 ) );
        }
        else if( std::wcscmp( buffer, L"Note" ) == 0 ) {
            std::wstring text( value );
            killQuotes( text );
            noteText = text;
        }
        else if( std::wcscmp( buffer, L"Caution" ) == 0 ) {
            std::wstring text( value );
            killQuotes( text );
            cautionText = text;
        }
        else if( std::wcscmp( buffer, L"Warning" ) == 0 ) {
            std::wstring text( value );
            killQuotes( text );
            warningText = text;
        }
        else if( std::wcscmp( buffer, L"Reference" ) == 0 ) {
            std::wstring text( value );
            killQuotes( text );
            referenceText = text;
        }
        else if( std::wcscmp( buffer, L"olChars" ) == 0 ) {
            std::wstring text( value );
            olCh = text;
        }
        else if( std::wcscmp( buffer, L"olClose1" ) == 0 ) {
            std::wstring text( value );
            olClosers[ 0 ] = text;
        }
        else if( std::wcscmp( buffer, L"olClose2" ) == 0 ) {
            std::wstring text( value );
            olClosers[ 1 ] = text;
        }
        else if( std::wcscmp( buffer, L"ulItemId1" ) == 0 ) {
            std::wstring text( value );
            ulBul[ 0 ] = text;
        }
        else if( std::wcscmp( buffer, L"ulItemId2" ) == 0 ) {
            std::wstring text( value );
            ulBul[ 1 ] = text;
        }
        else if( std::wcscmp( buffer, L"ulItemId3" ) == 0 ) {
            std::wstring text( value );
            ulBul[ 2 ] = text;
        }
        else if( std::wcscmp( buffer, L"cgraphicFontFaceName" ) == 0 ) {
            std::wstring text( value );
            killQuotes( text );
            cgraphicFontFace = text;
        }
        else if( std::wcscmp( buffer, L"cgraphicFontWidth" ) == 0 ) {
            cgraphicFontW = static_cast< int >( std::wcstol( value, 0, 10 ) );
        }
        else if( std::wcscmp( buffer, L"cgraphicFontHeight" ) == 0 ) {
            cgraphicFontH = static_cast< int >( std::wcstol( value, 0, 10 ) );
        }
        else if( std::wcscmp( buffer, L"Grammer" ) == 0 ) {
            doGrammer = true;
        }
        else if( std::wcscmp( buffer, L"eGrammer" ) == 0 ) {
            doGrammer = false;
        }
    }
}